sbit LCD_RS=p3^0;
sbit LCD_RW=P3^1;
sbit LCD_E=p3^5;
/*The main function*/
void main(void)
{
int k;
uchar n;
LCD_init();
LCD_clr();
for(n=0;n <10;n++)
{
LCD_DAT_Write(table_2[k++]);
}
}
/***************************************************
LCD Function
****************************************************/
/*Locate the coordinate*/
static void LCD_goxy(uchar x, uchar y)
{
uchar tmp;
tmp=x&0xf;
switch(y)
{
case 1:
tmp|=LINE1_ADDR;
case 2:
tmp|=LINE2_ADDR;
case 3:
tmp|=LINE3_ADDR;
case 4:
tmp|=LINE4_ADDR;
break;
}
LCD_CMD_Write(tmp)
}
/*Write a string to LCD*/
static void LCD_string(uchar *s)
{
uchar i;
for(i=0;s[i]!='\0';i++)
{
LCD_DAT_Write(s[i]);
}
/*Clear the display of LCD*/
static void LCD_clr(void)
{
LCD_busy();
LCD_CMD_Write(0x01);
LCD_goxy(1,1);
}
/*Write instruction to LCD*/
void LCD_CMD_Write(unsigned char pass_value)
{
LCD_busy();
LCD_RW=0;
LCD_E=1;
LCD_E=0;
LCD_Data_port=pass_value;
LCD_E=1;
LCD_E=0;
}
/*LCD_init:Initialize the LCD*/
void LCD_init(void)
{
uchar pass;
uchar i;
i=3;
do{
pass=0x38;
LCD_RS=0;
LCD_RW=0;
_nop_();
LCD_Data_Port=pass;
pass=0xff;
while(pass--);//Delay
LCD_E=1;
LCD_E=0;
}while(i--);
pass=0x01;
LCD_CMD_Write(pass);//Clear display and set display data address to 0
pass=0x06;
LCD_CMD_Write(pass);//Display data RAM pointer incremented after write
pass=0x0c;
LCD_CMD_Write(pass);//Open LCD ,close the cursor and flash
//***Write a char to LCD***//
void LCD_putbyte(uchar c)
{
LCD_DAT_Write(c);
}
/*/
void LCD_DAT_Write(uchar pass_value)
{
LCD_busy();
LCD_RS=1;
LCD_RW=0;
LCD_Data_Port=pass_value;
LCD_E=1;
LCD_E=0;
}
/*Read the value of ACC*/
static uchar LCD_RAM_Read(void)
{
uchar pass;
LCD_Data_Port=0xff;
LCD_RS=0;
LCD_RW=1;
LCD_E=1;
pass=LCD_Data_Port;
pass=pass&0x7f;
LCD_E=0;
return(pass);
}
/*Read data from LCD*/
static uchar LCD_Read(void)
{
uchar val;
LCD_busy();
LCD_RS=1;
LCD_RW=1;
LCD_Data_Port=0xff;
LCD_E=1;
val=LCD_Data_Port;
return(val);
LCD_E=0;
}
void LCD_busy(void)
{
uchar pass;
LCD_RS=0;
LCD_RW=1;
LCD_Data_Port=0xff;
do{
pass=LCD_Data_Port;
}while(pass&0x80);
LCD_E=0;
}
/*****************************************
以下是引用chang4152在2003-9-4 21:18:32的发言: HT1621是什么芯片? |
typdef uchar unsigned char;
最后注释的格式错误,应为:
/* 注释 */
// 注释