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

Simple question about port i/o

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







Simple question about port i/o
PostPosted: Wed Jan 16, 2008 6:20 pm     Reply with quote

HI,

I have written a very simple program to turn all the port bits on for the 12F509. But when I run it in MPLAB I cant get GP2 to turn on. I was wondering if this is some strange querk in MPLAB or is there something wrong with my program?? I'm beginning to tear my hair out!!

Code:
//                             Version 1.00
//
//
//********************************************************

#include "12F509.h"

#fuses INTRC,NOWDT,NOPROTECT,NOPROTECT,NOMCLR
#use delay(clock=4000000

void main(void)
{
/********************************************************
                        Initilisation
*********************************************************/

 set_tris_b(0x00);   //Set PORT all output

/*******************************************************
                            Main
********************************************************/

output_high(pin_b0);
output_high(pin_b1);
output_high(pin_b2);
output_high(pin_b3);
output_high(pin_b4);
output_high(pin_b5);
         
}


TIA
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jan 16, 2008 7:14 pm     Reply with quote

Quote:

output_high(pin_b0);
output_high(pin_b1);
output_high(pin_b2);
output_high(pin_b3);
output_high(pin_b4);
output_high(pin_b5);

I cant get GP2 to turn on

You probably mean GP3. It can't be done because that's an input-only
pin.
Guest








PostPosted: Thu Jan 17, 2008 2:24 am     Reply with quote

No, its GP2 & GP3. I know GP3 cant be outputted as it is configured as input only.

I still cant get this to work?????
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jan 17, 2008 2:46 am     Reply with quote

It's probably because the T0CS bit in the OPTION register is set to 1.
Use the set_options() macro to change the OPTION register so that
bit is set to 0. Example:

Add the set_options() macro above main(), and then call it at the
start of your program. See the 12F509 data sheet for an explanation
of the bits in the OPTION register.
Code:

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

void main()
{
set_options(0xC0);   // Allow use of GP2 for i/o


// Put the rest of your program here.



while(1); // Prevent PIC from going to sleep.  Important !
}
Guest








PostPosted: Thu Jan 17, 2008 3:49 am     Reply with quote

Thanks for that, works fine now. Very Happy
stewc
Guest







PostPosted: Thu Jan 17, 2008 8:00 am     Reply with quote

I am making progress but have encountered another problem

Here is my code

Code:
#include "12F509.h"

#use fast_io(B)
#fuses INTRC,NOWDT,PROTECT,NOPROTECT,MCLR
#use delay(clock=4000000)

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

#define ENABLEPULLUPS (0)
#define DISABLEPULLUPS (128)

void main(void)
{
/******************************************************************************
            Initilisation
******************************************************************************/

   
      SETUP_TIMER_0(RTCC_DIV_1 | ENABLEPULLUPS);   //Work around to enable pullups

   set_options(0x80);               // Allow use of GP2 for i/o

    set_tris_b(0x3A);            //Set PORT to desired I/O

/******************************************************************************
                Main
******************************************************************************/

      while(1)
      {
         output_bit(PIN_B2,input(PIN_B1));
         
         output_bit(PIN_B0,input(PIN_B3));
      }   
}


The program doesnt read B3 properly and subsequently wont output to B0
If I change B3 to B1 it works fine.

I have built a simple test circuit to test this. a switch to GND off B1 and B3 and 2 LEDs off B0 and B2. B3 is normally high (pullups enabled) and goes low when I press the button but it doesnt read it properly.

I cant see what is wrong
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jan 17, 2008 5:49 pm     Reply with quote

Quote:

The program doesnt read B3 properly.

#fuses INTRC,NOWDT,PROTECT,NOPROTECT,MCLR

Whenever a pin doesn't work as expected, it's probably because it
has not been configured to work in the desired mode.

Download the 12F509 data sheet and look at this table (on page 13 in
the Acrobat reader):
Quote:
TABLE 3-2: PIC12F508/509 PINOUT DESCRIPTION

It shows the three possible modes that the GP3 pin can be in.
http://ww1.microchip.com/downloads/en/DeviceDoc/41236D.pdf

One of them is programming mode, which is not relevant. The other
two modes are: GP3 can either be an input pin or it can be the MCLR pin.
These two modes are controlled by Config bits (CCS calls them fuses).
You can see a list of the fuse settings at the top of the 12F509.H file.
Quote:
/////// Fuses: LP,XT,INTRC,RC,NOWDT,WDT,PROTECT,NOPROTECT,NOMCLR,MCLR

Here's the file location:
Quote:
c:\Program Files\picc\Devices\12F509.h

By looking at that table in the data sheet, and the list of fuse settings,
you should be able to figure out how to fix the problem.
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