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

152                          8. INTERMEDIATE LEVEL PROJECTS

                            Enable0 = Disable;
                            Flag = 2;
                            if(Digits[3] != 0)                      // If MSD Digit non zero
                            {
                                Segments = LEDS[Digits[3]];         // Send to PORT C
                                Enable3 = Enable;                   // Enable Digit 3
                            }
                        }
                        else if(Flag == 2)                          // If to refresh Digit 2
                        {
                            Enable3 = Disable;
                            Flag = 1;
                            if(Digits[2] != 0 || (Digits[2] == 0 && Digits[3] != 0))
                            {
                                Segments = LEDS[Digits[2]];         // Send to PORT C
                                Enable2 = Enable;                   // Enable Digit 2
                            }
                        }
                        else if(Flag == 1)                          // If to refresh Digit 1
                        {
                            Enable2 = Disable;
                            Flag = 0;
                            if(Digits[1] != 0 || (Digits[3] != 0 || Digits[2] != 0))
                            {
                                Segments = LEDS[Digits[1]];         // Send to PORT C
                                Enable1 = Enable;                   // Enable Digit 1
                            }
                        }
                        else if(Flag == 0)                          // If to refresh Digit 0
                        {
                            Enable1 = Disable;
                            Flag = 3;
                            Segments = LEDS[Digits[0]];             // Send to PORT C
                            Enable0 = Enable;                       // Enable Digit 0
                        }
                    }


                    int main()
                    {

                        Enable3 = Disable;                          // Disable Digit 3
                        Enable2 = Disable;                          // Disable Digit 2
                        Enable1 = Disable;                          // Disable Digit 1
                        Enable0 = Disable;                          // Disable Digit 0

                        tim.attach(&Refresh, 0.005);
                        while(1)                                    // Do forever
                        {
                            CNT++;                                  // Increment CNT
                            wait(1.0);                              // Wait 1 second
                        }
                    }
                 FIG. 8.15,  CONT’D
   161   162   163   164   165   166   167   168   169   170   171