Page 111 - ARM Based Microcontroller Projects Using MBED
P. 111

7.7 PROJECT 4—ROTATING LEDs                       97
                 *********************************************************************
                                         ROTATING LEDS
                                         =============
                 In this modified version of the program The PortOut statement is used
                 to configure PORT C. Mask 0x00FF sets PC_0 to PC_7 bits to all 1's so
                 that all the lower byte of PORT C is used.

                 Author: Dogan Ibrahim
                 Date  : August 2018
                 File: LED8-2
                 ************************************************************************/
                 #include "mbed.h"
                 PortOut LEDS(PortC, 0x00FF);
                 int State[] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
                 int main()
                 {
                     while(1)
                     {
                         for(int k = 0; k < 8; k++)              // Do 8 times
                         {
                             LEDS = State[k];                    // Turn LED ON
                             wait(0.25);                         // Wait 250ms
                         }
                     }
                 }

            FIG. 7.30  Modified program.

                    /*******************************************************************
                                ROTATE LEDS
                                ===========
                    In this modified program, the BusOut statement is used. The delay
                    between teh outputs is set to 0.5 second

                    Author: Dogan Ibrahim
                    Date  : August 2018
                    File  : LED8-3
                    *******************************************************************/
                    #include "mbed.h"

                    BusOut LEDS(PC_0,PC_1,PC_2,PC_3,PC_4,PC_5,PC_6,PC_7);
                    int main()
                    {
                        int k = 0;                      // First LED
                        while(1)                        // Endless loop
                        {
                            LEDS = 1 << k;              // LED ON
                            wait(0.5);                  // Wait 0.5 second
                            k++;                        // Increment LED count
                            if(k == 8)k = 0;            // Back to first LED
                        }
                    }

            FIG. 7.31  Another modified program.
   106   107   108   109   110   111   112   113   114   115   116