View previous topic :: View next topic |
Author |
Message |
Doug Guest
|
OSCCAL and compiler version 2.706 |
Posted: Mon Feb 16, 2004 10:08 pm |
|
|
Hi all, I am working on a project which uses a 12c672 chip. I have version 2.706 of the CCS compiler. Digging through the archives of this board I discovered that a problem with OSCCAL was fixed in 2.708 of the compiler. Does anyone know what the fix was? My assembly output of the call to the OSCCAL calibration looks likes this after I compile the code:
Code: |
0000 3000 movlw 0x0
0001 008A movwf 0xA
0002 2828 goto 0x28
.
.
. // serveral lines of assembly
.
.
0028 3007 movlw 0x7
0029 008A movwf 0xA
002A 27FF call 0x7FF
002B 0085 movwf 0x5
002C 3000 movlw 0x0
002D 008A movwf 0xA
002E 287A goto MAIN |
Does it look correct? If not what should I do to fix it?
Thanks
Doug |
|
|
Felix Althaus
Joined: 09 Sep 2003 Posts: 67 Location: Winterthur, Switzerland
|
|
Posted: Tue Feb 17, 2004 6:36 am |
|
|
Hello
I don't remeber how much ROM the 672 has, but if it's 2048 words, your code seems to be correct (if there is a 'RETLW XX' instruction at address 0x7FF).
Felix |
|
|
Doug Guest
|
|
Posted: Tue Feb 17, 2004 9:55 am |
|
|
Ok, good . Its a 2K rom, I just wasn't sure if there was a change made which affected the loading of the OSCCAL register.
Thanks,
Doug |
|
|
Felix Althaus
Joined: 09 Sep 2003 Posts: 67 Location: Winterthur, Switzerland
|
|
Posted: Tue Feb 17, 2004 10:21 am |
|
|
Hello Doug
I'm very sorry but I think I have overlooked something:
Your compiler stores the osccal value in the register 0x05 but that's the GPIO. Can you have a look at the PIC12c672 output of the picchips program? What does it say about the osccal register location?
If the fault is there, perhaps you can correct it with the device table editor. If you don't have one you can use this code (as I do):
#byte OSCCAL = 0x8F
// somewhere at the beginning of main():
OSCCAL = YOUR_VALUE;
The compiler should handle the bank switching automatically.
Felix |
|
|
Doug Guest
|
|
Posted: Tue Feb 17, 2004 11:12 am |
|
|
Ahhh... yes, the data sheet says the OSCCAL value is at 8F. I thought it was kind of strange that the value got writen to 05 but I figured it was due to bank selection.
So if I program multiple chips can I do my own routine at the beginning like:
Code: |
#byte OSCCAL = 0x8F
main(){
// initialization code
#asm
movlw 0x07
movwf 0x0A
call 0x7FF
movwf OSCCAL
movlw 0x00
movwf 0x0A
#endasm
// rest of program
} |
Can I put that in my code to fix the problem?
Thanks,
Doug |
|
|
Felix Althaus
Joined: 09 Sep 2003 Posts: 67 Location: Winterthur, Switzerland
|
|
Posted: Tue Feb 17, 2004 1:19 pm |
|
|
Yes that's possible, but I don't know if the compiler accepts a #byte-definition within assembly code. Perhaps you have to define OSCCAL with:
#define OSCCAL 0x8F
Perhaps you also have to switch to the correct bank (and back) before moving the return value to OSCCAL.
Felix |
|
|
Doug Guest
|
|
Posted: Tue Feb 17, 2004 1:46 pm |
|
|
Ok, according to the data sheet I only have to set bit 5 of register 3 (status register) to switch banks. But what does putting 0x07 into PCLATH (0A) before the call to 0x7FF do? Is this another form of bank switching? I'm confused about the use of banks.
Thanks,
Doug |
|
|
Felix Althaus
Joined: 09 Sep 2003 Posts: 67 Location: Winterthur, Switzerland
|
|
Posted: Tue Feb 17, 2004 3:15 pm |
|
|
Hi
The 0x07 into PCLATH is the "page switch" so the PIC can access the upper program memory pages (in this case the highest one where the retlw XX lies).
Have a look at the datasheet.
Felix |
|
|
Doug Guest
|
|
Posted: Tue Feb 17, 2004 3:36 pm |
|
|
Thanks Felix!
I didn't know "page switch" and "bank select" were two different things. I need to learn more.
I'll look into it. |
|
|
Doug Guest
|
|
Posted: Tue Feb 17, 2004 5:47 pm |
|
|
Ok I think I have it now.....
Here's what I did:
Code: |
#define OSCCAL 0x8f
.
.
.
.
main(){
// initialization code here
#asm
movlw 0x07
movwf 0x0A
call 0x7FF
movwf OSCCAL
movlw 0x00
movwf 0x0A
#endasm
// rest of program
|
And here is what it looks like after I compiled it:
Code: |
movlw 0x7
movwf 0xA
call 0x7FF
bsf 0x3,0x5
movwf 0xF
movlw 0x0
bcf 0x3,0x5
movwf 0xA
|
Notice how CCS took care of the bank selection bit automatically. Now when I run MPLAB Simulator it updates the OSCCAL register properly.
Thank you Felix, for helping me with this work around. |
|
|
|