预览加载中,请您耐心等待几秒...
1/10
2/10
3/10
4/10
5/10
6/10
7/10
8/10
9/10
10/10

亲,该文档总共26页,到这已经超出免费预览范围,如果喜欢就直接下载吧~

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

显示键盘扫描动态显示#include<REG51.H> constunsignedcharseg[10]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90}; delay(); main() {unsignedcharcout,t,i,a[6]={1,2,3,4,5,6};//{8,9,12,5,1} while(1) {cout=0x20; for(i=0;i<6;i++) {t=a[i]; P0=seg[t]; P2=cout; delay(); cout=cout>>1; P0=0xff;//灭显示 } } } delay() {unsignedchari=250; while(i--); } 思考:思考题(1)程序清单思考题(2)程序清单三+1秒定时显示Main()例2-4 #include<REG51.H> constunsignedcharseg[10]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90}; unsignedcharcout=0,sec=0,time[2]={0};//全局变量,cout,中断次数,sec,秒单元变量,time[2]显示缓冲区 Voiddisplay();//动态显示 Voiddelay();//延时 main() {TMOD=0X01; TH0=0X3C; TL0=0XB0; ET0=1; EA=1; TR0=1; while(1)display(); }Voiddisplay() {unsignedcharb=0x02,t,i; for(i=0;i<2;i++) {t=time[i]; P0=seg[t]; P2=b; b=b>>1; delay(); P0=0xff; } } Voiddelay() {unsignedchari=250; while(i--); } at0()interrupt1 {TH0=0X3C; TL0=0XB0; cout++; if(cout==20) {cout=0; sec++; if(sec==60) sec=0; time[0]=sec/10; time[1]=sec%10; } } 思考题实验思考题程序清单voiddisplay() {unsignedcharb=0x20,t,i; for(i=0;i<6;i++) {t=time[5-i]; P0=seg[t]; P2=b; b=b>>1; delay(); P0=0xff; } } voiddelay() {unsignedchari=250; while(i--); } at0()interrupt1 {TH0=0X3C; TL0=0XB0; cout++; if(cout==20) {cout=0; sec++; if(sec==60) {sec=0; min++; if(min==60) {min=0; hour++; if(hour==24)hour=0; time[4]=hour%10; time[5]=hour/10; } time[2]=min%10; time[3]=min/10; } time[0]=sec%10; time[1]=sec/10; } }思考题:交通灯问题#include"at89x51.h" unsignedcharcount; bitflag; unsignedchardis[4]={0,0,0,0}; constunsignedcharseg[10]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90}; voiddisp(unsignedchar*dis); voidT0_srv(void)interrupt1using1 {TL0=-50000%256; TH0=-50000/256; count++; if(count==20) {count=0; flag=1; } } voiddelay() {unsignedchari=250; while(i--); } voiddisp() {unsignedcharb=0x08,t,i; for(i=0;i<4;i++) {t=dis[i]; P0=seg[t]; P2=b; b=b>>1; delay(); P0=0xff; } }main() {unsignedcharsum,a,b,c,d; TMOD=0X01;TL0=-50000%256;TH0=-50000/256; ET0=1;EA=1;TR0=1;P1=0xff;sum=0;a=