PORT byte problem


Closed Thread
Results 1 to 3 of 3
  1. #1
    IFF1749's Avatar
    IFF1749 Guest

    Angry PORT byte problem

    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.

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    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/show...=&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

  3. #3
    IFF1749's Avatar
    IFF1749 Guest


    Did you find this post helpful? Yes | No

    Default

    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.

Similar Threads

  1. Problem with 16Ff648a
    By aerostar in forum mel PIC BASIC Pro
    Replies: 18
    Last Post: - 12th November 2009, 18:15
  2. LCD freeze
    By harryweb in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 5th October 2009, 08:01
  3. byte compression
    By Norbert in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 16th June 2007, 18:04
  4. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27
  5. 16F877 RAM Question
    By Art in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 6th August 2005, 11:47

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts