Hi All,
All other pins are working well as expected but RA4 PIN which is open drain type in pic 16f628a not working with the hardware arrangement like Vcc--R(470E)--LED--RA4. ckt is attached.
And the program is here for this operation.
Code:
#define RELAY3 PORTAbits.RA4
#define TRIS_RELAY3 TRISAbits.TRISA4
void main() // ......
{
CMCON = 0x07;//comparator disable
TRIS_RELAY3 =0; //RA4 pin making it as o/p here
RELAY3 =0; //RA4 PIN>>Open drain
while(1) // wait forever for the data received and ready AND BEING operate with below to approproate load.
{
switch(command) // swich on
{
case 0x22: RELAY3 = !RELAY3; //Toggle relay 3// ITS OPEN DRAIN RA4 PIN/
break;
//others switch command
}
}
}
code for this particular pin is shown above.
what am i missing in the code/ hardware for this particular pin for which this ra4 pin not operating while the others pin working correctly with their respective port settings.
As a current sink it will still work as expected. I would guess you have the pin configured to use LVP mode which makes it an input to start the programming process. Check the CONFIG word to make sure the pin is configured for I/O operation.
MY CONFIG IS THIS...
//__CONFIG(FOSC_HS & WDTE_OFF & PWRTE_OFF & MCLRE_OFF & BOREN_ON & LVP_OFF & CPD_ON & CP_ON);
Is not LVP related to RB4 pin and making this RB4 as digital i/o ?
when LVP=0, the RB4 becomes i/p pin.
Code:
data sheet says:
bit 7: LVP: Low-Voltage Programming Enable bit
1 = RB4/PGM pin has PGM function, low-voltage programming enabled
0 = RB4/PGM is digital I/O, HV on MCLR must be used for programming
Oops! My mistake, sorry. I guess my memory of those devices is fading away! I confused RA4 with RB4.
Try writing a simple program that just drives the pin high or low to see if 'low' makes the LED turn on. Possibly it is working but something else in your software is turning the LED off immediately.