Hi,
I'm using PortB for the patterns of 7-segmen displays, RB1 to RB7. If I want to use RB0 as other output port, in the looked up table, can I do like this:
retlw b'0110100x'? So that RB0 is not affected.
I don't want RB0 to be affected by the multiplexing of 7-segment displays.
You have to combine the bits. The easiest way is to put a zero in your table and or the bit in. EG,
Code:
call TableStuff; get the value from the table
btfsc PORTB,0; Test state of port b
iorlw 0x01; if it's set then set bit 0 of W
movwf PORTB; write it to the port
No, not directly, but you could mask off RB0 before writing the byte to PORTB:
Instead of x, make all bit0's in your lookup table 0's. Then do something like this:
call table
;data for portB now in W....
BTFSC PORTB, RB0 ; check bit0
IORLW b'00000001' ; set bit0 in W if RB0 was set
MOVWF PORTB ; Write data from W to portB
Thanks, but the multiplexing happens during interrupt, every 4 ms. And I need to control RB0 in the main routine.
Then I think the pin has to be left unused.
Nono.. I didn't state clearly. I use interrupt vector to count for the delay time. Previously, my interrupt happens every 4 ms, and the instructions in ISR takes around 17 us to be executed. Then I count for around 250 times to get 1 second. Now 2 us is added into the interrupt vector, I need to change abit the value of PR2 and the 250, to make it be more accurate.
If you are using PR2 then your interrupt should stay at 4mS. I assume you have something like a prescaler of 16 and a PR2 value of 250 to give a 4mS ISR. Adding 2uS will not effect the timing of the ISR.
I'm using 4 MHz crystal, so 1 us per instruction. Prescaler 4 and postscaler 4 and PR2 is actually 245. So interrupt happens every 3.92 ms. The instructions in the ISR takes around 17 us. So interrupt takes 3.937 ms, I count 254 times to get 1 second. If 2 us added to the ISR, multiply around 250 times, then around 500 us is increased every second. I need to calculate it because I need the accuracy.
I'm using 4 MHz crystal, so 1 us per instruction. Prescaler 4 and postscaler 4 and PR2 is actually 245. So interrupt happens every 3.92 ms. The instructions in the ISR takes around 17 us. So interrupt takes 3.937 ms, I count 254 times to get 1 second. If 2 us added to the ISR, multiply around 250 times, then around 500 us is increased every second. I need to calculate it because I need the accuracy.
It sounds like you are writing to PR2 in your ISR. You should set PR2 to 250, the prescaler to 16, postscaler to 1 and your interrupts will be at 4mS exactly. Do not rewrite the PR2 value in your ISR or your timing will be completely messed up.
I must admit that I don't normally use Timer 2 as I prefer the 16 bit period of Timer 1.
However, as I understand it (with PR2=1),
Timer2 starts of equal to zero.
The prescaler gets incremented until it reaches 16.
Timer2 gets incremented.
Timer2 = PR2.
Timer2 gets reset.
Go around again.
So I think it's 16uS. But, I may be wrong. Edit, if you care to try it in the simulator, I would be interested in the result. I may, time permitting, try it myself tomorrow (it's 10PM here).
You always load PR2 with the value you want -1. I'm sure I've read why somewhere but promptly forgot about it since all you really need to remember is the -1 part (grin). So that means that if you want the interrupt flag set at 32-usecs you'd load PR2 with 2-1.
You always load PR2 with the value you want -1. I'm sure I've read why somewhere but promptly forgot about it since all you really need to remember is the -1 part (grin).
The TMR2 register value increments from 00h until it
matches the PR2 register value and then resets to 00h
on the next increment cycle. The PR2 register is a
readable and writable register. The PR2 register is
initialized to FFh upon Reset.