#include <REG52.H>//80C52特殊功能寄存器定义
#define LED_PORT0 P0 //用P0口驱动灯,低亮,高灭
#define LED_PORT1 P1 //用p1口驱动灯,低亮,高灭
#define LED_PORT2 P2 //用P2口驱动灯,低亮,高灭
void time(unsigned int ucMs);/* 延时单位:毫秒 */
void main(void)
{
unsigned char ucTimes;
#define DELAY_TIME 400 //延时
while(1)
{
LED_PORT0=0xff;//灭P0口灯
time(200);
//从左往右依次点亮LED
for(ucTimes=0;ucTimes<8;ucTimes++){//循环点亮P1口灯
LED_PORT0 = LED_PORT0 - (0x01<<ucTimes);//亮灯需低电平驱动
time(DELAY_TIME);
}
LED_PORT1=0xff;//灭P1口灯
time(200);
//然后从右往左依次点亮LED
for(ucTimes=0;ucTimes<8;ucTimes++){//循环点亮P1口灯
LED_PORT1 = LED_PORT1 - (0x01<<ucTimes);//亮灯需低电平驱动
time(DELAY_TIME);
}
LED_PORT2=0xff;//灭P2口灯
time(200);
//然后从右往左依次点亮LED
for(ucTimes=0;ucTimes<8;ucTimes++){//循环点亮P2口灯
LED_PORT2 = LED_PORT2 - (0x01<<ucTimes);//亮灯需低电平驱动
time(DELAY_TIME);
}
LED_PORT0=0xff;//灭P0口灯
LED_PORT1=0xff;//灭p1口灯
LED_PORT2=0xff;//灭p2口灯
time(200);
//从左往右依次点亮LED
for(ucTimes=0;ucTimes<8;ucTimes++){//循环点亮P2口灯
LED_PORT2 = LED_PORT2 - (0x80>>ucTimes);//亮灯需低电平驱动
time(DELAY_TIME);
}
//然后从右往左依次点亮LED
for(ucTimes=0;ucTimes<8;ucTimes++){//循环点亮P1口灯
LED_PORT1 = LED_PORT1 - (0x80>>ucTimes);//亮灯需低电平驱动
time(DELAY_TIME);
}
//从左往右依次点亮LED
for(ucTimes=0;ucTimes<8;ucTimes++){//循环点亮P0口灯
LED_PORT0 = LED_PORT0 - (0x80>>ucTimes);//亮灯需低电平驱动
time(DELAY_TIME);
}
time(1000);
LED_PORT0=0xff;//time(DELAY_TIME);//全灭
LED_PORT1=0xff;//time(DELAY_TIME);//全灭
LED_PORT2=0xff;//time(DELAY_TIME);//全灭
time(1000);
LED_PORT0=0;//time(DELAY_TIME);//全亮
LED_PORT1=0;//time(DELAY_TIME);//全亮
LED_PORT2=0;//time(DELAY_TIME);//全亮
time(1000);
LED_PORT0=0xff;//time(DELAY_TIME);//全灭
LED_PORT1=0xff;//time(DELAY_TIME);//全灭
LED_PORT2=0xff;//time(DELAY_TIME);//全灭
time(1000);
LED_PORT0=0;//time(DELAY_TIME);//全亮
LED_PORT1=0;//time(DELAY_TIME);//全亮
LED_PORT2=0;//time(DELAY_TIME);//全亮
}
}
/*********** time C **************/
void time(unsigned int ucMs)//延时单位:ms
{
#define DELAYTIMES 239
unsigned char ucCounter; // 延时设定的循环次数
while (ucMs!=0) {
for (ucCounter=0; ucCounter<DELAYTIMES; ucCounter++){}//延时
ucMs--;
}
}
上面的是Keil部分的代码
第一张是五角星的LED灯的摆放,本人艺术水平低,外加Protues不能自定义角度摆放所以样子有点丑。第二张是芯片(AT89C52,没有.BUS的后缀)引脚的图 。
联调的步骤在本人的第一篇文章中有http://t.csdnimg.cn/WPFNe。
如果有技术上的错误,欢迎各位指正。