// Use writec() and timer interrupt functions to implement a digital clock! // By using the timer interrupt, users can easily implement any timing functions needed. // To improve the accuracy of the clock, writings to LCD should be minimized. // Proved to work on MT-20, MT-28 and MT-ARM chips, need to remove the "seconds" display for MT-40 series chips! int ps; // previous seconds int s; // seconds int h; // hours int m; // minutes main() { h = 23; m = 59; s = 50; writes("~XCEOL", 0); // disable the 'clear to end of line' feature of LCD update_hours(); writec(2, ':', 0); // show separator update_minutes(); writec(5, ':', 0); // show separator loop { if(s != ps) { ps = s; update_seconds(); } if(s >= 60) { s = 0; m++; update_minutes(); } if(m >= 60) { m = 0; h++; if(h >= 24) h = 0; update_minutes(); update_hours(); } } } second_tick() timer 1000 // this timer interrupt increments the 'seconds' counter every 1000ms, i.e. 1 second // do keep the toal processing time for this function small to maintain the accuracy of the timing required. { s++; } update_seconds() { writec(6, s/10+'0', 0); writec(7, s%10+'0', 0); } update_minutes() { writec(3, m/10+'0', 0); writec(4, m%10+'0', 0); } update_hours() { writec(0, h/10+'0', 0); writec(1, h%10+'0', 0); }