-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdisplay_driver.h
More file actions
107 lines (100 loc) · 1.62 KB
/
display_driver.h
File metadata and controls
107 lines (100 loc) · 1.62 KB
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
104
105
106
107
typedef unsigned char UC8;
#include"delay.h"
#define LCD_D 0xf<<23
#define RS 1<<21
#define E 1<<22
void LCD_INIT(void);
void LCD_CMD(UC8);
void LCD_DATA(UC8);
void LCD_STR(UC8* );
void LCD_INT(int);
void LCD_FLOAT(float);
void LCD_INIT(void)
{
IODIR1 |= LCD_D|RS|E;
LCD_CMD(0x01);//to clear the screen
LCD_CMD(0x02);// to set cursur to first position
LCD_CMD(0x0c);// cursur off and lcd on
LCD_CMD(0X28);// to select the 4 bit mode
LCD_CMD(0X80);
}
void LCD_CMD(UC8 cmd)
{
IOCLR1 = LCD_D;
IOSET1 = ((cmd >> 4) & 0x0F) << 23;
IOCLR1 = RS ;
IOSET1 = E;
delaym(2);
IOCLR1 = E;
IOCLR1 = LCD_D;
IOSET1 = (cmd&0x0f)<<23;
IOCLR1 = RS ;
IOSET1 = E;
delaym(2);
IOCLR1 = E;
}
void LCD_DATA(UC8 d)
{
IOCLR1 = LCD_D;
IOSET1 = ((d >> 4) & 0x0F) << 23;
IOSET1 = RS;
IOSET1 = E;
delaym(2);
IOCLR1 = E;
IOCLR1 = LCD_D;
IOSET1 = (d&0x0f)<<23;;
IOSET1 = RS;
IOSET1 = E;
delaym(2);
IOCLR1 = E;
}
void LCD_INT(int n)
{
UC8 a[10] ;
int i = 0;
if(n==0)
LCD_DATA(48);// to print zero
else
{
if(n<0)
{
LCD_DATA('-');
n = -n;
}
while(n)
{
a[i++] = n%10;
n = n/10;
}
if(i==0)
i = 2;
for(i = i-1;i>=0;i--)
LCD_DATA(48+a[i]);
}
}
void LCD_STR(UC8* s)
{
UC8 j = 0;
while(*s)
{
LCD_DATA(*s++);
j++;
if(j == 16)
LCD_CMD(0XC0);
}
}
void LCD_FLOAT(float f)
{
int d;
int i;
if(f<0)
{
f = -f;
LCD_DATA('-');
}
i = (int)f;
d = (int)((f-i)*1000.0);
LCD_INT(i);
LCD_DATA('.');
LCD_INT(d);
}