'
'* Project name:
' Softare I2C RTC Read (PCF8583)
'* Author:
' MikroElektronika, September 2006.
' * Description:
' This program demonstrates how to use soft_i2c library.
' * Test configuration:
' MCU: ATmega16
' Dev.Board: Easy AVR 4
' Oscillator: External, 8 MHz
' Ext. Modules: Real Time Clock board
' SW: mikroBasic for AVR 4.0
' * NOTES:
' put pull-up resisteors on i2c port for communication
' bug corrected in YEAR
'
program Soft_I2C_RTC_Read
dim sec, min, hr, day, mn, year as byte
temp as string[5]
txt as string[5]
' Reads time and date information from RTC (PCF8583)
sub procedure Read_Time(dim byref sec, min, hr, day, mn, year as byte)
year = 0
Soft_I2C_Start
Soft_I2C_Write($A0)
Soft_I2C_Write(2)
Soft_I2C_Start
Soft_I2C_Write($A1)
sec = Soft_I2C_Read(1)
min = Soft_I2C_Read(1)
hr = Soft_I2C_Read(1)
day = Soft_I2C_Read(1)
mn = Soft_I2C_Read(0)
Soft_I2C_Stop()
end sub
sub procedure Transform_Time(dim byref sec, min, hr, day, mn, year as byte)
dim tmp as byte
sec = Bcd2Dec(sec)
min = Bcd2Dec(min)
hr = Bcd2Dec(hr)
year = (day and $C0) >> 6
tmp = ((day and $30) >> 4)*10
day = day and $0F + tmp
tmp = ((mn and $10) >> 4)*10
mn = (mn and $0F) + tmp
year = 8 - year '(next leap year - year)
end sub ' after 2008 replace 8 by 12
main:
Soft_I2C_Init(PORTC,4,3)
Glcd_Init(PORTD, 2, 3, 4, 5, 7, 6, PORTA)
Glcd_Set_Font(font5x7,5,8,32)
Glcd_Fill(0x00)
Glcd_Write_Text("Current time",10,0,1)
Glcd_Write_Text(": :" ,36,1,1)
Glcd_Write_Text("Current date",10,3,1)
Glcd_Write_Text("200",52,4,1)
Glcd_Write_Text(" Software I2C",10,6,1)
' Main loop
while TRUE
Read_Time(sec, min, hr, day, mn, year)
Transform_Time(sec, min, hr, day, mn, year)
select case mn
case 1 txt = "Jan"
case 2 txt = "Feb"
case 3 txt = "Mar"
case 4 txt = "Apr"
case 5 txt = "May"
case 6 txt = "Jun"
case 7 txt = "Jul"
case 8 txt = "Aug"
case 9 txt = "Sep"
case 10 txt = "Oct"
case 11 txt = "Nov"
case 12 txt = "Dec"
case else txt = "..."
end select
' Dump date and time to GLCD
Glcd_Write_Text(txt,30,4,1)
ByteToStr(sec, temp)
Glcd_Write_Text(temp, 70, 1, 1)
ByteToStr(min, temp)
Glcd_Write_Text(temp, 40, 1, 1)
ByteToStr(hr, temp)
Glcd_Write_Text(temp, 10, 1, 1)
ByteToStr(day, temp)
Glcd_Write_Text(temp, 10, 4, 1)
ByteToStr(year, temp)
Glcd_Write_Text(temp, 70, 4, 1)
Delay_ms(200)
wend
end.
Bug corrected in Soft_I2C_RTC_Read
General discussion on mikroBasic for AVR.
Author
Message
Re: Bug corrected in Soft_I2C_RTC_Read
#2 Post by zristic » 02 Jan 2007 10:17
Can you please describe what you changed here?
#3 Post by Tess » 03 Jan 2007 12:07
Of course, the variable YEAR was bad in the procedure transform_Time.
The pcf8583 display the difference between the next leap year (2008) and the current year (2007) : 2008-2007=1
YEAR= 1
sub procedure Transform_Time(dim byref sec, min, hr, day, mn, year as byte)
dim tmp as byte
sec = Bcd2Dec(sec)
min = Bcd2Dec(min)
hr = Bcd2Dec(hr)
year = (day and $C0) >> 6
tmp = ((day and $30) >> 4)*10
day = day and $0F + tmp
tmp = ((mn and $10) >> 4)*10
mn = (mn and $0F) + tmp
year = 8 - year '(next leap year - year)
end sub ' after 2008 replace 8 by 12
Tess.
The pcf8583 display the difference between the next leap year (2008) and the current year (2007) : 2008-2007=1
YEAR= 1
sub procedure Transform_Time(dim byref sec, min, hr, day, mn, year as byte)
dim tmp as byte
sec = Bcd2Dec(sec)
min = Bcd2Dec(min)
hr = Bcd2Dec(hr)
year = (day and $C0) >> 6
tmp = ((day and $30) >> 4)*10
day = day and $0F + tmp
tmp = ((mn and $10) >> 4)*10
mn = (mn and $0F) + tmp
year = 8 - year '(next leap year - year)
end sub ' after 2008 replace 8 by 12
Tess.
Return to “mikroBasic for AVR General”
Jump to
- NECTO Studio
- ↳ IDE
- ↳ IDE General
- ↳ IDE Beta Testing
- ↳ IDE Wish List
- ↳ ARM AI Compilers
- ↳ mikroC AI for ARM
- ↳ mikroC AI for ARM General
- ↳ mikroC AI for ARM Beta Testing
- ↳ mikroC AI for ARM Wish List
- ↳ PIC AI compilers
- ↳ mikroC AI for PIC
- ↳ mikroC AI for PIC General
- ↳ mikroC AI for PIC Beta Testing
- ↳ mikroC AI for PIC Wish List
- ↳ PIC32 AI Compilers
- ↳ mikroC AI for PIC32
- ↳ mikroC AI for PIC32 General
- ↳ mikroC AI for PIC32 Beta Testing
- ↳ mikroC AI for PIC32 Wish List
- ↳ dsPIC AI Compilers
- ↳ mikroC AI for dsPIC
- ↳ mikroC AI for dsPIC General
- ↳ mikroC AI for dsPIC Beta Testing
- ↳ mikroC AI for dsPIC Wish List
- ↳ AVR AI Compilers
- ↳ mikroC AI for AVR
- ↳ mikroC AI for AVR General
- ↳ mikroC AI for AVR Beta Testing
- ↳ mikroC AI for AVR Wish List
- ↳ Additional Software
- ↳ Visual TFT AI
- ↳ Visual TFT AI General
- ↳ Visual TFT AI Beta Testing
- ↳ Visual TFT AI Wish List
- PRO Compilers
- ↳ PIC PRO Compilers
- ↳ PIC Compilers General
- ↳ mikroC PRO for PIC
- ↳ mikroC PRO for PIC General
- ↳ mikroC PRO for PIC Beta Testing
- ↳ mikroC PRO for PIC Wish List
- ↳ mikroBasic PRO compiler for PIC
- ↳ mikroBasic PRO for PIC General
- ↳ mikroBasic PRO for PIC Beta Testing
- ↳ mikroBasic PRO for PIC Wish List
- ↳ mikroPascal PRO for PIC
- ↳ mikroPascal PRO for PIC General
- ↳ mikroPascal PRO for PIC Beta Testing
- ↳ mikroPascal PRO for PIC Wish List
- ↳ dsPIC PRO Compilers
- ↳ dsPIC Compilers General
- ↳ mikroC PRO for dsPIC30/33 and PIC24
- ↳ mikroC PRO for dsPIC30/33 and PIC24 General
- ↳ mikroC PRO for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroC PRO for dsPIC30/33 and PIC24 Wish List
- ↳ mikroBasic PRO for dsPIC30/33 and PIC24
- ↳ mikroBasic PRO for dsPIC30/33 and PIC24 General
- ↳ mikroBasic PRO for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroBasic PRO for dsPIC30/33 and PIC24 Wish List
- ↳ mikroPascal PRO for dsPIC30/33 and PIC24
- ↳ mikroPascal PRO for dsPIC30/33 and PIC24 General
- ↳ mikroPascal PRO for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroPascal PRO for dsPIC30/33 and PIC24 Wish List
- ↳ PIC32 PRO Compilers
- ↳ PIC32 Compilers General
- ↳ mikroC PRO for PIC32
- ↳ mikroC PRO for PIC32 General
- ↳ mikroC PRO for PIC32 Beta Testing
- ↳ mikroC PRO for PIC32 Wish List
- ↳ mikroBasic PRO for PIC32
- ↳ mikroBasic PRO for PIC32 General
- ↳ mikroBasic PRO for PIC32 Beta Testing
- ↳ mikroBasic PRO for PIC32 Wish List
- ↳ mikroPascal PRO for PIC32
- ↳ mikroPascal PRO for PIC32 General
- ↳ mikroPascal PRO for PIC32 Beta Testing
- ↳ mikroPascal PRO for PIC32 Wish List
- ↳ AVR PRO Compilers
- ↳ AVR Compilers General
- ↳ mikroC PRO for AVR
- ↳ mikroC PRO for AVR General
- ↳ mikroC PRO for AVR Beta Testing
- ↳ mikroC PRO for AVR Wish List
- ↳ mikroBasic PRO compiler for AVR
- ↳ mikroBasic PRO for AVR General
- ↳ mikroBasic PRO for AVR Beta Testing
- ↳ mikroBasic PRO for AVR Wish List
- ↳ mikroPascal PRO for AVR
- ↳ mikroPascal PRO for AVR General
- ↳ mikroPascal PRO for AVR Beta Testing
- ↳ mikroPascal PRO for AVR Wish List
- ↳ FT90x PRO Compilers
- ↳ FT90x Compilers General
- ↳ mikroC PRO for FT90x
- ↳ mikroC PRO for FT90x General
- ↳ mikroC PRO for FT90x Beta Testing
- ↳ mikroC PRO for FT90x Wish List
- ↳ mikroBasic PRO compiler for FT90x
- ↳ mikroBasic PRO for FT90x General
- ↳ mikroBasic PRO for FT90x Beta Testing
- ↳ mikroBasic PRO for FT90x Wish List
- ↳ mikroPascal PRO for FT90x
- ↳ mikroPascal PRO for FT90x General
- ↳ mikroPascal PRO for FT90x Beta Testing
- ↳ mikroPascal PRO for FT90x Wish List
- ↳ 8051 PRO Compilers
- ↳ 8051 Compilers General
- ↳ mikroC PRO for 8051
- ↳ mikroC PRO for 8051 General
- ↳ mikroC PRO for 8051 Beta Testing
- ↳ mikroC PRO for 8051 Wish List
- ↳ mikroBasic PRO compiler for 8051
- ↳ mikroBasic PRO for 8051 General
- ↳ mikroBasic PRO for 8051 Beta Testing
- ↳ mikroBasic PRO for 8051 Wish List
- ↳ mikroPascal PRO for 8051
- ↳ mikroPascal PRO for 8051 General
- ↳ mikroPascal PRO for 8051 Beta Testing
- ↳ mikroPascal PRO for 8051 Wish List
- ↳ ARM PRO Compilers
- ↳ ARM Compilers General
- ↳ mikroC PRO for ARM
- ↳ mikroC PRO for ARM General
- ↳ mikroC PRO for ARM Beta Testing
- ↳ mikroC PRO for ARM Wish List
- ↳ mikroBasic PRO for ARM
- ↳ mikroBasic PRO for ARM General
- ↳ mikroBasic PRO for ARM Beta Testing
- ↳ mikroBasic PRO for ARM Wish List
- ↳ mikroPascal PRO for ARM
- ↳ mikroPascal PRO for ARM General
- ↳ mikroPascal PRO for ARM Beta Testing
- ↳ mikroPascal PRO for ARM Wish List
- ↳ Older versions of Compilers
- ↳ Older versions of mikroC Compilers
- ↳ mikroC for PIC
- ↳ mikroC General
- ↳ mikroC Beta Testing
- ↳ mikroC Wish List
- ↳ mikroC for dsPIC30/33 and PIC24
- ↳ mikroC for dsPIC30/33 and PIC24 General
- ↳ mikroC for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroC for dsPIC30/33 and PIC24 Wish List
- ↳ RSC-4x mikroC
- ↳ RSC-4x mikroC General
- ↳ RSC-4x mikroC Wish List
- ↳ mikroC Beta testing
- ↳ Older versions of mikroBasic Compilers
- ↳ mikroBasic compiler for PIC
- ↳ mikroBasic General
- ↳ mikroBasic Beta Testing
- ↳ mikroBasic Wish List
- ↳ mikroBasic compiler for dsPIC30/33 and PIC24
- ↳ mikroBasic for dsPIC30/33 and PIC24 General
- ↳ mikroBasic for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroBasic for dsPIC30/33 and PIC24 Wish List
- ↳ mikroBasic for dsPIC30/33 and PIC24 Bug List
- ↳ Obsolete Project: mikroBasic compiler for AVR
- ↳ mikroBasic for AVR General
- ↳ mikroBasic for AVR Wish List
- ↳ mikroBasic Beta testing
- ↳ Older versions of mikroPascal Compilers
- ↳ mikroPascal compiler for PIC
- ↳ mikroPascal FAQ
- ↳ mikroPascal General
- ↳ mikroPascal Beta Testing
- ↳ mikroPascal Wish List
- ↳ mikroPascal Bug List
- ↳ mikroPascal compiler for dsPIC30/33 and PIC24
- ↳ mikroPascal for dsPIC30/33 and PIC24 General
- ↳ mikroPascal for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroPascal for dsPIC30/33 and PIC24 Wish List
- ↳ mikroPascal for dsPIC30/33 and PIC24 Bug List
- ↳ Obsolete Project: mikroPascal compiler for AVR
- ↳ mikroPascal for AVR General
- ↳ mikroPascal for AVR Wish List
- ↳ mikroPascal Beta testing
- ↳ Library Development Discussion
- ↳ Code Requests
- Additional Software
- ↳ Visual TFT Software
- ↳ Visual TFT General
- ↳ Visual TFT Beta Testing
- ↳ Visual TFT Wish List
- ↳ Visual GLCD Software
- ↳ Visual GLCD General
- ↳ Visual GLCD Beta Testing
- ↳ Visual GLCD Wish List
- ↳ Package Manager Software
- ↳ Package Manager General
- ↳ Package Manager Beta Testing
- ↳ Package Manager Wishlist
- ↳ GLCD Font Creator Software
- ↳ SpeakUp Software
- ↳ Timer Calculator
- ↳ CAN Calculator
- ↳ mikroBootloader
- Hardware
- ↳ Development Boards
- ↳ CODEGRIP programmer and debugger
- ↳ Mikromedia
- ↳ mikroProg™ programmer and debugger
- ↳ Development Boards Wishlist
- ↳ Review
- ↳ Click Boards release
- ↳ Hexiwear
- Website & Forums
- ↳ Libstock Discussion
- ↳ Product Announcements
- ↳ Website & Forums General Discussion
- ↳ Website & Forums Wishlist
- ↳ User Projects