|
#include<reg51.h>
#define uint unsigned int
#define uchar unsigned char
sbit RS=P2^0;
sbit RW=P2^1;
sbit E=P2^2;
sbit BF=P0^7;
/********************************************************************************************************/
void delay_us(uint i)
{
while(--i);
}
/*****************************************************
***************************************************/
void delay1ms()
{
unsigned char i,j;
for(i=0;i<10;i++)
for(j=0;j<33;j++)
;
}
/********************************************************************************************************/
void delay_ms(uchar n)
{
uchar i;
for(i=0;i<n;i++)
delay1ms();
}
/********************************************************************************************************/
unsigned char BusyTest(void)
{
bit result;
RS=0;
RW=1;
E=1;
delay_us(4)
result=BF;
E=0;
return result;
}
/********************************************************************************************************/
void Write_order_add (unsigned char dictate)
{
while(BusyTest()==1)
RS=0;
RW=0;
E=0;
delay_us(2);
P0=dictate;
delay_us(4)
E=1;
delay_us(4);
E=0;
}
/********************************************************************************************************/
void WriteData(unsigned char y)
{
while(BusyTest()==1);
RS=1;
RW=0;
E=0;
P0=y;
delay_us(4);
delay_us(4);
E=0;
}
/****************************************************
***************************************************/
void LcdInit(void)
{
delay_ms(15);
Write_order_add(0x38);
delay_ms(5);
Write_order_add(0x38);
delay_ms(5);
Write_order_add(0x38);
delay_ms(5);
Write_order_add(0x0E);
delay_ms(5);
Write_order_add(0x06);
delay_ms(5);
Write_order_add(0x01)
delay_ms(5);
}
void main(void)
{ uchar i;
LcdInit();
Write_order_add(0xC7);
WriteData('A');
}
|
|