单片机上机操作测验题部分答案.docVIP

  • 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的倒计时秒表,秒表的显

文档评论(0)

1亿VIP精品文档

相关文档