Page 73 - Making PIC Microcontroller Instruments and Controllers
P. 73

ADVAICED  EXERCISET COI|IROLIING  !J  RC SERVO FBOL  THE KEYBoIRD   63



                   qF,ii{ili!{inilaillli:  cenerates telephone key tones  on the  piezo  speaker  (555-1212)
                    CLEBR
                    DEFINE  OSC  4
                    DIMFOUT PORtC.2,    t5,  5,  5,  !,   2,
                    ElID

                     The key tones  generated  are rough  (before  filtering), but you can tell that rhey mimic
                   the telephone dialing tones. The signal  needs to go through a filter and then an ampli
                   fier to be clean and viable. This command  has a number of constraints,  depending on
                   the  processor  used and the speed of the oscillator in the circuit. See rhe PICBASIC PRO
                   Compiler manual for details.
                     The FREQOUT command  can also be used to gercrate telephone dialing frequen-
                   cies. See the PICBASIC PRO  Compiler manual for details.

                   Advanced Exercise:  Controllins an RC

                   Servo from the Keyboard


                   Now that ws know how to generate pulses  and confol  the LCD, we can use the LAB
                   Xl  to control ihe  position  of an  RC se  o connecred to  po  JT  from  switches SWl,2,
                   and 3 on the keyboard. Program  5.11 is designed such that  . . .

                     Swilch I will turn tbe  servo clockwise incrementally.

                     Switch 2 will center the servo from wherever  it is.
                     Switch 3 will turn  the se  o counrerclockwise incrementally.
                     The circuitly for this exercise is shown in Figure  5.6.
                     Note that by changing a few variables that are defined up front, we can adjust the
                   centerposition,  the incremental step value,  and the extreme CW and CCWpositions of
                   the servo.  (This program  has been adapted  ftom, and made simpler than, a  Fogram  in
                   the microEngineering  Labs sample  ptograms.  It is instructive to compare this program
                   with the  programs  SERVOX and  SERVOI in the sample  programs.)

                   l]]il!.!.!!&l.ia€!!:!!:t  servo Position control for an Fyc seruo from PoRTB buflons
                    (This program  uses a servo on  JumperJT)
                    CI.EAR
                    DEFTNE  OSC  4
                    DEFINE   IJCD_DREG  PORTD                  ;  define  LCD  connections
                    DEFTNE  IJCD_DBIT   4                      ,  defne  LCD  connections
                    DEFINE   IJCD  RSREG  PORTE                ,  de6ne  LCD  coanecEions
                    DEFTNE  IJCD  RSBIT   O                    ,  de6ne  LCD  connecEions
                    DEFINE   I|cD  EREG  PORTE                 ,  de6ne  LCD  connections
                    DEFINE   I|cD  EBIT   1                    ,  de6ne  l,CD  connections
                    POS  VAR  WORD                             ,  serwo  posilion   variable
   68   69   70   71   72   73   74   75   76   77   78