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.

Compiling and linking files with MPLAB

Status
Not open for further replies.

glias

Full Member level 2
Joined
Jul 31, 2004
Messages
140
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,298
Activity points
1,076
I don't success in compiling a multiple file project :
I mean that I would want to have a macro.inc (with macro functions) file and main.asm file which contain my code.
I put the linker file into my project and add the macro.inc in the header file.
I also put in my code the macro.inc with a include directive.

Do you know if I must choose "Generate relocatable code" or "generate absolute code" ?
when I tried the first one, it give me this error :

MPLINK 4.39, Linker
Device Database Version 1.1
Copyright (c) 1998-2011 Microchip Technology Inc.
Error - file './COMPA.o', section '.org_5', Symbol '_.org_5_01F6' is not word-aligned.
It can not be used as the target of a call or goto instruction.
Errors : 1

for the absolute code :

MPLINK 4.39, Linker
Device Database Version 1.1
Copyright (c) 1998-2011 Microchip Technology Inc.
Error - file './COMPA.o', section '.org_5', Symbol '_.org_5_01F6' is not word-aligned.
It can not be used as the target of a call or goto instruction.
Errors : 1

Do you know why it can't compile it ?

here is .asm code :
Code:
	LIST P=18F4620		;directive to define processor
	#include <P18F4620.INC>	;processor specific variable definitions
	#include "macros.inc"

;******************************************************************************
;Configuration bits
;Microchip has changed the format for defining the configuration bits, please 
;see the .inc file for futher details on notation.  Below are a few examples.



;   Oscillator Selection:
    CONFIG	OSC = ECIO6 
	CONFIG WDT = OFF, FCMEN=OFF, IESO=ON, PWRT = OFF, BOREN = OFF, BORV = 3
	CONFIG WDTPS = 1, CCP2MX = PORTC, PBADEN = ON, LPT1OSC = OFF, MCLRE = ON
	CONFIG STVREN = ON, LVP = OFF, XINST = OFF, DEBUG = ON, CP0 = OFF, CP1 = OFF
	CONFIG CP2 = OFF, CP3 = OFF, CPB = OFF, CPD = OFF, WRT0 = OFF, WRT1 = OFF
	CONFIG WRT2 = OFF, WRT3 = OFF, WRTC = OFF, WRTB = OFF, WRTD = OFF
	CONFIG EBTR0 = OFF, EBTR1 = OFF, EBTR2 = OFF, EBTR3 = OFF, EBTRB = OFF
	
;******************************************************************************
;Variable definitions
; These variables are only needed if low priority interrupts are used. 
; More variables may be needed to store other special function registers used
; in the interrupt routines.

DAT 	equ 0x00
RS 		equ 0x01
CLK 	equ 0x03
CEn		equ 0x02
BLANK	equ 0x01
SEL		equ 0x03
RESETn	equ	0x04
BP1		equ 0x00
BP2		equ 0x01
BP3		equ 0x02

		CBLOCK	0x080
		WREG_TEMP	;variable used for context saving 
		STATUS_TEMP	;variable used for context saving
		BSR_TEMP	;variable used for context saving
		ENDC

		CBLOCK	0x000
		EXAMPLE		;example of a variable in access RAM
		Data_Counter
		Data_to_send
		Char_counter
		Char_loop
		Flag_delay
		Mode
		Mux_Adr
		Char_column
;		Message_adr
		ENDC
 
; Messages table
		org 0x1000
Base_adr_mes   	data    "C" "H" " " "2" ; Channel 2
Channel_3	   	data    "C" "H" " " "3" ; Channel 3
Channel_4		data    "C" "H" " " "4" ; Channel 4
Channel_5		data    "C" "H" " " "5" ; Channel 5
Channel_6		data    "C" "H" " " "6" ; Channel 6
Channel_7		data    "C" "H" " " "7" ; Channel 7
Channel_8		data    "C" "H" " " "8" ; Channel 8

; Char table
	org 0x1100
Base_adr_char	data 0x0020, 0x0000, 0x0000 ; space character
				data 0x3E43, 0x4141, 0x2241 ; 'C'
				data 0x7F48, 0x0808, 0x7F08 ; 'H'
				data 0x4232, 0x5161, 0x4649 ; '2'
				data 0x2133, 0x4541, 0x314B ; '3'
				data 0x1834, 0x1214, 0x107F ; '4'
				data 0x2735, 0x4545, 0x3945 ; '5'
				data 0x3C36, 0x494A, 0x3049 ; '6'
				data 0x0137, 0x0971, 0x0305 ; '7'
				data 0x3638, 0x4949, 0x3649 ; '8'

	global Message_adr
	global Display_temp_l, Display_temp_h
	udata
Message_adr    	res 1
Display_temp_l	res 1
Display_temp_h	res 1


;******************************************************************************
;EEPROM data
; Data to be programmed into the Data EEPROM is defined here

		ORG	0xf00000

		de "",	 0x08, 0x1C, 0x3E, 0x7F, 0x00
		de 0x08,     0x30, 0x45, 0x48, 0x40, 0x30
		;data kButton_Play, play	

;******************************************************************************
;Reset vector
; This code will start executing when a reset occurs.

		Code
		ORG	0x0000

		goto	Main		;go to start of main code

;******************************************************************************
;High priority interrupt vector
; This code will start executing when a high priority interrupt occurs or
; when any interrupt occurs if interrupt priorities are not enabled.

		ORG	0x0008

		bra	HighInt		;go to high priority interrupt routine

;******************************************************************************
;Low priority interrupt vector and routine
; This code will start executing when a low priority interrupt occurs.
; This code can be removed if low priority interrupts are not used.
		
		ORG	0x0018
		
		movff	STATUS,STATUS_TEMP	;save STATUS register
		movff	WREG,WREG_TEMP		;save working register
		movff	BSR,BSR_TEMP		;save BSR register

;	*** low priority interrupt code goes here ***


		movff	BSR_TEMP,BSR		;restore BSR register
		movff	WREG_TEMP,WREG		;restore working register
		movff	STATUS_TEMP,STATUS	;restore STATUS register
		retfie

;******************************************************************************
;High priority interrupt routine
; The high priority interrupt code is placed here to avoid conflicting with
; the low priority interrupt vector.

HighInt:
	movff	STATUS,STATUS_TEMP	;save STATUS register
	movff	WREG,WREG_TEMP		;save working register
	movff	BSR,BSR_TEMP		;save BSR register

;	*** high priority interrupt code goes here ***
	
	btfsc INTCON,1 				; Flag test of ext0
	call Ext0
	btfsc INTCON3,0 			; Flag test of ext1
	call Ext1
	btfsc INTCON3,1 			; Flag test of ext2
	call Ext2
	btfsc INTCON,2 				; Flag test of timer0
	call Timer0
	btfsc PIR1,0				; Flag test of timer1
	call Timer1
End_IT
	movff	BSR_TEMP,BSR		; Restore BSR register
	movff	WREG_TEMP,WREG		; Restore working register
	movff	STATUS_TEMP,STATUS	; Restore STATUS register
	retfie FAST

Ext0							; BP Mode
	bcf INTCON,1				; Clear flag
	call BEEP_ON
	;clrf Test_Mode
	;movf Mode,w				; Mode=0 => selection of the channel
								; Mode=1 => detector temperature
	;movf Test_Mode 			; Mode=2 => board temperature
	;movlw 0x
	return

Ext1							; BP INC
	bcf INTCON3,0				; Clear flag
	call BEEP_ON
	movlw 0x07					
	cpfseq Mux_Adr,0			; Test if Mux_Adr is max
	incf Mux_Adr				; Mux_Adr+1
	return

Ext2							; BP DEC
	bcf INTCON3,1				; Clear flag
	call BEEP_ON				
	movlw 0x01
	cpfseq Mux_Adr,0			; Test if Mux_Adr is min
	decf Mux_Adr				; Mux_Adr-1
	return

Timer0
	bcf INTCON,2			 	; Clear interrupt flag
	bsf Flag_delay,0			; Set flag
	btg PORTA,6					; Led blink
	btg PORTC,0					; Led blink
	bcf T0CON,7					; Timer0 OFF
	bcf T1CON,0					; Timer1 OFF	
	return

Timer1
	bcf PIR1,0					; Clear Timer1 flag
	btg PORTC,2					; Toggle output
	movlw 0x90					; Timer1
	movwf T1CON					; Internal Osc - Prescaler=2
	movlw 0xFD					
	movwf TMR1H
	movlw 0x8E
	movwf TMR1L
	bsf T1CON,0 				; Timer1 ON	
	return

;******************************************************************************
;Start of main program
; The main program code is placed here.

Main:

; Variables init
	movlw 0x01
	movwf Mux_Adr					; Init Mux_Adr to 0x01
	movff Mux_Adr,PORTE				; 0x00 address MUST NOT BE USED !!!
; PORT init
	clrf PORTA
	movlw b'10000111'
	movwf TRISA
	clrf PORTB
	movlw 0x07
	movwf TRISB
	clrf PORTC
	movlw 0x80
	movwf TRISC
	clrf PORTD
	movlw 0x00
	movwf TRISD
	clrf PORTE
	movlw 0x00
	movwf TRISE
	
; ADC init
	movlw 0x0C
	movwf ADCON1 					; RA0:RA2 are analog all others are digital
	bsf PORTC, 0 					; Init for led blink
	bcf	PORTA, 6 					; Init for led blink
	
	bsf PORTE,0

; Timer0 Configuration for Beep duration
	movlw 0x87
	movwf T0CON
	movlw 0xD9
	movwf TMR0H
	movlw 0xDA
	movwf TMR0L

; IT init	
	movlw b'11110000'
	movwf INTCON	
	movlw b'10000100'
	movwf INTCON2
	movlw b'11011000'
	movwf INTCON3
	movlw b'00000000'
	movwf PIR1
	movlw b'00000000'
	movwf PIR2
	movlw b'00000001'
	movwf PIE1
	movlw b'00000000'
	movwf PIE2
	bsf   RCON, IPEN

; PWM for sound
	;movlw d'155'
	;movwf PR2
	;movlw 0x27
	;movwf CCPR1L
	;bcf CCP1CON,5
	;bcf CCP1CON,4
	;bsf T2CON,1 ; Prescale=16
	;bsf T2CON,TMR2ON ; Timer2 ON
	;bsf CCP1CON,2 ; PWM mode
	;bsf CCP1CON,3 ; PWM mode

; Display configuration
	clrf Flag_delay
	call Delay_300ms
	call Delay_300ms
	call Delay_300ms
	
	bcf PORTC,RESETn 					; Reset active
	bsf PORTC,RESETn 					; Reset inactive
	bsf PORTD,SEL						; Internal OSC
	bcf PORTD,CLK						; Clock line '0'
		
	call CLR_display					; Clear subroutine call
	call CONF_Display					; Configuration subroutine call
	Write_display Channel_3				; write "Channel 2"
	
Main_loop
	movff Mux_Adr,PORTE					; Up to date mux addresses
	goto Main_loop						; Main loop
	
; Subroutines definition
	
CONF_Display
	bsf PORTD,RS						; Set RS line
	bcf PORTD,CEn						; CEn='0'
	movlw 0x80							; CW1=0x80
	movwf Data_to_send
	call Send_data_byte					; Call subroutine to send a byte
	movlw 0x4D							; CW0=0x4D
	movwf Data_to_send					
	call Send_data_byte					; Call subroutine to send a byte
	return
	
Send_data_byte
	movlw 0x08							; Intialize the bit counter
	movwf Data_Counter 					; 
SDB_Loop
	rlcf Data_to_send,1					; Rotate left Data_to_send
	bc Set_data							; Carry=1
	bcf PORTD,DAT						; Set Data to '0'
DisplayConf_1
	bsf PORTB,CLK						; Set clock line
	bcf PORTB,CLK						; Reset clock line
	decfsz Data_Counter,1				; Decrement Data_Counter
	goto SDB_Loop						; Loop if not 0
	goto End_data_byte					; Data_Counter is 0, byte transfer is fichished
Set_data
	bsf PORTD,DAT						; Set Data to '1'
	goto DisplayConf_1					; Jump to the next bit process...
End_data_byte
	bsf PORTD,CEn						; Set CEn to '1' to end data transfert
	return				

Send_char
	bcf PORTD,RS						; Selection of data register
	bcf PORTD,CEn						; Enable
	bsf PORTB,CLK						; Set clock line to generate a low transistion edge
	bcf PORTB,CLK						;
	movlw 0x05
	movwf Char_column			
SC_loop
	movlw 0x7F
	movwf Data_to_send
	call Send_data_byte					; Send data
	decfsz Char_counter,1				; Decrement Char_counter
	goto SC_loop						; end									
	return

BEEP_ON
	movlw 0x87
	movwf T0CON
	movlw 0xFE							; High=D9 ; Low=DA for 1sec
	movwf TMR0H
	movlw 0x17							; Timer0 load
	movwf TMR0L
	movf TMR0L,w
	bsf T0CON,7							; Timer0 ON
	movlw 0x90							; Timer1
	movwf T1CON							; Internal Osc - Prescaler=2
	movlw 0xFD
	movwf TMR1H
	movlw 0x8E
	movwf TMR1L
	bsf T1CON,0 						; Timer1 ON		
	return
	
CLR_display
	bcf PORTD,RS						; Select pixel reg
	bcf PORTD,CEn						; Enter data
	bcf PORTD,DAT						; Data line to '0'
	movlw d'160'						; 4 char * 5 columns * 8 lines = 160
	movwf Char_loop						; Store in Char_loop
Clear_loop	
	bsf PORTB,CLK						; CLK rising edge
	bcf PORTB,CLK						; CLK='0'
	decfsz Char_loop,1					;
	goto Clear_loop						; Loop if != '0'	
	bsf PORTD,CEn						; CEn='1'
	call Delay_300ms					; Delay
	return

INIT_display
	bsf PORTD,RS						; Control reg select
	movlw 0x4D
	movwf Data_to_send
	bcf PORTD,CEn						; Data mode
	call Send_data_byte					; Send data
	return

Delay_300ms
	movlw 0x87
	movwf T0CON
	movlw 0xF4
	movwf TMR0H
	movlw 0x8D
	movwf TMR0L
	bsf T0CON,7							; Timer0 ON
	btfss Flag_delay,0
	goto $-1
	clrf Flag_delay						; reset flag
	return

	END

and the macro.inc header file :

Code:
Write_display macro Message_adr
	movlw 0x00							; Set the upper address
	movwf TBLPTRU					
	movlw HIGH(Message_adr)				; Set the high byte address
	movwf TBLPTRH
	movlw LOW(Message_adr)				; Set the low byte address
	movwf TBLPTRL
	tblrd*+								; Read the content and increment
	movff TABLAT,Display_temp_l			; 	
	tblrd*+								; Read the content and increment
	movff TABLAT,Display_temp_h			;
	endm
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top