Pic16f877a led lightup program not working

Thread Starter

MonsterofAmp

Joined Mar 14, 2009
11
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!
 

mik3

Joined Feb 4, 2008
4,843
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
 

Thread Starter

MonsterofAmp

Joined Mar 14, 2009
11
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.
 

AlexR

Joined Jan 16, 2008
732
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.
Rich (BB code):
	list      p=16F877A		; list directive to define processor
	include <p16F877A.inc>	; processor specific variable definitions
	ERRORLEVEL -302			; get rid of idiotic message 302
; The include file has equates for all ports and registers so 
; the next 5 lines are redundant.
;STATUS equ 03h
;TRISE equ 89h
;PORTE equ 09h
;TRISA equ 85h
;PORTA equ 05h
	ORG 0x000		; Reset vector
	goto Initpic	; Where to go on reset
	ORG 0x004		; Interrupt vector
	goto Initpic	; Where to og on interrupt
	ORG 0x010		; This is where the program realy starts
Initpic clrf PORTE
	clrf PORTA
	BSF STATUS, 5
	MOVLW 0x06 		; Configure all pins
	MOVWF ADCON1 	; as digital inputs
	clrf TRISE
	clrf TRISA
	BCF STATUS, 5
	movlw 07h
	movwf PORTE
	movlw 0ffh
	movwf PORTA
	goto Initpic
	end
 
Last edited:

Thread Starter

MonsterofAmp

Joined Mar 14, 2009
11
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:

AlexR

Joined Jan 16, 2008
732
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.
 
Top