Module-IV
Introduction to ARM
Programming
Department of EECE-19ECS431-EMBEDDED SYSTEMS 1
LPC214x Pin configuration
LPC214x Pin configuration
Department of EECE-19ECS431-EMBEDDED SYSTEMS 2
Registers
• Different registers used for configuring or controlling a pin of an
ARM microcontroller.
• In microcontrollers, pins are divided into different PORTS.
• Usually a 32-bit microcontroller will have 32 pins per PORT
(sometimes it may vary).
• LPC2148 have 2 PORTS, P0 and P1. Each pin of these ports are
named as P0.0, P0.1, P0.2, P1.0, P1.2 etc.
Department of EECE-19ECS431-EMBEDDED SYSTEMS 3
3
INPUT/OUTPUT PORTS (GPIO of
LPC2148)
LPC2148 has two IO ports each of 32-bit wide, provided by
64 IO pins. Ports are named as P0 and P1.
Pins of each port labeled as Px.y where “x” stands for port
number, 0 or 1. Where “y” stands for pin number usually
between 0 to 31.
Each pin can perform multiple functions.
For example: Pin no.1 which is P0.21 serves as GPIO as
well as PWM5, AD1.6 (A/D converter1, input 6), CAP1.3
(Capture input for Timer1, Channel 3).
Department of EECE-19ECS431-EMBEDDED SYSTEMS 4
4
INPUT/OUTPUT PORTS (GPIO of
LPC2148)
CONFIGURE GPIO in LPC2148:
Department of EECE-19ECS431-EMBEDDED SYSTEMS 5
5
INPUT/OUTPUT PORTS (GPIO of
LPC2148)
CONFIGURE GPIO in LPC2148:
PORT 0 is a 32-bit I/O port with individual direction controls for each
bit.
Total of 28 pins of the Port 0 can be used as a general purpose bi-
directional digital I/Os while P0.31 provides digital output functions
only.
The operation of port 0 pins depends upon the pin function selected
via the pin connect block. Pins P0.24, P0.26 and P0.27 are not
available.
PORT 1 is a 32-bit bi-directional I/O port with individual direction
controls for each bit.
The operation of port 1 pins depends upon the pin function selected
via the pin connect block. Pins 0 through 15 of port 1 are not
available.
PORT0 and PORT1 are controlled via two groups of registers
Department of EECE-19ECS431-EMBEDDED SYSTEMS 6
6
Registers for C programming
IOSEL0
Port 0 has 32 pins (P0.0 to P0.31). Each pin can have multiple
functions. On RESET, all pins are configured as GPIO pins. However
we can re-configure using the registers IOSEL0 and IOSEL1. IOSEL0
is used to select function of P0.0 to P0.15. Each pin has up to 4
functions so 2 bits/pin in IOSEL0 is provided for selecting function.
IOSEL1
IOSEL1 is used to select function of Pins P0.16 to P0.31
IOSEL2
IOSEL2 is used to select function of Pins P1.16 to P1.31
Department of EECE-19ECS431-EMBEDDED SYSTEMS 7
7
Registers for C programming
PINSELx:
• Most of the pins of an ARM microcontroller is multi-functional, every
pin can be made to perform one of the assigned function by setting bits of
PINSEL register.
Department of EECE-19ECS431-EMBEDDED SYSTEMS 8
8
Registers for C programming
PINSELx:
The configuration register is called PINSEL and is classified in
to three registers: PINSEL0, PINSEL1 and PINSEL2.
These configuration registers are of 32-bit wide. Any pin on
the LPC2148 can have a maximum of 4 functions.
Hence in order to select one of the four functions, two
corresponding bits of the PINSEL register are needed.
So, a 32-bit PINSEL register can control 16 pins with 2-bits to
control each pin.
PINSEL0 controls PORT0 pins P0.0 to P0.15, PINSEL1 controls
PORT0 pins P0.16 to P0.31 and PINSEL2 controls PORT1 pins
Department of EECE-19ECS431-EMBEDDED SYSTEMS 9
P1.16 to P1.31. 9
Registers for C programming
The following table shows the PINSEL0 and corresponding functions on
the PORT0.
Department of EECE-19ECS431-EMBEDDED SYSTEMS 10
10
Registers for C programming
• IO0DIR
• IO0DIR is used to configure pins of Port 0-P0 as input or output
pins.
• 1= Output Pin
0= Input Pin
• Example: IO0DIR=0x0000FFFF means P0.0 to P0.15 are
configured as output pins and P0.16 to P0.31 are configured as input
pins.
• IO1DIR
• IO1DIR is used to configure pins of Port 1-P1 as input or output
pins.
• 1= Output Pin
0= Input Pin
• Example: IO1DIR=0xAAAAAAAA means even pins (P1.0, P1.2,
P1.4 etc.) are configured as input pins and odd pins (P1.1, P1.3,
P1.5 etc.) are configured as input pins.
Department of EECE-19ECS431-EMBEDDED SYSTEMS 11
11
Registers for C programming
• IO0SET
• It is used to set pins of Port0-P0 to logic 1.
• Example: IO0SET=0x0000FFFF will set pins P0.0 to P0.15 at logic 1. It will
not affect other pins.
• IO0CLR
• It is used to set pins of Port0-P0 to logic 0.
• Example: IO0CLR=0x0000FFFF will set pins P0.0 to P0.15 at logic 0. It will
not affect other pins.
• IO1SET
• It is used to set pins of Port1-P1 to logic 1.
• Example: IO1SET=0x0000FFFF will set pins P1.0 to P1.15 at logic 1. It will
not affect other pins.
• IO1CLR
• It is used to set pins of Port1-P1 to logic 0.
• Example: IO1CLR=0x0000FFFF will set pins P1.0 to P1.15 at logic 0. It will
not affect other pins.
Department of EECE-19ECS431-EMBEDDED SYSTEMS 12
12
Registers for C programming
Department of EECE-19ECS431-EMBEDDED SYSTEMS 13
13
Simple C programs for application with LED
PROGRAM TO BLINK LED CONNECTED
P0.3 pin WITH ARM(LPC2148)
CONTROLLER
#include<lpc214x.h>
void delay();
void main()
{
PINSEL0=0X00000000;
IO0DIR |=0XFFFFFFFF; //Port 0 is now
acting as a output pin
while(1)
{
IOSET0 |=0X00000008; //Port 0.3 pin
high now (LED is glowing)
delay();
IOCLR0 |=0X00000008; //Port 0.3 pin
low now (LED is OFF)
delay();
}
}
void delay()
{
unsigned int i;
for(i=0;i<30000;i++);
}
Department of EECE-19ECS431-EMBEDDED SYSTEMS 14
14
Simple C programs for application with LED
PROGRAM TO BLINK LEDS CONNECTED
WITH ARM(LPC2148) CONTROLLER
#include<lpc214x.h>
void delay();
void main()
{
PINSEL0=0X00000000;
IO0DIR |=0XfffffFFF; //Port 0 is now
acting as a output pin
while(1) {
IOSET0 |=0XfffffFFF; //Port 0's all pins
are high now (LED is glowing)
delay();
IOCLR0 |=0XFFFfffff; //Port 0's all pins
are low now (LED is OFF)
delay();
}
}
void delay()
{
unsigned int i;
for(i=0;i<30000;i++);
}
Department of EECE-19ECS431-EMBEDDED SYSTEMS 15
15
Simple C programs for application with LED
PROGRAM OF ALTERNATE LEDs GLOW
CONNECTED TO ARM(LPC21XX)
#include<lpc214x.h>
void delay();
void main()
{
PINSEL0=0X00000000;
IO0DIR |=0XFFFFFFFF;
while(1)
{
IOSET0 |=0X55555555;
delay();
IOCLR0 |=0XAAAAAAAA;
delay();
}
}
void delay()
{
unsigned int i;
for(i=0;i<30000;i++);
}
Department of EECE-19ECS431-EMBEDDED SYSTEMS 16
16
Simple C programs for application with LED
#include "lpc214x.h" // Include LPC2148 header file
#define LED_PORT IO0PIN // Define LED to Port0
#define LED_DIR IO0DIR // Define Port0 direction register
void delayMs(unsigned int x);
int main()
{
PINSEL0 = 0x00000000; // Define port lines as GPIO
LED_DIR |= 0x00000100; // Define LED pin as O/P
LED_PORT |= 0x00000000; // Turn off the LED initially
while(1) // Loop forever
{
LED_PORT |= 0x00000100; // Turn ON LED
delayMs(1000); // 1 second delay
LED_PORT &= 0x00000000; // Turn OFF LED
delayMs(1000); // 1 second delay
}
}
void delayMs(unsigned int x)
{
unsigned int j;
for(;x>0;x--)
for(j=0; j<0x1FFF; j++); Department of EECE-19ECS431-EMBEDDED SYSTEMS 17
} 17
Timers
The LPC2148 has two functionally identical general-purpose
timers: Timer0 and Timer1.
These both timers are 32-bit along with 32-bit prescaler.
Timer allows us to generate precise time delay.
How Timers in LPC2148 ARM7 Microcontroller Works?
Department of EECE-19ECS431-EMBEDDED SYSTEMS 18
18
Timers
Department of EECE-19ECS431-EMBEDDED SYSTEMS 19
19
Timers
Department of EECE-19ECS431-EMBEDDED SYSTEMS 20
20
Timers
In this code LED will Blink with a 1-second delay. I’m using Timer 0 in this code. LEDs are connected to Port 0.
#include<lpc214x.h>
void delay(unsigned int z);
void pll();
int main(void)
IO0DIR=0xffffffff;
pll(); //Fosc=12Mhz,CCLK=60Mhz,PCLK=60MHz
while(1) {
IO0SET=0xffffffff;
delay(1000); //1sec delay
IO0CLR=0xffffffff;
delay(1000); //1sec delay
} Department of EECE-19ECS431-EMBEDDED SYSTEMS 21
21
Timers
void pll() //Fosc=12Mhz,CCLK=60Mhz,PCLK=60MHz
PLL0CON=0x01;
PLL0CFG=0x24;
PLL0FEED=0xaa;
PLL0FEED=0x55;
while(!(PLL0STAT&(1<<10)));
PLL0CON=0x03;
PLL0FEED=0xaa;
PLL0FEED=0x55;
VPBDIV=0x01;
Department of EECE-19ECS431-EMBEDDED SYSTEMS 22
22
Timers
void delay(unsigned int z)
T0CTCR=0x0; //Select Timer Mode
T0TCR=0x00; //Timer off
T0PR=59999; //Prescaler value for 1ms
T0TCR=0x02; //Timer reset
T0TCR=0x01; //Timer ON
while(T0TC<z);
T0TCR=0x00; //Timer OFF
T0TC=0; //Clear the TC value. This is Optional.
Department of EECE-19ECS431-EMBEDDED SYSTEMS 23
23
Phase Locked Loop (PLL)
• There are two PLL modules in the LPC2141/2/4/6/8 microcontroller.
• The PLL0 is used to generate the CCLK clock (system clock) while the PLL1 has to
supply the clock for the USB at the fixed rate of 48 MHz.
• Structurally these two PLLs are identical with exception of the PLL interrupt
capabilities reserved only for the PLL0.
• The PLL0 and PLL1 accept an input clock frequency in the range of 10 MHz to 25
MHz only.
• The input frequency is multiplied up the range of 10 MHz to 60 MHz for the CCLK
and 48 MHz for the USB clock using a Current Controlled Oscillators (CCO).
Department of EECE-19ECS431-EMBEDDED SYSTEMS 24
24
PLL
The multiplier can be an integer value from 1 to 32 (in practice, the multiplier value
cannot be higher than 6 on the LPC2141/2/4/6/8 due to the upper frequency limit of the
CPU).
The CCO operates in the range of 156 MHz to 320 MHz, so there is an additional
divider in the loop to keep the CCO within its frequency range while the PLL is
providing the desired output frequency.
The output divider may be set to divide by 2, 4, 8, or 16 to produce the output clock.
Since the minimum output divider value is 2, it is insured that the PLL output has a 50%
duty cycle.
Department of EECE-19ECS431-EMBEDDED SYSTEMS 25
25
PLL
PLL activation is controlled via the PLLCON register. The PLL multiplier and divider
values are controlled by the PLLCFG register. These two registers are protected in order
to prevent accidental alteration of PLL parameters or deactivation of the PLL.
Department of EECE-19ECS431-EMBEDDED SYSTEMS 26
26
PLL
Department of EECE-19ECS431-EMBEDDED SYSTEMS 27
27
PLL
Department of EECE-19ECS431-EMBEDDED SYSTEMS 28
28
PLL
Register description
Department of EECE-19ECS431-EMBEDDED SYSTEMS 29
29
PLL
PLL Control register (PLL0CON ):
Department of EECE-19ECS431-EMBEDDED SYSTEMS 30
30
PLL
Register description
Department of EECE-19ECS431-EMBEDDED SYSTEMS 31
31
PLL
PLL Configuration register (PLL0CFG ):
Department of EECE-19ECS431-EMBEDDED SYSTEMS 32
32
PLL
PLL Configuration register (PLL0CFG ):
Department of EECE-19ECS431-EMBEDDED SYSTEMS 33
33
PLL
PLL Configuration register (PLL0CFG ):
Department of EECE-19ECS431-EMBEDDED SYSTEMS 34
34
PLL
PLL Status register (PLL0STAT):
Department of EECE-19ECS431-EMBEDDED SYSTEMS 35
35
PLL
Deriving PCLK from CCLK
Department of EECE-19ECS431-EMBEDDED SYSTEMS 36
36
PLL
How to Configure PLL
1.Enable PLL --------- PLL0CON=0x01
2.Configure PLLCFG -------MSEL 4 for 5 and PSEL 2.
3.FEED sequesnce-------- PLL0FEED=0xAA; PLL0FEED=0x55;
4. PLL Status register--- PLL0STAT
5. Connect the PLL-------PLL0CON-----00000011=0x03
6. FEED sequesnce-------- PLL0FEED=0xAA; PLL0FEED=0x55;
7.Derive PCLK--------- VPBDIV---PCLK.
Department of EECE-19ECS431-EMBEDDED SYSTEMS 37
37
Timers
Register description
Each Timer/Counter contains the following registers
1)Timer Control Register (TCR):Timer Control register used to control the timer
control functions. We’ll enable, disable and reset Timer Counter (TC) through this
register
Department of EECE-19ECS431-EMBEDDED SYSTEMS 38
38
Timers
Register description
Each Timer/Counter contains the following registers
2) Count Control Register (CTCR):
The Count Control Register (CTCR) is used to select between Timer and Counter mode,
and in Counter mode to select the pin and edge(s) for counting.
Department of EECE-19ECS431-EMBEDDED SYSTEMS 39
39
Timers
Register description
Each Timer/Counter contains the following registers
2) Count Control Register (CTCR):
The Count Control Register (CTCR) is used to select between Timer and Counter mode,
and in Counter mode to select the pin and edge(s) for counting.
Department of EECE-19ECS431-EMBEDDED SYSTEMS 40
40
Timers
Register description
3) Timer Counter (TC)
The 32-bit Timer Counter is incremented when the Prescale Counter reaches its terminal
count. Unless it is reset before reaching its upper limit, the TC will count up through the
value 0xFFFF FFFF and then wrap back to the value 0x0000 0000.
4). Prescale Register (PR)
The 32-bit Prescale Register specifies the maximum value for the Prescale Counter.
Department of EECE-19ECS431-EMBEDDED SYSTEMS 41
41
Timers
Register description
5) Prescale Counter Register (PC)
The Prescale Counter is incremented on every PCLK. When it reaches the value stored in the
Prescale Register, the Timer Counter is incremented and the Prescale Counter is reset on the
next PCLK.
Department of EECE-19ECS431-EMBEDDED SYSTEMS 42
42
Timers
TIMER REGISTERS in LPC2148
Department of EECE-19ECS431-EMBEDDED SYSTEMS 43
43
Timers
TIMER REGISTERS in LPC2148
Department of EECE-19ECS431-EMBEDDED SYSTEMS 44
44
Timers
TIMER REGISTERS in LPC2148
Department of EECE-19ECS431-EMBEDDED SYSTEMS 45
45
LCD interfacing
• LCDs (Liquid Crystal Displays) are used for displaying status or
parameters in embedded systems.
• A 16×2 LCD means it can display 16 characters per line and there are
2 such lines. In this LCD each character is displayed in a 5×7 pixel
matrix.
• LCD 16x2 is 16 pin device which has 8 data pins (D0-D7) and 3
control pins (RS, RW, EN). The remaining 5 pins are for supply and
backlight for the LCD.
• The control pins help us configure the LCD in command mode or
data mode. They also help configure read mode or write mode and
when to read or write.
Department of EECE-19ECS431-EMBEDDED SYSTEMS 46
LCD interfacing
The command register stores the command instructions given to the
LCD.
A command is an instruction given to LCD to do a predefined task
like initializing it, clearing its screen, setting the cursor position,
controlling the display, etc.
The data register stores the data to be displayed on the LCD. The data
is the ASCII value of the character to be displayed on the LCD.
LCD 16x2 can be used in 4-bit mode or 8-bit mode depending on the
requirement of the application
Department of EECE-19ECS431-EMBEDDED SYSTEMS 47
Interfacing LCD with LPC2148
Department of EECE-19ECS431-EMBEDDED SYSTEMS 48
48
LCD interfacing
Department of EECE-19ECS431-EMBEDDED SYSTEMS 49
LCD interfacing
Pin Function Name
No
1 Ground (0V) Ground
2 Supply voltage; 5V (4.7V – 5.3V) Vcc
Contrast adjustment; through a variable VEE
3 resistor
4 Selects command register when low; and Register Select
data register when high
5 Low to write to the register; High to read Read/write
from the register
6 Sends data to data pins when a high to low Enable
pulse is given
7 DB0
8 DB1
9 DB2
10 DB3
8-bit data pins
11 DB4
12 DB5
13 DB6
14 DB7
15 Backlight VCC (5V) Led+
Department of EECE-19ECS431-EMBEDDED SYSTEMS 50
16 Backlight Ground (0V) Led-
LCD interfacing
LCD Data pins D0-D7
are connected to pins
P0.8-P0.15 of Port 0
LCD control pins RS,
RW and EN are
connected to P0.4,
P0.5 P0.6 respectively.
Department of EECE-19ECS431-EMBEDDED SYSTEMS 51
LCD interfacing
Command Write Function
For command mode, RS = 0.
RW = 0 for write.
High to low EN pulse of minimum 450ns high pulse width.
Data Write Function (Single Character)
For data mode, RS = 1.
RW = 0 for write.
High to low EN pulse of minimum 450ns high pulse width.
Data Write Function(String)
For data mode, RS = 1.
RW = 0 for write.
High to low EN pulse of minimum 450ns high pulse width.
Department of EECE-19ECS431-EMBEDDED SYSTEMS 52
LCD interfacing
Department of EECE-19ECS431-EMBEDDED SYSTEMS 53
LCD interfacing Program
#include <lpc214x.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
void delay_ms(uint16_t j) /* Function for delay in milliseconds */
{
uint16_t x,i;
for(i=0;i<j;i++)
{
for(x=0; x<6000; x++); /* loop to generate 1 millisecond delay with
Cclk = 60MHz */
}
}
Department of EECE-19ECS431-EMBEDDED SYSTEMS 54
LCD interfacing Program
int main(void)
{
int j;
j = 0;
char val_j[3];
LCD_INIT();
LCD_STRING("Good Day! hello");
LCD_CMD(0xC0);
LCD_STRING("Val of j is:");
for(j=0;j<10;j++)
{
sprintf(val_j,"%d ",j);
LCD_STRING(val_j);
delay_ms(100);
LCD_CMD(0xCC);
}
return 0;
} Department of EECE-19ECS431-EMBEDDED SYSTEMS 55
LCD interfacing Program
void LCD_CMD(char command)
{
IO0PIN = ( (IO0PIN & 0xFFFF00FF) | (command<<8) );
IO0SET = 0x00000040; /* EN = 1 */
IO0CLR = 0x00000030; /* RS = 0, RW = 0 */
delay_ms(2);
IO0CLR = 0x00000040; /* EN = 0, RS and RW unchanged(i.e.
RS = RW = 0) */
delay_ms(5);
}
Department of EECE-19ECS431-EMBEDDED SYSTEMS 56
LCD interfacing Program
void LCD_INIT(void)
{
IO0DIR = 0x0000FFF0; /* P0.8 to P0.15 LCD Data. P0.4,5,6 as
RS RW and EN */
delay_ms(20);
LCD_CMD(0x38); /* Initialize lcd */
LCD_CMD(0x0C); /* Display on cursor off */
LCD_CMD(0x06); /* Auto increment cursor */
LCD_CMD(0x01); /* Display clear */
LCD_CMD(0x80); /* First line first position */
}
Department of EECE-19ECS431-EMBEDDED SYSTEMS 57
LCD interfacing Program
void LCD_STRING (char* msg)
{
uint8_t i=0;
while(msg[i]!=0)
{
IO0PIN = ( (IO0PIN & 0xFFFF00FF) | (msg[i]<<8) );
IO0SET = 0x00000050; /* RS = 1, , EN = 1 */
IO0CLR = 0x00000020; /* RW = 0 */
delay_ms(2);
IO0CLR = 0x00000040; /* EN = 0, RS and RW unchanged(i.e. RS = 1,
RW = 0) */
delay_ms(5);
i++;
}
} Department of EECE-19ECS431-EMBEDDED SYSTEMS 58
LCD interfacing Program
void LCD_CHAR (char msg)
{
IO0PIN = ( (IO0PIN & 0xFFFF00FF) | (msg<<8) );
IO0SET = 0x00000050; /* RS = 1, , EN = 1 */
IO0CLR = 0x00000020; /* RW = 0 */
delay_ms(2);
IO0CLR = 0x00000040; /* EN = 0, RS and RW
unchanged(i.e. RS = 1, RW = 0) */
delay_ms(5);
}
Department of EECE-19ECS431-EMBEDDED SYSTEMS 59
LM35 Temperature Sensor
Department of EECE-19ECS431-EMBEDDED SYSTEMS 60
LM35 Temperature sensor
Department of EECE-19ECS431-EMBEDDED SYSTEMS 61
61
LM35 Temperature sensor
Department of EECE-19ECS431-EMBEDDED SYSTEMS 62
62
Interfacing LM35 with LPC2148
•#include <lpc214x.h>
•#include <stdint.h>
•#include "LCD-16x2-8bit.h"
•#include <stdio.h>
•#include <string.h>
•int main(void)
•{
•uint32_t result;
float voltage;
•char volt[18];
•LCD_Init();
•PINSEL1 = 0x01000000; /* P0.28 as AD0.1 */
•AD0CR = 0x00200402; /* ADC operational, 10-bits, 11 clocks for conversion */
•
Department of EECE-19ECS431-EMBEDDED SYSTEMS 63
Interfacing LM35 with LPC2148
•while(1)
• {
• AD0CR = AD0CR | (1<<24); /* Start Conversion */
• while ( (AD0DR1 & 0x80000000) ==0); /* Wait till DONE */
• result = AD0DR1;
• result = (result>>6);
• result = (result & 0x000003FF);
• voltage = ( (result/1023.0) * 3.3 ); /* Convert ADC value to equivalent voltage */
• LCD_Command(0x80);
• sprintf(volt, "Voltage=%.2f V ", voltage);
• LCD_String(volt);
• memset(volt, 0, 18);
• }
Department of EECE-19ECS431-EMBEDDED SYSTEMS 64
•}
ADC (Analog to Digital Converter)
• 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.
• ADCs in LPC2148 use Successive Approximation technique to convert
analog signal into digital form.
• This Successive Approximation process requires a clock less than or equal to
4.5 MHz. We can adjust this clock using clock divider settings.
• Both ADCs in LCP2148 convert analog signals in the range of 0V to VREF
(typically 3V) Department of EECE-19ECS431-EMBEDDED SYSTEMS 65
ADC (Analog to Digital Converter)
Department of EECE-19ECS431-EMBEDDED SYSTEMS 66
ADC (Analog to Digital Converter)
AD0.1:4, AD0.6:7 & AD1.7:0 (Analog Inputs)
• These are Analog input pins of ADC.
• If ADC is used, signal level on analog pins must not be above the level
of VDDA (7th Pin) otherwise, ADC readings will be invalid.
• If ADC is not used, then the pins can be used as 5V tolerant digital I/O
pins.
VREF (Voltage Reference)
• Provide Voltage Reference for ADC.
VDDA& VSSA (Analog Power and Ground)
• These are the power and ground pins for ADC. These should be same
as VDD & VSS.
Department of EECE-19ECS431-EMBEDDED SYSTEMS 67
ADC (Analog to Digital Converter)
ADC0 Registers
ADC registers which are used to control and monitors the ADC operation.
Department of EECE-19ECS431-EMBEDDED SYSTEMS 68
ADC (Analog to Digital Converter)
ADC0 Registers
ADC registers which are used to control and monitors the ADC operation.
Department of EECE-19ECS431-EMBEDDED SYSTEMS 69
ADC (Analog to Digital Converter)
ADC0 Registers
ADC registers which are used to control and monitors the ADC operation.
Department of EECE-19ECS431-EMBEDDED SYSTEMS 70
ADC (Analog to Digital Converter)
ADC0 Registers
ADC registers which are used to control and monitors the ADC operation.
Department of EECE-19ECS431-EMBEDDED SYSTEMS 71
ADC (Analog to Digital Converter)
ADC0 Registers
ADC registers which are used to control and monitors the ADC operation.
Department of EECE-19ECS431-EMBEDDED SYSTEMS 72
ADC (Analog to Digital Converter)
ADC0 Registers
ADC registers which are used to control and monitors the ADC operation.
Department of EECE-19ECS431-EMBEDDED SYSTEMS 73
ADC (Analog to Digital Converter)
ADC0 Registers
ADC registers which are used to control and monitors the ADC operation.
Department of EECE-19ECS431-EMBEDDED SYSTEMS 74
ADC (Analog to Digital Converter)
• Steps for Analog to Digital Conversion
Configure the ADxCR (ADC Control Register) according to the need of
application.
Start ADC conversion by writing appropriate value to START bits in ADxCR.
(Example, writing 001 to START bits of the register 26:24, conversion is
started immediately).
Monitor the DONE bit (bit number 31) of the corresponding ADxDRy (ADC
Data Register) till it changes from 0 to 1. This signals completion of
conversion. We can also monitor DONE bit of ADGSR or the DONE bit
corresponding to the ADC channel in the ADCxSTAT register.
Read the ADC result from the corresponding ADC Data Register.
ADxDRy. E.g. AD0DR1 contains ADC result of channel 1 of ADC0.
Department of EECE-19ECS431-EMBEDDED SYSTEMS 75