Micon Car Rally / Mbed 2 deprecated Interrrupt_Timer_LED

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 //------------------------------------------------------------------//
00002 //Supported MCU:   RZ/A1H
00003 //File Contents:   Interrupt Timer LED (GR-PEACH version)
00004 //Version number:  Ver.1.00
00005 //Date:            2016.01.18
00006 //Copyright:       Renesas Electronics Corporation
00007 //------------------------------------------------------------------//
00008 
00009 //Include
00010 //------------------------------------------------------------------//
00011 #include "mbed.h"
00012 
00013 //Constructor
00014 //------------------------------------------------------------------//
00015 Ticker      interrput;
00016 DigitalOut  LED_R(LED1);
00017 DigitalOut  LED_G(LED2);
00018 DigitalOut  LED_B(LED3);
00019 
00020 //Prototype
00021 //------------------------------------------------------------------//
00022 void intTimer( void );                  /* Interrupt fanction       */
00023 void timer( unsigned long timer_set );
00024 
00025 //Globle
00026 //------------------------------------------------------------------//
00027 volatile unsigned long  cnt_timer;      /* Used by timer function   */
00028 
00029 //Main
00030 //------------------------------------------------------------------//
00031 int main( void )
00032 {
00033     /* Initialize MCU functions */
00034     interrput.attach(&intTimer, 0.001);
00035  
00036     while(1) {
00037         LED_R = 1;
00038         timer( 1000 );
00039         LED_R = 0;
00040         timer( 1000 );
00041     }
00042 }
00043 
00044 //Interrupt Timer
00045 //------------------------------------------------------------------//
00046 void intTimer( void )
00047 {
00048     cnt_timer++;
00049 }
00050 
00051 //Timer fanction
00052 //------------------------------------------------------------------//
00053 void timer( unsigned long timer_set )
00054 {
00055     cnt_timer = 0;
00056     while( cnt_timer < timer_set );
00057 }
00058 
00059 //------------------------------------------------------------------//
00060 // End of file
00061 //------------------------------------------------------------------//