Multi-function IR receiver.

Easily add IR functionality to any audio project with this full featured receiver.

SONY 12-bit SIRC version available in red, green or blue.

  • Control volume, treble, bass, source and power.
  • Configurable for up to 4 sources.
  • User configurable “friendly” source labels.
  • VU meter screen saver.
  • Optional keypad.
  • Buffered JFET audio out.
  • Sinking outputs can directly drive 5v, 12v or 24v relays.
  • 3 X 2 channel Microchip digital POTs and Microchip processor.
  • Open source firmware – source code will be available for the Sony 12bit SIRC version (PIC Basic Pro).
  • Universal Remote compatible.
  • 3.8” X 2.6” footprint

 

IR receiver V1.1


SONY DAV10  V1

'EULA: Licensed under the MIT License agreement.

'Copyright (2019) PJL Electronics LLC

'Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal
'in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
'of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

'The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

'THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
'FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
'IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


'IR Multifunction decoder V1  SONY DAV10

'PICBASIC PRO



osccon = $78         
DEFINE OSC 8
'DEFINE OSCCAL_1K 1
'define write_init 1



Include "modedefs.bas"  ' Include serial modes
 
leds var word
 
TRISA = %00000000
TRISB = %00110000
TRISC = %00010000
low portb.7 



 '''''''''''''''''''''''''''''''''''The inits

 


'init the VU/Define ADCIN parameters
Define  ADC_BITS    4  ' Set number of bits in result 
Define  ADC_CLOCK    3     ' Set clock source (3=rc) 
Define  ADC_SAMPLEUS 5' Set sampling time in uS 

ADCON0 = %00000001      ' Set  adc clock to RC
ADCON1 = %00000000      ' VREF+ to VD,VREF- to VSS,FOSC/2,Sign-magnitude
ADCON2 = %00001111     ' ADC- reference selected by ADNREF,Auto-conversion off




initPOT:
'define sift_pauses 20
skc         var PORTC.6  ' SPI pot
si          var PORTC.7   ' SPI pot
high PORTC.0
high PORTC.1
high PORTC.5
commandw    var byte

initIR:
define PULSEIN_MAX 530
IR_Sense var portc.4
ST var word
IR_Word var word
bits var byte
ID var word

pause 1000
initLCD:
Define LCD_DREG PORTA
DEFINE LCD_DBIT 0
define LCD_RSREG PORTC
define LCD_RSBIT 3
define LCD_EREG PORTC 
define LCD_EBIT 2
define LCD_BITS 8
define LCD_LINES 2
define LCD_COMANDUS 500
define LCD_DATAUS 60
lcdout $FE, 1
pause 1000
lcdout $FE, $40, %00000100, %00001110, 	%00011111,  %00000100, 	%00000100,%00000100, %00011111,	%00000000
lcdout $FE, $48, %00011000, %00011100, %00011110, %00011111, %00011111,	%00011110, 	%00011100, 	%00011000
lcdout $FE, $50, %00001110, %00001110, %00001110, %00001110, %00001110, %00011111, %00001110, %00000100
lcdout $FE, $58, %00000000,	%00000000,	%00000000,	%00000100,	%00000100, 	%00000000, 	%00000000,  %00000000
lcdout $FE, $60, %00000110,	%00000110,	%00000110,	%00000110,	%00000110, 	%00000110, 	%00000110,  %00000110

'LCDOUT $FE, 1, "    ", $00 , $01 , $02 , $03, $04
'pause 30000







intSYSTEM:
temp1   var word
temp2   var byte
temp3   var byte
temp4   var byte
temp5   var byte
carry   var bit
power   var bit
mute    var byte
volume  var word 
bass    var word
treb    var word
source1  var word
source2  var word
source3  var word
source4  var word
selected  var byte
selectbuff  var byte
adc1   var byte
adc2   var byte
lhold   var byte
rhold   var byte
holdctr   var byte
lblank1 var byte
rblank1 var byte
lblank2 var byte
rblank2 var byte
saver   var word
vuint   var word
potval   var byte
idletimer   var word
read 0, bass, treb, source1, source2, source3, source4, selected
if bass = 255 and treb = 255 then gosub justhatched
idletimer = 0
volume = 15
mute = 0
power = 1
gosub powerset
low PORTC.0
potval = volume
gosub setpot
high PORTC.0
low PORTC.5 
potval = treb
gosub setpot
high PORTC.5
low PORTC.1 
potval = bass
gosub setpot
high PORTC.1
gosub selectport





''''''''''''''''''''''''''''''''''''''Main Program

saver = 0
vuint = 0
top:
ir_word = 0
ID = 0 
gosub irin 
    If ir_word > 0 then 
        if  ir_word = 1034 then gosub powerset
        if power = 0 then  goto top
        if ir_word = 1086 then goto selectsource
        if  ir_word = 2587 then goto setbass 
        if  ir_word = 2564 then goto volup    
        if  ir_word = 1033 then goto voldown  
        if  ir_word = 1282 then goto volmute 
        saver = 0         
        'pause 2
        'LCDOUT $FE, $C0, "    ", #IR_Word, "    " 
    endif
if power = 1 and mute = 0 then saver = saver + 1
if saver < 100 then  goto top
lhold = 0
rhold = 0 
holdctr = 0

vuback:
gosub clearscr
LCDOUT $FE, $80, "L "
LCDOUT $FE, $C0, "R "
VU:
    if vuint = 7 then
        pulsin portc.4, 0, st
        if st > 490  then      
            for temp4 = 1 to 7
                ir_word = 0
                gosub irin
                if  ir_word = 1034 then gosub powerset
                if power = 0 then  goto top
                if ir_word = 1086 then goto selectsource
                if  ir_word = 2587 then goto setbass 
                if  ir_word = 2564 then goto volup    
                if  ir_word = 1033 then goto voldown  
                if  ir_word = 1282 then goto volmute
            next
        endif
     else 
     gosub readadcl
     endif  
            if holdctr > 30 then        '>sticky    <fast
                    if (1 &  holdctr) then
                            if lhold > 0 then lhold = lhold - 1
                            if rhold > 0 then rhold = rhold - 1
                    endif
            endif                
    if holdctr = 43 then  holdctr = 0              
    if temp2 > lhold then 
         lhold = temp2
         holdctr = 0
         endif
    lblank1 = lhold -temp2
    lblank2 = 16 -temp2
    'LCDOUT $FE, 1,  "  ", #temp2
    LCDOUT $FE, $80+2, rep 255\temp2, rep 32\lblank1, $04, rep 32\lblank2
    if vuint = 14 then
        pulsin portc.4, 0, st
        if st > 490  then      
            for temp4 = 1 to 7
                ir_word = 0
                gosub irin
                if  ir_word = 1034 then gosub powerset
                if power = 0 then  goto top
                if  ir_word = 2587 then goto setbass 
                if  ir_word = 2564 then goto volup    
                if  ir_word = 1033 then goto voldown  
                if  ir_word = 1282 then goto volmute 
            next
        endif
     vuint = 0
     else 
     gosub readadcr
     endif  
     if temp3 > rhold then  
        rhold = temp3
        holdctr = 0
        endif
    rblank1 = rhold -temp3
    rblank2 = 16 -temp3
    'LCDOUT $FE, $C0, "  ", #temp3
    LCDOUT $FE, $C0+2, rep 255\temp3 , rep 32\rblank1, $04, rep 32\rblank2
    holdctr = holdctr +1
    vuint = vuint +1
    if (temp2 =1) and (temp3 = 1) then
        idletimer = idletimer +1
        else
        idletimer = 0
        endif 
     if idletimer = 4000 then
        idletimer = 0
        power = 1
        gosub powerset 
        goto top
        endif  
goto VU




setbass:  '''''''''''''''''''''''''''''''  start of soundfield sub menu
        gosub clearscr
        LCDOUT $FE, $80, "Bass:", 124, "6", $03, "3", $03, "0", $03, "3", $03, "6", 124
        temp4 = 1
        temp2 = 0
        gosub fixbass
        gosub displayfield
        gosub debouncelong
        bassloop:
        'LCDOUT $FE, 1, #temp
            'gosub fixbass
            ir_word = 0
            ID = 0      
            gosub irin
            If ir_word > 0 then
                    gosub debounce
                  if ir_word = 2564 then
                    bass = bass +1
                    if bass > 255 then bass = 255
                    gosub fixbass
                    gosub displayfield
                    temp4 = 0
                    low PORTC.1 
                    potval = bass
                    gosub setpot
                    high PORTC.1
                  endif
                  if ir_word = 1033 then
                     bass = bass -1
                     if bass  > 255 then  bass = 0
                     gosub fixbass
                     gosub displayfield
                     temp4 = 0
                     low PORTC.1 
                     potval = bass
                     gosub setpot
                     high PORTC.1
                  endif 
                    if ir_word = 1086 then goto bassout
                    if  ir_word = 2587 then goto settreb 
                    if  ir_word = 1034 then 
                        gosub powerset
                        goto top
                    endif    
                    gosub debounce
                    gosub debounce 
                endif
                temp4 = temp4 + 1
                if temp4 > 250 then goto vuback
                goto bassloop
                bassout:
                gosub displayvolume
                gosub debouncelong
                goto top   
              
settreb:  ''soundfield sub menu
        gosub clearscr
        LCDOUT $FE, $80, "Treb:", 124, "6", $03, "3", $03, "0", $03, "3", $03, "6", 124
        temp4 = 1
        temp2 = 0
        gosub fixtreb
        gosub displayfield
        gosub debouncelong
        trebloop:
        'LCDOUT $FE, 1, #temp
            'gosub fixbass
            ir_word = 0
            ID = 0      
            gosub irin
            If ir_word > 0 then
                    gosub debounce
                  if ir_word = 2564 then
                    treb = treb +1
                    if treb > 255 then treb = 255
                    gosub fixtreb
                    gosub displayfield
                    temp4 = 0
                    low PORTC.5 
                    potval = treb
                    gosub setpot
                    high PORTC.5
                  endif
                  if ir_word = 1033 then
                     treb = treb -1
                     if treb  > 255 then  bass = 0
                     gosub fixtreb
                     gosub displayfield
                     temp4 = 0
                     low PORTC.5 
                     potval = treb
                     gosub setpot
                     high PORTC.5
                  endif 
                    if ir_word = 1086 then goto setbass
                    if  ir_word = 2587 then goto setsorce
                    if  ir_word = 1034 then 
                        gosub powerset
                        goto top
                    endif 
                    gosub debounce
                    gosub debounce 
                endif
                temp4 = temp4 + 1
                if temp4 > 250 then goto vuback
                goto trebloop
                trebout:
                gosub displayvolume
                goto top  
                
setsorce:
    temp4 = 0
    temp5 = 1
    gosub clearscr
    LCDOUT $FE, $80, "Set names:"
    LCDOUT $FE, $C0, #temp5, " : "
    temp3 = source1
    gosub printsource
setsourceloop:    
    ir_word = 0
    gosub irin
        If ir_word > 0 then
            if  ir_word = 1282 then goto sourceedit 
            if ir_word = 1086 then goto settreb 
                if  ir_word = 2564 then 
                    temp5 = temp5 + 1                
                    if temp5 = 5 then temp5 = 1
                    endif         
                if  ir_word = 1033 then  
                    temp5 = temp5 - 1
                    if temp5 = 0 then temp5 = 4
                    endif 
                if  ir_word = 1034 then 
                    gosub powerset
                    goto top
                    endif
            gosub clearscr
            LCDOUT $FE, $80, "Set names:"        
            LCDOUT $FE, $C0, #temp5, " : " 
            if temp5=1 then temp3 = source1
            if temp5=2 then temp3 = source2
            if temp5=3 then temp3 = source3
            if temp5=4 then temp3 = source4            
            gosub printsource       
            gosub debouncelong        
            endif 
        temp4 = temp4 + 1
        if temp4 > 250 then goto vuback
        goto setsourceloop
sourceedit: 
        LCDOUT $FE, $80+11, " EDIT"
        gosub debouncelong 
sourceeditloop:
    ir_word = 0
    gosub irin
        If ir_word > 0 then 
                if  ir_word = 2564 then 
                    temp3 = temp3 + 1                          
                    if temp3 > 31 then temp3 = 1
                    endif
                if  ir_word = 1033 then  
                    temp3 = temp3 - 1                          
                    if temp3 = 255 then temp3 = 31
                    endif
                if  ir_word = 1282 then 
                    LCDOUT $FE, $80+11, "SAVED"
                    if temp5=1 then source1 = temp3
                    if temp5=2 then source2 = temp3
                    if temp5=3 then source3 = temp3
                    if temp5=4 then source4 = temp3
                    gosub debouncelong 
                    goto setsourceloop 
                    endif
                LCDOUT $FE, $C0, #temp5, " : "      
                gosub printsource   
                 gosub debouncelong
                 endif
                 goto sourceeditloop  
                 
                 
 selectsource:
    gosub clearscr
    if selected=1 then temp3 = source1
    if selected=2 then temp3 = source2
    if selected=3 then temp3 = source3
    if selected=4 then temp3 = source4
    temp5 = selected 
    LCDOUT $FE, $80, "Source:"    
    gosub printsource2 
    LCDOUT $FE, $C0, "SELECTED"       
    gosub debouncelong
    temp4 = 0
 selectsourceloop:    
    ir_word = 0
    gosub irin
        If ir_word > 0 then
            if ir_word = 2564  then 
                temp5 = temp5 + 1                
                if temp5 = 5 then temp5 = 1
                endif         
            if  ir_word = 1033 then  
                temp5 = temp5 - 1
                if temp5 = 0 then temp5 = 4
                endif                                            
            if  ir_word = 1034 then 
                gosub powerset
                goto top
                endif
             if  ir_word = 1282 then  
                        selected = temp5
                        low PORTC.0 
                        potval = 0
                        gosub setpot
                        high PORTC.0
                        gosub selectport 
                        low PORTC.0 
                        potval = 15
                        volume = 15
                        gosub setpot
                        high PORTC.0 
                        endif
             if  ir_word = 2587 then goto  selectsourceout
        if temp5=1 then temp3 = source1
        if temp5=2 then temp3 = source2
        if temp5=3 then temp3 = source3
        if temp5=4 then temp3 = source4 
        if temp3 = 0 then goto   selectsourceloop
        gosub clearscr
        LCDOUT $FE, $80, "Source:"
        gosub printsource2  
        if temp5 = selected then  LCDOUT $FE, $C0, "SELECTED"     
        gosub debouncelong 
        temp4 = 0            
        endif 
 temp4 = temp4 + 1
 if temp4 > 250 then goto vuback             
 goto selectsourceloop:               
 selectsourceout:
        gosub clearscr
        gosub displayvolume
        gosub debouncelong
        goto top  

selectport:  
selectbuff = 0
if power = 1 then selectbuff = selectbuff+128     
if selected = 1 then  selectbuff = selectbuff+8
if selected = 2 then  selectbuff = selectbuff+4
if selected = 3 then  selectbuff = selectbuff+2
if selected = 4 then  selectbuff = selectbuff+1
portb=selectbuff
'pause 20000
return 
                 
                
volup:
if volume < 15 then volume = volume +1
if volume => 15  and volume < 100 then volume = volume +5
if volume => 100   then volume = volume +10
mute = 0
if volume > 255 then volume = 255
low PORTC.0 
potval = volume
gosub setpot
high PORTC.0
gosub displayvolume
gosub debounce
goto top

voldown:
if volume =< 15 then volume = volume -1
if volume > 15  and volume < 100 then volume = volume -5
if volume => 100   then volume = volume -10
    if volume >254 then  
    volume = 0
    mute = 0
    endif
low PORTC.0    
potval = volume
gosub setpot
high PORTC.0
gosub displayvolume
gosub debounce
goto top

volmute:
if mute = 0 then 
    mute = volume
    volume = 0
else
    gosub displayvolume
    for volume = 1 to mute -1
        low PORTC.0 
        potval = volume
        gosub setpot
        high PORTC.0
        gosub displayvolumefast
        pause 10 
    next 
    gosub displayvolume  
    mute = 0
endif
low PORTC.0 
potval = volume
gosub setpot
high PORTC.0
gosub displayvolume
gosub debouncelong
goto top

    

''''''''''''''''''''''''''''''''''''The subs
clearscr:
lcdout $FE, 1
pause 25
return

justhatched:
gosub clearscr
LCDOUT $FE, $80, "Just hatched"
LCDOUT $FE, $C0, "loading defaults"
selected = 1
source1  =1
source2  =2
source3  =3
source4  =4
bass = 128
treb = 128
pause 1000
gosub clearscr
LCDOUT $FE, $80, "Hello world"
pause 1000
write 0, bass, treb, source1, source2, source3, source4, selected 
pause 1000
LCDOUT $FE, $80, "meet the"
LCDOUT $FE, $C0, "new boss"
pause 1000
return


printsource:
    if temp3 = 0 then LCDOUT $FE, $C0+4, "Disabled"
    if temp3 = 1 then LCDOUT $FE, $C0+4, "Aux  ", rep 32\3
    if temp3 = 2 then LCDOUT $FE, $C0+4, "Aux 1", rep 32\3
    if temp3 = 3 then LCDOUT $FE, $C0+4, "Aux 2", rep 32\3
    if temp3 = 4 then LCDOUT $FE, $C0+4, "Aux 3", rep 32\3
    if temp3 = 5 then LCDOUT $FE, $C0+4, "Aux 4", rep 32\3
    if temp3 = 6 then LCDOUT $FE, $C0+4, "CD  ", rep 32\4
    if temp3 = 7 then LCDOUT $FE, $C0+4, "CD 1", rep 32\4
    if temp3 = 8 then LCDOUT $FE, $C0+4, "CD 2", rep 32\4
    if temp3 = 9 then LCDOUT $FE, $C0+4, "Dac  ", rep 32\3
    if temp3 = 10 then LCDOUT $FE, $C0+4, "Dac 1", rep 32\3
    if temp3 = 11 then LCDOUT $FE, $C0+4, "Dac 2", rep 32\3
    if temp3 = 12 then LCDOUT $FE, $C0+4, "Line  ", rep 32\2
    if temp3 = 13 then LCDOUT $FE, $C0+4, "Line 1", rep 32\2
    if temp3 = 14 then LCDOUT $FE, $C0+4, "Line 2", rep 32\2
    if temp3 = 15 then LCDOUT $FE, $C0+4, "Line 3", rep 32\2
    if temp3 = 16 then LCDOUT $FE, $C0+4, "Line 4", rep 32\2
    if temp3 = 17 then LCDOUT $FE, $C0+4, "PC  ", rep 32\4
    if temp3 = 18 then LCDOUT $FE, $C0+4, "PC 1", rep 32\4
    if temp3 = 19 then LCDOUT $FE, $C0+4, "PC 2", rep 32\4
    if temp3 = 20 then LCDOUT $FE, $C0+4, "Phono  ", rep 32\1
    if temp3 = 21 then LCDOUT $FE, $C0+4, "Phono 1", rep 32\1
    if temp3 = 22 then LCDOUT $FE, $C0+4, "Phono 2", rep 32\1
    if temp3 = 23 then LCDOUT $FE, $C0+4, "Tape  ", rep 32\2
    if temp3 = 24 then LCDOUT $FE, $C0+4, "Tape 1", rep 32\2
    if temp3 = 25 then LCDOUT $FE, $C0+4, "Tape 2", rep 32\2
    if temp3 = 26 then LCDOUT $FE, $C0+4, "Tuner  ", rep 32\1
    if temp3 = 27 then LCDOUT $FE, $C0+4, "Tuner 1", rep 32\1
    if temp3 = 28 then LCDOUT $FE, $C0+4, "Tuner 2", rep 32\1
    if temp3 = 29 then LCDOUT $FE, $C0+4, "Video  ", rep 32\1
    if temp3 = 30 then LCDOUT $FE, $C0+4, "Video 1", rep 32\1
    if temp3 = 31 then LCDOUT $FE, $C0+4, "Video 2", rep 32\1
    return
    
    printsource2:
    if temp3 = 0 then LCDOUT $FE, $88, "Disabled"
    if temp3 = 1 then LCDOUT $FE, $88, rep 32\3,"Aux  "
    if temp3 = 2 then LCDOUT $FE, $88, rep 32\3,"Aux 1"
    if temp3 = 3 then LCDOUT $FE, $88, rep 32\3,"Aux 2"
    if temp3 = 4 then LCDOUT $FE, $88, rep 32\3,"Aux 3"
    if temp3 = 5 then LCDOUT $FE, $88, rep 32\3,"Aux 4"
    if temp3 = 6 then LCDOUT $FE, $88, rep 32\5,"CD  "
    if temp3 = 7 then LCDOUT $FE, $88, rep 32\5,"CD 1"
    if temp3 = 8 then LCDOUT $FE, $88, rep 32\5,"CD 2"
    if temp3 = 9 then LCDOUT $FE, $88,  rep 32\3,"Dac  "
    if temp3 = 10 then LCDOUT $FE, $88, rep 32\3,"Dac 1"
    if temp3 = 11 then LCDOUT $FE, $88, rep 32\3,"Dac 2"
    if temp3 = 12 then LCDOUT $FE, $88, rep 32\2,"Line  "
    if temp3 = 13 then LCDOUT $FE, $88, rep 32\2,"Line 1"
    if temp3 = 14 then LCDOUT $FE, $88, rep 32\2,"Line 2"
    if temp3 = 15 then LCDOUT $FE, $88, rep 32\2,"Line 3"
    if temp3 = 16 then LCDOUT $FE, $88, rep 32\2,"Line 4"
    if temp3 = 17 then LCDOUT $FE, $88, rep 32\4,"PC  "
    if temp3 = 18 then LCDOUT $FE, $88, rep 32\4,"PC 1"
    if temp3 = 19 then LCDOUT $FE, $88, rep 32\4,"PC 2"
    if temp3 = 20 then LCDOUT $FE, $88, rep 32\1,"Phono  "
    if temp3 = 21 then LCDOUT $FE, $88, rep 32\1,"Phono 1"
    if temp3 = 22 then LCDOUT $FE, $88, rep 32\1,"Phono 2"
    if temp3 = 23 then LCDOUT $FE, $88, rep 32\2,"Tape  "
    if temp3 = 24 then LCDOUT $FE, $88, rep 32\2,"Tape 1"
    if temp3 = 25 then LCDOUT $FE, $88, rep 32\2,"Tape 2"
    if temp3 = 26 then LCDOUT $FE, $88, rep 32\1,"Tuner  "
    if temp3 = 27 then LCDOUT $FE, $88, rep 32\1,"Tuner 1"
    if temp3 = 28 then LCDOUT $FE, $88, rep 32\1,"Tuner 2"
    if temp3 = 29 then LCDOUT $FE, $88, rep 32\1,"Video  "
    if temp3 = 30 then LCDOUT $FE, $88, rep 32\1,"Video 1"
    if temp3 = 31 then LCDOUT $FE, $88, rep 32\1,"Video 2"
    return
       

powerchk:
    temp5 = 0
    ir_word = 0
    gosub irin
    gosub debounce
    if  ir_word = 1034 then temp5 = 1
return


readadcl:
ADcin 11, adc1         ' Read channel 11 to adval
'pause 1
if adc1 > 7 then  adc1 = adc1 -3
if adc1 > 11 then  adc1 = adc1 -2
if adc1 > 17 then adc1 = 17
if adc1 < 5 then  
    if adc1 > 0 then adc1 = adc1 + 1
    adc1 = abs(adc1+adc1+adc1+adc2+4)/4
    endif   
temp2 = abs((temp2*9)+(adc1*2)+1)/11
if temp2 > 13 then temp2 = 13 
return

readadcr:
ADcin 13, adc2         ' Read channel 13 to adval
'pause 1
if adc2 > 7 then   adc2 = adc2 - 3
if adc2 > 11 then   adc2 = adc2 - 2
if adc2 > 17 then adc2 = 17 
if adc2 < 5 then
    if adc2 > 0 then adc2 = adc2 + 1
    adc2 = abs(adc2+adc2+adc2+adc1+4)/4
    endif
temp3 = abs((temp3*9)+(adc2*2)+1)/11
if temp3 > 13 then temp3 = 13
return







    

    




                
powerset:
if power = 1 then
    low portb.7
    power = 0
    mute = 0 
    volume = 15
    gosub clearscr
    LCDOUT $FE, $80, "Power off"
    write 0, bass, treb, source1, source2, source3, source4, selected 
     gosub debouncelong
else 
    read 0, bass, treb 
     high portb.7 
    power = 1
    low PORTC.0
    potval = volume
    gosub setpot
    high PORTC.0
    gosub displayvolume 
    gosub debouncelong
endif
saver = 0
return   



displayvolume:
gosub clearscr
if volume = 0 then  
    LCDOUT $80, "Volume: Muted"
    else
    LCDOUT $80, "Volume:" 
    endif
gosub displayvolumefast
saver = 0
return   

displayvolumefast:
temp1 = volume / 20
if volume = 0  then LCDOUT $FE, $C0,  rep 255\temp1, "  ", #volume
if volume < 10 and volume > 0 then LCDOUT $FE, $C0,  rep 255\temp1, $01, " .", #volume dig 0
if volume >=10 and volume < 100 then LCDOUT $FE, $C0,  rep 255\temp1,  $01, " ", #volume dig 1, ".", #volume dig 0
if volume >=100 then LCDOUT $FE, $C0, rep 255\temp1, $01, " ", #volume dig 2, #volume dig 1
return


fixbass:
            if bass => 128 then
                 temp2 = bass - 128
                 carry = 0
                 endif
            if bass < 128  then
                temp2 = 128 - bass
                carry = 1
                endif
return

fixtreb:
            if treb => 128 then
                 temp2 = treb - 128
                 carry = 0
                 endif
            if treb < 128  then
                temp2 = 128 - treb
                carry = 1
                endif
return

displayfield:
    temp4 = 1
    temp5 = temp2/2
            temp3 = temp2 /30
            'LCDOUT $FE, $C0, #temp3
            if carry = 0 then 
                LCDOUT $FE, $C0,  "+", #temp5 dig 1, ".",#temp5 dig 0, #temp2 dig 0 ,  124, rep 95\temp3+4, $00, rep 95\4-temp3, 124
                endif
            if carry = 1 then 
            LCDOUT $FE, $C0,  "-", #temp5 dig 1, ".",#temp5 dig 0, #temp2 dig 0 ,  124, rep 95\4-temp3,  $00, rep 95\temp3+4, 124
                endif    
return   




irin:
pulsin portc.4, 0, st
'LCDOUT $FE, $C0, #st
    IF st <440 OR st >520 Then Return' If not valid then exit
For bits=0 to 11
    Pulsin portc.4,0,Id ' Receive the IR bit pulse 
    ir_word.0[bits] = 0
    If id >=440 then ir_word.0[bits] = 1 ' If its >= 65 then we've received a 1
    'LCDOUT $FE, $C0, "   ", #id, "    "
Next
return

debounce:
pulsin portc.4, 1, st
'LCDOUT $FE, $C0, #st
 IF  (st  >400) or (ST = 0) Then Return
goto debounce 


    
debouncelong:
pulsin portc.4, 1, st
'LCDOUT $FE, $C0, #st
    IF   (ST = 0) Then Return
    goto debouncelong 

setpot:
commandw = %00000000
pause 1
shiftout PORTC.7, PORTC.6, 1, [commandw]
pause 1
shiftout PORTC.7, PORTC.6, 1, [potval]
commandw = %00010000
pause 1
shiftout PORTC.7, PORTC.6, 1, [commandw]
pause 1
shiftout PORTC.7, PORTC.6, 1, [potval]
pause 1
return



    





%d bloggers like this: