Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Pic16f877a intro to relocatable code

Status
Not open for further replies.

kemalkemal

Member level 1
Member level 1
Joined
Jan 27, 2013
Messages
38
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Visit site
Activity points
1,672
Hi all,
After one week that i've decided to learn relocatable code with assembler and after i found out solutions to problems i encounter here is my solutionless problem :)
i wrote just a simple code to load port b with b'01010101' like this.

;calling file

Code ASM - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
list        p=16f877a   
#include    <p16f877a.inc>  
        __CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _RC_OSC & _WRT_OFF & _LVP_ON & _CPD_OFF
extern  prog
RESET_VECTOR    CODE    0x0000 
nop                        ; 
pagesel start
goto    start              
INT_VECTOR      CODE    0x0004 
INTERRUPT
 retfie                 
MAIN_PROG       CODE
start
pagesel prog
call    prog
    END                       ;



reference file

Code ASM - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
list        p=16f877a   
    #include    <p16f877a.inc>  
global port1,prog
udata
port1   res     1
;**********************************************************************
MAIN_PRO       CODE
prog
banksel TRISB
clrf    TRISB
banksel port1
movlw   b'01010101'
movwf   port1
movf    port1,w
banksel PORTB
movwf   PORTB
retlw   0
    END                       ;


I build this without error , make the hex file with mpasmwin. But when i load hex into pic , i dont see 01010101 on port b of my development board.

ANy idea? Thanks.
 
Last edited by a moderator:

hii
check your circuit if it is connected properly.... try it in a simulation.

if the circuit is not at all working, then check ur oscillator circuit and your CONFIG bits
 
Hi,

You do not say what your dev board is, but generally most hobbyist programmers do not use LVP so you Must set LVP=OFF or it may not program correctly.

In Assembly you have a choice of Absolute or Relocatable code, however if you read up on relocatable code its often considered only useful for very complex coding and even then problems are often reported.

For the majority of diy projects Absolute code is much simpler and virtually all web examples and tutorial are in Absolute code.

Would strongly suggest you change over to Absolute modl in your project Options.

Here is your code reworked for Absolute mode, so much simpler , surley ?

Code:
	list p=16f877a 
	#include <p16f877a.inc> 
	__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _RC_OSC & _WRT_OFF & _LVP_OFF & _CPD_OFF

	cblock 0x0020		; RAM LOCATION
;	port1				; bad choice of label  -use -
	work1
	endc



	ORG  0x0000 		;RESET_VECTOR
	goto start

	ORG  0x0004 		;INT_VECTOR CODE
	retfie 



start					;MAIN_PROG CODE

	clrf	PORTB		;CLEAR PORTB		
	banksel	TRISB
	clrf	TRISB		;SET PORTB TO OUTPUTS
	banksel	PORTB

	movlw	b'01010101'
	movwf	work1
;	movf	port1,w	   ; not needed as the value is still in W

	movwf	PORTB

loop goto	loop		

	END
 
First I change my _RC_OSC config to _XT_OSC and then set LVP to off. And problem is solved.Thanks again.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top