基于51单片机简易计算器的原理图如下
基于51单片机简易计算器的pcb图如下
任务书如下
一. 设计要求
(一) 基本任务
该简易计算器设计硬件电路采用三部分电路模块构成, 第一部分是键盘模块
电路, 采用 4*4 矩阵式键盘作为输入电路; 第二部分是 LCD1602 液晶显示模块;
第三部分是以 51 单片机作为控制核心。 软件程序主要由三部分组成: 主程序、
按键扫描程序和 LCD1602 显示程序。
(二) 性能指标
(1) 用单片机 stc89C51 设计一个简易计算器, 并用 1602 液晶显示相应的
数据。
(2) 可以进行简单的加减乘除运算。
(3) 最大可以 9999*9999, 。
(4) 可以通过 proteus 仿真。
附: 可供选用的元件清单
1)1602 液晶
2)排针*16
3)16p 母座
4)STC89C51 单片机
5)40 脚 IC 座
6)10k 电阻*2
7)1.5k 电阻
8)103 排阻
9)10uf 电解电容
10)12M 晶振
11)30pf 电容*2
12)按键*17
13)自锁开关等等
Proteus仿真如下
单片机源程序如下:- #include "reg52.h"
- #include "string.h"
- #include "stdio.h"
- #include "lcd1602.h"
- #include "keyboard.h"
- #define keydeng 14
- #define keyzuoyi 12
- code unsigned char KeyDisPlaybuf[16] =
- {
- '1', '2', '3', '+',\
- '4', '5', '6', '-',\
- '7', '8', '9', '*',\
- '<', '0', '=', '/'
- };
- long Count(char *ch, char len)//简单计算器 仅支持+-*/
- {
- unsigned char i = 0;
- char Operation;
- long Num1=0,Num2=0;
- while(i<len && ch[i]!='+' && ch[i]!='-' && ch[i]!='*' && ch[i]!='/')
- {
- Num1*=10;
- Num1+=ch[i]-'0';
- i++;
- }
- Operation=ch[i++];
- while(i<len && ch[i]!='=')
- {
- Num2*=10;
- Num2+=ch[i]-'0';
- i++;
- }
- switch(Operation)
- {
- case'+':return Num1+Num2;
- case'-':return Num1-Num2;
- case'*':return Num1*Num2;
- case'/':return Num1/Num2;
- }
- return 0;
- }
- void EasyCounter(void)
- {
- unsigned char buff[30];
- unsigned char text[30];
- unsigned char key;
- unsigned char i = 0;
- do
- {
- key = keycan();//读取键值
- if(key!=0xff)//键值不等于0
- {
- text[i++]=KeyDisPlaybuf[key];//记录键值对应的字符
- text[i]='\0';
- LCD_ShowStr(0,0," ");
- LCD_ShowStr(16-strlen(text),0,text);
- }
- if(key==keyzuoyi&&i>0)//按下"<"时删除一位
- i-=2;
- }while(key!=keydeng);//按下'='时结束输入
- sprintf(buff, "%ld", Count(text, strlen(text)));
- LCD_ShowStr(0,1," ");
- LCD_ShowStr(16-strlen(buff),1,buff);
- }
- void main(void)
- {
- LCD_Init();
- while(1)
- {
- EasyCounter();
- }
- }
复制代码- #include "reg52.h"
- #include "keyboard.h"
- #define Key P1
- code unsigned char KeyValueL[]={0xf7,0xfb,0xfd,0xfe};
- code unsigned char KeyValueH[]={0x70,0xb0,0xd0,0xe0};
- void KeyDelay(unsigned char xms)
- {
- unsigned char i;
- while(xms--)
- {
- for(i=0; i<120; i++);
- }
- }
- unsigned char keycan(void)
- {
- unsigned char i,j;
- unsigned char tmp;
- Key=0xf0;
- if(Key!=0xf0)
- {
- KeyDelay(10);
- if(Key!=0xf0)
- {
- for(i=0; i<4; i++)
- {
- Key=KeyValueL[i];
- for(j=0; j<4; j++)
- {
- if((Key&0xf0)==KeyValueH[j])
- {
- tmp=i+j*4;
- while(Key!=KeyValueL[i]);
- return tmp;
- }
- }
- }
- }
- }
- return 0xff;
- }
复制代码
所有资料51hei提供下载:
原理图andPCB图.zip
(9.1 MB, 下载次数: 61)
简易计算器.doc
(676.5 KB, 下载次数: 55)
c程序,和仿真.zip
(89.59 KB, 下载次数: 79)
|