Vous êtes sur la page 1sur 3

;===============================================================================

;Name:
Julio Sanchez with changes by Peter Seid
;Class:
AME 487
;Date:
04/25/2015
;Exercise:
Homework 5 - The Digital Clock
;Description:
Create a Digital Clock
;MCU:
PIC16F84A
;References:
See Homework_5.pdf for further information
;===============================================================================
;===========================
;
switches
;===========================
; Switches used in __config directive:
;
_CP_ON
Code protection ON/OFF
; * _CP_OFF
; * _PWRTE_ON
Power-up timer ON/OFF
;
_PWRTE_OFF
;
_WDT_ON
Watchdog timer ON/OFF
; * _WDT_OFF
;
_LP_OSC
Low power crystal oscillator
; * _XT_OSC
External parallel resonator/crystal oscillator
;
_HS_OSC
High speed crystal resonator (8 to 10 MHz)
;
Resonator: Murate Erie CSA8.00MG = 8 MHz
;
_RC_OSC
Resistor/capacitor oscillator (simplest, 20% error)
; |
; |_____ * indicates setup values
processor 16f84A
include
<p16f84A.inc>
__config _XT_OSC & _WDT_OFF & _PWRTE_ON & _CP_OFF
;=====================================================
;
variables in PIC RAM
;=====================================================
; Declare variables at 3 memory locations used for delay loop
j
equ
0x0c
k
equ
0x0d
i
equ
0x0e
;========================================================
;
m a i n
p r o g r a m
;========================================================
org
0
; start at address 0
goto
main
;=============================
; space for interrupt handler
;=============================
org
0x04
;=============================
;
main program
;=============================
main:
; Initialize all lines in port B for output (bits 0-6 are for 7 segment display)
movlw
B'00000000'
; w = 00000000 binary
tris
PORTB
; Set up port B for output
; Make sure 7-Segment displays 'zero' from the start
movlw
B'01101111'
movwf
PORTB
; Initialize all lines in port A for output
movlw
B'00000000'
; w = 00000000 binary
tris
PORTA
; Set up port A for output
; Make sure both LEDs start OFF
movlw
B'00000000'
movwf
PORTA
minuteLoop:
; Display 0 on 7 segment for 5 seconds
movlw
B'01101111' ; Byte for #0

movwf
call

PORTB
wait5Seconds

; Set port B pins to display #0

; Display 1 on 7 segment for 5 seconds


movlw
B'00000110' ; Byte for #1
movwf
PORTB
; Set port B pins to display #1
call
wait5Seconds
; Display 2 on 7 segment for 5 seconds
movlw
B'00111011' ; Byte for #2
movwf
PORTB
; Set port B pins to display #2
call
wait5Seconds
; Display 3 on 7 segment for 5 seconds
movlw
B'00011111' ; Byte for #3
movwf
PORTB
; Set port B pins to display #3
call
wait5Seconds
; Display 4 on 7 segment for 5 seconds
movlw
B'01010110' ; Byte for #4
movwf
PORTB
; Set port B pins to display #4
call
wait5Seconds
; toggle second LED to indicate 1 hour has passed
btfss
PORTA,1
; if second LED is already on, skip this
call
toggleOn
; otherwise, turn it on
btfsc
call

PORTA,1
toggleOff

; if second LED is already off, skip this


; otherwise, turn it off

goto

minuteLoop

; start the cycle over infinitely

;==========================================================
; 5 second delay routine while flashing first LED on/off
;==========================================================
wait5Seconds:
movlw
B'00000001' ; turn first LED on for 1 second
movwf
PORTA
call
delay
movlw
movwf
call

B'00000000'
PORTA
delay

; turn first LED off for 1 second

movlw
movwf
call

B'00000001'
PORTA
delay

; turn first LED on for 1 second

movlw
movwf
call

B'00000000'
PORTA
delay

; turn first LED off for 1 second

movlw
movwf
call

B'00000001'
PORTA
delay

; turn first LED on for 1 second

movlw
movwf

B'00000000'
PORTA

; turn first LED off

return
;================================
;
turn second LED on
;================================
toggleOn:
movlw
B'00000010'
movwf
PORTA
return

;================================
;
turn second LED off
;================================
toggleOff:
movlw
B'00000000'
movwf
PORTA
return
;================================
; 1 second delay sub-routine
;================================
delay:
movlw
.8
;
movwf
i
;
movlw
.204
;
movwf
j
;
iloop:
movwf
jloop:
movwf

=
=
=
=

8 decimal
w
204 decimal
w

; j = w

; k = w

kloop:
decfsz
k,f
goto
kloop
decfsz
j,f
goto
jloop
decfsz
i,f
goto
iloop
return
end

w
i
w
j

; k = k-1, skip next if zero


; j = j-1, skip next if zero
; i = i-1, skip next if zero

Vous aimerez peut-être aussi