// Handel-C decade counter and seven-segment display simulation plugin void increment_decade(unsigned 4 *count, unsigned 1 Hold); set clock = external "Dummy"; void main (void) { // Declarations unsigned 1 stop; unsigned 4 count[2]; unsigned 1 hold; unsigned 8 cycles; unsigned 7 seg1, seg2; // variables must be static to be initialised static unsigned 7 encoder[10] = {0x01, 0x4f, 0x12, 0x06, 0x4c, 0x24, 0x20, 0x0f, 0x00, 0x04}; // Plugin interfaces // Seven segment display 1 interface bus_out () display1 (unsigned 7 out = seg1) with { extlib="7segment.dll", extinst="disp1", extfunc="PlugInSet" }; // Seven segment display 2 interface bus_out () display2 (unsigned 7 out = seg2) with { extlib="7segment.dll", extinst="disp2", extfunc="PlugInSet" }; // Initialisation par { stop = 0; count[0] = 0; count[1] = 0; } par { // Cycle counter - use this to divide the clock while (!stop) par { cycles++; hold = (cycles != 0xff); } // Call the counter while (!stop) increment_decade(count, hold); // Seven segment displays while (!stop) par { seg1 = encoder[count[1]]; seg2 = encoder[count[0]]; } } } // This function describes a two digit BCD counter 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]++; }