Pic16f877a led lightup program not working

Discussion in 'Embedded Systems and Microcontrollers' started by MonsterofAmp, Mar 14, 2009.

  1. MonsterofAmp

    Thread Starter Member

    Mar 14, 2009
    11
    0
    I have an Olimex usb dev board with a serial icsp. It's the 40 pin package, i got this hoping to interface it with my atmega168 microcontroller that i turned into a pong game.
    I used C for the arduino but i wanted to learn asm with the pic so i wanted to start off simple on the pic with a simple asm led light up code,
    problem is it won't light up porte or porta.

    I compile the code with mplab ide and made sure the selected device was the 16f877a but when i open the .hex file in IC Prog and look at it in asm view i see it has a label for i 16F84 which is not what i selected from the options.
    Also when i compile the code it gives me an error message 302 saying that the register in opperand is not in bank 0, but i'm possitive that i'm changing the status register bit 5 high/low to go to and from bank zero/one.

    I did leave the pgm on to the pic the first 2 times i tried burning the program to the but i took it out and tried burning multiple prog's multiple times to the pic but does anyone think it might have burnt the pic or something?

    ;simple code
    STATUS equ 03h
    TRISE equ 89h
    PORTE equ 09h
    TRISA equ 85h
    PORTA equ 05h
    ORG 0x000
    goto Initpic
    ORG 0x004
    goto Initpic
    ORG 0x010
    Initpic clrf PORTE
    clrf PORTA
    BSF STATUS, 5
    clrf TRISE
    clrf TRISA
    BCF STATUS, 5
    movlw 07h
    movwf PORTE
    movlw 0ffh
    movwf PORTA
    goto Initpic
    end

    the program is suposed to light the led up on any pin on port a/e but it doesn't on any pin can anyone please show me some flaw or error i'm not seeing?

    Thanks in advanced i really have no clue why it's not working!
     
  2. mik3

    Senior Member

    Feb 4, 2008
    4,846
    63
    This part of the code is always skipped. I don't know what it does because I don't program in assembly but it never executes.


    goto Initpic
    ORG 0x004
    goto Initpic
    ORG 0x010
     
  3. MonsterofAmp

    Thread Starter Member

    Mar 14, 2009
    11
    0
    For some reason when i comment those lines out that you posted Mik3
    goto Initpic
    ORG 0x004
    goto Initpic
    ORG 0x010
    The build succeeds but the pic still doesnt light any of the led's on any of the ports!? I am trying to make it as much as a basic asm program as possible to eliminate any bugs and i still am getting no reaction from any of the ports and yes i am setting the ports to output CLRF on the TRISA/E register going to bank 0 and setting port a/e all high.
     
  4. mik3

    Senior Member

    Feb 4, 2008
    4,846
    63
    I am sorry but I am using C for my programming so I can't really help you.
     
  5. AlexR

    Well-Known Member

    Jan 16, 2008
    735
    54
    Those lines that you commented out are perfectly valid and should be left in. The address 0x004 is where the interrupt vector lives and even though you are not using interrupts that code is there so that if an interrupt does occur the program will restart at the initpic label.

    The real reason you are not lighting a LED is that both ports A and E can be analog or digital ports and they default to analog. You have to configure them to be digital ports before you can output logic level voltage to operate a LED.

    This is what I think your code should look like but I haven't tested it so no doubt you will find something wrong.
    Code ( (Unknown Language)):
    1.  
    2.     list      p=16F877A     ; list directive to define processor
    3.     include <p16F877A.inc>  ; processor specific variable definitions
    4.     ERRORLEVEL -302         ; get rid of idiotic message 302
    5. ; The include file has equates for all ports and registers so
    6. ; the next 5 lines are redundant.
    7. ;STATUS equ 03h
    8. ;TRISE equ 89h
    9. ;PORTE equ 09h
    10. ;TRISA equ 85h
    11. ;PORTA equ 05h
    12.     ORG 0x000       ; Reset vector
    13.     goto Initpic    ; Where to go on reset
    14.     ORG 0x004       ; Interrupt vector
    15.     goto Initpic    ; Where to og on interrupt
    16.     ORG 0x010       ; This is where the program realy starts
    17. Initpic clrf PORTE
    18.     clrf PORTA
    19.     BSF STATUS, 5
    20.     MOVLW 0x06      ; Configure all pins
    21.     MOVWF ADCON1    ; as digital inputs
    22.     clrf TRISE
    23.     clrf TRISA
    24.     BCF STATUS, 5
    25.     movlw 07h
    26.     movwf PORTE
    27.     movlw 0ffh
    28.     movwf PORTA
    29.     goto Initpic
    30.     end
    31.  
     
    Last edited: Mar 15, 2009
  6. MonsterofAmp

    Thread Starter Member

    Mar 14, 2009
    11
    0
    Thank you so much i will try that code out but PortB I tried only editing portb tris b nothing else and it does not work either. Does Port B do something else i'm not aware of im using pin 2 of 0-7.

    Also when taking the .hex file of the built program using your code exactly in the ICProg program in the asm view the 9fh address is replaced with 1fh address and it still is labeld as 16f84 pic not 16f877a is this just ICProg should i worry about it because i still am getting nothing even when defining the address's myself w/out that include .
     
    Last edited: Mar 15, 2009
  7. AlexR

    Well-Known Member

    Jan 16, 2008
    735
    54
    Port B is a straight out digital port but your code does not mention port B and the compiler would not find port B unless you either had a specific equate for port B or the p16f877a include file at the start of your program.
     
Loading...