如圖:
IMG_20181103_132852.jpg (47.68 KB, 下載次數: 33)
下載附件
2018-11-3 14:41 上傳
有背光顯示,第一排顯示黑色方塊
單片機源程序如下:
- /***********************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); //開光標
- }
復制代碼
|