标题: Nokia 5110_DS18B20显示程序 [打印本页]

作者: 51黑科技    时间: 2016-2-2 02:55
标题: Nokia 5110_DS18B20显示程序


  1. /**********Nokia 5110 LCD 显示程序***************/
  2. /**********作者:郑文             ***************/
  3. /**********芯片:AT89S52          **************/
  4. /*功能:支持中文显示、字符显示、图片显示********/
  5. #include <reg52.h>
  6. #include <intrins.h>
  7. #include "english_6x8_pixel.h"
  8. #include "picture84x48.h"
  9. #include "Nokia_5110.h"
  10. #include "18b20.h"

  11. #define uchar unsigned char
  12. #define uint  unsigned int

  13. uchar  tem_h,tem_l,tem_f,tem_f1,tem_f2;
  14. uint   tem;         //温度读取后*10后存储空间地址
  15. float  tem_read;    //温度读取保存地址空间

  16. void Delay1ms(unsigned int count);
  17. void  temperature_read_charge(void);
  18. void nokia_5110_picture();//写一屏图


  19. /************毫秒延时程序********************/
  20. void Delay1ms(unsigned int count)
  21. {
  22. unsigned int i,j;
  23. for(i=0;i<count;i++)
  24. for(j=0;j<120;j++);
  25. }
  26. /********************************************/
  27. /*void  temperature_read_charge(void)
  28. {

  29.     tem_read=ReadTemperature();  
  30.     tem=tem_read*1000;             //温度精确到小数点后3位
  31.     tem_h=tem/10000+0x30;     //温度高位
  32.     tem_l=( tem-(tem_h-0x30)*10000 )/1000+0x30; //温度低位
  33.     tem_f=( tem-(tem_h-0x30)*10000-(tem_l-0x30)*1000 )/100+0x30;
  34.     tem_f1=( tem-(tem_h-0x30)*10000-(tem_l-0x30)*1000-(tem_f-0x30)*100 )/10+0x30;
  35.     tem_f2=( tem-(tem_h-0x30)*10000-(tem_l-0x30)*1000-(tem_f-0x30)*100-(tem_f1-0x30)*10 )+0x30;
  36.     Delay1ms(100);
  37. }
  38. */


  39. /**********************************************/
  40. void nokia_5110_picture()//写一屏图
  41. {
  42. uchar e;
  43. uchar t;
  44. uchar k;
  45. uint d;
  46.    d=0;
  47.    for(t=0;t<6;t++)
  48.     {
  49.       for(k=0;k<84;k++)
  50.       {
  51.     e=dal[d];
  52.        write_byte(e,1);
  53.        d=d+1;
  54.       }
  55.     }
  56. }
  57. /**************************************/

  58. /*****************主程序********************/
  59. void main(void)
  60. {
  61.        unsigned main_i,x,y;
  62.         unsigned xnum ,ynum;
  63.       float T_temp;
  64.    uchar i;
  65.    uchar moni_temp;

  66.         P2=0X00;
  67.   LED_A =1;
  68.         LCD_VDD   =1;
  69.         LCD_GND   =0;
  70. LCD_Init(); //初始化液晶
  71. LCD_Clear();


  72.       /***********指定地址显示汉字(x,y,table)*********************/
  73.       
  74.        /***********取点(x,y,byte数据)*************/
  75.        /*其中X=[0,83] Y=[0,5] byte 显示是从下到上 */

  76.     nokia_5110_picture();
  77. LCD_set_XY(42,3);
  78. LCD_write_char(124);
  79. LCD_write_char('C');




  80. /* while(1)
  81.   {
  82.    for(i=0;i<8;i++)
  83.    {
  84.    LCD_set_XY(68,4);
  85. LCD_write_char(125+i);
  86.   Delay1ms(100);
  87. }
  88.   for(i=0;i<8;i++)
  89.    {
  90.    LCD_set_XY(68,3);
  91. LCD_write_char(125+i);
  92.   Delay1ms(100);
  93. }
  94. for(i=0;i<8;i++)
  95.    {
  96.    LCD_set_XY(68,2);
  97. LCD_write_char(125+i);
  98.   Delay1ms(100);
  99. }
  100.     for(i=0;i<8;i++)
  101.    {
  102.     LCD_set_XY(68,1);
  103. LCD_write_char(125+i);
  104.   Delay1ms(100);
  105. }
  106. for(i=0;i<8;i++)
  107.    {
  108.     LCD_set_XY(68,0);
  109. LCD_write_char(125+i);
  110.   Delay1ms(100);
  111. }

  112. LCD_set_XY(68,0);
  113. LCD_write_char(125);
  114. LCD_set_XY(68,1);
  115. LCD_write_char(125);
  116. LCD_set_XY(68,2);
  117. LCD_write_char(125);
  118. LCD_set_XY(68,3);
  119. LCD_write_char(125);
  120. LCD_set_XY(68,4);
  121. LCD_write_char(125);



  122.   }*/

  123. while(1)
  124. {
  125.    /********温度数据的读取和转换*************/
  126.     tem_read=ReadTemperature();  
  127.     tem=tem_read*1000;             //温度精确到小数点后一位08.1.8
  128.     tem_h=tem/10000+0x30;     //温度高位
  129.     tem_l=( tem-(tem_h-0x30)*10000 )/1000+0x30; //温度低位
  130.     tem_f=( tem-(tem_h-0x30)*10000-(tem_l-0x30)*1000 )/100+0x30;
  131.     tem_f1=( tem-(tem_h-0x30)*10000-(tem_l-0x30)*1000-(tem_f-0x30)*100 )/10+0x30;
  132.     tem_f2=( tem-(tem_h-0x30)*10000-(tem_l-0x30)*1000-(tem_f-0x30)*100-(tem_f1-0x30)*10 )+0x30;

  133. //Delay1ms(5);
  134.   LCD_set_XY(12,3);
  135.   LCD_write_char(tem_h);
  136. // Delay1ms(5);
  137.   LCD_write_char(tem_l);
  138. // Delay1ms(5);
  139.   LCD_write_char('.');
  140. // Delay1ms(5);
  141.   LCD_write_char(tem_f);
  142. // Delay1ms(5);
  143.   LCD_write_char(tem_f1);
  144.   //Delay1ms(5);

  145.   moni_temp=((tem_h-0x30)*10+tem_l-0x30)+1;//加1是修正值

  146. if(moni_temp>0 && moni_temp<8)
  147. {


  148.    LCD_set_XY(68,3);
  149.   LCD_write_char(125);
  150.   LCD_set_XY(68,2);
  151.   LCD_write_char(125);
  152.   LCD_set_XY(68,1);
  153.   LCD_write_char(125);
  154.   LCD_set_XY(68,0);
  155.   LCD_write_char(125);

  156.      LCD_set_XY(68,4);
  157.   LCD_write_char(125+moni_temp);
  158. }
  159.     else if(moni_temp>=8 && moni_temp<16)
  160. {
  161.   LCD_set_XY(68,2);
  162.   LCD_write_char(125);
  163.   LCD_set_XY(68,1);
  164.   LCD_write_char(125);
  165.   LCD_set_XY(68,0);
  166.   LCD_write_char(125);

  167.   LCD_set_XY(68,4);
  168.   LCD_write_char(132);
  169.   LCD_set_XY(68,3);
  170.   LCD_write_char(125+moni_temp-8);
  171. }
  172.   else if(moni_temp>=16 && moni_temp<24)
  173. {
  174.   LCD_set_XY(68,1);
  175.   LCD_write_char(125);
  176.   LCD_set_XY(68,0);
  177.   LCD_write_char(125);

  178.   LCD_set_XY(68,4);
  179.   LCD_write_char(132);
  180.    LCD_set_XY(68,3);
  181.   LCD_write_char(132);
  182.   LCD_set_XY(68,2);
  183.   LCD_write_char(125+moni_temp-16);
  184. }
  185. else if(moni_temp>=24 && moni_temp<32)
  186. {
  187.   LCD_set_XY(68,0);
  188.   LCD_write_char(125);

  189.   LCD_set_XY(68,4);
  190.   LCD_write_char(132);
  191.    LCD_set_XY(68,3);
  192.   LCD_write_char(132);
  193.   LCD_set_XY(68,2);
  194.   LCD_write_char(132);

  195.   LCD_set_XY(68,1);
  196.   LCD_write_char(125+moni_temp-24);
  197. }
  198. else if(moni_temp>=32 && moni_temp<40)
  199. {
  200.   LCD_set_XY(68,4);
  201.   LCD_write_char(132);
  202.    LCD_set_XY(68,3);
  203.   LCD_write_char(132);
  204.   LCD_set_XY(68,2);
  205.   LCD_write_char(132);
  206.   LCD_set_XY(68,1);
  207.   LCD_write_char(132);

  208.      LCD_set_XY(68,0);
  209.   LCD_write_char(125+moni_temp-32);
  210. }
  211. else
  212. {;}


  213. }
  214.       
  215. }
复制代码




作者: 爱玩单片机    时间: 2016-3-11 14:57
有大神测试过吗




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1