Ds1307 Bascom Programming
Home | Products | Teensy | Blog | Forum |
You are here:TeensyTeensyduinoLibrariesDS1307RTC |
| DS1307RTC allows you to access real time clock (RTC) chips compatible withthe DS1307. It is intended to be used with theTime library.
Hardware RequirementsDS1307RTC works with the DS1307, DS1337 and DS3231 real time clock chips.The DS1307 chip only works with 5 volt power. The DS1337 and DS3231can use 3.3 or 5 volts. Teensy 3.0 has a built-in RTC, so the DS1337 offers little benefit.However, the DS3231 includes a temperature compensated crystal, so itis recommended for applications requiring high accuracy. The ChronoDotboard provides the DS3231 chip in an easy-to-use package. For usewith Teensy 3.0, you must add pullup resistors for the SDA and SCL signals. Basic UsageRTC.get();Reads the current date & time as a 32 bit 'time_t' number. Zero is returnedif the DS1307 is not running or does not respond. RTC.set(t);Sets the date & time, using a 32 bit 'time_t' number. Returns true forsuccess, or false if any error occurs. RTC.read(tm);Read the current date & time as TimeElements variable. See the Time libraryfor TimeElements details. Returns true on success, or false if thetime could not be read. RTC.write(tm);Sets the date & time, using a TimeElements variable. Returns true for RTC.chipPresent();Returns true if a DS1307 compatible chip was present after using the4 functions. If an error occurs, this can be used to distinguish betweena DS1307 that is not running vs no chip connected at all. Example ProgramDS1307RTC includes 2 examples, to read or set the time.You can open this example from File > Examples > DS1307RTC > ReadTest. |
Ds1307 Bascom Programs
Here you can find a step-by-step tutorial about the Bascom-AVR code to drive
the AVR Ethernet I/O-board
Ds1307 Bascom Program Free
This tutorial is based on my own hardware
Ds1307 Bascom Code
Step 1. Get the hardware.. | |
---|---|
A bare board size 180 x 90 mm. | |
Step 2: Description | |
AVR Ethernet I/O board. Atmega128, 2 x MAX3232EEWE for 2 x RS232, 1 x VNC1L-1A with 2 x USB connector, black/white composite video with Atmega32, DS1307 Real Time Clock with battery backup, PS/2 keyboard connector, Wiz810MJ ethernet module and LCD 16 x 2 with backlight. | |
Step 3: Some images building the board | |
Main processor, Atmega128, 3,3 volt, on 8 Mhz. | |
Step 4: Fusebits Atmega128 and Atmega32 | |
The fusebits of the Atmega32, the composite video controller. The fusebits of the Atmega128, the main processor. | |
Step 5: Atmega32 as a composite video chip | |
On http://www.sbprojects.net/projects/apple1/a-one-terminal.htm you can find the a1term.zip made by a electronics-friend. You can find a copy of the video controller software, including the source file, on his Download page. The program was written using his SB-Assembler. The entire program runs in one single interrupt routine. The main program is empty, well almost empty. Interrupts are spaced exactly 64µs apart for 50Hz systems, or 63.5µs for 60Hz systems. Each interrupt routine starts by generating an H-Sync pulse. A state machine then determines what is to be done during the rest of the line. Care should be taken that the interrupt routine ends before it's time to start a new one. What needs to be done?
All these tasks are performed inside the interrupt routine. A simple state machine determines what task needs to be done during each particular video line. Some lines leave no time to do anything else but control the video/sync outputs. Other lines allow plenty of time ( >55µs ) to do other tasks. These other tasks are: accepting characters from the Apple 1, sending the characters to the serial output, scrolling the screen, flashing the cursor, etc, etc. When the a1video.hex-file has been loaded in the Atmega32, here a demo how to use it with the Atmega128. Bascom-AVR can be used to program the Atmega32. Start Bascom-AVR, push on the button program chip, but instead of program, press on manual program. Erase the Atmega32, set the fusebits, load the buffer with the a1video.hex file (standard there is asked for a BIN-file, you can however load a HEX-file) and flash it into the Atmega32.
Close up of the Atmega32 video controller, Wiz810MJ ethernet module and PS/2 keyboard connector. During testing, small messages on the LCD are essential. The result on a DVD-player with composite connection (yellow plug right) | |
Step 6: Driving LCD 16 x 2 and the serial ports | |
Settings for COM2, in the middle of JP4.
2 x MAX3232EEWE and connectors | |
Step 7: VNC1L-1A - USB Controller | |
Two buttons to program the VNC1L-1A USB-controller on the AVR Ethernet I/O board. Called PROG and RESET. When you buy the VNC1L-1A, it is almost blanc, it has a bootloader. With the COM2 serial port, a terminal program like Hyperterminal (on 115200 baud) and a ROM-file from www.vinculum.com you can load the VNC1L-1A with the functions you want it to have. Once firmware has been loaded, an upgrade or other functions can be flashed by just plugging a USB memory stick in one of the USB connectors. By removing two SMD resistors and placing two resistors on another place both buttons can be connected to the Atmega128, so you will have a total of 5 buttons to work with. 2 x USB connector Don't under-estimate placing this chip on the AVR Ethernet I/O board, the VNC1L-1A. When you put the JP4 jumpers to the right, COM2 with it's MAX3232 is connected to the VNC1L-1A and you can type the commands from Hyperterminal at 9600 baud. When a memorystick is inserted it is detected. First thing is looking for a file to upgrade the firmware of the VNC1L-1A. FS, followed with IDD will show you the information of the memory stick. To create and write to a file this is what you can do in Hyperterminal Avitools 3 7.
And to do this from within Bascom-AVR 'VNC - Doing a DIR of the USB-stick, create a file called AVR.TXT, add or append a line of text and read the file back. 'Monkey proof code $regfile 'm128def.dat' $crystal = 8000000 $baud = 9600 ' first hardware UART $baud1 = 9600 ' second hardware UART Declare Sub Wait_for_prompt Declare Sub Reset_vnc Declare Sub Usb_cmd(byval Command As String) 'dimension used variables Dim C As String * 1 Dim X As Byte Dim Z As Byte Dim Command As String * 15 Dim Usb_handle As Byte Dim Check As Byte Dim Teller As Word Dim No_stick As Byte Open 'COM2:' For Binary As #2 Open 'COM1:' For Binary As #1 Config Portc.7 = Output Config Timer1 = Timer , Prescale = 256 'Config timer1 for a 1 second interval Enable Timer1 On Timer1 Isr_timer1 'Timer interrupt routine Enable Interrupts 'Activate the Interrupts Timer1 = 34285 'Startvalue for the second timer Do Call Reset_vnc usb_handle = 1 Check = 10 Call Wait_for_prompt Wait 3 Call Usb_cmd( 'DIR') Check = 10 Call Wait_for_prompt Wait 3 Call Usb_cmd( 'IPA') Wait 1 Call Usb_cmd( 'OPW AVR.TXT') Check = 10 Call Wait_for_prompt Call Usb_cmd( 'WRF 17') Wait 1 Call Usb_cmd( 'Bens HobbyCorner{013}') Check = 10 Call Wait_for_prompt Wait 1 Call Usb_cmd( 'CLF AVR.TXT') Check = 10 Call Wait_for_prompt Wait 1 Call Usb_cmd( 'RD AVR.TXT') Check = 10 Call Wait_for_prompt Incr Teller Loop Until Teller = 10000 End 'reset VNC1L-1A Sub Reset_vnc Reset Portc.7 Set Portc.7 Check = 10 Incr No_stick If No_stick = 10 Then Print 'No stick' Stop End If End Sub Sub Usb_cmd(command As String) Print Command For X = 1 To Len(command) C = Mid(command , X , 1) Z = Asc(c) Put #2 , Z Waitms 100 Next X Z = 13 Put #2 , Z End Sub Sub Wait_for_prompt Do Get #2 , Z Print Chr(z); Loop Until Z = Asc( '>') Check = 0 No_stick = 0 End Sub Isr_timer1: 'ISR of Timer1 Timer1 = 34285 'Timer1 must start from 34285 again If Usb_handle = 1 Then Decr Check If Check = 0 Then Call Reset_vnc End If End If Return You have to format your USB memory stick with 512 bytes sector size. This can be done like this: FORMAT E: /FS:FAT32 /A:512 | |
Step 8: Tools and toughts about VNC1L-1A | |
The way to program the blanc VNC1L-1A USB chip. Start VPROG_COM.EXE, select the right ROM-file, select the COM-port, press PROG on the board and power-up the board. Shortly press RESET and the firmware update is started. | |
Step 9: PS/2 keyboard | |
'PS2-keyboard | |
Step 10: Wiz810MJ-ethernet controller | |
' WIZ810MJ Ethernet demo '--------------------------------------------- ' Atmega128 and WIZ810MJ '---------------------------------------------
More examples for the WIZ810MJ can be found here: http://benshobbycorner.tk/bzijlstra/software/examples/wiz810mj.htm | |
Step 10: DS1307 Real Time Clock | |
To check if the DS1307Z+ can be found on the I2c-bus I use the I2c-scanner which I wrote a few years back. and here the code $regfile 'm128def.dat' | |
To be continued.. | |
Thanks to: | |
Thanks to Mark Alberts Thanks to San Bergmans | |
Ben Zijlstra - Ben's HobbyCorner - 2009 |