[其他MCU] 【TRK-KEA8开发笔记】——AD+UART的开发

[复制链接]
 楼主| Luis德华 发表于 2015-12-6 20:53 | 显示全部楼层 |阅读模式
先上硬件电路图:

芯片的SCH告诉我们,KEA8有一个ADC接口,是ADC-PTA7这个接口,根据原理图,我们找到具体模块、

原来是一个光耦三极管(光线传感器),是利用三极管的特性进而实现开关。
看懂了硬件部分,我们进行软件部分的编写:
 楼主| Luis德华 发表于 2015-12-6 20:54 | 显示全部楼层
  1. #include "SKEAZN84.h"                  
  2. #include "delay.h"
  3. #include "kea8_gpio.h"
  4. #include "kea8_uart.h"
  5. #include "stdio.h"
  6. #include "kea8_pit.h"
  7. #include "kea8_adc.h"
  8. extern uint16_t ADC_GetoneValue(ADCHn adcn_ch, ADC_nbit bit);
  9. void GPIO_Cfg(void)
  10. {
  11.                 GPIO_InitTypeDef GPIO_InitStructure;
  12.         GPIO_InitStructure.GPIOx = PTC;  
  13.         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  14.         GPIO_InitStructure.GPIO_Pin = PTC1|PTC2;  
  15.         GPIO_InitStructure.GPIO_InitState = Bit_RESET;
  16.         GPIO_Init(&GPIO_InitStructure);
  17. }
  18. void UART_Cfg(void)
  19. {
  20.         UART_InitTypeDef UART_InitStruct;
  21.         UART_InitStruct.UART_BaudRate = 115200;
  22.         UART_InitStruct.UART_WordLength = UART_WordLength_8b ;  
  23.         UART_InitStruct.UART_StopBits = UART_StopBits_1;      
  24.         UART_InitStruct.UART_Parity = UART_Parity_No;         
  25.         UART_InitStruct.UART_Mode = UART_Mode_Rx|UART_Mode_Tx;
  26.         UART_InitStruct.UART_PIN = RX_PTB0_TX_PTB1 ;         
  27.         UART_Init(&UART_InitStruct);                     
  28.         UART_ITConfig(UART_IT_RXNE, ENABLE);            
  29.         NVIC_Init(UART0_IRQn,1);
  30. }
  31. void PIT_Cfg(void)
  32. {
  33.         PIT_InitTypeDef  PIT_InitStruct;
  34.         PIT_InitStruct.CHANNELx = PIT_CHANNEL0;
  35.         PIT_InitStruct.PIT_Mode = PIT_Mode_ms;  
  36.         PIT_InitStruct.Timer = 1000;           
  37.         PIT_Init(&PIT_InitStruct);            
  38.         PIT_ITConfig(PIT_CHANNEL0,ENABLE);     
  39.         PIT_ClearFlag(PIT_CHANNEL0);         
  40.         PIT_Cmd(PIT_CHANNEL0,ENABLE);         
  41.         NVIC_Init(PIT_CH0_IRQn,1);   
  42. }
  43. int main()
  44. {
  45.         double volage= 0;
  46.         int i=0 ;
  47.         SystemCoreClockUpdate();         
  48.         for(;;)
  49.         {
  50.                 volage = 0;
  51.                 for(i =0 ;i<10 ; i++)
  52.                 volage +=(double)ADC_GetoneValue(ADC_CHANNEL_AD3, ADC_12BIT);        
  53.                 volage = volage/4096.0 ;//因为我们选择了分辨率为12倍的ADC,所以精度为2^12=4096;
  54.                 printf("Volage : %lf \n",volage);               
  55.                 delay_ms(1000);//延时1S效果更好
  56.         }
  57. }

您需要登录后才可以回帖 登录 | 注册

本版积分规则

40

主题

370

帖子

4

粉丝

40

主题

370

帖子

4

粉丝
快速回复 在线客服 返回列表 返回顶部