98 lines
2.2 KiB
C
98 lines
2.2 KiB
C
/* *************************************************************** *
|
|
* Z80 LCD interface header file *
|
|
* (c) 27.09.2017 Paolo Iocco *
|
|
* *
|
|
***************************************************************** *
|
|
*
|
|
* This code will interface to a standard LCD controller
|
|
* like the Hitachi HD44780. It uses it in 4 bit mode, with
|
|
* the hardware connected as in lcd.h
|
|
*
|
|
***************************************************************** */
|
|
|
|
#include "lcd.h"
|
|
unsigned char LCD_Port=0;
|
|
|
|
|
|
/* easy delay procedure */
|
|
void delay(int tempo){
|
|
int i;
|
|
for (i=0;i<=tempo;i++) {
|
|
__asm
|
|
nop
|
|
__endasm;
|
|
}
|
|
}
|
|
|
|
/* sets or clears the RS bit: CMD/DATA bit */
|
|
void lcd_rs(unsigned char command){
|
|
if (command==DATA)
|
|
setb(LCD_Port,RS_PIN);
|
|
else
|
|
clrb(LCD_Port,RS_PIN);
|
|
//Display=LCD_Port;
|
|
}
|
|
|
|
/* generates the strobe pulse and sends the data out */
|
|
void lcd_strobe(void){
|
|
setb(LCD_Port,EN_PIN);
|
|
Display=LCD_Port;
|
|
clrb(LCD_Port,EN_PIN);
|
|
Display=LCD_Port;
|
|
}
|
|
|
|
/* write a byte to the LCD in 4 bit mode */
|
|
void lcd_write(unsigned char c) {
|
|
LCD_Port = (LCD_Port & 0xF0) | (c >> 4);
|
|
lcd_strobe();
|
|
LCD_Port = (LCD_Port & 0xF0) | (c & 0x0F);
|
|
lcd_strobe();
|
|
delay(4);
|
|
}
|
|
|
|
/* Clear and home the LCD */
|
|
void lcd_clear(void) {
|
|
lcd_rs(CMD);
|
|
lcd_write(0x1);
|
|
delay(200);
|
|
}
|
|
|
|
/* write a string of chars to the LCD */
|
|
void lcd_puts(const char * s) {
|
|
while(*s)
|
|
lcd_putch(*s++);
|
|
}
|
|
|
|
/* write one character to the LCD */
|
|
void lcd_putch(char c) {
|
|
lcd_rs(DATA); // write characters
|
|
lcd_write(c);
|
|
delay(4);
|
|
}
|
|
|
|
/* Go to the specified position */
|
|
void lcd_goto(unsigned char pos) {
|
|
lcd_rs(CMD);
|
|
lcd_write(0x80+pos);
|
|
}
|
|
|
|
/* initialise the LCD - put into 4 bit mode */
|
|
void lcd_init(void) {
|
|
lcd_rs(CMD); // write control bytes
|
|
delay(150); // power on delay
|
|
LCD_Port = 0x3; // attention!
|
|
lcd_strobe();
|
|
delay(500);
|
|
lcd_strobe();
|
|
delay(100);
|
|
lcd_strobe();
|
|
delay(500);
|
|
LCD_Port = 0x2; // set 4 bit mode
|
|
lcd_strobe();
|
|
delay(4);
|
|
lcd_write(0x28); // 4 bit mode, 1/16 duty, 5x8 font
|
|
lcd_write(0x08); // display off
|
|
lcd_write(0x0F); // display on, blink curson on
|
|
lcd_write(0x06); // entry mode
|
|
}
|