用单片机控制LED灯(项目)

#include <reg52.h>
#define uchar unsigned char
sbit LED_RED = P2^;
sbit LED_GREEN = P2^;
sbit LED_BLUE = P2^; //要显示的颜色值
uchar COLOR_RED = 0xff;
uchar COLOR_GREEN = 0xcc;
uchar COLOR_BLUE = 0x33; uchar i = ; //初始化定时器,用于控制PWM波
void Init_INT0(){
TMOD = 0x02;//工作方式2,8位自动装置定时器
TH0 = 0xf0;
TL0 = TH0;
ET0 = ;
EA = ;
TR0 = ;
} void main(){
Init_INT0();
while();
} void INT0_Resolve() interrupt {
//i的值从0-255循环,当i到达255时,i++的结果为0
i++; //红色LED的PWM波形
if(i < COLOR_RED){
LED_RED = ;
}else{
LED_RED = ;
}
//绿色LED的PWM波形
if(i < COLOR_GREEN){
LED_GREEN = ;
}else{
LED_GREEN = ;
}
//蓝色LED的PWM波形
if(i < COLOR_BLUE){
LED_BLUE = ;
}else{
LED_BLUE = ;
}
}
上一篇:P2679 子串


下一篇:命令行运行android模拟器