//*************************************************************************
// 初始化IO口子程序
//*************************************************************************
void Port_init()
{
P4SEL = 0x00;
P4DIR = 0xFF; //數據口輸出模式
P5SEL = 0x00;
P5DIR|= BIT5 + BIT6 + BIT7; //控制口設置為輸出模式
}
//***********************************************************************
// 顯示屏命令寫入函數
//***********************************************************************
void LCD_write_com(unsigned char com)
{
RS_CLR;
RW_CLR;
EN_SET;
DataPort = com; //命令寫入端口
delay_ms(5);
EN_CLR;
}
//***********************************************************************
// 顯示屏數據寫入函數
//***********************************************************************
void LCD_write_data(unsigned char data)
{
RS_SET;
RW_CLR;
EN_SET;
DataPort = data; //數據寫入端口
delay_ms(5);
EN_CLR;
}
//***********************************************************************
// 顯示屏清空顯示
//***********************************************************************
void LCD_clear(void)
{
LCD_write_com(0x01); //清屏幕顯示
delay_ms(5);
}
//***********************************************************************
// 顯示屏字符串寫入函數
//***********************************************************************
void LCD_write_str(unsigned char x,unsigned char y,unsigned char *s)
{
if (y == 0)
{
LCD_write_com(0x80 + x); //第一行顯示
}
else
{
LCD_write_com(0xC0 + x); //第二行顯示
}
while (*s)
{
LCD_write_data( *s);
s ++;
}
}
//***********************************************************************
// 顯示屏單字符寫入函數
//***********************************************************************
void LCD_write_char(unsigned char x,unsigned char y,unsigned char data)
{
if (y == 0)
{
LCD_write_com(0x80 + x); //第一行顯示
}
else
{
LCD_write_com(0xC0 + x); //第二行顯示
}
LCD_write_data( data);
}
//***********************************************************************
// 顯示屏初始化函數
//***********************************************************************
void LCD_init(void)
{
LCD_write_com(0x38); //顯示模式設置
delay_ms(5);
LCD_write_com(0x08); //顯示關閉
delay_ms(5);
LCD_write_com(0x01); //顯示清屏
delay_ms(5);
LCD_write_com(0x06); //顯示光標移動設置
delay_ms(5);
LCD_write_com(0x0C); //顯示開及光標設置
delay_ms(5);
}
//***********************************************************************
// 液晶顯示界面初始化
//***********************************************************************
void LCD_Desk(void)
{
LCD_clear();
LCD_write_str(0,0,"The Key Number:");
delay_ms(250);
}
|