Assemble circuit as figure 4.1 and Download Program to PIC16F628

Source Code For Experiment 4
list p= 16 f 628 ; list directive to define processor
#include
;processor specific variable definitions
__CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _XT_OSC & _MCLRE_ON & _LVP_OFF
COUNT equ 0 x 20
SETTIME equ 0 x 21
org 0 x 000
clrf PORTA ; Initial PORTA
; output data latches
movlw 0 x 07 ; Turn Comparator off and
movwf CMCON ; Enable pins for I/O
bsf STATUS,RP 0 ; Select Bank 1
movlw 0 x 0 F ; RA 0- RA 3 = Input RA 4 = Output
movwf PORTA ;
bcf STATUS,RP 0 ; Return to Bank 0
Loop1 bsf PORTA, 4 ; Start Rising Pulse
call Delay ; Delay
bcf PORTA, 4 ; Falling Pulse
call Delay
btfsc PORTA, 3 ; Test RA 3 Press
goto Check 2 ; If No Continue Check
movlw 0 x 20 ; If RA 3 Press Set Time = 20 H
movwf SETTIME
goto Loop1 ; Continue
Check 2 btfsc PORTA, 1 ; Test RA 1 Press
goto Check 1 ; If No Continue Check
movlw 0 x 55 ; If RA 1 Press
movwf TIME ; Set Time = 55 H
goto Loop1 ; Continue
Check 1 btfsc PORTA, 0 ; Test RA 0 Press
goto Loop1 ; If No Begin Pulse Again
movlw 0 x 60 ; If RA 0 Press
movwf TIME ; Set Time = 60 H
goto Loop1 ; Begin Pulse Again
Delay movf TIME,w ; Delay Use Change Delay Time
movwf COUNT ; With TIME Register
decfsz COUNT,f
goto $-1
return
END ; of program
Tools & Components
Name List Quantity
MPLAB -
PIC16F628 1
4 MHz Crystal 1
Push Button Switch 1 PC 4
33 pF Capacitors 2
4.7K Resistors 1
1K Resistors 3
220 Resistors 3
PIEZO 1
LED 3
No comments:
Post a Comment