// Handel-C decade counter and test void increment_decade(unsigned 4 *count, unsigned 1 Hold); set clock = external "Dummy"; void main (void) { // Declarations unsigned 1 stop; unsigned 8 i; unsigned 4 count[2]; unsigned 1 hold; unsigned 8 cycles; hold = 0; cycles = 0; par { // Stimulus { // Count a while for (i = 0; i < 8; i++) ; // Takes 9 cycles // => count = "09" // Hold a while hold = 1; // + 1 cycle = 10 // => count = "01" for (i = 0; i < 8; i++) ; // + 9 cycles = 19 // => count = "10" // Count right round hold = 0; // + 1 cycle = 20 // => count = "10" for (i = 0; i < 89; i++) ; // + 90 cycles = 110 // => count = "00" // Stop the simulator stop = 1; } // Cycle counter while (!stop) cycles++; // Call the counter while (!stop) increment_decade(count, hold); } } void increment_decade(unsigned 4 *count, unsigned 1 Hold) { if (Hold) count[0] = count[0]; /* You have to do something! */ else if ( count[0] == 9 ) par { /* "par" ensures one cycle */ count[0] = 0; if ( count[1] == 9 ) count[1] = 0; else count[1]++; } else count[0]++; }