-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlcd.c
executable file
·98 lines (84 loc) · 1.64 KB
/
lcd.c
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
/*
* lcd.c
*
* Created on: 2022��6��25��
* Author: Joseph
*/
#include <msp430.h>
#include "lcd.h"
#include "strUtils.h"
#include "numberUtils.h"
#define RS_L P6OUT&=~BIT1
#define RS_H P6OUT|=BIT1
#define RW_L P6OUT&=~BIT2
#define RW_H P6OUT|=BIT2
#define E_L P6OUT&=~BIT3
#define E_H P6OUT|=BIT3;
#define delay(ms) __delay_cycles((long)(500000*(double)ms/1000.0));
#define dataOut(data) P3OUT=data
void lcdInit()
{
P6DIR |= BIT0 + BIT1 + BIT2 + BIT3;
lcdWriteCom(0x38);
lcdWriteCom(8);
lcdClear();
lcdWriteCom(6);
lcdWriteCom(0x0c);
lcdSetCursor(1, 1);
}
void lcdWriteCom(char com)
{
P3DIR = 0xFF;
E_L;
RS_L;
RW_L;
dataOut(com);
delay(1);
E_H
;
delay(5);
E_L;
}
void lcdWriteData(char data)
{
P3DIR = 0xFF;
E_L;
RS_H;
RW_L;
dataOut(data);
delay(1);
P3OUT = data;
E_H
;
delay(5);
E_L;
}
void lcdClear()
{
lcdWriteCom(0x01);
}
void lcdShowStr(char *str, int start)
{
if (start > 15)
lcdSetCursor(1, start - 16);
else
lcdSetCursor(0, start);
int i = 0;
while (str[i])
{
if (i + start == 16)
lcdSetCursor(1, 0);
lcdWriteData(str[i++]);
}
}
void lcdShowNumber(int number, int position)
{
char *numberStr = (char*) malloc((getNumberLen(number) + 1) * sizeof(char));
numberToStr(number, numberStr);
lcdShowStr(numberStr, position);
free(numberStr);
}
void lcdSetCursor(int row, int column)
{
lcdWriteCom(0x80 | (column + (row ? 0x40 : 0)));
}