Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] Interface LCD between pic microcontroller and mikroC

Status
Not open for further replies.

sumonpic10

Newbie level 5
Newbie level 5
Joined
Jul 30, 2016
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
99
Hi, I try to program the pic microcontroller according my controller. There I used 3 button for enter the program menu, change the program number. When press the prog_button then enter the program. And press forw_button the change the number also. But when i press the revs_button then came random display. Below my code.. I don't understand where is mistake. Please help me


Best regard
Sumon Ahmed




Code C - [expand]
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections
 
 
sbit prog_button      at portc.f0;  // button interface with portC
sbit enter_button     at portc.f1;
sbit forw_button      at portc.f2;
sbit revs_button      at portc.f3;
 
 
 
 
 
char main_1[] = "MAIN MENU";      // string character
char prog_1[] = "1 program";
char prog_2[] = "2 program";
char prog_3[] = "3 program";
char blank_1[] = "          ";    // blank display
 
 
int prog_code = 0;        // variable declared
 
 
 
 
// program function //////
 
 
prog_init()
 
{
 
   while(prog_code==1)
 
   {
    
    if(forw_button == 1) && (prog_code ==1)     // if enter button press /////
 
    {
      
      Lcd_Cmd(_LCD_CLEAR);  // Clear display
      prog_code = 2;        // prog_code value changed
      delay_ms(200);    // delay time 200ms
 
    }
 
 
 
 
 
    Lcd_Out(1,1,main_1);
    Lcd_Out(2,1,prog_1);
    Lcd_Out(3,1,prog_2);
    Lcd_Out(4,1,prog_3);
    delay_ms(300);
    Lcd_Out(1,1,main_1);
    Lcd_Out(2,1,blank_1);
    Lcd_Out(3,1,prog_2);
    Lcd_Out(4,1,prog_3);
    delay_ms(300);
 
 
 
 
 
 
   }
 
 
    
    while(prog_code==2)
 
   {
    
    if(forw_button == 1) && (prog_code ==2)     // if enter button press /////
 
    {
      
      Lcd_Cmd(_LCD_CLEAR);  // Clear display
      prog_code = 3;        // prog_code value changed
      delay_ms(200);    // delay time 200ms
 
    }
 
 
    if(revs_button == 1) && (prog_code ==2)     // if enter button press /////
 
    {
      
      Lcd_Cmd(_LCD_CLEAR);  // Clear display
      prog_code = 1;        // prog_code value changed
      delay_ms(200);    // delay time 200ms
 
    }
 
 
 
 
 
    Lcd_Out(1,1,main_1);
    Lcd_Out(2,1,prog_1);
    Lcd_Out(3,1,prog_2);
    Lcd_Out(4,1,prog_3);
    delay_ms(300);
    Lcd_Out(1,1,main_1);
    Lcd_Out(2,1,prog_1);
    Lcd_Out(3,1,blank_1);
    Lcd_Out(4,1,prog_3);
    delay_ms(300);
 
 
 
 
 
 
   }
 
 
 
    while(prog_code==3)
 
   {
    
    if(forw_button == 1) && (prog_code ==3)     // if enter button press /////
 
    {
      
      Lcd_Cmd(_LCD_CLEAR);  // Clear display
      prog_code = 0;    // prog_code value changed
      delay_ms(200);    // delay time 200ms
 
    }
 
 
    if(revs_button == 1) && (prog_code ==3)     // if enter button press /////
 
    {
      
      Lcd_Cmd(_LCD_CLEAR);  // Clear display
      prog_code = 2;        // prog_code value changed
      delay_ms(200);    // delay time 200ms
 
    }
 
 
 
 
 
    Lcd_Out(1,1,main_1);
    Lcd_Out(2,1,prog_1);
    Lcd_Out(3,1,prog_2);
    Lcd_Out(4,1,prog_3);
    delay_ms(300);
    Lcd_Out(1,1,main_1);
    Lcd_Out(2,1,prog_1);
    Lcd_Out(3,1,prog_2);
    Lcd_Out(4,1,blank_1);
    delay_ms(300);
 
 
 
 
 
 
   }
 
 
 
 
 
 
 
}
 
 
 
 
 
 
 
 
 
void main()
{
    TRISB = 0;
    PORTB = 0xFF;
    ANSEL = 0; // Configure AN pins as digital I/O
    ANSELH = 0;
 
    Lcd_Init(); // Initialize LCD
    Lcd_Cmd(_LCD_CLEAR); // Clear display
    Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
 
 
    while(1)
 
    {
 
      
    Lcd_Out(1,1," programmable");
    Lcd_Out(2,1," digital controller ");
 
 
 
 
 
        if(prog_button == 1)      // if button is press
 
        {
           Lcd_Cmd(_LCD_CLEAR);     // Clear display
           prog_init();     // call a function
           prog_code = 1;       // prog_code value changed
           delay_ms(200);   // delay time 200ms
        }
 
 
 
}

 
Last edited by a moderator:

MikroC has some strange quirks but from your description, it hasn't stored the text correctly, try changing the lines to:
Code:
char *main_1 = "MAIN MENU"; // string character
char *prog_1 = "1 program";
char *prog_2 = "2 program";
char *prog_3 = "3 program";
char *blank_1 = " "; // blank display

I can't confirm if that will fix it because I don't use that compiler.

Brian.
 

hello,



for me

Code:
char main_1[] = "MAIN MENU"; // string character
char prog_1[] = "1 program";
char prog_2[] = "2 program";
char prog_3[] = "3 program";
char blank_1[] = " ";	// blank display

seem correct with MikroC

What MCU are you using ?

Waht inside the message Windows ?
IPR_Bit problems can occurs wit PIC16F
because use of a lot of RAM
better to use constant to define your messages ..
 
Dear All, I used pic16f887 mcu & 20x4 lcd. . And mikroC compiler build without any errors. But problem facing when I simulate in proteus 8.6 or practical in circuit.

Thanks
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top