You are on page 1of 2

1 #include "lcd.

h"
2
3
4 void LCD_init(void)
5 {
6 PCF8574_init();
7 delay_ms(100);
8
9 bl_state = BL_ON;
10 data_value = 0x04;
11 PCF8574_write(data_value);
12
13 delay_ms(10);
14
15 LCD_send(0x33, CMD);
16 LCD_send(0x32, CMD);
17
18 LCD_send((_4_pin_interface | _2_row_display | _5x7_dots), CMD);
19 LCD_send((display_on | cursor_off | blink_off), CMD);
20 LCD_send((clear_display), CMD);
21 LCD_send((cursor_direction_inc | display_no_shift), CMD);
22 }
23
24
25 void LCD_toggle_EN(void)
26 {
27 data_value |= 0x04;
28 PCF8574_write(data_value);
29 delay_ms(dly);
30 data_value &= 0xF9;
31 PCF8574_write(data_value);
32 delay_ms(dly);
33 }
34
35
36 void LCD_send(unsigned char value, unsigned char mode)
37 {
38 switch(mode)
39 {
40 case CMD:
41 {
42 data_value &= 0xF4;
43 break;
44 }
45 case DAT:
46 {
47 data_value |= 0x01;
48 break;
49 }
50 }
51
52 switch(bl_state)
53 {
54 case BL_ON:
55 {
56 data_value |= 0x08;
57 break;
58 }
59 case BL_OFF:
60 {
61 data_value &= 0xF7;
62 break;
63 }
64 }
65
66 PCF8574_write(data_value);
67 LCD_4bit_send(value);
68 delay_ms(dly);
69 }
70
71
72 void LCD_4bit_send(unsigned char lcd_data)
73 {
74 unsigned char temp = 0x00;
75
76 temp = (lcd_data & 0xF0);
77 data_value &= 0x0F;
78 data_value |= temp;
79 PCF8574_write(data_value);
80 LCD_toggle_EN();
81
82 temp = (lcd_data & 0x0F);
83 temp <<= 0x04;
84 data_value &= 0x0F;
85 data_value |= temp;
86 PCF8574_write(data_value);
87 LCD_toggle_EN();
88 }
89
90
91 void LCD_putstr(char *lcd_string)
92 {
93 do
94 {
95 LCD_putchar(*lcd_string++);
96 }while(*lcd_string != '\0') ;
97 }
98
99
100 void LCD_putchar(char char_data)
101 {
102 if((char_data >= 0x20) && (char_data <= 0x7F))
103 {
104 LCD_send(char_data, DAT);
105 }
106 }
107
108
109 void LCD_clear_home(void)
110 {
111 LCD_send(clear_display, CMD);
112 LCD_send(goto_home, CMD);
113 }
114
115
116 void LCD_goto(unsigned char x_pos,unsigned char y_pos)
117 {
118 if(y_pos == 0)
119 {
120 LCD_send((0x80 | x_pos), CMD);
121 }
122 else
123 {
124 LCD_send((0x80 | 0x40 | x_pos), CMD);
125 }
126 }

You might also like