FRDM-KL46Z board sLCD demo code
Fork of FRDM-KL46Z LCD rtc Demo by
Diff: main.cpp
- Revision:
- 4:15da67d64f85
- Parent:
- 3:fb38dbc95b12
- Child:
- 5:15c484c41006
--- a/main.cpp Sat Sep 27 14:56:06 2014 +0000 +++ b/main.cpp Sat Sep 27 16:45:43 2014 +0000 @@ -1,14 +1,27 @@ +#ifndef RTC_CLOCK_TEST +//#define RTC_CLOCK_TEST +#endif //RTC_CLOCK_TEST +#ifndef LED_BLINK_TEST +//#define LED_BLINK_TEST +#endif //LED_BLINK_TEST + //_____________________________________________________________// //======== INCLUDES ===========================================// //¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯// +#if (defined RTC_CLOCK_TEST) || (defined LED_BLINK_TEST) #include "mbed.h" +#endif //RTC_CLOCK_TEST || LED_BLINK_TEST +#ifdef RTC_CLOCK_TEST #include "SLCD.h" +#endif //RTC_CLOCK_TEST //_____________________________________________________________// //======== DEFINES ============================================// //¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯// +#ifdef LED_BLINK_TEST #define PWMDWELL 50 // milliseconds #define DFDELTA 0.01 +#endif //RTC_CLOCK_TEST //_____________________________________________________________// //======== MACROS =============================================// @@ -17,12 +30,18 @@ //_____________________________________________________________// //======== PROTOTYPES =========================================// //¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯// +#if (defined RTC_CLOCK_TEST) || (defined LED_BLINK_TEST) void initializeSetting (void); +#endif //RTC_CLOCK_TEST || LED_BLINK_TEST +#ifdef LED_BLINK_TEST void ledBlink (float dutyfactor); +#endif //LED_BLINK_TEST +#ifdef RTC_CLOCK_TEST void rtcClock (void); void scrollMessage (void); void switchinput1_INTIRQ (void); void switchinput3_INTIRQ (void); +#endif //LED_BLINK_TEST //_____________________________________________________________// //======== TABLES =============================================// @@ -31,12 +50,16 @@ //_____________________________________________________________// //======== VARIABLES ==========================================// //¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯// -DigitalOut greenled_DO(LED1); -DigitalOut redled_DO(LED2); +#ifdef LED_BLINK_TEST PwmOut greenled_PO(LED1); PwmOut redled_PO(LED2); DigitalIn switchinput1_DI(SW1); DigitalIn switchinput3_DI(SW3); +float defaultdutyfactor = 0.0; +#endif //LED_BLINK_TEST +#ifdef RTC_CLOCK_TEST +DigitalOut greenled_DO(LED1); +DigitalOut redled_DO(LED2); InterruptIn switchinput1_INT(SW1); InterruptIn switchinput3_INT(SW3); SLCD slcd; @@ -45,24 +68,31 @@ int i, j, k, lastscroll, display_timer, minute, hour, colon, dp; char message[60]; char buffer[32]; -float defaultdutyfactor = 0.0; +#endif //RTC_CLOCK_TEST //_____________________________________________________________// //======== MAIN() =============================================// //¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯// int main () { +#if (defined RTC_CLOCK_TEST) || (defined LED_BLINK_TEST) initializeSetting(); +#endif //RTC_CLOCK_TEST || LED_BLINK_TEST while (true) { +#ifdef RTC_CLOCK_TEST rtcClock(); - +#endif //RTC_CLOCK_TEST + +#ifdef LED_BLINK_TEST if (!switchinput1_DI) { + ledBlink(0.5); + } else if (!switchinput3_DI) { ledBlink(1.0); - } else if (!switchinput3_DI) { - ledBlink(10.0); } else { + ledBlink(2.0); } +#endif //LED_BLINK_TEST } } @@ -74,12 +104,16 @@ //! @[in] nil //! @retval nil //! ------------------------------------------------------------- +#if (defined RTC_CLOCK_TEST) || (defined LED_BLINK_TEST) void initializeSetting (void) { - time_t seconds = time(NULL); - +#ifdef LED_BLINK_TEST switchinput1_DI.mode(PullUp); switchinput3_DI.mode(PullUp); +#endif //LED_BLINK_TEST + +#ifdef RTC_CLOCK_TEST + time_t seconds = time(NULL); slcd.All_Segments(1); wait(2); @@ -89,7 +123,7 @@ greenled_DO = 1; redled_DO = 1; - sprintf(message, " rtc clock s3 sets the hours s1 sets the minutes"); + sprintf(message, " rtc clock sw3 sets the hours sw1 sets the minutes"); // scrolling message scroll.start(); @@ -102,13 +136,16 @@ switchinput1_INT.rise(switchinput1_INTIRQ); // start set Minutes IRQ switchinput3_INT.rise(switchinput3_INTIRQ); // start set Hours IRQ +#endif //RTC_CLOCK_TEST } +#endif //RTC_CLOCK_TEST || LED_BLINK_TEST //! ------------------------------------------------------------- //! @brief LED Blink -//! @[in] dutyfactor Duty Factor +//! @[in] dutyfactor Duty Factor Integer //! @retval nil //! ------------------------------------------------------------- +#ifdef LED_BLINK_TEST void ledBlink (float dutyfactor) { redled_PO.write(defaultdutyfactor); @@ -117,12 +154,14 @@ if (defaultdutyfactor >= dutyfactor) defaultdutyfactor = 0.0; wait_ms(PWMDWELL); } +#endif //! ------------------------------------------------------------- //! @brief RTC Clock //! @[in] nil //! @retval nil //! ------------------------------------------------------------- +#ifdef RTC_CLOCK_TEST void rtcClock (void) { time_t seconds = time(NULL); @@ -149,18 +188,20 @@ if (display_timer > 9) display_timer = 0; wait(0.5); } +#endif //RTC_CLOCK_TEST //! ------------------------------------------------------------- //! @brief Scroll Message //! @[in] nil //! @retval nil //! ------------------------------------------------------------- +#ifdef RTC_CLOCK_TEST void scrollMessage (void) { if (scroll.read_ms() > lastscroll + 350) { scroll.reset(); if (i > 58) { - i=0; + i = 0; } int j, k = i; for (j = 0; j < 4; j++) { @@ -175,11 +216,14 @@ lastscroll = scroll.read_ms(); } } +#endif //RTC_CLOCK_TEST + //! ------------------------------------------------------------- //! @brief Set Minutes ISR //! @[in] nil //! @retval nil //! ------------------------------------------------------------- +#ifdef RTC_CLOCK_TEST void switchinput1_INTIRQ (void) { display_timer = 7; @@ -199,12 +243,14 @@ t.tm_year = 114; set_time(mktime(&t)); } +#endif //RTC_CLOCK_TEST //! ------------------------------------------------------------- //! @brief Set Hours ISR //! @[in] nil //! @retval nil //! ------------------------------------------------------------- +#ifdef RTC_CLOCK_TEST void switchinput3_INTIRQ (void) { display_timer = 7; @@ -224,3 +270,4 @@ t.tm_year = 114; set_time(mktime(&t)); } +#endif //RTC_CLOCK_TEST