找回密码
 立即注册

QQ登录

只需一步,快速开始

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

DS18B20在lcd12864液晶屏上显示

[复制链接]
跳转到指定楼层
楼主
本程序分为DS18B20、头文件、12864液晶和主程序四个部分


单片机源程序如下:
  1. //*************************************************************************
  2. //                        初始化IO口子程序
  3. //*************************************************************************
  4. void Port_init()
  5. {

  6.   P4SEL = 0x00;
  7.   P4DIR = 0xFF;
  8.   P5SEL = 0x00;
  9.   P5DIR|= BIT0 + BIT1 + BIT5 + BIT6 + BIT7;
  10.   PSB_SET;                  //液晶并口方式
  11.   RST_SET;
  12. }

  13. //***********************************************************************
  14. //        显示屏命令写入函数
  15. //***********************************************************************
  16. void LCD_write_com(unsigned char com)
  17. {       
  18.   RS_CLR;
  19.   RW_CLR;
  20.   EN_SET;
  21.   DataPort = com;
  22.   delay_ms(5);
  23.   EN_CLR;
  24. }

  25. //***********************************************************************
  26. //        显示屏数据写入函数
  27. //***********************************************************************
  28. void LCD_write_data(unsigned char data)
  29. {
  30.   RS_SET;
  31.   RW_CLR;
  32.   EN_SET;
  33.   DataPort = data;
  34.   delay_ms(5);
  35.   EN_CLR;
  36. }

  37. //***********************************************************************
  38. //        显示屏清空显示
  39. //***********************************************************************

  40. void LCD_clear(void)
  41. {
  42.   LCD_write_com(0x01);
  43.   delay_ms(5);
  44. }

  45. //***********************************************************************
  46. //函数名称:DisplayCgrom(uchar hz)显示CGROM里的汉字
  47. //***********************************************************************
  48. void DisplayCgrom(uchar addr,uchar *hz)
  49. {
  50.   LCD_write_com(addr);
  51.   delay_ms(5);
  52.   while(*hz != '\0')  
  53.   {
  54.     LCD_write_data(*hz);
  55.     hz++;
  56.     delay_ms(5);
  57.   }

  58. }

  59. //***********************************************************************
  60. //        显示屏单字符写入函数
  61. //***********************************************************************
  62. void LCD_write_char(unsigned char x,unsigned char y,unsigned char data)
  63. {
  64.        
  65.     if (y == 0)
  66.     {
  67.             LCD_write_com(0x80 + x);        //第一行显示
  68.     }
  69.     if(y == 1)
  70.     {
  71.             LCD_write_com(0x90 + x);        //第二行显示
  72.     }
  73.     if (y == 2)
  74.     {
  75.             LCD_write_com(0x88 + x);        //第三行显示
  76.     }
  77.     if(y == 3)
  78.     {
  79.             LCD_write_com(0x98 + x);        //第四行显示
  80.     }
  81.     delay_ms(1);
  82.     LCD_write_data(data);
  83.     delay_ms(1);
  84. }

  85. //***********************************************************************
  86. //        显示屏字符串写入函数
  87. //***********************************************************************
  88. void LCD_write_str(unsigned char x,unsigned char y,unsigned char *s)
  89. {
  90.        
  91.     if (y == 0)
  92.     {
  93.             LCD_write_com(0x80 + x);        //第一行显示
  94.     }
  95.     if(y == 1)
  96.     {
  97.             LCD_write_com(0x90 + x);        //第二行显示
  98.     }
  99.     if (y == 2)
  100.     {
  101.             LCD_write_com(0x88 + x);        //第三行显示
  102.     }
  103.     if(y == 3)
  104.     {
  105.             LCD_write_com(0x98 + x);        //第四行显示
  106.     }
  107.     delay_ms(2);
  108.     while (*s)
  109.     {
  110.             LCD_write_data( *s);
  111.         delay_ms(2);
  112.             s ++;
  113.     }
  114. }

  115. //***********************************************************************
  116. //        显示屏初始化函数
  117. //***********************************************************************
  118. void LCD_init(void)
  119. {
  120.   LCD_write_com(FUN_MODE);                        //显示模式设置
  121.   delay_ms(5);
  122.   LCD_write_com(FUN_MODE);                        //显示模式设置
  123.   delay_ms(5);
  124.   LCD_write_com(CURSE_DIR);                        //显示模式设置
  125.   delay_ms(5);
  126.   LCD_write_com(DISPLAY_ON);                        //显示开
  127.   delay_ms(5);
  128.   LCD_write_com(CLEAR_SCREEN);                        //清屏
  129.   delay_ms(5);
  130. }

  131. //***********************************************************************
  132. //      液晶显示界面初始化
  133. //***********************************************************************
  134. void LCD_Desk(void)
  135. {   


  136. …………限于本文篇幅 余下代码请从51黑下载附件…………


复制代码

完整资料打包下载:
DS18B20_12864.zip (63.25 KB, 下载次数: 90)




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

使用道具 举报

沙发
ID:261045 发表于 2017-12-13 12:57 | 只看该作者
很好的东东,谢谢啦
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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