制作出来实物图如下,使用的是无字库的12864液晶屏:
单片机源码:
- # include<reg52.h>
- # define uchar unsigned char
- # define uint unsigned int
- # define LCD_date P0
- sbit dula = P2^7;
- sbit wela = P2^6;
- sbit lcden = P3^4;
- sbit lcdrs = P3^5;
- sbit lcdwr = P3^6;
- sbit lcdpsb = P3^7;
- uchar *addr;
- uchar code GDcode[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x07,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x3F,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0xFF,0xFF,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x01,0xFF,0xFF,0xF8,0x00,0x00,0x00,0x7F,0x80,0x00,0x00,0x7F,0x80,0x00,0x00,
- 0x00,0x03,0xFF,0xFF,0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,0x87,0xF0,0x00,0x00,0x3F,0x00,0x00,0x00,0xC1,0x80,0x00,0x00,0xE3,0x80,0x00,
- 0x7F,0xC3,0xF8,0x00,0x00,0x3F,0x80,0x00,0x00,0x7F,0x00,0x00,0x00,0x7F,0x00,0x00,
- 0x7B,0x83,0xF0,0x00,0x00,0x3F,0x00,0x00,0x00,0x1C,0x00,0x00,0x00,0x1C,0x00,0x00,
- 0x79,0xC1,0xF0,0x00,0x00,0x27,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x21,0xC0,0x00,0x00,0x00,0x67,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0xE0,0x00,0x00,0x00,0x40,0x07,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
- 0x00,0xE0,0x00,0x00,0x00,0xC0,0x07,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
- 0x00,0x30,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x38,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x9C,0x00,0x00,0x06,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x01,0x07,0x00,0x00,0x0C,0x60,0x07,0xF8,0x00,0x00,0x00,0x01,0xE0,0x00,0x00,0x70,
- 0x01,0x81,0xC0,0x00,0x38,0x10,0x03,0x30,0x00,0x00,0x00,0x03,0x60,0x00,0x00,0x30,
- 0x01,0x00,0xF8,0x00,0xE0,0x10,0x03,0x30,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x30,
- 0x01,0x00,0x03,0xAD,0x00,0x10,0x01,0xE1,0xE3,0xF7,0xF8,0x06,0x01,0xE1,0xE1,0xF0,
- 0x00,0xA0,0x0B,0x0E,0xA2,0xA0,0x01,0xE3,0x31,0xC3,0x30,0x06,0x03,0x33,0x33,0x30,
- 0x00,0x00,0x54,0x00,0x00,0x00,0x01,0xE3,0xF1,0x81,0xE0,0x06,0xF3,0x33,0x33,0x30,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xE3,0x01,0x81,0xE0,0x06,0x63,0x33,0x33,0x30,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC3,0x31,0x80,0xC0,0x03,0x63,0x33,0x33,0x30,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC1,0xE3,0xE0,0xC0,0x01,0xC1,0xE1,0xE1,0xF8,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x80,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
- void delay(uint z)
- {
- uint x,y;
- for (x = z; x > 0; --x)
- for (y = 110; y > 0; --y);
- }
- void write_cmd(uchar cmd)
- {
- lcdrs = 0;
- lcdwr = 0;
- lcden = 0;
- P0 = cmd;
- delay(5);
- lcden = 1;
- delay(5);
- lcden = 0;
- }
- void write_dat(uchar dat)
- {
- lcdrs = 1;
- lcdwr = 0;
- lcden = 0;
- P0 = dat;
- delay(5);
- lcden = 1;
- delay(5);
- lcden = 0;
- }
- void GDlcd_init()
- {
- lcdpsb = 1;
- write_cmd(0x36); //执行时间为72us所以才延时
- delay(10);
- write_cmd(0x01);//4.6ms
- delay(10);
- }
- /*void cle_init()
- {
- uchar m,n;
- write_cmd(0x34);
- for (m = 0; m < 32; ++m)
- {
- write_cmd(0x80+m);
- write_cmd(0x80);
- for (n = 0; n < 16; ++n)
- {
- write_dat(0x00);
- }
- }
- } */
- void dispicture()
- {
- uint i,j;
- //上半屏显示
- for (i = 0; i < 32; ++i)
- {
- write_cmd(0x80+i);
- write_cmd(0x80);
- for (j = 0; j < 16; ++j)
- {
- write_dat(*addr++);
- }
- }
- //下半屏显示
- for (i = 0; i < 32; ++i)
- {
- write_cmd(0x80+i);
- write_cmd(0x88);
- for(j = 0; j < 16; ++j)
- {
- write_dat(*addr++);
- }
- }
- }
- void main()
- {
- dula = 0;
- wela = 0;
- delay(10);
- GDlcd_init();
- // cle_init();
- addr = GDcode;
- dispicture();
- while(1);
- }
复制代码
|