1、单片机上机操作考试题及答案单片机上机考试试题1.使得8个发光二极管循环点亮,采用定时器方式0使得每个发光二极管点亮的时间为0.5s。#include int count=0;int minute=0;int temp;char code style8=0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe;void desplay() temp=minute%8; P0= styletemp;void toProc() interrupt 1 count+; TH0=0x0c; TL0=0x78;void main() TMOD=0; TH0=0x0c; TL0=0x7
2、8; 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=0K1=0,K2=1K1=1,K2=0K1=1,K2=1#include char code style4=0x0,0xf0,0x33,0xff;sbit P1_0=P10;sbit P1_1=P11;void main() P0=0xff; while(1) if(P1_0=0&P1_
3、1=0) P0=style0; if(P1_0=0&P1_1=1) P0=style1; if(P1_0=1&P1_1=0) P0=style2; if(P1_0=1&P1_1=1) P0=style3; 3.在一个数码管上循环显示“H”“E”“L”“L”“O” ,循环的时间为1s。#include char code style5=0x89,0x86,0xc7,0xc7,0xc0;int i;int count=0;int second=0;void t0Pro() interrupt 1 count+; TL0=0xB0; TH0=0x3c; void display() i=second
4、%5; P0=stylei; void main() TMOD=0x01; EA=1; TR0=1; ET0=1; TL0=0xB0; TH0=0x3c; while(1) if(count=20) second+; count=0; display(); 4.在6个数码管上分别显示自己学号的后六位数字。#includechar code code1=0x4f,0x4f,0x01,0x06,0x06,0x4f;sbit p1_0=P10;char num;void delay(int timer) while(timer) -timer; void main() int i; while(1)
5、 num =0xFE; for(i=0;i6;i+) P1=num; P2=code1i; delay(1000); num=(num1)|1; 5.做一个简易30s的倒计时秒表,秒表的显示通过8个发光二极管显示出来。#include#includestdio.hint count;count=0;void t0Proc() interrupt 1 TH0=0x3c; TL0=0xb0; count+; if(count=10) P0=P0+1; count=0; if(P0=0xff) P0=0xe1; void main() EA=1; ET0=1; TMOD=1; TH0=0x3c; T
6、L0=0xb0; TR0=1; P0=0xe1; while(1); 6.使用外中断0来控制,去实现下列功能。其中K1为按键,P1口对应8个发光二极管的状态P1.0P1.1P1.2P1.3P1.4P1.5P1.6P1.7无按键按下(循环)有按键按下#include /sbit k1=P20; int count=0;void delay(unsigned char i); void int0Proc() interrupt 0 count+; P1=0xf0;void main() EA=1; EX0=1; IT0=1; P1=0xcc; while(1) if(count%2=0) if(P
7、1=0xcc) P1=0x30; delay(500); else P1=0xcc; delay(500); void delay(unsigned char i) unsigned char j,k; for(k=0;ki;k+) for(j=0;j255;j+); 7.通过A/D转换电路,将模拟电压值在两个发光二极管上显示出来。(查询和中断方式均可)#include#include#define a XBYTE0xcfa8sbit p=P32;sbit shi=P34;sbit ge=P35;void sepr(unsigned char w);void disp();unsigned c
8、har i,x,chh,chl;void main() while(1) adc0809=0; while(p); x=adc0809; sepr(x); disp();void sepr(unsigned char w)unsigned char ch;ch=w;chh=ch/51;ch=ch%51;,chl=(ch*10)/51;void disp()unsigned char led1=0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f;unsigned char led2=0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xf
9、d,0x87,0xff,0xef ;shi=0;ge=1;a=led2chh;for(i=0;i50;i+);shi=1;ge=0;a=led1chl;for(i=0;i50;i+);8. 采用定时器方式1使得8个发光二极管按如下方式点亮,循环的时间为2sP1.0P1.1P1.2P1.3P1.4P1.5P1.6P1.7#include char code style4=0x0f,0xf0,0xcc,0xff;int i;int count=0;int second=0;void t0Pro() interrupt 1 count+; TL0=0xB0; TH0=0x3c; void displ
10、ay() i=second%4; P0=stylei; void main() TMOD=0x01; EA=1; TR0=1; ET0=1; TL0=0xB0; TH0=0x3c; while(1) if(count=40) second+; count=0; display(); 9.在一个数码管上循环显示“0”“1”“5” 3个数字,循环的时间为1s。#include char code style3=0xc0,0xf9,0x92;int i;int count=0;int second=0;void t0Pro() interrupt 1 count+; TL0=0xB0; TH0=0x
11、3c; void display() i=second%3; P0=stylei; void main() TMOD=0x01; EA=1; TR0=1; ET0=1; TL0=0xB0; TH0=0x3c; while(1) if(count=20) second+; count=0; display(); 10.在4个数码管上稳定显示出“A”“C”“E”“P” 四个字符。#include char code style4=0x88,0xc6,0x86,0x8c;void main() while(1) P0=style0; P2=style1; P3=style2; P1=style3; 11.试采用定时方式2,在P1.0引脚上输出频率为1KHz的方波(可能有问题)#includeint count;count=0;sbit p1_0=P10;void t0Proc() interrupt 1 p1_0=p1_0; void main() EA=1; ET0=
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1