找回密码
 立即注册

QQ登录

只需一步,快速开始

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

msp430单片机AD转换1602显示Proteus仿真+代码

[复制链接]
跳转到指定楼层
楼主
msp430,AD转换1602显示仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)


单片机源程序如下:
  1. /******************************************************************
  2. * 实验名称:LCD1602 显示仿真 (MSP430F249)
  3. *        
  4. * 实验说明:
  5. *     通设置系统主时钟(MCLK=8Mhz ) 、辅助时钟(ACLK=8Mhz )、
  6. *      子系统时钟(SMCLK=8Mhz )
  7. * 编译软件:Embedded Workbench 5.3
  8. *
  9. *仿真软件:proteus7.7 sp 2
  10. ******************************************************************/

  11. #include <MSP430x24x.h>
  12. #include <string.h>
  13. #define uchar unsigned char
  14. #define uint unsigned int

  15. /**************定义接口************************/
  16. #define LCDIO     P1OUT
  17. #define LCD1602_RS_1  P2OUT|=1  
  18. #define LCD1602_RS_0  P2OUT&=~1
  19. #define LCD1602_RW_1  P2OUT|=2
  20. #define LCD1602_RW_0  P2OUT&=~2
  21. #define LCD1602_EN_1   P2OUT|=4
  22. #define LCD1602_EN_0   P2OUT&=~4

  23. /**************定义函数************************/
  24. void LCD_write_command(unsigned char command);//写入指令函数
  25. void LCD_write_dat( unsigned char dat);//写入数据函数
  26. void LCD_set_xy( unsigned char x, unsigned char y );//设置显示位置函数
  27. void LCD_dsp_char( unsigned char x,unsigned char y, char dat);//显示一个字符函数
  28. void LCD_dsp_string(unsigned char X,unsigned char Y,const char *s);//显示字符串函数
  29. void LCD_init(void);//初始化函数
  30. void delay_nms(unsigned int n);//延时函数
  31. /********************************************/
  32. void delayms(uint t)
  33. {
  34.     uint i;
  35.     while(t--)
  36.       for(i=1330;i>0;i--);//进过参数的调整
  37. }
  38. /*******检查忙函数*************/
  39. void LCD_check_busy()      //实践证明,在我的LCD1602上,检查忙指令通过率极低,以
  40. {                                          //至于不能正常使用LCD。因此我没有再用检查忙函数。而使

  41.           P1DIR=0x00;
  42.           LCDIO=0xff;
  43.           LCD1602_RS_0;                 //要用200次循环便能完成。   
  44.           LCD1602_RW_1;
  45.           LCD1602_EN_1;
  46.         while(P1IN&0x80);
  47.         LCD1602_EN_0;
  48.         P1OUT=0x00;
  49.         P1DIR=0xFF;
  50. }
  51. /******************************/

  52. /**************写指令函数********************************/  
  53. void LCD_write_command(unsigned char command)
  54. {
  55.       
  56.         //LCD_check_busy(); //加上这句仿真无法通过
  57.         
  58.         LCD1602_RS_0;   
  59.         LCDIO=command;
  60.         LCD1602_EN_1;
  61.         
  62.         //delayms(1);
  63.         LCD1602_EN_0;
  64.         delayms(1);
  65.   
  66. }
  67. /***************************************************/
  68. /****************写数据函数************************/
  69. void LCD_write_dat( unsigned char dat)
  70. {
  71.       //LCD_check_busy();  //加上这句仿真无法通过
  72.       LCD1602_RS_1;
  73.       LCDIO=dat;
  74.       LCD1602_EN_1;
  75.       
  76.       //delayms(1);
  77.       LCD1602_EN_0;
  78.       delayms(1);
  79.       LCD1602_RS_0;


  80. }
  81. /****************************************************/
  82. /***************设置显示位置**************************/
  83. void LCD_set_xy( unsigned char x, unsigned char y )
  84. {
  85. unsigned char address;
  86. if (y == 1)
  87.      address = 0x80+x;
  88. else if (y == 2)
  89. {
  90.         address=0x80+0x40+x;
  91.         
  92. }
  93. LCD_write_command(address);
  94. }
  95. /***************************************************/
  96. /****************显示一个字符**********************/
  97. void LCD_dsp_char( unsigned char x,unsigned char y, char dat)
  98. {
  99. LCD_set_xy( x, y );
  100. LCD_write_dat(dat);
  101. }
  102. /**********************************************/
  103. /***************显示字符串函数***************/
  104. void LCD_dsp_string(unsigned char X,unsigned char Y,const char *s)
  105. {
  106.        uchar len,List;
  107.        len=strlen(s);
  108.        LCD_set_xy( X, Y );
  109.        for(List=0;List<len;List++)
  110.        //LCD_dsp_char(X+List,Y,s[List]);
  111.        LCD_write_dat(s[List]);
  112.       
  113. }
  114. /***********************************************/
  115. /********** 延时**********************/
  116. void delay_nms(unsigned int n)      
  117. {
  118.        unsigned int i=0,j=0;
  119.        for (i=n;i>0;i--)
  120.        for (j=0;j<10;j++);  
  121. }
  122. /**************************************/
  123. /************初始化函数****************/
  124. void LCD_init(void)
  125. {
  126.       LCD1602_RW_0;
  127.       LCD1602_EN_0;
  128.       //CLEARSCREEN;//clear screen
  129.       LCD_write_command(0x38);//set 8 bit data transmission mode
  130.       delayms(1);
  131.       LCD_write_command(0x38);//set 8 bit data transmission mode
  132.       delayms(1);
  133.       LCD_write_command(0x38);//set 8 bit data transmission mode
  134.       delayms(1);
  135.       LCD_write_command(0x06);//open display (enable lcd display)
  136.       delayms(1);
  137.       LCD_write_command(0x0C);//set lcd first display address
  138.       delayms(1);
  139.       LCD_write_command(0x01);//clear screen
  140.       delayms(1);
  141.       //LCD_write_command(0x80);//clear screen
  142.       //delayms(1);
  143. }
  144. /****************************************************/


  145. void main(void)
  146. {
  147.    
  148.     WDTCTL=WDTPW + WDTHOLD; // 关闭看门狗
  149.     P1DIR=0xFF;            // 设置方向
  150.     P1SEL=0;            // 设置为普通I/O 口
  151.    
  152.     P2DIR=0xFF;            // 设置方向
  153.     P2SEL=0;            // 设置为普通I/O 口
  154.    
  155.     P2OUT=0x00;
  156.     P1OUT=0x00;
  157.     delayms(200);   
  158.     LCD_init();
  159.    
  160.     while(1)
  161.     {
  162.    
  163.      LCD_dsp_string(1,1,"  LCD TEST   ");//在第一行第一列显示"LCD TEST"
  164.      LCD_dsp_string(1,2,"  SUCCSEEE!  ");//在第一行第一列显示"LCD TEST"
  165.      _BIS_SR(LPM0_bits+ GIE);//进入低功耗睡眠模式  
  166.     }

  167.    
  168. }
复制代码

所有资料51hei提供下载:
LCD1602.rar (243.5 KB, 下载次数: 59)


评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

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

使用道具 举报

来自 2#
ID:304785 发表于 2019-5-26 23:53 | 只看该作者
这篇帖子大家千万别下,这根本实现不了AD采集,仅仅是一个液晶的测试程序。强烈建议站长给删掉~!!!!

评分

参与人数 1黑币 +40 收起 理由
admin + 40 回帖助人的奖励!

查看全部评分

回复

使用道具 举报

板凳
ID:547542 发表于 2019-5-26 14:47 | 只看该作者

谢谢楼主分享! ......
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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