Dispport.c LCD driver

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
// filename : dispport.c
// display routine for LCD display module
// connected to Port0 DB0-DB7
#include <reg66x.h>
#include <string.h>
sbit E = P1^4;
sbit RS = P3^6;
sbit RW = P3^7;
void cursor(unsigned char, unsigned char);
void cld(void);
void D_CONTROL(unsigned char x)
{
RS = 0; RW = 0;
P0 = x;
E = 1;
E = 0;
P0 = 0xFF;
RS = 1; RW = 1;
}
unsigned char D_STATUS(void)
{
unsigned char x;
P0 = 0xFF;
RS = 0; RW = 1;
E = 1;
x = P0;
E = 0;
RS = 1;
return(x);
}
void D_WRITE(unsigned char x)
{
RS = 1; RW = 0;
P0 = x;
E = 1;
E = 0;
P0 = 0xFF;
RW = 1;
}
void init_display(void)
{
int x;
E = 0;
for(x=0; x<4800; x++); /* 30mS delay @11 MHz*/
D_CONTROL(0x38); /* reset af HD 44780 */
for (x=0; x<2400; x++); /* 15 mS delay @11MHz*/
D_CONTROL(0x38);
for (x=0; x<60; x++); /* 400uS delay @11MHz*/
D_CONTROL(0x38);
for(x=0; x<60; x++); /* 400uS delay @11HMz*/
D_CONTROL(0x38);
while(D_STATUS() & 0x80); /* busy-flag = 0 */
D_CONTROL(0x06); /* Entry mode */
while(D_STATUS() & 0x80);
D_CONTROL(0x0C); /* Display ON/OFF control */
while(D_STATUS() & 0x80);
D_CONTROL(0x01); /* Clear display */
while(D_STATUS() & 0x80);
cursor(1,1);
cld();
}
void cursor(char rk, char pos)
{
unsigned char x;
if (rk == 2)
x = 192;
else
x = 128;
if (pos < 25)
x = x+pos-1;
D_CONTROL(x);
while(D_STATUS() & 0x80); /* busy-flag = 0 */
}
void cld(void)
{
D_CONTROL(1);
while(D_STATUS() & 0x80); /* busy-flag = 0 */
}
char putchar(char c)
{
if(c != '\n')
{
D_WRITE(c);
while(D_STATUS() & 0x80); /* busy-flag = 0 */
}
return c;
}