I am trying to make a pwm using 8051. I am using external interrupt 0 (pin 3.1) to increase speed and interrupt 1 (pin 3.2) to decrease speed. My code is working fine for increasing speed but it does not work for decreasing speed. i.e interrupt 1 is not working properly.
I have never used 8051 mcu so I may not be of much help but one thing I see is that the inc variable is not decalerd as volatile and you should always do that when you have a variable used in both main and isr and may be changed in isr.
You have also used inc = inc-- in isr1 , this should have the same result as inc-- so why don't you just use inc--.
Maybe you also want to use some kind of condition so that the variable doesn't go below 0 (which will result in 255), for example
I didn't worked in past period with 8051 devices, but I remember that you should specify also interrupt attribute (interrupt vector). Try the following code:
Code C - [expand]
1
2
3
4
5
6
7
8
9
10
void ex0_isr (void) interrupt 0 using 0{
inc++;// Increment the count}void ex1_isr (void) interrupt 1 using 2{
inc=inc--;// Deccrement the count}
I didn't worked in past period with 8051 devices, but I remember that you should specify also interrupt attribute (interrupt vector). Try the following code:
Code C - [expand]
1
2
3
4
5
6
7
8
9
10
void ex0_isr (void) interrupt 0 using 0{
inc++;// Increment the count}void ex1_isr (void) interrupt 1 using 2{
inc=inc--;// Deccrement the count}