欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

標題: 多路ADC轉換-模擬串口發送 STC15系列庫函數與例程 [打印本頁]

作者: 王中心    時間: 2017-3-4 19:59
標題: 多路ADC轉換-模擬串口發送 STC15系列庫函數與例程
STC15系列庫函數與例程   03-多路ADC轉換-模擬串口發送

完整的源碼下載:
01-IO-跑馬燈.rar (26.46 KB, 下載次數: 27)

03-多路ADC轉換-模擬串口發送.rar (30.86 KB, 下載次數: 84)


主程序預覽:

  1. /*------------------------------------------------------------------*/
  2. /* --- STC MCU International Limited -------------------------------*/
  3. /* --- STC 1T Series MCU RC Demo -----------------------------------*/
  4. /* --- Mobile: (86)13922805190 -------------------------------------*/
  5. /* --- Fax: 86-0513-55012956,55012947,55012969 ---------------------*/
  6. /* --- Tel: 86-0513-55012928,55012929,55012966 ---------------------*/
  7. /* If you want to use the program or the program referenced in the  */
  8. /* article, please specify in which data and procedures from STC    */
  9. /*------------------------------------------------------------------*/


  10. #include        "config.h"
  11. #include        "GPIO.h"
  12. #include        "delay.h"

  13. /*************        功能說明        **************

  14. 本程序演示跑馬燈。
  15. 程序使用P2口來演示,輸出低驅動。用戶可以修改為別的口。

  16. ******************************************/

  17. /*************        本地常量聲明        **************/


  18. /*************        本地變量聲明        **************/


  19. /*************        本地函數聲明        **************/



  20. /*************  外部函數和變量聲明 *****************/



  21. /******************** IO配置函數 **************************/
  22. void        GPIO_config(void)
  23. {
  24.         GPIO_InitTypeDef        GPIO_InitStructure;                //結構定義
  25.         GPIO_InitStructure.Pin  = GPIO_Pin_All;                //指定要初始化的IO, GPIO_Pin_0 ~ GPIO_Pin_7, 或操作
  26.         GPIO_InitStructure.Mode = GPIO_OUT_PP;                //指定IO的輸入或輸出方式,GPIO_PullUp,GPIO_HighZ,GPIO_OUT_OD,GPIO_OUT_PP
  27.         GPIO_Inilize(GPIO_P2,&GPIO_InitStructure);        //初始化
  28. }



  29. /******************** 主函數 **************************/
  30. void main(void)
  31. {
  32.         u8        i,tmp;
  33.        
  34.         GPIO_config();
  35.        
  36.         while(1)
  37.         {
  38.                 tmp = 1;
  39.                 for(i=0; i<8; i++)
  40.                 {
  41.                         P2 = ~tmp;
  42.                         tmp <<= 1;
  43.                         delay_ms(250);
  44.                 }

  45.                 tmp = 0x80;
  46.                 for(i=0; i<8; i++)
  47.                 {
  48.                         P2 = ~tmp;
  49.                         tmp >>= 1;
  50.                         delay_ms(250);
  51.                 }
  52.         }
  53. }
復制代碼


  1. /*------------------------------------------------------------------*/
  2. /* --- STC MCU International Limited -------------------------------*/
  3. /* --- STC 1T Series MCU RC Demo -----------------------------------*/
  4. /* --- Mobile: (86)13922805190 -------------------------------------*/
  5. /* --- Fax: 86-0513-55012956,55012947,55012969 ---------------------*/
  6. /* --- Tel: 86-0513-55012928,55012929,55012966 ---------------------*/
  7. /* If you want to use the program or the program referenced in the  */
  8. /* article, please specify in which data and procedures from STC    */
  9. /*------------------------------------------------------------------*/

  10. #include        "config.h"
  11. #include        "adc.h"
  12. #include        "delay.h"
  13. #include        "soft_uart.h"


  14. /*************        功能說明        **************

  15. 本程序演示多路ADC查詢采樣,通過模擬串口發送給上位機,波特率9600,8,n,1。
  16. 用戶可以修改為1~8路的ADC轉換。

  17. ******************************************/

  18. /*************        本地常量聲明        **************/


  19. /*************        本地變量聲明        **************/


  20. /*************        本地函數聲明        **************/



  21. /*************  外部函數和變量聲明 *****************/


  22. void        ADC_config(void)
  23. {
  24.         ADC_InitTypeDef                ADC_InitStructure;                                //結構定義
  25.         ADC_InitStructure.ADC_Px        = ADC_P10 | ADC_P11 | ADC_P12;        //設置要做ADC的IO,        ADC_P10 ~ ADC_P17(或操作),ADC_P1_All
  26.         ADC_InitStructure.ADC_Speed     = ADC_360T;                        //ADC速度                        ADC_90T,ADC_180T,ADC_360T,ADC_540T
  27.         ADC_InitStructure.ADC_Power     = ENABLE;                        //ADC功率允許/關閉        ENABLE,DISABLE
  28.         ADC_InitStructure.ADC_AdjResult = ADC_RES_H8L2;                //ADC結果調整,        ADC_RES_H2L8,ADC_RES_H8L2
  29.         ADC_InitStructure.ADC_Polity    = PolityLow;                //優先級設置        PolityHigh,PolityLow
  30.         ADC_InitStructure.ADC_Interrupt = DISABLE;                        //中斷允許                ENABLE,DISABLE
  31.         ADC_Inilize(&ADC_InitStructure);                                        //初始化
  32.         ADC_PowerControl(ENABLE);                                                        //單獨的ADC電源操作函數, ENABLE或DISABLE
  33. }



  34. /**********************************************/
  35. void main(void)
  36. {
  37.         u8        i;
  38.         u16        j;

  39.         ADC_config();

  40.         while (1)
  41.         {

  42.                 for(i=0; i<3; i++)
  43.                 {
  44.                         delay_ms(250);

  45.                 //        Get_ADC10bitResult(i);                //參數0~7,查詢方式做一次ADC, 丟棄一次
  46.                         j = Get_ADC10bitResult(i);        //參數0~7,查詢方式做一次ADC, 返回值就是結果, == 1024 為錯誤
  47.                         TxSend('A');
  48.                         TxSend('D');
  49.                         TxSend(i+'0');
  50.                         TxSend('=');
  51.                         TxSend(j/1000 + '0');
  52.                         TxSend(j%1000/100 + '0');
  53.                         TxSend(j%100/10 + '0');
  54.                         TxSend(j%10 + '0');
  55.                         TxSend(' ');
  56.                         TxSend(' ');
  57.                 }
  58.                 PrintString("\r\n");
  59.         }
  60. }



復制代碼



作者: a1075511750    時間: 2018-7-16 22:33
謝謝,我收下了




歡迎光臨 (http://www.raoushi.com/bbs/) Powered by Discuz! X3.1