I am trying to use this serial LED display from sparkfun http://www.sparkfun.com/commerce/product_info.php?products_id=9230 with a 28x1 but it displays all zeros or nothing at all
could somebody please help
thanks
could somebody please help
thanks
Code:
; *******************************
; Filename: LEDClock.bas
; Date: 9/7/09
; File Version: V2.1
; Function: A Clock And Thermometer
; Target PICAXE:28X1
; *******************************
'Declare Symbols
symbol owport = 0
symbol seconds = b3
symbol mins = b4
symbol hour = b5
symbol day = b6
symbol date = b7
symbol month = b8
symbol year = b9
symbol temp = w1
symbol hour1 = b10
symbol hour2 = b11
symbol min1 = b12
symbol min2 = b13
symbol temp1 = b14
symbol temp2 =b15
symbol Ftemp = b16
symbol value = b17
init:
setfreq m8 'set internal clock to 8Mhz
i2cslave $D0,i2cslow,i2cbyte 'Initalize DS1307 on i2c bus
main:
if portc pin1 = 0 and pin2 = 1 then
readi2c 0,(seconds,mins,hour,day,date,month,year) 'Read RTC
if hour > $12 then ' test if PM or AM
hour = hour - $12
endif
hour1 = hour >> 4
hour2 = hour << 4
hour2 = hour2 >> 4
' hour1 has the first digit of the hour, hour2 has the second digit of the hour
min1 = mins >> 4
min2 = mins << 4
min2 = min2 >> 4
' min1 has the first digit of the minutes, min2 has the second digit of the minutes
gosub LEDTime
wait 1
endif
if portc pin1 = 1 and pin2 = 0 then
readtemp owport,temp
' temp (w1) is a 16-bit variable which holds an 8 bit number returned from the sensor.
' If bit position 7 is high, the celcius temperature is negative, else it is positive
' the absolute temperature value is held in bit positions 0 - 6
' theoretical temperature range is thus -127 to 127 celsius, or -196.6 to 260.6 farenheit
' actual sensor range is -55 to 125 celsius, or -67 to 257 farenheit
' program works for sensor temperatures between -32 and 126 celsius (-25.6 to 258.8 farenheit)
' values outside this range cause overflow/underflow
if temp < 127 then ' test for positive temperature reading
gosub PosCtoF
Temp1 = FTemp / 10 ' FTemp is decimal (not BCD like the time), grab first digit
Temp2 = FTemp // 10 ' grab second digit
gosub LEDTemperature
else ' else temperature reading is negative
gosub NegCtoF
if w0 > 17 then
Temp1 = FTemp / 10
Temp2 = FTemp // 10
gosub LEDTemperature
else
Temp1 = FTemp / 10
Temp2 = FTemp // 10
gosub LEDTemperature
endif
endif
wait 1
endif
goto main ' repeat
PosCtoF:
' w1 is in celsius; farenheit = 1.8*w1 + 32 = w1 + 8*w1/10 + 32
w2 = 8*temp / 10 ' w2 holds the integer portion of the value 8*w1/10
w3 =temp + w2 + 32 ' w3 holds the integer portion of temperature in farenheit
' w4 holds the decimal portion of the value 8*w1/10
' temperature in farenheight is "w3.w4"
Ftemp = w3
return
NegCtoF:
w0 = temp - 128
w1 = temp - 128 ' isolate the lower order 7 bits containing the absolute value of the temperature
' w1 is in celsius; farenheit = -1.8*w1 + 32 = -w1 - 8*w1/10 + 32
w2 = 8*temp / 10 ' w2 holds the (positive) integer portion of the value 8*w1/10
w4 = 8*temp// 10 ' w4 holds the decimal portion of the value 8*w1/10
w3 = -temp + 32 ' will not work if temperature is below -32 celsius (-25.6 farenheit)
if w3 <= w2 then
w3 = w2 - w3
else
w3 = w3 - w2 - 1
w4 = 10 - w4
end if
Ftemp = w3
' temperature in farenheit is "-w3.w4"
return
LEDTime:
' Order to send the time to the clock is hour1, hour2, min1, min2
sertxd (hour1, hour2, min1, min2)
return
LEDTemperature:
sertxd (0x78,Temp1,temp2,0x78) 'Send Temperature
return
Last edited: