資料清單:C程序+仿真+設(shè)計(jì)報(bào)告+使用說(shuō)明+元件清單+操作視頻
仿真版本:Proteus8.6及以上版本
程序編譯:Keil5 C51
編程語(yǔ)言:C語(yǔ)言
設(shè)計(jì)編號(hào):【Q09】
1.? 簡(jiǎn)介
? 本文提出了一種基于51單片機(jī)的LCD1602計(jì)算器設(shè)計(jì)。該設(shè)計(jì)是以AT89C51單片機(jī)為核心的計(jì)算器模擬系統(tǒng),輸入采用4×4矩陣鍵盤(pán),可以進(jìn)行加、減、乘、除、開(kāi)方數(shù)字運(yùn)算,并在LCD1602上顯示操作過(guò)程。
2.? 主要功能
a.通過(guò)LCD1602顯示計(jì)算過(guò)程。
b.通過(guò)4×4矩陣鍵盤(pán)進(jìn)行加、減、乘、除、開(kāi)方數(shù)字運(yùn)算。
3.? 源程序(Keil5)
本設(shè)計(jì)采用keil5 C51軟件(內(nèi)附安裝包)實(shí)現(xiàn)程序設(shè)計(jì)。如需用keil4打開(kāi)程序,可自行通過(guò).c和.h文件新建工程即可。
void DelayUs(unsigned char us)//delay us
{
unsigned char uscnt;
uscnt=us>>1; /*12MHz頻率*/
while(--uscnt);
}
/******************************************************************/
/* 毫秒函數(shù)聲明 */
/******************************************************************/
void DelayMs(unsigned char ms)
{
while(--ms)
{
DelayUs(250);
DelayUs(250);
DelayUs(250);
DelayUs(250);
}
}
/******************************************************************/
/* 寫(xiě)入命令函數(shù) */
/******************************************************************/
void WriteCommand(unsigned char c)
{
DelayMs(5);//操作前短暫延時(shí),保證信號(hào)穩(wěn)定
E=0;
RS=0;
RW=0;
_nop_();
E=1;
Data=c;
E=0;
}
/******************************************************************/
/* 寫(xiě)入數(shù)據(jù)函數(shù) */
/******************************************************************/
void WriteData(unsigned char c)
{
DelayMs(5); //操作前短暫延時(shí),保證信號(hào)穩(wěn)定
E=0;
RS=1;
RW=0;
_nop_();
E=1;
Data=c;
E=0;
RS=0;
}
/******************************************************************/
/* 寫(xiě)入字節(jié)函數(shù) */
/******************************************************************/
void ShowChar(unsigned char pos,unsigned char c)
{
unsigned char p;
if (pos>=0x10)
p=pos+0xb0; //是第二行則命令代碼高4位為0xc
else
p=pos+0x80; //是第二行則命令代碼高4位為0x8
WriteCommand (p);//寫(xiě)命令
WriteData (c); //寫(xiě)數(shù)據(jù)
}
/******************************************************************/
/* 寫(xiě)入字符串函數(shù) */
/******************************************************************/
void ShowString (unsigned char line,char *ptr)
{
unsigned char l,i;
l=line<<4;
for (i=0;*(ptr+i)!='