-
Notifications
You must be signed in to change notification settings - Fork 0
/
lcd.c
84 lines (78 loc) · 1.76 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
//Código:
//
// LCD.C
//
// Autor: Juan Nicola
//
//
// Rutinas para el manejo de un display Hitachi 44780 compatible.
//-------------------------------------------------------------------------------------------------
#include <xc.h>
#include "delay.h"
#include "lcd.h"
void lcd_send_quartet( char mode, char dato )
{
LCD_RS = mode;
PORTD = dato | (PORTD & 0x0f) ;
LCD_ENABLE = 1;
delay_ms(1);
LCD_ENABLE = 0;
}
void lcd_send( char mode, const char dato )
{
char dat = dato;
LCD_RS = mode;
dat = dato & 0xf0;
PORTD = dat | (PORTD & 0x0f) ;
LCD_ENABLE = 1;
delay_ms(1);
LCD_ENABLE = 0;
dat = ((dato<<4)& 0xf0);
PORTD = dat | (PORTD & 0x0f) ;
LCD_ENABLE = 1;
delay_ms(1);
LCD_ENABLE = 0;
delay_ms(1);
}
void lcd_init (void)
{
LCD_DATA_TRIS &= 0x00;
LCD_DATA = 0x00;
delay_ms(20);
lcd_send_quartet(LCD_COMMANDMODE, LCD_RESET);
delay_ms(10);
lcd_send_quartet(LCD_COMMANDMODE, LCD_RESET);
delay_ms(10);
lcd_send_quartet(LCD_COMMANDMODE, LCD_RESET);
delay_ms(10);
lcd_send_quartet(LCD_COMMANDMODE, LCD_D4_BIT_CONF);
delay_ms(10);
lcd_send(LCD_COMMANDMODE, LCD_D4_BIT);
delay_ms(10);
lcd_send(LCD_COMMANDMODE, LCD_CLEAR);
delay_ms(10);
lcd_send(LCD_COMMANDMODE, LCD_CURSOR_OFF);
delay_ms(10);
lcd_send(LCD_COMMANDMODE, LCD_NORMAL);
delay_ms(10);
lcd_send(LCD_COMMANDMODE, LCD_DIS_ON);
delay_ms(10);
}
void lcd_message (const char * mess )
{
while ( *mess )
{
lcd_send(LCD_CHARMODE, *mess ) ;
mess++ ;
}
}
void lcd_show_lines (const char *line1, const char *line2)
{
lcd_send (LCD_COMMANDMODE, LCD_CLEAR);
lcd_send (LCD_COMMANDMODE, LCD_LINE1);
lcd_message (line1);
lcd_send (LCD_COMMANDMODE, LCD_LINE2);
delay_ms (100);
lcd_message (line2);
delay_ms (500);
}