'===============================================================================
' GM12864-01A
' ST7567 LCD
' 128x64
' PLYTKA TESTOWA
'CKDIV8 wylaczony (bez zaznaczenia)
'DS1307 zegar dziala
'PC.4 - SDA , PC.5 - SCL
'LED-Y: PC.1 - RED , PC.2 - GREEN , PC.3 - ORANGE (zalaczane "1")
'Przyciski: PB.1 - LEWO , PD.7 - PRAWO , PD.6 - MENU , PB.0 - GORA , PB.2 - DOL
'sterowanie podswietleniem MOSFET-P , zalacza "0"
'LCD:
'PD.0 - SCL(SCLK) / PD.1 - SDA(SI) / PD.2 - DC(A0) / PD.3 - RST(RST) / PD.4 - CS(CS1) / PD.5 - BL(podswietlenie)
'dodane logo przy starcie
'===============================================================================
$regfile = "m328pdef.dat"
$crystal = 16000000
$hwstack = 64
$swstack = 64
$framesize = 64
'0-wejsce/1-wyjscie stan na pin
Config Portb = &B00111000 : Portb = &B00000111
Config Portc = &B11001111 : Portc = &B00110001
Config Portd = &B00111111 : Portd = &B11000000
'*******************************************************************************
'"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 Ds3231w = &HD0 ' Addresses of Ds3231 clock
Const Ds3231r = &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 DS3231
'Date$ = "10.08.24" 'dzien/miesiac/rok
'Time$ = "12.14.00"
'******************************konfig.TIMER0**************************************
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 = PortD.2 , Si = PortD.1 , Sclk = PortD.0 , Cs1 = PortD.4 , Rst = PortD.3
Const Negative_lcd = 0
Const Mirror_y = 1
'Dim N As Byte
'*******************************************************************************
Dim Menu As Integer
Enable Interrupts 'odblokowanie przerwan
'***************************** menu Program ************************************
S1 alias pind.6 : Ddrd.6 = 0 : portd.6 = 1 '"MENU/ENTER"
S2 alias pind.7 : ddrd.7 = 0 : portd.7 = 1 '"DOL"
S3 alias pinb.0 : ddrb.0 = 0 : portb.0 = 1 '"GORA"
S4 alias pinb.1 : ddrb.1 = 0 : portb.1 = 1 '"LEWO"
S5 alias pinb.2 : ddrb.2 = 0 : portb.2 = 1 '"PRAWO"
LED_R alias portc.1 : portc.1 = 0
LED_G alias portc.2 : portc.2 = 0
LED_Y alias portc.3 : portc.3 = 0
'***************************logo startowe**********************************
Initlcd
Lcdcontrast 35 'kontrast wyswietlacza, mozna zwiekszyc do 60
Cls
Menu = 1
Showpic 0 , 0 , Logo3 'moje logo 128x64
Wait 4
cls
'*************************petla glowna**************************************
Do
Debounce S1 , 0 , Tast1 , Sub 'S1 "MENU"
Debounce S2 , 0 , Tast5 , Sub 'S2 "DOL"
Debounce S3 , 0 , Tast3 , Sub 'S3 "GORA"
Debounce S4 , 0 , Tast4 , Sub 'S4 "LEWO" (powrot)
Debounce S5 , 0 , Tast2 , Sub 'S5 "PRAWO"(wejscie "OK")
If Menu = 1 Then 'tutaj co ma byc wyswietlane na ekranie glownym
setfont font12x16dig 'pierwsza cyfra-linia, druga cyfra-pozycja
lcdat 1 , 10 , Time$
lcdat 5 , 10 , Date$
setfont Font6x8
Lcdat 0 , 50 , "CZAS"
Lcdat 4 , 50 ,"DATA"
end if
'****************************menu glowne***********************************
If Menu = 10 Then 'Menupunkt 1 'Zapytanie o zmienna z Menu = x
Gosub Menu10
End If
If Menu = 11 Then 'Menupunkt 2
Gosub Menu11
End If
If Menu = 12 Then 'Menupunkt 3
Gosub Menu12
End If
If Menu = 13 Then 'Menupunkt 4
Gosub Menu13
End If
If Menu = 14 Then 'Menupunkt 5
Gosub Menu14
End If
If Menu = 15 Then 'Menupunkt 6
Gosub Menu15
End If
'****************************podmenu*****************************************
If Menu = 100 Then 'Menupunkt 1.1
Gosub Menu100
End If
If Menu = 110 Then 'Menupunkt 2.1
Gosub Menu110
End If
If Menu = 120 Then 'Menupunkt 3.1
Gosub Menu120
End If
If Menu = 130 Then 'Menupunkt 4.1
Gosub Menu130
End If
If Menu = 140 Then 'Menupunkt 5.1
Gosub Menu140
End If
If Menu = 150 Then 'Menupunkt 6.1
Gosub Menu150
End If
'********************************flagi***************************************
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
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 DS3231*******************************
Getdatetime:
I2cstart ' Generate start code
I2cwbyte Ds3231w ' send address
I2cwbyte 0 ' start address in 1307
I2cstart ' Generate start code
I2cwbyte Ds3231r ' 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 Ds3231w ' 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 Ds3231w ' send address
I2cwbyte 0 ' starting address in 1307
I2cwbyte _sec ' Send Data to SECONDS
I2cwbyte _min ' MINUTES
I2cwbyte _hour ' Hours
I2cstop
Return
'**********************************procedury*********************************
Tast1:
if menu = 1 then
menu =10
else
menu = 1
end if
'Menu = Menu * 10 'Menu zwieksza sie 10-krotnie 'Jak Menu jest wieksze niz 150, Menu jest dzielone przez wspolczynnik 10
'If Menu > 150 Then 'Menu = "150" musi byc dostosowany!
'Menu = Menu / 10
'End If
Cls 'czyszczenie wyswietlacza
Return
Tast2:
If Menu > 1 Then 'Verhindert ausschweifung von Startscreen
If Menu < 100 Then 'Zapobiega nadmiarowi w podmenu "pozycja menu x.1"
If Menu < 15 Then 'Zapobiegaj liczeniu w gore > 15; musi byc dostosowany
Incr Menu
Cls
End If
End If
End If
Return
Tast3:
If Menu > 1 Then
If Menu > 10 Then
If Menu < 100 Then
Decr Menu
Cls
End If
End If
End If
Return
Tast4:
If Menu > 1 Then 'Zapobiega awariom Menu = 1 / 10
Menu = Menu / 10
Cls
End If
Return
Tast5:
if menu => 10 then
Menu = Menu * 10 'Menu zwieksza sie 10-krotnie 'Jak Menu jest wieksze niz 150, Menu jest dzielone przez wspolczynnik 10
If Menu > 150 Then 'Menu = "150" musi byc dostosowany!
Menu = Menu / 10
End If
end if
cls
Return
'**********************************Menu glowne*******************************************
Menu10:
'Cls
Setfont Font6x8 'gosub Menu10
Lcdat 0 , 0 , " MENU " 'Przeskakuje do pierwszej pozycji wyswietlacza w pierwszej linii
Lcdat 1 , 0 , "-> UST.GODINA " 'Pisze tresc na wyswietlaczu;
Lcdat 2 , 0 , " UST.DATA "
Lcdat 3 , 0 , " PROGRAM_1 "
Lcdat 4 , 0 , " PROGRAM_2 "
Lcdat 5 , 0 , " PROGRAM_3 "
Lcdat 6 , 0 , " PROGRAM_4 "
Return
Menu11:
'Cls
Setfont Font6x8
Lcdat 0 , 0 , " MENU "
Lcdat 1 , 0 , " UST.GODINA "
Lcdat 2 , 0 , "-> UST.DATA "
Lcdat 3 , 0 , " PROGRAM_1 "
Lcdat 4 , 0 , " PROGRAM_2 "
Lcdat 5 , 0 , " PROGRAM_3 "
Lcdat 6 , 0 , " PROGRAM_4 "
Return
Menu12:
'Cls
Setfont Font6x8
Lcdat 0 , 0 , " MENU "
Lcdat 1 , 0 , " UST.GODINA "
Lcdat 2 , 0 , " UST.DATA "
Lcdat 3 , 0 , "-> PROGRAM_1 "
Lcdat 4 , 0 , " PROGRAM_2 "
Lcdat 5 , 0 , " PROGRAM_3 "
Lcdat 6 , 0 , " PROGRAM_4 "
Return
Menu13:
'Cls
Setfont Font6x8
Lcdat 0 , 0 , " MENU "
Lcdat 1 , 0 , " UST.GODINA "
Lcdat 2 , 0 , " UST.DATA "
Lcdat 3 , 0 , " PROGRAM_1 "
Lcdat 4 , 0 , "-> PROGRAM_2 "
Lcdat 5 , 0 , " PROGRAM_3 "
Lcdat 6 , 0 , " PROGRAM_4 "
Return
Menu14:
'Cls
Setfont Font6x8
Lcdat 0 , 0 , " MENU "
Lcdat 1 , 0 , " UST.GODINA "
Lcdat 2 , 0 , " UST.DATA "
Lcdat 3 , 0 , " PROGRAM_1 "
Lcdat 4 , 0 , " PROGRAM_2 "
Lcdat 5 , 0 , "-> PROGRAM_3 "
Lcdat 6 , 0 , " PROGRAM_4 "
Return
Menu15:
'Cls
Setfont Font6x8
Lcdat 0 , 0 , " MENU "
Lcdat 1 , 0 , " UST.GODINA "
Lcdat 2 , 0 , " UST.DATA "
Lcdat 3 , 0 , " PROGRAM_1 "
Lcdat 4 , 0 , " PROGRAM_2 "
Lcdat 5 , 0 , " PROGRAM_3 "
Lcdat 6 , 0 , "-> PROGRAM_4 "
Return
'*******************************podmenu************************************
Menu100:
setfont font12x16dig 'pierwsza cyfra-linia, druga cyfra-pozycja
lcdat 3 , 10 , Time$
Return
Menu110:
setfont font12x16dig 'pierwsza cyfra-linia, druga cyfra-pozycja
lcdat 3 , 10 , date$
Return
Menu120:
Setfont Font6x8
Lcdat 2 , 0 , "Menupunkt 3.1"
Return
Menu130:
Setfont Font6x8
Lcdat 2 , 0 , "Menupunkt 4.1"
Return
Menu140:
Setfont Font6x8
Lcdat 2 , 0 , "Menupunkt 5.1"
Return
Menu150:
Setfont Font6x8
Lcdat 2 , 0 , "Menupunkt 6.1"
Return
'*****************************fonty, logo startowe*************************
$include "font6x8.font"
$include "font12x16dig.font"
Logo3:
$bgf "Logo 128x64 v3.BGF"