
Originally Posted by
Darrel Taylor
When you're working with PBP, it's easy to forget that there are "BANKs" in the RAM because it's all handled for you.
But when you are writing at the ASM level, you have to remember about the BANKs. And on the F1 type parts, there are a lot of them. (32 to be exact).
In your case, RCREG is in BANK3.
And since you only have 1 variable in your program, it will obviously end up in BANK0. But when the program gets bigger, that may not be the case.
It should be able to find your variables no matter what bank they end up in.
Also, when you get an interrupt on an F1 part. You have no idea what bank it is in when it gets to the ISR.
It's up to you to change it to BANK0 (if that's the bank your ISR needs).
Really? I'm surprised! The BoostC compiler I use (sorry, still no PBP to play with here) apparently keeps track of the variables and registers used in my assembly language instructions and automatically inserts the 'movlb x' instructions for me. Now you have me wondering if that feature is unique to BoostC or if other compilers have it as well? Anyway, please notice how I had to comment out all of my bank select instructions after I discovered they were redundant;
Code:
/* *
* (C) 2012, K8LH - low level One-Wire R/W (Carry) Bit Driver *
* (hard coded for "owpin" defines and 8-MHz clock) (30 words) *
* */
void owrw() // read/write Carry bit
{ intcon.GIE = 0; // interrupts off
//asm movlb owport // bank 0 (inserted by compiler)
asm bcf owport,owpin // clear owpin output latch
//asm movlb owtris // bank 1 (inserted by compiler)
asm bcf owtris,owpin // owpin low (falling edge)
asm movf _pcl,F // pseudo bra $+1 (2 cycles)
asm movf _pcl,F // "
asm movf _pcl,F // "
asm skpnc // if a '1' (C=1)
asm bsf owtris,owpin // set owpin to hi-z '1'
asm movlw 18/3 //
dly1:
asm decfsz _wreg,W // DelayCy(14*usecs-10)
asm bra dly1 //
//asm movlb owport // bank 0 (inserted by compiler)
asm btfss owport,owpin // exactly 14-us from falling edge
asm clrc // clear Carry if 'owpin' was low
asm movlw 84/3 // balance of 60-usec "r/w slot"
dly2:
asm decfsz _wreg,W // DelayCy(47*usecs-10)
asm bra dly2 //
//asm clrf _wreg // wreg already 0 (see above)
asm rlf _wreg,W // save C (wreg = 0x00 or 0x01)
asm xorwf _crc,F // xor b0 bits, result in 'crc'
asm rrf _crc,F // xor result 0 (C=0)?
asm skpnc // yes, skip, else
asm iorlw 0x18 // wreg = x8+x5+x4+1 poly and b0 bit
asm rrf _wreg,W // restore C (wreg = 0x8C or 0x00)
asm xorwf _crc,F // apply the polynomial, or not
//asm movlb owtris // bank 1 (inserted by compiler)
asm bsf owtris,owpin // set owpin to hi-z '1' @ 61-usecs
intcon.GIE = 1; // interrupts on
} //
/* *
* (C) 2012, K8LH - One-Wire R/W Byte Function (11 words) *
* */
char owrw(u08 pbyte) // read/write byte
{ u08 i = 0; // bit counter
do //
{ asm rrf _pbyte,W // put output bit b0 in Carry
owrw(); // write then read bit
asm rrf _pbyte,F // save input bit from Carry
i++; //
} while(i.3 == 0); //
return pbyte; //
} //
Bookmarks