單片機(jī)C語(yǔ)言實(shí)例-127-PS2鍵盤輸入1602液晶顯示
內(nèi)容:
引腳定義如下:1-VSS 2-VDD 3-V0 4-RS 5-R/W 6-E 7-14 DB0-DB7 15-BLA 16-BLK
------------------------------------------------*/
#include "1602.h"
#include "delay.h"
#define CHECK_BUSY
sbit RS = P2^4; //定義端口
sbit RW = P2^5;
sbit EN = P2^6;
#define RS_CLR RS=0
#define RS_SET RS=1
#define RW_CLR RW=0
#define RW_SET RW=1
#define EN_CLR EN=0
#define EN_SET EN=1
#define DataPort P0
/*------------------------------------------------
判忙函數(shù)
------------------------------------------------*/
bit LCD_Check_Busy(void)
{
#ifdef CHECK_BUSY
DataPort= 0xFF;
RS_CLR;
RW_SET;
EN_CLR;
_nop_();
EN_SET;
return (bit)(DataPort & 0x80);
#else
return 0;
#endif
}
/*------------------------------------------------
寫入命令函數(shù)
------------------------------------------------*/
void LCD_Write_Com(unsigned char com)
{
while(LCD_Check_Busy()); //忙則等待
RS_CLR;
RW_CLR;
EN_SET;
DataPort= com;
_nop_();
EN_CLR;
}
/*------------------------------------------------
寫入數(shù)據(jù)函數(shù)
------------------------------------------------*/
void LCD_Write_Data(unsigned char Data)
{
while(LCD_Check_Busy()); //忙則等待
RS_SET;
RW_CLR;
EN_SET;
DataPort= Data;
_nop_();
EN_CLR;
}
/*------------------------------------------------
清屏函數(shù)
------------------------------------------------*/
void LCD_Clear(void)
{
LCD_Write_Com(0x01);
DelayMs(5);
}
/*------------------------------------------------
寫入字符串函數(shù)
------------------------------------------------*/
void LCD_Write_String(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 ++;
}
}
/*------------------------------------------------
寫入字符函數(shù)
------------------------------------------------*/
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);
}
/*------------------------------------------------
初始化函數(shù)
------------------------------------------------*/
void LCD_Init(void)
{
LCD_Write_Com(0x38); /*顯示模式設(shè)置*/
DelayMs(5);
LCD_Write_Com(0x38);
DelayMs(5);
LCD_Write_Com(0x38);
DelayMs(5);
LCD_Write_Com(0x38);
LCD_Write_Com(0x08); /*顯示關(guān)閉*/
LCD_Write_Com(0x01); /*顯示清屏*/
LCD_Write_Com(0x06); /*顯示光標(biāo)移動(dòng)設(shè)置*/
DelayMs(5);
LCD_Write_Com(0x0C); /*顯示開(kāi)及光標(biāo)設(shè)置*/
}
更多詳情參考附件文檔
+08:00C166聯(lián)盟網(wǎng)3891.png (38.45 KB, 下載次數(shù): 80)
下載附件
保存到相冊(cè)
2022-1-12 11:00 上傳
游客,如果您要查看本帖隱藏內(nèi)容請(qǐng) 回復(fù)
|