共2条
1/1 1 跳转至页
16,LCD 分享:2*16字符型LCD程序
问
#include<reg51.h>
//#include <intrins.h>
#define uchar unsigned char
bit bflag;
//sbit LIGHT=P0^4;
sbit P1_0=P1^0;
sbit P1_2=P1^2;
sbit RS=P2^0;//4jiao
sbit RW=P2^1;//5jiao
sbit E=P2^2;//6jiao
void lcd_clear(void); /*清屏*/
void lcd_chekbusy(void); /*测试忙*/
void lcd_wrcmd(uchar lcd_cmd); /*写命令*/
void lcd_wrdata(uchar lcd_data); /*写数据*/
void lcd_moveto(uchar position); /*写要显示的地方*/
//void lcd_cursor ( uchar cursor_cmd ); /*光标控制*/
void lcd_init(void); /*初始化*/
void delay(uchar x)
{
uchar i;
do
{
for(i=0;i<125;i++)
{;}
}
while (x--);
}
void lcd_chekbusy(void)
{
uchar middle;
do
{
RS=0;
RW=1;
E=1;
//delay(10);
middle=P0;
E=0;
bflag=(0x80&middle);
}
while(bflag==1);
bflag=1;
}
void lcd_wrcmd(uchar lcd_cmd)
{
//delay(1);
RS=0;
RW=0;
E=1;
P0=lcd_cmd;
//delay(1);
E=0;
//lcd_chekbusy();
//delay(1);
}
void lcd_wrdata(uchar lcd_data)
{
//lcd_chekbusy();
RS=1;
RW=0;
E=1;
P0=lcd_data;
E=0;
//lcd_chekbusy();
}
void lcd_clear(void)
{
lcd_wrcmd (0x01);
}
void lcd_moveto(uchar position) /*position为从左起算起1--16 */
{
uchar temp_1;
//lcd_chekbusy();
if (position<16)
temp_1=(position+0x80-1);
else
temp_1=((position-16)+0xc0);/////////////////已经修改
lcd_wrcmd(temp_1);
//lcd_chekbusy();
//delay ( 1 );
}
void lcd_wrstr( uchar *pdispstrda ) /* 函数 */
{ uchar i;
lcd_wrcmd(0x80); /*设置显示数据RAM*/
for (i=0;i<=7;i++)
{
lcd_wrdata(*pdispstrda);/* char of LCM */
pdispstrda++;
}
lcd_wrcmd(0xc0); /*设置显示数据RAM*/
for (i=0;i<=7;i++)
{
lcd_wrdata(*pdispstrda);/* char of LCM */
pdispstrda++;
}
}
void lcd_wrchar(uchar lcd_add,uchar lcd_data)
{
lcd_moveto(lcd_add);
lcd_wrdata(lcd_data);
}
void lcd_init(void)
{ uchar i;
delay(20);
for(i=0;i<8;i++)
{ lcd_wrcmd(0x30);
delay(5);
}
//lcd_chekbusy();
lcd_wrcmd(0x38);
lcd_chekbusy();
lcd_wrcmd(0x0c);
lcd_chekbusy();
lcd_wrcmd(0x06);
lcd_chekbusy();
lcd_wrcmd(0x01);
lcd_chekbusy();
}
main()
{
uchar dis_string[16]={"this is a test"};
uchar i,j,k;
k=1;
P0=0xff;
P2=0xff;
P1_2=1;
P1_0=0;
lcd_init();
bee:
lcd_moveto(1);
j='A';
for(i=0;i<16;i++)
{
delay(1);
lcd_wrdata(j);
j++;
};
lcd_wrcmd(0xc0);
for(i=0;i<16;i++)
{
delay(1);
lcd_wrdata(j);
j++;
}
delay(250);
lcd_wrstr(dis_string);
lcd_clear();
delay(1);
lcd_wrchar(3,'G');
delay(1);
lcd_wrdata('O');
delay(1);
lcd_wrdata('O');
delay(1);
lcd_wrdata('D');
P1_2=~P1_2;
goto bee;
} 答 1: 楼主的LCD主控芯片是什么型号啊? 答 2: 应该是通用的1602 lcd吧 答 3: ts1620对不起,各位,忘说了.是内含hd44780的ts1620.
//#include <intrins.h>
#define uchar unsigned char
bit bflag;
//sbit LIGHT=P0^4;
sbit P1_0=P1^0;
sbit P1_2=P1^2;
sbit RS=P2^0;//4jiao
sbit RW=P2^1;//5jiao
sbit E=P2^2;//6jiao
void lcd_clear(void); /*清屏*/
void lcd_chekbusy(void); /*测试忙*/
void lcd_wrcmd(uchar lcd_cmd); /*写命令*/
void lcd_wrdata(uchar lcd_data); /*写数据*/
void lcd_moveto(uchar position); /*写要显示的地方*/
//void lcd_cursor ( uchar cursor_cmd ); /*光标控制*/
void lcd_init(void); /*初始化*/
void delay(uchar x)
{
uchar i;
do
{
for(i=0;i<125;i++)
{;}
}
while (x--);
}
void lcd_chekbusy(void)
{
uchar middle;
do
{
RS=0;
RW=1;
E=1;
//delay(10);
middle=P0;
E=0;
bflag=(0x80&middle);
}
while(bflag==1);
bflag=1;
}
void lcd_wrcmd(uchar lcd_cmd)
{
//delay(1);
RS=0;
RW=0;
E=1;
P0=lcd_cmd;
//delay(1);
E=0;
//lcd_chekbusy();
//delay(1);
}
void lcd_wrdata(uchar lcd_data)
{
//lcd_chekbusy();
RS=1;
RW=0;
E=1;
P0=lcd_data;
E=0;
//lcd_chekbusy();
}
void lcd_clear(void)
{
lcd_wrcmd (0x01);
}
void lcd_moveto(uchar position) /*position为从左起算起1--16 */
{
uchar temp_1;
//lcd_chekbusy();
if (position<16)
temp_1=(position+0x80-1);
else
temp_1=((position-16)+0xc0);/////////////////已经修改
lcd_wrcmd(temp_1);
//lcd_chekbusy();
//delay ( 1 );
}
void lcd_wrstr( uchar *pdispstrda ) /* 函数 */
{ uchar i;
lcd_wrcmd(0x80); /*设置显示数据RAM*/
for (i=0;i<=7;i++)
{
lcd_wrdata(*pdispstrda);/* char of LCM */
pdispstrda++;
}
lcd_wrcmd(0xc0); /*设置显示数据RAM*/
for (i=0;i<=7;i++)
{
lcd_wrdata(*pdispstrda);/* char of LCM */
pdispstrda++;
}
}
void lcd_wrchar(uchar lcd_add,uchar lcd_data)
{
lcd_moveto(lcd_add);
lcd_wrdata(lcd_data);
}
void lcd_init(void)
{ uchar i;
delay(20);
for(i=0;i<8;i++)
{ lcd_wrcmd(0x30);
delay(5);
}
//lcd_chekbusy();
lcd_wrcmd(0x38);
lcd_chekbusy();
lcd_wrcmd(0x0c);
lcd_chekbusy();
lcd_wrcmd(0x06);
lcd_chekbusy();
lcd_wrcmd(0x01);
lcd_chekbusy();
}
main()
{
uchar dis_string[16]={"this is a test"};
uchar i,j,k;
k=1;
P0=0xff;
P2=0xff;
P1_2=1;
P1_0=0;
lcd_init();
bee:
lcd_moveto(1);
j='A';
for(i=0;i<16;i++)
{
delay(1);
lcd_wrdata(j);
j++;
};
lcd_wrcmd(0xc0);
for(i=0;i<16;i++)
{
delay(1);
lcd_wrdata(j);
j++;
}
delay(250);
lcd_wrstr(dis_string);
lcd_clear();
delay(1);
lcd_wrchar(3,'G');
delay(1);
lcd_wrdata('O');
delay(1);
lcd_wrdata('O');
delay(1);
lcd_wrdata('D');
P1_2=~P1_2;
goto bee;
} 答 1: 楼主的LCD主控芯片是什么型号啊? 答 2: 应该是通用的1602 lcd吧 答 3: ts1620对不起,各位,忘说了.是内含hd44780的ts1620.
共2条
1/1 1 跳转至页
回复
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |
打赏帖 | |
---|---|
与电子爱好者谈读图四被打赏50分 | |
与电子爱好者谈读图二被打赏50分 | |
【FRDM-MCXN947评测】Core1适配运行FreeRtos被打赏50分 | |
【FRDM-MCXN947评测】双核调试被打赏50分 | |
【CPKCORRA8D1B评测】---移植CoreMark被打赏50分 | |
【CPKCORRA8D1B评测】---打开硬件定时器被打赏50分 | |
【FRDM-MCXA156评测】4、CAN loopback模式测试被打赏50分 | |
【CPKcorRA8D1评测】--搭建初始环境被打赏50分 | |
【FRDM-MCXA156评测】3、使用FlexIO模拟UART被打赏50分 | |
【FRDM-MCXA156评测】2、rt-thread MCXA156 BSP制作被打赏50分 |