本帖最后由 学电子 于 2013-3-18 09:43 编辑
以下是我的程序。其中遇到了一点问题,请高手帮帮忙,指点指点。
#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
#define LCD_data P0
sbit wela=P2^7;
sbit dula=P2^6;
sbit LCD_EN=P3^4;
sbit LCD_RS=P3^5;
sbit LCD_RW=P3^6;
sbit LCD_PSB=P3^7;
uchar code num1[]={0x00,0x00,0x00,0x38,0x00,0x78,0x00,0xF8,0x01,0xF8,0x01,0xF8,0x00,0x78,0x00,0x78,
0x00,0x78,0x00,0x78,0x00,0x78,0x00,0x78,0x00,0x78,0x00,0x78,0x00,0x78,0x00,0x78,
0x00,0x78,0x00,0x78,0x00,0x78,0x00,0x78,0x00,0x78,0x00,0x78,0x00,0x78,0x00,0x78,
0x00,0x78,0x00,0x78,0x00,0x78,0x00,0x78,0x00,0x78,0x00,0x78,0x00,0x78,0x00,0x00};
/***************************************************************
以下是关于12864的子程序
***************************************************************/
void delay(uint z) //延时函数
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void check_lcd_busy() //忙检测
{
LCD_RS=0;
LCD_RW=1;
LCD_EN=1;
LCD_data=0xff;
while((LCD_data&0x80)==0x80);
LCD_EN=0;
}
void write_cmd(uchar cmd) //12864写指令
{
check_lcd_busy();
LCD_RS=0;
LCD_RW=0;
LCD_EN=0;
P0=cmd;
delay(5);
LCD_EN=1;
delay(5);
LCD_EN=0;
}
void write_dat(uchar dat) //12864写数据
{
check_lcd_busy();
LCD_RS=1;
LCD_RW=0;
LCD_EN=0;
P0=dat;
delay(5);
LCD_EN=1;
delay(5);
LCD_EN=0;
}
void clear_GDRAM() //清除GDRAM,防止花屏
{
uchar i,j;
write_cmd(0x34);
write_cmd(0x30);
write_cmd(0x0c);
write_cmd(0x06);
write_cmd(0x34);
for(j=0;j<32;j++)
{
write_cmd(0x80+j);
write_cmd(0x80);
for(i=0;i<16;i++)
{
write_dat(0x00);
write_dat(0x00);
}
}
}
void display_bmp(uchar x,uchar *bmp) //显示16*32的数字
{
uchar i,j,X;
X=0x80+x;
write_cmd(0x36);
for(i=0;i<16;i++)
{
write_cmd(0x90+i);
write_cmd(X);
for(j=0;j<2;j++)
write_dat(*bmp++);
}
for(i=0;i<16;i++)
{
write_cmd(0x80+i);
write_cmd(X+8);
for(j=0;j<2;j++)
write_dat(*bmp++);
}
write_cmd(0x36);
}
void lcd_init() //12864初始化
{
LCD_PSB=1;
write_cmd(0x30);
write_cmd(0x0c);
write_cmd(0x01);
write_cmd(0x06);
}
/***************************************************************
以下是主函数
***************************************************************/
void main()
{
wela=0;
dula=0;
delay(10);
lcd_init();
clear_GDRAM(); //如果把这句代码取消,屏幕显示花屏。但是如果加上这句,显示的特别慢。why????
while(1)
{
display_bmp(0,num1);
display_bmp(1,num1);
display_bmp(2,num1);
display_bmp(3,num1);
display_bmp(4,num1);
display_bmp(5,num1);
display_bmp(6,num1);
display_bmp(7,num1);
}
}
额,请你把意思说明白
一周热门 更多>