1  |  
  | 
2  | #include <stdio.h>
  | 
3  | #include <p18f25k22.h>
  | 
4  | #include <stdlib.h>
  | 
5  | #include "delays.h"
  | 
6  | 
  | 
7  | #include "string.h"
  | 
8  | 
  | 
9  | #pragma config  FOSC = INTIO7   // Internal oscillator block, CLKOUT function on OSC2, nachzulesen in P18F25K22.INC
  | 
10  | #pragma config  PWRTEN = ON     // Power up timer enabled
  | 
11  | #pragma config  BOREN = OFF     // Brown-out Reset disabled in hardware and software
  | 
12  | #pragma config  WDTEN = OFF     // Watch dog timer is always disabled. SWDTEN has no effect
  | 
13  | 
  | 
14  | #pragma code
  | 
15  | 
  | 
16  | #define LCD_PORT        LATB //LATB datapins are PB0 to PB4 (DB4 to DB7 on the DOG)
  | 
17  | #define PIN_ENABLE   LATBbits.LATB0
  | 
18  | #define PIN_RW     LATBbits.LATB3
  | 
19  | #define PIN_RS     LATBbits.LATB2 // set instruction
  | 
20  | 
  | 
21  | 
  | 
22  | //LCD_clock()
  | 
23  | void LCD_clock (void)
  | 
24  | {
 | 
25  | Delay10TCYx(3);
  | 
26  | PIN_ENABLE = 1;
  | 
27  | Delay10TCYx(3);
  | 
28  | PIN_ENABLE = 0;
  | 
29  | }
  | 
30  | //writes 8 bit to the ST7036 in 2 nibbles (2 x 4bit)
  | 
31  | void put_Data_to_Port(char data)
  | 
32  | {
 | 
33  |   char port_buffer = LCD_PORT;
  | 
34  |         
  | 
35  |   //write the high nibble first...
  | 
36  |   char nibble = (data & 0xF0);
  | 
37  |         LCD_PORT |= nibble;
  | 
38  |   //LCD_PORT |= (1 << PIN_ENABLE);
  | 
39  |         
  | 
40  |         Delay100TCYx(10);//_delay_ms(1);
  | 
41  |         
  | 
42  | 
  | 
43  | 
  | 
44  |         //LCD_PORT = port_buffer;
  | 
45  |   Delay100TCYx(10);//_delay_ms(1);
  | 
46  |         
  | 
47  |   //...then the low nibble
  | 
48  |   nibble = (data & 0x0F )<< 4;
  | 
49  |         LCD_PORT |= nibble;
  | 
50  |   //LCD_PORT |= (1 << PIN_ENABLE);
  | 
51  |   Delay100TCYx(10);//_delay_ms(1);
  | 
52  |         
  | 
53  |   //LCD_PORT = port_buffer;
  | 
54  | }
  | 
55  | 
  | 
56  | void LCD_put_Data_out(unsigned char data)
  | 
57  | {
 | 
58  |     PIN_RS = 0;
  | 
59  |     PIN_RW = 0;
  | 
60  |     //TRISB = 0x00;
  | 
61  |     //LCD_PORT &= ~(1 << PIN_RW);
  | 
62  |     //put_Data_to_Port(data);
  | 
63  |     //LCD_clock();
  | 
64  |     put_Data_to_Port(data);
  | 
65  |     LCD_clock();
  | 
66  | }
  | 
67  | 
  | 
68  | //brief Char an display senden; param str einzelnes char
  | 
69  | void LCD_out_char (char str)
  | 
70  | {
 | 
71  |     PIN_RS = 1; //RS auf high(Daten)
  | 
72  |     LCD_PORT |= (1 << PIN_RW);
  | 
73  |     //PIN_RW = 0;
  | 
74  |     if (str == 0xE4) str = 0x84; // wenn "ä" geschrieben werden soll, zeichensatz von LCD benutzen
  | 
75  |     if (str == 0xF6) str = 0x94; // wenn "ö" geschrieben werden soll, zeichensatz von LCD benutzen
  | 
76  |     if (str == 0xFC) str = 0x81; // wenn "ü" geschrieben werden soll, zeichensatz von LCD benutzen
  | 
77  |     if (str == 0xC4) str = 0x8E; // wenn "Ä" geschrieben werden soll, zeichensatz von LCD benutzen
  | 
78  |     if (str == 0xD6) str = 0x99; // wenn "Ö" geschrieben werden soll, zeichensatz von LCD benutzen
  | 
79  |     if (str == 0xDC) str = 0x9A; // wenn "Ü" geschrieben werden soll, zeichensatz von LCD benutzen
  | 
80  |     if (str == 0xB0) str = 0xDF; // wenn "°" geschrieben werden soll, zeichensatz von LCD benutzen
  | 
81  | 
  | 
82  |     LCD_put_Data_out(str); //char einfach auf Port legen
  | 
83  | }
  | 
84  | 
  | 
85  | //brief string an display senden; param string datenstring
  | 
86  | 
  | 
87  | void LCD_out_string(char *string)
  | 
88  | {
 | 
89  |     //PIN_RW = 0;
  | 
90  |     PIN_RS = 1; //RS auf high (Daten)
  | 
91  |     LCD_PORT |= (1 << PIN_RW);
  | 
92  |     while (*string !=0)
  | 
93  |     {
 | 
94  |         LCD_out_char(*string);
  | 
95  |         *string++;
  | 
96  |     }
  | 
97  | }
  | 
98  | void LCD_init(void)
  | 
99  | {
 | 
100  | 
  | 
101  | 
  | 
102  |   Delay10KTCYx(50);//ms(250);    // mehr als 40ms warten
  | 
103  |         
  | 
104  |         LCD_put_Data_out(0x30);//(0x33)
  | 
105  |   Delay10TCYx(200);  //(2 ms)
  | 
106  |         
  | 
107  |   //ST7036(FUNCTION_SET_INIT_0);  // Function set; 8 bit Datenlänge, 2 Zeilen
  | 
108  |         LCD_put_Data_out(0x30);//(0x33)
  | 
109  |   Delay10TCYx(3);    // mehr als 26,3µs warten
  | 
110  | 
  | 
111  |   //ST7036(FUNCTION_SET_INIT_1);  // Function set; 8 bit Datenlänge, 2 Zeilen, Instruction table 1
  | 
112  |   LCD_put_Data_out(0x30);//(0x32)
  | 
113  |         Delay10TCYx(3);    // mehr als 26,3µs warten
  | 
114  | 
  | 
115  |         //ST7036(FUNCTION_SET_INIT_2);  // Function set; 8 bit Datenlänge, 2 Zeilen, Instruction table 1
  | 
116  |         LCD_put_Data_out(0x30);
  | 
117  |         Delay10TCYx(3);    // mehr als 26,3µs warten
  | 
118  | 
  | 
119  |         //ST7036(INSTRUCTION_SET_0);  // Function set; 8 bit Datenlänge, 2 Zeilen, Instruction table 1
  | 
120  |   LCD_put_Data_out(0x20);
  | 
121  |         Delay10TCYx(3);    // mehr als 26,3µs warten
  | 
122  | 
  | 
123  |         //ST7036(INSTRUCTION_SET_1);  // Function set; 8 bit Datenlänge, 2 Zeilen, Instruction table 1
  | 
124  |   LCD_put_Data_out(0x26);
  | 
125  |         Delay10TCYx(3);    // mehr als 26,3µs warten
  | 
126  | 
  | 
127  |   //ST7036(BIAS_SET);  // Bias Set; BS 1/5; 3 zeiliges Display /1d
  | 
128  |   LCD_put_Data_out(0x14);
  | 
129  |         Delay10TCYx(3);    // mehr als 26,3µs warten
  | 
130  | 
  | 
131  |   //ST7036(CONTRAST_SET);  // Kontrast C3, C2, C1 setzen /7c
  | 
132  |   LCD_put_Data_out(0x55);//(0x7F)
  | 
133  |         Delay10TCYx(3);    // mehr als 26,3µs warten
  | 
134  | 
  | 
135  |   //ST7036(POWER_CONTROL);  // Booster aus; Kontrast C5, C4 setzen /50
  | 
136  |   LCD_put_Data_out(0x6D);// (0x6D)
  | 
137  |         Delay10TCYx(3);    // mehr als 26,3µs warten
  | 
138  | 
  | 
139  |   //ST7036(FOLLOWER_CONTROL);  // Spannungsfolger und Verstärkung setzen /6c
  | 
140  |   LCD_put_Data_out(0x78);// (0x6A)
  | 
141  |         Delay10TCYx(3);  // mehr als 200ms warten !!!
  | 
142  | 
  | 
143  |   //ST7036(DISPLAY_ON);  // Display EIN, Cursor EIN, Cursor BLINKEN /0f
  | 
144  |   LCD_put_Data_out(0x0F); // (0x0F)
  | 
145  |         Delay10TCYx(3);    // mehr als 26,3µs warten
  | 
146  | 
  | 
147  |   //ST7036(CLEAR_DISPLAY);  // Display löschen, Cursor Home
  | 
148  |   LCD_put_Data_out(0x01);
  | 
149  |         Delay10TCYx(200);  //
  | 
150  | 
  | 
151  |   //ST7036(ENTRY_MODE);  // Cursor Auto-Increment
  | 
152  |         LCD_put_Data_out(0x06);
  | 
153  |         //Delay10KTCYx(3);
  | 
154  | }
  | 
155  | 
  | 
156  | void main(void)
  | 
157  | {
 | 
158  |          
  | 
159  |         PORTB = 0x00;
  | 
160  |         TRISB = 0x00;
  | 
161  |         ANSELB = 0x00;
  | 
162  |         INTCON = 0x00;
  | 
163  | 
  | 
164  |   LCD_init;
  | 
165  |        
  | 
166  |         //LCD_put_Data_out(0x43);
  | 
167  |         
  | 
168  | //        Delay10TCYx(100);
  | 
169  | //  LCD_out_char('0xE4');
 | 
170  | //        while(1)
  | 
171  | //        {
 | 
172  | //            Nop();
  | 
173  | //        }
  | 
174  | //
  | 
175  | 
  | 
176  | }
  |