Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
ok, but what if i want to set particular intensity of an LED using software PWM using above logic . Can i do it?
#define ON 1
#define OFF 0
#define timer_val 200 //LED toggle frequency
int OnPulse = 217;
int OffPulse = 38;
char TOG = 0;
int i = 0;
void interrupt(){
if(INTCON.T0IF){
T0IF_bit = 0;
}
PORTC.B0 = 1;
//RC0_bit = 1;
//Delay_us(10000);
//PORTC.B2 = 1;
for(i=0;i<=500;i++) //For varying intensity
TMR0 = timer_val;
}
void main() {
TRISC = 0x00; //PortC as output
PORTC = 0x00; //Initial value on PortC
INTCON = 0b10100000;
INTCON.T0IF = 0;
T0CS_bit = 0;
PSA_bit = 0; //Prescaler is assigned to Timer0 module
PS0_bit = 1; //TMR0 rate 1:2
PS1_bit = 1;
PS2_bit = 1;
TMR0 = timer_val;
while(1){
PORTC.B0 = 0;
//PORTC.B2 = 0;
//Delay_ms(5);
}
}
#define ON 1
#define OFF 0
#define timer_val 200 //LED toggle frequency
int OnPulse = 217;
int OffPulse = 38;
char TOG = 0;
int i = 0;
void interrupt(){
if(INTCON.T0IF){
T0IF_bit = 0;
}
PORTC.B0 = 1;
//RC0_bit = 1;
//Delay_us(10000);
//PORTC.B2 = 1;
for(i=0;i<=500;i++) //For varying intensity
TMR0 = timer_val;
}
void main() {
TRISC = 0x00; //PortC as output
PORTC = 0x00; //Initial value on PortC
INTCON = 0b10100000;
INTCON.T0IF = 0;
T0CS_bit = 0;
PSA_bit = 0; //Prescaler is assigned to Timer0 module
PS0_bit = 1; //TMR0 rate 1:2
PS1_bit = 1;
PS2_bit = 1;
TMR0 = timer_val;
while(1){
PORTC.B0 = 0;
//PORTC.B2 = 0;
//Delay_ms(5);
}
}