Controlling PIC registers using XC8 C
Posted: Wed Nov 23, 2016 11:56 am
Hi
I have developed a battery-powered clock that periodically synchronises with the MSF transmitter at Anthorn. So far, I have not had to resort to the use of C and I enjoy FlowCode's clarity compared with my previous failed C attempt for this project.
I now have to refine the code to provide an acceptable battery life, and I need to be able to do the following (at least):
1) configure the PIC for minimum power consumption
2) enable weak pull-ups for portB, bits 4-7 (for a button interface) and disable them again during sleep
3) switch between a 4MHz clock rate (or greater) oscillator for the duration of time lock-on and update and a 32kHz external clock for timekeeping
All of these, so far as I can see, require the use of the C icon.
Is there any guidance on the coding to be used with the XC8 compiler please?
I have tried to interpret the XC8 compiler User Guide, which suggests (to me!) the use of the #pragma, but this gives a compile error, e.g.,
1217: #pragma INTSRC = 0;
^ (335) unknown pragma "INTSRC" (warning)
using the seemingly deprecated __config() statement gives
1221: __config ("WPUB", 0b11110000);
^ (195) expression syntax
Using just __WPUB = 0b11110000; I get
1159: __WPUB = 0b11110000;
^ (192) undefined identifier "__WPUB"
Using #pragma __WPUB = 0b11110000;, I get
1159: #pragma __WPUB = 0b11110000;
^ (335) unknown pragma "__WPUB" (warning)
By trial and error, I have found that, for example,
INTSRC = 0;
does work; Is this the general rule, i.e.,
a) Use the MPLab data sheet for your pic
b) Find the register definitions for the purpose in hand
c) Refer to the bit or group of bits by the data sheet name and set the value
This seems to work some of the time, e.g., PLLEN = 1 quadruples LED blink rate in a timer loop, but others such as
WPUB 0b11110000; does not change the voltages on portB(4..7), either measured on the pin or sampled using an input icon with the port open circuit; nor does it light any leds on an EB004 board (WPUB4 = 1; does not work either).
I am clearly missing something here, and will feel foolish when I hear the answer. Can you point me at where I should look for this please? Coming back here for each item is likely to prove tedious for all of us!
* I am using the PIC 18F45K22, EB006 with a PIC-KIT3 programmer (Olimex) *
Regards
Jim
I have developed a battery-powered clock that periodically synchronises with the MSF transmitter at Anthorn. So far, I have not had to resort to the use of C and I enjoy FlowCode's clarity compared with my previous failed C attempt for this project.
I now have to refine the code to provide an acceptable battery life, and I need to be able to do the following (at least):
1) configure the PIC for minimum power consumption
2) enable weak pull-ups for portB, bits 4-7 (for a button interface) and disable them again during sleep
3) switch between a 4MHz clock rate (or greater) oscillator for the duration of time lock-on and update and a 32kHz external clock for timekeeping
All of these, so far as I can see, require the use of the C icon.
Is there any guidance on the coding to be used with the XC8 compiler please?
I have tried to interpret the XC8 compiler User Guide, which suggests (to me!) the use of the #pragma, but this gives a compile error, e.g.,
1217: #pragma INTSRC = 0;
^ (335) unknown pragma "INTSRC" (warning)
using the seemingly deprecated __config() statement gives
1221: __config ("WPUB", 0b11110000);
^ (195) expression syntax
Using just __WPUB = 0b11110000; I get
1159: __WPUB = 0b11110000;
^ (192) undefined identifier "__WPUB"
Using #pragma __WPUB = 0b11110000;, I get
1159: #pragma __WPUB = 0b11110000;
^ (335) unknown pragma "__WPUB" (warning)
By trial and error, I have found that, for example,
INTSRC = 0;
does work; Is this the general rule, i.e.,
a) Use the MPLab data sheet for your pic
b) Find the register definitions for the purpose in hand
c) Refer to the bit or group of bits by the data sheet name and set the value
This seems to work some of the time, e.g., PLLEN = 1 quadruples LED blink rate in a timer loop, but others such as
WPUB 0b11110000; does not change the voltages on portB(4..7), either measured on the pin or sampled using an input icon with the port open circuit; nor does it light any leds on an EB004 board (WPUB4 = 1; does not work either).
I am clearly missing something here, and will feel foolish when I hear the answer. Can you point me at where I should look for this please? Coming back here for each item is likely to prove tedious for all of us!
* I am using the PIC 18F45K22, EB006 with a PIC-KIT3 programmer (Olimex) *
Regards
Jim