單片機(jī)C語(yǔ)言實(shí)例-144-1602液晶顯示的計(jì)算器
內(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
}
/*------------------------------------------------
寫(xiě)入命令函數(shù)
------------------------------------------------*/
void LCD_Write_Com(unsigned char com)
{
while(LCD_Check_Busy()); //忙則等待
RS_CLR;
RW_CLR;
EN_SET;
DataPort= com;
_nop_();
EN_CLR;
}
/*------------------------------------------------
寫(xiě)入數(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);
}
/*------------------------------------------------
寫(xiě)入字符串函數(shù)
------------------------------------------------*/
void LCD_Write_String(unsigned char x,unsigned char y,unsigned char *s)
{
while (*s)
{
LCD_Write_Char(x,y,*s);
s ++; x++;
}
}
/*------------------------------------------------
寫(xiě)入字符函數(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:00C325聯(lián)盟網(wǎng)7404.png (34.47 KB, 下載次數(shù): 5)
下載附件
保存到相冊(cè)
2022-1-19 14:49 上傳
游客,如果您要查看本帖隱藏內(nèi)容請(qǐng) 回復(fù)
|