


We can do this by (individually) changing the following internal variables: _day, _month, _year, _sec, _hour, _min
#Ds1307 bascom program manual
Therefore we need a manual way to set/change the date and time. This statement is rather impractical, as it will set the date/time contained in the two strings, not the current date/time.
#Ds1307 bascom program how to
The Megaclock.bas sample shows to us how to set the date/time using the following statements: Date$ = “11/11/00” Time$ = “02:02:00” Then load the program into the microcontroller and our RTC clock will work. Place an ATmega32 (or any of the above-mentioned AVR microcontrollers) on the MegaPin (or MiniPin II) board and set the fuse bit to Internal RC – this is important! Place a 32,768 kHz crystal into the appropriate socket (J18 at MegaPin, J7 at MiniPin II), disconnect jumper (J5 at MegaPin J3 at MiniPin II) on PortC. With this statement, we have set all of the necessary registers in the AVR to allow Timer2 to work in asynchronous mode. For our use, the statement will look as follows: Config Clock = Soft This statement is thoroughly described in the Bascom-AVR Help. The main part of that short program is this statement: CONFIG CLOCK = soft /USER Mark Alberts, has already written a basic sample program Megaclock.bas that can be found in the Program Files/MCS/Bascom-AVR/Samples folder. That would make this microcontroller ideal for a low-power clock. Possibly you might use an ATmega168P, which, according to its datasheet, promises very low energy consumption during sleep mode. It should perform well in your device too, providing that you connect it up accordingly. This program will perform well on both the MegaPin and MiniPin II development boards.
#Ds1307 bascom program code
The sample code described here, is very practical, uses very little of the microcontroller’s resources and to top it off, generates an accurate clock. Programmers seem to love generating 1 second pulse with a timer interrupt service routine which increments the values of variables for second/hour/day etc. None of those programmers used the RTC clock that is described in this chapter. I’ve met many Bascom programmers and seen many programs, where a real time clock was used.

With some help from simple Bascom code, one can make an accurate clock which will display date and time.īascom-AVR offers many “goodies”, one of which is certainly the RTC clock. These AVRs are the ATmega8, ATmega168 and ATmega16 etc. Some AVR microcontrollers have Timer2 which can operate in asynchronous mode.
