Try this code.
Schematic and code are also attached.
------------------------------------------------------------------------
@ DEVICE intrc_osc, MCLR_OFF,WDT_OFF,PROTECT_OFF
DEFINE LCD_EREG PORTA
' Set LCD Enable port
DEFINE LCD_EBIT 7
' Set LCD Enable bit
TRISA=%00100000
' RA5=Input, Rest= Output
TRISB=%01100001
' RB6, RB5, RB0 = Input, Rest=Output
'--------Assign name to ports---------------
potvar var portb.0
'Pot is connected to RB0.
servo var portb.3
'Servo is connected to RB3.
Button1 var portb.5
'Button1 is connected to Portb.5 and increases the frequency.
Button2 var portb.6
'Button2 is connected to Portb.6 and decreases the frequency.
'---------Variables-------------------------
pulse var byte
'Variable to hold Pot value for servo Position
freq var byte
'Variable to hold Button1 and Button2 adjustments for Frequency
'--------Initial Setup----------------------
Freq=18
'Initial Frequency
'--------Main Loop-------------------------
loop:
IF button1=0 then freq=freq+1
'Incr freq
IF button2=0 then freq=freq-1
'Decr freq
IF freq>30 then freq=30
'Max. Low freq
IF freq<5 then freq=5
'Max. High Freq
pot potvar,255,pulse
'Read pot and store the value in pulse variable
If pulse>240 then pulse=240
'Max. Pulse 240mS
IF pulse<60 then pulse=60
'Min. Pulse 60mS.
pulsout servo,pulse
'pulsout the stored pot value (pulse) to servo pin.
pause freq
lcdout $fe,1,"Pulse:",#pulse
LCDOUT $fe,$c0,"Freq:",#freq
goto loop
--------------------------------------------------------------------------
"If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte
Bookmarks