'===============================================================================
' GM12864-01A
' ST7567 LCD
' 128x64
'
'CKDIV8 wylaczony (bez zaznaczenia)
'LCD:
'RST-RST , Cs1-CS , A0-DC , SI-SDA , SCLK-SCL
'PD.0 - SCL(SCLK) / PD.1 - SDA(SI) / PD.2 - DC(A0) / PD.3 - RST(RST) / PD.4 - CS(CS1) / PD.5 - BL(podswietlenie)
'===============================================================================
$regfile = "m328pdef.dat"
$crystal = 16000000
$hwstack = 64
$swstack = 64
$framesize = 64
'0-wejsce/1-wyjscie stan na pin
Config Portb = &B00000000 : Portb = &B00111111
Config Portc = &B11001111 : Portc = &B01001110
Config Portd = &B00111111 : Portd = &B11100001
'*******************************************************************************
'$lib "Ds1307clock.lib" '"ds1307rtc.lib" modified lib
$lib "i2c_twi.lbx" ' we do not use software emulated I2C but the TWI
Config Sda = Portc.4 'DS1307 - SDA
Config Scl = Portc.5 'DS1307 - SCL
Config Twi = 400000 ' i2c speed
I2cinit
Const Ds1307w = &HD0 ' Addresses of Ds1307 clock
Const Ds1307r = &HD1
'definicja gdze trzymamy zmienne czas i data
Dim Weekday As Byte
Declare Sub Getdatetime
Declare Sub Settime
Config Clock = User ' this will dim the bytes automatic
Config Date = Dmy , Separator = . 'format wyswietlania daty DS1307
'Date$ = "02.12.17" 'dzien/miesiac/rok
'Time$ = "19.48.00"
'------------------------------------------------------------------------------
Config Timer0 = Timer , Prescale = 256
Enable Timer0 : On Timer0 Prztimer0
Enable Interrupts
'*******************************************************************************
Dim Flaga_4ms As Bit, Flaga_100ms As Bit ,Flaga_1s As Bit, Dzielnik As Byte , Dzielnik2 As Byte 'flagi
'********************************************************************************
$lib "glcd-ST7567.lib"
Config Graphlcd = 128x64sed , A0 = Portc.1 , Si = Portc.4 , Sclk = Portc.5 , Cs1 = Portc.3 , Rst = Portc.2
Const Negative_lcd = 0
Const Mirror_y = 1
'Dim N As Byte
'*******************************************************************************
'---------------------------------------------------------------------------
Initlcd
Lcdcontrast 35 'kontrast wyswietlacza, mozna zwiekszyc do 60
Cls
'************************************************************************************
Do
If Flaga_4ms = 1 Then 'co 4ms
Flaga_4ms = 0
'co ma byc co 4ms
End If
If Flaga_100ms = 1 Then ' co 100ms
Flaga_100ms = 0
'co ma byc po 100ms
gosub wyswietlanie
End If
If Flaga_1s = 1 Then 'co 1s
Flaga_1s = 0
'co ma byc co 1s
End If
Loop
End
'****************************przerwanie timer0******************************
Prztimer0:
Timer0 = 6
Flaga_4ms = 1
Incr Dzielnik
If Dzielnik = 25 Then '25*4ms = 100ms
Dzielnik = 0
Flaga_100ms = 1
Incr Dzielnik2
If Dzielnik2 = 10 Then '10*100ms=1s'
Dzielnik2 = 0
Flaga_1s = 1
End If
End If
Return
'*****************************************************************************
'***********************funkcje do obslugi DS1307*******************************
Getdatetime:
I2cstart ' Generate start code
I2cwbyte Ds1307w ' send address
I2cwbyte 0 ' start address in 1307
I2cstart ' Generate start code
I2cwbyte Ds1307r ' send address
I2crbyte _sec , Ack
I2crbyte _min , Ack ' MINUTES
I2crbyte _hour , Ack ' Hours
I2crbyte Weekday , Ack ' Day of Week
I2crbyte _day , Ack ' Day of Month
I2crbyte _month , Ack ' Month of Year
I2crbyte _year , Nack ' Year
I2cstop
_sec = Makedec(_sec) : _min = Makedec(_min) : _hour = Makedec(_hour)
_day = Makedec(_day) : _month = Makedec(_month) : _year = Makedec(_year)
Return
Setdate:
_day = Makebcd(_day) : _month = Makebcd(_month) : _year = Makebcd(_year)
I2cstart ' Generate start code
I2cwbyte Ds1307w ' send address
I2cwbyte 4 ' starting address in 1307
I2cwbyte _day ' Send Data to SECONDS
I2cwbyte _month ' MINUTES
I2cwbyte _year ' Hours
I2cstop
Return
Settime:
_sec = Makebcd(_sec) : _min = Makebcd(_min) : _hour = Makebcd(_hour)
I2cstart ' Generate start code
I2cwbyte Ds1307w ' send address
I2cwbyte 0 ' starting address in 1307
I2cwbyte _sec ' Send Data to SECONDS
I2cwbyte _min ' MINUTES
I2cwbyte _hour ' Hours
I2cstop
Return
'**********************************wyswietlanie*********************************
Wyswietlanie:
setfont font12x16dig 'pierwsza cyfra-linia, druga cyfra-pozycja
lcdat 1 , 1 , " ";"23:00:00" 'Time$
lcdat 5 , 1 , "2024-08-06"
setfont Font6x8
Lcdat 0 , 60 , "CZAS"
Lcdat 4 , 60 ,"DATA"
return
'******************************************************************************************
$include "font6x8.font"
$include "font12x16dig.font"