单片机学习(一 流水灯) (AT89S52)
/****************** *Author:xiehuan * *For:流水灯 * *QQ:736459657 * ******************/ #include<at89x52.h> #define TRUE 1 #define FALSE 0 #define uchar unsigned char #define uint unsigned int void delay(void); uint port_on(uint n); void main(void) { //P1=0; uint port; while(TRUE) { port=0; for(;port<8;port++) { P1=port_on(port); P2=port_on(port); delay(); } } } /*delay some time */ void delay(void) { uint i,j; for(i=100;i>0;i--) for(j=1000;j>0;j--) ; } /*set one port be light,0 is effective */ uint port_on(uint n) { switch(n) { case 0: return 0xFE;break; case 1: return 0xFD;break; case 2: return 0xFB;break; case 3: return 0xF7;break; case 4: return 0xEF;break; case 5: return 0xDF;break; case 6: return 0xBF;break; case 7: return 0x7F;break; } }