View previous topic :: View next topic |
Author |
Message |
stu807 Guest
|
Problem with pullups |
Posted: Thu Jan 10, 2008 6:43 am |
|
|
Hi
When I compile this code
Code: |
#include <12F508.h>
#fuses INTRC,NOWDT,PROTECT,NOPROTECT,MCLR
#use delay(clock=4000000)
#define ON 1
#define OFF 0
#define FIRE pin_b0 //ouput
#define ONOFF pin_b3 //input
#define ADJUST pin_b1 //input
#define LED pin_b2 //output
void main(void)
{
/******************************************************************************
Initilisation
******************************************************************************/
unsigned char rate = 30; //Steps of 5x2ms. Set initial rate to 300ms (approx 3 Hz)
unsigned char temp = 0;
boolean enable = OFF; //Set fire to off
set_tris_b(0x3C); //Set PORT to desired I/O
port_b_pullups(TRUE); //Turn on PULLUPS
output_low(LED); //Turn off LED
output_low(FIRE); //Turn off output
/******************************************************************************
Main
******************************************************************************/
while(1)
{
if (input(ONOFF)) //if enable is pressed
{
enable^=0x01; //Toggle enable
}
if (enable)
{
do
{
delay_ms(5); //Approx 10ms pulse width, 50% duty cycle
output_high(FIRE);
delay_ms(5);
output_low(FIRE);
}while (temp++ < rate); //Repeat to produce pulse of desired width
temp = 0; //Reset temp
}
}
}
|
I get the foloowing error
Clean: Deleting intermediary and output files.
Clean: Done.
Executing: "C:\Program Files\Microchip\Third Party\PICC\CCSC.EXE" "main.c" +FB +DF +LN +T -A +M +Z +Y=9 +EA
*** Error 12 "C:\Program Files\Microchip\Projects\Rapid Fire\main.c" Line 50(1,15): Undefined identifier -- port_b_pullups
1 Errors, 0 Warnings.
Halting build on first failure as requested.
BUILD FAILED: Thu Jan 10 12:36:20 2008
Am I missing a header file or something?
TIA |
|
|
Guest
|
|
Posted: Thu Jan 10, 2008 6:59 am |
|
|
Think I may have found the answer
From manual
Availability:
Only 14 and 16 bit devices (PCM and PCH). (Note: use SETUP_COUNTERS on PCB parts).
How do I do this for the 12F508 if this is the case? |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Thu Jan 10, 2008 9:08 am |
|
|
Anonymous wrote: | Think I may have found the answer
From manual
Availability:
Only 14 and 16 bit devices (PCM and PCH). (Note: use SETUP_COUNTERS on PCB parts).
How do I do this for the 12F508 if this is the case? | Read your post again, you have written down the answer yourself.
The 12 bit devices are stripped down to the bare minimum. Because of register changes the port_b_pullups() function is not working. Use setup_counters instead. See the header file of your chip for details and what options are available.
Here is an example that I think might work (not tested): Code: | SETUP_COUNTERS(RTCC_INTERNAL | RTCC_DIV_32 | RTCC_8_BIT, WDT_1152MS | DISABLE_PULLUPS); |
Note that the datasheet is not very clear, but it seems like weak pull ups are only supported on pins GP0, GP1 and GP3. |
|
|
Ttelmah Guest
|
|
Posted: Thu Jan 10, 2008 9:41 am |
|
|
'DISABLE_PULLUPS', turns the pullups off.
Any setup line for the timers, _without_ this, defaults to enabling them.
Page 17 of the data sheet,makes the supported pins pretty clear (only GP0, 1 & 3, as you say).
Best Wishes |
|
|
Guest
|
|
Posted: Thu Jan 10, 2008 9:45 am |
|
|
Thats great!! Thanks for that, got it working now! How did you figure that one out?? |
|
|
Guest
|
|
Posted: Thu Jan 10, 2008 10:19 am |
|
|
If I enable the internal pullups and set the relevant IO to input, will I see the GPIO register in the Special Functions Register window (MPLAB) go to 1 to reflect the pull up? |
|
|
|