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

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



芯片的SCH告诉我们,KEA8有一个ADC接口,是ADC-PTA7这个接口,根据原理图,我们找到具体模块、
 楼主| Mancherstun 发表于 2015-12-27 20:35 | 显示全部楼层


原来是一个光耦三极管(光线传感器),是利用三极管的特性进而实现开关。
看懂了硬件部分,我们进行软件部分的编写:
 楼主| Mancherstun 发表于 2015-12-27 20:36 | 显示全部楼层
  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);
 楼主| Mancherstun 发表于 2015-12-27 20:36 | 显示全部楼层
  1. void GPIO_Cfg(void)
  2. {
  3.                 GPIO_InitTypeDef GPIO_InitStructure;
  4.         GPIO_InitStructure.GPIOx = PTC;  
  5.         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  6.         GPIO_InitStructure.GPIO_Pin = PTC1|PTC2;  
  7.         GPIO_InitStructure.GPIO_InitState = Bit_RESET;
  8.         GPIO_Init(&GPIO_InitStructure);
  9. }
  10. void UART_Cfg(void)
  11. {
  12.         UART_InitTypeDef UART_InitStruct;
  13.         UART_InitStruct.UART_BaudRate = 115200;
  14.         UART_InitStruct.UART_WordLength = UART_WordLength_8b ;  
  15.         UART_InitStruct.UART_StopBits = UART_StopBits_1;      
  16.         UART_InitStruct.UART_Parity = UART_Parity_No;         
  17.         UART_InitStruct.UART_Mode = UART_Mode_Rx|UART_Mode_Tx;
  18.         UART_InitStruct.UART_PIN = RX_PTB0_TX_PTB1 ;         
  19.         UART_Init(&UART_InitStruct);                     
  20.         UART_ITConfig(UART_IT_RXNE, ENABLE);            
  21.         NVIC_Init(UART0_IRQn,1);
  22. }
 楼主| Mancherstun 发表于 2015-12-27 20:37 | 显示全部楼层
  1. void PIT_Cfg(void)
  2. {
  3.         PIT_InitTypeDef  PIT_InitStruct;
  4.         PIT_InitStruct.CHANNELx = PIT_CHANNEL0;
  5.         PIT_InitStruct.PIT_Mode = PIT_Mode_ms;  
  6.         PIT_InitStruct.Timer = 1000;           
  7.         PIT_Init(&PIT_InitStruct);            
  8.         PIT_ITConfig(PIT_CHANNEL0,ENABLE);     
  9.         PIT_ClearFlag(PIT_CHANNEL0);         
  10.         PIT_Cmd(PIT_CHANNEL0,ENABLE);         
  11.         NVIC_Init(PIT_CH0_IRQn,1);   
  12. }
 楼主| Mancherstun 发表于 2015-12-27 20:37 | 显示全部楼层
  1. int main()
  2. {
  3.         double volage= 0;
  4.         int i=0 ;
  5.         SystemCoreClockUpdate();         
  6.         for(;;)
  7.         {
  8.                 volage = 0;
  9.                 for(i =0 ;i<10 ; i++)
  10.                 volage +=(double)ADC_GetoneValue(ADC_CHANNEL_AD3, ADC_12BIT);      
  11.                 volage = volage/4096.0 ;//因为我们选择了分辨率为12倍的ADC,所以精度为2^12=4096;
  12.                 printf("Volage : %lf \n",volage);               
  13.                 delay_ms(1000);//延时1S效果更好
  14.         }
  15. }
您需要登录后才可以回帖 登录 | 注册

本版积分规则

35

主题

294

帖子

2

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

35

主题

294

帖子

2

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