STAMP Buzzer and LCD
This circuit is a slight enhancement to the simple buzzer circuit - I've added a LCD
display that shows the current value being used to drive the
buzzer. This simple project shows just how useful an LCD can be for
debugging.
Remember, this is code for a Basic Stamp II only! It won't work
on a BASIC Stamp I because the PBASIC commands have changed between
Stamp versions.
Click here to download the source code.
' buzzlcd.bs2
' Buzz the speaker at a given tone based on the pot input,
' and display the value being used on the LCD.
'
' The speaker is connected to pin 7
' The RC network is connected to pin 8
' The serial LCD connection is on pin 9
'
' NOTE: The LCD must be set to work on 2400 baud.
'
' THIS IS CODE FOR A BASIC STAMP II ONLY!!
'
' Mark Crosbie January 1998. mark@mastincrosbie.com
' These are some predefined constants for controlling the LCD
LCDPREFIX con 254
LCDCLS con 1
LCDHOME con 2
LCDBLANK con 8
LCDSCRLLEFT con 24
LCDSCRLRT con 28
N24N con 16780
result var word
dir9 = 1 ' set the LCD pin to output
dir7 = 1 ' set the speaker pin to output
serout 9,N24N,[LCDPREFIX, LCDCLS] ' clear the LCD
loop:
high 8 ' charge the capacitor
pause 10 ' wait for it to charge
rctime 8,1,result ' do the RC timing
freqout 7,10,result * 3 ' buzz the speaker
serout 9, N24N, [dec ? result] ' display the result
serout 9, N24N, [" "] ' display some blanking text
pause 10
serout 9,N24N, [LCDPREFIX, LCDHOME] ' home the cursor
goto loop
The LCD in this instance is a simple 2 line by 16 character display
available from Scott Edwards
Electronics. Using the LCD is simplicity itself - there are three
lines to connect: Power (+5V), Ground (0V) and the serial input. The
serial input can be driven directly from the Stamp output.
The LCD is set to 2400 baud in this example. There is a toggle switch
on the back of the LCD backpack that allows you to choose between 2400
baud and 9600 baud communication. If you choose 9600 baud, you'll have
to change the serial constant N24N.
|