Sahil_khan
Newbie level 6
- Joined
- Jan 27, 2013
- Messages
- 13
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Location
- Pakistan
- Activity points
- 1,399
Dear Guys
I am new to PIC Microcontroller and just started working on an example i.e. to read ADC value and convert it to ASCI and then display on LCD. I am using mikroC compiler.
Can some body explain what does the following code do ?
unsigned char ch;
unsigned int adc_rd;
char *text;
long tlong;
tlong = (long)adc_rd * 5000; // covert adc reading to milivolts
tlong = tlong / 1023; // 0..1023 -> 0-5000mV
ch = tlong / 1000; // extract volts digit
LCD_Chr(2,9,48+ch); // write ASCII digit at 2nd row, 9th column
LCD_Chr_CP('.');
ch = (tlong / 100) % 10; // extract 0.1 volts digit
LCD_Chr_CP(48+ch); // write ASCII digit at cursor point
ch = (tlong / 10) % 10; // extract 0.01 volts digit
LCD_Chr_CP(48+ch); // write ASCII digit at cursor point
ch = tlong % 10; // extract 0.001 volts digit
LCD_Chr_CP(48+ch); // write ASCII digit at cursor point
LCD_Chr_CP('V');
specifically, I can not understand the highlighted BLUE text.
Thank you all.
Regards
Sahil Khan
I am new to PIC Microcontroller and just started working on an example i.e. to read ADC value and convert it to ASCI and then display on LCD. I am using mikroC compiler.
Can some body explain what does the following code do ?
unsigned char ch;
unsigned int adc_rd;
char *text;
long tlong;
tlong = (long)adc_rd * 5000; // covert adc reading to milivolts
tlong = tlong / 1023; // 0..1023 -> 0-5000mV
ch = tlong / 1000; // extract volts digit
LCD_Chr(2,9,48+ch); // write ASCII digit at 2nd row, 9th column
LCD_Chr_CP('.');
ch = (tlong / 100) % 10; // extract 0.1 volts digit
LCD_Chr_CP(48+ch); // write ASCII digit at cursor point
ch = (tlong / 10) % 10; // extract 0.01 volts digit
LCD_Chr_CP(48+ch); // write ASCII digit at cursor point
ch = tlong % 10; // extract 0.001 volts digit
LCD_Chr_CP(48+ch); // write ASCII digit at cursor point
LCD_Chr_CP('V');
specifically, I can not understand the highlighted BLUE text.
Thank you all.
Regards
Sahil Khan