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

if(Flag == 3)                               // If to refresh Digit 3
                   {
                       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;                 // Disable 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()
               {
                   int Temp1, Temp2;
                   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);
                   Dice = 0;                                   // Ready to start
                   while(1)                                    // Do forever
                   {
                       if(button == 0)                         // If button is pressed
                       {
                           Temp1 = rand() % 6 +1;              // First number 1-6
                           Temp2 = rand() % 6 + 1;             // Second number 1-6
                           Dice = Temp1*100 + Temp2;           // Dice number
                           wait(5.0);                          // Wait 5 seconds
                           Dice = 0;                           // Ready to start
                       }
                   }
               }
            FIG. 8.19,  CONT’D
   168   169   170   171   172   173   174   175   176   177   178