如图:
有背光显示,第一排显示黑色方块
单片机源程序如下:
- /***********************lcd1602写命令函数************************/
- void write_com(uchar com)
- {
- e=0;
- rs=0;
- rw=0;
- P0=com;
- delay_uint(3);
- e=1;
- delay_uint(25);
- e=0;
- }
- /***********************lcd1602写数据函数************************/
- void write_data(uchar dat)
- {
- e=0;
- rs=1;
- rw=0;
- P0=dat;
- delay_uint(3);
- e=1;
- delay_uint(25);
- e=0;
- }
- /*********************光标控制***********************/
- void lcd1602_guanbiao(uchar open_off,uchar add)
- {
- if(open_off == 1) //开光标
- {
- write_com(0x80+add); //将光标移动到秒个位
- write_com(0x0f); //显示光标并且闪烁
- }
- else
- {
- write_com(0x0c); //关光标
- }
- }
- /***********************lcd1602上显示两位十进制数************************/
- void write_sfm2(uchar hang,uchar add,uchar date)
- {
- uchar shi,ge;
- if(hang==1)
- write_com(0x80+add);
- else
- write_com(0x80+0x40+add);
- shi=date%100/10;
- ge=date%10;
- write_data(0x30+shi);
- write_data(0x30+ge);
- }
- /***********************lcd1602上显示这字符函数************************/
- void write_string(uchar hang,uchar add,uchar *p)
- {
- if(hang==1)
- write_com(0x80+add);
- else
- write_com(0x80+0x40+add);
- while(1)
- {
- if(*p == '\0') break;
- write_data(*p);
- p++;
- delay_uint(50);
- }
- }
- /***********************lcd1602初始化设置************************/
- void init_1602()
- {
- write_com(0x38); //
- write_com(0x0c);
- write_com(0x06);
- delay_uint(1000);
- write_string(1,0," Password Lock ");
- write_string(2,0," Input: ");
- lcd1602_guanbiao(1,7+0x40); //开光标
- }
复制代码
|