Justinho27
Newbie level 5
- Joined
- Apr 24, 2014
- Messages
- 9
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 55
// 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 ch0, ch1, ch2, ch3, ch4, ch5, ch6, ch7;
unsigned int adc_rd0, adc_rd1, adc_rd2, adc_rd3;
char *text, *text3, *text1, *text2;
long et0, et1, et2, et3, kg1, kg2;
void main() {
INTCON = 0;
ANSELH = 0;
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(1);
Lcd_Cmd(_LCD_CLEAR);
text1 = "L/H:";
text2 = "R/H:";
Lcd_Cmd(_LCD_CLEAR);
while (1) {
Lcd_Out(1,1,text1);
Lcd_Out(2,1,text2);
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;
ch4 = et0 / 100;
ch5 = et2 / 100;
ch6 = kg1 / 1000;
ch7 = kg2 / 1000;
Lcd_Out(1,15,"KG");
Lcd_Out(2,15,"KG");
Lcd_Chr(1,11,48+ch6);
ch6 = (kg1 / 100) % 10;
Lcd_Chr(1,12,48+ch6);
ch6 = (kg1 / 10) & 10;
Lcd_Chr(1,13,48+ch6);
ch6 = kg1 % 10;
Lcd_Chr(1,14,48+ch6);
Lcd_Chr(2,11,48+ch7);
ch7 = (kg2 / 100) % 10;
Lcd_Chr(2,12,48+ch7);
ch7 = (kg2 / 10) & 10;
Lcd_Chr(2,13,48+ch7);
ch7 = kg2 % 10;
Lcd_Chr(2,14,48+ch7);
if (et0 > 99)
{
Lcd_Out(1,6,"FULL");
}
if (99 > et0 & et0 > 10)
{
Lcd_Out(1,6," ");
ch4 = (et0 / 10) % 10;
Lcd_Chr(1,7,48+ch4);
ch4 = et0 % 10;
Lcd_Chr(1,8,48+ch4);
Lcd_Chr(1,9,'%');
}
if (et0 < 10)
{
Lcd_Out(1,6,"LOW!");
}
if (et2 > 99)
{
Lcd_Out(2,6,"FULL");
}
if (99 > et2 & et2 > 10)
{
Lcd_Out(2,6," ");
ch5 = (et2 / 10) % 10;
Lcd_Chr(2,7,48+ch5);
ch5 = et2 % 10;
Lcd_Chr(2,8,48+ch5);
Lcd_Chr(2,9,'%');
}
if (et2 < 10)
{
Lcd_Out(2,6,"LOW!");
}
/*Lcd_Chr(1,11,48+ch0);
Lcd_Chr_CP('.');
ch0 = (tlong0 / 100) % 10;
Lcd_Chr_CP(48+ch0);
ch0 = (tlong0 / 10) % 10;
Lcd_Chr_CP(48+ch0);
ch0 = tlong0 % 10;
Lcd_Chr_CP(48+ch0);
Lcd_Chr_CP('V'); */
Delay_ms(1);
}
}
// 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 ch0, ch1, ch2, ch3, ch4, ch5, ch6, ch7, ch8;
unsigned int adc_rd0, adc_rd1, adc_rd2, adc_rd3;
char *text, *text3, *text1, *text2;
long et0, et1, et2, et3, kg1, kg2, skirtumas1, skirtumas2;
void main() {
INTCON = 0;
ANSELH = 0;
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(1);
Lcd_Cmd(_LCD_CLEAR);
text1 = "L/H TANK: ";
text2 = "R/H TANK: ";
Lcd_Cmd(_LCD_CLEAR);
while (1) {
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;
ch4 = et0 / 100;
ch5 = et2 / 100;
ch6 = kg1 / 1000;
ch7 = kg2 / 1000;
skirtumas1 = et0-et2;
skirtumas2 = et2-et0;
if ( skirtumas1 >= 15)
{
Lcd_Out(2,1," ");
Lcd_Out(2,14," ");
Lcd_Out(2,4,"R/H -> L/H");
Delay_ms(1);
}
if ( skirtumas2 >= 15)
{
Lcd_Out(2,1," ");
Lcd_Out(2,14," ");
Lcd_Out(2,4,"R/H <- L/H");
}
if (skirtumas1 < 15, skirtumas2 < 15)
{
if (et0 > 99)
{
Lcd_Out(1,1,text1);
Lcd_Out(1,11,"FULL");
}
if (99 > et0 & et0 > 10)
{
Lcd_Out(1,1,text1);
Lcd_Out(1,11," ");
ch4 = (et0 / 10) % 10;
Lcd_Chr(1,12,48+ch4);
ch4 = et0 % 10;
Lcd_Chr(1,13,48+ch4);
Lcd_Chr(1,14,'%');
}
if (et0 < 10)
{
Lcd_Out(1,1,text1);
Lcd_Out(1,11,"LOW!");
}
if (et2 > 99)
{
Lcd_Out(2,1,text2);
Lcd_Out(2,11,"FULL");
}
if (99 > et2 & et2 > 10)
{
Lcd_Out(2,1,text2);
Lcd_Out(2,11," ");
ch5 = (et2 / 10) % 10;
Lcd_Chr(2,12,48+ch5);
ch5 = et2 % 10;
Lcd_Chr(2,13,48+ch5);
Lcd_Chr(2,14,'%');
}
if (et2 < 10)
{
Lcd_Out(2,1,text2);
Lcd_Out(2,11,"LOW!");
}
}
}
}
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 // 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 ch[8], i = 0; char *text[4]; double et[4], kg[2], skirtumas[2]; const double myConst1 = 1.024, myConst2 = 45.3, tenPow2 = 100.0, tenPow3 = 1000.0; //1000 / 1024, 4530 / 100 = 45.3 void main() { INTCON = 0; ANSELH = 0; Lcd_Init(); // LCD display initialization Lcd_Cmd(_LCD_CURSOR_OFF); // LCD command (cursor off) Lcd_Cmd(_LCD_CLEAR); // LCD command (clear LCD) text[0] = "Fuel Balance"; // Define the first message Lcd_Out(1,1,text[0]); // Write the first message in the first line text[0] = "System by J.P."; // Define the second message Lcd_Out(2,1,text[0]); // Define the first message ADCON1 = 0x82; // A/D voltage reference is VCC TRISA = 0xFF; // All port A pins are configured as inputs Delay_ms(5); Lcd_Cmd(_LCD_CLEAR); text[1] = "L/H TANK: "; text[2] = "R/H TANK: "; while (1) { for(i = 0; i < 4; i++) { et[i] = ADC_Read(i) / myConst1; } et[0] = et[1] * tenPow2 / et[0]; et[2] = et[3] * tenPow2 / et[2]; kg[0] = et[0] * myConst2; kg[1] = et[2] * myConst2; ch[4] = et[0] / tenPow2; ch[5] = et[2] / tenPow2; ch[6] = kg[0] / tenPow3; ch[7] = kg[1] / tenPow3; skirtumas[0] = et[0] - et[2]; skirtumas[1] = et[2] - et[0]; if(skirtumas[0] >= 15.0) { Lcd_Out(2,1," "); Lcd_Out(2,14," "); Lcd_Out(2,4,"R/H -> L/H"); Delay_ms(1); } if(skirtumas[1] >= 15.0) { Lcd_Out(2,1," "); Lcd_Out(2,14," "); Lcd_Out(2,4,"R/H <- L/H"); } if((skirtumas[0] < 15.0) || (skirtumas[1] < 15.0)) { if(et[0] > 99.0) { Lcd_Out(1,1,text[1]); Lcd_Out(1,11,"FULL"); } else if((et[0] > 10.0) && (et[0] < 99.0)) { Lcd_Out(1,1,text[1]); Lcd_Out(1,11," "); ch[4] = (et[0] / 10) % 10; Lcd_Chr(1,12,48+ch[4]); ch[4] = et[0] % 10; Lcd_Chr(1,13,48+ch[4]); Lcd_Chr(1,14,'%'); } else if(et[0] < 10.0) { Lcd_Out(1,1,text[1]); Lcd_Out(1,11,"LOW!"); } if (et[2] > 99.0) { Lcd_Out(2,1,text[2]); Lcd_Out(2,11,"FULL"); } else if ((et[2] > 10.0) && (et[2] < 99.0)) { Lcd_Out(2,1,text[2]); Lcd_Out(2,11," "); ch[5] = (et[2] / 10) % 10; Lcd_Chr(2,12,48+ch[5]); ch[5] = et[2] % 10; Lcd_Chr(2,13,48+ch[5]); Lcd_Chr(2,14,'%'); } else if (et[2] < 10.0) { Lcd_Out(2,1,text[2]); Lcd_Out(2,11,"LOW!"); } } } }
Code C - [expand] 1 ch[4] = (et[0] / 10.0) % 10.0;
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?