Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

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:
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
During simulation, the program being executed by the simulator may require stimuli
from the outside. Stimulus is the simulation of hardware signals/data into the device.
This stimulus could be a level change or a pulse to an I/O pin of a port. It could be a
change to the values in an SFR (Special Function Register) or other data memory.
In addition, stimulus may need to happen at a certain instruction cycle or time during
the simulation. Alternately, stimulus may need to occur when a condition is satisfied;
for example, when the execution of program has reached a certain instruction address
during simulation.
Basically, there are two types of stimulus:
• Asynchronous – A one-time change to the I/O pin or RCREG triggered by a firing
button on the stimulus GUI within the MPLAB IDE.
• Synchronous – A predefined series of signal/data changes to an I/O pin, SFR or
GPR (e.g., a clock cycle).
To define when, what and how external stimuli are to happen to a program, you would
use the Stimulus Dialog tabs to create both asynchronous and synchronous stimulus
on a stimulus workbook. Advanced users can attach and generate an SCL (Simulator
Control Language) file for custom stimulus needs.
If you will be using multiple forms of stimulus input, you should be aware of input
 
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.

Latest threads

New Articles From Microcontroller Tips

Back
Top