You are on page 1of 3

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

;Name:
Julio Sanchez with changes by Peter Seid
;Class:
AME 487
;Date:
03/08/2015
;Exercise:
Homework 2
;Description:
Implement code to enable 7segment disp w/push buttons+switches
;MCU:
PIC16F84A
;References:
See Homework_2.pdf & PIC Course_02.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 occilator
; * _XT_OSC
External parallel resonator/crystal ocillator
;
_HS_OSC
High speed crystal resonator (8 to 10 MHz)
;
Resonator: Murate Erie CSA8.00MG = 8 MHz
;
_RC_OSC
Resistor/capacitor ocillator (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 2 memory locations
j
equ
0x0c
k
equ
0x0d
;========================================================
;
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
movlw
B'00000000'
; w = 00000000 binary
tris
PORTB
; Set up port B for output
; Set port B bit 0 ON
movlw
B'00000000'
; w := 0 binary
movwf
PORTB
; port B itself := w
; Clear the carry bit
bcf
STATUS,C
; Initialize lines 0/1/2/3/4 in port A for input
movlw
B'00011111'
; w = 00001111 binary
tris
PORTA
; Set up port A for output
; Set port A bit 0 ON
;
movlw
B'00000000'
; w := 0 binary
;
movwf
PORTA
; port A itself := w
; Clear the carry bit
;
bcf
STATUS,C
zero:

movlw
movwf
call

B'01101111' ; Byte for #0


PORTB
; Set port B pins to display #0
delay
; Wait before representing next number

switchState:
btfsc
goto

PORTA,4
nums5678

regularState:
btfsc
goto
btfsc
goto
btfsc
goto
btfsc
goto

PORTA,0
one
PORTA,1
two
PORTA,2
three
PORTA,3
four

; Test and skip if bit is clear

one:
movlw
movwf
call

B'00000110' ; Byte for #1


PORTB
; Set port B pins to display #1
delay
; Wait before representing next number

movlw
movwf
call

B'00111011' ; Byte for #2


PORTB
; Set port B pins to display #2
delay
; Wait before representing next number

movlw
movwf
call

B'00011111' ; Byte for #3


PORTB
; Set port B pins to display #3
delay
; Wait before representing next number

movlw
movwf
call

B'01010110' ; Byte for #4


PORTB
; Set port B pins to display #4
delay
; Wait before representing next number

two:

three:

four:

nums5678:
btfsc
goto
btfsc
goto
btfsc
goto
btfsc
goto

PORTA,0
five
PORTA,1
six
PORTA,2
seven
PORTA,3
eight

five:
movlw
movwf
call

B'01011101' ; Byte for #5


PORTB
; Set port B pins to display #5
delay
; Wait before representing next number

movlw
movwf
call

B'01111101' ; Byte for #6


PORTB
; Set port B pins to display #6
delay
; Wait before representing next number

movlw
movwf
call

B'00000111' ; Byte for #7


PORTB
; Set port B pins to display #7
delay
; Wait before representing next number

movlw
movwf

B'01111111' ; Byte for #8


PORTB
; Set port B pins to display #8

six:

seven:

eight:

call

delay

call
goto

delay
zero

; Wait before representing next number

;================================
;
delay sub-routine
;================================
delay:
movlw
.200
; w = 200 decimal
movwf
j
; j = w
jloop:
movwf
k
; k = w
kloop:
decfsz k,f
; k = k-1, skip next if zero
goto
kloop
decfsz j,f
; j = j-1, skip next if zero
goto
jloop
return
end

You might also like