/*
'*******************************************************************************
' Configurations
' Oscillator: INTOSC:I/O
' Watchdog Timer: OFF
' Power up Timer: Disabled
' Master Clear Enable: Enabled
' Browun Out Detect: Enabled
' Low Voltage Program: Disabled
' Data EE Read Protect: Disabled
' Code Protect: OFF
'*******************************************************************************
*/
// LED connections
sbit LED1 at RB0_bit;
sbit LED2 at RB1_bit;
sbit LED3 at RB2_bit;
sbit LED4 at RB3_bit;
sbit LED5 at RB4_bit;
sbit LED6 at RB5_bit;
sbit LED7 at RB6_bit;
sbit LED8 at RB7_bit;
sbit LED9 at RA0_bit;
sbit LED10 at RA1_bit;
sbit LED11 at RA2_bit;
sbit LED12 at RA3_bit;
sbit LED1_Direction at TRISB0_bit;
sbit LED2_Direction at TRISB1_bit;
sbit LED3_Direction at TRISB2_bit;
sbit LED4_Direction at TRISB3_bit;
sbit LED5_Direction at TRISB4_bit;
sbit LED6_Direction at TRISB5_bit;
sbit LED7_Direction at TRISB6_bit;
sbit LED8_Direction at TRISB7_bit;
sbit LED9_Direction at TRISA0_bit;
sbit LED10_Direction at TRISA1_bit;
sbit LED11_Direction at TRISA2_bit;
sbit LED12_Direction at TRISA3_bit;
// End LED connections
int i = 0 ,PWN_COUNTER = 256;
void PWM_FADE_1_TO_0(void);
void Delay(int num);
void main(void)
{
CMCON |= 7; // Comparator is Off
TRISA = 0;
PORTA = 0;
TRISB = 0;
PORTB = 0;
while(1){
PWM_FADE_1_TO_0();
}
}
void PWM_FADE_1_TO_0(void) // Duty cycle - 100% to 0%
{
for (i = 0; i < PWN_COUNTER; i++) {
LED1 = ~LED1;
Delay(10);
LED2 = ~LED2;
Delay(10);
LED3 = ~LED3;
Delay (10);
LED4 = ~LED4;
Delay(10);
LED5 = ~LED5;
Delay(10);
LED6 = ~LED6;
Delay(10);
LED7 = ~LED7;
Delay(10);
LED8 = ~LED8;
Delay(10);
LED9 = ~LED9;
Delay(10);
LED10 = ~LED10;
Delay(10);
LED11 = ~LED11;
Delay(10);
LED12 = ~LED12;
Delay(10);
}
}
void Delay(int num)
{
while(num>0)
num--;
}