why is my PORT not going HIGH?

Status
Not open for further replies.

st222

New Member
I configured my PORTA on mplab as an input but sending one to it does absolutely nothing. Does this means i can only see a change only if its configured as output?

my code goes:

Code:
org 0x00
goto init


org 0x04
nop
retfie


init: bsf STATUS,RP0
      bcf STATUS,RP1 ; bank 0
      movlw 0xFF
      movwf TRISA ; PORTA input
      bcf STATUS,RP0
      bsf STATUS,RP1 ; bank 2
      clrf ANSEL ; PORTA as digital I/O
      clrf ANSELH 
      bcf STATUS,RP1 ; back to bank 1
      
      
      
run: movlw 0xFF
     movwf PORTA ;why is PORTA not going high
     goto run      
end
 
Last edited:
Hi,
To output a '1' the port pin must be set to output, ie: TRISA=0
 
I configured my PORTA on mplab as an input but sending one to it does absolutely nothing. Does this means i can only see a change only if its configured as output?

By "sending one to it" do you mean you are toggling a stimulus in the simulator?

John
 
st222 Look at it this way A input means your waiting on something so you wait and read.

Now the output is like the mailman he is bringing you some more to read.

Input can be read high low and no Z

Output can be high or LOW

And to set for this is like what Eric said you set the TRIS register 0 sets to output and 1sets to input

You read the pin like this
If PORTB.1 = 1 // IT's high
If PORTB.1 = 0 // It's low
or
BTFSC portb,1 //Bit Test f, Skip if Clear
or
BTFSS portb,1 //Bit Test f, Skip if Set

why is PORTA not going high
because you didn't set it to output
Code:
MOVLW 00h ; Value used to
; initialize data
; direction
MOVWF TRISA

Code:
run: movlw 0xFF // This sets it high
     movwf PORTA ;why is PORTA not going high
     goto run
 
Last edited:
If the chip has a comparator... you need to disable it CMCON = 0x7... ( usually RA0 is the comparator input )
 
hi Burt,
I think you have a typo.
Eric
And to set for this is like what Eric said you set the TRIS register 1 sets to output and 0 sets to input
 
Last edited:
Sorry I was thinking out loud and had this part on my mind
Code:
movlw 0xFF
movwf TRISA ; PORTA input
Can't set inputs only read them
 
init: bsf STATUS,RP0
bcf STATUS,RP1 ; bank 0
movlw 0xFF
movwf TRISA ; PORTA input
This is Setting to INPUT
bcf STATUS,RP0
bsf STATUS,RP1 ; bank 2
clrf ANSEL ; PORTA as digital I/O
clrf ANSELH
bcf STATUS,RP1 ; back to bank 1



run: movlw 0xFF
movwf PORTA ;why is PORTA not going high
; this trying to set an output
goto run
end


Check your code.
 
Last edited:
Hi Burt,

it becomes clear now. Thanks for the explanation. Lets say i want to test the workings of interupt on change for PORTA.0, then obviously i'll need a change on PORTA.0.

if I understand very well, for simulation purposes i'll have to configure PORTA.0 as output so that i can be able to excite some change on it. is this right?

Thanks.
 
I simulation you test it just as with hardware you'll toggle the pin which depends on what simulation software your using how you do that some use work sheets that let you and some let you add a node with the value to simulate
 
I'm using MPLAB SIM.

I simulation you test it just as with hardware you'll toggle the pin which depends on what simulation software your using how you do that some use work sheets that let you and some let you add a node with the value to simulate
 
Have a look at the pdf that Jpanhalt posted on post12

I dont use it much these days I like oshonsoft and real hardware
 
Hi John,
I basically want to simulate an input to PORTA, so i'm just sending 1 to it in my code. I've never used a stimulus.

As pointed out, that won't work. That's the confusion I referred to. Set the pin direction as input (TRIS = 1 for that pin). Then use a Stimulus to make it high or low or oscillate as you want. Monitor what your program does. Step through the program to find your problems. Setting breakpoints can be very helpful, particularly if you have delays.

John

Edit: Of course, analog inputs for the pin, namely any comparator, need to be turned off as mentioned above.
 
Last edited:
Your code should look like this:
org 0x00
nop
goto init
org 0x04

init: bsf STATUS,RP0 ; select bank1 first, address of TRISA
movlw 0x00
movwf TRISA ; put 0x00 in TRISA to make all PortA pins output
bcf STATUS,RP0 ; go back to bank0 for programming
CLRF PORTA ; clear portA



run: movlw 0xFF
movwf PORTA ;portA pins should be high now
goto run
end

I recommend you take time to visit this site and learn the basics:

**broken link removed**


was this helpful?
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…