Var Byte query

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.
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
 

srnet

Senior Member
Cant see how the 'original' would have been for a PICAXE, since you have already discovered you get syntax errors for;

clockmin var byte

Because the editor does not recognise the format.

You presumably need to convert lines like above to;

Symbol clockmin = b10

or similar.
 

westaust55

Moderator
Concur with srnet.

Could have been some B.Stamp code or similar that someone ported on paper but never tested.
Can be the case when grabbing code from the internet.

The RTC states 1307 but a quick glance at the code suggests a serial/SPI comms for the 1307 and 7221 chips with chip select lines and SHIFTOUT commands so not an i2c DS1307.
 

hippy

Technical Support
Staff member
I would also guess the code was originally for a Basic Stamp or similar. There is quite a lot in there that probably has to change to make it work on a PICAXE but for the VAR variable allocations -

clockmin var byte

for PICAXE that would become -

symbol clockmin = bX

Where X would be a number which makes the variable unique to any other variable used in the program.
 

LED Maestro

Senior Member
Thanks. I figured as much that the code was not originally for picaxe which made me have another look into the manuals and the internet as I became confused (Not hard to confuse me ha). Thanks for all the advice. And westaust, I forgot to add my comms code for i2c data transfer between the pic, the RTC and the 7221. I will be using that rather than the shiftout command.

Again, thank you very much!
 
Top