|
單片機C語言實例-187-lcd-12864應用
#define uchar unsigned char
#define uint unsigned int
sbit p3_0=P3^0;
sbit p3_1=P3^1;
sbit p3_2=P3^2;
sbit p3_3=P3^3;
sbit p3_4=P3^4;
sbit p3_5=P3^5;
sbit p2_7=P2^7;
#define LCD_RW p3_1
#define LCD_DI p3_2
#define LCD_E p3_0
#define LCD_CS1 p3_4
#define LCD_CS2 p3_3
#define LCD_RES p3_5
#define LCD_BUSY p2_7
#define LCDPORT P2
#define LCDSTARTROW 0xC0
delay_ms(int ms)
{uchar i;
uint j;
for(j=2*ms;j>0;j--)
for(i=250;i>0;i--);
}
bit ChechBusy()
{
LCDPORT=0xFF;
LCD_RW=1;
LCD_DI=0;
LCD_E=1;
LCD_E=0;
return LCD_BUSY;
}
void write_cmd(uchar cmd)
{
while(ChechBusy());
LCD_E=0;
LCD_RW=0;
LCD_DI=0;
LCDPORT=cmd;
LCD_E=1;
LCD_E=0;
}
void write_data(uchar d)
{
while(ChechBusy());
LCD_E=0;
LCD_RW=0;
LCD_DI=1;
LCDPORT=d;
LCD_E=1;
LCD_E=0;
}
void LCD_init()
{
LCD_CS1=1;
LCD_CS2=1;
write_cmd(0x3F); //開顯示。
write_cmd(LCDSTARTROW); //設(shè)置起始行。
}
void main()
{
int i,j;
uchar u, *p=encoding_01;
LCD_init();
LCD_CS1=1;
LCD_CS2=1;
P1=0;
for (i=0;i<64;i++)
{ write_cmd(0xb9);
write_data(encoding_00);
}
write_cmd(0x40);
for (i=0;i<64;i++)
{ write_cmd(0xba);
write_data(encoding_00>>8);
}
LCD_CS1=0;
LCD_CS2=1;
for (i=0;i<64*8;i++)
{
u=0xb8+(7-i%8);
write_cmd(u);
u=0x40+i/8;
write_cmd(u);
u=*((uchar *)encoding_01+i);
write_data(u);
}
for (u=0;u<64;u++)
{
write_cmd(0xc0+u);
delay_ms(500);
}
while(1);
}
更多詳情參考附件文檔
+08:00C307聯(lián)盟網(wǎng)5529.png (30.9 KB, 下載次數(shù): 2)
下載附件
保存到相冊
2022-2-15 14:22 上傳
|
|