Code:
; test 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 = %00100000 ' CATODES TO PORTA
TRISB = %10000001 ' ANODES TO PORTB
CMCON = 7
DQ var PortB.7
SDA Var PORTA.5 ' DS1307 SDA pin #5
SCL Var PORTB.0 ' DS1307 SCL pin #6
DEFINE I2C_SLOW 1 ;without this nothing work !
DEFINE I2C_HOLD 1 ;without this nothing work !
DEFINE I2C_SCLOUT 1 ;without this nothing work !
'***************************************************************************************
eeprom 0, [%10100001,%01111010,%01110110,%01101110,%10100001] '0
eeprom 5, [%11111111,%01111101,%00000000,%01111111,%11111111] '1
eeprom 10,[%01111101,%00111110,%01101110,%01110110,%01111001] '2
eeprom 15,[%10111101,%01111110,%01110110,%01110110,%10101001] '3
eeprom 20,[%11100111,%11101011,%11101101,%00000000,%11101111] '4
eeprom 25,[%10111000,%01111010,%01111010,%01111010,%10100110] '5
eeprom 30,[%10100001,%01110110,%01110110,%01110110,%10101101] '6
eeprom 35,[%11111110,%00001110,%11110110,%11111010,%11111100] '7
eeprom 40,[%10001001,%01110110,%01110110,%01110110,%10001001] '8
eeprom 45,[%11111001,%01110110,%01110110,%01110110,%10001001] '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]
oraa var byte
orab var byte
minutea var byte
minuteb var byte
ttime var word
DS18B20_12bit CON %01111111
gosub write_1307
START:
CLEAR
gosub read_1307
' 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
; temperature=2340 ; UNCOMMENT FOR DISPLAY TEST
tempA = temperature DIG 3
tempB = temperature DIG 2
tempC = temperature DIG 1
; ttime = 2345 ; just for test
; oraa = ttime dig 3
; orab = ttime dig 2
; minutea = ttime dig 1
; minuteb = ttime dig 0
oraa = ((RTCHour>>4)& $01) ; ?????????????????????????
orab = (RTCHour & $0f) ; ?????????????????????????
minutea = ((RTCMin>>4)& $0f) ; ?????????????????????????
minuteb = (RTCMin & $0f) ; ?????????????????????????
if tempA = 0 then
FOR counter = 0 TO 4
leddata [counter+8] = %11111111
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
FOR counter = 0 TO 4
READ oraa*5+counter,leddata [counter+41]
NEXT
FOR counter = 0 TO 4
READ orab*5+counter,leddata [counter+47]
NEXT
FOR counter = 0 TO 4
READ minutea*5+counter,leddata [counter+57] 'stores minut digit in leddata locations 41,42,43,44,45
NEXT
FOR counter = 0 TO 4
READ minuteb*5+counter,leddata [counter+63] 'stores minut digit in leddata locations 41,42,43,44,45
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
;==========================================================================================================
for n=0 to 7
leddata [n] = %11111111
next n
leddata [13] = %11111111
leddata [19] = %11111111
leddata [20] = %00111111 ' DECIMAL POINT
leddata [21] = %00111111
leddata [22] = %11111111
leddata [28] = %11111111
leddata [29] = %11111100 ' degrees c
leddata [30] = %11111100
leddata [31] = %11100011
leddata [32] = %10111101
leddata [33] = %10111101
leddata [34] = %10111101
leddata [35] = %11111111
leddata [36] = %11111111
leddata [37] = %11111111
leddata [38] = %11111111
leddata [39] = %11111111
leddata [40] = %11111111
leddata [46] = %11111111
leddata [52] = %11111111
leddata [53] = %11111111
leddata [54] = %10111011
leddata [55] = %11111111
leddata [56] = %11111111
leddata [62] = %11111111
leddata [68] = %11111111
leddata [69] = %11111111
leddata [70] = %11111111
leddata [71] = %11111111
leddata [72] = %11111111
leddata [73] = %11111111
leddata [74] = %11111111
leddata [75] = %11111111
LOOPing:
FOR scroll = 0 TO 70
FOR scan = 0 TO 10
PORTA=%11111111
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:
' Set time & date to 11:59:00, Day 2, Date:Month:Year 30:08:2007
I2CWRITE SDA,SCL,$D0,$00,[$00,$59,$51,$02,$30,$08,$27,$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
return
end
Bookmarks