- 2
- 0
- 约1.45万字
- 约 41页
- 2019-09-02 发布于江苏
- 举报
单片机上机操作测验题部分答案
———————————————————————————————— 作者:
———————————————————————————————— 日期:
使得8个发光二极管循环点亮,采用定时器方式0使得每个发光二极管点亮的时间为0.5s。
#includereg51.h
#includeintrins.h
#define uchar unsigned char
uchar T_count=0;
//定时中断
void toProc() interrupt 1
{
TH0=(8192-5000)/32; //恢复初值
TL0=(8192-5000)%32;
if(++T_count==100) //0.5s移动一位
{
P0=_crol_(P0,1);
T_count=0;
}
}
//主函数
void main()
{
TMOD=0;
TH0=(8192-5000)/32; //5ms定时
TL0=(8192-5000)%32;
EA=1;
ET0=1;
TR0=1;
P0=0xfe;
while(1);
}
2.完成下面电路所示的功能,K1,K2对应两个开关按键。P1口对应发光二极管的状态
P1.0
P1.1
P1.2
P1.3
P1.4
P1.5
P1.6
P1.7
K1=0,K2=0
○
○
○
○
○
○
○
○
K1=0,K2=1
●
●
●
●
○
○
○
○
K1=1,K2=0
●
●
○
○
●
●
○
○
K1=1,K2=1
●
●
●
●
●
●
●
●
#includereg51.h
#define uint unsigned int
#define uchar unsigned char
sbit k1=P3^2;
sbit k2=P3^3;
//延时
void delay(uint x)
{
uchar i;
while(--x)
{
for(i=0;i120;i++);
}
}
//主函数
void main()
{
while(1)
{
if((k1==0)(k2==0)) //K1、K2同时按下
{
P1=0x00;
delay(10);
}
else if((k1==0)(k2==1)) //K1按下,K2不按
{
P1=0xcc;
delay(10);
}
else if((k1==1)(k2==0)) //K2按下,K1不按
{
P1=0xf0;
delay(10);
}
else
{
P1=0xff;
delay(10);
}
}
}
3.在一个数码管上循环显示“H”“E” “L” “L” “O” ,循环的时间为1s。
#includereg51.h
#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
{
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]; //初始化P0口
while(1);
}
4.在6个数码管上分别显示自己学号的后六位数字。
#includereg51.h
#includeintrins.h
#define uchar unsigned char
#define uint unsigned int
uchar code tab[]={};//学号自己设置
//延时
void delay(uint x)
{
uchar i;
while(x--)
{
for(i=0;i100;i++);
}
}
//主函数
void main()
{
uchar k;
uchar wei=0x01;
P0=~tab[0];
P2=0x01;
delay(1000);
while(1)
{
for(k=1;k6;k++)
{
wei=wei1;
P0=~tab[k]; //发送数字段码
P2=wei; //发送位码
delay(1000);
}
}
}
5.做一个简易30s的倒计时秒表,秒表的显
您可能关注的文档
最近下载
- 栽培措施对青贮玉米粗蛋白质含量及产量的影响.pdf VIP
- EN IEC 62660-3-2022 Secondary lithium-ion cells for the propulsion of electric road vehicles - Part 3:Safety requirements 电动道路车辆推进用二次锂离子电池. 第3部分: 安全要求.pdf
- 2024年江苏省淮安市中考语文真题试卷含答案.docx
- 安全员(矿山)试题库含参考答案.docx VIP
- 矿山安全员试题库(附参考答案).docx VIP
- Honor荣耀MagicBook Pro 14 用户手册-(FMB-P,01,zh-cn)说明书.pdf
- 选矿厂设计考试试卷及答案.docx VIP
- 社会工作者(初级)考试题库及答案【题库版】.pdf VIP
- 融媒体中心新媒体制作岗位专业测试及答案.docx VIP
- 高考物理一轮复习6.2机械能守恒定律-动能定理及其应用--(原卷版+解析).docx VIP
原创力文档

文档评论(0)