Code:
; Working variant for scroll - clock - thermometer
; using DS1307 & DS18B20
;
@ DEVICE pic16F628A, intOSC_osc_noclkout, WDT_OFF, PWRT_OFF, BOD_OFF, MCLR_OFF
define osc 4
INTCON = 0
TRISA = 000000 ' CATODES TO PORTA
TRISB = 000000 ' ANODES TO PORTB
CMCON = 7
DQ var PortB.7
SDA Var PORTB.6 ' DS1307 SDA pin #5
SCL Var PORTB.5 ' DS1307 SCL pin #6
'***************************************************************************************
eeprom 0, [100001,111010,110110,101110,100001] '0
eeprom 5, [111111,111101,000000,111111,111111] '1
eeprom 10,[111101,111110,101110,110110,111001] '2
eeprom 15,[111101,111110,110110,110110,101001] '3
eeprom 20,[100111,101011,101101,000000,101111] '4
eeprom 25,[111000,111010,111010,111010,100110] '5
eeprom 30,[100001,110110,110110,110110,101101] '6
eeprom 35,[111110,001110,110110,111010,111100] '7
eeprom 40,[001001,110110,110110,110110,001001] '8
eeprom 45,[111001,110110,110110,110110,001001] '9
counter var byte
scan var byte
scroll var byte
leddata var byte[75] 'Column Data for display 70 columns
temperature var Word 'reading from sensor
Sign var BIT
tempA var byte 'Stores First digit (High)
tempB var byte 'stores Second digit (Mid)
tempC var byte 'stores Third digit (low)
n var byte
DB Var BYTE[8] ' Data byte array
RTCSec Var DB[0] ' alias individual bytes in array
RTCMin Var DB[1]
RTCHour Var DB[2]
RTCDay Var DB[3]
RTCDate Var DB[4]
RTCMonth Var DB[5]
RTCYear Var DB[6]
RTCCtrl Var DB[7]
ore var word
minute var word
oraa var byte
orab var byte
minutea var byte
minuteb var byte
DS18B20_12bit CON 111111
gosub write_1307
START:
CLEAR
' Init Sensor
OWOUT DQ, 1, [$CC, $4E, 0, 0, DS18B20_12bit]
OWOut DQ, 1, [$CC, $48]
OWOut DQ, 1, [$CC, $B8]
OWOut DQ, 1, [$CC, $BE]
Pause 50
OWIn DQ, 2, [temperature.byte0, temperature.byte1]
Pause 50
OWOut DQ, 1, [$CC, $44]
OWOut DQ, 1, [$CC, $BE]
OWIn DQ, 2, [temperature.byte0, temperature.byte1]
Sign = temperature.15
temperature= ABS(temperature)
temperature=((temperature >> 4)*100) + ((temperature & $F) * 100 >> 4)
if sign then temperature= -temperature
tempA = temperature DIG 3
tempB = temperature DIG 2
tempC = temperature DIG 1
if tempA = 0 then
FOR counter = 0 TO 4
leddata [counter+8] = 111111
next
else
for counter = 0 to 4
READ tempA*5+counter,leddata [counter+8] 'stores 1st digit in leddata locations 8,9,10,11,12
NEXT
endif
FOR counter = 0 TO 4
READ tempB*5+counter,leddata [counter+14] 'stores 2nd digit in leddata locations 14,15,16,17,18
NEXT
FOR counter = 0 TO 4
READ tempC*5+counter,leddata [counter+23] 'stores 3rd digit in leddata locations 23,24,25,26,27
NEXT
gosub read_1307
oraa = ore dig 1
orab = ore dig 0
minutea = minute dig 1
minuteb = minute dig 0
FOR counter = 0 TO 4
READ oraa*5+counter,leddata [counter+41] 'stores hours digit 1 in leddata locations
NEXT
FOR counter = 0 TO 4
READ orab*5+counter,leddata [counter+47] 'stores hours digit 0 in leddata locations
NEXT
FOR counter = 0 TO 4
READ minutea*5+counter,leddata [counter+57] 'stores minutes digit 1 in leddata locations
NEXT
FOR counter = 0 TO 4
READ minuteb*5+counter,leddata [counter+63] 'stores minutes digit 0 in leddata locations
NEXT
;==========================================================================================================
'leddata locations 0-7 are blank so that data scrolls onto display
'leddata locations 8-12 1st digit (leading digit)
'leddata location 13 blank column between digits
'leddata locations 14-18 2nd digit
'leddata location 19 blank column between digits
'leddata locations 20 & 21 Decimal Point
'leddata locations 23 - 27 3rd digit (last digit)
'leddata locations 28 blank column between digits
'leddata locations 29 - 34 Degrees C symbol
'leddata location 35 is a blank column at end to clear display as it scrolls
'e.t.c.
;==========================================================================================================
for n=0 to 7
leddata [n] = 111111
next n
leddata [13] = 111111
leddata [19] = 111111
leddata [20] = 111111 ' DECIMAL POINT
leddata [21] = 111111
leddata [22] = 111111
leddata [28] = 111111
leddata [29] = 111100 ' degrees c
leddata [30] = 111100
leddata [31] = 100011
leddata [32] = 111101
leddata [33] = 111101
leddata [34] = 111101
leddata [35] = 111111
leddata [36] = 111111
leddata [37] = 111111
leddata [38] = 111111
leddata [39] = 111111
leddata [40] = 111111
leddata [46] = 111111
leddata [52] = 111111
leddata [53] = 111111
leddata [54] = 111011
leddata [55] = 111111
leddata [56] = 111111
leddata [62] = 111111
leddata [68] = 111111
leddata [69] = 111111
leddata [70] = 111111
leddata [71] = 111111
leddata [72] = 111111
leddata [73] = 111111
leddata [74] = 111111
leddata [75] = 111111
LOOPing:
FOR scroll = 0 TO 70
FOR scan = 0 TO 10
PORTA=111111
PAUSE 1
PORTb = 1
FOR counter = 0 TO 7
PORTa = leddata [counter]
PAUSE 1
PORTb = PORTb * 2
NEXT
NEXT
FOR counter = 0 TO 70
leddata [counter] = leddata [counter+1]
NEXT
NEXT
GOTO START
Write_1307:
I2CWRITE SDA,SCL,$D0,$00,[$59,$30,$9,$7,$14,$2,$10,$90] ' Write to DS1307
pause 10
RETURN
read_1307: ' Read time Secs,Mins,Hours,Day,Date,Month,Year,Control
I2CREAD SDA,SCL,$D1,$00,[STR DB\8] ' Read 8 bytes from DS1307
ore = (db[2] & $F )+((db[2]>>4)*10) ' Hex to Dec hour
minute = (db[1] & $F )+((db[1]>>4)*10) ' Hex to Dec minutes
RETURN
end
I think I will "upgrade" to 16F886 or 16F57 (more I/O pins) ...
Bookmarks