CSIW
Newbie level 5
- Joined
- Jan 6, 2015
- Messages
- 8
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 52
#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;
}
}
}
}
{
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();
}
}
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(); } }
Yes, because you don't clear the display, only overwrite the existing text, but not until end of line.my problem is when I get into the second menu which is cold drink menu / hot drink menu,
the LCD shows muddle / garbled.
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; } } }
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();
}
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?