-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLCD.c
More file actions
executable file
·91 lines (83 loc) · 1.58 KB
/
Copy pathLCD.c
File metadata and controls
executable file
·91 lines (83 loc) · 1.58 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
#include <arch/nxp/lpc23xx.h>
#include "LCD.h"
/* Espera t milisegundos */
void espera(unsigned int t)
{
unsigned int tf;
tf = T0TC + t; /* tf = Valor futuro do T0TC */
while(tf != T0TC); /* espera ate que tf==T0TC */
}
void LCDcomando(int c)
{
FIO3PIN0 = c;
FIO2CLR = LCD_RS;
FIO2SET = LCD_EN;
FIO2CLR = LCD_EN;
espera(20);
}
void LCDputchar(int c)
{
FIO3PIN0 = c;
FIO2SET = LCD_RS;
FIO2SET = LCD_EN;
FIO2CLR = LCD_EN;
espera(8);
}
void LCDinit(void)
{
FIO3DIR |= 0xff; /* P3.0 a P3.7 como saidas (dados do LCD) */
FIO2DIR |= (LCD_RS | LCD_EN);
FIO2CLR = LCD_EN;
espera(20);
LCDcomando(0x38);
LCDcomando(1);
LCDcomando(0x0c);
}
void LCDputs(char *s)
{
while(*s) LCDputchar(*s++);
}
/* Escreve numero decimal de 2 digitos */
void escreve2digs(int x)
{
LCDputchar((x/10) + '0'); /* Escreve dezena */
LCDputchar((x%10) + '0'); /* Escreve unidade */
}
/* Escreve um numero decimal */
void escreve_num(int num)
{
char digs[16];
int nd=0;
if(num<0)
{
LCDputchar('-'); num=-num;
}
do {
digs[nd++]= (num % 10) + '0';
num /= 10;
} while(num);
while(nd--) LCDputchar(digs[nd]);
}
/* escreve um float com 1 casa apos a virgula */
void escreve_float(float f)
{
char digs[16];
int nd = 0;
int num = (int) (f * 10); // Cast to int with one decimal point
if(num < 0)
{
LCDputchar('-'); num =- num;
}
do {
digs[nd++]= (num % 10) + '0';
num /= 10;
} while(num);
while(nd--)
{
if(nd == 0)
{
LCDputchar('.'); // Insere um ponto antes do ultimo digito
}
LCDputchar(digs[nd]);
}
}