# include <reg51.h>
# include <intrins.h>
# include <stdio.h>
#define uint unsigned int
#define uchar unsigned char
sbit lcddata= P2^2; //液晶数据端口
sbit lcdwr=P2^3; //写操作端口
sbit lcdcs=P2^4; //片选输入 为低的时候复位初始化且数据,命令无效。高的时候反之。
#define BAIS 0X52
#define SYSDIS 0X00
#define SYSEN 0X02
#define LCDOFF 0X04
#define LCDON 0X06
#define XTAL 0X28
#define RC256 0X30
#define TONEON 0X12
#define TONEOFF 0X10
#define WDTDIS 0X0A
/*****************************************段码*************************************************/
uchar code TAB[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
/**************延时程序1***************/
void delay1(uchar x)
{
uchar i,j;
for(i=0;i<x;i++)
for(j=0;j<120;j++);
}
/********************延时程序2**************/
void delay(uchar y)
{
while(--y);
}
/*********************写数据*********/
void wr_data(uint cnt,uchar date)
{
uint i;
for(i=0;i<cnt;i++)
{
lcdwr=0;
delay(10);
lcddata=(0x80&date);
delay(10);
lcdwr=1;
delay(5);
date<<=1;
}
}
/*********************写命令**********/
void wr_com(uchar com)
{
lcdcs=0;
delay(5);
wr_data(0x80,4);
wr_data(com,8);
lcdcs=1;
delay(5);
}
/********************液晶初始化程序**************/
void init()
{
lcddata=1;
lcdwr=1;
lcdcs=1;
wr_com(BAIS);
wr_com(RC256);
wr_com(SYSDIS);
wr_com(SYSEN);
wr_com(LCDON);
// wr_com(WDTDIS);
}
void display(uchar m,uchar n)
{
m<<=2;
lcdcs=0;
delay(5);
wr_data(0xA0,3);
wr_data(m,6);
wr_data(n,4);
lcdcs=1;
delay(5);
}
void cl_scren(uchar l)
{
uchar o=0;
for(l=0;l<32;l++)
{
display(0x00,o);
o++;
}
}
/*********************主程序*************/
void main ()
{
init();
cl_scren();
display(0xff,3);
while(1);
} |