#include "SKEAZN84.h"
#include "delay.h"
#include "kea8_gpio.h"
#include "kea8_uart.h"
#include "stdio.h"
#include "kea8_pit.h"
#include "kea8_adc.h"
extern uint16_t ADC_GetoneValue(ADCHn adcn_ch, ADC_nbit bit);
void GPIO_Cfg(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIOx = PTC;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_Pin = PTC1|PTC2;
GPIO_InitStructure.GPIO_InitState = Bit_RESET;
GPIO_Init(&GPIO_InitStructure);
}
void UART_Cfg(void)
{
UART_InitTypeDef UART_InitStruct;
UART_InitStruct.UART_BaudRate = 115200;
UART_InitStruct.UART_WordLength = UART_WordLength_8b ;
UART_InitStruct.UART_StopBits = UART_StopBits_1;
UART_InitStruct.UART_Parity = UART_Parity_No;
UART_InitStruct.UART_Mode = UART_Mode_Rx|UART_Mode_Tx;
UART_InitStruct.UART_PIN = RX_PTB0_TX_PTB1 ;
UART_Init(&UART_InitStruct);
UART_ITConfig(UART_IT_RXNE, ENABLE);
NVIC_Init(UART0_IRQn,1);
}
void PIT_Cfg(void)
{
PIT_InitTypeDef PIT_InitStruct;
PIT_InitStruct.CHANNELx = PIT_CHANNEL0;
PIT_InitStruct.PIT_Mode = PIT_Mode_ms;
PIT_InitStruct.Timer = 1000;
PIT_Init(&PIT_InitStruct);
PIT_ITConfig(PIT_CHANNEL0,ENABLE);
PIT_ClearFlag(PIT_CHANNEL0);
PIT_Cmd(PIT_CHANNEL0,ENABLE);
NVIC_Init(PIT_CH0_IRQn,1);
}
int main()
{
double volage= 0;
int i=0 ;
SystemCoreClockUpdate();
for(;;)
{
volage = 0;
for(i =0 ;i<10 ; i++)
volage +=(double)ADC_GetoneValue(ADC_CHANNEL_AD3, ADC_12BIT);
volage = volage/4096.0 ;//因为我们选择了分辨率为12倍的ADC,所以精度为2^12=4096;
printf("Volage : %lf \n",volage);
delay_ms(1000);//延时1S效果更好
}
}
|