SAM3S8/SD8 Software Package: examples/rtc_wave/main.c Source File

SAM3S8/SD8 Software Package 1.2

# main.c

Go to the documentation of this file.

    00001 /* ----------------------------------------------------------------------------
    00002  *         ATMEL Microcontroller Software Support
    00003  * ----------------------------------------------------------------------------
    00004  * Copyright (c) 2011, Atmel Corporation
    00005  *
    00006  * All rights reserved.
    00007  *
    00008  * Redistribution and use in source and binary forms, with or without
    00009  * modification, are permitted provided that the following conditions are met:
    00010  *
    00011  * - Redistributions of source code must retain the above copyright notice,
    00012  * this list of conditions and the disclaimer below.
    00013  *
    00014  * Atmel's name may not be used to endorse or promote products derived from
    00015  * this software without specific prior written permission.
    00016  *
    00017  * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
    00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
    00019  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
    00020  * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
    00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    00022  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
    00023  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
    00024  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
    00025  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
    00026  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    00027  * ----------------------------------------------------------------------------
    00028  */
    00029
    00030 /**
    00031  * \page rtc_wave RTC WAVE Example
    00032  *
    00033  * \section Purpose
    00034  *
    00035  * This basic example shows how to use the Real-Time Clock (RTC) peripheral
    00036  * available on the newest Atmel AT91 microcontrollers. The RTC enables easy
    00037  * time and date management and allows the user to monitor events like a
    00038  * configurable alarm, second change, calendar change, and generating waveform.
    00039  *
    00040  * \section Requirements
    00041  *
    00042  * This package can be used with SAM3S-EK2. We use RTCOUT1  to drive
    00043  * led, so please connect PB1(RTCOUT1) to PA19(Blue Led) before running example.
    00044  *
    00045  * \section Description
    00046  *
    00047  * Upon startup, the program displays the currently set time and date
    00048  * and a menu to perform the following:
    00049  *     \code
    00050  *     Menu:
    00051  *        t - Set time
    00052  *        d - Set date
    00053  *        i - Set time alarm
    00054  *        m - Set date alarm
    00055  *        c - Clear the alarm notification (only if it has been triggered)
    00056  *        w - Generate Waveform
    00057  *     \endcode
    00058  *
    00059  * Setting the time, date and time alarm is done by using Menu option "t", "d",
    00060  * the display is updated accordingly.
    00061  *
    00062  * The time alarm is triggered only when the second, minute and hour match the preset
    00063  * values; the date alarm is triggered only when the month and date match the preset
    00064  * values. If both time alarm and date alarm are set, only when the second, minute,
    00065  * hour, month and date match the preset values, the alarm will be triggered.
    00066  *
    00067  * Generating waveform is done by using Menu option "w" and a menu to peform the following:
    00068  *     \code
    00069  *     Menu:
    00070  *     0 - No Waveform
    00071  *     1 - 1 Hz square wave
    00072  *     2 - 32 Hz square wave
    00073  *     3 - 64 Hz square wave
    00074  *     4 - 512 Hz square wave
    00075  *     5 - Toggles when alarm flag rise
    00076  *     6 - Copy of the alarm flag
    00077  *     7 - Duty cycle programmable pulse
    00078  *     8 - Enter Backup mode
    00079  *     9 - Quit
    00080  *     \endcode
    00081  * Going into backup or low power operating modes does not affect the waveform
    00082  * generation outputs.
    00083  *
    00084  * \section Usage
    00085  *
    00086  * -# Build the program and download it inside the evaluation board. Please
    00087  *    refer to the
    00088  *    <a href="http://www.atmel.com/dyn/resources/prod_documents/6421B.pdf">
    00089  *    SAM-BA User Guide</a>, the
    00090  *    <a href="http://www.atmel.com/dyn/resources/prod_documents/doc6310.pdf">
    00091  *    GNU-Based Software Development</a> application note or to the
    00092  *    <a href="http://www.iar.com/website1/1.0.1.0/78/1/">
    00093  *    IAR EWARM User and reference guides</a>, depending on your chosen solution.
    00094  * -# On the computer, open and configure a terminal application
    00095  *    (e.g. HyperTerminal on Microsoft Windows) with these settings:
    00096  *   - 115200 bauds
    00097  *   - 8 bits of data
    00098  *   - No parity
    00099  *   - 1 stop bit
    00100  *   - No flow control
    00101  * -# Start the application.
    00102  * -# In the terminal window, the following text should appear:
    00103  *    \code
    00104  *     -- RTC Example xxx --
    00105  *     -- xxxxxx-xx
    00106  *     -- Compiled: xxx xx xxxx xx:xx:xx --
    00107  *
    00108  *     Menu:
    00109  *     t - Set time
    00110  *     d - Set date
    00111  *     i - Set time alarm
    00112  *     m - Set date alarm
    00113  *     w - Generate Waveform
    00114  *     q - Quit
    00115  *    \endcode
    00116  * -# Press one of the keys listed in the menu to perform the corresponding action.
    00117  *
    00118  * \section References
    00119  * - rtc_wave/main.c
    00120  * - rtc.c
    00121  * - rtc.h
    00122  */
    00123
    00124 /**
    00125  * \file
    00126  *
    00127  * This file contains all the specific code for the rtc example.
    00128  */
    00129
    00130 /*----------------------------------------------------------------------------
    00131  *        Headers
    00132  *----------------------------------------------------------------------------*/
    00133
    00134 #include "board.h"
    00135
    00136 #include <stdint.h>
    00137 #include <stdio.h>
    00138 #include <stdarg.h>
    00139
    00140 /*----------------------------------------------------------------------------
    00141  *        Local definitions
    00142  *----------------------------------------------------------------------------*/
    00143
    00144 /** Main menu is being displayed. */
    00145 #define STATE_MENU              0
    00146 /** Time is being edited. */
    00147 #define STATE_SET_TIME          1
    00148 /** Date is being edited. */
    00149 #define STATE_SET_DATE          2
    00150 /** Time alarm is being edited. */
    00151 #define STATE_SET_TIME_ALARM    3
    00152 /** Date alarm is being edited. */
    00153 #define STATE_SET_DATE_ALARM    4
    00154 /** Wave generating is being edited. */
    00155 #define STATE_WAVEFORM            5
    00156
    00157 /** Maximum size of edited string */
    00158 #define MAX_EDIT_SIZE       10
    00159
    00160 /** Macro for check digit character */
    00161 #define IsDigitChar(c) ((c) >= '0' && (c) <='9')
    00162 /** Macro for converting char to digit */
    00163 #define CharToDigit(c) ((c) - '0')
    00164 /** (SCR) Sleep deep bit */
    00165 #define SCR_SLEEPDEEP   (0x1 <<  2)
    00166 /*----------------------------------------------------------------------------
    00167  *        Local variables
    00168  *----------------------------------------------------------------------------*/
    00169
    00170 /** Current state of application. */
    00171 static unsigned int bState = STATE_MENU;
    00172
    00173 /** Edited hour. */
    00174 static unsigned char newHour;
    00175 /** Edited minute. */
    00176 static unsigned char newMinute;
    00177 /** Edited second. */
    00178 static unsigned char newSecond;
    00179
    00180 /** Edited year. */
    00181 static unsigned short newYear;
    00182 /** Edited month. */
    00183 static unsigned char newMonth;
    00184 /** Edited day. */
    00185 static unsigned char newDay;
    00186 /** Edited day-of-the-week. */
    00187 static unsigned char newWeek;
    00188
    00189 /** Indicates if alarm has been trigerred and not yet cleared. */
    00190 static unsigned char alarmTriggered = 0;
    00191
    00192 /** store time string */
    00193 static char rtc_time[8+1] = {'0', '0', ':', '0', '0', ':', '0', '0','\0'};
    00194 /** store date string */
    00195 static char date[10+1] = {'0', '0', '/', '0', '0', '/', '0', '0', '0', '0', '\0'};
    00196 /** week string */
    00197 static char pDayNames[7][4] = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};
    00198 /** console erase sequence */
    00199 static char pEraseSeq[] = "\b \b";
    00200 /** output format string buffer */
    00201 static char calendar[80];
    00202 /** for idendify refreshing menu */
    00203 static unsigned int bMenuShown = 0;
    00204
    00205 /*----------------------------------------------------------------------------
    00206  *        Local functions
    00207  *----------------------------------------------------------------------------*/
    00208
    00209 /**
    00210  * \brief Display a string on the terminal.
    00211  */
    00212 static inline void UART_puts( const char *pStr )
    00213 {
    00214     while ( *pStr )
    00215     {
    00216         UART_PutChar(*pStr++ ) ;
    00217     }
    00218 }
    00219
    00220 /**
    00221  * \brief Print a formatted string into a buffer.
    00222  */
    00223 static signed int _PrnToBuf( char *pBuf, const char *pFormat, ... )
    00224 {
    00225     va_list    ap ;
    00226     signed int rc ;
    00227
    00228     va_start( ap, pFormat ) ;
    00229     rc = vsprintf( pBuf, pFormat, ap ) ;
    00230     va_end( ap ) ;
    00231
    00232     return rc ;
    00233 }
    00234
    00235 /**
    00236  * \brief Get new time, successful value is put in newHour, newMinute, newSecond.
    00237  */
    00238 static int _GetNewTime( void )
    00239 {
    00240     char ucKey ;
    00241     int i=0 ;
    00242
    00243     /* clear setting variable */
    00244     newHour = newMinute = newSecond = 0xFF;
    00245
    00246     /* use time[] as a format template */
    00247     while ( 1 )
    00248     {
    00249         ucKey = UART_GetChar();
    00250
    00251         /* end input */
    00252         if ( ucKey == 0x0d || ucKey == 0x0a )
    00253         {
    00254             UART_puts("\n\r");
    00255             break;
    00256         }
    00257
    00258         /* DEL or BACKSPACE */
    00259         if ( ucKey == 0x7f || ucKey == 0x08 )
    00260         {
    00261             if ( i > 0 )
    00262             {
    00263                 /* end of time[], index then one more back */
    00264                 if ( !rtc_time[i] )
    00265                 {
    00266                     --i ;
    00267                 }
    00268
    00269                 UART_puts( pEraseSeq ) ;
    00270                 --i ;
    00271
    00272                 /* delimitor ':' for time is uneditable */
    00273                 if ( !IsDigitChar( rtc_time[i] ) && i > 0 )
    00274                 {
    00275                     UART_puts( pEraseSeq ) ;
    00276                     --i ;
    00277                 }
    00278             }
    00279         }
    00280
    00281         /* end of time[], no more input except above DEL/BS or enter to end */
    00282         if ( !rtc_time[i] )
    00283         {
    00284             continue ;
    00285         }
    00286
    00287         if ( !IsDigitChar( ucKey ) )
    00288         {
    00289             continue ;
    00290         }
    00291
    00292         UART_PutChar( ucKey ) ;
    00293         rtc_time[i++] = ucKey ;
    00294
    00295         /* ignore non digit position if not end */
    00296         if ( !IsDigitChar( rtc_time[i] ) && i < 8 )
    00297         {
    00298             UART_PutChar( rtc_time[i] ) ;
    00299             ++i ;
    00300         }
    00301     }
    00302
    00303     if ( i == 0 )
    00304     {
    00305         return 0 ;
    00306     }
    00307
    00308     if ( i != 0 && rtc_time[i] != '\0' )
    00309     {
    00310         return 1 ; /* failure input */
    00311     }
    00312
    00313     newHour = CharToDigit( rtc_time[0] ) * 10 + CharToDigit( rtc_time[1] ) ;
    00314     newMinute = CharToDigit( rtc_time[3] ) * 10 + CharToDigit( rtc_time[4] ) ;
    00315     newSecond = CharToDigit( rtc_time[6] ) * 10 + CharToDigit( rtc_time[7] ) ;
    00316
    00317     /* success input. verification of data is left to RTC internal Error Checking */
    00318     return 0 ;
    00319 }
    00320
    00321 /**
    00322  * \brief Calculate week from year, month,day.
    00323  */
    00324 static char _CalcWeek( int year, int month, int day )
    00325 {
    00326     char week ;
    00327
    00328     if ( month == 1 || month == 2 )
    00329     {
    00330         month += 12 ;
    00331         --year ;
    00332     }
    00333
    00334     week = (day+2*month+3*(month+1)/5+year+year/4-year/100+year/400)%7;
    00335
    00336     ++week ;
    00337
    00338     return week ;
    00339 }
    00340
    00341 /**
    00342  * \brief Get new time, successful value is put in newYear, newMonth, newDay, newWeek.
    00343  */
    00344 static int _GetNewDate( void )
    00345 {
    00346     char ucKey ;
    00347     int i=0;
    00348
    00349     /* clear setting variable */
    00350     newYear = 0xFFFF;
    00351     newMonth = newDay= newWeek = 0xFF;
    00352
    00353     /* use time[] as a format template */
    00354     while ( 1 )
    00355     {
    00356         ucKey = UART_GetChar() ;
    00357
    00358         /* end input */
    00359         if ( ucKey == 0x0d || ucKey == 0x0a )
    00360         {
    00361             UART_puts( "\n\r" ) ;
    00362             break ;
    00363         }
    00364
    00365         /* DEL or BACKSPACE */
    00366         if ( ucKey == 0x7f || ucKey == 0x08 )
    00367         {
    00368             if ( i > 0 )
    00369             {
    00370                 /* end of date[], index then one more back */
    00371                 if ( !date[i] )
    00372                 {
    00373                     --i ;
    00374                 }
    00375
    00376                 UART_puts( pEraseSeq ) ;
    00377                 --i ;
    00378
    00379                 /* delimitor '/' for date is uneditable */
    00380                 if ( !IsDigitChar( date[i] ) && i > 0 )
    00381                 {
    00382                     UART_puts( pEraseSeq ) ;
    00383                     --i ;
    00384                 }
    00385             }
    00386         }
    00387
    00388         /* end of time[], no more input except above DEL/BS or enter to end */
    00389         if ( !date[i] )
    00390         {
    00391             continue ;
    00392         }
    00393
    00394         if ( !IsDigitChar( ucKey ) )
    00395         {
    00396             continue;
    00397         }
    00398
    00399         UART_PutChar( ucKey ) ;
    00400         date[i++] = ucKey ;
    00401
    00402         /* ignore non digit position */
    00403         if ( !IsDigitChar( date[i] ) && i < 10 )
    00404         {
    00405             UART_PutChar( date[i] ) ;
    00406             ++i ;
    00407         }
    00408     }
    00409
    00410     if ( i == 0 )
    00411     {
    00412         return 0 ;
    00413     }
    00414
    00415     if ( i != 0 && date[i] != '\0' && i != 6 )
    00416     {
    00417         return 1 ; /* failure input */
    00418     }
    00419
    00420     /* MM-DD-YY */
    00421     newMonth = CharToDigit( date[0] ) * 10 + CharToDigit( date[1] ) ;
    00422     newDay = CharToDigit( date[3] ) * 10 + CharToDigit( date[4] ) ;
    00423     if ( i != 6 )
    00424     {/* not scenario of getting mm/dd/ only for alarm */
    00425         newYear = CharToDigit(date[6]) * 1000 + CharToDigit(date[7]) * 100 +
    00426                   CharToDigit(date[8]) * 10 + CharToDigit(date[9] ) ;
    00427         newWeek = _CalcWeek( newYear, newMonth, newDay ) ;
    00428     }
    00429
    00430     /* success input. verification of data is left to RTC internal Error Checking */
    00431     return 0 ;
    00432 }
    00433
    00434
    00435 /**
    00436  * \brief Displays the user interface on the terminal.
    00437  */
    00438 static void _RefreshDisplay( void )
    00439 {
    00440
    00441     unsigned char hour, minute, second ;
    00442     unsigned short year ;
    00443     unsigned char month, day, week ;
    00444
    00445     if ( bState != STATE_MENU )
    00446     { /* not in menu display mode, in set mode */
    00447     }
    00448     else
    00449     {
    00450         /* Retrieve date and time */
    00451         RTC_GetTime( RTC, &hour, &minute, &second ) ;
    00452         RTC_GetDate( RTC, &year, &month, &day, &week ) ;
    00453
    00454         /* display */
    00455         if ( !bMenuShown )
    00456         {
    00457             printf( "\n\rMenu:\n\r" ) ;
    00458             printf( "  t - Set time\n\r" ) ;
    00459             printf( "  d - Set date\n\r" ) ;
    00460             printf( "  i - Set time alarm\n\r" ) ;
    00461             printf( "  m - Set date alarm\n\r" ) ;
    00462             printf( "  w - Generate Waveform\n\r" ) ;
    00463
    00464             if ( alarmTriggered )
    00465             {
    00466                 printf( "  c - Clear alarm notification\n\r" ) ;
    00467             }
    00468
    00469             printf( "  q - Quit!\n\r" ) ;
    00470
    00471             printf( "\n\r" ) ;
    00472
    00473             bMenuShown = 1 ;
    00474         }
    00475
    00476         /* update current date and time */
    00477         _PrnToBuf( rtc_time, "%02d:%02d:%02d", hour, minute, second ) ;
    00478         _PrnToBuf( date, "%02d/%02d/%04d", month, day, year ) ;
    00479         _PrnToBuf( calendar, " [Time/Date: %s, %s %s ][Alarm status:%s]", rtc_time, date, pDayNames[week-1], alarmTriggered?"Triggered!":"" ) ;
    00480
    00481         printf( "\r%s", calendar ) ;
    00482     }
    00483 }
    00484
    00485 /**
    00486  * \brief Interrupt handler for the RTC. Refreshes the display.
    00487  */
    00488 void RTC_IrqHandler( void )
    00489 {
    00490     uint32_t dwStatus = RTC->RTC_SR ;
    00491
    00492     /* Second increment interrupt */
    00493     if ( (dwStatus & RTC_SR_SEC) == RTC_SR_SEC )
    00494     {
    00495         /* Disable RTC interrupt */
    00496         RTC_DisableIt( RTC, RTC_IDR_SECDIS ) ;
    00497
    00498         _RefreshDisplay() ;
    00499
    00500         RTC->RTC_SCCR = RTC_SCCR_SECCLR ;
    00501
    00502         RTC_EnableIt( RTC, RTC_IER_SECEN ) ;
    00503     }
    00504     /* Time or date alarm */
    00505     else
    00506     {
    00507         if ( (dwStatus & RTC_SR_ALARM) == RTC_SR_ALARM )
    00508         {
    00509             /* Disable RTC interrupt */
    00510             RTC_DisableIt( RTC, RTC_IDR_ALRDIS ) ;
    00511
    00512             alarmTriggered = 1 ;
    00513             _RefreshDisplay() ;
    00514             bMenuShown = 0 ; /* shown additional menu item for clear notification */
    00515             RTC->RTC_SCCR = RTC_SCCR_ALRCLR ;
    00516
    00517             RTC_EnableIt( RTC, RTC_IER_ALREN ) ;
    00518         }
    00519     }
    00520 }
    00521 /**
    00522  * \brief Enter Backup Mode.
    00523  * Enter condition: WFE + (SLEEPDEEP bit = 1)
    00524  */
    00525 static void _EnterBackupMode( void )
    00526 {
    00527     SCB->SCR |= SCR_SLEEPDEEP ;
    00528     __WFE() ;
    00529 }
    00530 /*----------------------------------------------------------------------------
    00531  *         Global functions
    00532  *----------------------------------------------------------------------------*/
    00533
    00534 /**
    00535  * \brief Application entry point for RTC example.
    00536  *
    00537  * \return Unused (ANSI-C compatibility).
    00538  */
    00539
    00540 extern int main( void )
    00541 {
    00542     uint8_t ucKey ;
    00543
    00544     /* Disable watchdog */
    00545     WDT_Disable( WDT ) ;
    00546
    00547     /* Output example information */
    00548     printf( "\n\r\n\r\n\r" ) ;
    00549     printf( "-- RTC Example %s --\n\r", SOFTPACK_VERSION ) ;
    00550     printf( "-- %s\n\r", BOARD_NAME ) ;
    00551     printf( "-- Compiled: %s %s --\n\r", __DATE__, __TIME__ ) ;
    00552
    00553     /* Select external 32K crystal to have better clock accuracy */
    00554     SUPC_SelectExtCrystal32K();
    00555
    00556     /* Default RTC configuration */
    00557     RTC_SetHourMode( RTC, 0 ) ; /* 24-hour mode */
    00558     if ( RTC_SetTimeAlarm( RTC, 0, 0, 0 ) )
    00559     {
    00560         printf( "\n\r Disable time alarm fail!" ) ;
    00561     }
    00562
    00563     if ( RTC_SetDateAlarm( RTC, 0, 0 ) )
    00564     {
    00565         printf( "\n\r Disable date alarm fail!" ) ;
    00566     }
    00567
    00568     /* Configure RTC interrupts */
    00569     NVIC_DisableIRQ( RTC_IRQn ) ;
    00570     NVIC_ClearPendingIRQ( RTC_IRQn ) ;
    00571     NVIC_SetPriority( RTC_IRQn, 0 ) ;
    00572     NVIC_EnableIRQ( RTC_IRQn ) ;
    00573     RTC_EnableIt( RTC, RTC_IER_SECEN | RTC_IER_ALREN ) ;
    00574
    00575     /* Refresh display once */
    00576     _RefreshDisplay() ;
    00577
    00578     /* Handle keypresses */
    00579     while ( 1 )
    00580     {
    00581         ucKey = UART_GetChar() ;
    00582
    00583         /* set time */
    00584         if ( ucKey == 't' )
    00585         {
    00586             bState = STATE_SET_TIME;
    00587
    00588             do
    00589             {
    00590                 printf( "\n\r\n\r Set time(hh:mm:ss): " ) ;
    00591             } while( _GetNewTime() ) ;
    00592
    00593             /* if valid input, none of variable for time is 0xff */
    00594             if ( newHour != 0xFF )
    00595             {
    00596                 if ( RTC_SetTime( RTC, newHour, newMinute, newSecond ) )
    00597                 {
    00598                     printf( "\n\r Time not set, invalid input!\n\r" ) ;
    00599                 }
    00600             }
    00601
    00602             bState = STATE_MENU ;
    00603             bMenuShown = 0 ;
    00604             _RefreshDisplay() ;
    00605         }
    00606
    00607
    00608         /* set date */
    00609         if ( ucKey == 'd' )
    00610         {
    00611             bState = STATE_SET_DATE ;
    00612
    00613             do
    00614             {
    00615                 printf( "\n\r\n\r Set date(mm/dd/yyyy): " ) ;
    00616             } while ( _GetNewDate() ) ;
    00617
    00618             /* if valid input, none of variable for date is 0xff(ff) */
    00619             if ( newYear !=0xFFFF )
    00620             {
    00621                 if ( RTC_SetDate( RTC, newYear, newMonth, newDay, newWeek ) )
    00622                 {
    00623                     printf( "\n\r Date not set, invalid input!\n\r" ) ;
    00624                 }
    00625             }
    00626
    00627             /* only 'mm/dd' inputed */
    00628             if ( newMonth != 0xFF && newYear == 0xFFFF )
    00629             {
    00630                 printf( "\n\r Not Set for no year field!\n\r" ) ;
    00631             }
    00632
    00633             bState = STATE_MENU ;
    00634             bMenuShown = 0 ;
    00635             _RefreshDisplay() ;
    00636         }
    00637
    00638
    00639         /* set time alarm */
    00640         if ( ucKey == 'i')
    00641         {
    00642             bState = STATE_SET_TIME_ALARM ;
    00643
    00644             do
    00645             {
    00646                 printf( "\n\r\n\r Set time alarm(hh:mm:ss): " ) ;
    00647             } while ( _GetNewTime() ) ;
    00648
    00649             if ( newHour != 0xFF )
    00650             {
    00651                 if ( RTC_SetTimeAlarm( RTC, &newHour, &newMinute, &newSecond ) )
    00652                 {
    00653                     printf( "\n\r Time alarm not set, invalid input!\n\r" ) ;
    00654                 }
    00655                 else
    00656                 {
    00657                     printf( "\n\r Time alarm is set at %02d:%02d:%02d!", newHour, newMinute, newSecond ) ;
    00658                 }
    00659             }
    00660             bState = STATE_MENU ;
    00661             bMenuShown = 0 ;
    00662             alarmTriggered = 0 ;
    00663             _RefreshDisplay() ;
    00664         }
    00665
    00666         /* set date alarm */
    00667         if ( ucKey == 'm' )
    00668         {
    00669             bState = STATE_SET_DATE_ALARM;
    00670
    00671             do
    00672             {
    00673                 printf( "\n\r\n\r Set date alarm(mm/dd/): " ) ;
    00674             } while ( _GetNewDate() ) ;
    00675
    00676             if ( newYear == 0xFFFF && newMonth != 0xFF )
    00677             {
    00678                 if ( RTC_SetDateAlarm( RTC, &newMonth, &newDay ) )
    00679                 {
    00680                     printf( "\n\r Date alarm not set, invalid input!\n\r" ) ;
    00681                 }
    00682                 else
    00683                 {
    00684                     printf( "\n\r Date alarm is set on %02d/%02d!", newMonth, newDay ) ;
    00685                 }
    00686
    00687             }
    00688             bState = STATE_MENU ;
    00689             bMenuShown = 0 ;
    00690             alarmTriggered = 0 ;
    00691             _RefreshDisplay() ;
    00692         }
    00693         /* Generate Waveform */
    00694         if ( ucKey == 'w' )
    00695         {
    00696             bState = STATE_WAVEFORM;
    00697             printf( "\n\rMenu:\n\r" ) ;
    00698             printf( "  0 - No Waveform\n\r" ) ;
    00699             printf( "  1 - 1 Hz square wave\n\r" ) ;
    00700             printf( "  2 - 32 Hz square wave\n\r" ) ;
    00701             printf( "  3 - 64 Hz square wave\n\r" ) ;
    00702             printf( "  4 - 512 Hz square wave\n\r" ) ;
    00703             printf( "  5 - Toggles when alarm flag rise\n\r" );
    00704             printf( "  6 - Copy of the alarm flag\n\r" );
    00705             printf( "  7 - Duty cycle programmable pulse\n\r" ) ;
    00706             printf( "  8 - Enter Backup Mode\n\r" ) ;
    00707             printf( "  9 - Quit\n\r" );
    00708             while(1)
    00709             {
    00710                 ucKey = UART_GetChar() ;
    00711                 UART_PutChar( ucKey ) ;
    00712                 if ( ucKey == '0' )     RTC_SetWaveForm(RTC, RTC_MR_OUT1_NO_WAVE);
    00713                 if ( ucKey == '1' )     RTC_SetWaveForm(RTC, RTC_MR_OUT1_FREQ1HZ);
    00714                 if ( ucKey == '2' )     RTC_SetWaveForm(RTC, RTC_MR_OUT1_FREQ32HZ);
    00715                 if ( ucKey == '3' )     RTC_SetWaveForm(RTC, RTC_MR_OUT1_FREQ64HZ);
    00716                 if ( ucKey == '4' )     RTC_SetWaveForm(RTC, RTC_MR_OUT1_FREQ512HZ);
    00717                 if ( ucKey == '5' )     RTC_SetWaveForm(RTC, RTC_MR_OUT1_ALARM_TOGGLE);
    00718                 if ( ucKey == '6' )     RTC_SetWaveForm(RTC, RTC_MR_OUT1_ALARM_FLAG);
    00719                 if ( ucKey == '7' )     RTC_SetWaveForm(RTC, RTC_MR_OUT1_PROG_PULSE);
    00720                 if ( ucKey == '9' )
    00721                 {
    00722                     bState = STATE_MENU ;
    00723                     bMenuShown = 0 ;
    00724                     _RefreshDisplay() ;
    00725                     break;
    00726                 }
    00727                 if(ucKey == '8' )
    00728                 {
    00729                     printf( "\n\rEnter in Backup Mode. Touch the LCD screen to wakeup.\n\r" );
    00730                     /* Enable the PIO for wake-up (high to low level Transition) */
    00731                     SUPC->SUPC_WUIR = PIN_TSC_IRQ_WUP_ID ;
    00732                     _EnterBackupMode();
    00733                 }
    00734             }
    00735         }
    00736
    00737         /* clear trigger flag */
    00738         if ( ucKey == 'c' )
    00739         {
    00740             alarmTriggered = 0 ;
    00741             bMenuShown = 0 ;
    00742             _RefreshDisplay() ;
    00743         }
    00744
    00745         /* quit */
    00746         if ( ucKey == 'q' )
    00747         {
    00748             break ;
    00749         }
    00750     }
    00751
    00752     return 0 ;
    00753 }
    00754

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines