1. When you use GOSUB to reach a sub-routine, there should always be a RETURN to get back.
2. TRIS is not necessary when using the HIGH and LOW commands.
3. GOTO start at the end of start ensures program execution will loop in start, and not fall through to the routines below it.
See how this works.
Code:
DEFINE osc 4 'using 4MHz oscillator
second VAR BYTE
'TRISB is not necessary when using the HIGH and LOW commands
'TRISB.0= 0 ' define portb.0 as output
'TRISB.1= 0 'define portb.1 as output
start:
second= second + 1 'count from 0 second..1 second..2 seconds and so on..
IF second <= 5 THEN
GOSUB loopa
ELSE
GOSUB loopb
PAUSE 500
ENDIF
GOTO Start
loopa:
HIGH PORTB.0 'blinking led in portb.0
PAUSE 500
LOW PORTB.0
PAUSE 500
'GOSUB loopa ' replaced with RETURN
RETURN
loopb:
HIGH PORTB.1 'blinking led in portb.1
PAUSE 500
LOW PORTB.1
PAUSE 500
'GOSUB loopb ' replaced with RETURN
RETURN 'return to start and count continuously until switch is switched off
END
Bookmarks