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

12F629 and the GP0 port

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







12F629 and the GP0 port
PostPosted: Wed Feb 26, 2003 7:36 am     Reply with quote

I use PIC12F629 and would like to use the port GP0 (Pin_A0) as input.
Here the C-source code (PCM) for that switch the Pullup:

SET_TRIS_A(0x39);
port_b_pullups(TRUE);
*0x95 = 0x31;

Does not function however for the Pin_A0.
The Pullup resistance is not switched on and I gets read with

"a = input(Pin_A0);" only LOW! :-(

Even if I equip the haven with an external Pullup,
I read in each case LOW!

What can I do?
___________________________
This message was ported from CCS's old forum
Original Post ID: 12116
mark r. hahn
Guest







Re: 12F629 and the GP0 port
PostPosted: Wed Feb 26, 2003 8:08 am     Reply with quote

Don't forget to turn off the ADC inputs. Carefull reading of the 12F629 data sheet will reveal that all inputs are analog by default after a reset. Not the way I would have designed the core, but MicroChip never seems to ask me about these things :-)

Mark

My code looks something like:

#define REG_WPU 0x95

// force ports to a known good state
output_a(0x00);

*REG_WPU = 0;
setup_adc(ADC_OFF);
setup_adc_ports(NO_ANALOGS);

// ra3 is input
set_tris_a(0x09);


:=I use PIC12F629 and would like to use the port GP0 (Pin_A0) as input.
:=Here the C-source code (PCM) for that switch the Pullup:
:=
:=SET_TRIS_A(0x39);
:=port_b_pullups(TRUE);
:=*0x95 = 0x31;
:=
:=Does not function however for the Pin_A0.
:=The Pullup resistance is not switched on and I gets read with
:=
:="a = input(Pin_A0);" only LOW! :-(
:=
:=Even if I equip the haven with an external Pullup,
:=I read in each case LOW!
:=
:=What can I do?
___________________________
This message was ported from CCS's old forum
Original Post ID: 12118
mark r. hahn
Guest







Re: 12F629 and the GP0 port
PostPosted: Wed Feb 26, 2003 8:16 am     Reply with quote

Doh!!

I was thinking of the 12F675!

Man I need some more coffee :-)

Sorry,

Mark

:=Don't forget to turn off the ADC inputs. Carefull reading of the 12F629 data sheet will reveal that all inputs are analog by default after a reset. Not the way I would have designed the core, but MicroChip never seems to ask me about these things :-)
:=
:=Mark
:=
:=My code looks something like:
:=
:= #define REG_WPU 0x95
:=
:= // force ports to a known good state
:= output_a(0x00);
:=
:= *REG_WPU = 0;
:= setup_adc(ADC_OFF);
:= setup_adc_ports(NO_ANALOGS);
:=
:= // ra3 is input
:= set_tris_a(0x09);
:=
:=
:=:=I use PIC12F629 and would like to use the port GP0 (Pin_A0) as input.
:=:=Here the C-source code (PCM) for that switch the Pullup:
:=:=
:=:=SET_TRIS_A(0x39);
:=:=port_b_pullups(TRUE);
:=:=*0x95 = 0x31;
:=:=
:=:=Does not function however for the Pin_A0.
:=:=The Pullup resistance is not switched on and I gets read with
:=:=
:=:="a = input(Pin_A0);" only LOW! :-(
:=:=
:=:=Even if I equip the haven with an external Pullup,
:=:=I read in each case LOW!
:=:=
:=:=What can I do?
___________________________
This message was ported from CCS's old forum
Original Post ID: 12119
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

Re: 12F629 and the GP0 port
PostPosted: Wed Feb 26, 2003 12:19 pm     Reply with quote

I would quit using CCS's built in functions and set the registers myself. This way you aren't as concerned with errors generated from the compiler.

#byte WPU = 0x95
#byte ANSEL = 0x9F
#byte TRISIO = 0x85

TRISIO = 0x39;
// Turn on pullups for GPIO0, GPIO4, and GPIO5. Note that GPIO3 does not have an internal pullup
WPU = 0x31;
// Make sure the pins are assigned to digital i/o. This can't hurt and also allows the code to work on an 12F675.
ANSEL = 0;



:=I use PIC12F629 and would like to use the port GP0 (Pin_A0) as input.
:=Here the C-source code (PCM) for that switch the Pullup:
:=
:=SET_TRIS_A(0x39);
:=port_b_pullups(TRUE);
:=*0x95 = 0x31;
:=
:=Does not function however for the Pin_A0.
:=The Pullup resistance is not switched on and I gets read with
:=
:="a = input(Pin_A0);" only LOW! :-(
:=
:=Even if I equip the haven with an external Pullup,
:=I read in each case LOW!
:=
:=What can I do?
___________________________
This message was ported from CCS's old forum
Original Post ID: 12129
Peter Werlitz
Guest







Re: 12F629 and the GP0 port
PostPosted: Thu Feb 27, 2003 4:38 am     Reply with quote

Thank you for the Tips. It did not help!
The GP0-Pullup does not switch on. :-(
Even if I read GP0 get I in each case LOW, even if I externally with a pullup
resistance put the pin!
What can I make in addition?
Many thanks!

Peter
___________________________
This message was ported from CCS's old forum
Original Post ID: 12162
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

Re: 12F629 and the GP0 port
PostPosted: Thu Feb 27, 2003 7:13 am     Reply with quote

How are you determining wether the input is high or low? Can you post the rest of your code. Maybe the problem lies elsewhere.

Regards,
Mark

:=Thank you for the Tips. It did not help!
:=The GP0-Pullup does not switch on. :-(
:=Even if I read GP0 get I in each case LOW, even if I externally with a pullup
:=resistance put the pin!
:=What can I make in addition?
:=Many thanks!
:=
:=Peter
___________________________
This message was ported from CCS's old forum
Original Post ID: 12165
Peter Werlitz
Guest







Re: 12F629 and the GP0 port
PostPosted: Thu Feb 27, 2003 8:15 am     Reply with quote

Hi Mark!

Here is the important part code. I hope, you find something, which is not correct.

// *** Test GP0 ***
#include <12F629.h>
#fuses INTRC_IO,NOMCLR,NOWDT,NOPROTECT,PUT,BROWNOUT
#use Delay(Clock=4000000) // RC-Osc. internal 4 MHz

#byte WPU = 0x95 // WPU
#byte ANSEL = 0x9F // ADC
#byte TRISIO = 0x85 // TRIS-IO

#define GP0 PIN_A0
#define GP2 PIN_A2

void init(void); //Prototype

// *** Init ***
void
init(){
ANSEL = 0; // ADC off (only 12F675 ??)
TRISIO = 0x39; // TRISIO: P0, P3, P4 and P5 = Inputs
port_b_pullups(TRUE); // OPTION-REG.7: GPPU = 0
WPU = 0x31; // Pullup P0, P4 and P5 on
}

// *** Main ***
void
main(){
init();
while(TRUE){
if(input(GP0) == TRUE) output_high(GP2);
else output_low (GP2);
}
}

Output "GP2" does not make the same as at the input "GP0"!

I thank for your assistance.

Greetings Peter
___________________________
This message was ported from CCS's old forum
Original Post ID: 12167
R.J.Hamlett
Guest







Re: 12F629 and the GP0 port
PostPosted: Thu Feb 27, 2003 10:06 am     Reply with quote

:=Hi Mark!
:=
:=Here is the important part code. I hope, you find something, which is not correct.
:=
:=// *** Test GP0 ***
:=#include <12F629.h>
:=#fuses INTRC_IO,NOMCLR,NOWDT,NOPROTECT,PUT,BROWNOUT
:=#use Delay(Clock=4000000) // RC-Osc. internal 4 MHz
:=
:=#byte WPU = 0x95 // WPU
:=#byte ANSEL = 0x9F // ADC
:=#byte TRISIO = 0x85 // TRIS-IO
:=
:=#define GP0 PIN_A0
:=#define GP2 PIN_A2
:=
:=void init(void); //Prototype
:=
:=// *** Init ***
:=void
:=init(){
:= ANSEL = 0; // ADC off (only 12F675 ??)
:= TRISIO = 0x39; // TRISIO: P0, P3, P4 and P5 = Inputs
:= port_b_pullups(TRUE); // OPTION-REG.7: GPPU = 0
:= WPU = 0x31; // Pullup P0, P4 and P5 on
:=}
:=
:=// *** Main ***
:=void
:=main(){
:= init();
:= while(TRUE){
:= if(input(GP0) == TRUE) output_high(GP2);
:= else output_low (GP2);
:= }
:=}
:=
:=Output "GP2" does not make the same as at the input "GP0"!
:=
:=I thank for your assistance.
:=
:=Greetings Peter
Try, instead of setting 'ANSEL', setting 'CMCON' (address 0x1F), so have the bottom three bits high. This register defaults to all zeros, which programs RA0 to RA3, as analog inputs to the comparator modules.
You can do this with the function:
setup_comparators(NC_NC_NC_NC);

or by directly accessing the address as you show with ANSEL.

Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 12173
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

Re: 12F629 and the GP0 port
PostPosted: Thu Feb 27, 2003 12:12 pm     Reply with quote

Try the following:

// *** Test GP0 ***
#include <12F629.h>
#fuses INTRC_IO,NOMCLR,NOWDT,NOPROTECT,PUT,BROWNOUT
#use Delay(Clock=4000000) // RC-Osc. internal 4 MHz

#byte WPU = 0x95 // WPU
#byte ANSEL = 0x9F // ADC
#byte CMCON = 0x19 // Comparator
#byte TRISIO = 0x85 // TRIS-IO

#use fast_IO (A)

#define GP0 PIN_A0
#define GP2 PIN_A2

void init(void); //Prototype

// *** Init ***
void
init(){
ANSEL = 0; // ADC off (only 12F675 ??)
CMCON = 0;
TRISIO = 0x39; // TRISIO: P0, P3, P4 and P5 = Inputs
port_b_pullups(TRUE); // OPTION-REG.7: GPPU = 0
WPU = 0x31; // Pullup P0, P4 and P5 on
}

// *** Main ***
void
main(){
init();
while(TRUE){
if(input(GP0) == TRUE) output_high(GP2);
else output_low (GP2);
}
}

Regards,
Mark
:=Hi Mark!
:=
:=Here is the important part code. I hope, you find something, which is not correct.
:=
:=// *** Test GP0 ***
:=#include <12F629.h>
:=#fuses INTRC_IO,NOMCLR,NOWDT,NOPROTECT,PUT,BROWNOUT
:=#use Delay(Clock=4000000) // RC-Osc. internal 4 MHz
:=
:=#byte WPU = 0x95 // WPU
:=#byte ANSEL = 0x9F // ADC
:=#byte TRISIO = 0x85 // TRIS-IO
:=
:=#define GP0 PIN_A0
:=#define GP2 PIN_A2
:=
:=void init(void); //Prototype
:=
:=// *** Init ***
:=void
:=init(){
:= ANSEL = 0; // ADC off (only 12F675 ??)
:= TRISIO = 0x39; // TRISIO: P0, P3, P4 and P5 = Inputs
:= port_b_pullups(TRUE); // OPTION-REG.7: GPPU = 0
:= WPU = 0x31; // Pullup P0, P4 and P5 on
:=}
:=
:=// *** Main ***
:=void
:=main(){
:= init();
:= while(TRUE){
:= if(input(GP0) == TRUE) output_high(GP2);
:= else output_low (GP2);
:= }
:=}
:=
:=Output "GP2" does not make the same as at the input "GP0"!
:=
:=I thank for your assistance.
:=
:=Greetings Peter
___________________________
This message was ported from CCS's old forum
Original Post ID: 12177
Peter Werlitz
Guest







Re: 12F629 and the GP0 port
PostPosted: Fri Feb 28, 2003 12:51 am     Reply with quote

Thanks you!

But it does not function. Apparent the haven GP0 cannot be
persuaded in addition an input to be with the 12F629. It is only output!
It be can that in the data sheet an error is?

Regards Peter
___________________________
This message was ported from CCS's old forum
Original Post ID: 12205
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: 12F629 and the GP0 port
PostPosted: Fri Feb 28, 2003 2:21 pm     Reply with quote

:=Thanks you!
:=
:=But it does not function. Apparent the haven GP0 cannot be
:=persuaded in addition an input to be with the 12F629. It is only output!
:=It be can that in the data sheet an error is?
:=
-----------------------------------------------------------

Can you tell us what version of the PCM compiler you have ?

Also, post a list of what configuration you want for each pin.
Example:
GP0 = input
GP1 = output
etc.

Then, we can install that version of the compiler, and compile
the code, and examine the .LST file, and find out exactly
what is happening.



___________________________
This message was ported from CCS's old forum
Original Post ID: 12234
Peter Werlitz
Guest







Re: 12F629 and the GP0 port
PostPosted: Mon Mar 03, 2003 2:00 am     Reply with quote

The PCM compiler is version 3.146. The PIC is 12F629.

GP0 should input
GP1 should output

Be I by the way exchanged with pins once. The same problem.
As outputs the pins always function, as inputs read I in each LOW!!!

The pins are simply never inputs and the inserted Pullup cannot I with both pins not switch on.

The C-code seems to be OK ONE.

The pins GP4 and GP5 function as inputs and there are also the inserted Pullups switched on.
Somehow must be configured the two pins GP0 and GP1 differently. ADC and comparators do not switch off anything had changed.

I am with my knowledge at the end.
___________________________
This message was ported from CCS's old forum
Original Post ID: 12298
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: 12F629 and the GP0 port
PostPosted: Mon Mar 03, 2003 2:27 pm     Reply with quote

:=The PCM compiler is version 3.146. The PIC is 12F629.
:=
:=GP0 should input
:=GP1 should output
:=
:=Be I by the way exchanged with pins once. The same problem.
:=As outputs the pins always function, as inputs read I in each LOW!!!
-----------------------------------------------------------

For PCM vs. 3.146, the following code looks OK.
This is very similar to the test program that was
already posted. But try it anyway.

I noticed that the start-up code that is inserted by
the compiler is writing 0x07 to register 0x1F.
That's the ADCON0 register, but it does not exist
for the 12F629. So hopefully, that code is harmless.


One other possible problem:
You are using the internal RC oscillator. Is it possible
that you have erased the calibration values which are
stored at ROM address 0x3FF. If you did, there could be
a problem. The compiler inserts code to call that address.
You can see it in the .LST file:

<PRE>
0004 23FF 00005 CALL 3FF
</PRE>

If you erased the code at ROM address 0x3FF, then the entire
program might not work. Maybe that's what is happening.

See this article by Mr. Hamlett on how to fix this problem:
<a href="http://www.pic-c.com/forum/general/posts/9234.html" TARGET="_blank">http://www.pic-c.com/forum/general/posts/9234.html</a>

<PRE>
#include <12F629.h>
#fuses INTRC_IO,NOMCLR,NOWDT,NOPROTECT,PUT,BROWNOUT
#use Delay(Clock=4000000) // RC-Osc. internal 4 MHz
<BR>
#byte WPU = 0x95 // WPU
#byte TRISIO = 0x85 // TRIS-IO
<BR>
#define GP0 PIN_A0
#define GP2 PIN_A2
<BR>
//=================================================
<BR>
void main()
{
<BR>
setup_comparator(NC_NC_NC_NC); // Turn off the comparators
<BR>
// TRISIO: P0, P3, P4 and P5 = Inputs
// P1, P2 = Outputs
TRISIO = 0x39;
<BR>
<BR>
port_b_pullups(TRUE); // OPTION-REG.7: GPPU = 0
<BR>
WPU = 0x31; // Pullup P0, P4 and P5 on
<BR>
while(TRUE)
{
if(input(GP0) == TRUE)
output_high(GP2);
else
output_low (GP2);
}
<BR>
}
</PRE>
___________________________
This message was ported from CCS's old forum
Original Post ID: 12310
Peter Werlitz
Guest







Re: 12F629 and the GP0 port
PostPosted: Tue Mar 04, 2003 1:10 am     Reply with quote

Yeep. The instruction

setup_comparator(NC_NC_NC_NC); // Turn off the comparators

is necessary for the PIC12F629/675, if one wants to use GP0 and GP1 as digital inputs. I thank all for the help. :-)

Best regards from old Germany
Peter
___________________________
This message was ported from CCS's old forum
Original Post ID: 12315
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