ME Labs, Inc.
719-520-5323
 
Home:
  Developer Resources:

Programming Clues
    Sample Programs
   
    PICBASIC PRO™
Compiler Manual
    PICBASIC™ Compiler
Manual
    Serin2/Serout2 Modes
    ASCII Character Set
    Number Conversion
    Floating Point
Routines
    PBP Debug Monitor
    Articles and Tutorials

Hardware Clues
    Parts / Vendor List
    PICPROTO™ Boards
    LAB-X1 Docs
    LAB-X2 Docs
    LAB-X20 Docs
    LAB-X3 Docs
    LAB-X4 Docs
    LAB-XUSB Docs
    LAB-XT Docs
     
 

ME Labs, Inc. | 1-719-520-5323 | Example Program - SOUNDFX.pbp

PICBASIC PRO program for SOUND experiments with the LAB-X1 and PIC16F193x series. Adjust POTs 1/3 to adjust sound note/duration.
' Name        : SOUNDFX.pbp
' Compiler    : PICBASIC PRO Compiler 2.6
' Assembler   : MPASM
' Target PIC  : 40-pin 16F1934 or similar
' Hardware    : LAB-X1 Experimenter Board
' Oscillator  : 4MHz external crystal
' Keywords    : LCDOUT, SOUND
' Description : PICBASIC PRO program for SOUND experiments with the LAB-X1
' and PIC16F193x series. Adjust POTs 1/3 to adjust sound note/duration.
'

' Define LCD pins
Define LCD_DREG  PORTD
Define LCD_DBIT  4
Define LCD_RSREG PORTE
Define LCD_RSBIT 0
Define LCD_EREG  PORTE
Define LCD_EBIT  1

' Allocate variables
x Var Byte
y Var Byte

   Gosub Init      ' Hardware initialization routine
      
mainloop:
   Gosub getx      ' Get x value for note
   Gosub gety      ' Get y value for duration
   
   Lcdout $fe, 1,   " Note=", #x     ' Show note value
   Lcdout $fe, $c0, " Duration=", #y ' Show duration value
   
   Pause 30             ' Adjust time here for time between notes
   Sound PORTC.2,[x,y]  ' Play note for duration
   Goto mainloop        ' Do it forever
   
' Subroutine to read a/d convertor
getad:
   Pauseus 50       ' Wait for channel to setup
   ADCON0.1 = 1     ' Start A/D conversion
   While ADCON0.1   '
   Wend             ' Wait for conversion to complete
   Return

' Subroutine to get pot x value on RA0
getx:
   ADCON0 = ADCON0 & 1 ' ADCON0 = %00000001 = Channel 0, A/D enabled
   Gosub getad
   x = ADRESH
   Return

' Subroutine to get pot y value on RA1
gety:
   ADCON0.2 = 1       ' ADCON0 =%00000101 = Channel 1, A/D enabled
   Gosub getad
   y = ADRESH
   Return
   
Init:
   ANSELA = 3    ' Make porta 0, 1, analog inputs
   ANSELB = 0    ' portb all digital
   ANSELD = 0    ' portd all digital
   ANSELE = 0    ' porte all digital
   
   ADCON1 = %01000000  ' Left justify for 8-bit, Fosc/4, +Vref/-Vref = Vdd/gnd
   ADCON0 = %00000001  ' A/D module enabled
   OPTION_REG.7 = 1    ' Disable PORTB pullups
   TRISD = 0           ' PORTD all outputs
   
   Pause 100           ' Wait for LCD to start
   Return              ' Return to caller
   
   End

           

Download the program file.