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.

subroutine errors. (error 113)

Status
Not open for further replies.

sam_ecko

New Member
Hi I am trying to write some code and am met by errors for my subroutines (error 113)

it seems to not recognise subroutines that are before the main part of my code). the code is all in the same format (caps) its just the positioning i am having an issue with. To the point that it doesn't even recognise:

org 0x00
GOTO START


START
CALL INITIALISE

(the rest of the code).

I am a relative newbie to this (did it at uni years ago but never encountered this problem and had technicians to quickly help with any issues).

my code is pretty basic, but would appreciate any help i can get.
 
LIST P=16F628
#include "P16F628.INC"
__config _INTRC_OSC_NOCLKOUT & _LVP_OFF & _WDT_OFF & _PWRTE_ON & _BODEN_ON & _MCLRE_OFF

;----------------------------
CBLOCK 0X20
LOOP1,LOOP2,LOOP3,LOOP4,LOOP5,LOOP6 ;Loop4 = potential to extend delay timing
ENDC

;----------------------------
;Initialise
;----------------------------
ORG 0X00
CALL INIT
ORG 0x10
INIT
CLRF PORTA ; Initialize port A
CLRF PORTB ; Initialize port B

BSF STATUS,RP0 ; RAM bank 1

CLRF TRISA ; All pins port A output
CLRF TRISB ; All pins port B output
BCF STATUS,RP0 ; RAM bank 0
;-----------------------------
MOVLW 7
MOVWF CMCON ; Comparators off, all pins digital I/O

;------------------------------

;-------------------------------
SUB1
BSF PORTA,2
CALL DELAY
BCF PORTA,2
BCF PORTA,0
return
;-----------------------------
SUB2
BSF PORTA,1
CALL DELAY
BCF PORTA,1
BCF PORTA,6
return
;-----------------------------
SUB3
BSF PORTA,0
CALL DELAY
BCF PORTA,0
BCF PORTA,7
return
;-----------------------------
; Delay = 1 seconds
; Clock frequency = 4 MHz = 1 cycle per 1us

; Actual delay = 1 seconds = 10000000 cycles
;=256*256*16=1X10(6) cycles
DELAY
MOVLW 0xFF
MOVWF LOOP1
MOVLW 0XFF
MOVWF LOOP2
MOVLW 0x4
MOVWF LOOP3

DELAY1
MOVLW 0xFF
MOVWF LOOP1
DECFSZ LOOP1,F
GOTO $-1

DELAY2
DECFSZ LOOP2,F
GOTO DELAY1

DELAY3
MOVLW 0XFF
MOVWF LOOP2
DECFSZ LOOP3,F
GOTO DELAY1

RETURN

END
;-----------------------------
START
CALL INIT

BTFSC PORTB,0 ;CHECK TOP BUTTON
BSF PORTA,3 ;SET TOP RED LED
BTFSC PORTB,1 ;CHECK MID BUTTON
BSF PORTA,6 ;SET MID RED LED
BTFSC PORTB,2 ;CHECK BOTTOM BUTTON
BSF PORTA,7 ;SET BOTTOM RED LED
BTFSC PORTB,4 ;CHECK ROOM1
CALL SUB1
BTFSC PORTB,6 ;CHECK ROOM2
CALL SUB2 ;CALL LIGHT SUBROUTINE2
BTFSC PORTB,7 ;CHECK ROOM3
CALL SUB3 ;CALL LIGHTS SUBROUTINE3
GOTO START
END
 
LIST P=16F628
#include "P16F628.INC"
__config _INTRC_OSC_NOCLKOUT & _LVP_OFF & _WDT_OFF & _PWRTE_ON & _BODEN_ON & _MCLRE_OFF

;----------------------------
CBLOCK 0X20
LOOP1,LOOP2,LOOP3,LOOP4,LOOP5,LOOP6 ;Loop4 = potential to extend delay timing
ENDC

;----------------------------
;Initialise
;----------------------------
ORG 0X00
goto START
ORG 0x10
INIT
CLRF PORTA ; Initialize port A
CLRF PORTB ; Initialize port B

BSF STATUS,RP0 ; RAM bank 1

CLRF TRISA ; All pins port A output
CLRF TRISB ; All pins port B output
BCF STATUS,RP0 ; RAM bank 0
;-----------------------------
MOVLW 7
MOVWF CMCON ; Comparators off, all pins digital I/O

;------------------------------

;-------------------------------
SUB1
BSF PORTA,2
CALL DELAY
BCF PORTA,2
BCF PORTA,0
return
;-----------------------------
SUB2
BSF PORTA,1
CALL DELAY
BCF PORTA,1
BCF PORTA,6
return
;-----------------------------
SUB3
BSF PORTA,0
CALL DELAY
BCF PORTA,0
BCF PORTA,7
return
;-----------------------------
; Delay = 1 seconds
; Clock frequency = 4 MHz = 1 cycle per 1us

; Actual delay = 1 seconds = 10000000 cycles
;=256*256*16=1X10(6) cycles
DELAY
MOVLW 0xFF
MOVWF LOOP1
MOVLW 0XFF
MOVWF LOOP2
MOVLW 0x4
MOVWF LOOP3

DELAY1
MOVLW 0xFF
MOVWF LOOP1
DECFSZ LOOP1,F
GOTO $-1

DELAY2
DECFSZ LOOP2,F
GOTO DELAY1

DELAY3
MOVLW 0XFF
MOVWF LOOP2
DECFSZ LOOP3,F
GOTO DELAY1

RETURN

END
;-----------------------------
START
CALL INIT

BTFSC PORTB,0 ;CHECK TOP BUTTON
BSF PORTA,3 ;SET TOP RED LED
BTFSC PORTB,1 ;CHECK MID BUTTON
BSF PORTA,6 ;SET MID RED LED
BTFSC PORTB,2 ;CHECK BOTTOM BUTTON
BSF PORTA,7 ;SET BOTTOM RED LED
BTFSC PORTB,4 ;CHECK ROOM1
CALL SUB1
BTFSC PORTB,6 ;CHECK ROOM2
CALL SUB2 ;CALL LIGHT SUBROUTINE2
BTFSC PORTB,7 ;CHECK ROOM3
CALL SUB3 ;CALL LIGHTS SUBROUTINE3
GOTO START
END
 
Remove the END instruction before START and it should be good to go.

Mike.
 
hi pommie, my reply is a little late but i did that and it worked. thank you! (I missed that bit after checking the code over and over) :)
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top