internetuser2k12
Banned
Hello!
The resistors connected to 555 should be 730 Ohms each, but if I make it 730 Ohms, the ADC doesn't work. If I make the resistor values 10K it works, but the adc readings are not correct on varying the temperature of LM35. What is the problem?
The code is like this
The resistors connected to 555 should be 730 Ohms each, but if I make it 730 Ohms, the ADC doesn't work. If I make the resistor values 10K it works, but the adc readings are not correct on varying the temperature of LM35. What is the problem?
The code is like this
Code:
// LCD module connections
sbit LCD_RS at P3_0_bit;
sbit LCD_EN at P3_1_bit;
sbit LCD_D4 at P3_2_bit;
sbit LCD_D5 at P3_3_bit;
sbit LCD_D6 at P3_4_bit;
sbit LCD_D7 at P3_5_bit;
// End LCD module connections
#define ADC_SC P2_6_bit // set the start pin to P2_0
#define ADC_EOC P2_7_bit // set the End of Conversion to p2_1
#define ADC_OE P2_5_bit // set the output enable to p2_2
#define ADC_ALE P2_4_bit // aet the Adress Latch Enable to P2_4
#define ADD_A P2_2_bit
#define ADD_B P2_1_bit
#define ADD_C P2_0_bit
#define ADC_DATA P1 // set the 8-bit data to p0 port.
void adc_init();
unsigned char adc_getdata();
double d_adc_val;
unsigned char getdata, adc_val;
char str_adc_val[17];
char txt1[] = "A Project by";
char txt2[] = "Smitha B T";
/*---------------------------------------------------------------------
Initialize the adc
void adc_init();
---------------------------------------------------------------------*/
void adc_init() //
{
ADC_EOC = 1;
//P1 = 0xFF;
ADC_ALE = 0;
ADC_OE = 0;
ADC_SC = 0;
ADD_A = 0;
ADD_B = 0;
ADD_C = 0;
Delay_ms(2);
}
/*---------------------------------------------------------------------
Get the data from ADC
unsigned char adc_getdata(void);
---------------------------------------------------------------------*/
unsigned char adc_getdata()
{
ADC_ALE = 1; // enable ALE
Delay_ms(2);
ADC_SC = 1; // Start the ADC conversion
Delay_ms(1);
ADC_ALE = 0;
Delay_ms(1);
ADC_SC = 0;
Delay_ms(1);
// Waiting for Conversion end
while(ADC_EOC == 1);
while(ADC_EOC == 0);
ADC_OE = 1; // set the Output Enable
Delay_ms(1);
getdata = ADC_DATA; // Get the ADC data
ADC_OE = 0; // clear the Output Enable
return getdata;
}
void main(){
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear Display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
LCD_Out(1,3,txt1); // Write text in first row
LCD_Out(2,4,txt2); // Write text in second row
Delay_ms(2000); // 3 sec delay
Lcd_Cmd(_LCD_CLEAR); // Clear Display
adc_init();
while(1) {
adc_val = adc_getdata(); // read adc input and assign the value to adc_val
d_adc_val = adc_val * 0.588235524798245;
FloatToStr(d_adc_val, str_adc_val); // convert adc_val to string
Lcd_Out(1,3,"Temperature"); //
Lcd_Out(2,3,str_adc_val); // Display adc value
}
}