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??
I mus be stupide but..
Started by ●April 14, 2012
Reply by ●April 14, 20122012-04-14
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 by ●April 14, 20122012-04-14
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 by ●April 14, 20122012-04-14
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 by ●April 14, 20122012-04-14
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 CargillMany 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 by ●April 14, 20122012-04-14
On 2012-04-14, Andre <pas.mois@ailleur.be> wrote:> The following prog works on a pic16f84A> if ( RA0 == 1 )> But the read RA0 never occurs on a pic16f627RA0 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 by ●April 17, 20122012-04-17
Le 14/04/2012 20:03, John Temples a écrit :> On 2012-04-14, Andre<pas.mois@ailleur.be> 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é