PDA

View Full Version : PORT byte problem



IFF1749
- 7th August 2004, 16:24
Greetings


MCU is pic18f452 & program is simple:

TRISA = %00000000 'set all PORTA to outputs

Start:

PORTA.0 = 1 'turn on led1
PAUSE 1000
PORTA.1 = 1 'turn on led2
PAUSE 1000
PORTA.2 = 1 'turn on led3
PAUSE 1000
PORTA.3 = 1 'turn ON led4
PAUSE 1000
PORTA = %00000000 'turn OFF all leds

goto Start

...but what really happens is not that i expected
all the leds wont be turned ON at the end,
when led2 turns ON the led 1 turns OFF
and when the led3 turns ON led 2 turns OFF and so on,
only 1 led is turned ON at time..

Why is it like this?

Has much as I understand the PORTA.x=1 must modify
only 1 bit in PORTA - not to set 1 bit and clear others.

Hawe I done something wrong or is there something i
dont know?

Best Regards
IFF.

Melanie
- 7th August 2004, 17:40
I have come across this problem sporadically... though I haven't had enough time to investigate why sometimes it occurs in some applications and sometimes it doesn't.

It last happened to me when I did this example...

http://www.picbasic.co.uk/forum/showthread.php?s=&threadid=573

...which co-incidentally I've just noticed, also had all the LED's sequentially on PortA... hmmm...

Generally I have employed this kind of easy work-around when caught in a corner with clients gunning for me... and you'll notice I did a similar thing with that comms example.


PortAStatus var BYTE
PortA0 var PortAStatus.0
PortA1 var PortAStatus.1
PortA2 var PortAStatus.2
PortA3 var PortAStatus.3
' etc etc

Start:

PORTA0 = 1:PortA=PortAStatus 'turn on led1
PAUSE 1000
PORTA1 = 1:PortA=PortAStatus 'turn on led2
PAUSE 1000
PORTA2 = 1:PortA=PortAStatus 'turn on led3
PAUSE 1000
PORTA3 = 1:PortA=PortAStatus 'turn on led4
PAUSE 1000
PortAStatus = %00000000:PortA=PortAStatus 'turn OFF all leds
PAUSE 1000

goto Start

IFF1749
- 7th August 2004, 18:18
Hello again

I used a bit of a assembler to overcome this problem,
writing bitwise to PORTA register was not successful
the same problem occured.

Writing bitwise to LATA register was the right thing to do,
worked fine.

TRISA = %00000000 'set all PORTA to outputs

Start:

@ bsf 0xf89,0 ;PORTA.0 = 1 'turn on led1
PAUSE 1000
@ bsf 0xf89,1 ;PORTA.1 = 1 'turn on led2
PAUSE 1000
@ bsf 0xf89,2 ;PORTA.2 = 1 'turn on led3
PAUSE 1000
@ bsf 0xf89,3 ;PORTA.3 = 1 'turn ON led4
PAUSE 1000
PORTA = %00000000 'turn OFF all leds

goto Start

I have this question:
Is it possible to write BITWISE directly to memory in PB,
Something like [POKE address, bit no.]

Best Regards
IFF.