Need help for turning PIC16F628A's RA4 pin to high

Thread Starter

erickoh1985

Joined Feb 28, 2008
7
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
 

mik3

Joined Feb 4, 2008
4,843
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);
}
}
 

Thread Starter

erickoh1985

Joined Feb 28, 2008
7
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.
 

AlexR

Joined Jan 16, 2008
732
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.
 

ximon

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

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

Si.
 
Top