资源描述:
《单片机上机操作考试题及答案.pdf》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、.单片机上机考试试题1.使得8个发光二极管循环点亮,采用定时器方式0使得每个发光二极管点亮的时间为0.5s。#includeintcount=0;intminute=0;inttemp;charcodestyle[8]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};voiddesplay(){temp=minute%8;P0=style[temp];}voidtoProc()interrupt1{count++;TH0=0x0c;TL0=0x78;}voidmain(){TMOD=0;TH0=0x0c;
2、TL0=0x78;TR0=1;ET0=1;EA=1;while(1){if(count==100){minute++;count=0;}desplay();}}..2.完成下面电路所示的功能,K1,K2对应两个开关按键。P1口对应发光二极管的状态P1.0P1.1P1.2P1.3P1.4P1.5P1.6P1.7K1=0,K2=0○○○○○○○○K1=0,K2=1●●●●○○○○K1=1,K2=0●●○○●●○○K1=1,K2=1●●●●●●●●#includecharcodestyle[4]={0x0,0xf0,0x33,0xff};sbit
3、P1_0=P1^0;sbitP1_1=P1^1;voidmain(){P0=0xff;while(1){if(P1_0==0&&P1_1==0){P0=style[0];}if(P1_0==0&&P1_1==1){P0=style[1];}if(P1_0==1&&P1_1==0)..{P0=style[2];}if(P1_0==1&&P1_1==1){P0=style[3];}}}3.在一个数码管上循环显示“H”“E”“L”“L”“O”,循环的时间为1s。#includecharcodestyle[5]={0x89,0x86,0xc7,0x
4、c7,0xc0};inti;intcount=0;intsecond=0;voidt0Pro()interrupt1{count++;TL0=0xB0;TH0=0x3c;}voiddisplay(){..i=second%5;P0=style[i];}voidmain(){TMOD=0x01;EA=1;TR0=1;ET0=1;TL0=0xB0;TH0=0x3c;while(1){if(count==20){second++;count=0;}display();}}..4.在6个数码管上分别显示自己学号的后六位数字。#includechar
5、codecode1[]={0x4f,0x4f,0x01,0x06,0x06,0x4f};sbitp1_0=P1^0;charnum;voiddelay(inttimer){while(timer){--timer;}}voidmain(){inti;while(1){..num=0xFE;for(i=0;i<6;i++){P1=num;P2=code1[i];delay(1000);num=(num<<1)
6、1;}}}5.做一个简易30s的倒计时秒表,秒表的显示通过8个发光二极管显示出来。#include#include"stdio.h"i
7、ntcount;count=0;voidt0Proc()interrupt1{TH0=0x3c;TL0=0xb0;count++;if(count==10){P0=P0+1;..count=0;if(P0==0xff){P0=0xe1;}}}voidmain(){EA=1;ET0=1;TMOD=1;TH0=0x3c;TL0=0xb0;TR0=1;P0=0xe1;while(1);}6.使用外中断0来控制,去实现下列功能。其中K1为按键,P1口对应8个发光二极管的状态P1.0P1.1P1.2P1.3P1.4P1.5P1.6P1.7无按键按●●○○●●○○下(循
8、环)●●●●○○●●有按键按●●●●○○○○下..#include//sbitk1=P2^0;intcount=0;voiddelay(unsignedchari);voidint0Proc()interrupt0{count++;P1=0xf0;}voidmain(){EA=1;EX0=1;IT0=1;P1=0xcc;while(1){if(count%2==0){if(P1==0xcc){P1=0x30;delay(500);}else{P1=0xcc;delay(500);}}}}voiddelay(unsignedchari){un
9、signedcharj,k;for(k=0;k