资源描述:
《C51单片机程序电子教案.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、1.定时器实验程序:#include#include#defineuintunsignedint#defineucharunsignedcharuchartemp,bai,shi,ge,aa,cnt;ucharcodetable[]={0x28,0x7e,0xa2,0x62,0x74,0x61,0x21,0x7a,0x20,0x60};voiddelay(uintz);voidinit();voiddisplay(ucharbai,ucharshi,ucharg
2、e);voidmain(){init();while(1){if(aa==20){aa=0;temp++;if(temp==1001){temp=0;}bai=temp/100;shi=temp%100/10;ge=temp%10;}display(bai,shi,ge);}}voiddelay(uintz){uintx,y;for(x=z;x>0;x--)for(y=110;y>0;y--);}voiddisplay(ucharbai,ucharshi,ucharge){P0=table[bai];
3、P2=0xfe;delay(1);P0=table[shi];P2=0xfd;delay(1);P0=table[ge];P2=0xfb;delay(1);}voidinit(){aa=0;cnt=0;temp=0;P1=0xfe;TMOD=0X11;//T1、T0工作方式均为1TH0=(65536-50000)/256;TL0=(65536-50000)%256;//计时50msTH1=(65536-50000)/256;TL1=(65536-50000)%256;EA=1;ET0=1;TR0=1;
4、//使能T1,T0ET1=1;TR1=1;}voidtimer0()interrupt1{TH0=(65536-50000)/256;TL0=(65536-50000)%256;aa++;}voidtimer1()interrupt3{TH1=(65536-50000)/256;TL1=(65536-50000)%256;cnt++;if(cnt>=20){cnt=0;P1=_crol_(P1,1);//流水灯}}2.矩阵键盘试验程序:#include#include5、.h>#defineucharunsignedchar#defineuintunsignedintcharcodeSST516[3]_at_0x003b;chartable[17]={0x28,0x7e,0xa2,0x62,0x74,0x61,0x21,0x7a,0x20,0x60,0x30,0x25,0xa9,0x26,0xa1,0xb1};uchardis_buf,buf;uchartemp;ucharkey;voiddelay(ucharx)//延时函数{ucharj;while((x--)!=
6、0){for(j=0;j<125;j++);}}/*键扫描子程序*/voidkeyscan(void){P1=0x0F;delay(1);temp=P1;temp=temp&0x0F;temp=~(temp
7、0xF0);if(temp==1)key=0;elseif(temp==2)key=1;elseif(temp==4)key=2;elseif(temp==8)key=3;elsekey=16;P1=0xF0;delay(1);temp=P1;temp=temp&0xF0;temp=~((temp
8、>>4)
9、0xF0);if(temp==1)key=key+0;elseif(temp==2)key=key+4;elseif(temp==4)key=key+8;elseif(temp==8)key=key+12;elsekey=16;dis_buf=table[key];//改变后键值赋给dis_buf}voidkeydown(void){P1=0xF0;if(P1!=0xF0)//P1状态改变说明有键按下{keyscan();while(P1!=0xF0);}}main(){P0=0xFF;P2
10、=0x7F;dis_buf=0xBF;buf=0xBF;//备份dis_bufwhile(1){keydown();P0=dis_buf;//键值送显示if(dis_buf!=buf)//当dis_buf改变时,说明键值改变{dis_buf=buf;P2=_crol_(P2,1);//数码管移位显示}delay(2);}}审核标识一览表被审核单位:编制人:日期:索引号:截止日/期间:复核人:日期:页次:本所注册会计师在编制审核工作底稿时,可采用审核标识代