Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- ******************************************************************************
- * @file main.c
- * @author Ac6
- * @version V1.0
- * @date 01-December-2013
- * @brief Default main function.
- ******************************************************************************
- */
- #include "stm32f4xx.h"
- #include "stm32f4_discovery.h"
- double ADC_Result, ADC_Result2;
- double score, score2;
- int main(void)
- {
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC2, ENABLE);
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
- GPIO_InitTypeDef GPIO_InitStructure1;
- /* Configure PD12, PD13, PD14 and PD15 in output pushpull mode */
- GPIO_InitStructure1.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14
- | GPIO_Pin_15;
- GPIO_InitStructure1.GPIO_Mode = GPIO_Mode_OUT;
- GPIO_InitStructure1.GPIO_OType = GPIO_OType_PP;
- GPIO_InitStructure1.GPIO_Speed = GPIO_Speed_100MHz;
- GPIO_InitStructure1.GPIO_PuPd = GPIO_PuPd_NOPULL;
- GPIO_Init(GPIOD, &GPIO_InitStructure1);
- GPIO_InitTypeDef GPIO_InitStructure;
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
- GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- ADC_InitTypeDef ADC_InitStructure;
- ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
- ADC_InitStructure.ADC_ScanConvMode = DISABLE;
- ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
- ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1;
- ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
- ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
- ADC_InitStructure.ADC_NbrOfConversion = 1;
- ADC_Init(ADC1, &ADC_InitStructure);
- ADC_InitTypeDef ADC_InitStructure2;
- ADC_InitStructure2.ADC_Resolution = ADC_Resolution_12b;
- ADC_InitStructure2.ADC_ScanConvMode = DISABLE;
- ADC_InitStructure2.ADC_ContinuousConvMode = ENABLE;
- ADC_InitStructure2.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1;
- ADC_InitStructure2.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
- ADC_InitStructure2.ADC_DataAlign = ADC_DataAlign_Right;
- ADC_InitStructure2.ADC_NbrOfConversion = 1;
- ADC_Init(ADC2, &ADC_InitStructure2);
- ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 1, ADC_SampleTime_84Cycles);
- ADC_RegularChannelConfig(ADC2, ADC_Channel_2, 1, ADC_SampleTime_84Cycles);
- ADC_Cmd(ADC1, ENABLE);
- ADC_Cmd(ADC2, ENABLE);
- for (;;) {
- ADC_SoftwareStartConv(ADC1);
- ADC_SoftwareStartConv(ADC2);
- while (ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET)
- ;
- ADC_Result = ADC_GetConversionValue(ADC1);
- score = (ADC_Result * 3) / 4095;
- while (ADC_GetFlagStatus(ADC2, ADC_FLAG_EOC) == RESET)
- ;
- ADC_Result2 = ADC_GetConversionValue(ADC2);
- score2 = (ADC_Result2 * 3) / 4095;
- if (score > 0 && score < 0.75 && score2 > 0 && score2 < 0.75) {
- GPIO_SetBits(GPIOD, GPIO_Pin_12);
- GPIO_ResetBits(GPIOD, GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15);
- }
- if (score > 0.75 && score < 1.5 && score2 > 0.75 && score2 < 1.5) {
- GPIO_SetBits(GPIOD, GPIO_Pin_13);
- GPIO_ResetBits(GPIOD, GPIO_Pin_12 | GPIO_Pin_14 | GPIO_Pin_15);
- }
- if (score > 1.5 && score < 2.25 && score2 > 1.5 && score2 < 2.25) {
- GPIO_SetBits(GPIOD, GPIO_Pin_14);
- GPIO_ResetBits(GPIOD, GPIO_Pin_13 | GPIO_Pin_12 | GPIO_Pin_15);
- }
- if (score > 2.25 && score <= 3 && score2 > 2.25 && score2 <= 3) {
- GPIO_SetBits(GPIOD, GPIO_Pin_15);
- GPIO_ResetBits(GPIOD, GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_12);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement