|
|
View previous topic :: View next topic |
Author |
Message |
Peter Werlitz Guest
|
12F629 and the GP0 port |
Posted: Wed Feb 26, 2003 7:36 am |
|
|
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 |
Posted: Wed Feb 26, 2003 8:08 am |
|
|
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 |
Posted: Wed Feb 26, 2003 8:16 am |
|
|
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
|
Re: 12F629 and the GP0 port |
Posted: Wed Feb 26, 2003 12:19 pm |
|
|
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 |
Posted: Thu Feb 27, 2003 4:38 am |
|
|
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
|
Re: 12F629 and the GP0 port |
Posted: Thu Feb 27, 2003 7:13 am |
|
|
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 |
Posted: Thu Feb 27, 2003 8:15 am |
|
|
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 |
Posted: Thu Feb 27, 2003 10:06 am |
|
|
:=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
|
Re: 12F629 and the GP0 port |
Posted: Thu Feb 27, 2003 12:12 pm |
|
|
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 |
Posted: Fri Feb 28, 2003 12:51 am |
|
|
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
|
Re: 12F629 and the GP0 port |
Posted: Fri Feb 28, 2003 2:21 pm |
|
|
:=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 |
Posted: Mon Mar 03, 2003 2:00 am |
|
|
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
|
Re: 12F629 and the GP0 port |
Posted: Mon Mar 03, 2003 2:27 pm |
|
|
:=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 |
Posted: Tue Mar 04, 2003 1:10 am |
|
|
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 |
|
|
|
|
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
|