单片机上机操作考试题部分答案
合集下载
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
{
TH0=0x3c;
TL0=0xb0;
if(++T_count==10)
{
P0=tab[i];
i=(i+1)%5;
T_count=0;
}
}
void main()
{
TMOD=1;
TH0=0x3c;
TL0=0xb0;
EA=1;
TR0=1;
ET0=1;
P0=tab[0];6个数码管上分别显示自己学号的后六位数字。
#include<>
#define uchar unsigned char
#define uint unsigned int
uchar code tab[]={0xbf,0x86,0xed};
uchar T_count=0;
uchar i=1;
void intoProc() interrupt 1
{
#include<>
#define uchar unsigned char
#define uint unsigned int
uchar code tab[]={0xf6,0xf9,0xb8,0xb8,0xbf};
uchar T_count=0;
uchar i=1;
void t0Proc() interrupt 1
{
case 0:
if(++T_count==10)
{
P1=~tab[i];
i=(i+1)%3;
T_count=0;
State=1;
}
break;
case 1:
if(++T_count==20)
{
P1=~tab[i];
i=(i+1)%3;
T_count=0;
State=2;
}
break;
case 2:
uchar T_count=0;
uchar i=0;
void delay(int x)
{
uchar i;
while(x--)
{
for(i=0;i<100;i++);
}
}
void t0Proc() interrupt 1
{
TH0=0x3c; 用外中断1来控制,当无按键按下时8个发光二极管循环点亮,循环点亮的时间为1s,有按键按下时,8个发光二极管全部熄灭。
#include<>
#define uchar unsigned char
#define uint unsigned int
void delay(uint x)
{
uchar i;
while(x--)
{
for(i=0;i<100;i++);
}
}
void main()
{
while(1)
{
P0=0xf7;一个20s的简易秒表,当按键K1按下时,秒表暂停计数,K2按下时,开始计数。
○
○
○
○
○
○
○
○
K1=0,K2=1
●
●
●
●
○
○
○
○
K1=1,K2=0
●
●
○
○
●
●
○
○
K1=1,K2=1
●
●
●
●
●
●
●
●
#include<>
#define uint unsigned int
#define uchar unsigned char
sbit k1=P3^2;
sbit k2=P3^3;
一个数码管上循环显示“H”“E” “L”“L”“O”,循环的时间为1s。
#define uint unsigned int
uchar code tab[]={0x05,0x06,0x03};
uchar T_count=0;
uchar State=0;
uchar i=1;
void t0Proc() interrupt 1
{
TH0=0x3c;
TL0=0xb0;
switch(State)
uchar i=1;
void t0Proc() interrupt 1
{
TH0=0x3c;
TL0=0xb0;
switch(State)
{
case 0:
if(++T_count==30)
{
P1=~tab[i];
i=(i+1)%4;
T_count=0;
State=1;
}
break;
case 1:
if(++T_count==10)
#include<>
#include<>
#define uchar unsigned char
#define uint unsigned int
uchar code tab[]={};一个简易30s的倒计时秒表,秒表的显示通过8个发光二极管显示出来。
#include<>
#define uchar unsigned char
#define uchar unsigned char
sbit k1=P3^2;
sbit k2=P3^3;
成下面电路的功能,P1口对应发光二极管的状态,状态1显示的时间为1s,状态2显示的时间为2s,状态3显示的时间为3s,如此循环
状态1
●
○
●
状态2
○
●
●
状态3
●
●
○
#include<>
#define uchar unsigned char
○
●
●
●
●
●
●
●
●
#include<>
#define uchar unsigned char
#define uint unsigned int
uchar code tab[]={0x0f,0xf0,0xcc,0x00};
uchar T_count=0;
uchar i=1;
void t0Proc() interrupt 1
void delay(int x)
{
uchar i;
while(x--)
{
for(i=0;i<120;i++);
}
}
void main()
{P0=taຫໍສະໝຸດ [0];P2=tab[1];
P3=tab[2];
P1=tab[3];
delay(500);
}
20. 完成下面电路的功能,P1口对应发光二极管的状态,状态1显示的时间为3s,状态2显示的时间为1s,状态3显示的时间为,状态4显示的时间为,如此循环
void delay1s()
{
uchar i;
for(i=0;i<10;i++)
{
TH1=0x3c;
TL1=0xb0;
TR1=1;用外中断0来控制,去实现下列功能。
其中K1为按键,P1口对应8个发光二极管的状态
无按键按下(循环)
●
●
○
○
●
●
○
○
●
●
●
●
○
○
●
●
有按键按下
●
●
●
●
○
○
○
○
#include<>
uchar State=0;
uchar T_count=0;
uchar i=1;
void t0Proc() interrupt 1
{
TH0=0x3c;
TL0=0xb0;
switch(State)
{
case 0:
if(++T_count==20)
{
P2=tab[i];
i=(i+1)%8;
if(i==7)
{
P1=~tab[i];
i=(i+1)%4;
T_count=0;
State=2;
}
break;
case 2:
if(++T_count==5)
{
P1=~tab[i];
i=(i+1)%4;
T_count=0;
State=3;
}
break;
case 3:
if(++T_count==1)
{
P1=~tab[i];
TH0=0x3c;
TL0=0xb0;
if(++T_count==10)
{
P0=tab[i];
i=(i+1)%3;
T_count=0;
}
}
void main()
{
TMOD=1;
TH0=0x3c;
TL0=0xb0;
EA=1;
TR0=1;
ET0=1;
P0=tab[0];4个数码管上稳定显示出“A” “C”“E” “P”四个字符。
#include<>
#include<>
#define uchar unsigned char
uchar code tab[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
uchar code tab1[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
EA=1;
ET0=1;
TR0=1;
P2=tab[0];
while(1);
}
19.在4个数码管上显示出当天的日期。
#include<>
#define uchar unsigned char
#define uint unsigned int
uchar code tab[]={0x06,0x5b,0x06,0x6f};
if(++T_count==30)
{
P1=~tab[i];
i=(i+1)%3;
i=1;
T_count=0;
State=0;
}
break;
}
}
void main()
{
TMOD=1;
TH0=0x3c;
TL0=0xb0;
EA=1;
ET0=1;
TR0=1;
P1=~tab[0];
while(1);
}
18.彩灯系统,实现8个发光二极管从左到右点亮,每个发光二极管点亮的时间为2s,然后从右到左亮,每个发光二极管点亮的时间为.
#include<>
#define uint unsigned int
#define uchar unsigned char
uchar tab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
sbit k1=P3^2;
sbit k2=P3^3;
#define uint unsigned int
#define uchar unsigned char
uchar code tab[]={0xcc,0x30};
sbit k1=P3^2;
采用定时器方式1使得8个发光二极管按如下方式点亮,循环的时间为2s
○
○
○
○
●
●
●
●
●
●
●
●
○
○
○
○
●
●
○
○
●
●
○
#include<>
#define uchar unsigned char
#define uint unsigned int
uchar code tab1[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uchar code tab2[]={0x6f,0x7f,0x07,0x7d,0x6d,0x66,0x4f,0x5b,0x06,0x3f};
uchar T_count=0;
sbit k1=P1^0;
{
TH0=0x3c;
TL0=0xb0;
if(++T_count==20)
{
P0=tab[i];
i=(i+1)%4;
T_count=0;
}
}
void main()
{
TMOD=1;
TH0=0x3c;
TL0=0xb0;
EA=1;
TR0=1;
ET0=1;
P0=tab[0]; 一个数码管上循环显示“0” “1” “5” 3个数字,循环的时间为1s。
{
State=1;
}
T_count=0;
}
break;
case 1:
if(++T_count==15)
{
i=(i+1)%8;
P2=tab1[i];
if(i==7)
{
State=0;
i=1;
}
T_count=0;
}
break;
}
}
void main()
{
TMOD=1;
TH0=0x3c;
TL0=0xb0;
1.使得8个发光二极管循环点亮,采用定时器方式0使得每个发光二极管点亮的时间为。
#include<>
#include<>
#define uchar unsigned char
uchar T_count=0;
成下面电路所示的功能,K1,K2对应两个开关按键。P1口对应发光二极管的状态
K1=0,K2=0
uchar i=1;
完成下面电路所示的功能,K1,K2对应两个开关按键。P1口对应发光二极管的状态
K1=0,K2=0
●
●
●
●
●
●
●
●
K1=0,K2=1
●
●
●
●
○
○
○
○
K1=1,K2=0
○
○
○
○
●
●
○
○
K1=1,K2=1
○
●
○
●
○
●
○
●
#include<>
#define uint unsigned int
状态1
○
○
●
●
状态2
○
●
●
●
状态3
●
●
●
●
状态4
○
○
○
○
#include<>
#define uchar unsigned char
#define uint unsigned int
uchar code tab[]={0x0c,0x0e,0x0f,0x00};
uchar T_count=0;
uchar State=0;
i=(i+1)%4;
T_count=0;
State=0;
}
break;
}
}
void main()
TH0=0x3c;
TL0=0xb0;
if(++T_count==10)
{
P0=tab[i];
i=(i+1)%5;
T_count=0;
}
}
void main()
{
TMOD=1;
TH0=0x3c;
TL0=0xb0;
EA=1;
TR0=1;
ET0=1;
P0=tab[0];6个数码管上分别显示自己学号的后六位数字。
#include<>
#define uchar unsigned char
#define uint unsigned int
uchar code tab[]={0xbf,0x86,0xed};
uchar T_count=0;
uchar i=1;
void intoProc() interrupt 1
{
#include<>
#define uchar unsigned char
#define uint unsigned int
uchar code tab[]={0xf6,0xf9,0xb8,0xb8,0xbf};
uchar T_count=0;
uchar i=1;
void t0Proc() interrupt 1
{
case 0:
if(++T_count==10)
{
P1=~tab[i];
i=(i+1)%3;
T_count=0;
State=1;
}
break;
case 1:
if(++T_count==20)
{
P1=~tab[i];
i=(i+1)%3;
T_count=0;
State=2;
}
break;
case 2:
uchar T_count=0;
uchar i=0;
void delay(int x)
{
uchar i;
while(x--)
{
for(i=0;i<100;i++);
}
}
void t0Proc() interrupt 1
{
TH0=0x3c; 用外中断1来控制,当无按键按下时8个发光二极管循环点亮,循环点亮的时间为1s,有按键按下时,8个发光二极管全部熄灭。
#include<>
#define uchar unsigned char
#define uint unsigned int
void delay(uint x)
{
uchar i;
while(x--)
{
for(i=0;i<100;i++);
}
}
void main()
{
while(1)
{
P0=0xf7;一个20s的简易秒表,当按键K1按下时,秒表暂停计数,K2按下时,开始计数。
○
○
○
○
○
○
○
○
K1=0,K2=1
●
●
●
●
○
○
○
○
K1=1,K2=0
●
●
○
○
●
●
○
○
K1=1,K2=1
●
●
●
●
●
●
●
●
#include<>
#define uint unsigned int
#define uchar unsigned char
sbit k1=P3^2;
sbit k2=P3^3;
一个数码管上循环显示“H”“E” “L”“L”“O”,循环的时间为1s。
#define uint unsigned int
uchar code tab[]={0x05,0x06,0x03};
uchar T_count=0;
uchar State=0;
uchar i=1;
void t0Proc() interrupt 1
{
TH0=0x3c;
TL0=0xb0;
switch(State)
uchar i=1;
void t0Proc() interrupt 1
{
TH0=0x3c;
TL0=0xb0;
switch(State)
{
case 0:
if(++T_count==30)
{
P1=~tab[i];
i=(i+1)%4;
T_count=0;
State=1;
}
break;
case 1:
if(++T_count==10)
#include<>
#include<>
#define uchar unsigned char
#define uint unsigned int
uchar code tab[]={};一个简易30s的倒计时秒表,秒表的显示通过8个发光二极管显示出来。
#include<>
#define uchar unsigned char
#define uchar unsigned char
sbit k1=P3^2;
sbit k2=P3^3;
成下面电路的功能,P1口对应发光二极管的状态,状态1显示的时间为1s,状态2显示的时间为2s,状态3显示的时间为3s,如此循环
状态1
●
○
●
状态2
○
●
●
状态3
●
●
○
#include<>
#define uchar unsigned char
○
●
●
●
●
●
●
●
●
#include<>
#define uchar unsigned char
#define uint unsigned int
uchar code tab[]={0x0f,0xf0,0xcc,0x00};
uchar T_count=0;
uchar i=1;
void t0Proc() interrupt 1
void delay(int x)
{
uchar i;
while(x--)
{
for(i=0;i<120;i++);
}
}
void main()
{P0=taຫໍສະໝຸດ [0];P2=tab[1];
P3=tab[2];
P1=tab[3];
delay(500);
}
20. 完成下面电路的功能,P1口对应发光二极管的状态,状态1显示的时间为3s,状态2显示的时间为1s,状态3显示的时间为,状态4显示的时间为,如此循环
void delay1s()
{
uchar i;
for(i=0;i<10;i++)
{
TH1=0x3c;
TL1=0xb0;
TR1=1;用外中断0来控制,去实现下列功能。
其中K1为按键,P1口对应8个发光二极管的状态
无按键按下(循环)
●
●
○
○
●
●
○
○
●
●
●
●
○
○
●
●
有按键按下
●
●
●
●
○
○
○
○
#include<>
uchar State=0;
uchar T_count=0;
uchar i=1;
void t0Proc() interrupt 1
{
TH0=0x3c;
TL0=0xb0;
switch(State)
{
case 0:
if(++T_count==20)
{
P2=tab[i];
i=(i+1)%8;
if(i==7)
{
P1=~tab[i];
i=(i+1)%4;
T_count=0;
State=2;
}
break;
case 2:
if(++T_count==5)
{
P1=~tab[i];
i=(i+1)%4;
T_count=0;
State=3;
}
break;
case 3:
if(++T_count==1)
{
P1=~tab[i];
TH0=0x3c;
TL0=0xb0;
if(++T_count==10)
{
P0=tab[i];
i=(i+1)%3;
T_count=0;
}
}
void main()
{
TMOD=1;
TH0=0x3c;
TL0=0xb0;
EA=1;
TR0=1;
ET0=1;
P0=tab[0];4个数码管上稳定显示出“A” “C”“E” “P”四个字符。
#include<>
#include<>
#define uchar unsigned char
uchar code tab[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
uchar code tab1[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
EA=1;
ET0=1;
TR0=1;
P2=tab[0];
while(1);
}
19.在4个数码管上显示出当天的日期。
#include<>
#define uchar unsigned char
#define uint unsigned int
uchar code tab[]={0x06,0x5b,0x06,0x6f};
if(++T_count==30)
{
P1=~tab[i];
i=(i+1)%3;
i=1;
T_count=0;
State=0;
}
break;
}
}
void main()
{
TMOD=1;
TH0=0x3c;
TL0=0xb0;
EA=1;
ET0=1;
TR0=1;
P1=~tab[0];
while(1);
}
18.彩灯系统,实现8个发光二极管从左到右点亮,每个发光二极管点亮的时间为2s,然后从右到左亮,每个发光二极管点亮的时间为.
#include<>
#define uint unsigned int
#define uchar unsigned char
uchar tab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
sbit k1=P3^2;
sbit k2=P3^3;
#define uint unsigned int
#define uchar unsigned char
uchar code tab[]={0xcc,0x30};
sbit k1=P3^2;
采用定时器方式1使得8个发光二极管按如下方式点亮,循环的时间为2s
○
○
○
○
●
●
●
●
●
●
●
●
○
○
○
○
●
●
○
○
●
●
○
#include<>
#define uchar unsigned char
#define uint unsigned int
uchar code tab1[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uchar code tab2[]={0x6f,0x7f,0x07,0x7d,0x6d,0x66,0x4f,0x5b,0x06,0x3f};
uchar T_count=0;
sbit k1=P1^0;
{
TH0=0x3c;
TL0=0xb0;
if(++T_count==20)
{
P0=tab[i];
i=(i+1)%4;
T_count=0;
}
}
void main()
{
TMOD=1;
TH0=0x3c;
TL0=0xb0;
EA=1;
TR0=1;
ET0=1;
P0=tab[0]; 一个数码管上循环显示“0” “1” “5” 3个数字,循环的时间为1s。
{
State=1;
}
T_count=0;
}
break;
case 1:
if(++T_count==15)
{
i=(i+1)%8;
P2=tab1[i];
if(i==7)
{
State=0;
i=1;
}
T_count=0;
}
break;
}
}
void main()
{
TMOD=1;
TH0=0x3c;
TL0=0xb0;
1.使得8个发光二极管循环点亮,采用定时器方式0使得每个发光二极管点亮的时间为。
#include<>
#include<>
#define uchar unsigned char
uchar T_count=0;
成下面电路所示的功能,K1,K2对应两个开关按键。P1口对应发光二极管的状态
K1=0,K2=0
uchar i=1;
完成下面电路所示的功能,K1,K2对应两个开关按键。P1口对应发光二极管的状态
K1=0,K2=0
●
●
●
●
●
●
●
●
K1=0,K2=1
●
●
●
●
○
○
○
○
K1=1,K2=0
○
○
○
○
●
●
○
○
K1=1,K2=1
○
●
○
●
○
●
○
●
#include<>
#define uint unsigned int
状态1
○
○
●
●
状态2
○
●
●
●
状态3
●
●
●
●
状态4
○
○
○
○
#include<>
#define uchar unsigned char
#define uint unsigned int
uchar code tab[]={0x0c,0x0e,0x0f,0x00};
uchar T_count=0;
uchar State=0;
i=(i+1)%4;
T_count=0;
State=0;
}
break;
}
}
void main()