PDA

View Full Version : Port Digital Output Not Changing Properly



rsocor01
- 26th March 2017, 02:08
Hi,

I'm using a 18F4550 PIC code that's running on PBP2.50. I'm pulling my hair out trying to figure out why this code won't work. :confused:



DUMMYVAR VAR BYTE

TRISB = %00000000 'SET ALL B PORTS AS OUTPUTS
ADCON1 = %00001111 'SET ALL PORTS TO DIGITAL

MAIN:

PORTA.0 = 1
PORTA.1 = 1

DO SOME STUFF......

GOTO MAIN


PORTA.0 stays low and never changes to high. However, if I do the following, then the code works and I get both ports high.



DUMMYVAR VAR BYTE

TRISB = %00000000 'SET ALL B PORTS AS OUTPUTS
ADCON1 = %00001111 'SET ALL PORTS TO DIGITAL

MAIN:

DUMMYVAR = 3
PORTA.0 = DUMMYVAR.0 : PORTA.1 = DUMMYVAR.1

DO SOME STUFF......

GOTO MAIN


So, why does the second code works and the first one doesn't? Do you need a pause or delay when changing individual port settings in the same port bank? Does the commands HIGH and LOW resolve this issue? :confused:

Thanks,

Robert

richard
- 26th March 2017, 02:26
classic RMW read modify write
watch this
http://www.microchip.com/webinars.microchip.com/WebinarDetails.aspx?dDocName=en556253
click on
View streaming media version:

rsocor01
- 26th March 2017, 05:34
Richard, wow I wasn't aware of this issue. Check out the following article. It explains in detail exactly what happened in my code.

https://download.mikroe.com/documents/compilers/mikroc/pic/help/rmw.htm

rsocor01
- 26th March 2017, 06:00
Also, is it possible to use LATCH instead or PORTx.x in PBP? How would you use the LATCH register?

richard
- 26th March 2017, 06:09
yes it's not the most thrilling video but it does explain the issue in easy to understand terms.


is it possible to use LATCH instead or PORTx.x in PBP?


pretty easy for chips with LAT regs

in your case
LATA.0 =1
LATA.1 =1

note LAT(X) cannot be used with compound commands THAT auto set TRIS regs like SERIN,I2CIN,TOGGLE etc

rsocor01
- 26th March 2017, 07:06
Thanks Richard. That helps a lot.