'****************************************************************
'* Name : UNTITLED.BAS *
'* Author : Matthew Reid *
'* Notice : Copyright (c) 2013 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 9/14/2013 *
'* Version : 1.0 *
'* Notes : *
'* : external oscillator *
'****************************************************************
include "modedefs.bas"
#CONFIG
__config _CONFIG1, _EXTCLK & _WDT_OFF & _MCLR_OFF & _BODEN_OFF & _LVP_OFF
#ENDCONFIG
trisb = %10101001
trisa = %11000011
OSCCON = %00001000
CMCON = $07' disable comparators
ANSEL = %00000001
'--------a to d stuff---------------
Define ADC_BITS 10 ' Set number of bits in result
Define ADC_CLOCK 3 ' Set clock source (3=rc)
Define ADC_SAMPLEUS 50 ' Set sampling time in uS
adval Var Word
counter var byte: counter = 0
ADCON0.7 = 1
'------------------------
'-------------- digi pot stuff
plus var porta.6
minus var porta.1
Rst var porta.4:Rst = 0
clk var porta.3:Clk=0
dq var porta.2:Dq=0
I var byte
Wiper0 var byte
Wiper1 var byte
ch1_pot var byte
ch2_pot var byte
'read eeprom previously saved values
read 5, ch1_pot
read 6, ch2_pot
'150 = 10.21 volts , 50 = 4.27
Wiper0= 50
Wiper1=50
'-----------------------------
Define OSC 16
'vout input to micro
vout var portb.5
'channel change stuff
ch1 var portb.1: ch1 =1
ch2 var portb.2: ch2=0
sel var portb.0
current_channel var bit
'read current channel from eeprom
read 7, current_channel
last var bit
'timing measurement variables
pulsehigh var word
pulsehigh1 var word
pulselow var word
pulselow1 var word
duty var word
freq var word: freq = 100
dummy var word
signalinput var portb.3
t1on var t1con.0
gosub intro_screen
gosub cleartimer
gosub set_pot
mainloop:
'minus 2 to wiper variable by pressing plus
if minus = 0 then
'checks which channel unit is currently on
if current_channel = 0 then
'keep integer from rolling over
if ch1_pot>5 then
ch1_pot= ch1_pot -2
endif
else
if ch2_pot>5 then
ch2_pot= ch2_pot -2
endif
endif
'write values into eeprom
write 5, ch1_pot
write 6, ch2_pot
endif
'add 1 to wiper variable by pressing plus
if plus = 0 then
if current_channel = 0 then
'keep integer from rolling over
if ch1_pot<250 then
ch1_pot= ch1_pot +2
endif
else
if ch2_pot<250 then
ch2_pot= ch2_pot +2
endif
endif
'write values into eeprom
write 5, ch1_pot
write 6, ch2_pot
endif
gosub set_pot
'the following code waits for a square wave, it is set up so if the vout is
'on, and all the buttons are untouched it will properly get square wave,
'other wise it exits while loop. pressing plus or minus exits the loop
while signalinput=1 && vout=1 && plus = 1 && minus = 1 : wend
while signalinput=0 && vout=1 && plus = 1 && minus = 1 : wend
t1on=1
while signalinput=1 && vout=1 && plus = 1 && minus = 1 : wend
t1on=0
pulsehigh.highbyte=tmr1h
pulsehigh.lowbyte=tmr1l
pulsehigh= pulsehigh/4
gosub cleartimer
while signalinput=0 && vout=1 && plus = 1 && minus = 1 : wend
while signalinput=1&& vout=1 && plus = 1 && minus = 1 : wend
t1on=1
while signalinput=0 && vout=1 && plus = 1 && minus = 1 : wend
t1on=0
pulselow.highbyte=tmr1h
pulselow.lowbyte=tmr1l
pulselow= pulselow/4
gosub cleartimer
'if there is power display duty and freq, if not display zero
if vout=1 then
if plus = 1 && minus = 1 then 'need this otherwise freq and duty are set incorrectly
pulsehigh1=pulsehigh/100
pulselow1=pulselow/100
duty=pulsehigh/(pulselow1+pulsehigh1)
freq= 10000/(((pulselow+pulsehigh)/100))
endif
else
duty=0
freq=0
endif
'only updates LCD every 6 loops to allow for smoother display
if counter = 6 then
serout PORTB.4,N9600,[$fe,$c0] 'put curser on second line
serout PORTB.4,N9600,[#freq, " CPS "]
serout PORTB.4,N9600,[$fe,$c8]
serout PORTB.4,N9600,["Duty ",#duty,"% "]
gosub get_ad
if current_channel = 0 then
serout PORTB.4,N9600,[$fe,$80]
serout PORTB.4,N9600,["CH 1"]
ch1=1
ch2=0
else
serout PORTB.4,N9600,[$fe,$80]
serout PORTB.4,N9600,["CH 2"]
ch1=0
ch2=1
endif
counter = 0
else
counter = counter + 1
endif
gosub set_channel
Goto mainloop
cleartimer:
tmr1l = 0
tmr1h = 0
return
set_channel:
'make sure power is off before switching banks
if vout=0 then
'push button has pull ups, checks for high to low transition
if sel = 0 && last= 1 then
current_channel= ~current_channel
'read current channel from eeprom
write 7, current_channel
endif
last = sel
endif
return
get_ad:
ADCIN 0, adval
adval=adval*4286
dummy= div32 10000
dummy= dummy+129
serout PORTB.4,N9600,[$fe,$86]
serout PORTB.4,N9600,[#(dummy/1000),".", #((dummy//1000)/10)]
serout PORTB.4,N9600,[$fe,$8a]
serout PORTB.4,N9600,[" VOLTS "]
counter = 0
return
intro_screen:
'intro screen
pause 1000
serout PORTB.4,N9600,[$fe,$1] 'clear everything
serout PORTB.4,N9600,[$1b,$2a,255] ' set LCD backlight
serout PORTB.4,N9600,[$fe,$1]
serout PORTB.4,N9600,[" BLAKE WOOD "]
serout PORTB.4,N9600,[$fe,$c0]
serout PORTB.4,N9600,[" INK "]
pause 500
serout PORTB.4,N9600,[$fe,$80]
serout PORTB.4,N9600,["* BLAKE WOOD *"]
serout PORTB.4,N9600,[$fe,$c0]
serout PORTB.4,N9600,["* INK *"]
pause 500
serout PORTB.4,N9600,[$fe,$80]
serout PORTB.4,N9600,["** BLAKE WOOD **"]
serout PORTB.4,N9600,[$fe,$c0]
serout PORTB.4,N9600,["** INK **"]
pause 500
serout PORTB.4,N9600,[$fe,$80]
serout PORTB.4,N9600,["***BLAKE WOOD***"]
serout PORTB.4,N9600,[$fe,$c0]
serout PORTB.4,N9600,["*** INK ****"]
pause 500
serout PORTB.4,N9600,[$fe,$80]
serout PORTB.4,N9600,["***BLAKE WOOD***"]
serout PORTB.4,N9600,[$fe,$c0]
serout PORTB.4,N9600,["**** INK *****"]
pause 500
serout PORTB.4,N9600,[$fe,$80]
serout PORTB.4,N9600,["***BLAKE WOOD***"]
serout PORTB.4,N9600,[$fe,$c0]
serout PORTB.4,N9600,["***** INK ******"]
pause 500
serout PORTB.4,N9600,[$fe,$80]
serout PORTB.4,N9600,["***BLAKE WOOD***"]
serout PORTB.4,N9600,[$fe,$c0]
serout PORTB.4,N9600,["******INK *******"]
pause 500
serout PORTB.4,N9600,[$fe,$80]
serout PORTB.4,N9600,["***BLAKE WOOD***"]
serout PORTB.4,N9600,[$fe,$c0]
serout PORTB.4,N9600,["******INK********"]
pause 500
serout PORTB.4,N9600,[$fe,$1]
return
set_pot:
if current_channel = 0 then
wiper1= ch1_pot
else
wiper1=ch2_pot
endif
pause 1
'start transition
Rst = 1
pause 1
'stack select
Dq=1
pause 1
Clk=1
pause 1
Clk=0
pause 1
'first wiper
For i = 0 to 7
'dq= ~dq
Dq=wiper0.7
'wiper0 = wiper0<<1
if i = 0 then
dq = wiper0.7
elseif i = 1 then
dq = wiper0.6
elseif i = 2 then
dq = wiper0.5
elseif i = 3 then
dq = wiper0.4
elseif i = 4 then
dq = wiper0.3
elseif i = 5 then
dq = wiper0.2
elseif i = 6 then
dq = wiper0.1
else
dq = wiper0.0
endif
Clk=1
pause 1
Clk=0
pause 1
Next i
'second wiper
For i = 0 to 7
if i = 0 then
dq = wiper1.7
elseif i = 1 then
dq = wiper1.6
elseif i = 2 then
dq = wiper1.5
elseif i = 3 then
dq = wiper1.4
elseif i = 4 then
dq = wiper1.3
elseif i = 5 then
dq = wiper1.2
elseif i = 6 then
dq = wiper1.1
else
dq = wiper1.0
endif
Clk=1
pause 1
Clk=0
pause 1
Next i
'end transition and set resistance
Rst = 0
pause 1
return
Comments