Code:
DEFINE LOADER_USED 1
define OSC 4
'::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
'::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
INCLUDE "MODEDEFS.BAS" ' Include Shiftin/out modes
DEFINE HSER_RCSTA 90h ' setup receive register
DEFINE HSER_TXSTA 20h ' setup transmit register
DEFINE HSER_BAUD 4800 ' setup baud rate
OPTION_REG.7 = 0
'::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
'::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
' Alias pins
RST VAR PORTC.1
IO VAR PORTC.2 'data pin
SCLK VAR PORTC.3 'clock pin
led var PORTB.0 'heartbeat
Butt1 VAR PORTB.4
Butt2 VAR PORTB.5
Butt3 VAR PORTB.6
Mute var PORTB.7
'lcd var PORTC.4
'::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
' Program Variables
'::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
' Allocate variables
leftvolume VAR BYTE
rightvolume VAR BYTE
loops var word
hold var byte
Gain var word
setting var word
leftvolume = 100 '0 = no gain, 255 = max gain
rightvolume = 100 '0 = no gain, 255 = max gain
gain = 0
setting = 0
mute = 0
PortB.2 = 0
loops = 0
'::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
'::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
TRISA = %00111111 'Set PORTA RA0-RA5 to input
TRISB = %00000000 'Set PORTB to all output except RB0/INT
PORTB = %00000000 'Set all outputs to 0 (off)
TRISC = %10000000 'Set PORTC to all output
PORTC = %00000000 'Set all outputs to 0 (off)
'ADCON1 = 7
Low RST ' Reset RTC
Low SCLK
high PortB.2
read 1, leftvolume 'Read from EEprom and initialize variable
read 2, rightvolume
read 3, mute
read 4, PortB.2
pause 500
mainloop:
if loops = 2500 then
gosub heartbeat
Low RST
SHIFTOUT IO,SCLK,1,[leftvolume, rightvolume]
high rst
else
loops = loops + 1
endif
GoTo mainloop 'Do it forever
heartbeat:
toggle led
loops = 0
button Butt1,0,100,10,hold,1,Increasegain
button Butt2,0,100,10,hold,1,Decreasegain
button Butt3,0,254,255,hold,1,Quiet
return
Increasegain:
if PortB.2 = 1 then return
leftvolume = leftvolume + 1
rightvolume = rightvolume + 1
HSerout ["Left = ",dec leftvolume, 13,10]
HSerout ["Right = ",dec rightvolume, 13,10]
gosub getgain
HSerout ["Gain = ",dec gain, 13,10]
write 1, leftvolume
write 2, rightvolume
return
Decreasegain:
if PortB.2 = 1 then return
leftvolume = leftvolume - 1
rightvolume = rightvolume - 1
HSerout ["Left = ",dec leftvolume, 13,10]
HSerout ["Right = ",dec rightvolume, 13,10]
gosub getgain
HSerout ["Gain = ",dec gain, 13,10]
write 1, leftvolume
write 2, rightvolume
return
Quiet:
toggle Mute 'Mute or unmute
PortB.2 =~ mute 'Led on muted
write 3, mute 'save mute status
write 4, PortB.2 'save mute led status
if PortB.2 = 1 then
HSerout ["Muted",13,10]
else
HSerout ["Left = ",dec leftvolume, 13,10]
HSerout ["Right = ",dec rightvolume, 13,10]
endif
return
GetGain:
setting = (255 - leftvolume)* 5 'Gain = 31.5 - [0.5 • (255 - N)]
gain = 315 - setting
return
end
Thanks for any help.
Bookmarks