Hi this coding I have inside the ISR.
For every 10ms it’s giving an TMR0 interrupt. So I count 100 times to get 1 second.
After I checking whether it has reaches 60 seconds to get 1 minute.
What I need is the output must stay ON 50% & other 50% must be OFF.
The coding done for 2 minutes on & 2 minutes off from 4 minutes.
Hi,
Do you want to toggle RB0 every 2 minutes? Or you need to use the Second and Minute GPRs in the main routine?
Try this:
Code:
ISR decfsz COUNT,F
retfie
movlw .100
movwf COUNT
decfsz Second,F
retfie
movlw .120
movwf Second
comf PORTB, w
andlw 0x01
iorwf PORTB, f
retfie
*EDIT: This routine will not work, RB0 will always be high. Because it is inclusive OR. When one input is already high, the output is high for sure. Check the latest reply
TMR0 is the worst possible choice, it's only really included to maintain backwards compatibility with ancient PIC's - use TMR2 which is far more useful and easy to use.
If you do use TMR0 I suggest you check the PICList and Application notes, where you can find suggestions on how to work round some of it's limitations. Basically, unlike TMR2, you can't just set it to 10mS and go.
Hi Suraj143,
I haven't used comf either
It is complement, means toggle all the bits in PORTB. And yes, your code works too, but you can avoid using another GPR.
Timer 1 is really a better solution. 10 ms interrupt can be done without any prescaler since it is 16 bits timer.
Hi I applied bananas COMF coding to toggle the output from minute variable. After I replaced the iorwf PORTB, W with movwf PORTB & it worked well. But it didn’t work with that iorwf instruction.
Code:
comf PORTB,W
andlw 0x01
movwf PORTB
Now the problem is the PORTB, 0 bit will toggle but its effecting to the other 7 bits from the above coding.
Is there any method or instruction to toggle only the PORTB zero bit but without damaging other bits?
No, you just need the two instructions I posted above to toggle bit zero of Port B. You should try and work out why this works and you will get a better understanding.