#include // LCD Screen routines for the motorola 6811 using a Hitachi HD44780 // Written by Lee Rosenberg rosenl@rpi.edu // Developed for use with Introl C 4.0 // October 21, 1998 void OpenXLCD(char); // configures I/O pins for external LCD void SetDDRamAddr(char); // sets display data address char BusyXLCD(void); // returns busy status of the LCD void WriteCmdXLCD(char); // write a command to the lcd void WriteDataXLCD(char); // writes data byte to the LCD void WriteBuffer(char *buffer); // Writes a string to the screen // Write Buffer // Write a string of bytes to the HD44780 void WriteBuffer(char *buffer) { while(*buffer) // while buffer not empty { while(BusyXLCD()); // check if screen busy WriteDataXLCD(*buffer); // write character to screen buffer++; // increment pointer } return; } // OpenXLCD // This configures the LCD screen. void OpenXLCD(char lcdtype) { int i; _H11PORTC = 0; _H11DDRC = 0x00; _H11PORTA = 0x00; // delay for 15ms. This is customized for the HC11 and must be changed for other processors for(i=0; i<40,000; i++); // set up interface to LCD _H11DDRC = 0xFF; _H11PORTC = 0x3F; // Function set command (8 bit) _H11PORTA = 0x20; // clock cmd in for(i=0; i<30;i++); // delay for ~18 clock cycles _H11PORTA = 0x00; // delay for at least 4.1 ms for(i=0;i<9000;i++); // setup interface _H11PORTC=0x3F; // Function set command(8 bit) _H11PORTA = 0x20; // clock in cmd for(i=0;i<30;i++); _H11PORTA = 0x00; // delay for at least 100us for(i=0;i<500;i++); // set up interface _H11PORTC = 0x3F; // function set command (8 bit) _H11PORTA = 20; for(i=0;i<30;i++); _H11PORTA = 0x00; WriteCmdXLCD(lcdtype); // function set cmd 8 bit interface WriteCmdXLCD(0x0C); WriteCmdXLCD(0x01); return; } // WriteCmdXLCD // Writes a command to the controller void WriteCmdXLCD(char cmd) { int i; while(BusyXLCD()); _H11DDRC = 0xFF; _H11PORTC = cmd; // write cmd to port _H11PORTA = 0x00; // set control signals for(i=0; i<30; i++); _H11PORTA=0x20; for(i=0;i<30;i++); _H11PORTA=0x00; for(i=0;i<30;i++); _H11DDRC=0x00; return; } // SetDDRamAddr // Set the address of the LCD controller void SetDDRamAddr(char DDaddr) { int i; while(BusyXLCD()); _H11DDRC=0xFF; _H11PORTC=(DDaddr | 0x80); // write cmd and addr to port _H11PORTA=0x00; for(i=0;i<30;i++); _H11PORTA=0x20; for(i=0;i<30;i++); _H11PORTA=0x00; for(i=0;i<30;i++); _H11DDRC =0x00; return; } // BusyXLCD // This checks the busy status of the HD 44780 char BusyXLCD(void) { int i; _H11DDRC=0x00; _H11PORTA=0x08; // set control bits for(i=0;i<30;i++); _H11PORTA=0x28; for(i=0;i<30;i++); if(_H11PORTC & 0x80) { _H11PORTA = 0x00; return 1; } else { _H11PORTA = 0x00; return 0; } } // WriteDataXLCD // Writes data to the controller void WriteDataXLCD(char data) { int i; while(BusyXLCD()); _H11DDRC = 0xFF; _H11PORTC = data; _H11PORTA = 0x10; for(i=0;i<30;i++); _H11PORTA=0x30; for(i=0;i<30;i++); _H11PORTA=0x00; _H11DDRC= 0x00; return; }