-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlcd.h
97 lines (67 loc) · 1.36 KB
/
lcd.h
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
#include<avr/io.h>
#include<util/delay.h>
#define E 2
void enable(){
PORTC|=(1<<E);
_delay_ms(1);
PORTC&=~(1<<E);
_delay_ms(1);
}
void lcd_cmd(unsigned char cmd){
PORTC=0x02|(cmd&0xf0); // transmit higher nibble of commands
enable();
PORTC=0x02|((cmd&0x0f)<<4); // transmit lower nibble of commands
enable();
}
void lcd_data(unsigned char data){
PORTC=0x03|(data&0xf0); // transmit higher nibble of data
enable();
PORTC=0x03|((data&0x0f)<<4); // transmit lower nibble of data
enable();
}
void lcd_init(){
DDRC=0xff; // PORTC in output mode
_delay_ms(15);
lcd_cmd(0x03); // Set LCD output to 4 bit
_delay_ms(45);
lcd_cmd(0x02); // cmd to return home
_delay_ms(15);
lcd_cmd(0x01); // cmd for clear screen
lcd_cmd(0x28); // cmd to operate lcd in 4 bit mode
lcd_cmd(0x0f); // cmd for cursor blinking
lcd_cmd(0x80); // cmd to return cursor to first line
}
void lcd_string(unsigned char *ptr){
while(*ptr!='\0'){
lcd_data(*ptr);
ptr++;
}
}
void gotoxy1(unsigned char pos){
if(pos<16)
lcd_cmd(0x80+pos);
else{
lcd_string("Position 0-15");
_delay_ms(2000);
lcd_cmd(0x01);
}
}
void gotoxy2(unsigned char pos){
if(pos<16)
lcd_cmd(0xc0+pos);
else{
lcd_string("Position 0-15");
_delay_ms(2000);
lcd_cmd(0x01);
}
}
void lcd_showvalue(int n){
lcd_data(n+48);
}
void lcd_num(unsigned int n){
unsigned char buff[30];
sprintf(buff,"%d",n);
lcd_string(buff);
}
void lcd_exit(){
}