Page 70 - Making PIC Microcontroller Instruments and Controllers
P. 70
THE INFUI
THE OUTPUTAND
60 COI{TBOLI.II{G READING
Beep
A Simple
We have one other piece ofhardwarc we can oulput to on thc LAB-XI and that is the
small piezoelectric speaker on the board. This speaker is connected to line PORTC 2.
The PWM (Pulse Widlh Modulation) commdnd can be used to create a shol1 beep
ofl thc piezoelectric speaker on the LAB_XI. The command specines the PORIC pin
to be used, the duly cycle and thc duration olthe beep (100 milliseconds in our case)
See Program 5.7.
:l!!!'Eii!l$]|:: Generates a short ione on the piezo speaker (Nole thai line c2 is
HPW[jl Channel 1)
CI,EAR
DEFIT|IE OSC 4
PW!{ PORTC.2, 127. 100
EI{ID end the progran
Bogram 5.7 provides a 0.1 second (100 psec) beep. Circuirry is shown in Figure 5 5'
Press the reset bulton to rcpeat the beep.
Check to see what happens il you leave the END statement off-
Prcgram 5.? generales a 50 percent duty cycle for 100 cycles
i:l!i!f'!Ci$5:: rhe basic circuilry for generating tones
on the piezo speaker on the hardware providecl. (ll you
use the infrared receiver, its slgnaLwill appear on line 44
Only relevant circuitry is shown.)