First of all I would like to apologize for my bad English.
I´m trying to build an RTC with the BIGAVR and an ATMEGA128 16I.
It is not the first time i m fighting with some bugs in the mikrobasic
compiler, but today maybe i am the problem not the compiler.....
There shout be 10 pulses every minute by the timer and every 10 pulses
the second shoult become (second +1) and so on....
So i can display the actually time........
in the moment the time ist to slowly an the display shows many wrong strings
here is the actually code. if you have an idea
in the fact i am out of germany some comments are in german ;-)
Code: Select all
program All_Codes
'*** This is a project with all my little programs, tested and untested.
'** Include all my files
'* Include all Vars/Consts
include Time_Date_var
'* Include all Codes
include Inits
'include Time_Date_code
'** Some exclusive Const in TEXT
'** Some exclusive Vars in TEST
dim i as integer
'###############################################################################
'################################################## TEST
sub procedure GLCD_dTime
dim text1 as string [5]
dim text2 as string [5]
dim text3 as string [5]
CLI
if dUhr = true then
byteToStr(Sek, Sekunden)
byteToStr(Min, Minuten )
byteToStr(Std, Stunden )
GLCD_Enable
Glcd_Box(0, 55, 50, 63, 0)
WordToStr(@Sekunden, text1)
WordToStr(@Minuten , text2)
WordToStr(@Stunden , text3)
Glcd_Write_Text(Sekunden, 0, 4, 1) ' here the display should show only 56 for example but there ist 564012
' so every time there are some symbols to much...... i have noidea
Glcd_Write_Text(text1, 64, 4, 1) ' i think it is a compiler problem....
Glcd_Write_Text("Second", 88, 4, 1)
Glcd_Write_Text(Minuten, 0, 5, 1)
Glcd_Write_Text(text2, 64, 5, 1)
Glcd_Write_Text("Minute", 88, 5, 1)
Glcd_Write_Text(Stunden, 0, 6, 1)
Glcd_Write_Text(text3, 64, 6, 1)
Glcd_Write_Text("Hour", 88, 6, 1)
GLCD_Disable
duhr = false
end if
SEI
end sub
sub procedure GLCD_Time_get org OVF1addr 'OC1Aaddr 'OVF1addr 'OVF0addr
CLI ' disable interupts
inc (cnt1)
if cnt1 = 10 then
duhr = true
PORTD = not (PORTD)
inc (Sek)
cnt1 = 0
end if
if Sek = 60 then
inc (Min)
Sek = 0
end if
if Min = 60 then
inc (Std)
Min = 0
end if
if Std = 24 then
Std = 0
end if
SEI ' enable interupts
end sub
'################################################## TEST END
'###############################################################################
'** Programcode
main:
SREG.7 = 1 ' enable global interrupt Timer0
TIMSK.2 = 1 ' enable interrupt on overflow Timer1
TCCR1B.0 = 1 ' start timer with 64 prescaler Timer1 - 10 mal pro sekunde
TCCR1B.1 = 1 ' " 40536
TCCR1B.2 = 0 ' "
TIMSK.4 = 0 ' enable interrupt on matchA Timer1
OCR1AH = hi(40536)
OCR1AL = lo(40536)
'* Run Programm ' first start
DDRB = 255 ' PortC set ==> output
DDRD = 255 ' PortD set ==> output
PortB = 0 ' PortC set ==> 00000000
PortD = 0 ' PortD set ==> 00000000
Sek = 0 ' @ the first start reset time
Min = 0
Std = 0
Tag = 0
Mon = 0
Jhr = 0
cnt1 = 0
'* GLCD reset ' clear glcd
GLCD_Enable
GLCD_Fill(0)
GLCD_Disable
duhr = true
'* Main_Loop
while true ' blink led on portB
delay_ms (500)
PortB = not (PortB)
if Button(PORTC, 0, 50, 1) then ' If PortC.0 is pressed the clock gets reset
Sek = 0
Min = 0
Std = 0
Tag = 0
Mon = 0
Jhr = 0
end if
GLCD_dTime ' procedure shows time (should do.... )
wend
end.
Code: Select all
module Time_Date_var
' Zeit / Datum (Time / Date)
'-------------------------------------------------------------------------------
' Const
const MONTHS as byte[12] = (31,28,31,30,31,30,31,31,30,31,30,31)
const YEARS as word[17] = (2008,2012,2016,2020,2024,2028,
2032,2036,2040,2044,2048,2052,
2056,2060,2064,2068,2072)
const dpkt = " : "
' Vars ' GERMAN // ENGLISCH
dim startZeit as boolean ' true = reset von Sek,Min... // true = reset of Sek, Min, Std, Tag.....
dim dUhr as boolean ' trur = Uhr sichtbar // true = Clock visible on GLCD
dim cnt1 as byte ' Counter 1
dim Sek as byte 'absolute 0x0121 ' Sekunde als Zahl // Second as numbder
dim Min as byte 'absolute 0x0124 ' Minute als Zahl // Minute as numbder
dim Std as byte 'absolute 0x0127 ' Stunde als Zahl // Hour as numbder
dim Tag as word ' Tag als Zahl // Day as numbder
dim Mon as byte ' Monat als Zahl // Month as numbder
dim Jhr as word ' Jahr als Zahl // Year as numbder
dim UhrText as string [7] ' gesamte Uhrzeit als Text // complete Time e.g. hh:mm:ss
dim Sekunden as string [1] ' Sekunde als Text // Second as text
dim Minuten as string [1] ' Minute als Text // Minute as numbder
dim Stunden as string [1] ' Stunde als Text // Hour as numbder
dim DatumText as string [9] ' gesamtes Datum als Text // comlete Date e.g. dd.mm.yyyy
dim Tage as string [1] ' Tage als Text // Day-number as text
dim Monate as string [1] ' Monate als Text // Month-number as text
dim Jahre as String [1] ' Jahre als Text // Year-number as numbder
startZeit = true ' TEST
dUhr = false ' TEST
end.
Code: Select all
module Inits
'############################################################################### ALLES OK UND GEPRÜFT
' Name: Init_GLCD
' Zweck: Diese Prodzedur kompensiert erst die Eigenarten des Compilers
' ########## GLCD_Enable ###########
'--------------------------------------
'Prozedur: GLCD einrichten
sub procedure GLCD_Enable
Glcd_Init(PORTE, 2, 3, 4, 5, 7, 6, PORTA)
Glcd_Set_Font(font5x7,5,7,32)
end sub
'--------------------------------------
'-------------------------------------------------------------------------------
' ########## GLCD_getMid ###########
'--------------------------------------
'Prozedur: Mittel-Position auf GLCD
sub procedure GLCD_getMid (dim byref XPosition, YZeile as byte)
Glcd_Set_Page(YZeile)
Glcd_Set_X(XPosition)
end sub
'--------------------------------------
'-------------------------------------------------------------------------------
' ########## LCD_Enable ###########
'--------------------------------------
'Prozedur: LCD einrichten
sub procedure LCD_Enable
Lcd_Init(PORTA, 3, 2, PORTA, LCD_HI_NIBBLE)
end sub
'--------------------------------------
'-------------------------------------------------------------------------------
end.