资源描述:
《郭天祥十天学会单片机中的源程序》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、Lesson2-1#includesbitp1_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#include#defineuintunsignedint#defineucharunsignedcharsbitD1=P1^0;//voiddelay(
2、);voiddelay(uint);voidmain(){while(1){D1=0;delay(100);D1=1;delay(100);}}/*voiddelay(){uintx,y;for(x=100;x>0;x--)for(y=600;y>0;y--);}*/voiddelay(uintz){uintx;uchary;for(x=z;x>0;x--)for(y=20;y>0;y--);}Lesson2-3#include#include#defineuintunsi
3、gnedint#defineucharunsignedcharuchartemp,num,num1;sbitbeep=P2^3;voiddelay(uint);voidmain(){temp=0xfe;while(1){for(num1=0;num1<3;num1++){for(num=0;num<8;num++){P1=temp;beep=0;delay(100);temp=_crol_(temp,1);P1=0xff;beep=1;delay(100);}}for(num1=0;num1<3;num1++){
4、for(num=0;num<8;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;x>0;x--)for(y=110;y>0;y--);}Lesson3-1#includesbitdula=P2^6;sbitwela=P2^7;voidmain(){wela=1;P0=0xc0;wela=0;dul
5、a=1;P0=0x06;dula=0;while(1);}Lesson3-2#include#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);voidm
6、ain(){wela=1;//11101010P0=0xea;wela=0;while(1){for(num=0;num<16;num++){dula=1;P0=table[num];dula=0;delay(1000);}}}voiddelay(uintz){uintx,y;for(x=z;x>0;x--)for(y=110;y>0;y--);}Lesson3-3#include#defineuintunsignedint#defineucharunsignedcharsbitdula=P2^
7、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;n
8、um<16;num++){d1=1;dula=1;P0=table[num];dula=0;delay(1000);}}}voiddelay(uintz){uintx,y;for(x=z;x>0;x--)for(y=110;y>0;y--);}voidexter0()interrupt0{d1=0;}Lesson3-4#include#defineuin