Lab 4: the Flasher
Omar Kassar 201503246
Objective:
in this lab we will learn the techniques of the delay by :
• Explain the principle of doing a delay = 1s
• Also we will introduce the concept of subroutine and the CALL instruction.
Ex
• Write a program that makes LL ( left LED ) and RL ( right LED ) flash with 1S
ON / 1S OFF
• change to 10pps ( pulse per second ) frequency flashing
• Keep increasing frequency till you can’t see the LEDs flashing anymore.
Solution:
a)
Flow-chart:
Code:
FLASHER BSF PORTB,0
BSF PORTB,7
CALL DELAY1S
BCF PORTB,0
BCF PORTB,7
CALL DELAY1S
GOTO FLASHER
DELAY1S MOVLW D'5'
MOVWF REF3
REFILL2 MOVLW D'255'
MOVLW REF2
REFILL1 MOVLW D'255'
MOVLW REF1
CORE DECFSZ REF1,F
GOTO CORE
DECFSZ REF2,F
GOTO REFILL1
DECFSZ REF3,F
GOTO REFILL2
RETURN
SWITCHTEST BTFSS PORTA,RA0 ;PART C)
GOTO SWITCHTEST
FLASHER10PPS BSF PORTB,0
BSF PORTB,7
CALL DELAY50MS
BCF PORTB,0
BCF PORTB,7
CALL DELAY50MS
GOTO SWITCHTEST
DELAY50MS MOVLW D'1'
MOVWF REF3
REFILL2 MOVLW D'64'
MOVLW REF2
REFILL1 MOVLW D'255'
MOVLW REF1
CORE DECFSZ REF1,F
GOTO CORE
DECFSZ REF2,F
GOTO REFILL1
DECFSZ REF3,F
GOTO REFILL2
RETURN