为了正常的体验网站,请在浏览器设置里面开启Javascript功能!

51单片机程序

2017-10-16 8页 doc 41KB 14阅读

用户头像

is_954223

暂无简介

举报
51单片机程序51单片机程序 //该程序用数码管显示按键的编码及编码的平方 #include #define uint unsigned int #define uchar unsigned char sbit dula=P2^6; sbit wela=P3^7; uint numone,numtwo; uchar temp,one,two,three,four,five,six; uchar code list[]={ 0x3f,0x06,0x5b,0x4f, 0x66,0x6d,0x7d,0x07, 0x7f,0x6f,0...
51单片机程序
51单片机程序 //该程序用数码管显示按键的编码及编码的平方 #include #define uint unsigned int #define uchar unsigned char sbit dula=P2^6; sbit wela=P3^7; uint numone,numtwo; uchar temp,one,two,three,four,five,six; uchar code list[]={ 0x3f,0x06,0x5b,0x4f, 0x66,0x6d,0x7d,0x07, 0x7f,0x6f,0x77,0x7c, 0x39,0x5e,0x79,0x71}; void delay(uint z) { uint x,y; for(x=100;x>0;x--) for(y=z;y>0;y--); } void shuma(uchar a,uchar b,uchar c,uchar d,uchar e,uchar f) { if(a==0) P0=0xff; else { dula=1; P0=list[a]; dula=0; P0=0xff; wela=1; P0=0xfe; wela=0; delay(1); } if(b==0) P0=0xff; else { dula=1; P0=list[b]; dula=0; P0=0xff; wela=1; P0=0xfd; wela=0; delay(1); } if((c==0)&&(b==0)) P0=0xff; else { dula=1; P0=list[c]; dula=0; P0=0xff; wela=1; P0=0xfb; wela=0; delay(1); } if(d==0) P0=0xff; else { dula=1; P0=list[d]; dula=0; P0=0xff; wela=1; P0=0xf7; wela=0; delay(1); } if((e==0)&&(d==0)) P0=0xff; else { dula=1; P0=list[e]; dula=0; P0=0xff; wela=1; P0=0xef; wela=0; delay(1); } if((f==0)&&(e==0)&&(d==0)) P0=0xff; //注意此处是为了解决第十个按键按下时,十位和个位不显示的问 else { dula=1; P0=list[f]; dula=0; P0=0xff; wela=1; P0=0xdf; wela=0; delay(1); } } void init() { one=numone%10; //numone表示第几个按下 two=numone%100/10; three=numone/100; four=numtwo%10; //numtwo表示按下的平方 five=numtwo%100/10; six=numtwo/100; } void main() { while(1) { P3=0xfe; temp=P3; temp=temp&0xf0; if(temp!=0xf0) { delay(5); if(temp!=0xf0) { switch(temp) { case 0xe0: numone=1;numtwo=1;P1=0xfe;break; case 0xd0: numone=2;numtwo=4;P1=0xfd;break; case 0xb0: numone=3;numtwo=9;P1=0xfc;break; case 0x70: numone=4;numtwo=16;P1=0xfb;break; } //下面两行放于此处数码管只有在键盘按下时才会显示 } } init(); shuma(three,two,one,six,five,four); P3=0xfd; temp=P3; temp=temp&0xf0; if(temp!=0xf0) { delay(5); if(temp!=0xf0) { switch(temp) { case 0xe0: numone=5;numtwo=25;P1=0xfa;break; case 0xd0: numone=6;numtwo=36;P1=0xf9;break; case 0xb0: numone=7;numtwo=49;P1=0xf8;break; case 0x70: numone=8;numtwo=64;P1=0xf7;break; } //下面两行放于此处数码管只有在键盘按下时才会显示 } } init(); shuma(three,two,one,six,five,four); P3=0xfb; temp=P3; temp=temp&0xf0; if(temp!=0xf0) { delay(5); if(temp!=0xf0) { switch(temp) { case 0xe0: numone=9;numtwo=81;P1=0xf6;break; case 0xd0: numone=10;numtwo=100;P1=0xf5;break; case 0xb0: numone=11;numtwo=121;P1=0xf4;break; case 0x70: numone=12;numtwo=144;P1=0xf3;break; } //下面两行放于此处数码管只有在键盘按下时才会显示 } } init(); shuma(three,two,one,six,five,four); P3=0xf7; temp=P3; temp=temp&0xf0; if(temp!=0xf0) { delay(5); if(temp!=0xf0) { switch(temp) //用二极管指示按下第几个按键 { case 0xe0: numone=13;numtwo=169;P1=0xf2;break; case 0xd0: numone=14;numtwo=196;P1=0xf1;break; case 0xb0: numone=15;numtwo=225;P1=0xf0;break; case 0x70: numone=16;numtwo=256;P1=0xef;break; } //下面两行放于此处数码管只有在键盘按下时才会显示 } } init(); shuma(three,two,one,six,five,four); } }
/
本文档为【51单片机程序】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。

历史搜索

    清空历史搜索