找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 4004|回复: 1
打印 上一主题 下一主题
收起左侧

多路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. }



复制代码


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏1 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:243791 发表于 2018-7-16 22:33 | 只看该作者
谢谢,我收下了
回复

使用道具 举报

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

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表