/* * LCDClock.java * * Created on 27 September 2001, 02:42 */ import java.util.Date; import com.dalsemi.comm.*; /** * * @author cjb * @version */ public class LCDClock extends java.lang.Object { /** Creates new LCDClock */ public LCDClock() { } public static void main (String args[]) { //initialise LCD LCDPort.sendControl(0x38); //2 line display, 8 bit data LCDPort.sendControl(0x0C); //turn on display, no cursor LCDPort.sendControl(0x01); //clear the screen Date now = new Date(); while(true) { Date then = now; now = new Date(); String date = getTwoDigitNumber(now.getDate()) + "-" + getTwoDigitNumber(now.getMonth() + 1) + "-" + (new Integer(now.getYear() + 100)).toString().substring(1); String time = getTwoDigitNumber(now.getHours()) + ":" + getTwoDigitNumber(now.getMinutes()) + ":" + getTwoDigitNumber(now.getSeconds()); //only update if a second has passed if(now.getSeconds() != then.getSeconds()) { LCDPort.sendControl(0x01); //clear the screen LCDPort.setAddress((int)0); //move to beginning of 1st line writeStringToLCD(date); LCDPort.setAddress((int)40); //move to beginning of second line writeStringToLCD(time); } } } /** * write a string to the LCD */ private static void writeStringToLCD(String str) { char[] chars = str.toCharArray(); for(int i=0;i