89c52 delay
This is for 16x1 (8x2 electrical) in Ke*l. Written for AT89S8252/3. Possibly may be of some use to you.
LCD.H
/*
* LCD interface header file
* See lcd.c for more info
*/
/* write a byte to the LCD in 4 bit mode */
extern void lcd_write(unsigned char);
/* Clear and home the LCD */
extern void lcd_clear(void);
/* write a string of characters to the LCD */
LCD.C
#include <reg51.h>
#include "delay.h"
sbit LCD_RS =P1^0; // Register select
sbit LCD_E =P1^1; // Enable
#define LCD_STROBE ((LCD_E = 1),(LCD_E=0))
// Time in Milliseconds
void DelayMs(unsigned char cnt)
{ cnt=2*cnt;
do
{DelayUs(500);}
while(--cnt != 0);
}
// Send to Display
void lcd_write(unsigned char c)
{
unsigned char Movit;
Movit = (c >> 2);
P1 = (P1 & 0xC3) | (Movit & 0x3C);
LCD_STROBE;
Movit = (c << 2);
P1 = (P1 & 0xC3) | (Movit & 0x3C);
LCD_STROBE;
DelayUs(60);
}
// Clear and home the LCD
void lcd_clear(void)
{
LCD_RS = 0;
lcd_write(0x80);
DelayMs(2);
}
// Position the Cursor
void lcd_goto(unsigned char pos)
{
LCD_RS = 0;
DELAY
#define XTAL_FREQ 12
#define DelayUs(x) { unsigned char _dcnt; \
_dcnt = (x)*((XTAL_FREQ)/12); \
while(--_dcnt != 0) \
continue; }
extern void DelayMs(unsigned char);
Added after 10 minutes:
Sorry I forgot the connections
P1.0 = RS
P1.1 = E
P1.2 = D4
P1.3 = D5
P1.4 = D6
P1.5 = D7
Ground Pin 3 on LCD
Delay shown is "Delay.h"
Added after 5 minutes:
Sorry I meant ground R/W pin. Pin 3 is contrast, cannot remember if 3 goes to vcc or vss for full contrast.