资源说明:The Network Time Protocol (NTP) has revolutionized the world. Suddenly one could have anywhere in the world accurate time and date. NTP is a simple UDP based protocol and can be implemented in a Microcontroller. Using the tuxgraphics ethernet board and a LCD display we build a nice clock which gets time and date via NTP. Just attach it to you DSL router!
Tuxgraphics ntp clock with build-in web interface
See http://tuxgraphics.org/electronics/ Copyright of most software and all diagrams: Guido Socher License for everything: GPL V2 See http://www.gnu.org/licenses/gpl.html --------------------------------------------------------------------------- All parts needed to build this AVR ethernet solution can be ordered from http://shop.tuxgraphics.org/ !! READ THIS FIRST !! --------------------- Edit the file main.c and change the lines: static uint8_t mymac[6] = {0x54,0x55,0x58,0x10,0x00,0x28}; static uint8_t myip[4] = {10,0,0,28}; static uint8_t gwip[4] = {10,0,0,1}; int16_t hours_offset_to_utc=40; For the first device you build you will not need to change the mymac line. But you will probably need to change the IP address (myip). It must be a free address from the address range in your home network. gwip is the default GW ip (how to get into the internet, normally the internal IP of your DSL router). hours_offset_to_utc is the time offset to UTC in hours times 10. You set this according to your timezone (-10 is Germany, France etc.. in winter). You can change all those values also later on without re-compiling but you want to have usable default values. Check the file "Makefile" and make sure the MCU is set correctly: ! MCU=atmega168 ! DUDECPUTYPE=m168 ! or ! MCU=atmega328p ! DUDECPUTYPE=m328 Adapt also the "LOADCMD" variable at the begining of the Makefile to be able to run "make load". You need an avr-gcc development environment in order to compile this. See http://tuxgraphics.org/electronics/200901/avr-gcc-linux.shtml To compile the final software use the command: make Note: windows users may use and modify the supplied winmake.bat to setup the environment correctly. The command make load will execute the avrdude command to load the main.hex software (NTP clock).# vim:sw=8:ts=8:si:et
Note your programmer might interfere with the enc28j60! For the avrusb500 with 30cm cable you can normally leave the cable on. For all other programmers it is however saver to remove the programmer cable and power down/up the device. This is because the SPI interface is used for loading of the software and communication to the enc28j60. To see a list of all possible build targets run the command: make help Selecting the right clock source -------------------------------- Tuxgraphics hardware sold as of march 2007 is prepared to use the clock signal from the enc28j60. To use this you need to change the low fuse byte once from 0x62 to 0x60: avrdude -p m168 -c stk500v2 -u -v -U lfuse:w:0x60:m or avrdude -p m328 -c stk500v2 -u -v -U lfuse:w:0x60:m or just type in your Linux shell: make fuse After programming the fuse settings of atmega168 and atmega88 should be: low fuse: 0x60 high fuse: 0xdf ext. fuse: 0x01 For the atmega328p the hfuse and efuse bytes look slightly different. The idea is however the same. Just change the lfuse from factory default to 0x60. The fuse settings of the atmega328 are after programming: lfuse reads as 0x60 hfuse reads as 0xD9 efuse reads as 0x07 details of the lfuse bits: CKDIV8 = 0 CKOUT = 1 SUT1 = 1 SUT0 = 0 CKSEL3 = 0 CKSEL2 = 0 CKSEL1 = 0 CKSEL0 = 0 If you are unsure what the current fuse setting are on the atmega then you can read the fuse settings with a command like: avrdude -p m168 -c stk500v2 -v -q The result should be this (default factory settings for atmega168): avrdude: safemode: lfuse reads as 62 avrdude: safemode: hfuse reads as DF avrdude: safemode: efuse reads as 1 The result should be this (default factory settings for atmega328p, the efuse is dependent on the chip revision): avrdude: safemode: lfuse reads as 62 avrdude: safemode: hfuse reads as D9 avrdude: safemode: efuse reads as 7 Compiling on non-Unix systems ----------------------------- Please use the provided Makefile !!! It will also work under Windows. Take a look at the supplied winmake.bat and winload.bat file. This bat script might be needed to set the environment correctly. A description of what makefiles are and how they work can be found at: http://tuxgraphics.org/electronics/200912/makefiles.shtml Hardware tests and other test software -------------------------------------- This package contains besides the NTP clock also other software that you can use to test the hardware. They are simple examples and good if you want to understand how a specific aspect of the main software works. 1) test_lcd.c This is a simple LCD display test: Compile and load it with the command make load_test_lcd 2) test_basic_ntpclient.c This is a simple web-page sending an NTP query and it displays the time received. Change the IP addresses as described further up but this time in file test_basic_ntpclient.c and the use the command make load_test_basic_ntpclient to compile and load the software. Using the NTP clock ------------------- Point your web browser to http://10.0.0.28 (or what ever IP address you have given your hardware) and you should see the time and date in the same way as it is shown on the LCD: AVR NTP clock Sun 2007-10-28 21:22:50 (UTC +1) refresh The LCD display has a link status and update status indicator on the right (behind the braces). The meaning of this character is: - nothing: ETH link ok, NTP time sync up-to date - '/': ETH link down - '|': ETH link up but ntp sever could not be reached yet. The clock tries to sync every hour. Thus if you cut your internet connection during the night then you will see this character. Note that the clock will continue to run form the internal crystal. Changing the configuration -------------------------- To change from summer to winter time or to modify any IP point your web browser to http://10.0.0.28/config (or what ever IP address you have given your hardware at compile time) The default password (if you did not change is) is: secret You can rest any changes back to compile time default values in case you forgot what you changed. Connect pin PB0 on the atmega chip with GND and power-cycle the clock. It will then come up with the compile time default settings. Revision history ---------------- 2007-10-28: version 0.1 -- first public version 2007-11-06: version 0.2 -- remove blocking loop at startup. Missing cast in gmtime function (thanks to Scott Parlane) Write link indicator in the first line. There is more space Allow multiple of 0.5 hours offset to utc 2008-04-26: version 0.3 -- Codevision compatibility The new avrdude checks if you have a atmega88 or atmega168 this needs to be reflected now in the Makefile. -- Make password sting longer -- add a "continue button" 2008-05-17: version 0.4 -- it was not possible to store time zones with negative offset. 2008-07-22: version 0.5 -- fault in time zones data on config page fixed 2009-03-25: version 0.6 -- Updates for atmega328 2009-06-24: version 0.7 -- Display own MAC addr. in config page. 2009-08-02: version 0.8 -- Update for string buffer overrun (change buf to 570) 2010-01-31: version 0.9 -- Major re-write. Now using the new TCP/IP stack. 2010-02-06: version 1.0 -- Make use of the arp refresh feature in the new stack 2012-10-21: version 1.1 -- add options to show 24h/12h and time offset to UTC in display -- repeat messages immediately multiple times until first time successful 2013-02-15: version 1.2 -- fix faulty password check
本源码包内暂不包含可直接显示的源代码文件,请下载源码包。