Connect with us

PIC assembly code doesn't chang ports ?

Discussion in 'Electronic Design' started by Rodo, Jun 6, 2007.

Scroll to continue with content
  1. Rodo

    Rodo Guest

    Hi all,

    I'm trying some assembly code for the PIC18F1320. I've always used C but the
    new job has some projects in assembly code for the cheap PICs (PIC12F508 and
    509) and I'm required to be able to modify them. YEACH!. So ... I have some
    of these PICs and I'm playing with the stuff. Anyhow ... I'm using the ICD2
    and MPLAB 7.4 to write the assy code. It compiles with no errors or
    warnings. I'm using the debugger to watch the port pins (PortA and PortB
    pins 0) toggle but no luck. Here is the code:

    movlw 0x70 ;Internal Oscillator, 31kHz
    movwf OSCCON ;

    movlw 0 ;set portA for output <---Line0
    movwf TRISA ; <---Line1
    movlw 1 <---Line2
    movwf LATA <---Line3
    movwf PORTA ;make all pins low except pin0 <---Line4

    movlw 0 ;set portB for output
    movwf TRISB ;
    movlw 1 ;
    movwf PORTB ;make all pins low except pin0

    I can see the WREG change when I step through Line0, I also see Line1 turn
    the value for TRISA to zero. Then Line2 places a 1 in WREG but line3 and
    Line4 don't change the PortA pin0 or the value in the watch window. I tried
    writting to the LAT register when the Port didn't work but it didn't make a
    difference. I tried to change the bank to 0xf0 like:

    movlb 0xf0

    between Line0 and Line1 but still no luck.


    Can someone shed some light into this please ?

    Thanks
     
  2. You need to configure the pins as digital I/O. That is your immediate
    problem. See datasheet table 10-2.. in particular ADCON1 which causes
    the port pins to power up in analog mode.

    Also, you should (almost) always use the LATx register rather than the
    PORTx register.


    Best regards,
    Spehro Pefhany
     
  3. For the low end micros, you need to perform bank switching when you are
    configuring the port (Bank 1) and then writing to it (Bank 0). I don't
    think this applies to the 18F parts (I use 18F242), but is probably needed
    for the 12F508 and 12F509. The MPLAB assembler will usually give a warning
    for addresses not in Bank 0, but there is a directive to turn off that
    warning.

    The LATx register is usually best for bit set and reset operations, which
    use a Read-Modify-Write on the entire port. If you are writing data to the
    entire port, it is not really necessary. Sometimes it is good to read the
    port after writing to it to make sure the outputs have changed. If there is
    a large capacitive load, it may take a while.

    Paul
     
  4. Marra

    Marra Guest

    What fun, I remember having these probs in the early 1980's.
    experience is a wonderful thing.
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-