#include #include // LCD Screen routines for the motorola 6812 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; _H12PORTH = 0; _H12DDRH = 0x00; _H12PORTG = 0x00; _H12DDRG= 0xFF; // delay for 15ms. This is customized for the HC12 and must be changed for other processors for(i=0; i<130,000; i++); // set up interface to LCD _H12DDRH = 0xFF; _H12PORTH = 0x3F; // Function set command (8 bit) _H12PORTG = 0x20; // clock cmd in for(i=0; i<100;i++); // delay for ~18 clock cycles _H12PORTG = 0x00; // delay for at least 4.1 ms for(i=0;i<40000;i++); // setup interface _H12PORTH=0x3F; // Function set command(8 bit) _H12PORTG = 0x20; // clock in cmd for(i=0;i<100;i++); _H12PORTG = 0x00; // delay for at least 100us for(i=0;i<1000;i++); // set up interface _H12PORTH = 0x3F; // function set command (8 bit) _H12PORTG = 0x20; for(i=0;i<100;i++); _H12PORTG = 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()); _H12DDRG = 0xFF; _H12DDRH = 0xFF; _H12PORTG = 0x00; // set control signals _H12PORTH = cmd; // write cmd to port for(i=0; i<100; i++); _H12PORTG=0x20; for(i=0;i<100;i++); _H12PORTG=0x00; for(i=0;i<100;i++); _H12DDRH=0x00; return; } // SetDDRamAddr // Set the address of the LCD controller void SetDDRamAddr(char DDaddr) { int i; while(BusyXLCD()); _H12DDRG = 0xFF; _H12DDRH=0xFF; _H12PORTH=(DDaddr | 0x80); // write cmd and addr to port _H12PORTG=0x00; for(i=0;i<100;i++); _H12PORTG=0x20; for(i=0;i<100;i++); _H12PORTG=0x00; for(i=0;i<100;i++); _H12DDRH =0x00; return; } // BusyXLCD // This checks the busy status of the HD 44780 char BusyXLCD(void) { int i; _H12DDRG = 0xFF; _H12DDRH=0x00; _H12PORTG=0x08; // set control bits for(i=0;i<100;i++); _H12PORTG=0x28; for(i=0;i<100;i++); if(_H12PORTH & 0x80) { _H12PORTG = 0x00; return 1; } else { _H12PORTG = 0x00; return 0; } } // WriteDataXLCD // Writes data to the controller void WriteDataXLCD(char data) { int i; while(BusyXLCD()); _H12DDRG = 0xFF; _H12DDRH = 0xFF; _H12PORTH = data; _H12PORTG = 0x10; for(i=0;i<100;i++); _H12PORTG=0x30; for(i=0;i<100;i++); _H12PORTG=0x00; _H12DDRH= 0x00; return; }