LCD.c 文件
#include "LCD.h"
extern const unsigned char lcd_Table[]="V=0123456789.";
void lcd_1602_chuzhi(void)
{
// en=0;
// rw=0;
// rs=0;
lcd_1602_xiemingling(0x38);
lcd_1602_xiemingling(0x0c);
lcd_1602_xiemingling(0x06);
delay(50);
}
void delay( unsigned int xms)
{
int i,j;
for(i=xms;i>0;i--);
for(j=110;j>0;j--);
}
void lcd_1602_xiemingling(unsigned char n)
{
rs=1;
rs=0;
rw=1;
delay(5);
rw=0;
P0=n;
delay(5);
en=1;
delay(100);
en=0;
}
void lcd_1602_clean()
{
lcd_1602_xiemingling(0x01);
}
void lcd_1602_xieshuju(unsigned char m)
{
rs=0;
rs=1;
rw=1;
delay(5);
rw=0;
P0=m;
en=1;
delay(100);
en=0;
}
void lcd_display(int cl)
{
lcd_1602_xiemingling(0x80+0x00);
delay(5);
lcd_1602_xieshuju(lcd_Table[0]);
lcd_1602_xieshuju(lcd_Table[1]);
lcd_1602_xieshuju(lcd_Table[cl/100]);
lcd_1602_xieshuju(lcd_Table[12]);
lcd_1602_xieshuju(lcd_Table[cl%100/10]);
lcd_1602_xieshuju(lcd_Table[cl%100]);
}
LCD.h文件
#include <reg52.h>
sbit en=P2^1;
sbit rs=P2^3;
sbit rw=P2^2;
//extern const unsigned char lcd_Table[]="V=0123456789.";
void delay( unsigned int xms);
void lcd_1602_clean();
void lcd_1602_chuzhi(void);
void lcd_1602_xiemingling(unsigned char n);
void lcd_1602_xieshuju(unsigned char m);
void lcd_display(int cl);
main.c文件
#include "LCD.h"
void main()
{
int n1;
n1=2;
lcd_1602_chuzhi();
lcd_1602_clean();
while(1)
{
lcd_display(n1);
}
}
|