Justinho27
Newbie level 5
- Joined
- Apr 24, 2014
- Messages
- 9
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 55
Hi, yesterday i have made some improvements in my code and solved some problems. At the moment my code looks like this:
Main problem now is that result im getting now on my LCD is blinking (Delay 2000ms) text: https://clip2net.com/s/7isFai.
When i remove this part from my code:
Result on LCD is this: https://clip2net.com/s/7isHtr.
And when i remove this part of code:
I get this result: https://clip2net.com/s/7isJnk.
So, why those parts of code doesn't work together? lol Maby it's some kind of lack of MCU's resources? Or LCD resources, lol... And, also, when im trying to place more "Lcd_Out" statement rather than "Lcd_Chr" its also doesnt work properly.
Anybody knows anything about this? Please help me
Attaching my mikroC project files:
Code:
// 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
unsigned char ch1, ch2, ch3, ch4, ch5, ch6, ch7, ch8, ch9, ch10, ch11, ch12, ch13, ch14;
unsigned int adc_rd0, adc_rd1, adc_rd2, adc_rd3, LCDType, oldType;
char *text, *text3, *text1, *text2, *transfering, *space;
long et0, et1, et2, et3, kg1, kg2, skirtumas1, skirtumas2, oldet0, oldet2;
int i;
void LCDOutput(int Type) {
if (oldType != LCDType) {
Lcd_Cmd(_LCD_CLEAR);
}
if (Type <= 2) {
Lcd_Out(1,3,transfering);
} else {
text1 = "L/H:";
Lcd_Out(1,1,text1);
text2 = "R/H:";
Lcd_Out(2,1,text2);
}
switch (Type) {
case 1:
Lcd_Out(2,4,"R/H -> L/H");
break;
case 2:
Lcd_Out(2,4,"R/H <- L/H");
break;
case 3:
// Percentage
ch1 = (et0 / 100) % 10;
if (ch1 != 0) {
Lcd_Chr(1,6, 48+ch1);
} else {
Lcd_Chr(1,6,27);
}
ch2 = (et0 / 10) % 10;
if (ch2 != 0 || ch1 != 0) {
Lcd_Chr(1,7, 48+ch2);
} else {
Lcd_Chr(1,7,27);
}
ch3 = et0 % 10;
Lcd_Chr(1,8,48+ch3);
Lcd_Chr(1,9,'%');
ch4 = (et2 / 100) % 10;
if (ch4 != 0) {
Lcd_Chr(2,6,48+ch4);
} else {
Lcd_Chr(2,6,27);
}
ch5 = (et2 / 10) % 10;
if (ch5 != 0 || ch4 != 0) {
Lcd_Chr(2,7, 48+ch5);
} else {
Lcd_Chr(2,7,27);
}
ch6 = et2 % 10;
Lcd_Chr(2,8,48+ch6);
Lcd_Chr(2,9,'%');
//Kilos
ch7 = (kg1 / 1000) % 10;
if (ch7 != 0) {
Lcd_Chr(1,11,48+ch7);
} else {
Lcd_Chr(1,11,27);
}
ch6 = (kg1 / 100) % 10;
if (ch7 != 0 || ch6 != 0) {
Lcd_Chr(1,12, 48+ch6);
} else {
Lcd_Chr(1,12,27);
}
ch8 = (kg1 / 10) % 10;
if (ch8 != 0 || ch7 != 0 || ch6 != 0) {
Lcd_Chr(1,13, 48+ch8);
} else {
Lcd_Chr(1,13,27);
}
ch9 = kg1 % 10;
Lcd_Chr(1,14,48+ch9);
Lcd_Out(1,15,"KG");
break;
default:
Lcd_Cmd(_LCD_CLEAR);
break;
}
}
void main() {
INTCON = 0;
ANSELH = 0;
LCDType = 0;
oldType = 0;
space = " ";
transfering = "TRANSFERING:";
Lcd_Init(); // LCD display initialization
Lcd_Cmd(_LCD_CURSOR_OFF); // LCD command (cursor off)
Lcd_Cmd(_LCD_CLEAR); // LCD command (clear LCD)
text = "Fuel Balance"; // Define the first message
Lcd_Out(1,1,text); // Write the first message in the first line
text = "System by J.P."; // Define the second message
Lcd_Out(2,1,text); // Define the first message
ADCON1 = 0x82; // A/D voltage reference is VCC
TRISA = 0xFF; // All port A pins are configured as inputs
Delay_ms(2000);
Lcd_Cmd(_LCD_CLEAR);
while (1) {
oldet0 = et0;
oldet2 = et2;
adc_rd0 = ADC_Read(0);
adc_rd1 = ADC_Read(1);
adc_rd2 = ADC_Read(2);
adc_rd3 = ADC_Read(3);
et0 = (long)adc_rd0 * 1000;
et1 = (long)adc_rd1 * 1000;
et2 = (long)adc_rd2 * 1000;
et3 = (long)adc_rd3 * 1000;
et0 = et0 / 1023;
et1 = et1 / 1023;
et2 = et2 / 1023;
et3 = et3 / 1023;
et0 = et1 * 100 / et0;
et2 = et3 * 100 / et2;
kg1 = et0 * 4530 / 100;
kg2 = et2 * 4530 / 100;
skirtumas1 = et0-et2;
skirtumas2 = et2-et0;
oldType = LCDType;
LCDType = 0;
if (skirtumas1 > 15 || skirtumas2 > 15) { // Transfering type
if ( skirtumas1 > 15) {
LCDType = 1;
Delay_ms(1);
} else if (skirtumas2 > 15){
LCDType = 2;
}
} else { // Data showing type
LCDType = 3;
}
if (oldType != LCDType || oldet0 != et0 || oldet2 != et2) {
LCDOutput(LCDType);
}
}
}
Main problem now is that result im getting now on my LCD is blinking (Delay 2000ms) text: https://clip2net.com/s/7isFai.
When i remove this part from my code:
Code:
// Percentage
ch1 = (et0 / 100) % 10;
if (ch1 != 0) {
Lcd_Chr(1,6, 48+ch1);
} else {
Lcd_Chr(1,6,27);
}
ch2 = (et0 / 10) % 10;
if (ch2 != 0 || ch1 != 0) {
Lcd_Chr(1,7, 48+ch2);
} else {
Lcd_Chr(1,7,27);
}
ch3 = et0 % 10;
Lcd_Chr(1,8,48+ch3);
Lcd_Chr(1,9,'%');
ch4 = (et2 / 100) % 10;
if (ch4 != 0) {
Lcd_Chr(2,6,48+ch4);
} else {
Lcd_Chr(2,6,27);
}
ch5 = (et2 / 10) % 10;
if (ch5 != 0 || ch4 != 0) {
Lcd_Chr(2,7, 48+ch5);
} else {
Lcd_Chr(2,7,27);
}
ch6 = et2 % 10;
Lcd_Chr(2,8,48+ch6);
Lcd_Chr(2,9,'%');
And when i remove this part of code:
Code:
//Kilos
ch7 = (kg1 / 1000) % 10;
if (ch7 != 0) {
Lcd_Chr(1,11,48+ch7);
} else {
Lcd_Chr(1,11,27);
}
ch6 = (kg1 / 100) % 10;
if (ch7 != 0 || ch6 != 0) {
Lcd_Chr(1,12, 48+ch6);
} else {
Lcd_Chr(1,12,27);
}
ch8 = (kg1 / 10) % 10;
if (ch8 != 0 || ch7 != 0 || ch6 != 0) {
Lcd_Chr(1,13, 48+ch8);
} else {
Lcd_Chr(1,13,27);
}
ch9 = kg1 % 10;
Lcd_Chr(1,14,48+ch9);
Lcd_Out(1,15,"KG");
So, why those parts of code doesn't work together? lol Maby it's some kind of lack of MCU's resources? Or LCD resources, lol... And, also, when im trying to place more "Lcd_Out" statement rather than "Lcd_Chr" its also doesnt work properly.
Anybody knows anything about this? Please help me
Attaching my mikroC project files: