比较牛批的1602液晶程序,通过引号可以直接显示在屏幕上
单片机源程序如下:
- #include "reg52.h"
- sbit rs=P2^0;
- sbit rw=P2^1;
- sbit sn=P2^2;
- #define sjk P0
- void delay_ms(unsigned int q)
- {
- while(q--);
- }
- void Write_instruction_data1602(unsigned char q,w)
- {
- rs=q;
- delay_ms(1);
- sjk=w;
- sn=1;
- delay_ms(1);
- sn=0;
- }
- void liquid1602crystal()
- {
- Write_instruction_data1602(0,0x0c);
- Write_instruction_data1602(0,0x38);
- Write_instruction_data1602(0,0x06);
- Write_instruction_data1602(0,0x80+0x40) ;
- }
- void display_characters1602(bit q,unsigned char w,unsigned char *e)
- {
- if(q==0)
- {
- Write_instruction_data1602(0,0x80+w);
- while(*e!='\0')
- {
- Write_instruction_data1602(1,*e);
- delay_ms(1);
- e++;
- }
- }
- else
- {
- Write_instruction_data1602(0,0x80+0x40+w);
- while(*e!='\0')
- {
- Write_instruction_data1602(1,*e);
- delay_ms(1);
- e++;
- }
- }
- }
- void main()
- {
- rw=0;
- liquid1602crystal();
- display_characters1602(0,0,"2021/7/3 week6");
- display_characters1602(1,0,"20:30:56 27.0C");
- while(1);
- }
复制代码
Keil代码工程:
Keil.7z
(11.52 KB, 下载次数: 6)
|