Code:
@ DEVICE pic16F877A, intOSC_osc_noclkout, WDT_ON, PWRT_ON, BOD_ON, MCLR_OFF
DEFINE OSC 4
OPTION_REG.7 = 0
ADCON0 = %110000000
ADCON1 = %000000111
CMCON=7
CVRCON=0
PORTA = %00000001 'Set all INPUTS to 0 except RA0 = DQ
TRISA = %00000001 'Set PORTA RA0-RA5
PORTB = %00000000 'Set all outputs to 0 (off)
TRISB = %00000000 'Set PORTB to all output
PORTC = %00000000 'Set all outputs to 0 (off)
TRISC = %00000000 'Set PORTC to all output
DQ var PortA.0
SDA Var PORTC.4 ' DS1307 SDA pin #5
SCL Var PORTC.3 ' DS1307 SCL pin #6
'***************************************************************************************
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 75 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
RTCSec Var byte ' alias individual bytes in array
RTCMin Var byte
RTCHour Var byte
RTCDay Var byte
RTCDate Var byte
RTCMonth Var byte
RTCYear Var byte
RTCCtrl Var byte
oraa var byte
orab var byte
minutea var byte
minuteb var byte
DS18B20_12bit CON %01111111
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
; temperature=2340 ; UNCOMMENT FOR DISPLAY TEST
tempA = temperature DIG 3
tempB = temperature DIG 2
tempC = temperature DIG 1
gosub read_1307
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:
I2CWRITE SDA,SCL,$D0,$00,[$00,$55,$15,$2,$6,$7,$4,$90] ' Write to DS1307
pause 10
RETURN
read_1307: ' Read time Secs,Mins,Hours,Day,Date,Month,Year,Control
I2CRead SDA,SCL,$D0,$00,[ RTCSec,RTCMin,RTCHour,RTCDay,RTCDate,RTCMonth,RTCYear,RTCCtrl]
RETURN
END
And I've got many errors :
Bookmarks