crazynight
Senior Member
I am still learning and enjoying working with picaxe; I like to break my projects down into simple modules, my next aim is to read the time from a RTC and display it on a 4x7 segment display running SPI. I have started out by reading the temp and displaying that before adding i2c to the mix. This is the result.
This is the code any comments are welcome as I am keen to learn better methods.
This is the code any comments are welcome as I am keen to learn better methods.
Code:
#picaxe 20X2
symbol DS18B20_Pin = C.7 ' temp pin
symbol CLK = B.5 'Clock pin
symbol DTA = B.6 'Data pin
symbol DIM = B.7 'DIM pin
symbol pattern = b0
symbol pattern2 = b1
main:
readtemp DS18B20_Pin, w1 ; read value into w1
goto writetemp
writetemp:
if w1 = w4 then 'check to see if the temp has changed
goto main
endif
w4 = w1 'set w4 to the temp (w1) this is used later to check the temp and only update if needed.
w2 = w1 / 10 ' extract the left most digit from the temp reading
w3 = w1 // 10 ' extract the right most digit from the temp reading
lookup w2, (%11111100, %01100000, %11011010, %11110010, %01100110, %10110110, %10111110, %11100000, %11111110, %11100110), pattern 'lookup pattern for left most digit
'represents 0 1 2 3 4 5 6 7 8 9
lookup w3, (%11111100, %01100000, %11011010, %11110010, %01100110, %10110110, %10111110, %11100000, %11111110, %11100110), pattern2 'lookup pattern for right most digit
'represents 0 1 2 3 4 5 6 7 8 9
spiout CLK, DTA, LSBFirst_L, (%10011100) 'send 'C'
spiout CLK, DTA, LSBFirst_L, (%11000110) 'send '''
spiout CLK, DTA, LSBFirst_L, (pattern2) 'send right most digit
spiout CLK, DTA, LSBFirst_L, (pattern) 'send left most digit
goto main