Motherboard Forums


Reply
Thread Tools Display Modes

I mus be stupide but..

 
 
Andre
Guest
Posts: n/a
 
      04-14-2012, 04:09 PM
Begining with pic programing in C

The following prog works on a pic16f84A
#include <htc.h>
/***** CONFIGURATION *****/
__CONFIG(0x3F61);
/***** MAIN PROGRAM *****/
void main()
{
// Initialisation
TRISB = 0b00000000;
PORTB = 0b11110000;
for (;
{
// turn on LED only if button pressed
if ( RA0 == 1 )
PORTB = 0b000011;
else
PORTB = 0b110000;

}
// repeat forever
}

But the read RA0 never occurs on a pic16f627
Diplay is allways 0b110000

I am using picc ( lite ) from command line or via a Makefile
picc --warn=9 --chip=16f627a less2.c
BTW: if I use --strict, it refuse to compile ( to many errors -- FROM
the included file /usr/local/hitech/picc/9.8/include/pic16f627.h ) ???

Tested on a Vellman kit K8048 ( here a VM111 as I buy it fully monted )

It gives the same results when using MPlab??
 
Reply With Quote
 
 
 
 
Andre
Guest
Posts: n/a
 
      04-14-2012, 04:29 PM
Le 14/04/2012 18:09, Andre a écrit :
> Begining with pic programing in C
>
> The following prog works on a pic16f84A
> #include <htc.h>
> /***** CONFIGURATION *****/
> __CONFIG(0x3F61);
> /***** MAIN PROGRAM *****/
> void main()
> {
> // Initialisation
> TRISB = 0b00000000;
> PORTB = 0b11110000;
> for (;
> {
> // turn on LED only if button pressed
> if ( RA0 == 1 )
> PORTB = 0b000011;
> else
> PORTB = 0b110000;
>
> }
> // repeat forever
> }
>
> But the read RA0 never occurs on a pic16f627
> Diplay is allways 0b110000
>
> I am using picc ( lite ) from command line or via a Makefile
> picc --warn=9 --chip=16f627a less2.c
> BTW: if I use --strict, it refuse to compile ( to many errors -- FROM
> the included file /usr/local/hitech/picc/9.8/include/pic16f627.h ) ???
>
> Tested on a Vellman kit K8048 ( here a VM111 as I buy it fully monted )
>
> It gives the same results when using MPlab??


BTW: I am using PikDev to prog the chip.

A similar prog in assembler works, so it doesn't seems to be the chip
nor the programmer.
André
Many thanks in advances


 
Reply With Quote
 
 
 
 
Wolfgang Mahringer
Guest
Posts: n/a
 
      04-14-2012, 04:30 PM
Hi Andre,

In order to use a PORTA pin like RA0, you should
also setup TRISA.
Additionally, the 16f62x has a CMCON register which needs
setup, if you want to use RA0..3.

Have a look in the processor's datasheet.

However, I can say nothing about the PICC compiler...I use CC5X.

HTH,
Wolfgang


--
From-address is Spam trap
Use: wolfgang (dot) mahringer (at) sbg (dot) at
 
Reply With Quote
 
Les Cargill
Guest
Posts: n/a
 
      04-14-2012, 04:31 PM
Andre wrote:
> Begining with pic programing in C
>
> The following prog works on a pic16f84A
> #include <htc.h>
> /***** CONFIGURATION *****/
> __CONFIG(0x3F61);
> /***** MAIN PROGRAM *****/
> void main()
> {
> // Initialisation
> TRISB = 0b00000000;
> PORTB = 0b11110000;
> for (;
> {
> // turn on LED only if button pressed
> if ( RA0 == 1 )
> PORTB = 0b000011;
> else
> PORTB = 0b110000;
>
> }
> // repeat forever
> }
>
> But the read RA0 never occurs on a pic16f627
> Diplay is allways 0b110000
>


What setup is required to make RA0 an input on a
pic16f627? Does the button press actually change the state
of RA0? ( put a scope on it, in other words ).


> I am using picc ( lite ) from command line or via a Makefile
> picc --warn=9 --chip=16f627a less2.c
> BTW: if I use --strict, it refuse to compile ( to many errors -- FROM
> the included file /usr/local/hitech/picc/9.8/include/pic16f627.h ) ???
>



Are you sure your path points you to the right compiler? This
sounds a little like you don't have the toolchain set up
correctly.

Otherwise...

??? really? I'd find a forum or send their support an
email. Is there another #include that pic16f627.h depends on?


Do their #includes include other #includes, or are you expected
to do that for them?

Does pic16f627.h have a #if _PIC16F627_H_ at the top ( and the
appropriately placed #endif at the bottom) ?


> Tested on a Vellman kit K8048 ( here a VM111 as I buy it fully monted )
>
> It gives the same results when using MPlab??


--
Les Cargill
 
Reply With Quote
 
Andre
Guest
Posts: n/a
 
      04-14-2012, 04:47 PM
Le 14/04/2012 18:31, Les Cargill a écrit :
> Andre wrote:
>> Begining with pic programing in C
>>
>> The following prog works on a pic16f84A
>> #include <htc.h>
>> /***** CONFIGURATION *****/
>> __CONFIG(0x3F61);
>> /***** MAIN PROGRAM *****/
>> void main()
>> {
>> // Initialisation
>> TRISB = 0b00000000;
>> PORTB = 0b11110000;
>> for (;
>> {
>> // turn on LED only if button pressed
>> if ( RA0 == 1 )
>> PORTB = 0b000011;
>> else
>> PORTB = 0b110000;
>>
>> }
>> // repeat forever
>> }
>>
>> But the read RA0 never occurs on a pic16f627
>> Diplay is allways 0b110000
>>

>
> What setup is required to make RA0 an input on a
> pic16f627? Does the button press actually change the state
> of RA0? ( put a scope on it, in other words ).
>
>
>> I am using picc ( lite ) from command line or via a Makefile
>> picc --warn=9 --chip=16f627a less2.c
>> BTW: if I use --strict, it refuse to compile ( to many errors -- FROM
>> the included file /usr/local/hitech/picc/9.8/include/pic16f627.h ) ???
>>

>
>
> Are you sure your path points you to the right compiler? This
> sounds a little like you don't have the toolchain set up
> correctly.
>
> Otherwise...
>
> ??? really? I'd find a forum or send their support an
> email. Is there another #include that pic16f627.h depends on?
>
>
> Do their #includes include other #includes, or are you expected
> to do that for them?
>
> Does pic16f627.h have a #if _PIC16F627_H_ at the top ( and the
> appropriately placed #endif at the bottom) ?
>
>
>> Tested on a Vellman kit K8048 ( here a VM111 as I buy it fully monted )
>>
>> It gives the same results when using MPlab??

>
> --
> Les Cargill

Many thanks.

I don't use MPlab for this as it doesn't support the K8048 programmer.
When I use it, I can upload the .hex file into PikDev and then progrem
the chip
But Mplab use picc.
And rememeber tha the same prog work with a pic16f84a ??
I don't have a osciloscope ( Helas ) I am retired and oding this only
for fun ;-)))
I will be looking at your suggestions asap, my wife's calling ;-))
Andre
 
Reply With Quote
 
John Temples
Guest
Posts: n/a
 
      04-14-2012, 06:03 PM
On 2012-04-14, Andre <(E-Mail Removed)> wrote:
> The following prog works on a pic16f84A


> if ( RA0 == 1 )


> But the read RA0 never occurs on a pic16f627


RA0 is an analog pin by default. Analog pins cannot be used as
digital inputs. You must disable the analog features on the pin (the
comparator).

--
John W. Temples, III
 
Reply With Quote
 
Andre
Guest
Posts: n/a
 
      04-17-2012, 09:16 AM
Le 14/04/2012 20:03, John Temples a écrit :
> On 2012-04-14, Andre<(E-Mail Removed)> wrote:
>> The following prog works on a pic16f84A

>
>> if ( RA0 == 1 )

>
>> But the read RA0 never occurs on a pic16f627

>
> RA0 is an analog pin by default. Analog pins cannot be used as
> digital inputs. You must disable the analog features on the pin (the
> comparator).
>

That's was the problem. I configured COMCON and miracle ..
Many thanks.
André
 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT. The time now is 05:32 AM.


Welcome!
Welcome to Motherboard Point
 

Advertisment