dolphinlabs
...
Doplhin labs
News

LPC2148-ADC Interfacing



Warning: readfile(ADC.htm) [function.readfile]: failed to open stream: No such file or directory in /home/dolphinlabs/public_html/Word-SubMenu-Display.php on line 104

1.      ADC

Objective:

Interfacing of ADC with LPC2148 microcontroller

Hardware Connections for LPC2148 Board:-

1.      Plug in the USB cable to your computer and to the Board. Once the USB cable is plugged in, Board is powered up

2.      Connect ANALOG VIN of ADC to +5V supply and GND to GND pin of supply.

3.      Connect Pot to P0.28 pin of microcontroller.

4.      Connect +5V pin of LCD interface to +5V supply pin and GND pin of LCD interface to GND pin of supply.

5.      Connect RS pin of LCD to P1.17 pin of microcontroller.

6.      Connect RW pin of LCD to P1.18 pin of microcontroller.

7.      Connect EN pin of LCD to P1.19 pin of microcontroller.

8.      Connect data pins of LCD D4-D7 to P1.20-P1.23 pins of microcontroller.

Diagram:

Source code:

#include<lpc21xx.h>

  /**********LCD Pin Configuration**********/

#define EN 19

#define RS 17

#define RW 18

//These all are connected on Port-1 of Controller, so make sure before using IOSET and IOCLR Functions

/*****************************************/

 

/***********FUNCTION PROTOTYPE***********/

void ADC_Init(void);

unsigned int Read_ADC(void);

void Delay(unsigned long value);

void Write_Cmd(unsigned int value);

void Write_Data(unsigned int value);

void Lcd_Init(void);                        //Initialize Lcd Module

void Lcd_Write(unsigned int value);

void Lcd_Cmd(unsigned int value);

void Lcd_Write_Text(unsigned char*);

/****************************************/

 

int main()

{   unsigned int adc_data;

    unsigned char ones,tens,hundreds,thousands;

   IODIR0=0xff0000;             //Data lines from P1.16 to P1.23

  IOCLR0=0xff0000;

    //unsigned int adc_data;

   // unsigned char ones,tens,hundreds,thousands;

    Lcd_Init();

    Delay(10000);

    Lcd_Write_Text("   WELCOME...");

    Delay(100000);

    Delay(100000);

    Lcd_Cmd(0xC0);

    Lcd_Write_Text(" LPC2148 DEVBRD");

    Delay(100000);

    Delay(100000);

    Delay(100000);

    Delay(100000);

    Delay(100000);

    Delay(100000);

    Delay(100000);

    Delay(100000);

    Delay(100000);

    Delay(100000);

    Delay(100000);

    Delay(100000);

    Delay(100000);

    Delay(100000);

    Delay(100000);

    Delay(100000);

    Lcd_Cmd(0x01);

    Lcd_Write_Text("ADC EXAMPLE");

    ADC_Init();

    Delay(100000);

    while(1)

    {

   adc_data = Read_ADC();

       Delay(100000);

        ones = adc_data % 10;

        adc_data = adc_data / 10;

        tens = adc_data % 10;

        adc_data = adc_data / 10;

        hundreds = adc_data % 10;

        adc_data = adc_data / 10;

        thousands = adc_data % 10;

 

        Lcd_Cmd(0xC0);        //Second Row

        Lcd_Write(thousands | 0x30);

        Lcd_Write(hundreds | 0x30);

        Lcd_Write(tens | 0x30);

        Lcd_Write(ones | 0x30);

        Delay(100000);

        Delay(100000);

        Delay(100000);

        Delay(100000);

    }

}

 

/***********FUNCTION DEFINITION************/

 

void Delay(unsigned long value)

{

     while(value>0)

    {

        value--;

    }

}

void Lcd_Init(void)

{   

    IO1DIR |= 0x00FE0000;

    //Pins P1.17 to P.23 as Output Pin

    Delay(200000);

    Write_Cmd(0x30<<16);

    Delay(100000);

    Write_Cmd(0x30<<16);

    Delay(100000);

    Write_Cmd(0x30<<16);

    Delay(100000);

    Write_Cmd(0x20<<16);

    //These are the Commands for LCD Initialization in 4-Bit Mode

    Lcd_Cmd(0x01);

    Lcd_Cmd(0x06);

    Lcd_Cmd(0x0C);

    Lcd_Cmd(0x80);

}

 

void Write_Cmd(unsigned int value)

{

    //First of all Clear the LCD Data Pins

    IO1CLR |= 0x00F00000;

    //To Write RW = 0

    IO1CLR |= (1<<RW);

    //Write to Command Register RS = 0

    IO1CLR |= (1<<RS);

    //Write to Pins

    IO1SET |= 0x00F00000 & value;

    IO1SET |= (1<<EN);

    Delay(30000);

    IO1CLR |= (1<<EN);

}

 

void Write_Data(unsigned int value)

{

       //First of all Clear the LCD Data Pins

    IO1CLR |= 0x00F00000;

    //To Write RW = 0

    IO1CLR |= (1<<RW);

    //Write to Data Register RS = 1

    IO1SET |= (1<<RS);

    //Write to Pins

    IO1SET |= 0x00F00000 & value;

    IO1SET |= (1<<EN);

    Delay(30000);

    IO1CLR |= (1<<EN);

}

void Lcd_Cmd(unsigned int value)

{

    Write_Cmd(value<<16);

    Write_Cmd(value<<20);

}

void Lcd_Write(unsigned int value)

{

    Write_Data(value<<16);

    Write_Data(value<<20);

}

void Lcd_Write_Text(unsigned char *data)

{

    while(*data != '\0')

    {

        Lcd_Write(*data);

        data++;

        Delay(10000);

    }

}

void ADC_Init()

{

    PINSEL1 |= 0x01000000;        //Configure P0.28 as AD0.2

    AD0CR = 0x00200F02;

    /*

    SEL = 0x02 as AD0.1 is Choosen

    CLKDIV = 0x0F

    CLKS and BURST = 0x0 means that 11 Intruction Cycles used,resulting in 10-Bit Data

    And Don't Start the Conversion Now

    */

}

unsigned int Read_ADC()

{

    unsigned int adc_data;

    AD0CR |= 0x01000000;        //Start the ADC Conversion

    //Delay(100000);

    do

    {

        adc_data = AD0DR1;

    }while(!(adc_data & 0x80000000));

    //Wait untill the DONE bits Sets

    AD0CR &= ~0x01000000;                 /* Stop A/D Conversion            */

    //AD0CR &= 0xFE000000;        //Stop the ADC Conversion

    adc_data = adc_data>>6;

    adc_data = adc_data & 0x3FF;    //Clearing all other Bits

    return (adc_data);

}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


Get SOCIAL







SAFE & SECURE SHOPPING

visa card master card maestro card
Maverick IT Industries Pvt. Ltd.