Sei sulla pagina 1di 3

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

;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

; Check if button1 pressed & if so, don't skip next


; Check if button2 pressed & if so, don't skip next
; Check if button3 pressed & if so, don't skip next
; Check if button4 pressed & if so, don't skip next

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

; Decrement Counter2, if it's zero skip next line


; LED OFF
; 1 second wait (50x20ms)
; Move decimal 50 to Counter2

L3:

Wait:
movlw
movwf

0x10
Counter1

; Decrement Counter2, if it's zero skip next line

; Move hex 0x10 to variable Counter1

L0:
clrw
bcf

STATUS,C

; Clear the work register


; Clear carry bit in the STATUS register

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

; Adds hex 0x10 to value in work register


; Nothing happens in this line
; Test if STATUS carry bit is set. If so, skip next
; Decrement Counter1, if it's zero skip next line

; Move decimal d 5 to work register


; Move work register to Button_Count variable
;
;
;
;
;

Detect falling edge skip next line if PORTA,1 set


Jump to previous line
Skip next line if PORTA,1 clear
Jump to previous line
Decrement Button_Count, skip next line if is zero

; Move decimal d 7 to work register


; Move work register to Button_Count variable
;
;
;
;
;

Detect falling edge skip next line if PORTA,2 set


Jump to previous line
Skip next line if PORTA,2 clear
Jump to previous line
Decrement Button_Count, skip next line if is zero

; Move decimal d 9 to work register


; Move work register to Button_Count variable
; Detect falling edge skip next line if PORTA,3 set

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

;
;
;
;

Jump to previous line


Skip next line if PORTA,3 clear
Jump to previous line
Decrement Button_Count, skip next line if is zero

; Move decimal d 11 to work register


; Move work register to Button_Count variable
;
;
;
;
;

Detect falling edge skip next line if PORTA,3 set


Jump to previous line
Skip next line if PORTA,3 clear
Jump to previous line
Decrement Button_Count, skip next line if is zero

Potrebbero piacerti anche