LED Maestro
Senior Member
Hey all, I found this code, open source for a project i am doing. the original editor used a ds1307, max7221 and a picaxe 28x2 all of which i am also using in my project. I downloaded the code but whilst loking through i noticed lines of code that consisted of Var byte labels. I have never come across this when programming before, at least not in basic programming. I was wondering how i could convert these to symbols. I have included the code below. I am basically reading the time from the rtc, shifting it to the pic and then o/ping to the 7221 to display on 7 seg displays.
any help is greatly appreciated. I have already spent several hours on google trying to solve it myself. I have managed to change a few of the first instances of the var byte code into standard symbol definitions.
any help is greatly appreciated. I have already spent several hours on google trying to solve it myself. I have managed to change a few of the first instances of the var byte code into standard symbol definitions.
Code:
REM target device: PIC28X2
REM peripherels: MAX1307 RTC and MAX7221 Display driver
pause 100
symbol temp0=b0
symbol temp1=b1
symbol i=b2
'pin assignments###########################
'PGD var portb.7 'in circuit programming pins
'PGC var portb.6 'do not need to declare these
'PGM var portb.3 'so i just note them here.
'data communication
symbol dout=C.5 'data out
symbol din=C.4 'data in to
symbol dclock=C.3 'clock for data
symbol s7221=C.0 'chip select LED driver
symbol s1307=C.1 : low s1307 'chip select RTC
symbol debugLED=C.7 'i can blink this led to check code
'RTC chip#################################
clockmin var byte : clockmin = %00000000 'default hours are 12
clockhour var byte : clockhour = %01010010 'in packed binary coded decimel
'setup addresses
rmin var byte
rmin = $01
wmin var byte
wmin = $81
rhour var byte : whour var byte
rhour = $02 : whour = $82
'set control register
high s1307
shiftout dout, dclock,1, [$8F,%00000011 ]
low s1307
pause 50
high s1307 'set clock to default time
shiftout dout, dclock,1, [wmin]
shiftout dout, dclock,1, [setmin]
low s1307
high s1307
shiftout dout, dclock,1, [whour]
shiftout dout, dclock,1, [sethour]
low s1307
'LED driver#############################
digit0 var byte : digit0 = 1
digit1 var byte : digit1 = 2
digit2 var byte : digit2 = 3
digit3 var byte : digit3 = 4
row4 var byte : row4 = %00000001
dots var row4.0
'set decode to decode numbers or set LEDs individually
low s7221
shiftout dout, dclock, 1, [%00001001,%00001111 ]
high s7221
'set intensity of LEDs
low s7221
shiftout dout, dclock, 1, [%00001010, %00001111]
high s7221
'set scan limit - how many digits
low s7221
shiftout dout, dclock, 1, [%00001011, %00000100]
high s7221
'turn driver on (shutdown mode = off)
low s7221
shiftout dout, dclock, 1, [%00001100, %00000001]
high s7221
'test LEDS
for i = 1 to 3
low s7221
shiftout dout, dclock, 1, [%00001111, %00000001]
high s7221
high debugLED
pause 100
low s7221
shiftout dout, dclock, 1, [%00001111, %00000000]
high s7221
low debugLED
pause 50
next
gosub display
pause 500
'###############################################
'the main loop###################################
main:
gosub display
gosub readclock
gosub converttime
endif
goto main
'subroutines####################################
converttime:
digit0 = clockmin & $0F
digit1 = (clockmin & $F0) >> 4
digit2 = clockhour & $0F
digit3 = (clockhour & $10) >> 4
return
readclock:
high s1307
shiftout dout, dclock,1, [rmin]
shiftin din, dclock,2, [clockmin]
low s1307
high s1307
shiftout dout, dclock,1, [rhour]
shiftin din, dclock,2, [clockhour]
low s1307
return
display:
if digit3 = 0 then
digit3 = 15
endif
for i = 0 to 4 'output each digit one at a time
lookup i, [%00000001,%00000010,%00000011,%00000100,%00000101],temp0
lookup2 i, [digit0,digit1,digit2,digit3,row4],temp1
low s7221
shiftout dout, dclock, 1, [temp0,temp1]
high s7221
next
if digit3 = 15 then
digit3 = 0
endif
return