标题: STC15单片机1602液晶屏比较方便输出字符程序 [打印本页]

作者: 保持微笑    时间: 2021-11-10 10:57
标题: STC15单片机1602液晶屏比较方便输出字符程序
比较牛批的1602液晶程序,通过引号可以直接显示在屏幕上

单片机源程序如下:
  1. #include "reg52.h"
  2. sbit rs=P2^0;  
  3. sbit rw=P2^1;
  4. sbit sn=P2^2;
  5. #define sjk P0
  6. void delay_ms(unsigned int q)
  7. {
  8.                         while(q--);
  9. }
  10. void Write_instruction_data1602(unsigned char q,w)
  11. {
  12.                         rs=q;
  13.                         delay_ms(1);
  14.                         sjk=w;
  15.                         sn=1;
  16.                         delay_ms(1);
  17.                         sn=0;
  18. }
  19. void liquid1602crystal()
  20. {
  21.                         Write_instruction_data1602(0,0x0c);
  22.                         Write_instruction_data1602(0,0x38);
  23.                         Write_instruction_data1602(0,0x06);
  24.                         Write_instruction_data1602(0,0x80+0x40) ;
  25. }
  26. void display_characters1602(bit q,unsigned char w,unsigned char *e)
  27. {
  28.                         if(q==0)
  29.         {
  30.                         Write_instruction_data1602(0,0x80+w);
  31.                         while(*e!='\0')
  32.                 {
  33.                         Write_instruction_data1602(1,*e);
  34.                         delay_ms(1);
  35.                         e++;
  36.                 }
  37.         }
  38.                         else
  39.         {
  40.                         Write_instruction_data1602(0,0x80+0x40+w);
  41.                         while(*e!='\0')
  42.                 {
  43.                         Write_instruction_data1602(1,*e);
  44.                         delay_ms(1);
  45.                         e++;
  46.                 }
  47.         }
  48. }
  49. void main()
  50. {
  51.                         rw=0;
  52.                         liquid1602crystal();
  53.                         display_characters1602(0,0,"2021/7/3 week6");
  54.                         display_characters1602(1,0,"20:30:56  27.0C");
  55.                         while(1);
  56. }
复制代码

Keil代码工程: Keil.7z (11.52 KB, 下载次数: 6)





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