symbol freq = w0 'define frequency in binary symbol ch = b2 'define first counter as byte (channel) symbol mask = w2 'bit mask is a word symbol m = b3 'define counter (multiple use) as a byte symbol bit = w4 'variable to use for the bit symbol volt = w5 'voltage reading symbol voltsum = w3 'voltage running total main: pause 500 'stabilize power supply 1/2 sec low 1 'initialize low 2 'initialize low 4 'initialize pause 500 'stabilize 1/2 sec freq = %0100000011011000 'center of UHF channel 14 loop1: for ch=14 to 69 'scan UHF TV channels high 1 'raise tuner program enable pause 10 'enable stabilize gosub datal 'set 1st bit zero for UHF gosub datal 'set 2nd bit zero for UHF gosub datal 'set 3rd bit zero for UHF gosub datal 'set 4th bit zero for UHF mask=%0100000000000000 'define mask, start with 15th bit loop2: for m=1 to 15 bit = freq & mask if bit=0 then datal2 'bit was low, hence send low goto datah2 'otherwise send a high loop3: mask = mask / %10 'divide by 2 to get mask for next lower bit next m 'loop the program gosub datah 'set 20th bit one (spacer bit) gosub datal 'set 21st bit zero gosub datal 'set 22nd bit zero gosub datal 'set 23rd bit zero gosub datah 'set 24th bit one gosub datal 'set 25th bit zero gosub datah 'set 26th bit one gosub datal 'set 27th bit zero, note last pin4 is low pause 10 'pause to stabilize low 1 'lower program enable to take voltage reading pause 1000 'pause to stabilize input 4 'make pin 4 an input...important! pause 1000 'pause to stabilize voltsum = 0 'initialize voltage average for m=1 to 10 'loop to perform averaging readadc10 4, volt 'read the voltage on DATA pin 4 voltsum=voltsum + volt 'running total for the loop pause 100 'time average over 1 second next m 'keep looping to take average volt = voltsum / 10 'math to take average output 4 'make pin 4 an output...important! serout 0, n2400,(#ch,32,#volt,13,10) 'output channel and voltage freq = freq + %11000000 'increment UHF channel by 6 MHZ low 4 'make sure pin 4 returns low next ch 'loop the program for next channel 'Housekeeping stuff for ending the program low 4 'end with DATA in a known state low 2 'end with CLOCK in a known state low 1 'end with ENABLE in a known state pause 10 'pause to stabilize end 'end the program datah: 'subroutine high 2 'raise clock pause 10 high 4 'sub to transmit high bit pause 10 low 2 pause 10 return 'required for subroutines datal: 'subroutine high 2 'raise clock pause 10 low 4 'sub to transmit low bit pause 10 low 2 pause 10 return 'required for subroutines datah2: 'program jump high 2 'raise clock pause 10 high 4 'code to transmit high bit pause 10 low 2 pause 10 goto loop3 datal2: 'program jump high 2 'raise clock pause 10 low 4 'code to transmit low bit pause 10 low 2 pause 10 goto loop3 'pin 1 is enable, pin 2 is clock, pin 4 is data and voltage read 'w0 is the tune frequency in binary