標題: DS18B20在lcd12864液晶屏上顯示 [打印本頁]

作者: 慕邪丶晴楓    時間: 2017-5-11 21:19
標題: 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)





作者: cduhuapu    時間: 2017-12-13 12:57
很好的東東,謝謝啦




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