/[H8]/trunk/PIC/Torbens/mylcd.c
ViewVC logotype

Contents of /trunk/PIC/Torbens/mylcd.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 101 - (show annotations) (download)
Fri May 25 14:20:54 2007 UTC (17 years ago) by torben
File MIME type: text/plain
File size: 2283 byte(s)
Trying to implement this !"#€%&/()= LCD module
1
2 #include <pic18.h>
3 #include "mylcd.h"
4
5
6 #include "delay.h"
7 #include "MyI2C.h"
8
9
10 bit enable0;
11 bit enable1;
12
13 void mylcd_strobe(void)
14 {
15 if (enable0)
16 LCD_EN0 = 1;
17 if (enable1)
18 LCD_EN1 = 1;
19
20 asm("nop");
21 asm("nop");
22 DelayUs(1);
23
24 if (enable0)
25 LCD_EN0 = 0;
26
27 if (enable1)
28 LCD_EN1 = 0;
29 }
30
31 void mylcd_write_byte(unsigned char data)
32 {
33 StartI2C(LCD_IC);
34 WriteI2CByte( data );
35 StopI2C();
36 DelayUs(4); //I2C spec's siger min 4.7 uSec mellem stop og næste start
37 }
38
39
40 void mylcd_cmd(unsigned char c)
41 {
42 LCD_WAIT; // may check LCD busy flag, or just delay a little, depending on lcd.h
43
44 mylcd_write_byte(c);
45 mylcd_strobe();
46 }
47
48 void mylcd_data(unsigned char c)
49 {
50 LCD_WAIT; // may check LCD busy flag, or just delay a little, depending on lcd.h
51
52 LCD_RS0 = 1;
53 LCD_RS1 = 1;
54 mylcd_cmd(c);
55 LCD_RS0 = 0;
56 LCD_RS1 = 0;
57 }
58
59
60
61
62 void mylcd_init(void)
63 {
64 char init_value = 0x3F;
65 mylcd_write_byte(0);
66
67 enable0 = 1;
68 enable1 = 1;
69
70 LCD_RS0 = 0;
71 LCD_EN0 = 0;
72 LCD_RW0 = 0;
73 LCD_RS0_TRIS = OUTPUT_PIN;
74 LCD_EN0_TRIS = OUTPUT_PIN;
75 LCD_RW0_TRIS = OUTPUT_PIN;
76
77 LCD_RS1 = 0;
78 LCD_EN1 = 0;
79 LCD_RW1 = 0;
80 LCD_RS1_TRIS = OUTPUT_PIN;
81 LCD_EN1_TRIS = OUTPUT_PIN;
82 LCD_RW1_TRIS = OUTPUT_PIN;
83
84 /*
85 DelayMs(15);
86 mylcd_write_byte(init_value);
87 mylcd_strobe();
88 DelayMs(5);
89 mylcd_write_byte(init_value);
90 mylcd_strobe();;
91 DelayUs(200);
92 mylcd_write_byte(init_value);
93 mylcd_strobe();
94 */
95
96 //DEM20485 init
97
98 DelayMs(35); //Make sure LCD is initialized
99 mylcd_write_byte(0b00110000);
100 mylcd_strobe();
101 DelayUs(50);
102 mylcd_write_byte(0b00001111);
103 mylcd_strobe();
104 DelayUs(50);
105 mylcd_write_byte(0b00000001);
106 mylcd_strobe();
107 DelayMs(2);
108 mylcd_write_byte(0b00000110);
109 mylcd_strobe();
110 DelayUs(50);
111 /*
112
113
114
115 mylcd_cmd(0x38);
116
117 mylcd_cmd(0xF); //Display On, Cursor On, Cursor Blink
118 mylcd_cmd(0x1); //Display Clear
119 mylcd_cmd(0x6); //Entry Mode
120
121 mylcd_cmd(0x80); //Initialize DDRAM address to zero
122 /*
123 mylcd_cmd(0x02); //Home
124
125 */
126 }
127
128
129
130 void mylcd_enable_lcd0(unsigned char enable)
131 {
132 if (enable)
133 enable0 = 1;
134 else
135 enable0 = 0;
136 }
137
138 void mylcd_enable_lcd1(unsigned char enable)
139 {
140 if (enable)
141 enable1 = 1;
142 else
143 enable1 = 0;
144 }

  ViewVC Help
Powered by ViewVC 1.1.20