Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
;Class:
AME 487
;Date:
05/06/2015
;Exercise:
Homework 3
;Description:
Timers and Counter with multiple push buttons
;MCU:
PIC16F84A
;References:
See Homework_3.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 _HS_OSC &_CP_OFF & _WDT_OFF & _PWRTE_ON
;=====================================================
;
variables in PIC RAM
;=====================================================
; Declare variables at 3 memory locations used for delay loop
Counter1
equ
0x0C
Counter2
equ
0x0D
Button_Count
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:
bsf
PORTB,0
; Make the LED on PORTB.0 "off"
bsf
STATUS,RP0
; Goto Bank 1 to set Port Direction
movlw
B'00011110'
; w = 00000111 binary
tris
PORTA
; Set up PortA 1/2/3/4 for input
bcf
TRISB,0
; Set RB0 to Output
bcf
STATUS,RP0
; Go back to Bank 0
buttonCheckLoop:
btfsc
PORTA,1
call
Button_Press1
btfsc
PORTA,2
call
Button_Press2
btfsc
PORTA,3
call
Button_Press3
btfsc
PORTA,4
call
Button_Press4
goto
Loop:
bcf
movlw
movwf
buttonCheckLoop
PORTB,0
d'50'
Counter2
; LED ON
; 1 second wait (50x20ms)
; Move decimal 50 to Counter2
L2:
call
decfsz
goto
bsf
movlw
movwf
Wait
Counter2,f
L2
PORTB,0
d'50'
Counter2
call
decfsz
goto
goto
Wait
Counter2,f
L3
Loop
L3:
Wait:
movlw
movwf
0x10
Counter1
L0:
clrw
bcf
STATUS,C
L1:
addlw
nop
btfss
goto
decfsz
goto
return
0x01
STATUS,C
L1
Counter1,f
L0
Button_Press1:
movlw
d'5'
movwf
Button_Count
Loop_B1:
btfss
PORTA,1
goto
$-1
btfsc
PORTA,1
goto
$-1
decfsz Button_Count
goto
Loop_B1
return
Button_Press2:
movlw
d'7'
movwf
Button_Count
Loop_B2:
btfss
PORTA,2
goto
$-1
btfsc
PORTA,2
goto
$-1
decfsz Button_Count
goto
Loop_B2
return
Button_Press3:
movlw
d'9'
movwf
Button_Count
Loop_B3:
btfss
PORTA,3
goto
btfsc
goto
decfsz
goto
return
$-1
PORTA,3
$-1
Button_Count
Loop_B3
Button_Press4:
movlw
d'11'
movwf
Button_Count
Loop_B4:
btfss
PORTA,4
goto
$-1
btfsc
PORTA,4
goto
$-1
decfsz Button_Count
goto
Loop_B4
return
end
;
;
;
;