I am currently doing a mini-project on temperature sensor using 8051 micro-controller. The 8051 micro-controller will receive 8bit temperature data from Analogue-to-Digital Converter which is connected to a temperature sensor(eg. LM35) I have a problem in translating the 8bit data from ADC to a temperature reading (eg. 38 celcius)in keil. I hope to understand the structure or the procedure in carrying out this step. Thank you!
void main(void) { char ebit,ans; ebit = 0x01; ans = ebit*(100/256); } how can i display the value in ans on LCD ? void lcdPutStr (char *string) { char i; i=0; while(string[i]) { lcdPutCh (string[i++]); } } this is the program segment for putting the characters into LCD.
Make OPORT volatile. Stefan
Below is the C prog. I notice that the problem is lies with "OPORT = instr;" because it suppose to move what is in instr into OPORT which is in Xdata at location 0000h but it did not. #include <reg51.h> void delay5ms(void); void delay1ms(void); void lcdWriteInstrReg(char instr); void lcdInit(void); void lcdClrScr(void); char xdata OPORT _at_ 0x0000; sbit pinRW = P3^3; sbit pinRS = P3^4; sbit pinE = P3^5; void main(void) { lcdInit(); while(1); }//end main void lcdWriteInstrReg(char instr) { OPORT = instr; //o/p to D0-D7 pinRW = 0; //write pinRS = 0; //RS=0 for instr Reg pinE = 0; pinE = 1; pinE = 0; } void lcdInit(void) { delay5ms(); delay5ms(); delay5ms(); delay5ms(); lcdWriteInstrReg(0x38); delayms(); lcdWriteInstrReg(0x38); delay1ms(); lcdWriteInstrReg(0x38); delay1ms(); lcdWriteInstrReg(0x06); delay1ms(); lcdWriteInstrReg(0x0f); delay1ms(); lcdClrScr(); } void lcdClrScr(void) { lcdWriteInstrReg(0x01); delay1ms(); delay1ms(); }
"which port would i acquire the 8bit data because the AT89C52 have 4 port?" You choose!
thanks! by the way, which port would i acquire the 8bit data because the AT89C52 have 4 port? Futhermore, i have set aside P0 to LCD display and P1 to keypad.
Perhaps you are confused by the fact that there are actually two scale factors involved here: 1. As Drew pointed out, the sensor produces a linear +10 mV per degree C. So that's an easy one - you can easily get from mV to degrees C, can't you? 2. There's the scale factor of the ADC: * what voltage (and, thus, temperature) does the value 0x00 represent? * what voltage (and, thus, temperature) does the value 0xFF represent? From there you can easily deduce what voltage step (and, thus, temperature step) produces a 1-bit step in the ADC value (eg, 0x00 to 0x01) "Futhermore, I am using AT89C52 micro-controller." Again, that's irrelevant - the principle is the same irrespective of what you run it on!
"Each step from 0000 0000 to 0000 0001 contribute to a certain degree C." Exactly - so all you need to do is apply the scale factor that relates the 1-bit step to a certain degree C. You may also need to add an offset to account for the Celsius temperature corresonding to the 8-bit binay 0000 0000. Assuming it's linear, it's your good old y = mx + c Note that this has nothing specifically to do with Keil - the principle is the same whatever tools you use, and whatever language, from whatever vendor! Try thinking about how you'd do it by hand!
how can i programme to allow the incoming binary to becoming a temperature reading appearing on the keil? How about using an array? For example:
float temp_table [256] = { ... };
Thank you for the overview, I appreciate it. Now I am having a problem on how to convert the incoming 8-bit data from ADC to a temperature reading by using the keil Software. Futhermore, I am using AT89C52 micro-controller. I am aware that 8-bit data would have 256 combination from 0000 0000 to 1111 1111. Each step from 0000 0000 to 0000 0001 contribute to a certain degree C. However, how can i programme to allow the incoming binary to becoming a temperature reading appearing on the keil?
The data sheet http://www.national.com/pf/LM/LM35.html says that the part produces a linear +10 mV per degree C. So, take the voltage measurement from the ADC and divide to get a temperature. You might need to add a constant to account for the "zero" point of the device. Or, to look at it another way, you have an 8-bit ADC, which 8 bits have to cover the whole temperature range. So you could just scale the 0-255 value to the range of temperatures for the LM35. It should be a nice, simple, one-line calculation. What problem are you having, exactly?
View all questions in Keil forum