Update

One new tab added. Open in browser view if it is not visible. (25/08/2022 08:48)

Read Analog values and display on LCD in LPC2148



In 
electronics, an analog-to-digital converter (ADCA/D, or A-to-D) is a system that converts an analog signal, such as a sound picked up by a microphone or light entering a digital camera, into a digital signal.


Analog to Digital Converter(ADC) is used to convert analog signal into digital form. LPC2148 has two inbuilt 10-bit ADC i.e. ADC0 & ADC1.


  • ADC0 has 6 channels &ADC1 has 8 channels.
  • Hence, we can connect 6 distinct types of input analog signals to ADC0 and 8 distinct types of input analog signals to ADC1.



1)    main_program.c

#include<LPC214x.h>
#include"LCD.h"
#include"ADC.h"
int main()
{
 int dat, i=0;
 char buf[4];
 init_adc();
 PINSEL0 = 0x00000000;
 PINSEL1 = 0x00000000;
 IODIR0  = 0x0007FF00;
 LCD_INIT();
 LCD_MESSAGE("ADC Value");
 while(1)
 {
 delay(5);
 LCD_COMMAND(0xC0);
  
 dat = read_adc();
 i=0;
 while(dat > 0)
 {
 buf[i] = dat % 10;
 dat = dat / 10;
 i++;
 }
 while(--i >= 0)
 {
 LCD_DATA(buf[i] + '0'); // data is convered for LCD
 }
 delay(5);
 LCD_DATA(' ');
 LCD_DATA(' ');
 LCD_DATA(' ');
 LCD_DATA(' ');
}
}


2)    ADC.h header file

void init_adc()
{
PINSEL1 = 0x01000000;
AD0CR = 0x00200402; // ADC operational, 10-bits, 11 clocks for conversion
}
int read_adc()
{
int result;
AD0CR = AD0CR | (1<<24); // Start
while ( !(AD0DR1 & 0x80000000) ); // Wait till DONE
result = AD0DR1;
result = (result>>6);
result = (result & 0x000003FF);
return result;
}

No comments: