您好,欢迎访问三七文档
当前位置:首页 > 电子/通信 > 综合/其它 > 郭天祥单片机程序.doc
Lesson2-1#includereg52.hsbitp1_1=P1^0unsignedintavoidmain(){while(1){a=51000;p1_1=0;while(a--);a=51000;while(a--);p1_1=1;a=51000;while(a--);a=51000;while(a--);}}Lesson2-2#includereg52.h#defineuintunsignedint#defineucharunsignedcharsbitD1=P1^0;//voiddelay();voiddelay(uint);voidmain(){while(1){D1=0;delay(100);D1=1;delay(100);}}/*voiddelay(){uintx,y;for(x=100;x0;x--)for(y=600;y0;y--);}*/voiddelay(uintz){uintx;uchary;for(x=z;x0;x--)for(y=20;y0;y--);}Lesson2-3#includereg52.h#includeintrins.h#defineuintunsignedint#defineucharunsignedcharuchartemp,num,num1;sbitbeep=P2^3;voiddelay(uint);voidmain(){temp=0xfe;while(1){for(num1=0;num13;num1++){for(num=0;num8;num++){P1=temp;beep=0;delay(100);temp=_crol_(temp,1);P1=0xff;beep=1;delay(100);}}for(num1=0;num13;num1++){for(num=0;num8;num++){P1=temp;beep=0;delay(100);temp=_cror_(temp,1);P1=0xff;beep=1;delay(100);}}while(1);}}voiddelay(uintz){uintx,y;for(x=z;x0;x--)for(y=110;y0;y--);}Lesson3-1#includereg52.hsbitdula=P2^6;sbitwela=P2^7;voidmain(){wela=1;P0=0xc0;wela=0;dula=1;P0=0x06;dula=0;while(1);}Lesson3-2#includereg52.h#defineuintunsignedint#defineucharunsignedcharsbitdula=P2^6;sbitwela=P2^7;ucharnum;ucharcodetable[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};voiddelay(uintz);voidmain(){wela=1;//11101010P0=0xea;wela=0;while(1){for(num=0;num16;num++){dula=1;P0=table[num];dula=0;delay(1000);}}}voiddelay(uintz){uintx,y;for(x=z;x0;x--)for(y=110;y0;y--);}Lesson3-3#includereg52.h#defineuintunsignedint#defineucharunsignedcharsbitdula=P2^6;sbitwela=P2^7;sbitd1=P1^0;ucharnum;ucharcodetable[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};voiddelay(uintz);voidmain(){EA=1;//开总中断EX0=1;//开外部中断0//IT0=1;TCON=0x01;wela=1;//11101010P0=0xea;wela=0;while(1){for(num=0;num16;num++){d1=1;dula=1;P0=table[num];dula=0;delay(1000);}}}voiddelay(uintz){uintx,y;for(x=z;x0;x--)for(y=110;y0;y--);}voidexter0()interrupt0{d1=0;}Lesson3-4#includereg52.h#defineuintunsignedint#defineucharunsignedcharsbitdula=P2^6;sbitwela=P2^7;sbitd1=P1^0;ucharnum,num1;tt;ucharcodetable[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};voiddelay(uintz);voidmain(){num=0;tt=0;TMOD=0x11;//设置定时器0为工作方式1TH0=(65536-10000)/256;TL0=(65536-10000)%256;TH1=(65536-20000)/256;TL1=(65536-20000)%256;//EA=1;//开总中断ET0=1;//开定时器0中断ET1=1;TR0=1;//启动定时器0TR1=1;wela=1;//11101010P0=0xea;wela=0;dula=1;P0=0x3f;dula=0;while(1){if(num1==25){num1=0;P1=~P1;}if(tt==100){tt=0;num++;if(num==16)num=0;dula=1;P0=table[num];dula=0;}}}voiddelay(uintz){uintx,y;for(x=z;x0;x--)for(y=110;y0;y--);}voidtime0()interrupt1{TH0=(65536-10000)/256;TL0=(65536-10000)%256;tt++;}voidtime1()interrupt3{TH1=(65536-20000)/256;TL1=(65536-20000)%256;num1++;}Lesson4-1#includereg52.h#includeintrins.h#defineuintunsignedint#defineucharunsignedcharuchartemp,aa,num;sbitdula=P2^6;sbitwela=P2^7;ucharcodetable[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};voiddelay(uintz);voidmain(){num=0;aa=0;TMOD=0x01;TH0=(65536-50000)/256;TL0=(65536-50000)%256;EA=1;ET0=1;TR0=1;temp=0xfe;P1=temp;dula=1;P0=table[0];dula=0;wela=1;P0=0xc0;wela=0;while(1){delay(1000);temp=_crol_(temp,1);P1=temp;/*if(aa==40){aa=0;num++;if(num==16)num=0;dula=1;P0=table[num];dula=0;}*/}}voiddelay(uintz){uintx,y;for(x=z;x0;x--)for(y=110;y0;y--);}voidtimer0()interrupt1{TH0=(65536-50000)/256;TL0=(65536-50000)%256;aa++;if(aa==40){aa=0;num++;if(num==16)num=0;dula=1;P0=table[num];dula=0;}}Lesson4-2#includereg52.h#includeintrins.h#defineuintunsignedint#defineucharunsignedcharuchartemp,aa,numdu,numwe;sbitdula=P2^6;sbitwela=P2^7;ucharcodetable[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};ucharcodetablewe[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf};//voiddelay(uintz);voidmain(){numdu=0;numwe=0;aa=0;TMOD=0x01;TH0=(65536-5000)/256;TL0=(65536-5000)%256;EA=1;ET0=1;TR0=1;while(1){//delay(1000);//temp=_crol_(temp,1);//P1=temp;if(aa==1){aa=0;numdu++;if(numdu==7)numdu=1;dula=1;P0=table[numdu];dula=0;wela=1;P0=tablewe[numwe];wela=0;numwe++;if(numwe==6)numwe=0;}}}/*voiddelay(uintz){uintx,y;for(x=z;x0;x--)for(y=110;y0;y--);}*/voidtimer0()interrupt1{TH0=(65536-5000)/256;TL0=(65536-5000)%256;aa++;}Lesson4-3#includereg52.h#defineuintunsignedint#defineucharunsignedcharuchartemp,aa,bai,shi,ge;sbitdula=P2^6;sbitwela=P2^7;ucharcodetable[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};voiddisplay(ucharbai,ucharshi,ucharge);voiddelay(uintz);voidinit();voidmain(){init();//初始化子程序while(1){if(aa==20){aa=0;temp++;if(temp==100){temp=0;}bai=temp/100;shi=temp%100/10;ge=temp%10;}display(bai,shi,ge);}}voiddelay(uintz){uintx,y;for(x=z;x0;x--)for(y=110;y0;y--);}voiddisplay(ucharbai,ucharshi,ucharge){dula=1;P0=table[bai];dula=0;//送百位数P0=0xff;//打开瞬间一个都不亮,消影wela=1;P0=0xfe;//位选通百位数wela=0;delay(1);dula=1;P0=table[shi];dula=0;P0=0xff;wela=1;P0=0xfd;wela=0;delay(1);dula=1;P0=table[ge];dula=0;P0=0xff;wela=1;P0=0xfb;wela=0;delay
本文标题:郭天祥单片机程序.doc
链接地址:https://www.777doc.com/doc-4000630 .html