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] problem in LCD screen showing the menu

Status
Not open for further replies.

CSIW

Newbie level 5
Joined
Jan 6, 2015
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
52
My LCD screen is EB-005-00-3

EB005-72-3.jpg

and here is my code for drink menu:

Code:
#include "LCDdrive.h"                        //LCD header file

void MainMenu(void);
void ColdMenu(void);
void HotMenu(void);
char themain=1;
char cold=1;
char hot=1;


void main()
{
 TRISD=0x9f;
 TRISB=0x00;
 PORTB=0x00;
 PORTD=0x00;
 while(1)
 {
  Mainmenu();
 }
}

void MainMenu()
{
 LCD_initialise();
 while(1)
 {
  if(themain==1)
  {
   LCD_cursor(0,0);
   LCD_puts(">Cold drinks");
   LCD_cursor(0,1);
   LCD_puts(" Hot drinks");
  }
  if(themain==2)
  {
   LCD_cursor(0,0);
   LCD_puts(" Cold drinks");
   LCD_cursor(0,1);
   LCD_puts(">Hot drinks");
  }
  if(PORTD.B0==1)
  {
   themain=1;
  }
  if(PORTD.B1==1)
  {
   themain=2;
  }
  if(PORTD.B2==1&&themain==1)
  {
   ColdMenu();
  }
  if(PORTD.B2==1&&themain==2)
  {
   HotMenu();
  }

}
}


void ColdMenu()
{
 LCD_initialise();
 while(1)
 {
  if(cold==1)
  {
   LCD_cursor(0,0);
   LCD_puts(">Orange Juice");
   LCD_cursor(0,1);
   LCD_puts(" Fizzy Drink");
  }

  if(cold==2)
  {
   LCD_cursor(0,0);
   LCD_puts(" Orange Juice");
   LCD_cursor(0,1);
   LCD_puts(">Fizzy Drink");
  }

  if(cold==3)
  {
   LCD_cursor(0,0);
   LCD_puts(" Fizzy Drink ");
   LCD_cursor(0,1);
   LCD_puts(">Water      ");
  }

  if(PORTD.B0==1)
  {
   cold=cold-1;
   if(cold<1)
   {
    cold=1;
   }
  }

  if(PORTD.B1==1)
  {
   cold=cold+1;
   if(cold>3)
   {
    cold=3;
   }
  }
}
}

void HotMenu()
{
 LCD_initialise();
 while(1)
 {
  if(hot==1)
  {
   LCD_cursor(0,0);
   LCD_puts(">Tea      ");
   LCD_cursor(0,1);
   LCD_puts(" Coffee");
  }

  if(hot==2)
  {
   LCD_cursor(0,0);
   LCD_puts(" Tea      ");
   LCD_cursor(0,1);
   LCD_puts(">Coffee");
  }

  if(hot==3)
  {
   LCD_cursor(0,0);
   LCD_puts(">chocolate");
   LCD_cursor(0,1);
   LCD_puts(" soup  ");
  }

  if(hot==4)
  {
   LCD_cursor(0,0);
   LCD_puts(" chocolate");
   LCD_cursor(0,1);
   LCD_puts(">soup  ");
  }

  if(PORTD.B0==1)
  {
   hot=hot-1;
   if(hot<1)
   {
    hot=1;
   }
  }

  if(PORTD.B1==1)
  {
   hot=hot+1;
   if(hot>4)
   {
    hot=4;
   }
  }
}
}

my problem is when I get into the second menu which is cold drink menu / hot drink menu,
the LCD shows muddle / garbled.

I am so sure that they can run separately but not when I combine them:bang:

Can anyone help me clear my mind that where is the problem in my code? :cry:
 

PIC16F device ? Getting IRP bit must be set manually to access xyz variable in messages windows ? If yes, change to PIC18F.
 
  • Like
Reactions: zhila

    zhila

    Points: 2
    Helpful Answer Positive Rating
Thanks for helping!

But what should I do if I can't change it?

It is my assignment and those microcontrollers are fixed, not possible to be changed.

I am asked to create this program for P16F877A, but I am stuck on this step.

Is it possible to solve the problem except changing devices?
 

You have initialized themain as 1 before calling the main function and when the program changes the value of themain based on the input from portd,it does not have any effect on the previously set value of themain.
This code should work.Make these changes and let us know what happens.

Code:
{
  
  if(PORTD.B0==1)
  {
   themain=1;
  }
  if(PORTD.B1==1)
  {
   themain=2;
  }
  if(themain==1)
  {
   LCD_cursor(0,0);
   LCD_puts(">Cold drinks");
   LCD_cursor(0,1);
   LCD_puts(" Hot drinks");
  } 
  if(themain==2)
  {
   LCD_cursor(0,0);
   LCD_puts(" Cold drinks");
   LCD_cursor(0,1);
   LCD_puts(">Hot drinks");
  }
  if(PORTD.B2==1&&themain==1)
  {
   ColdMenu();
  }
  if(PORTD.B2==1&&themain==2)
  {
   HotMenu();
 }

 }
 

Which Compiler are you using ?

Try like this for all strings. Place all strings in ROM by declaring them as const char type.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
const char part1[] = "some text";
char msg[20];
 
// copy const to ram string
char * CopyConst2Ram(char * dest, const char * src){
  char * d ;
  d = dest;
  for(;*dest++ = *src++;)
    ;
  return d;
}
 
void main(){
 
  Lcd_puts(CopyConst2Ram(msg, part1)); 
 
}

 

You have initialized themain as 1 before calling the main function and when the program changes the value of themain based on the input from portd,it does not have any effect on the previously set value of themain.
This code should work.Make these changes and let us know what happens.

Code:
{
  
  if(PORTD.B0==1)
  {
   themain=1;
  }
  if(PORTD.B1==1)
  {
   themain=2;
  }
  if(themain==1)
  {
   LCD_cursor(0,0);
   LCD_puts(">Cold drinks");
   LCD_cursor(0,1);
   LCD_puts(" Hot drinks");
  } 
  if(themain==2)
  {
   LCD_cursor(0,0);
   LCD_puts(" Cold drinks");
   LCD_cursor(0,1);
   LCD_puts(">Hot drinks");
  }
  if(PORTD.B2==1&&themain==1)
  {
   ColdMenu();
  }
  if(PORTD.B2==1&&themain==2)
  {
   HotMenu();
 }

 }



Thanks for helping!

But there is no different between your code and my code, the main menu is still working.

The problem is the second menu which is after the choice of "cold drink" and "hot drink".

I know it is hard to understand what I mean, please give me 10 minutes for taking picture for you :thumbsup:

- - - Updated - - -

Thanks for helping!

I understand what you mean but I can't understand the code:cry:

This is only a half gone for the assignment, I will add more choices in the problem, is that mean I will face the same problem if I don't change the style of using LCD_puts?
 

my problem is when I get into the second menu which is cold drink menu / hot drink menu,
the LCD shows muddle / garbled.
Yes, because you don't clear the display, only overwrite the existing text, but not until end of line.

You should consider how the display works.
 
I had think about that and I tried run each menu separately and they are success.

The word that couldn't be cover by other word, I used space " " for doing it.


sorry about I can't show the picture now, but I will upload it as soon as I can (before 8 p.m.)


Thanks for helping!!

- - - updated - - -

sorry I am the newbie of using and writing program, can you please give me an example how to use this function?

It seems it can really fix my problem!!!! :thumbsup:
 
Last edited by a moderator:

Here is my problem


the MainMenu is working :
IMG_2290.JPGIMG_2291.JPG

but when I get into ColdMenu, the choice "water" changes to be "Fizzy drink" :
IMG_2292.JPGIMG_2293.JPG

if I build a exactly same program without combine with MainMenu and HotMenu, it is working :
IMG_2296.JPG

There is the same problem with HotMenu when I combine them...:-(
 

Hi same issue come to me as well
which compiler are you using
 


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
#include "LCDdrive.h"                        //LCD header file
 
void MainMenu(void);
void ColdMenu(void);
void HotMenu(void);
char themain=1;
char cold=1;
char hot=1;
 
 
void main()
{
 TRISD=0x9f;
 TRISB=0x00;
 PORTB=0x00;
 PORTD=0x00;
 LCD_initialise();
 while(1)
 {
  Mainmenu();
 }
}
 
void MainMenu()
{
 
 
  if(themain==1)
  {
   LCD_cursor(0,0);
   LCD_puts(">Cold drinks");
   LCD_cursor(0,1);
   LCD_puts(" Hot drinks");
  }
  if(themain==2)
  {
   LCD_cursor(0,0);
   LCD_puts(" Cold drinks");
   LCD_cursor(0,1);
   LCD_puts(">Hot drinks");
  }
  if(PORTD.B0==1)
  {
   themain=1;
  }
  if(PORTD.B1==1)
  {
        Lcd_clear(); //make clear previous display before type new display
   themain=2;
  }
  if(PORTD.B2==1&&themain==1)
  {
   ColdMenu();
  }
  if(PORTD.B2==1&&themain==2)
  {
   HotMenu();
  }
 
 
}
 
 
void ColdMenu()
{
 
  if(cold==1)
  {
   LCD_cursor(0,0);
   LCD_puts(">Orange Juice");
   LCD_cursor(0,1);
   LCD_puts(" Fizzy Drink");
  }
 
  else if(cold==2)
  {
   LCD_cursor(0,0);
   LCD_puts(" Orange Juice");
   LCD_cursor(0,1);
   LCD_puts(">Fizzy Drink");
  }
 
  else if(cold==3)
  {
   LCD_cursor(0,0);
   LCD_puts(" Fizzy Drink ");
   LCD_cursor(0,1);
   LCD_puts(">Water      ");
  }
 
  if(PORTD.B0==1)
  {
   cold=cold-1;
        Lcd_clear(); //make clear previous display before type new display
   if(cold<1)
   {
    cold=1;
   }
  }
 
  if(PORTD.B1==1)
  {
   cold=cold+1;
        Lcd_clear(); //make clear previous display before type new display
  
   if(cold>3)
   {
    cold=3;
   }
  }
}
 
 
void HotMenu()
{
 
 
  if(hot==1)
  {
   LCD_cursor(0,0);
   LCD_puts(">Tea      ");
   LCD_cursor(0,1);
   LCD_puts(" Coffee");
  }
 
  else if(hot==2)
  {
   LCD_cursor(0,0);
   LCD_puts(" Tea      ");
   LCD_cursor(0,1);
   LCD_puts(">Coffee");
  }
 
  else if(hot==3)
  {
   LCD_cursor(0,0);
   LCD_puts(">chocolate");
   LCD_cursor(0,1);
   LCD_puts(" soup  ");
  }
 
 else if(hot==4)
  {
   LCD_cursor(0,0);
   LCD_puts(" chocolate");
   LCD_cursor(0,1);
   LCD_puts(">soup  ");
  }
 
  if(PORTD.B0==1)
  {
   hot=hot-1;
        Lcd_clear(); //make clear previous display before type new display
  
   if(hot<1)
   {
    hot=1;
   }
  }
 
  if(PORTD.B1==1)
  {
   hot=hot+1;
        Lcd_clear(); //make clear previous display before type new display
   
   if(hot>4)
   {
    hot=4;
   }
  }
}



replace the lcd_clear();function where i mentioned Lcd_clear(); and test and see the result.
 

I am using PIC16F877A
 

sorry it is still not working, and it couldn't go into the ColdMenu or HotMenu:cry:
 

Code:
 char subcount;
 if(PORTD.B2)
{
   subcount++;
if(subcount>2) subcount=0;

}
if(subcount==1)
{
 if(themain==1)
  {
   ColdMenu();
  }
}
if(subcount==2)
{
  if(themain==2)
  {
   HotMenu();
  }
}

try this one
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top