CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

PIC10F220 problem initializing GP0 as input.

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
qbone



Joined: 04 Sep 2012
Posts: 6
Location: Danmark

View user's profile Send private message MSN Messenger

PIC10F220 problem initializing GP0 as input.
PostPosted: Mon Sep 24, 2012 5:50 am     Reply with quote

Hey guys
I have a problem with my code. I cannot get my PIC to set GP0 (PIN_B0) as an input.
I have a 10K pull down resistor on it, but I still measure 1.925V.
Can you see if I am doing something wrong? As far as I could read in the datasheet I just need to turn the ADC off.

Code:
#include <10F220.h>
#fuses NOMCLR,NOPROTECT,NOWDT,NOMCPU,IOSC4
#use delay(clock=4000000)
#rom 0xFF = {0xC00}  // Put MOVLW 0x00 at end of ROM
#byte osccal = 0x05

#define GP0      PIN_B0
#define GP1      PIN_B1
#define GP2      PIN_B2
#define GP3      PIN_B3

#define set_options(value)   {#ASM         \
                              MOVLW  value \
                              OPTION       \
                              #ENDASM}
void init()
{
   osccal = osccal & 0xFE;
   set_options(0xDF);
   setup_timer_0(T0_INTERNAL);
   setup_adc(ADC_OFF);
   setup_adc_ports(NO_ANALOGS);
}

void main()
{
   init();
   long i;
   while(TRUE) {
      output_low(GP1);
      if(!input(GP2) == 1) {          // If fridge open
         delay_ms(10000);          // 10sec delay
         if(input(GP0) == 1) {      // If postpone
            delay_ms(30000);       // 30sec delay
         }
         while(!input(GP2)) {      // Buzz frequency
            for(i = 0; i < 600; i++) {
               delay_us(400);
               output_high(GP1);
               delay_us(400);
               output_low(GP1);
            }
            delay_ms(1000);
         }
      }
   }
}


I even tried adding output_float(GP0) / output_float(PIN_B0) in my init() routine, but it doesn't change anything :(

I am programming in MPLAB v8.85, compiling with CCS C Compiler v4.
my programmer is a Olimex PIC-MCP-USB (PICSTART+).
Ttelmah



Joined: 11 Mar 2010
Posts: 19327

View user's profile Send private message

PostPosted: Mon Sep 24, 2012 7:06 am     Reply with quote

I'd be triple checking for a short, almost invisible wire 'whisker', connecting the pin to something else.

Best Wishes
qbone



Joined: 04 Sep 2012
Posts: 6
Location: Danmark

View user's profile Send private message MSN Messenger

PostPosted: Mon Sep 24, 2012 8:12 am     Reply with quote

I have just tried burning it on a new IC, and moving it some places on the breadboard, but I still get the same result Confused
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Mon Sep 24, 2012 10:19 am     Reply with quote

An internal pull up resistor would give you the kind of voltage you're reporting. (Just a thought)

I presume you're working on a white board of some sort.

The weak pull-ups are controlled by the option register and SHOULD default to disabled.

Mike
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Sep 24, 2012 12:56 pm     Reply with quote

I was able to make GP0 work as an input on a 10F222. That PIC is in
the same family as the 10F220. I put a 4.7K pull-up resistor (to +5v)
on GP0. Then I put an oscilloscope probe on GP2. Then when I tapped
pin GP0 with a ground lead, the oscilloscope showed GP2 going to 0v.
When I removed the ground on GP0, then GP2 went back to +5v output.
So it's working. This was tested with PCB vs. 4.073 (which is included with
MPLAB vs. 8.86).
Code:

#include <10F222.h>
#fuses NOMCLR,NOPROTECT,NOWDT,NOMCPU,IOSC4
#use delay(clock=4M)

#define GP0 PIN_B0
#define GP1 PIN_B1
#define GP2 PIN_B2
#define GP3 PIN_B3

#define set_options(value)   {#ASM         \
                              MOVLW  value \
                              OPTION       \
                              #ENDASM}

//====================================
void main(void)
{
int8 temp;

setup_adc_ports(NO_ANALOGS);
set_options(0xDF);

while(1)
  {
   temp = input(GP0);     // Read GP0 input level
   output_bit(GP2, temp); // Output same level to GP1   
  }

}
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Mon Sep 24, 2012 1:25 pm     Reply with quote

Yes, but is it possible that when you work the other way up, as the original poster is doing, that the internal pull-up is fighting the 10k pull-down.?

Mike
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Sep 24, 2012 2:33 pm     Reply with quote

Quote:

void init()
{
osccal = osccal & 0xFE;
set_options(0xDF);
setup_timer_0(T0_INTERNAL);
setup_adc(ADC_OFF);
setup_adc_ports(NO_ANALOGS);
}

The line in bold is over-writing the OPTION register settings that were
done by the previous line. Look at the .LST file to see this.


Quote:
void main()
{
init();
long i;

CCS doesn't support declaration of variables in the middle of code.
Put all local variable declarations at the start of the function.
Ttelmah



Joined: 11 Mar 2010
Posts: 19327

View user's profile Send private message

PostPosted: Tue Sep 25, 2012 8:53 am     Reply with quote

As another comment, what actual compiler version?. V4, is a 'family' of at present over 130 versions. The versions below about 4.070, were basically 'beta', and are full of bugs....
I notice you are manually setting the OSCCAL register. The compiler does this automatically if the internal oscillator is selected, and if you are doing this because this doesn't work, it suggests a very early compiler, possibly with initialisation problems.

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group