lcd12864显示基本程序
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
#define lcd_starthang 0XC0 // 起始行
#define lcd_ye 0XB8 // 页指令
#define lcd_lie 0X40 // 列指令
#define RW PE3
#define DI PE2
#define E PE4
#define CS1 PE0
#define CS2 PE1
#define RST PE5
#define lcd_port PORTD //液晶排线
#define lcd_ddr DDRD //输入输出
#define lcd_ctrl PORTE //控制端口
#define lcd_pin PIND //控制状态的数据
#define RW1() lcd_ctrl |=(1<
//延时子函数
void _delay_us(int x)
{
while(x--);
}
void _delay_ms(int x)
{
unsigned char i;
while(x--)
{
for(i=0;i<120;i++);
}
}
//判断总线忙
void LCD_wait_ready()
{
check_busy:
lcd_ddr =0X00; lcd_port=0XFF;//打开全部引脚
RW1();asm ("nop"); DI0();
E1(); asm ("nop"); E0();
if (lcd_pin & 0x80) goto check_busy;
}
//写入命令
void LCD_write_command(uchar dat)
{
LCD_wait_ready();
lcd_ddr =0XFF; lcd_port=0XFF;//打开全部引脚
RW0();asm ("nop");DI0();
lcd_port=dat;
E1();asm ("nop");E0();
}
//写入数据
uchar fxshow=0;
void LCD_write_data(uchar data)
{
LCD_wait_ready();
lcd_ddr =0XFF; lcd_port=0XFF;
RW0();asm ("nop");DI1();
if(!fxshow) lcd_port=data;else lcd_port=~data;
E1();asm ("nop");E0();
}
//初始化
void LCD_chushihua()
{
LCD_write_command(0x3f);_delay_ms(15);
}
//读取数据线
uchar LCD_read()
{
uchar dat;
lcd_ddr =0X00; lcd_port=0XFF;
RW1();asm ("nop"); DI0();
E1(); asm ("nop"); E0();
dat=lcd_pin;
return dat;
}
//显示函数
//y 页,l:列,0-127;j:显示的字节数;r:字节缓冲地址
void LCD_show(uchar y,uchar l,uchar j,const uchar *r)
{
uchar i;
if(l<64)//-------------------------------------
{CS1_1();CS2_0();
LCD_write_command(lcd_ye+y);
LCD_write_command(lcd_lie+l);
if(l+j<64)//------------------
{ for (i=0;i
for (i=0;i<64-l;i++) LCD_write_data(r[i]); //左半屏幕显示
CS1_0();CS2_1();
LCD_write_command(lcd_ye+y);
LCD_write_command(lcd_lie);
for (i=64-l;i
}
else //--------------------------------------l>64;
{CS1_0();CS2_1();
LCD_write_command(lcd_ye+y);
LCD_write_command(lcd_lie+l-64);
for (i=0;i
}
//清屏函数
void LCD_QingPing()
{
uchar i,j;
LCD_write_command(0xae);;
CS1_1();CS2_1();
LCD_write_command(lcd_ye);
LCD_write_command(lcd_lie);
for (i=0;i<8;i++)
{ LCD_write_command(lcd_ye+i);
for(j=0;j<128;j++)
{LCD_write_command(lcd_lie+j);
LCD_write_data(0x00);}
}
LCD_write_command(0x3f);
}
//显示8x16点阵 y:0-2-4-6l:0-64
void LCD_display816(uchar y,uchar l,uchar *r)
{
LCD_show(y, l,8, r );
LCD_show(y+1,l,8,r+8 );
}
//显示多个8x16点阵
void LCD_display8161(uchar y,uchar l,uchar D,uchar *r)
{
uchar i;
for(i=0;i
}
//显示16x16点阵
void LCD_display1616(uchar y,uchar l,uchar *r)
{
LCD_show(y, l,16, r );
LCD_show(y+1,l,16,r+16);
}
//显示多个16x16点阵
void LCD_display16161(uchar y,uchar l,uchar D, uchar *r)
{
uchar i;
for(i=0;i
}