I have written a code for getting input from ADC 0804 and then display the value on 16x2 lcd I need help in writing a function to convert ADC output into a value which can be displayed in 16x2 lcd. ADC is used to convert temperature output from lm35. 5V supply voltage and Vref=2.5V. I need code for - convert_display(value) Also keil compiler gives error - adc_inter.c(16): error C141: syntax error near '='. I am unable to understand what should be done?
#include <reg51.h> #include <stdio.h> #include <string.h> void msdelay(unsigned int time); void convert_display(unsigned char value); #define RD P2^5; #define WR P2^6; #define INTR P2^7; unsigned long MYDATA;
void main() { unsigned char value; MYDATA = P1; MYDATA = 0xFF; INTR = 1; RD = 1; WR = 1; while(1) { WR=0; WR=1; while(INTR==1) { } RD=0; value=MYDATA; convert_display(value); RD=1; } }
void msdelay(unsigned int time) { unsigned char x,y; for(x=0;x<=time;x++) for(y=0;y<=1275;y++); }
Please will you give me c code? I'll study the code. - Take input from ADC 0804 and display it at 16x2 lcd display.
I have written a code. At last, no errors and no warnings. Now I need function definition for "convert_display" Please help me. I have to convert temperature from lm35 ->ADC0804(ref voltage 2.28V) ->89s51and display it on 16x2 lcd display.
#include <REGX51.h> #include <stdio.h> #include <string.h> void msdelay(unsigned int time); void convert_display(unsigned char value); #define SET(reg, bit) reg |= (1 << bit) // Sets a bit in reg. #define CLR(reg, bit) reg &= ~(1 << bit) // Clears a bit in reg. #define INTR P2^7 #define RD P2^5 #define WR P2^6 #define MYDATA P0 void main() { unsigned char value; SET(P2,5); SET (P2,6); SET (P2,7); MYDATA =0xFF; while(1) { CLR(P2,6); SET(P2,6); while(INTR==1) { } CLR(P2,5); value=MYDATA; convert_display(value); SET(P2,5); } } void convert_display(unsigned char value) { } void msdelay(unsigned int time) { unsigned char x,y; for(x=0;x<=time;x++) for(y=0;y<=1275;y++); }
The number/alphabets must be in ascii format to be dispalyed on lcd. Heard about itoa function? perform a web search.
There is plenty of code already on this very site - not to mention the rest of the internet - for you to study.
There are also plenty of resources to help you learn 'C' programming; eg,
blog.antronics.co.uk/.../
So what do you think these lines are for
#include <stdio.h> #include <string.h>
Get out your 'C' textbook, and look at the functions provided by the Standard 'C' Library...
Again, here are some 'C' learning resources - including a free online textbook:
Amit: One of the problems is that you are not being specific enough for people to help you.
First do you want to display the number as binary, hex, or ascii? do you want to display the equivalent of the value, or do you need to convert it to some other engineering value? In your example, you have the value as 0xFF.
do you need to convert that to floating point voltage, or temperature or what?
There are a myriad of ways of doing this. There is a C function itoa that given a value, and a pointer to a buffer in memory, will create a ascii equivalent. So for 0xFF you would see 0x32 0x35 0x35 in the buffer. (ascii for 255). OR there is the sprintf function that will let you format the number pretty much how you want in memory, it will convert it to binary, hex, ascii etc.
As a noobe C programmer, if you are going to be able to program, you would be best advised to get a copy of K&RC or find a good 'C' reference site on the internet.
www.tutorialspoint.com/.../c_function_sprintf.htm as you can see from this link, you could use this for example. unsigned char buffer[20];
sprintf( &(buffer[0]),"%x",value); would convert it to a hex value in memory. And for the other sharp teeth on the list, I happen to like to be very specific with my pointers, so I *am* going to put a & in front, and a [index] after it to be explicit.
"OR there is the sprintf function that will let you format the number pretty much how you want in memory, it will convert it to binary, hex, ascii etc."
Think twice about this statement. sprintf() can now either make a number into writable characters (ASCII) or into binary, hex etc? Next thing - what numerical bases can sprintf() use when translating a number into a sequence of ASCII characters?
Peter:
obviously sprintf converts to ascii. What I meant, was that it will convert your number into an equivalent ascii number. %o gives you octal %x gives you hex
I have worked with a version that had a %b and would give you the result in ascii binary i.e. 0x31 0x30 0x31 0x31 0x30 for 10110b That is not part of the standard library
if you do "%h",value you get base 16 or hex %o base 8 or octal %c base 256 when you think about it :) %u base 10
or is it base-128 ... ?
Base 128 if you are a 7 bit character. 256 if you are an 8 bit character. 00-0xFF. Technically it has to be 256 because the definition of a base requires the number to reset to 0 when you get to the end of the range 0-0xf then 0 0x7F +1 0x80, so if you are looking at it as a 7 bit word, and you mask the upper one off, then it would be base 128.
Actually I don't know *what* sprintf would do if you gave it a 16 bit number. It might use the upper byte on one endian machine or the lower byte on a different endian machine, or it might just spit it's guts all over you at compile time, if you did your prototyping right.
I wish the C guys had seen fit to adopt my quad for long long, but way back it got nixed. I still think quad would be a good one for a 64 bit variable.
Base 128 would imply that a 8-bit character larger than 127 would represent a printout of two ASCII characters - the high bit isn't allowed to just be masked away when talking about base-n numeric operations.
About printf() and 16-bit values - the language standard does cover multi-character character constants, but as implementation-defined.
I have a bit bad access to standard documents right now, but the old ISO 9899 standard (C99) has the following note (§6.4.4.4, bullet 10): "The value of an integer character constant containing more than one character (e.g., 'ab'), or containing a character or escape sequence that does not map to a single-byte execution character, is implementation-defined."
And J.3.4 covers implementation-specific behavior relating to characters: "The value of an integer character constant containing more than one character or containing a character or escape sequence that does not map to a single-byte execution character (6.4.4.4).
Character constants containing multiple characters are also a common cause for compilation warnings, because of the portability issues.