sbit LED1 at RC0_bit;
sbit LED2 at RC1_bit;
sbit LED3 at RC2_bit;
sbit LED6 at RC3_bit;
sbit LED4 at RC4_bit;
sbit LED5 at RC5_bit;
#define SW_PORT PORTA
#define SW_TEST_VAL 0xD7
#define PWM_FREQ 5000
unsigned short gPwmDuty = 255;
void testButtonRelease() {
while((SW_PORT & 0xF7) != 0xF7);
}
void main() {
CMCON = 7;
TRISA = 0xFF;
TRISC = 0x00;
PORTA = 0x00;
PORTC = 0x00;
PWM1_Init(PWM_FREQ);
PWM1_Set_Duty(gPwmDuty);
PWM1_Start();
while(1) {
if((SW_PORT & SW_TEST_VAL) == 0xD6) {
Delay_ms(80);
testButtonRelease();
LED1 = ~LED1;
}
else if((SW_PORT & SW_TEST_VAL) == 0xD5) {
Delay_ms(80);
testButtonRelease();
LED2 = ~LED2;
}
else if((SW_PORT & SW_TEST_VAL) == 0xD3) {
Delay_ms(80);
testButtonRelease();
LED3 = ~LED3;
}
else if((SW_PORT & SW_TEST_VAL) == 0xC7) {
Delay_ms(80);
testButtonRelease();
LED4 = ~LED4;
}
else if((SW_PORT & SW_TEST_VAL) == 0x97) {
Delay_ms(80);
testButtonRelease();
if((gPwmDuty >= 0) && (gPwmDuty <= 254)) {
gPwmDuty++;
PWM1_Set_Duty(gPwmDuty);
}
}
else if((SW_PORT & SW_TEST_VAL) == 0x57) {
Delay_ms(80);
testButtonRelease();
if((gPwmDuty <= 255) && (gPwmDuty > 0)) {
gPwmDuty--;
PWM1_Set_Duty(gPwmDuty);
}
}
}
}