本文目录一览:
怎样用C语言程序让单片机外接设备LCD液晶屏进入休眠状态
//使液晶进入休眠其实就是关闭液晶显示,比如1602,发送08这个命令就可以了。
#define LCD1602_FLAG
#define LCD1602_PORT P1
#includereg52.h
#includestddef.h
#include"dtype.h"
sbit lcd1602_rs=P3^7;
sbit lcd1602_e=P3^5;
sbit lcd1602_rw=P3^6;
sbit lcd1602_busy=P1^7;
sbit keydis=P3^0;
sbit keyno=P3^1;
/*
************************************
* 函数名称:lcd1602_CheckBusy()
* 函数功能:状态查询
************************************
*/
void lcd1602_CheckBusy()
{
do
{
lcd1602_busy=1;
lcd1602_rs=0;
lcd1602_rw=1;
lcd1602_e=0;
lcd1602_e=1;
}
while(lcd1602_busy);
}
/*
***************************************
* 函数名称: lcd1602_WriteCmd()
* 函数功能:写命令
***************************************
*/
void lcd1602_WriteCmd(const INT8U cmd)
{
lcd1602_CheckBusy();
lcd1602_rs=0;
lcd1602_rw=0;
lcd1602_e=1;
LCD1602_PORT=cmd;
lcd1602_e=0;
}
/*
*******************************************
* 函数名称:lcd1602_WriteData()
* 函数功能:写数据
*********************************************
*/
void lcd1602_WriteData(const INT8U c)
{
lcd1602_CheckBusy();
lcd1602_rs=1;
lcd1602_rw=0;
lcd1602_e=1;
LCD1602_PORT=c;
lcd1602_e=0;
}
/*
***********************************************
* 函数名称:lcd1602_Init()
* 函数功能:初始化LCD
***********************************************
*/
void lcd1602_Init()
{
lcd1602_WriteCmd(0x38); //显示模式为8位2行5*7点阵
lcd1602_WriteCmd(0x0f); //display enable,flag enable,flash enable,
lcd1602_WriteCmd(0x06); //flag move to right,screen don't move
lcd1602_WriteCmd(0x01); //clear screen
}
/*
************************************************
* 函数名称:lcd1602_Display()
* 函数功能: 字符显示
************************************************
*/
void lcd1602_Display(const INT8U *ptr)
{
INT8U data i=0;
INT8U *data q;
q=ptr;
lcd1602_WriteCmd(0x80);
while(q!=NULL (*q!='\0') i16)
{
lcd1602_WriteData(*q);
q++;
i++;
}
lcd1602_WriteCmd(0xc0);
while(q!=NULL (*q!='\0') i=16 i32)
{
lcd1602_WriteData(*q);
q++;
i++;
}
}
main()
{
INT8U *txt="hello friend!";
lcd1602_Init();
while(1)
{
if(keydis==0)
{
while(keydis==0);
lcd1602_Display(txt); //显示信息
}
if(keyno==0)
{
while(keyno==0);
lcd1602_WriteCmd(0x08); //关闭显示
}
}
}
51单片机lcd显示c语言程序
不知你用的LCD属于那种型号,似乎不像1602。
如果得到的数值小于1000,就正常显示个十白位的数字,比如345就显示34.5;如果大于1000,3个赋值都是0x39,即ASCII字符‘9’,这样的结果就是会在LCD上显示99.9,表示超过1000的量程范围。
猜测REQ是对LCD写控制信号,busy是LCD返回的“忙”信号,for循环16次就是把lcdtem字符数组中的16个字符写到LCD上显示。
以上回答你满意么?
LCD屏 用C语言如何写
//51单片机驱动ST7070控制16*2的字符型LCD
#include reg52.h
sbit RS = P3^2;
sbit R_W = P3^3;
sbit EN = P3^4;
sbit busy=P1^7;
sbit Auto=P3^6;
sbit step=P3^7;
void write_command(char);
void write_data(char);
void delay_s(int);
void delayms(int);
unsigned char checkbusy(void);
void scan(void);
void madefont(void);
void money(void);
void abcd(void);
void number(void);
void picure(void);
void white(void);
void black(void);
void snow(void);
void hoi(void);
void hline(void);
void vline(void);
void net(void);
void frame(void);
void main(void)
{
delay_s(40);
// write_command(0x20);
// write_command(0x20);
write_command(0x38); // FUNCTION SET
delay_s(10);
write_command(0x38); //FUNCTION SET
delay_s(2);
write_command(0x38); //FUNCTION SET
delay_s(2) ;
write_command(0x28); //FUNCTION SET
delay_s(2);
write_command(0x28); //FUNCTION SET
delay_s(2);
write_command(0x0c); //Display on
delay_s(10) ;
write_command(0x01); //Clear Display
delay_s(10) ;
write_command(0x06); // entry mode set
delay_s(10) ;
// write_command(0x0c); //display on
// delay_s(2);
// write_command(0x01); //CLEAR display
// delay_s(2);
write_command(0x2C); //FUNCTION SETC EXT=1
delay_s(2);
write_command(0x04); //bias resistor set,External bias resistor select.
delay_s(2);
checkbusy();
money();
delay_s(200);
scan();
checkbusy();
abcd();
delay_s(200);
scan();
checkbusy();
number();
delay_s(200);
scan();
checkbusy();
picure();
delay_s(200);
scan();
checkbusy();
white();
delay_s(200);
scan();
checkbusy();
black();
delay_s(200);
scan();
checkbusy();
snow();
delay_s(50);
scan();
checkbusy();
hoi();
delay_s(200);
scan();
madefont(); //造字
delay_s(200);
checkbusy();
hline();
delay_s(200);
scan();
checkbusy();
vline();
delay_s(200);
scan();
checkbusy();
net();
delay_s(200);
scan();
checkbusy();
frame();
delay_s(200);
scan();
}
void write_command(char comm)
{ RS = 0;
R_W = 0;
EN = 1;
P1=comm0xf0;
delayms(1);
EN = 0;
EN=1;
comm=4;
P1=comm0xf0;
EN=0;
}
void write_data(char dda)
{ RS = 1;
R_W = 0;
EN = 1;
P1=dda0xf0;
delayms(1);
EN = 0;
EN=1;
dda=4;
P1=dda0xf0;
EN=0;
}
void delay_s(int c)
{ int i,j;
for (i = 0; i=c; i++)
for ( j = 1; j=1000; j++);
}
void delayms(int c1)
{ int i,j;
for (i = 0; i=c1; i++)
for ( j = 1; j=50; j++);
}
unsigned char checkbusy(void) //检测 BF
{
busy=0x01;
RS = 0;
R_W = 1;
EN = 0;
EN = 1;
while(busy);//当BUSY=1时,不断循环,当BUSY=0时,开始执行下一条指令.
return(busy);
}
void madefont(void) //造字
{
int i,j;
write_command(0x40);
for(i=0;i4;i++) //HLINE,CODE=00H
{
write_data(0x1f);
write_data(0x00);
}
for(i=0;i8;i++) //VLINE ,code=01h
{
write_data(0x15);
}
for(i=0;i4;i++) //net,CODE=02H
{
write_data(0x15);
write_data(0x0a);
}
for(i=0;i1;i++) //Frame,CODE=03H
{
write_data(0x1f);
for(j=0;j6;j++)
{
write_data(0x11);
}
write_data(0x1f);
}
}
void scan(void)
{
while(step==1Auto==0)
{
delay_s(5);
}
if(step==0)
{
delay_s(5);
while(step==0)
{
delay_s(5);
}
delay_s(5);
}
else if(Auto==1)
{
delay_s(5);
}
delay_s(5);
write_command(0x01);
}
void money (void)
{
int i,j;
write_command(0x80);
for(i=0;i2;i++)
{
for(j=0;j1;j++)
{
write_data(0xB1);
write_data(0xB2);
write_data(0xB3);
write_data(0xB4);
write_data(0xB5);
write_data(0xB6);
write_data(0xB7);
write_data(0xB8);
write_data(0xB9);
write_data(0xBA);
write_data(0xBB);
write_data(0xBC);
write_data(0xB1);
write_data(0xBE);
write_data(0xBF);
write_data(0xC0);
write_data(0xD1);
write_data(0xD2);
write_data(0xD3);
write_data(0xD4);
write_data(0xD5);
write_data(0xD6);
write_data(0xD7);
write_data(0xD8);
write_data(0xD9);
write_data(0xDA);
write_data(0xDB);
write_data(0xDC);
write_data(0xD1);
write_data(0xDE);
write_data(0xDF);
write_data(0xE0);
}
}
}
void abcd (void)
{
int i,j;
write_command(0x80);
for(i=0;i2;i++)
{
for(j=0;j1;j++)
{
write_data(0x41);
write_data(0x42);
write_data(0x43);
write_data(0x44);
write_data(0x45);
write_data(0x46);
write_data(0x47);
write_data(0x48);
write_data(0x49);
write_data(0x4A);
write_data(0x4B);
write_data(0x4C);
write_data(0x4D);
write_data(0x4E);
write_data(0x4F);
write_data(0x50);
write_data(0x61);
write_data(0x62);
write_data(0x63);
write_data(0x64);
write_data(0x65);
write_data(0x66);
write_data(0x67);
write_data(0x68);
write_data(0x69);
write_data(0x6A);
write_data(0x6B);
write_data(0x6C);
write_data(0x61);
write_data(0x6E);
write_data(0x6F);
write_data(0x70);
}
}
}
void number (void)
{
int i,j;
write_command(0x80);
for(i=0;i2;i++)
{
for(j=0;j1;j++)
{
write_data(0x11);
write_data(0x12);
write_data(0x13);
write_data(0x14);
write_data(0x15);
write_data(0x16);
write_data(0x17);
write_data(0x18);
write_data(0x19);
write_data(0x1A);
write_data(0x1B);
write_data(0x1C);
write_data(0x11);
write_data(0x1E);
write_data(0x1F);
write_data(0x20);
write_data(0x31);
write_data(0x32);
write_data(0x33);
write_data(0x34);
write_data(0x35);
write_data(0x36);
write_data(0x37);
write_data(0x38);
write_data(0x39);
write_data(0x3A);
write_data(0x3B);
write_data(0x3C);
write_data(0x31);
write_data(0x3E);
write_data(0x3F);
write_data(0x40);
}
}
}
void picure (void)
{
int i,j;
write_command(0x80);
for(i=0;i2;i++)
{
for(j=0;j1;j++)
{
write_data(0x81);
write_data(0x82);
write_data(0x83);
write_data(0x84);
write_data(0x85);
write_data(0x86);
write_data(0x87);
write_data(0x88);
write_data(0x89);
write_data(0x8A);
write_data(0x8B);
write_data(0x8C);
write_data(0x81);
write_data(0x8E);
write_data(0x8F);
write_data(0x90);
write_data(0x91);
write_data(0x92);
write_data(0x93);
write_data(0x94);
write_data(0x95);
write_data(0x96);
write_data(0x97);
write_data(0x98);
write_data(0x99);
write_data(0x9A);
write_data(0x9B);
write_data(0x9C);
write_data(0x91);
write_data(0x9E);
write_data(0x9F);
write_data(0xA0);
}
}
}
void white (void)
{
int i,j;
write_command(0x80);
for(i=0;i4;i++)
{
for(j=0;j8;j++)
{
write_data(0x91);
write_data(0x92);
}
}
}
void black(void)
{
int i,j;
write_command(0x80);
for(i=0;i4;i++)
{
for(j=0;j8;j++)
{
write_data(0xff);
write_data(0xff);
}
}
}
void snow(void)
{
int i,j;
write_command(0x80);
for(i=0;i4;i++)
{
for(j=0;j16;j++)
{
write_data(0xdb);
// write_data(0x32);
// write_data(0x33);
// write_data(0x34);
}
}
}
void hoi (void)
{
int i,j;
write_command(0x80);
for(i=0;i4;i++)
{
for(j=0;j16;j++)
{
// write_data(0x00);
// write_data(0x01);
// write_data(0x02);
write_data(0x03);
}
}
}
void hline (void)
{
int i,j;
write_command(0x80);
for(i=0;i4;i++)
{
for(j=0;j40;j++)
{
write_data(0x01);
}
}
}
void vline(void)
{
int i,j;
write_command(0x80);
for(i=0;i4;i++)
{
for(j=0;j40;j++)
{
write_data(0x02);
}
}
}
void net(void)
{
int i,j;
write_command(0x80);
for(i=0;i4;i++)
{
for(j=0;j40;j++)
{
write_data(0x03);
}
}
}
void frame(void)
{
int i,j;
write_command(0x80);
for(i=0;i4;i++)
{
for(j=0;j40;j++)
{
write_data(0x04);
}
}
}
用C语言编写LCD显示程序
LCD有哪些寄存器?各表示什么含义,控制什么功能?
写出来的程序又如何验证是否正确?
其实,你只需要对LCD的打开、关闭,以及能把一个数据块显示在LCD上就行了
“常见字母、数字、符号、中文、自定义字符、图形,以及文字和图形混和显示;光标显示/隐藏(Cursor
on/off)、显示字符闪烁(Display
character
blink);画面清除(Display
clear)、光标归位(Return
home)”
这些功能,只需要在这个数据块上进行操作,然后再送到LCD显示。