比較牛批的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)
2021-11-10 17:33 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|