📄 rgbpwm.c
字号:
/* RGB PWM Channels */
int led1Dir[3] = { -1,1,-1 };
int led2Dir[3] = { 1,-1,-1 };
int led3Dir[3] = { -1,1,1 };
unsigned char led1Duty[3] = { 100,20,100 };
unsigned char led2Duty[3] = { 10,130,200 };
unsigned char led3Duty[3] = { 80,100,20 };
unsigned char led1Pin[3] = { 0, 1, 2 }; /* RB0, RB1, RB2 */
unsigned char led2Pin[3] = { 5, 6, 7 }; /* RB5, RB6, RB7 */
unsigned char led3Pin[3] = { 0, 1, 2 }; /* RA0, RA1, RA2 */
unsigned char timerTick=0;
unsigned char doPwm(unsigned char pwmDuty[], unsigned char pwmPin[]) {
unsigned char i;
for(i=0;i<3;i++) {
if(timerTick == 0 && pwmDuty[i] != 0) { // reset at start.
pwmPin[i] = 0;
// resBit(pShadow, pwmPin[i]);
} else if(timerTick == pwmDuty[i] && pwmDuty[i] != 255) { // set at duty.
//setBit(pShadow, pwmPin[i]);
pwmPin[i] = 1;
}
}
return 0;
}
static void Intr(void) interrupt 0 { /* interrupt service routine */
unsigned char i;
GIE=0;
if(T0IF) {
doPwm(led1Duty,led1Pin);
doPwm(led2Duty,led2Pin);
doPwm(led3Duty,led3Pin);
timerTick++;
if(timerTick >= 254) {
timerTick=0;
for(i=0;i<3;i++) {
led1Duty[i] += led1Dir[i];
if((led1Duty[i] <= 0)||(led1Duty[i] >= 255)) {
led1Dir[i] = led1Dir[i]*-1;
}
led2Duty[i] += led2Dir[i];
if((led2Duty[i] <= 0)||(led2Duty[i] >= 255)) {
led2Dir[i] = led2Dir[i]*-1;
}
led3Duty[i] += led3Dir[i];
if((led3Duty[i] <= 0)||(led3Duty[i] >= 255)) {
led3Dir[i] = led3Dir[i]*-1;
}
}
}
TMR0 = 0xE0;
T0IF = 0;
}
}but i need to find any way to switch port's pins faster. First proposal is good
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -