Need help for turning PIC16F628A's RA4 pin to high

Discussion in 'Embedded Systems and Microcontrollers' started by erickoh1985, May 1, 2008.

  1. erickoh1985

    Thread Starter New Member

    Feb 28, 2008
    7
    0
    i have a problem of turning on LED light at RA4 for PIC16F628A.
    i know that this pin (RA4) is also T0CKI and CMP2 pin.
    i think by default this pin (RA4) is set as TOCKI or CMP2 but not as I/O pin, therefore this pin can't turn High.
    So is anyone know how to set this pin (RA4 pin) as I/O pin?
    i am using ccs c compiler.tx.

    below is my source code and circuit picture, please refer it for more detail. Tx.

    Code:

    #include <16F628A.h>
    #fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP,INTRC_IO
    #use delay(clock=4000000)
    void main()
    {
    set_tris_a(0b00000000);
    output_a(0b00000000);
    while (true)
    {

    output_a(0b11111111);
    }
    }

    my picture link: http://www.imagehosting.com/show.php/1726932_pic16f628a.JPG.html
     
  2. mik3

    Senior Member

    Feb 4, 2008
    4,846
    63
    try this

    #include <16F628A.h>
    #fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP,INTRC_IO
    #use delay(clock=4000000)
    void main()
    {
    setup_oscillator(OSC_8MHZ);

    set_tris_a(0b00000000);
    output_a(0b00000000);
    while (true)
    {

    output_a(0b11111111);
    }
    }
     
  3. erickoh1985

    Thread Starter New Member

    Feb 28, 2008
    7
    0
    i have try the code that you provide to me.Tx 1st.
    but the error come out show "OSC_8MHz" is undefined.
    since i am using internal crystal so it should put "setup_oscillator(OSC_4MHZ);" instead of "setup_oscillator(OSC_8MHZ);" right??
    below is the code:
    #include <16F628A.h>
    #fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP,INTRC_IO
    #use delay(clock=4000000)
    void main()
    {
    setup_oscillator(OSC_4MHZ);

    set_tris_a(0b00000000);
    output_a(0b00000000);
    while (true)
    {

    output_a(0b11111111);
    }
    }

    with above code, the LED on RA4 still remain at LOW....it does not goes High.
     
  4. AlexR

    Well-Known Member

    Jan 16, 2008
    735
    54
    When your PIC fires up the pins on port A default to being analog inputs. You need to configure port A to be a digital port by writing the appropriate value to the cmcon register, check the data sheet to see what value you need but 0x0F seems to work for me.
     
  5. Art

    Distinguished Member

    Sep 10, 2007
    785
    61
    I think it's cmcon = 0x07 to set all ports digital for F628.
     
  6. ximon

    New Member

    Sep 5, 2009
    1
    0
    Pin RA4 is open collector, you need a pull-up resistor

    (Yes i know this thread is old but it might help somebody)

    Si.
     
Loading...