Вот пример программирования для PIC (4-х битный режим, флаг занятости не используется). Из него все должно быть понятно.
Код
/*
* LCD interface example
* 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 follows (the standard 14 pin
* LCD connector is used):
*
* PORTB bits 0-3 are connected to the LCD data bits 4-7 (high nibble)
* PORTA bit 4 is connected to the LCD RS input (register select)
* PORTA bit 5 is connected to the LCD EN bit (enable)
*
*/
static bit LCD_RS @ ((unsigned)&PORTC*8+4); // Register select
static bit LCD_EN @ ((unsigned)&PORTC*8+5); // Enable
#define LCD_STROBE ((LCD_EN = 1),(LCD_EN=0))
void LCD_Write(unsigned char c) {
PORTB = c >> 4;
LCD_STROBE;
PORTB = c;
LCD_STROBE;
DelayUs(40);
}
void LCD_Clear(void) {
LCD_RS = 0;
LCD_Write(0x1);
DelayMs(2);
}
void LCD_Puts(const char * s) {
LCD_RS = 1;
while(*s)
LCD_Write(*s++);
}
void LCD_Goto(unsigned char pos) {
LCD_RS = 0;
LCD_Write(0x80+pos);
}
void LCD_Init(void) {
LCD_RS = 0;
DelayMs(15);
PORTB = 0x3;
LCD_STROBE;
DelayMs(5);
LCD_STROBE;
DelayUs(100);
LCD_STROBE;
DelayMs(5);
PORTB = 0x2;
LCD_STROBE;
DelayUs(40);
LCD_Write(0x28); // 4 bit mode, 1/16 duty, 5x8 font
LCD_Write(0x08); // display off
LCD_Write(0x0C); // display on, blink curson on
LCD_Write(0x06); // entry mode
}