The Experiment 3 we will Generated sound (one frequency) by use PIC16F628 . first of all see Timing Diagram as figure 3.1 for to understand


Assemble circuit as figure 3.2 and load Program to PIC16F628 . RA4 Connect with PIEZO , The Frequency can be calculate by formula as below
f = 1/ T
1/(768 uSec + 768 uSec) = 651 Hz
Source Code For Experiment 3
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
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 b' 11101111 ' ; RA 4 = Output
movwf PORTA ; Other = Input
bcf STATUS,RP 0 ; Return to Bank 0
Loop1 bsf PORTA, 4 ; High RA 4 768 usec
call Delay
bcf PORTA, 4 ; Low RA 4 768 usec
call Delay
goto Loop1 ; Frequency = 1/(768 usec + 768 usec)
; = 651 Hz
Delay clrf 0 x 20 ; Delay 768 usec
decfsz 0 x 20 ,f
goto $-1
return
END

Tools & Components
Name List Quantity
MPLAB -
PIC16F628 1
4MHz Crystal 1
Push Button Switch 1 PC 1
33pF Capacitors 2
4.7K Resistors 1
1K Resistors 1
PIEZO 1
No comments:
Post a Comment