| The Datasheet Archive - 100 Million Datasheets from 7500 Manufacturers. |
AN018801-0404 This publication subject replacement later edition.
Top Searches for this datasheetApplication Using Real-Time Clock eZ80F91 AN018801-0404 This publication subject replacement later edition. determine whether later edition exists, request copies publications, contact: ZiLOG Worldwide Headquarters Race Street Jose, 95126 Telephone: 408.558.8500 Fax: 408.558.8300 www.zilog.com ZiLOG registered trademark ZiLOG Inc. United States other countries. other products and/or service names mentioned herein trademarks companies with which they associated. Information Integrity information contained within this document been verified according general principles electrical mechanical engineering. applicable source code illustrated document either written authorized ZiLOG employee licensed consultant. Permission these codes form, besides intended application, must approved through license agreement between both parties. ZiLOG will responsible code(s) used beyond intended application. Contact local ZiLOG Sales Office obtain necessary license agreements. Document Disclaimer ©2004 ZiLOG, Inc. rights reserved. Information this publication concerning devices, applications, technology described intended suggest possible uses superseded. ZiLOG, INC. DOES ASSUME LIABILITY PROVIDE REPRESENTATION ACCURACY INFORMATION, DEVICES, TECHNOLOGY DESCRIBED THIS DOCUMENT. ZiLOG ALSO DOES ASSUME LIABILITY INTELLECTUAL PROPERTY INFRINGEMENT RELATED MANNER INFORMATION, DEVICES, TECHNOLOGY DESCRIBED HEREIN OTHERWISE. Except with express written approval ZiLOG, information, devices, technology critical components life support systems authorized. licenses other rights conveyed, implicitly otherwise, this document under intellectual property rights. AN018801-0304 Application Note Application Using Real-Time Clock eZ80F91 Table Contents List Figures List Tables Abstract Overview Features Objects eZ80Acclaim!Real-Time Clock Developing RZK-RTC Application Hardware Architecture Software Implementation Adding Application Project Standard Testing Test Setup Test Procedure Using RZK-RTC Application Summary Appendix A-Reference Appendix B-Flowcharts Appendix C-Source Code Files Files AN018801-0404 Application Note Application Using Real-Time Clock eZ80F91 List Figures Figure Block Diagram Embedded RTC-RZK application Architecture Figure Connection Details between eZ80F91 MCU, Module, Keypad. Figure Functions Keypad keys Figure Block diagram World Clock Application with Figure Connection Download RZK-RTC Application eZ80F91 Figure Flowchart Application Entry Task Figure Flowchart Timer Figure Flowchart Keypad Thread Entry Task Figure Flowchart Keypad Thread Task Figure Flowchart Thread Entry Task List Tables Table List References AN018801-0404 Application Note Application Using Real-Time Clock eZ80F91 Abstract This Application Note describes ZiLOG Real-time Kernal (RZK) application that uses real-time clock (RTC) peripheral ZiLOG's eZ80F91 function world clock. keypad display interface provided view local time local date country, local time with daylight saving, also operate stopwatch. current time maintained 24-hour format. source code file AN0188-SC01.zip, associated with this Application Note available ZiLOG website. Overview ZiLOG Real-time Kernel (RZK) real-time, pre-emptive, multitasking kernel designed time-critical embedded applications. currently available with ZiLOG's eZ80Acclaim!family microcontrollers microprocessors. real-time multitasking kernel (also called real-time operating system, RTOS) software which ensures that time-critical events processed efficiently possible.The RTOS generally simplifies design process system allowing application divided into multiple independent elements called tasks. Features functional architecture configurable, scalable modular design provides rich features easy-to-use APIs. features tuned stringent memory performance requirements 8-bit domain. compact with minimal footprint accommodated Flash area target processor. allows rapid context switching between threads besides offering quick interrupt responses. features pre-emptive, prioritybased, multitasking scheduler, provides timing support delays, time-outs other periodic events. Users take advantage RZK's time-slicing option with adjustable time slices. addition various configuration options, provides priority inheritance facility. Objects objects used real-time application development threads, message queues, event groups, semaphores, timers, partitions regions (memory objects), interrupts. objects kernel services resource management provide APIs interface application.The application optionally uses objects, based requirements. AN018801-0404 Abstract Application Note Application Using Real-Time Clock eZ80F91 brief overview Thread Control functions presented below. Thread Control Thread Control functions used create threads perform following operations created thread: Suspending thread finitely infinitely Resuming thread that suspends infinitely Deleting thread Changing priority thread Yielding control other threads Getting thread parameters more information RZK, please refer Reference Manual (RM0006) that available ZiLOG website. eZ80Acclaim!Real-Time Clock eZ80F91 device member ZiLOG's family eZ80Acclaim!Flash Microcontrollers.The eZ80F91 high-speed single-cycle instruction-fetch microcontroller with maximum clock speed 50MHz.The rich peripheral eZ80F91 makes suitable variety applications, including industrial control, embedded communication, point-of-sale terminals. following section discusses real-time clock peripheral eZ80F91 MCU, which used this Application Note. Real-Time Clock eZ80F91 features real-time clock with on-chip 32KHz oscillator, selectable 50/60Hz input, separate battery backup. realtime clock (RTC) keeps time maintaining count seconds, minutes, hours, day-of-the-week, day-of-the-month, year, century. current time maintained 24-hour format. format count alarm registers selectable between binary binary-coded-decimal (BCD) operations.The calendar operation maintains correct month automatically compensates leap year. more details real-time clock refer eZ80F91 Product Specification document (PS0192), available ZiLOG website. AN018801-0404 Overview Application Note Application Using Real-Time Clock eZ80F91 Developing RZK-RTC Application This Application Note focuses multi-threaded environment along with timer. software timer accuracy enhanced increasing number ticks second. This section contains hardware software implementation details developing RZK-RTC application. Hardware Architecture Figure block diagram hardware architecture featuring eZ80 Development Platform with eZ80F91 Module, keypad, Character module. Keypad (4x4) eZ80F91 Port Port Display (16x2) Figure Block Diagram Embedded RTC-RZK application Architecture Port eZ80F91 connected Character module that displays time date. Port eZ80F91 connected keypad that scans keys continuously.The columns keypad pulled with resistance, making them HIGH normally. Figure following page contains details this connection. AN018801-0404 Developing RZK-RTC Application Application Note Application Using Real-Time Clock eZ80F91 (3.3 Character Module (16x2) eZ80F91 ROW4 ROW3 ROW2 ROW1 COL1 COL2 COL3 COL4 Keypad (4x4) (3.3 Figure Connection Details between eZ80F91 MCU, Module, Keypad. Figure page illustrates details keypad.The keypad marked with numeric keys (0-9) function keys (A-F).The function keys are: local time local date enter function terminate function (enter/exit key) activate stopwatch select default country/set daylight saving view country time AN018801-0404 Developing RZK-RTC Application Application Note Application Using Real-Time Clock eZ80F91 Connector Column View country time Select default country daylight saving stopwatch Local Time Enter Local Date Figure Functions Keypad keys Software Implementation There tasks-the task Keypad task-which perform basic functionality setting displaying country, time date, also stopwatch operations. Auxillary functions, such conversion from binary ASCII, ASCII BCD, time addition subtraction, other manipulation functions required tasks, provided AuxFunc.c file (see Appendix page 18). Figure page illustrates basic software flow implemented RZKRTC application. AN018801-0404 Developing RZK-RTC Application Application Note Application Using Real-Time Clock eZ80F91 Module Keypad Module Display Module Central Repository Data manipulation Figure Block diagram World Clock Application with module updates Central Repository every second. Keypad module scans keys continuously hits. Display module reads date from Central Repository continuously updates time date display.The Data Manipulation module takes care changing data format appropriately processing data. functions-RZKApplicationEntry() function RZKTImer1() routine explained following sections before application tasks explained. RZKApplicationEntry() This function main entry point application into RZK. application program entry function performs following operations: Initializes peripherals Creates threads Keypad (LCDTask() KeyPadTask()) Creates timer Resumes threads AN018801-0404 Developing RZK-RTC Application Application Note Application Using Real-Time Clock eZ80F91 RZKTimer1() This software timer interrupt service routine (ISR) reads real-time clock registers-second, minute, hour, day, month, year-and updates global variables Central Repository. LCDTask() LCDTask() thread continuously updates time date display. When user selects functional (mode selection), LCDTask() thread displays appropriate string Character Module. Pressing instead number keys terminates selected functionality LCDTask() thread resumes displaying current time date LCD. main operations performed this thread are: Checks mode selection keys pressed specific functionality. mode selection keys followed pressed, this thread reads appropriate string Central Repository displays module. user does press number keys instead presses selected function terminated module updated with current time date. user does select mode selection key, this thread updates module with current time date. KeyPadTask() This thread continuously scans keypad. When mode selection pressed, detects press ready take user input form other presses time date select country.The thread then updates Central Repository with this data. main operations performed this thread are: Scan keys, row- column-wise Check mode selection pressed mode selection pressed, wait other presses Update repository with data number keys AN018801-0404 Developing RZK-RTC Application Application Note Application Using Real-Time Clock eZ80F91 Adding Application Project Standard This section contains details adding RZK-RTC application project file standard downloading internal Flash memory eZ80F91 MCU. software available ZiLOG website downloaded with user registration key. installed location specified user; default location C:\Program Files\ZiLOG. Perform following steps application files directory: Connect eZ80F91 Development Kit, ZPAKII, shown Figure eZ80F91 Development (eZ80F910200ZC0) RS-232 ZPAK eZ80 Development Platform Ethernet Ethernet Ethernet Port Ethernet LAN/WAN/INTERNET Figure Connection Download RZK-RTC Application eZ80F91 Using download RZK, browse location where downloaded, open .\eZ80F91\Sample Programs folder. Download AN0188-SC01.zip file extract contents folder your Notice that there folder \RTC within extracted folder. Copy \RTC folder paste into .\eZ80F91\Sample Programs folder. Notice that there folders within \RTC folder.These folders are: \IntFlash containing RTC.pro file downloaded internal Flash memory MCU. AN018801-0404 Developing RZK-RTC Application Application Note Application Using Real-Time Clock eZ80F91 \Ram containing RTC.pro file downloaded memory MCU. Launch HyperTerminal program address ZPAKII downloading application program. Note: Refer ZPAKII Product User Guide (PUG0015) details. Launch ZDSII eZ80Acclaim!4.7.0, open project located path: <RZK Installed Dir>\rzk1.0.0\eZ80F91\Sample Programs\Rtc\<RAM Flash>\RTC.pro Build project download eZ80F91 using ZDSII. Note: Please modify project settings project files. Refer ZDSII-eZ80Acclaim!User Manual (UM0144). Testing This section describes RZK-RTC application tested. Test Setup Figure illustrates connection diagram between LAN/WAN, eZ80F91 Development Kit. Figure illustrates connection diagram between eZ80F91 MCU, Keypad module. Equipment Used eZ80F91 Development with eZ80F91 Module Keypad 16x2 Character Module fitted with Hitachi HD44780 controller Test Procedure Make sure that project file, RTC.pro built downloaded eZ80F91 MCU. (See Adding Application Project Standard page Connect eZ80F91 Module Keypad Character Module shown Figure page From within ZDSII, project. AN018801-0404 Testing Application Note Application Using Real-Time Clock eZ80F91 Press Keypad keys select country default, local time local date, stopwatch. Refer Using RZK-RTC Application section details using features this application. Using RZK-RTC Application RZK-RTC application used following ways: Default Country Display Press keypad repeatedly select country; stop when country your choice displayed display. Press enter selected country default country. Pressing displays daylight saving status. Users set/ change daylight saving this point pressing again; daylight saving enabled/disabled depending current status (see Set/ Change Daylight Saving section below). Users defer daylight saving settings pressing immediately after pressed first time. Press exit from process. Set/Change Daylight Saving change daylight saving settings, press keypad; current daylight saving status displayed. default, daylight saving disabled; displays toggled enable disable daylight saving. enable daylight saving, press function enabled. displays daylight saving status YES. disable daylight saving, press displays indicating that daylight saving disabled. Press enter selected daylight saving setting. Local Time first-time setting, repeat process default country. press Local Time message appears display. Press number keys enter current time; current time displayed. Press local time exit from process. AN018801-0404 Testing Application Note Application Using Real-Time Clock eZ80F91 Local Date first-time setting, repeat process default country. press Local Date message appears display. Press number keys enter current date; current date displayed. Press local date exit from process. View Country Time Press repeatedly select country; stop when country your choice displayed display. Press exit from process; selected country's local time date displayed. Stopwatch Press select stopwatch. Press again start stop stopwatch. Press exit from process. RZK-RTC application successfully runs eZ80F91 MCU. Selecting country setting local time local date works satisfactory. Summary This Application Note highlights capability ZiLOG Real-time Kernel (RZK) efficiently scan keypad inputs display world clock time date using real-time clock peripheral eZ80F91 MCU. application also provides stopwatch feature. Going forward, embedded real-time clocks, described this Application Note, used simple tasks such setting alarms, synchronizing other RZK-related tasks, such home automation, where user time switching OFF/ON certain home appliances from remote location using ZiLOG's TCP/IP stack-ZTP. AN018801-0404 Summary Application Note Application Using Real-Time Clock eZ80F91 Appendix A-Reference Further details about eZ80F91 MCU, ZDSII found references listed Table Table List References Topic eZ80F91 Document Name eZ80F91 Flash with Ethernet Product Specifications (PS0192) eZ80F91 Module Product Specification (PS0193) ZDSII-IDE ZiLOG Developer Studio II-eZ80Acclaim!User Manual (UM0144) Reference Manual (RM0006) User Manual (UM0075) Quick Start Guide (QS0027) Note: These documents available ZiLOG website. AN018801-0404 Appendix A-Reference Application Note Application Using Real-Time Clock eZ80F91 Appendix B-Flowcharts This appendix lists flowcharts various tasks performed RZK-RTC application described this Application Note. Application entry task flowchart illustrated Figure Start Initialize devices Keypad interface interface interface Create Display task Keypad task timer Resume Keypad Display tasks Figure Flowchart Application Entry Task AN018801-0404 Appendix B-Flowcharts Application Note Application Using Real-Time Clock eZ80F91 flowchart timer illustrated Figure Start Update time date repository (hh:mm:ss time mm/dd/yy date) second flag stopwatch activated? Update stopwatch time hh:mm:ss Figure Flowchart Timer AN018801-0404 Appendix B-Flowcharts Application Note Application Using Real-Time Clock eZ80F91 flowchart first part Keypad task illustrated Figure Start mode pressed? view country time pressed? Read selected country name time; Write display buffer; default country? Read selected country time difference; Real-time clock accordingly; stopwatch pressed? Increment stopwatch clock every second Figure Flowchart Keypad Thread Entry Task AN018801-0404 Appendix B-Flowcharts Application Note Application Using Real-Time Clock eZ80F91 flowchart concluding part Keypad task illustrated Figure local time pressed? Read time from keypad hh:mm:ss; Write time into Repository hh:mm:ss; mode flag local date pressed? Read date from keypad mm:dd:yy; Write date into Repository mm:dd:yy; mode flag Enter pressed? Reset with time/date/ time date; mode flag Figure Flowchart Keypad Thread Task AN018801-0404 Appendix B-Flowcharts Application Note Application Using Real-Time Clock eZ80F91 flowchart task illustrated Figure Start mode flag Write time date string display Test mode Write mode string display Figure Flowchart Thread Entry Task AN018801-0404 Appendix B-Flowcharts Application Note Application Using Real-Time Clock eZ80F91 Appendix C-Source Code This appendix contains listing source code associated with RTC-RZK Application Note. source code available AN0188-SC01.zip file that downloadable from ZiLOG website. Note: AN0188-SC01.zip file also contains code files display. These files taken from Character Interface eZ80Acclaim!MCUs Application Note source code file, AN0159SC01.zip (downloadable from ZiLOG website). display files listed this section. Files following files listed this section: Rtcmain.c InitializeRTC Devices.c RtcTask.c AuxFunc.c File RTCmain.c Description This file contains entry point function application. initialization RTC, creating thread timer also done this file. Copyright 2004 ZiLOG Inc. RIGHTS RESERVED. source code this file written authorized ZiLOG employee licensed consultant. source code been verified fullest extent possible. Permission this code granted royalty-free basis. However users cautioned authenticate code contained herein. ZiLOG DOES GUARANTEE VERACITY SOFTWARE. AN018801-0404 Appendix C-Source Code Application Note Application Using Real-Time Clock eZ80F91 standard header files #include <stdio.h> #include <string.h> #include "RtcTask.h" #include "LCD_API.h" header files #include #include #include #include "ZSysgen.h" "ZTypes.h" "ZThread.h" "ZTimer.h" macros macros threads #define PRIORITY #define STACK_SIZE #define RR_TICK thread priority stack size thread round robin tick schedular extern struct RTC_parm RTC_parm1; extern struct Country_Time Country[NO_OF_COUNTRYS]; extern char countrycount; extern function declarations function initializing UART port printing messages console extern void InitUART(); extern void RZKFormatError(UINT num) extern RZK_STATUS_t RZKGetErrorNum( global variables thread handles store RZK_THREADHANDLE_t g_hthd1 RZK_THREADHANDLE_t g_hthd2 RZK_TIMERHANDLE_t hTimer stack threads char g_thd1stack STACK_SIZE AN018801-0404 Appendix C-Source Code Application Note Application Using Real-Time Clock eZ80F91 char g_thd2stack STACK_SIZE application entry void RZKApplicationEntry() RZK_STATUS_t status countrycount DEFAULT_COUNTRY; Init_Country(); InitUART(); Initialize UART port print messages console InitRTC(); Init Real Time Clock InitKeypad(); Init port keypad interface init_timer3(); init timer3 delay LCD_init(); Init Display LCD_clear(); clear initially LCD_prints(" ZiLOG LCD_setposition(1,0); LCD_prints(" delayms(100); hTimer RZKCreateTimer(( unsigned char status RZKEnableTimer( hTimer printf("\nStarting create threads" create threads with same priority attributes thread round robin mode printf("\nCreating thread #1") g_hthd1 RZKCreateThread( unsigned char "Thread1", LCDTask, NULL, NULL,(g_thd1stack STACK_SIZE), PRIORITY, RR_TICK, RZK_THREAD_PREEMPTION RZK_THREAD_ROUNDROBIN) validate thread handle g_hthd1 NULL printf("\nUnable create thread error description is"); RZKFormatError( RZKGetErrorNum() return AN018801-0404 Appendix C-Source Code Application Note Application Using Real-Time Clock eZ80F91 printf("\nCreating thread #2"); g_hthd2 RZKCreateThread( unsigned char "Thread2", KeyPadTask, NULL, NULL,(g_thd2stack STACK_SIZE PRIORITY, RR_TICK, RZK_THREAD_PREEMPTION RZK_THREAD_ROUNDROBIN); validate thread handle g_hthd2 NULL printf("\nUnable create thread error code %d", RZKGetErrorNum() unable create thread delete thread status RZKDeleteThread(g_hthd1) if(status RZKERR_SUCCESS) printf("\nCould able delete thread error description is"); RZKFormatError( status return delayms(1000); RZKResumeThread(g_hthd1); RZKResumeThread(g_hthd2); file File InitializeRTCDevices.c Description This file initializes keypad port. Copyright 2004 ZiLOG Inc. RIGHTS RESERVED. source code this file written authorized ZiLOG employee licensed consultant. source code been verified fullest extent possible. Permission this code granted royalty-free initial delay resume thread1 resume thread2 AN018801-0404 Appendix C-Source Code Application Note Application Using Real-Time Clock eZ80F91 basis. However users cautioned authenticate code contained herein. ZiLOG DOES GUARANTEE VERACITY SOFTWARE. #include #include #include #include #include #include #include "ZSysgen.h" "ZTypes.h" "ZThread.h" "ZMemory.h" "ZTimer.h" "ZInterrupt.h" "ZEventgroup.h" #include "LCD_API.h" #include "RtcTask.h" Header file //void bin_to_ascii1(unsigned char,unsigned char,unsigned char,char void InitRTC(void) RTC); RTC_CTL 0x01; RTC_CEN RTC_YR RTC_MON RTC_DOM RTC_HRS RTC_MIN RTC_SEC RTC_DOW RTC_CTL 0x00; unlocks RTC_UNLOCK write other registers. selected with reset counts BCD, should counting binary locks RTC_LOCK enables counting void InitKeypad(void) LCD_gpio_set AN018801-0404 Appendix C-Source Code Application Note Application Using Real-Time Clock eZ80F91 PB_DR PB_DDR PB_ALT1 PB_ALT2 0xFF; 0x0F; 0x00; 0x00; initialize output (7-4) input (3-0) initialize output (7-4) input (3-0) file File RtcTask.c Description This file contains thread keypad display. Copyright 2004 ZiLOG Inc. RIGHTS RESERVED. source code this file written authorized ZiLOG employee licensed consultant. source code been verified fullest extent possible. Permission this code granted royalty-free basis. However users cautioned authenticate code contained herein. ZiLOG DOES GUARANTEE VERACITY SOFTWARE. standard header files #include <stdio.h> #include <string.h> #include "RtcTask.h" #include "LCD_API.h" header files #include "ZSysgen.h" #include "ZTypes.h" #include "ZThread.h" AN018801-0404 Appendix C-Source Code Application Note Application Using Real-Time Clock eZ80F91 extern function declarations extern void RZKFormatError(UINT num); extern RZK_STATUS_t RZKGetErrorNum(); extern RZK_THREADHANDLE_t g_hthd1; extern struct RTC_parm RTC_parm1; extern struct Country_Time Country[NO_OF_COUNTRYS]; extern unsigned char char *ststring,*sdstring,*sswstring; time, date pointer char *dtstring,*ddstring,*dswstring; display selected country time ptr, display selected country date char pointer reading from atring extern char secflg, swsecond, swminute, swhour; char setdefaultcountry=0; char default_set,DSTflg FALSE; LCD_clear_flg2=0; Thread entry function thread1 void LCDTask() LCD_clear_flg=0; LCD_clear(); LCD_setposition(0,0); LCD_prints(RTC_parm1.DispTime); LCD_setposition(1,0); LCD_prints(RTC_parm1.DispDate); while(1) Clear screen AN018801-0404 Appendix C-Source Code Application Note Application Using Real-Time Clock eZ80F91 dtstring RTC_parm1.DispTimeArry; ddstring RTC_parm1.DispDateArry; if(setmodeflg==TRUE) if(mode==SET_GMT_TIME) if(default_set TRUE) if(LCD_clear_flg==0) LCD_clear();// Clear screen LCD_setposition(0,0); LCD_setposition(1,0); String centralized 16x2 only LCD_clear_flg=1; else if(LCD_clear_flg==0) LCD_clear(); Clear screen LCD_setposition(0,0); LCD_prints("set Def-country"); LCD_setposition(1,0); LCD_prints("Press F"); LCD_clear_flg=1; if(mode==SET_GMT_DATE) if(default_set TRUE) if(LCD_clear_flg==0) LCD_clear(); Clear screen LCD_setposition(0,0); LCD_setposition(1,0); String centralized 16x2 only AN018801-0404 Appendix C-Source Code Application Note Application Using Real-Time Clock eZ80F91 LCD_clear_flg=1; else if(LCD_clear_flg==0) LCD_clear(); Clear screen LCD_setposition(0,0); LCD_prints("set Def-country"); LCD_setposition(1,0); LCD_prints("Press F"); LCD_clear_flg=1; if(mode==STOP_WATCH) if(LCD_clear_flg==0) LCD_clear(); Clear screen LCD_setposition(0,0); if(startswflg==TRUE) LCD_setposition(1,10); LCD_prints("RUN else LCD_setposition(1,10); LCD_prints("STOP"); LCD_setposition(1,0); String centralized 16x2 only LCD_clear_flg=1; if(mode==SELECT_COUNTRY) if(new_country_flg==TRUE) LCD_clear(); Clear screen LCD_setposition(0,0); AN018801-0404 Appendix C-Source Code Application Note Application Using Real-Time Clock eZ80F91 (char *)dtstring);// convert into ASCII store repository LCD_setposition(1,0); LCD_prints(RTC_parm1.DispTime); new_country_flg=FALSE; if(secflg==TRUE) LCD_setposition(0,0); (char *)dtstring); convert into ASCII store repository LCD_setposition(1,5); String centralized 16x2 only ving[0]==1)) LCD_setposition(1,14); LCD_prints("DS"); String centralized 16x2 only secflg=FALSE; LCD_clear_flg=1; if(mode==DEFAULT_COUNTRY_TIME) if(LCD_clear_flg2==0) LCD_clear(); Clear screen if(selconflg==TRUE) LCD_setposition(0,0); LCD_prints("Selection Done"); LCD_setposition(1,0); LCD_prints("For DST-press E"); LCD_clear_flg2=1; LCD_clear_flg=1; selconflg=FALSE; AN018801-0404 Appendix C-Source Code Application Note Application Using Real-Time Clock eZ80F91 else LCD_setposition(0,0); LCD_prints("Daylight-Saving"); LCD_setposition(1,0); LCD_prints("DayLight-"); LCD_setposition(1,10); if(DSTflg==TRUE) LCD_prints("YAS"); else LCD_prints("NO"); LCD_clear_flg2=1; LCD_clear_flg=1; selconflg=FALSE; else if(secflg==TRUE) if(LCD_clear_flg==1) LCD_clear(); Clear screen LCD_setposition(0,0); LCD_prints(RTC_parm1.DispTime); LCD_setposition(1,0); LCD_prints(RTC_parm1.DispDate); *)dtstring); //convert into ASCII store repository *)ddstring); //convert into ASCII store repository LCD_setposition(0,5); String centralized 16x2 only .DLSaving[0]==1)) LCD_setposition(0,14); LCD_prints("DS"); String centralized 16x2 only AN018801-0404 Appendix C-Source Code Application Note Application Using Real-Time Clock eZ80F91 LCD_setposition(1,5); String centralized 16x2 only secflg=FALSE; LCD_clear_flg=0; Thread entry function thread2 void KeyPadTask() while(1) RZK_STATUS_t status PB_DR ROW_1;//scane column keypadin (PB_DR 0x0F); if(ROW_1) if(keypadin==COL_1) PB_DR 0xFF; if(mode==SET_GMT_TIME) *(ststring ch_count) if(mode==SET_GMT_DATE) *(sdstring ch_count) keydelayms(NUM_KEY_DELAY); if(keypadin==COL_2) PB_DR 0xFF; if(mode==SET_GMT_TIME) *(ststring ch_count) if(mode==SET_GMT_DATE) *(sdstring ch_count) ch_count++; keydelayms(NUM_KEY_DELAY); if(keypadin==COL_3) '1'; '1'; '2'; '2'; AN018801-0404 Appendix C-Source Code Application Note Application Using Real-Time Clock eZ80F91 PB_DR 0xFF; if(mode==SET_GMT_TIME) *(ststring ch_count) '3'; if(mode==SET_GMT_DATE) *(sdstring ch_count) '3'; ch_count++; keydelayms(NUM_KEY_DELAY); if(keypadin==COL_4) PB_DR 0xFF; mode SELECT_COUNTRY;// mode date countrycount++; countrycount=0; selconflg TRUE; new_country_flg=TRUE; setmodeflg=TRUE; keydelayms(400); PB_DR ROW_2; keypadin (PB_DR 0x0F); scan column if(ROW_2) if(keypadin==COL_1) PB_DR 0xFF; if(mode==SET_GMT_TIME) *(ststring ch_count) '4'; if(mode==SET_GMT_DATE) *(sdstring ch_count) '4'; ch_count++; keydelayms(NUM_KEY_DELAY); if(keypadin==COL_2) PB_DR 0xFF; if(mode==SET_GMT_TIME) *(ststring ch_count) '5'; if(mode==SET_GMT_DATE) AN018801-0404 Appendix C-Source Code Application Note Application Using Real-Time Clock eZ80F91 *(sdstring ch_count) '5'; ch_count++; keydelayms(NUM_KEY_DELAY); if(keypadin==COL_3) PB_DR 0xFF; if(mode==SET_GMT_TIME) *(ststring ch_count) '6'; if(mode==SET_GMT_DATE) *(sdstring ch_count) '6'; ch_count++; keydelayms(NUM_KEY_DELAY); if(keypadin==COL_4) PB_DR 0xFF; if(mode==DEFAULT_COUNTRY_TIME) (DSTflg==TRUE) DSTflg FALSE; else DSTflg TRUE; mode DEFAULT_COUNTRY_TIME; setdefaultcountry countrycount; default_set TRUE; LCD_clear_flg2=0; setmodeflg=TRUE; keydelayms(400); PB_DR ROW_3; scan column keypadin (PB_DR 0x0F); if(ROW_3) if(keypadin==COL_1) PB_DR 0xFF; if(mode==SET_GMT_TIME) *(ststring ch_count) '7'; if(mode==SET_GMT_DATE) AN018801-0404 Appendix C-Source Code Application Note Application Using Real-Time Clock eZ80F91 *(sdstring ch_count) '7'; ch_count++; keydelayms(NUM_KEY_DELAY); if(keypadin==COL_2) PB_DR 0xFF; if(mode==SET_GMT_TIME) *(ststring ch_count) '8'; if(mode==SET_GMT_DATE) *(sdstring ch_count) '8'; ch_count++; keydelayms(NUM_KEY_DELAY); if(keypadin==COL_3) PB_DR 0xFF; if(mode==SET_GMT_TIME) *(ststring ch_count) '9'; if(mode==SET_GMT_DATE) *(sdstring ch_count) '9'; ch_count++; keydelayms(NUM_KEY_DELAY); if(keypadin==COL_4) PB_DR 0xFF; mode STOP_WATCH;// mode stop watch if(startswflg==TRUE) startswflg=FALSE; else startswflg=TRUE; setmodeflg=TRUE; keydelayms(250); PB_DR ROW_4; scan column keypadin (PB_DR 0x0F); if(ROW_4) if(keypadin==COL_1) AN018801-0404 Appendix C-Source Code Application Note Application Using Real-Time Clock eZ80F91 PB_DR 0xFF; mode SET_GMT_TIME;// mode setting ststring RTC_parm1.SetGMTTimeClock; setmodeflg=TRUE; keydelayms(100); if(keypadin==COL_2) PB_DR 0xFF; if(mode==SET_GMT_TIME) *(ststring ch_count) '0'; if(mode==SET_GMT_DATE) *(sdstring ch_count) '0'; ch_count++; keydelayms(NUM_KEY_DELAY); if(keypadin==COL_3) PB_DR 0xFF; mode SET_GMT_DATE;// mode date sdstring RTC_parm1.SetGMTDateClock; setmodeflg=TRUE; keydelayms(100); if(keypadin==COL_4) PB_DR 0xFF; ststring RTC_parm1.SetGMTTimeClock; sdstring RTC_parm1.SetGMTDateClock; if(mode==STOP_WATCH) if(ch_count>=7) if(mode==SET_GMT_TIME) AsciitoBCDSetTime(); AsciitoBCDGMT(); CalGMTTime(); ReInitRTCTime(); reinitialize if(mode==SET_GMT_DATE) AsciitoBCDSetDate(); ReInitRTCDate(); reinitialize AN018801-0404 Appendix C-Source Code Application Note Application Using Real-Time Clock eZ80F91 ch_count=0x00; swsecond=0x00; swminute=0x00; swhour=0x00; setmodeflg=FALSE; startswflg=FALSE; keydelayms(100); countrycount setdefaultcountry; mode ENTER; mode reinitialize with time if(ch_count ststring RTC_parm1.SetGMTTimeClock; setmodeflg=FALSE; mode 0x00; ch_count=0x00; if((ch_count 2)||(ch_count ch_count++; if(((mode SET_GMT_DATE)&&(secflg=TRUE))) if(ch_count<8) if(mode==SET_GMT_TIME) *(ststring ch_count) if(mode==SET_GMT_DATE) *(sdstring ch_count) keydelayms(50); if(mode==SET_GMT_TIME) *(ststring ch_count) '_'; if(mode==SET_GMT_DATE) *(sdstring ch_count) '_'; keydelayms(50); else keydelayms(50); AN018801-0404 Appendix C-Source Code Application Note Application Using Real-Time Clock eZ80F91 file File AuxFun.c Description This file contantes auxilary functions used world clock. Copyright 2004 ZiLOG Inc. RIGHTS RESERVED. source code this file written authorized ZiLOG employee licensed consultant. source code been verified fullest extent possible. Permission this code granted royalty-free basis. However users cautioned authenticate code contained herein. ZiLOG DOES GUARANTEE VERACITY SOFTWARE. standard header files #include <stdio.h> #include <string.h> #include "RtcTask.h" #include "LCD_API.h" header files #include "ZSysgen.h" #include "ZTypes.h" #include "ZThread.h" #include "ZTimer.h" AN018801-0404 Appendix C-Source Code Application Note Application Using Real-Time Clock eZ80F91 struct RTC_parm RTC_parm1; struct Country_Time Country[NO_OF_COUNTRYS]; char extern char *dtstring,*ddstring,*dwcstring; pointer writing into display string extern char *ststring,*sdstring,*sswstring; time, date pointer extern char //pointer reading from atring extern char char Hsettimecarry,Msettimecarry; unsigned char unsigned char GMTday,GMTmonth,GMTyear; unsigned char unsigned char NEWhour,NEWminute,NEWsecond; char dsplyhour, dsplyminute, dsplysec; char secflg, swsecond, swminute, swhour; char secflg=FALSE; char swsecond=0, swminute=0, swhour=0; unsigned volatile key_current_ms; Used keypad Initialize country name time void Init_Country(void) Local Time"); AN018801-0404 Appendix C-Source Code Application Note Application Using Real-Time Clock eZ80F91 Local Date"); Watch"); /********* initialize country name time difference from GMT*******/ Time"); Country[0].DLSaving[0]=0; daylight saving Delhi-India"); Country[1].DLSaving[0]=0; daylight saving Jose-USA"); hour Country[2].DLSaving[0]=1; daylight saving hour Country[3].DLSaving[0]=1; daylight saving York-USA"); hour Country[4].DLSaving[0]=1; daylight saving Time Country[5].DLSaving[0]=1; daylight saving Country[6].DLSaving[0]=1; daylight saving Country[7].DLSaving[0]=0; daylight saving hour Country[8].DLSaving[0]=1; daylight saving AN018801-0404 Appendix C-Source Code Application Note Application Using Real-Time Clock eZ80F91 Country[9].DLSaving[0]=0; daylight saving Country[10].DLSaving[0]=1; daylight saving Country[11].DLSaving[0]=0; daylight saving Country[12].DLSaving[0]=0; daylight saving Kong-China"); Country[13].DLSaving[0]=0; daylight saving Country[14].DLSaving[0]=0; daylight saving Country[15].DLSaving[0]=0; daylight saving convert binary data into ASCII data void bin_to_ascii1(unsigned char c,unsigned char d,unsigned char char *buff) unsigned charh,k; read hour binary ASCII conversion*/ for(h 100;c 100,h++); for(k 10;c 10,k++); *(buff+1) ('0'+(c 0x0f)); *(buff+0) 0x0f) '0'); read minute binary ASCII conversion*/ for(h 100;d 100,h++); AN018801-0404 Appendix C-Source Code Application Note Application Using Real-Time Clock eZ80F91 for(k 10;d 10,k++); *(buff+4) ('0'+(d 0x0f)); *(buff+3) 0x0f) '0'); read second binary ASCII conversion*/ for(h 100;e 100,h++); for(k 10;e 10,k++); *(buff+7) ('0'+(e 0x0f)); *(buff+6) 0x0f) '0'); time with country defference from time void AddTime(void) char tempsumHN,tempsum; NEWsecond RTCsecond GMTsecond; NEWminute RTCminute GMTminute; if(NEWminute>=60) NEWminute (NEWminute 60); GMThour GMThour+1; NEWhour (RTChour GMThour); if(NEWhour>=24) NEWhour (NEWhour 24); if(DSTflg==TRUE) NEWhour NEWhour calculate time from country local time void CalGMTTime(void) RTCGMTsecond SetGMTsecond; if(SetGMTminute<GMTminute) AN018801-0404 Appendix C-Source Code Application Note Application Using Real-Time Clock eZ80F91 SetGMTminute SetGMTminute SetGMThour SetGMThour RTCGMTminute SetGMTminute GMTminute; if(SetGMThour<GMThour) SetGMThour SetGMThour RTCGMThour SetGMThour GMThour; if(DSTflg==TRUE) RTCGMThour RTCGMThour delay function void keydelayms (unsigned milliseconds) key_current_ms TMR3_CTL 0x01; while (key_current_ms milliseconds) Delay loop TMR3_CTL 0xFE; Stop delayms convert ASCII data into data void AsciitoBCDSetTime(void) char if(mode==STOP_WATCH) SetGmtTstring RTC_parm1.SetStopWatch; SetGmtTstring RTC_parm1.SetGMTTimeClock; temphour *SetGmtTstring++; temphour (temphour-0x30) temphour (temphour <<4); hour temphour; temphour *SetGmtTstring++; AN018801-0404 Appendix C-Source Code Application Note Application Using Real-Time Clock eZ80F91 temphour (temphour-0x30)& 0x0F; SetGMThour (hour temphour); SetGMThour TimeCont(SetGMThour); SetGmtTstring++; tempminute *SetGmtTstring++; tempminute (tempminute 0x30); tempminute (tempminute minute tempminute; tempminute *SetGmtTstring++; tempminute (tempminute 0x30) 0x0F; SetGMTminute (minute tempminute); SetGMTminute TimeCont(SetGMTminute); SetGmtTstring++; tempsec *SetGmtTstring++; tempsec (tempsec 0x30); tempsec (tempsec tempsec; tempsec *SetGmtTstring++; tempsec (tempsec 0x30) 0x0F; SetGMTsecond (sec tempsec); SetGMTsecond TimeCont(SetGMTsecond); Convert ASCII data into data void AsciitoBCDGMT(void) char GmtTstring temphour *GmtTstring++; temphour (temphour-0x30) temphour (temphour <<4); hour temphour; temphour *GmtTstring++; temphour (temphour-0x30)& 0x0F; GMThour (hour temphour); GMThour TimeCont(GMThour); AN018801-0404 Appendix C-Source Code Application Note Application Using Real-Time Clock eZ80F91 GmtTstring++; tempminute *GmtTstring++; tempminute (tempminute 0x30); tempminute (tempminute minute tempminute; tempminute *GmtTstring++; tempminute (tempminute 0x30) 0x0F; GMTminute (minute tempminute); GMTminute TimeCont(GMTminute); GmtTstring++; tempsec *GmtTstring++; tempsec (tempsec 0x30); tempsec (tempsec tempsec; tempsec *GmtTstring++; tempsec (tempsec 0x30) 0x0F; GMTsecond (sec tempsec); GMTsecond TimeCont(GMTsecond); Convert ASCII data into data void AsciitoBCDSetDate(void) GmtDstring RTC_parm1.SetGMTDateClock; tempmonth *GmtDstring++; tempmonth (tempmonth 0x30); tempmonth (tempmonth month tempmonth; tempmonth *GmtDstring++; tempmonth (tempmonth 0x30) 0x0F; GMTmonth (month tempmonth); GMTmonth TimeCont(GMTmonth); GmtDstring++; tempday *GmtDstring++; tempday (tempday-0x30) tempday (tempday <<4); AN018801-0404 Appendix C-Source Code Application Note Application Using Real-Time Clock eZ80F91 tempday; tempday *GmtDstring++; tempday (tempday-0x30)& 0x0F; GMTday (day tempday); GMTday TimeCont(GMTday); GmtDstring++; tempyear *GmtDstring++; tempyear (tempyear 0x30); tempyear (tempyear year tempyear; tempyear *GmtDstring++; tempyear (tempyear 0x30) 0x0F; GMTyear (year tempyear); GMTyear TimeCont(GMTyear); Function used ASCII conversion unsigned TimeCont(unsigned input) if((input 0x0A)&&(input 0x1F)) input input if((input 0x20)&&(input 0x2A)) input input if((input 0x2A)&&(input 0x3F)) input input if((input 0x40)&&(input 0x4A)) input input if((input 0x4A)&&(input 0x5F)) input input return input; timer1 void SWTimer1(void) extern char *dtstring, *ddstring, *swstring; AN018801-0404 Appendix C-Source Code Application Note Application Using Real-Time Clock eZ80F91 sswstring RTC_parm1.SetStopWatch; *dtstring 0xDF; *ddstring 0xEF; RTCsecond RTC_SEC; RTCminute RTC_MIN; RTChour RTC_HRS; RTCday RTC_DOM; RTCmonth RTC_MON; RTCcent RTC_CEN; RTCyear RTC_YR; AsciitoBCDGMT(); AddTime(); if(NEWhour<RTChour) RTCday=RTCday if(setmodeflg==TRUE) swsecond++; if(swsecond==60) swminute++; swsecond=0; if(swminute==60) swhour++; swminute=0; if(swhour==24) swhour=0; *)sswstring); convert into ASCII store repository secflg=TRUE; Read data AN018801-0404 Appendix C-Source Code Application Note Application Using Real-Time Clock eZ80F91 delay timer3 #pragma interrupt void isr_timer3(void) dummyread; dummyread TMR3_IIR; key_current_ms++ Read register obligatory Increment count file Files following header files listed this section: RtcTask.h File RtcTask.h Description Copyright 2004 ZiLOG Inc. RIGHTS RESERVED. source code this file written authorized ZiLOG employee licensed consultant. source code been verified fullest extent possible. Permission this code granted royalty-free basis. However users cautioned authenticate code contained herein. ZiLOG DOES GUARANTEE VERACITY SOFTWARE. definitions AN018801-0404 Appendix C-Source Code Application Note Application Using Real-Time Clock eZ80F91 #define #define #define #define #define TRUE FALSE TIMER2_INTRID TIMER3_INTRID 0xEF 0xDF 0xBF 0x7F 0x07 0x0B 0x0D 0x0E total country default country "GMT Time" #define INITIAL_DELAY #define TIMEOUT_PERIOD #define NUM_KEY_DELAY #define #define #define #define #define #define #define #define #define #define #define #define #define #define SET_GMT_TIME SET_GMT_DATE STOP_WATCH SELECT_COUNTRY DEFAULT_COUNTRY_TIME ENTER ROW_1 ROW_2 ROW_3 ROW_4 COL_1 COL_2 COL_3 COL_4 #define HOUR #define MINUTE #define SECOND #define NO_OF_COUNTRYS #define DEFAULT_COUNTRY prototype function declarations void InitRTC(void); void InitKeypad(void); interface void LCDTask(); void KeyPadTask(); Init Real Time Clock Init port keypad AN018801-0404 Appendix C-Source Code Application Note Application Using Real-Time Clock eZ80F91 void Init_Country(void); void AsciitoBCDGMT(void); void AsciitoBCDSetTime(void); void AsciitoBCDSetDate(void); void ReInitRTCTime(void); void ReInitRTCDate(void); void CalGMTTime(void); unsigned TimeCont(unsigned input); void bin_to_ascii1(unsigned char, unsigned char, unsigned char, char*); void SWTimer1(void); void AddTime(void); void init_timer3(void); void keydelayms(unsigned milliseconds); void isr_timer3(void); structure used data repository struct Country_Time char CountryName[20]; char GMTTimeDeff[10]; char DLSaving[1]; struct RTC_parm char DispTimeArry[10]; char DispTime[5]; char DispDateArry[10]; char DispDate[5]; char char char char char char file SetGMTTimeClock[10]; SetGMTTime[15]; SetGMTDateClock[10]; SetGMTDate[15]; SetStopWatch[10]; StopWatch[15]; AN018801-0404 Appendix C-Source Code Other recent searchesUC33063A - UC33063A UC33063A Datasheet TRSL-5120G - TRSL-5120G TRSL-5120G Datasheet TJA1040 - TJA1040 TJA1040 Datasheet ISO11898 - ISO11898 ISO11898 Datasheet TJA1041 - TJA1041 TJA1041 Datasheet TJA1050 - TJA1050 TJA1050 Datasheet SLLS912 - SLLS912 SLLS912 Datasheet QB-78K0KX1H - QB-78K0KX1H QB-78K0KX1H Datasheet PTH12000 - PTH12000 PTH12000 Datasheet M11271ENG - M11271ENG M11271ENG Datasheet HCS-125 - HCS-125 HCS-125 Datasheet AON7430 - AON7430 AON7430 Datasheet
Privacy Policy | Disclaimer |