#picaxe 20X2 ' version C.3 * marks
' .-----_-----. .----------------------------------------------------------------------------.
' | V+ 0V | | 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 |
' | SI SO | | | | | | | | | | | | | | | |
' | C.7 B.0 |--> DB4 | Back view DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0 E GND RS VCC GND |
' | C.6 B.1 |--> DB5 | ^ ^ ^ ^ 0V 0V 0V 0V ^ 0V ^ V+ 0V |
' | C.5 B.2 |--> DB6 | Winstar OLED (2 line controllers (128-191)(192-255) 64+64 characters) |
' | C.4 B.3 |--> DB7 | (128-147) Line 1 Cursor Position |
' E <--| C.3 B.4 | | (192-211) Line 2 Cursor Position |
' RS <--| C.2 B.5 |<-> SDA | (148-167) Line 3 Cursor Position ( continuation of line 1 ) |
' | C.1 B.6 | | (212-231) Line 4 Cursor Position ( continuation of line 2 ) |
' | C.0 B.7 |--> SCL | EH002004A/B |
' '-----------' '----------------------------------------------------------------------------'
dirsC = %10111111
dirsB = %00001111
HI2Csetup off
pause 400
SYMBOL E = C.3
SYMBOL RS = C.2
SYMBOL senddata = b0
TABLE 0, ($3,$3,$3) ' parrallel interface expects 8bit data first
TABLE 3, ($2) ' ($20)sets to 4bit ,will now allow data too be received in two nibbles
TABLE 4, ($2,$A) ' data in two parts Msb first ($28)2lineControllers/5x8font/Eng-Jap) ($2A)Eng-Rus)
TABLE 6, ($0,$8,$0,$1,$0,$2,$0,$6,$0,$C) ' ($08)Display Off) ($01)Clear Display) ($02)Return Home) ($06)Entry Mode Set) ($0C)Display On)
TABLE 18, ("SatSunMonTueWedThuFri")
TABLE 40, ("marks......")
SYMBOL index = b1 : SYMBOL CRC = b1
SYMBOL Day = b2
SYMBOL secs = b3
SYMBOL mins = b4
SYMBOL hours = b5
SYMBOL date = b6
SYMBOL month = b7
SYMBOL year = b8
SYMBOL CommonYear = b9
SYMBOL PM_AM = b10
SYMBOL DayNumber = W6
SYMBOL DSTend = W7
SYMBOL DSTstart = W8 SYMBOL DayS = W8
SYMBOL D0 = b20
SYMBOL D1 = b21
SYMBOL D2 = b22
SYMBOL D3 = b23
SYMBOL D4 = b24
SYMBOL D5 = b25
SETFREQ M64
pause 400
IntialiseOLed:
FOR index = 0 to 15
READTABLE index, senddata : outpinsB = senddata : PULSOUT E,1 ' Initialise OLED/LCD
NEXT index : PAUSE 20
Display:
LOW RS
senddata = 129 : outpinsB = senddata >> 4 : PULSOUT E,1 : outpinsB = senddata : PULSOUT E,1'(128-147) Line 1 Cursor Position
HIGH RS
pause 400
FOR index = 40 TO 50
READTABLE index, senddata
outpinsB = senddata >> 4 : PULSOUT E,1 : outpinsB = senddata : PULSOUT E,1 ' sending characters to Line 1
NEXT index
IntialiseRTC:
HI2Csetup I2Cmaster, %11010000, I2Cfast_64, I2Cbyte ' DS3231
;;;; Collect date and time from the PICAXE Editor
bptr=28
FOR index = 2 TO 18
LOOKUP index,(ppp_datetime),@bptrinc ' ("2015-01-31 10:00:25")
NEXT index
;;;; Entering date and time in $BCD convert from ASCII
#terminal 76800
bptr =28
year = @bptrinc*$10+@bptrinc-$30 :inc bptr ' $0 to $99
month = @bptrinc*$10+@bptrinc-$30 :inc bptr ' $1 to $12
date = @bptrinc*$10+@bptrinc-$30 :inc bptr ' $1 to $31
hours = @bptrinc*$10+@bptrinc-$30 :inc bptr ' $0 to $23
mins = @bptrinc*$10+@bptrinc-$30 :inc bptr ' $0 to $59
secs = @bptrinc*$10+@bptrinc-$30 ' $0 to $59
READ 255,CRC : IF CRC <> 0 THEN Main ' Skip if time already programmed
HI2Cout $0 , (secs,mins,hours) ' RTC always expects (GMT +00:00)
HI2Cout $4 , (date,month,year)
Adjustsecs:
HI2Cin $0 , (secs)
IF secs <> $32 THEN adjustsecs
secs = secs + $27 ' add seconds (to allow for how long it takes to program)
HI2Cout $0 , (secs)
WRITE 255,53 ' we can make use of an existing eeprom entry
Main:
HI2Cin $0 , (secs,mins,hours) ' Read DS3231
HI2Cin $4 , (date,month,year) ' Read DS3231
;
FOR bptr = 3 TO 8
@bptr = bcdtobin @bptr ' Convert BCD to DECimal
NEXT
DayNumberOfTheYear:
CommonYear = year //4 +3 /4 'CommonYear =1
DayNumber = month +9 /12
DayNumber = CommonYear + DayNumber * DayNumber
DayNumber = month *275 /9 +date -30 -DayNumber
DayOfWeek:
DayS = year *368 **65046 '365.2485 * year 1-99
Day = days + DayNumber //7 'Sat=0 Sun=1 Mon=2 Tue=3 Wed=4 Thu=5 Fri=6
BritishSummerTime: ' United Kingdom
DSTstart = Days +89 //7
DSTstart = 91 -CommonYear -DSTstart ' Last SunDay in March
DSTend = Days +303 //7
DSTend = 305 -CommonYear -DSTend ' Last SunDay in October
IF DayNumber < DSTstart OR DayNumber > DSTend THEN GMT
IF DayNumber = DSTstart AND hours <1 THEN GMT ' DST starts at GMT 0100
IF DayNumber = DSTend AND hours >0 THEN GMT ' DST ends at GMT 0100
IF hours =23 THEN
INC date : day=day+1//7
IF date =31 AND month =4 OR month =6 OR month =9 THEN : date =1 INC month: ENDIF
IF date =32 THEN : date =1 INC month: ENDIF
ENDIF
BST: Sertxd ("BST ") : hours =hours +1//24 : GOTO DisplayTime ' DST +1
GMT: Sertxd ("GMT ") ' StandardTime
DisplayTime: day =day*3 +18
PM_AM = "P" : IF hours <12 THEN : PM_AM ="A": ENDIF ' Indicate PM or AM
hours = hours //12 : IF hours =0 THEN: hours =12 : ENDIF ' 24 to 12 hour format
D5 = hours /10 +$30 : IF D5 = "0" THEN : D5 = " " : ENDIF 'Zero blanking
D4 = hours //10 +$30
D3 = mins /10 +$30
D2 = mins //10 +$30
D1 = secs /10 +$30
D0 = secs //10 +$30
DisplayOled:
LOW RS
senddata = 128 : outpinsB = senddata >> 4 : PULSOUT E,1 : outpinsB = senddata : PULSOUT E,1'(128-147) Line 1 Cursor Position
HIGH RS
FOR index = 0 TO 2 ' sending characters to LCD line one
readtable day,senddata
outpinsB = senddata >> 4 : PULSOUT E,1 : outpinsB = senddata : PULSOUT E,1'
INC day
sertxd (senddata) ' comment out to remove day from terminal
NEXT index
FOR index = 0 TO 11 ' sending characters to LCD line 1
LOOKUP index,(" ",D5,D4,":",D3,D2,":",D1,D0," ",PM_AM,"M"),senddata
outpinsB = senddata >> 4 : PULSOUT E,1 : outpinsB = senddata : PULSOUT E,1'
NEXT index
sertxd (" ",#date,"/",#month,"/20",#year," ") ' (Date dd/mm/20yy) uncomment to display on terminal
sertxd (" ",D5,D4,":",D3,D2,":",D1,D0," ",PM_AM,"M",cr,lf) ' (Time HH:MM:SS AM)
GOTO main