|
|
#include "reg51.h"
sbit LED1=P1^0;
sbit LED2=P1^1;
unsigned char cycle=0;
unsigned int step=1;
unsigned int bright=0;
unsigned char cycle2=0;
unsigned int step2;
unsigned int bright2=0;
void test1(void);
void test2(void);
void delay(unsigned int time_i);
void main(){
while(1){
test1();
test2();
}
}
void test1(void){
if(++cycle >250){
cycle = 0;
switch (step){
case 1 :
bright++;
if(bright > 250){
step ++;
}break;
case 2 :
bright--;
if(bright < 1){
step = 3;
step2 = 1;
}break;
}
}
if(cycle < bright){
LED1=0; //燈亮
}
else{
LED1=1; // 燈滅
}
}
void test2(void){
if(++cycle2 >250){
cycle2 = 0;
switch (step2){
case 1 :
bright2++;
if(bright2 > 250){
step2 ++;
}break;
case 2 :
bright2--;
if(bright2 < 1){
step2 = 3;
step = 1;
}break;
}
}
if(cycle2 < bright2){
LED2=0; //燈亮
}
else{
LED2=1; //
}
}
換LED的步驟出錯(cuò)了。將這個(gè)和你的程序?qū)φ障戮颓宄恕?/td> |
|