PIC18F13K22 IO problems

Beta Testing discussion on mikroBasic PRO for PIC.
Post Reply
Author
Message
cgagner
Posts: 57
Joined: 01 Jan 2006 19:56
Location: Saint Bruno de Montarville, Qc Canada

PIC18F13K22 IO problems

#1 Post by cgagner » 20 Nov 2012 00:58

Hi,
I have this very simple code that does not work. If I access PORTA.0 directly it works fine but going trough an IF bloc, it does not. I am sure I must be over looking some evident missing something. I have been reading all I could in the PIC's data sheets, internet, etc.
EasyPic7

program MyProject
' test
' Declarations section
' Use an PIC18F13K22, INTOSC 8MHz
main:
' Main program

cm1con0.c1on = 0 ' comparators off
cm2con0.c2on = 0
adon_bit = 0 'adc off

porta = 0
trisa.1 = 1
trisa.0 = 0
lata.0 = 1
delay_ms(1000)

while TRUE
'delay_ms(1000) ' this works... if you uncomment the bloc and comment the if bloc.
'lata.0 = 1
'delay_ms(1000)
'lata.0 = 0

if porta.1 = 1 then ' this does not... as is...
lata.0 = 1
else
lata.0 = 0
end if

wend
end.

janni
Posts: 5373
Joined: 18 Feb 2006 13:17
Contact:

Re: PIC18F13K22 IO problems

#2 Post by janni » 20 Nov 2012 01:46

You should configure respective PORTA inputs as digital. Otherwise they stay analog and will be read as zero when treated as digital. Look for ANSELA register in datasheet.

cgagner
Posts: 57
Joined: 01 Jan 2006 19:56
Location: Saint Bruno de Montarville, Qc Canada

Re: PIC18F13K22 IO problems

#3 Post by cgagner » 20 Nov 2012 03:25

Many thanks for a very fast and constructive answer. All is working fine.
Claude Gagner

Post Reply

Return to “mikroBasic PRO for PIC Beta Testing”