Another simple program misbehaving


Closed Thread
Results 1 to 4 of 4

Hybrid View

  1. #1
    Join Date
    Feb 2009
    Location
    Southern California
    Posts
    86

    Default Another simple program misbehaving

    I'm having problems with the below code. It is written for a 16F1829. It is a stripped down version of what I want. I am guesssing the problem is with not disabling something analog or the pull ups not working right. I have tried adding 4.7k external pull up resistors on both B4 and B5 to 5 volts as well. This is the first time I have tried using this part.

    Code:
    asm
        __CONFIG    _CONFIG1, _FOSC_INTOSC & _WDTE_ON & _PWRTE_OFF & _MCLRE_OFF & _IESO_OFF 
        __CONFIG    _CONFIG2, _PLLEN_ON & _LVP_OFF & _STVREN_OFF
    endasm
            
    Clear
    define OSC 32
    
    OSCCON = %11110000              '32 MHz internal
    
    ANSELA = 0              'set porta to digital
    ANSELB = 0
    ANSELC = 0
    
    OPTION_REG.7 = 0    'enable weak pullups
    WPUB = %00110000
    INLVLB = 0
    
    CM1CON0.7 = 0        'disable comparator
    CM2CON0.7 = 0
    
    TRISA = %011000         '0-2 tx pins
    TRISB = %11001111       'red and green
    TRISC = %11111111       '
    
    Red         var PORTB.5
    Green       var PORTB.4
    
    PORTA = %000111
    PORTB = 0
    PORTC = 0
    
    Pause 1000
    
    mainloop:
    
        green = 1
        red = 0
        pause 1000
        green = 0
        red = 1
        pause 1000
    goto mainloop
    
    end
    The basic program toggles a red and green line, one high and one low. If I comment out both green or both red lines the program behaves exactly as desired, with the un-commented line going on and off. When both red and green are in the code then the green light remains on and the red light will toggle. I have tried to look for every register I can find in the datasheet that may have anything to to with this, but no luck. I have also pulled the legs up from the circuit and checked with a volt meter just to make sure there aren't any physical problems with the board. I have also use multiple chips.

    thanks in advance for the help.

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Re: Another simple program misbehaving

    What happen if you change your High & red definition with
    Code:
    Red         var LATB.5
    Green       var LATB.4
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Feb 2009
    Location
    Southern California
    Posts
    86


    Did you find this post helpful? Yes | No

    Default Re: Another simple program misbehaving

    Quote Originally Posted by mister_e View Post
    What happen if you change your High & red definition with
    Code:
    Red         var LATB.5
    Green       var LATB.4
    ...magically all my problems seem to go away now. I've never needed to use LATX before. Maybe you can educate me a little on why I needed to this time. The datasheet seems to imply that writing to the latch is just a more direct way of writing to the port, but maybe I'm not catching the nuance.

    Thanks
    David

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Re: Another simple program misbehaving

    You should also do it with PIC18 and with all PIC having LATx register. This is to avoid the R-M-W issue. The datasheet explain it, like you said. For further details you may want to have a look at this document

    http://www.cornerstonerobotics.org/c...mw_problem.pdf
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

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