1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
| #include<reg51.h> //包含51单片机寄存器定义的头文件 sbit P17=P1^7;
unsigned char RUN[8] = {0xf1, 0xf3, 0xf2, 0xf6, 0xf4, 0xfc, 0xf8, 0xf9} unsigned char FFZ[8] = {0xf9, 0xf8, 0xfc, 0xf4, 0xf6, 0xf2, 0xf3, 0xf1} unsigned char P2_REG=0;
void delay(void) { unsigned int i; for(i=0;i<2000;i++); }
void run(unsigned char *p) { unsigned char i; for(i=0;i<4;i++) { P1=p[i]; delay(); } }
void stop(void) { P1=0xFF ; }
void main(void) { P2=P2_REG=0x70; P17=0; while(1) { if(P2!=0x70) { delay(); if(P2!=0x70) { if((P2&0x70)==0x60) { while((P2&0xF0)!=0x70); if ((P2_REG&0x10)==0) P2_REG = 0x70; else P2_REG = P2_REG&0x60; P17=~P17; } if((P2&0x70)==0x50) { while((P2&0x70)!=0x70); if ((P2_REG&0x20)==0) P2_REG = P2_REG|0x20; else P2_REG = P2_REG&0x50; } if((P2&0x70)==0x30) { while((P2&0x70)!=0x70); if ((P2_REG&0x40)==0) P2_REG = P2_REG|0x40; else P2_REG = P2_REG&0x30; } } } switch(P2_REG) { case 0x00: run(RUN); break; case 0x20: run(FFZ); break; case 0x60: case 0x40: stop(); break; } } }
|