PDA

View Full Version : How to set pin to digital by default? PIC18F24J50



picmilan
- 29th May 2016, 03:37
Hello there,

I have a PIC18F24J50 and I want to set pin 0 of port A to digital pin inorder to have a push button turn an led on and off.

I have a C code that is working and sets pin 0 of port B to digital using


ANCON1bits.PCFG12 = 1;

All the C code:


void main(void) {
ANCON1bits.PCFG12 = 1; //RB0
TRISB=1;
TRISC=0;
RC0=0;
do
{
if(RB0 == 0)
{
__delay_ms(10);
if(RB0 == 0)
{
RC0 = 1;
__delay_ms(10);
RC0 = 0;
}
}
}while(1);
}

I am trying to do the same but I get error regarding PCFG12 that it doesn't exist!


All basic code:



PCFG12=1
TRISC.0 = 0
TRISB = 001111
button1 VAR PORTB.0

LED VAR PORTC.0
PortB = 0
mainloop:
If button1 = 0 Then
Low LED
Pause 600
Else
High LED
Pause 600
Endif
Goto mainloop


I appreciate if you help me get i working in Basic! Thanks

HenrikOlsson
- 29th May 2016, 07:23
PCFG12 is bit 4 in ANCON1 so

ANCON1.4 = 1
should do it, but that's for AN12 which is RB0 while you're talking about RA0 which is AN0 so

ANCON0.0 = 1

/Henrik.

picmilan
- 29th May 2016, 21:27
ANCON1.4 = 1 worked thanks!