资源描述:
《侯士亮单片机考试程序》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、题目五、蜂鸣器及显示按下按键K1,蜂鸣器响200ms后停止,即响一声,数码管前3位不显示,最后1位显示1;按下按键K2,蜂鸣器响200ms后停止,过200ms后再响200ms,即响2声,数码管倒数第二位位显示2;按下按键K3,蜂鸣器响2声,数码管倒数第3位显示3;...,按下按键K5,蜂鸣器响5声,数码管倒数第1位显示5,...,按下K8,蜂鸣器响8声,数码管倒数第4位显示8。#include"stc15f2k60s2.h"#include"absacc.h"#include"intrins.h"
2、#include"init.h"#defineucharunsignedchar#defineuintunsignedintvoiddisplay(intnum);sbitN1=P3^3;sbitN2=P4^0;sbitN3=P5^5;sbitN4=P5^4;sbitring=P4^3;uchartime;unsignedcharcodetable[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x
3、86,0x8e};unsignedcharcodek[]={0,0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};voidmain(){ucharanjian,j;init();while(1){ring=1;anjian=XBYTE[0xfbff];if(anjian==k[1]){display(1);ring=~ring;time=10;TR0=1;while(time>0);time=10;ring=~ring;while(time>0);TR0=0;}if
4、(anjian==k[2]){display(2);ring=~ring;time=10;TR0=1;for(j=2;j>0;j--){while(time>0);time=10;ring=~ring;while(time>0);time=10;ring=~ring;}TR0=0;}if(anjian==k[3]){display(3);ring=~ring;time=10;TR0=1;for(j=3;j>0;j--){while(time>0);time=10;ring=~ring;while(
5、time>0);time=10;ring=~ring;}TR0=0;}if(anjian==k[4]){display(4);ring=~ring;time=10;TR0=1;for(j=4;j>0;j--){while(time>0);time=10;ring=~ring;while(time>0);time=10;ring=~ring;}TR0=0;}if(anjian==k[5]){display(5);ring=~ring;time=10;TR0=1;for(j=5;j>0;j--){wh
6、ile(time>0);time=10;ring=~ring;while(time>0);time=10;ring=~ring;}TR0=0;}if(anjian==k[6]){display(6);ring=~ring;time=10;TR0=1;for(j=6;j>0;j--){while(time>0);time=10;ring=~ring;while(time>0);time=10;ring=~ring;}TR0=0;}if(anjian==k[7]){display(7);ring=~r
7、ing;time=10;TR0=1;for(j=7;j>0;j--){while(time>0);time=10;ring=~ring;while(time>0);time=10;ring=~ring;}TR0=0;}if(anjian==k[8]){display(8);ring=~ring;time=10;TR0=1;for(j=8;j>0;j--){while(time>0);time=10;ring=~ring;while(time>0);time=10;ring=~ring;}TR0=0
8、;}}}voidt0_time()interrupt1{time--;}voiddisplay(intnum){switch(num){case1:N1=1;N2=1;N3=1;N4=0;break;case2:N1=1;N2=1;N3=0;N4=1;break;case3:N1=1;N2=0;N3=1;N4=1;break;case4:N1=0;N2=1;N3=1;N4=1;break;case5:N1=1;N2=1;N3=1;N4=0;break;case6:N1=1;N2=1