-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlcd.c
84 lines (71 loc) · 1.41 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
#include <Arduino.h>
#include <avr/io.h>
#include <util/delay.h>
#include <stdio.h>
#include "lcd.h"
void init_lcd(void);
void moveto(unsigned char, unsigned char);
void stringout(char *);
void writecommand(unsigned char);
void writedata(unsigned char);
void writenibble(unsigned char);
void init_lcd() {
DDRB |= 0b00000011 ;
DDRD |= 0b11110000 ;
_delay_ms(15);
writecommand(0x03);
_delay_ms(5);
writecommand(0x03) ;
_delay_us(120);
writecommand(0x03) ;
writecommand(0x02) ;
_delay_ms(2);
writecommand(0x28);
_delay_ms(2);
writecommand(0x0f);
_delay_ms(2);
_delay_ms(25);
writecommand(0x01);
}
void moveto(unsigned char row, unsigned char col) {
if(row==0) {
writecommand(0x80+col);
}
if(row==1) {
writecommand(0xc0+col);
}
}
void stringout(char *str) {
do {
writedata(*str);
str++;
} while(*str!= '\0');
}
void writecommand(unsigned char cmd) {
unsigned char temp;
PORTB&=~(0x01);
temp=cmd&0xF0;
writenibble(temp);
temp=cmd&0x0F;
temp=temp<<4;
writenibble(temp);
_delay_ms(3);
}
void writedata(unsigned char dat) {
unsigned char temp;
PORTB|=0x01;
temp=dat&0xF0;
writenibble(temp);
temp=dat&0x0F;
temp=temp<<4;
writenibble(temp);
_delay_ms(3);
}
void writenibble(unsigned char lcdbits) {
PORTD |= lcdbits ;
PORTB &= ~(0x02);
_delay_us(1);
PORTB |= (0x02);
_delay_ms(1);
PORTB &= ~(0x02);
}