您好,欢迎访问三七文档
当前位置:首页 > 电子/通信 > 综合/其它 > AT89C51单片机开发板程序
AT89C51单片机开发板程序1个LED数码管静态显示0-9)includereg52.h#defineucharunsignedchar#defineuintunsignedintuchari。ucharcodea[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}。voiddelay(uintz。voidmain({while(1{for(i=0。i10。i++{P2=0xfe。P0=a[i]。delay(1000。}}}voiddelay(uintz{uintx,y。for(x=z。x0。x--for(y=122。y0。y--。}LED数码管显示0-99)#includereg52.hunsignedcharcount,num。unsignedcharcodetable[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}。voidmain({P2=0xfe。IE=0x82。TMOD=0x01。TCON=0x30。while(1。}voidTOINT(interrupt1{TH0=0xd8。TL0=0xf0。if(P2&1P1=table[num/10]。elseP1=table[num%10]。P2^=3。if(++count100return。count=0。if(++num99num=0。}定时控制一只闪亮的灯#includereg51.h#defineucharunsignedchar#defineuintunsignedintuintn。sbitled=P0^0。voidmain({TMOD&=0xf1。TMOD|=0x01。TH0=(65536-10000/256。TL0=(65536-10000%256。EA=1。ET0=1。TR0=1。while(1{}}voidtimer0(interrupt1{TH0=(65536-10000/256。TL0=(65536-10000%256。n++。if(n==100{n=0。led=~led。}}用独立键盘显示LED数码管1-4)#includereg52.h#defineucharunsignedchar#defineuintunsignedintucharcodea[]={0xc0,0xf9,0xa4,0xb0,0x99,0xff}。voiddelay(uintz。voidmain({ucharb,c。c=5。while(1{P0|=0x0f。b=P0。b&=0x0f。if(b!=0x0f{delay(20。P0|=0x0f。b=P0。b&=0x0f。if(b!=0x0f{switch(b{case0x0e:c=1。break。case0x0d:c=2。break。case0x0b:c=3。break。case0x07:c=4。break。default:c=0。}}}P1&=0xfe。P2=a[c]。}}voiddelay(uintz{uintx,y。for(x=z。x0。x--for(y=122。y0。y--。}用矩阵键盘显示LED数码管0-9,A-F)#includereg52.h#defineuintunsignedint#defineucharunsignedcharucharcodea[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0xff}。voiddelay(uintz。sbithang1=P0^3。sbithang2=P0^2。sbithang3=P0^1。sbithang4=P0^0。voidmain({ucharb,c。c=16。while(1{hang1=0。hang2=1。hang3=1。hang4=1。P0|=0xf0。b=P0。b&=0xf0。if(b!=0xf0{delay(10。P0|=0xf0。b=P0。b&=0xf0。if(b!=0xf0{switch(b{case0xe0:c=0。break。case0xd0:c=1。break。case0xb0:c=2。break。case0x70:c=3。break。default:c=16。}}}P3&=0xf0。P2=a[c]。hang1=1。hang2=0。hang3=1。hang4=1。P0|=0xf0。b=P0。b&=0xf0。if(b!=0xf0{delay(10。P0|=0xf0。b=P0。b&=0xf0。if(b!=0xf0{switch(b{case0xe0:c=4。break。case0xd0:c=5。break。case0xb0:c=6。break。case0x70:c=7。break。default:c=16。}}}P3&=0xf0。P2=a[c]。hang1=1。hang2=1。hang3=0。hang4=1。P0|=0xf0。b=P0。b&=0xf0。if(b!=0xf0{delay(10。P0|=0xf0。b=P0。b&=0xf0。if(b!=0xf0{switch(b{case0xe0:c=8。break。case0xd0:c=9。break。case0xb0:c=10。break。case0x70:c=11。break。default:c=16。}}}P3&=0xf0。P2=a[c]。hang1=1。hang2=1。hang3=1。hang4=0。P0|=0xf0。b=P0。b&=0xf0。if(b!=0xf0{delay(10。P0|=0xf0。b=P0。b&=0xf0。if(b!=0xf0{switch(b{case0xe0:c=12。break。case0xd0:c=13。break。case0xb0:c=14。break。case0x70:c=15。break。default:c=16。}}}P3&=0xf0。P2=a[c]。}}voiddelay(uintz{uintx,y。for(x=z。x0。x--for(y=122。y0。y--。}一只闪亮的灯#includereg52.h#defineucharunsignedchar#defineuintunsignedintsbitled=P2^0。voiddelay(uintz。voidmain({led=0。delay(1000。led=1。delay(1000。}voiddelay(uintz{uintx。uinty。for(x=z。x0。x--for(y=122。y0。y--。}中断控制流水灯(从右向左#includereg52.h#includeintrins.h#defineucharunsignedchar#defineuintunsignedintucharled,temp。voiddelay(uintz。voidmain({EA=1。EX1=1。temp=0x7f。while(1{P2=temp。temp=_cror_(temp,1。delay(1000。}}voiddelay(uintz{uintx,y。for(x=z。x0。x--for(y=122。y0。y--。}voidextern1(interrupt2{P2=0x00。delay(2000。P2=0xff。delay(2000。}中断控制流水灯(从左向右#includereg52.h#includeintrins.h#defineucharunsignedchar#defineuintunsignedintucharled,temp。voiddelay(uintz。voidmain({EA=1。EX1=1。temp=0xfe。while(1{P2=temp。temp=_crol_(temp,1。delay(1000。}}voiddelay(uintz{uintx,y。for(x=z。x0。x--for(y=122。y0。y--。}voidextern1(interrupt2{P2=0x00。delay(2000。P2=0xff。delay(2000。}1位密码锁#includereg52.h#defineucharunsignedchar#defineuintunsignedint#definemima3#defineduanmaP1sbitweima=P3^0。sbitredled=P0^5。sbitgreenled=P0^6。ucharkey=0xff。voidscankey(。voiddelay(uintz。voidmain({weima=0。while(1{duanma=0xbf。redled=1。greenled=1。scankey(。if(key==mima{duanma=0x8c。greenled=0。delay(3000。key=0xff。}if(key!=0xff{duanma=0x86。redled=0。delay(3000。key=0xff。}else{duanma=0xbf。redled=1。greenled=1。}}}voidscankey({ucharkeyinput。P0|=0x0f。keyinput=P0。keyinput&=0x0f。if(keyinput!=0x0f{delay(10。P0|=0x0f。keyinput=P0。keyinput&=0x0f。if(keyinput!=0x0f{switch(keyinput{case0x0e:key=0。break。case0x0d:key=1。break。case0x0b:key=2。break。case0x07:key=3。break。default:key=0xff。}}}}voiddelay(uintz{uintx,y。for(x=z。x0。x--for(y=122。y0。y--。}电子钟#includereg52.h#defineucharunsignedchar#defineuintunsignedintucharcodeduan[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}。ucharcodewei[]={0xfe,0xfd,0xfb,0xf7}。uchartt,i,sec,min。ucharxianshi[4]。voiddelay(uintz。voidinit(。voidmain({init(。while(1{if(tt=20{tt=0。sec++。if(sec==60{sec=0。min++。if(min==60{min=0。}}}xianshi[0]=duan[sec%10]。xianshi[1]=duan[sec/10]。xianshi[2]=duan[min%10]。xianshi[3]=duan[min/10]。for(i=0。i4。i++{P2=xianshi[i]。P0=wei[i]。delay(5。}}}voidinit({TMOD&=0XF1。TMOD|=0X01。TH0=(65536-50000/256。TL0=(65536-50000%256。EA=1。ET0=1。TR0=1。}voidtimer0(interrupt1{TH0=(65536-50000/256。TL0=(65536-50000%256。tt++。}voiddelay(uintz{uintx,y。for(x=z。x0。x--for(y=122。y0。y--。}交通灯#includereg52
本文标题:AT89C51单片机开发板程序
链接地址:https://www.777doc.com/doc-4742620 .html