1. This forum section is a read-only archive which contains old newsgroup posts. If you wish to post a query, please do so in one of our main forum sections (here). This way you will get a faster, better response from the members on Motherboard Point.

I mus be stupide but..

Discussion in 'Embedded' started by Andre, Apr 14, 2012.

  1. Andre

    Andre Guest

    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??
     
    1. Advertising

  2. Andre

    Andre Guest

    Re: I must be stupide but..

    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
     
    1. Advertising

  3. 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
     
  4. Les Cargill

    Les Cargill Guest

    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
     
  5. Andre

    Andre Guest

    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
     
  6. John Temples

    John Temples Guest

    On 2012-04-14, Andre <> 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
     
  7. Andre

    Andre Guest

    Le 14/04/2012 20:03, John Temples a écrit :
    > On 2012-04-14, Andre<> 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é
     
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Doug G.
    Replies:
    5
    Views:
    473
    - HAL9000
    Jul 12, 2003
  2. TomG
    Replies:
    0
    Views:
    368
  3. Maxy Z. Toplik

    Re: Homie did an excellent job but!!

    Maxy Z. Toplik, Jul 12, 2003, in forum: Abit
    Replies:
    1
    Views:
    348
    John Lewis
    Jul 13, 2003
  4. Andy Louie
    Replies:
    1
    Views:
    733
  5. Wendell III
    Replies:
    5
    Views:
    296
    Wendell III
    Jul 16, 2005
Loading...

Share This Page