|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
|
; ; |
|
; Created by : Youri Klaassens ; |
|
; Date : 07 October, 2017 ; |
|
; Description : Set LED while button pressed ; |
|
; ; |
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
|
|
|
|
|
#include <p16f1829.inc> |
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
|
; ; |
|
; Configuration bits ; |
|
; ; |
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
|
|
|
__CONFIG _CONFIG1, (_FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_ON & _CLKOUTEN_OFF & _IESO_OFF & _F$ |
|
__CONFIG _CONFIG2, (_WRT_OFF & _PLLEN_OFF & _STVREN_OFF & _LVP_OFF); |
|
|
|
cblock 0x70 |
|
__delay ;Set alias 'delay' for file register 0x70. |
|
endc |
|
|
|
org 0 ;Try to assemble at location 0x0000 |
|
|
|
INIT: |
|
banksel OSCCON ;Go to bank1 |
|
movlw b'00111000' ;Move bit pattern 00111000 into the working register (500 kHz internal oscillator) |
|
movwf OSCCON ;Move the bit pattern in the working register into the OSCCON register |
|
|
|
;No need to say 'move to bank TRISA' because TRISA is in the same RAM bank as OSCCON (bank1) |
|
bsf TRISA, 2 ;Switch is attached to pin 17 (RA2). Bit 2 of TRISA register should be 1 (means input) |
|
|
|
;No need to say 'move to bank TRISC' because TRISC is in the same RAM BANK as TRISA (bank1) |
|
clrf TRISC ;Set all bits in the TRISC register to 0 (means output) |
|
|
|
banksel ANSELA ;Go to bank3 |
|
bcf ANSELA, 2 ;Set bit ANSA2 of the ASELA register to 0 (means digital input) |
|
|
|
banksel LATC ;Go to bank2 |
|
clrf LATC ;Set all C pins to logical LOW |
|
|
|
MAIN: |
|
banksel PORTA ;Go to bank0 |
|
btfss PORTA, 2 ;Check if the input on pin 17 (switch) is HIGH or LOW. NOTE: The circuit is active-low. |
|
;While pressing the button, the microcontroller read a logic 0 as input. |
|
;While leaving the button alone, the microcontroller read a logic 1 as input. |
|
bra SETLED ;Go to label SETLED |
|
bra CLEARLED ;Go to label CLEARLED |
|
SETLED: |
|
movlw b'01100100' ;Move decimal 100 into the working register |
|
movwf __delay ;Move decimal 100 into common RAM (0x70) |
|
|
|
decfsz __delay, 1 ;Decrement the value in location __delay by 1 (causes a 2,4 miliseconds delay) |
|
;If 0, skip the next line. |
|
goto $-1 ;Go 1 instruction back |
|
|
|
banksel PORTA ;Go to bank0 |
|
btfsc PORTA, 2 ;Check if bit2 of the PORTA register is still 0. |
|
;If 0, the user still holds the button. |
|
;If 1, the user does not hold the button. |
|
goto MAIN ;Go to label MAIN |
|
|
|
banksel LATC ;Go to bank2 |
|
bsf LATC, 1 ;Set LED DS2 to logic HIGH |
|
goto MAIN ;Go to label MAIN |
|
|
|
CLEARLED: |
|
banksel LATC ;Go to bank2 |
|
bcf LATC, 1 ;Set LED DS2 to logic LOW |
|
goto MAIN ;Go to label MAIN |
|
|
|
end ;We will never reach this |