Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Help Compiling a HEX file

Status
Not open for further replies.
I'm trying to build a circuit I found while searching on the internet and I'm having trouble writing a HEX file. I must say first that I not very experienced in programming, compiling, and microcontrollers but I can't figure out what step I'm missing. Here's the code I'm trying to compile:

Code:
; 8DGTCACC.INC: 8 digits CA or CC 7-segments LED display
; using conditional assembly

;-------------------- keywords for conditional assembly -----------------

; uncomment only one among these two directives
#define useCAdisplay		; if using Common Anode 7-segment display
;#define useCCdisplay		; if using Common Cathode 7-segment display

; uncomment only one among these five directives
;#define PORTX	5		; if using PORTA (full 8 bits, example: PIC16F628)
#define PORTX	6		; if using PORTB (any 18 pins mid-range PICmicro)
;#define PORTX	7		; if using PORTC (any 28 pins mid-range PICmicro)
;#define PORTX	8		; if using PORTD (any 40 pins mid-range PICmicro)
;#define PORTX	9		; if using PORTE (any 40 pins mid-range PICmicro)

;------------------------------------------------------------------------
; declare in the main file:
;------------------------------------------------------------------------
;	numdgt			; .128, then .64, .32, .16, .8, .4, .2, .1
;	rlfcnt			; .8, then .7, .6, .5, .4, .3, .2, .1
;	affvis			; ratio display visible
;	dgtvis			; digit currently displayed
;
;	dgtDS7			; digit #7 (left most digit)
;	dgtDS6			; digit #6
;	dgtDS5			; digit #5
;	dgtDS4			; digit #4
;	dgtDS3			; digit #3
;	dgtDS2			; digit #2
;	dgtDS1			; digit #1
;	dgtDS0			; digit #0 (right most digit)
;
;------------------------------------------------------------------------
; macro to prepare input parameters to "Disp" routine
;------------------------------------------------------------------------
DISPDGT	macro	posdgt, dgt
	MOVLW	posdgt
	MOVWF	rlfcnt
	MOVF	dgt, w
	CALL	Disp
	endm

;------------------------------------------------------------------------
;config. RBx & CC as outputs, (if Common Cathode), then RBx=HIGH & CC=LOW
;Config. RBx & CA as outputs, (if Common Anode), then RBx=LOW & CA=HIGH
;------------------------------------------------------------------------
SEGx	macro REGx, RBx, jump, configRB, dgtX
	BTFSC dgtX, RBx
	GOTO  jump

#ifdef	useCCdisplay
	BTFSS REGx, RBx		; conditional assembly
#endif

#ifdef	useCAdisplay
	BTFSC REGx, RBx		; conditional assembly
#endif
	
	GOTO  jump
	BSF STATUS, RP0		; flip to bank1
	MOVLW configRB
	XORWF dgtX, w
	MOVWF PORTX 
	BCF STATUS, RP0		; go back to bank0
	MOVLW configRB

#ifdef	useCCdisplay	
	XORLW 0FFh		; complement W (conditional assembly)
#endif
 
	MOVWF PORTX

	MOVLW	.128		; internal delay = 0.5 ms (quartz 4 MHz)
	ADDLW	0FFh		; W--
	BTFSS	STATUS, Z	; bit Z=1 (i.e. W = 0 ?)
	GOTO	$-2		; loop = 4 * 128 = 512 us
	
	endm

;-----------------------------------------------------------------------
; Routine to display 8 digits
; (one digit at a time, segment by segment individually)
;-----------------------------------------------------------------------
Display
	MOVLW	.15
	MOVWF	affvis
dispdgts
	DISPDGT	.8, dgtDS7
	DISPDGT	.7, dgtDS6
	DISPDGT	.6, dgtDS5
	DISPDGT	.5, dgtDS4
	DISPDGT	.4, dgtDS3
	DISPDGT	.3, dgtDS2
	DISPDGT	.2, dgtDS1
	DISPDGT	.1, dgtDS0	
	
	DECFSZ	affvis, f
	GOTO	dispdgts
	RETURN

;-----------------------------------------------------------------------
; Common Cathode digit, light segment by segment
; Common Anode digit, light segment by segment
;-----------------------------------------------------------------------
Disp
	MOVWF   dgtvis

	MOVLW	high Tab7seg
	MOVWF	PCLATH
	MOVF	dgtvis, w	; (dgtvis) -> W
	CALL	Tab7seg		; convert
	MOVWF	dgtvis		; (dgtvis) converted to 7 segments code
	
#ifdef	useCAdisplay
	COMF	dgtvis, f	; conditional assembly (for Common Anode)
#endif
	CLRF	numdgt
	BSF	dgtvis, 7
	BSF	STATUS, C
rlfloop
	RLF	numdgt, f
	RLF	dgtvis, f
	BTFSC	STATUS, C
	GOTO	setBit0
	BCF	dgtvis, 0
	GOTO	rlfnext
setBit0
	BSF	dgtvis, 0	
rlfnext
	BCF	STATUS, C
	DECFSZ	rlfcnt, f
	GOTO	rlfloop
	
DispsegA SEGx dgtvis,0,DispsegB,0FEh, numdgt ; Disp. dgtvis, bit0
DispsegB SEGx dgtvis,1,DispsegC,0FDh, numdgt ; Disp. dgtvis, bit1
DispsegC SEGx dgtvis,2,DispsegD,0FBh, numdgt ; Disp. dgtvis, bit2
DispsegD SEGx dgtvis,3,DispsegE,0F7h, numdgt ; Disp. dgtvis, bit3
DispsegE SEGx dgtvis,4,DispsegF,0EFh, numdgt ; Disp. dgtvis, bit4
DispsegF SEGx dgtvis,5,DispsegG,0DFh, numdgt ; Disp. dgtvis, bit5
DispsegG SEGx dgtvis,6,DispsegX,0BFh, numdgt ; Disp. dgtvis, bit6
DispsegX SEGx dgtvis,7,Dispoff, 07Fh, numdgt ; Disp. dgtvis, bit7

Dispoff
	CLRF	PORTX		; clear portX 
	RETURN

; 8DGTCNT.ASM: main file to test display file "8DGTCACC.INC" 

;------------------------------------------------------------------------------
	list P = 16F628A
#include <p16f628a.inc>
	__CONFIG _CP_OFF &_BODEN_OFF &_PWRTE_ON &_WDT_OFF &_LVP_OFF &_MCLRE_OFF &_INTRC_OSC_NOCLKOUT

;---------------------- DEFINE HARDWARE ---------------------------------------
#define	BTN	PORTA, 4	; push button connected to RA4

;--------------------- DEFINE VARIABLES ---------------------------------------
	CBLOCK	0x70		; common RAM [16 bytes, 0x70 to 0x7F]
	numdgt			; .128, puis .64, .32, .16, .8, .4, .2, .1
	rlfcnt			; .8, puis .7, .6, .5, .4, .3, .2, .1
	affvis			; ratio display visible
	dgtvis			; digit currently displayed
	
	dgtDS7			; digit #7 (left most digit)
	dgtDS6, dgtDS5, dgtDS4	; digit #6, digit #5, digit #4
	dgtDS3, dgtDS2, dgtDS1	; digit #3, digit #2, digit #1
	dgtDS0			; digit #0 (right most digit)
	ENDC

;------------------------------------------------------------------------------
; increment one digit from 0 to maxi-1 ; if maxi, then wrap to 0 
;------------------------------------------------------------------------------
INC1	macro	digitX, maxi, jump 
	INCF	digitX, f	; increment digitX 
	MOVLW	maxi
	XORWF	digitX, w
	BTFSS	STATUS, Z	; digitX = maxi ?
	GOTO	jump		; no
	CLRF	digitX		; yes, then clear digitX
	endm

;//////////////////////////////////////////////////////////////////////////////
	ORG  0x00		; reset vector
	GOTO Start
;------------------------------------------------------------------------
; L.U.T. to convert a decimal value into the corresponding 7 segment code
;------------------------------------------------------------------------
Tab7seg
	ADDWF PCL, f		; display 7 segments GFEDCBA
	DT 3Fh, 06h, 5Bh, 4Fh, 66h, 6Dh, 7Dh, 07h, 7Fh, 6Fh

;/////////////////////////////////////////////////////////////////////////////////	
#include "8DGTCACC.INC"
;/////////////////////////////////////////////////////////////////////////////////
Start
	bsf	STATUS, RP0	; flip to Bank 1
	bsf	BTN		; config. BTN as input
	bcf	STATUS, RP0	; back to Bank 0

	clrf	dgtDS7
	clrf	dgtDS6
	clrf	dgtDS5
	clrf	dgtDS4
	clrf	dgtDS3
	clrf	dgtDS2
	clrf	dgtDS1
	clrf	dgtDS0
tstBtn
	btfsc	BTN		; BTN pushed
	goto	majDisp		; no
IncDgts
	INC1	dgtDS0, .10, majDisp
	INC1	dgtDS1, .10, majDisp  
	INC1	dgtDS2, .10, majDisp
	INC1	dgtDS3, .10, majDisp  
	INC1	dgtDS4, .10, majDisp
	INC1	dgtDS5, .10, majDisp  
	INC1	dgtDS6, .10, majDisp
	INC1	dgtDS7, .10, majDisp
majDisp
	CALL    Display
	GOTO	tstBtn
;------------------------------------------------------------------------
	END

I'm using a Velleman K8048 and PicProg2009 software with a 16F628A. When I take the assembly file and past the code into it to covert to a hex file I get a bunch of errors (see attached text file). It looks like things are undefined and it can't find the the include files. Anyone know what I'm doing wrong?

Thanks!
 
That posted code is supposed to be two separate files, one include and one assembler file.

Find attached zip, asm code compiles fine under MPASMWIN.

Should compile ok for you also.

Regards,

Wilksey
 
That posted code is supposed to be two separate files, one include and one assembler file.

Find attached zip, asm code compiles fine under MPASMWIN.

Should compile ok for you also.

Regards,

Wilksey

Thank you very much sir! I really appreciate it. I was thinking it was supposed to be 2 separate files but I wasn't sure.
 
Not a problem, that's why there was so many errors, as the PIC include file has to be first before the calls, you could have merged the two, but it was designed to be two separate files.

Happy Coding!
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top