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