|
制作出来的实物图如下:
电路原理图如下:
刚好老师要求做一个简单的计算器,就顺便发到这里来了。 首先是部分代码:
- #include<reg51.h>#define uint unsigned int
- #define uchar unsigned char
- // 0 1 2 3 4 5 6 7 8 9 c = + - * /
- uint tab[17] = {0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10,0x08,0x03,0x46,0x21,0x06,0x0e,0xff};
- uchar i;//这个放按键值
- uchar j;//这个在等号按出前暂时放加减乘除的运算
- uchar memory_N=0,memory_O=0;//这个用来放置输入的数字 memory_0 是第一个数字,memory_N 是第二个数
- uchar nextNeedClearly = 0;//这个用来判断下一个输入的数字显示在屏幕前要不要清楚旧的显示内容
- uchar sh[4];//显示字符存放
- uint choose[4]={0x01,0x02,0x04,0x08};//数码管选中
- uchar useToShow = 0;//等于0选中最左边数码管,往右类推
- void delay(uchar i){
- uchar j,k;
- for (j = 0; j < i; j++){
- for (k = 0; k < 128; k++){
- }
- }
- }
- void pushFun(uchar i){//挪位函数,负责在数据输入时显示在屏幕上向左移
- if ((sh[2] == tab[16])&&(sh[3] == tab[0])){
- sh[3] = tab[i];
- }else{
- sh[0] = sh[1];
- sh[1] = sh[2];
- sh[2] = sh[3];
- sh[3] = tab[i];
- }
- }
- void pushNem(uint i){//这个函数实现将数字i变换为要显示的4位
- uchar a,b,c,d;
- a = i / 1000;
- b = (i / 100)%10;
- c = (i / 10)%10;
- d = i%10;
- sh[0] = tab[a];
- sh[1] = tab[b];
- sh[2] = tab[c];
- sh[3] = tab[d];
- if (a == 0){
- sh[0] = tab[16];
- if (b == 0){
- sh[1] = tab[16];
- if (c == 0){
- sh[2] = tab[16];
- }
- }
- }
- }
- void clearly(){
- sh[0] = tab[16];//初始化屏幕显示"0"
- sh[1] = tab[16];
- sh[2] = tab[16];
- sh[3] = tab[0];
- }
- void main(){
- uint row,column,temp;
- EA = 1;
- ET1 = 1;
- TMOD = 0X10;
- TH1 = 0xf6;
- TL1 = 0x3c;
- TR1 = 1;//open T1
- clearly();
- while(1){
- P1=0x0f;
- if(P1!=0x0f){
- delay(10);
- if(P1!=0x0f){
- row=P1;
- P1=0xff;
- P1=0xf0;
- column = P1;
- temp = (row)|(column);
- if(temp == 0xee)i=7;
- if(temp == 0xde)i=8;
- if(temp == 0xbe)i=9;
- if(temp == 0x7e)i=15; // /
- if(temp == 0xed)i=4;
- if(temp == 0xdd)i=5;
- if(temp == 0xbd)i=6;
- if(temp == 0x7d)i=14; // *
- if(temp == 0xeb)i=1;
- if(temp == 0xdb)i=2;
- if(temp == 0xbb)i=3;
- if(temp == 0x7b)i=13; // -
- if(temp == 0xe7)i=10; // c
- if(temp == 0xd7)i=0;
- if(temp == 0xb7)i=11; // =
- if(temp == 0x77)i=12; // +
- while(P1!=0xf0);
复制代码 用到的开发板图及元件图贴出来和仿真图,以及文档和仿真文件和c文件都在附件里面了!
|
评分
-
查看全部评分
|