Proteus原理图
控制代码(人人都说goto的坏处,但是用起来真的很爽,hahaha~
#include <reg52.h>#define uchar unsigned char#define uint unsigned intsbit key1 = P1^0;sbit key2 = P1^1;sbit key3 = P1^2;sbit key4 = P1^3;sbit key5 = P1^4;uchar speed=65;uchar code zheng[] = {0x09,0x08,0x0c,0x04,0x06,0x02,0x03,0x01};uchar code fan[] = {0x01,0x03,0x02,0x06,0x04,0x0c,0x08,0x09};void delay1ms(uint t){char i;while(t--){for(i=0;i<113;i++);}}void main(){uchar i;uchar button=0;while(1){if (key1==0){button=1;}if (key2==0){button=2;}if(button==1||button==2){if(button==1){zhengzhuan:for(i=0;i<8;i++){if(key2==0) {button=2;goto fanzhuan;}P2 = fan[i];delay1ms(speed);if(key5==0||key3==0||key4==0) goto next;}}if(button==2){fanzhuan:for(i=0;i<8;i++){if(key1==0) {button=1;goto zhengzhuan;}P2 = zheng [i];delay1ms(speed);if(key5==0|| key3 == 0 || key4 == 0) goto next;}}}next:if (key3==0){speed = speed + 5;if (speed>100)speed = 100;}if (key4==0){speed = speed - 5;if (speed<40)speed = 40;}if(key5==0){button=0;}}}