You are on page 1of 29

1.

STUDY OF ARM PROCESSOR KIT


AIM:
To study the ARM processor kit.
HARDWARE DETAILS:
The LPC Microcontroller is based on a 32\16 bit ARM7TDMI-s CPU with real time emulation and
embedded trace support, that combines with the microcontroller with embedded high sped 512KB flash
memory. It can work with 16-bit Thumb mode. With useful Implemented peripherals, plentiful code
examples and a board set of addition on board. Vi 2148 syllabus make fast and reliable tools that can
satisfy the needs of experienced engineers and beginners a like. Vi 2148SB boards achieve their small
size through modern SMD technology and multilayer Design. All controller signal and ports extend from
the controller to high density pitch connectors of the board. Vi 2148SB hardware manual describe the
board’s design and function. Precise specification for the NXP LPC2148 microcontroller can be found I
enclosed microcontroller data sheet/user’s manual. In this manual schematic diagrams and block
diagrams are attached.
ABOUT LPC2148SB CPU:
The LPC2148 microcontroller are based on a 32/16 bit ARM7TDMI-s CPU with real-time
emulation and embedded trace support that combines the microcontroller with embedded high speed
flash memory ranging from 32 KB to 512 KB. A 128-bit wide memory interface and unique accelerator
enable 32-bit code execution at the maximum clock rate. For critical code size alternative 16-bit Thumb
mode reduces code than 30% with minimal performance penalty. Due to their tiny size and low power
consumption, LPC2148 are ideal for application where miniaturization is a key requirement, such as
access control and point-of-sale. A blend of serial communication interfaces ranging from a USB 2.0 full
speed device, multiple UARTs, SPI, SSP to I2Cs and on-chip SRAM of 8 KB up to 40 KB, make these
devices very well suited for communication gateways and protocol converters, soft modems, voice
recognition and low end imaging, providing both large buffer size and high processing power. Various
32-bit timers, single or dual 10-bit ADC(s),10-bit DAC, PWM channels and 45 fast GPIO lines with up to
nine edge or level sensitive external interrupt pins make these microcontrollers particularly suitable for
industrial control and medical systems.
ABOUT ON BOARD PERIPHERALS:
 NXP LPC2148 Microcontroller (TQFP-64 Packaging)
 8 digital output – LED
 8 digital input – switch
 4*4 matrix keyboard
 Character based LCD (16*2)
 Graphics LCD (128*64)
 RS232 port o External interrupt source
 Analog input trimmer
 Two SPDT relay
 I2C Peripherals
o Real time clock
o Serial EEPROM
o Seven segment
 Buzzer
 Temperature sensor
 Stepper motor interface
 20 pin expansion Header o
 Power supply section.
APPLICATION:
 Industrial control
 Medical systems
 Access control
 Point-of-sale o Communication gateway
 Embedded soft modem
 General purpose application
MEMORY MAPPING OF THE I/O AND PERIPHERALS:
The memory mapping control alters the mapping of the interrupt vectors that appear beginning
at address 0x00000000. Vectors may be mapped to the bottom of the on-chip flash memory, or to the
on chip static RAM. This allows code running in different memory spaces to have control of the
interrupts.
MEMORY MAP CONCEPTS AND OPERATING MODES:
The basic concept on the LPC2148 is that each memory area has a “natural” in the memory map.
This is the address range for which code residing in that area is written. The bulk of each memory space
remains permanently fixed in the same location, eliminating the need to have portions of the code
designed to run in different address ranges.
UNIVERSAL ASYNCHRONOUS RECEIVER TRANSMITTER:
The LPC2148 each contains two UARTs. In addition to standard transmit and receive data lines, the
LPC2148 UARTs also provide a full modem control handshake interface. Compared to previous LPC2000
microcontrollers, UARTs in LPC2148 introduce a fractional baud rate generator for both UARTs, enabling
these microcontrollers to achieve standard baud rates such as 115200 with any crystal frequency above
2MHz. in addition, auto-CTS/RTS flow-control functions are fully implemented in hardware (UART 1 in
LPC2144/46/48 only).  16 byte receive and transmit FIFOs  Register location conform to 550 industries
standard  Receiver FIFO trigger points at 1,4,8 and 14 bytes  Built-in fractional baud rate generator
with auto bauding capabilities  Mechanism that enables software and hardware flow control
implementation.

RESULT:
2. SIMULATION OF ADDITION AND SUBTRACTION ON ARM IN ASSEMBLY
AIM:
To write an assembly language program for Addition, Subtraction and simulate the program in
the software.
APPARATUS REQUIRED:
1. Personal computer
2. IAR embedded software
PROCEDURE:
1. Open IAR Embedded software in the desktop.
2. Select, project → create new project →asm → ok.
3. Create new folder in desktop and save the project.
4. Enter the program in the workspace.
5. Save the program.
6. In options select, general option as core ARM7TDMI-S
7. Select the output converter as intel extended.
8. Select the path for linker.
9. Rebuild all
10. Select project →debug without downlading
11. Select view → register. The register window will show in the workspace.
12. Select project →make and restart debugger.
13. Press F11 key and Verify the output in register window.
FLOW CHART
PROGRAM:
#include <NXP/iolpc2148.h>
NAME main
PUBLIC __iar_program_start
SECTION .intvec : CODE (2)
CODE32
__iar_program_start
B main
SECTION .text : CODE (2)
CODE32
main NOP
LDR R0,=0X5
LDR R1,=0XA
ADD R8,R1,R0
SUB R9,R1,R0
stop B stop
END

RESULT:
3. SIMULATION OF MULTIPLICATION OPERATION ON ARM IN ASSEMBLY
AIM:
To write an assembly language program for Multiplication operations and simulate the program
in the software.
APPARATUS REQUIRED:
1. Personal computer
2. IAR embedded software
PROCEDURE:
1. Open IAR Embedded software in the desktop.
2. Select, project → create new project →asm → ok.
3. Create new folder in desktop and save the project.
4. Enter the program in the workspace.
5. Save the program.
6. In options select, general option as core ARM7TDMI-S
7. Select the output converter as intel extended.
8. Select the path for linker.
9. Rebuild all
10. Select project →debug without downlading
11. Select view → register. The register window will show in the workspace.
12. Select project →make and restart debugger.
13. Press F11 key and Verify the output in register window.
FLOW CHART
PROGRAM:
#include <NXP/iolpc2148.h>
NAME main
PUBLIC __iar_program_start
SECTION .intvec : CODE (2)
CODE32
__iar_program_start
B main
SECTION .text : CODE (2)
CODE32
main NOP
LDR R0,=0X5
LDR R1,=0XA
MUL R10, R1, R0
UMULL R11,R12, R1,R0
stop B stop
END

RESULT:
4. SIMULATION OF C PROGRAM FOR SOFT DELAY

AIM:
To write an assembly language program for soft delay and simulate the program in the software.

APPARATUS REQUIRED:
1. Personal computer
2. IAR embedded software
3. Embedded kit
4. Connecting cables
PROCEDURE:
1. Open IAR Embedded software in the desktop.
2. Select, project → create new project →C→ ok.
3. Create new folder in desktop and save the project.
4. Enter the program in the workspace.
5. Save the program.
6. In options select, general option as core ARM7TDMI-S
7. Select the output converter as intel extended.
8. Select the path for linker.
9. Rebuild all
10. Open flash magic and browse your hex file.
11. Load the program to kit and verify the output.

FLOWCHART
PROGRAM:
#include<nxp/iolpc2148.h>
void delay_ms(int j) //delay routine
{
int i;
for(i=0;i<j;i++);
}
void main()
{
unsigned int n,m=4000;

PINSEL0 = 0x00000000;
PINSEL1 = 0x00000000; // PINSEL(0,1,2) = 0 configures the pins as GPIO
PINSEL2 = 0x00000000;
IO1DIR = 0xff000000; // only P1.24 to p1.31 pin will be configured as Output Pin.
while(1)
{
for(n=0x00;n<0x08;n++)
{
IO1PIN=0x01000000 << n; // Set 1 st LED to 8th LED
delay_ms(m);
}

m=m*2; // generating variable delay for


if(m>32000) // variable flashing speed
{m=4000;}
}
}

RESULT:
5. REALIZING TIMER PERIPHERAL IN ARM BY POLLING METHOD

AIM:
To write a C program for realizing timer peripheral in ARM by polling method.
APPARATUS REQUIRED:
1. Personal computer
2. IAR embedded software
3. Embedded kit
4. Connecting cables
PROCEDURE:
1. Open IAR Embedded software in the desktop.
2. Select, project → create new project → C → ok.
3. Create new folder in desktop and save the project.
4. Enter the program in the workspace.
5. Save the program.
6. In options select, general option as core ARM7TDMI-S
7. Select the output converter as intel extended. FLOWCHART:
8. Select the path for linker.
9. Rebuild all
10. Open flash magic and browse your hex file.
11. Load the program to kit and verify the output.
PROGRAM:
#include<nxp\iolpc2148.h>
unsigned int LED_value = 0xf0;
unsigned int timer_delay = 1000 ;
void timer_init()
{
VPBDIV = 0x00000001;
T0PR = 12000*timer_delay ;
T0MR0 = 0x01;
T0MCR = 0x02;
T0TCR = 0x00000002;
T0TCR = 0x00000001;
}
void main(void)
{
PINSEL0 = 0X00000000;
PINSEL1 = 0x00000000;
PINSEL2 = 0X00000000;
IO1DIR = 0xff000000;
timer_init();
IO1PIN = 0xff000000;
while(1)
{
if( T0TC==0 )
{
IO1PIN = LED_value <<24;
while(T0TC==0);
}
else
IO1PIN = 0x00000000;
}
}

RESULT:
6. REALIZING TIMER PERIPHERAL IN ARM BY INTERRUPT DRIVEN METHOD

AIM:
To write a program for realizing timer peripheral in ARM by interrupt driven method.
APPARATUS REQUIRED:
1. Personal computer
2. IAR embedded software
3. Embedded kit
4. Connecting cables
PROCEDURE:
1. Open IAR Embedded software in the desktop.
2. Select, project → create new project → C → ok.
3. Create new folder in desktop and save the project.
4. Enter the program in the workspace.
5. Save the program.
6. In options select, general option as core ARM7TDMI-S
7. Select the output converter as intel extended.
8. Select the path for linker.
9. Rebuild all
10. Open flash magic and browse your hex file. FLOW CHART:
11. Load the program to kit and verify the output.

PROGRAM:

#include <NXP/iolpc2148.h>
#include <intrinsics.h>
#include <stdio.h>
void timer0_ISR();
void timer0_init();
void feed (void);
__irq __arm void irq_handler (void);
__fiq __arm void fiq_handler (void);
void main(void)
{
PINSEL2 = 0X00000000;
IO1DIR = 0xff000000;
timer0_init();
__enable_interrupt();
while(1)
{
IO1PIN = 0x55000000;
}
}
void timer0_ISR()
{
IO1PIN = 0xAA000000;
for(int i = 0; i < 500000; ++i);
T0IR = 1;
}
void timer0_init()
{
PLLCON_bit.PLLC = PLLCON_bit.PLLE = 0;
feed();
VPBDIV_bit.VPBDIV = 0;
T0IR =0xFF;
T0TC = 0 ;
T0PR = 0 ;
T0MR0 = 3000000;
T0MCR = 3 ;
T0TCR = 1 ;
VICIntSelect = 0;
VICIntEnClear = 0xFFFFFFFF;
VICProtection = 0;
VICVectAddr = 0;
VICProtection = 0;
VICIntSelect &= ~(1<<VIC_TIMER0);
VICVectAddr0 = (unsigned int)&timer0_ISR;
VICVectCntl0 = 0x20 | VIC_TIMER0;
VICIntEnable |= (1<<VIC_TIMER0);
}
__irq __arm void irq_handler (void)
{
void (*interrupt_function)();
interrupt_function = (void(*)())VICVectAddr;
(*interrupt_function)();
VICVectAddr = 0;
}
__fiq __arm void fiq_handler (void)
{ while(1);
}
void feed (void)
{
PLLFEED=0xAA;
PLLFEED=0x55;
}

RESULT:
7. REALIZATION OF INPUT AND OUTPUT PORT IN C
AIM:
To write an C program for realization of input(Switch) and output(LED) port on embedded kit.
APPARATUS REQUIRED:
1. Personal computer
2. IAR embedded software
3. Embedded kit
4. Connecting cables
PROCEDURE:
1. Open IAR Embedded software in the desktop.
2. Select, project →create new project →C→ ok.
3. Create new folder in desktop and save the project.
4. Enter the program in the workspace.
5. Save the program.
6. In options select, general option as core ARM7TDMI-S
7. Select the output converter as intel extended.
8. Select the path for linker.
9. Rebuild all
10. Open flash magic and browse your hex file.
11. Load the program to kit and verify the output.
FLOW CHART
PROGRAM:
#include <nxp/iolpc2148.h>
static void delay (void)
{
volatile inti,j;
for (i=0;i<0x3F;i++)
for (j=0;j<500;j++);
}
// SWITCH INTERFACE
// SW0 - SW7 : P0.16 - P0.23
// LED0 - LED7 : P1.23 - P1.31
// Switch Staus Displayed on LED
//------------------------------------------------------------------------------
void main()
{
// PINSEL0 = 0x00000000;
PINSEL1 = 0x00000000; // Configured as GPIO port
PINSEL2 = 0x00000000; // Configured as GPIO port
IO0DIR = 0X00000000; // P0.16 TO P0.23 Configured as input
IO1DIR = 0Xff000000; // P1.23 TO P1.31 Configured as output

while(1)
{
// IO0CLR = 0XFF000000;
// IO1CLR = 0XFF000000;
IO1PIN = (~(IO0PIN & 0x00FF0000)<<0x08);
// delay();
}
}

RESULT:
8.EXTERNAL INTERRUPT PULSE DISPLAY IN LED
AIM:
To write a program for counting external interrupt pulses(VIC) and to display the count value in
LED.
APPARATUS REQUIRED:
1. Personal computer
2. IAR embedded software
3. Embedded kit
4. Connecting cables

PROCEDURE:
1. Open IAR Embedded software in the desktop.
2. Select, project → create new project → C → ok.
3. Create new folder in desktop and save the project.
4. Enter the program in the workspace.
5. Save the program.
6. In options select, general option as core ARM7TDMI-S
7. Select the output converter as intel extended.
8. Select the path for linker.
9. Rebuild all
10. Open flash magic and browse your hex file.
11. Load the program to kit and verify the output.

FLOWCHART
PROGRAM
#include<nxp\iolpc2148.h>

#include "intrinsics.h"

#include "stdio.h"

void EXINT3(void);

int temp;

unsigned int i=0x01;

int putchar(int ch)

if(ch=='\n')

while((U0LSR&0x20)!=0x20);

U0THR='\r';

while((U0LSR&0x20)!=0x20);

return(U0THR=ch);

void main()

PINSEL0=0X00000005; // Selecting/configuring the pins as RxD & TxD.

VPBDIV=0X01; // Making Pclk = Xclk.

int baudrate = (12000000/(19200*0.5)); // Baudrate setting (9600 bps)

U0LCR=0X83;

U0DLL = baudrate & 0X00FF;

U0DLM=( baudrate>>8) & 0X00FF;

U0LCR=0X03;

PINSEL1_bit.P0_30=2;

PINSEL2=0x00000000;

IO1DIR=0xff000000;

VICIntSelect &= ~(1<<VIC_EINT3); //Select the interrupt

VICVectAddr0 = (unsigned int)&EXINT3;

VICVectCntl0 = 0x20 | VIC_EINT3;


VICIntEnable |= (1<<VIC_EINT3);

__enable_interrupt(); //Enable Global Interrupts

while(1);

void EXINT3(void)

EXTINT_bit.EINT3=1;

IO1PIN=0x00000000;

temp=(IO1PIN | i);

IO1PIN=temp << 24;

i++;

printf("External interrupt occured\n\r");

#pragma vector=0x18

__irq __arm void irq_handler (void)

void (*interrupt_function)();

unsigned int vector;

vector = VICVectAddr;

interrupt_function = (void(*)())vector;

(*interrupt_function)();

VICVectAddr = 0;

__fiq __arm void fiq_handler (void) /*------ FIQ Handler Function ---------*/

{ while(1); }

RESULT:
9. SEVEN SEGMENT LED DISPLAY INTERFACE IN C
AIM:
To write a program for seven segments LED display interface in C on embedded kit.
APPARATUS REQUIRED:
1. Personal computer
2. IAR embedded software
3. Embedded kit
4. Connecting cables
PROCEDURE:
1. Open IAR Embedded software in the desktop.
2. Select, project → create new project → C → ok.
3. Create new folder in desktop and save the project.
4. Enter the program in the workspace.
5. Save the program.
6. In options select, general option as core ARM7TDMI-S
7. Select the output converter as intel extended.
8. Select the path for linker.
9. Rebuild all
10. Open flash magic and browse your hex file.
11. Load the program to kit and verify the output.
FLOW CHART
PROGRAM:
#include<nxp/iolpc2148.h>
#include<stdio.h>
#define DESIRED_BAUDRATE 19200
#define CRYSTAL_FREQUENCY_IN_HZ 12000000
#define PCLK CRYSTAL_FREQUENCY_IN_HZ
// since VPBDIV=0x01 #define DIVISOR (PCLK/(16*DESIRED_BAUDRATE))
int i,temp,Temp1,addr;
unsigned char i2c_data[] = {0x00,0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7c,0x07,0x7f,0x67};
static void delay(void )
{
volatile int i,j;
for (i=0;i<5;i++)
for (j=0;j<50;j++);
}
static void delay1(void )
{
volatile int i,j;
for (i=0;i<100;i++)
for (j=0;j<500;j++); }
void i2c_write(char a,char add)
{
//START CONDITION
I2C0CONSET=0x60; //0x60 chang //start I2C data transmission when set STA flag.
delay();
delay();
temp=I2C0STAT;
while(temp!=0x08)
temp=I2C0STAT;
//SLAVE ADDRESS
I2C0DAT=add;
I2C0CONCLR=0x28;
temp=I2C0STAT;
delay();
while(temp!=0x18)
{
temp=I2C0STAT;
delay();
}
//Data Write
I2C0DAT=a;
I2C0CONCLR=0x08;
temp=I2C0STAT;
while(temp!=0x28)
{
temp=I2C0STAT;//& 0x28;
delay();
}
//STOP CONDITION
I2C0CONSET=0x10;
I2C0CONCLR=0x8;
delay1();
}
int putchar(int ch)
{
while (!(U0LSR&0x20)) {}
return(U0THR=ch);
}
void main()
{
PINSEL0=0x00000055 ;
VPBDIV=0x01 ;
I2C0CONCLR=0x6C; //clear I2C0CONCLR register
I2C0CONSET=0x40; //Enable I2C.
I2C0SCLH=110;
I2C0SCLL=90;
while(1)
{
for(int i=0;i<=10;i++)
i2c_write(i2c_data[i],0x40);
for(int i=0;i<=10;i++)
i2c_write(i2c_data[i],0x42);
for(int i=0;i<=10;i++)
i2c_write(i2c_data[i],0x44);
for(int i=0;i<=10;i++)
i2c_write(i2c_data[i],0x46);
for(int i=0;i<=10;i++)
i2c_write(i2c_data[i],0x48);
for(int i=0;i<=10;i++)
i2c_write(i2c_data[i],0x4A);
}
}

RESULT:
10. SERIAL TRANSMISSION AND RECEPTION OF A CHARACTER IN C BY POLLING METHOD
AIM:
To write a cprogram for serial transmission and reception of a character by polling method.
APPARATUS REQUIRED:
1. Personal computer
2. IAR embedded software
3. Embedded kit
4. Connecting cables
PROCEDURE:
1. Open IAR Embedded software in the desktop.
2. Select, project → create new project → C → ok.
3. Create new folder in desktop and save the project.
4. Enter the program in the workspace.
5. Save the program.
6. In options select, general option as core ARM7TDMI-S
7. Select the output converter as intel extended.
8. Select the path for linker.
9. Rebuild all
10. Open wintalk and verify the output.
FLOW CHART
PROGRAM:
#include<nxp/iolpc2148.h>
#define f 12000000
void serial_Init(void)
{
unsigned int baudrate;
PINSEL0=0X00000005;
VPBDIV=0X01;
baudrate = (f/(9600*16));
U0LCR=0X80;
U0DLL = baudrate & 0X00FF;
U0DLM=( baudrate>>8) & 0X00FF;
U0LCR=0X03; } char serialrx(void)
{
unsigned char rxdata;
while(!(U0LSR&0x01));
rxdata=U0RBR;
return rxdata;
} void serialtx(char txdata)
{
while(!(U0LSR&0x20));
U0RBR=txdata;
}
void main()
{
unsigned char msg[]="\r\nEnter the Data : ";
unsigned int i,rxdata; serial_Init();
while(1)
{
for(i=0;msg[i]!='\0';i++)
{
serialtx(msg[i]);
}
rxdata = serialrx();
serialtx(rxdata);
}}
RESULT:
11. SERIAL TRANSMISSION AND RECEPTION OF A CHARACTER IN C BY INTERRUPT METHOD

AIM:
To write a program for serial transmission and reception of a character in c by interrupt method.
APPARATUS REQUIRED:
1. Personal computer
2. IAR embedded software
3. Embedded kit
4. Connecting cables
PROCEDURE:
1. Open IAR Embedded software in the desktop.
2. Select, project → create new project → C → ok.
3. Create new folder in desktop and save the project.
4. Enter the program in the workspace.
5. Save the program.
6. In options select, general option as core ARM7TDMI-S
7. Select the output converter as intel extended.
8. Select the path for linker.
9. Rebuild all
10. Open wintalk and verify the output.
FLOW CHART:
PROGRAM:
#include <NXP/iolpc2148.h>
#include <intrinsics.h>
#include <stdio.h>
void UART0_ISR();
void UART0_init();
void feed (void);
void serialtx(char txdata);
__irq __arm void irq_handler (void);
__fiq __arm void fiq_handler (void);
void main(void)
{
unsigned char msg[]="\r\n UART0 Interrupt Program. ";
PINSEL2 = 0X00000000;
IO1DIR = 0xff000000;
UART0_init();
__enable_interrupt();
for(int i=0;msg[i]!='\0';i++)
{
serialtx(msg[i]);
}
while(1)
{
IO1PIN = 0x55000000;
}
}
void UART0_ISR()
{
int temp,buf;
__disable_interrupt();
IO1PIN = 0xAA000000;
for(int i = 0; i < 10000; ++i)
temp = U0IIR;
temp =( temp>>1 )& 0x07;
if (temp==2)
{
while (U0LSR & 0x01)
{
buf=U0RBR;
serialtx(buf);
}
}
__enable_interrupt();
VICVectAddr = 0;
}
void UART0_init()
{
PLLCON_bit.PLLC = PLLCON_bit.PLLE = 0;
feed();
VPBDIV_bit.VPBDIV = 0;
PINSEL0=0X00000005;
VPBDIV=0X01;
int baudrate = (12000000/(9600*16));
U0LCR=0X80;
U0DLL = baudrate & 0X00FF;
U0DLM=( baudrate>>8) & 0X00FF;
U0LCR=0X03;
U0IER = 0x01;
VICIntSelect = 0;
VICIntEnClear = 0xFFFFFFFF;
VICProtection = 0;
VICVectAddr = 0;
VICProtection = 0;
VICIntSelect &= ~(1<<VIC_UART0);
VICVectAddr0 = (unsigned int)&UART0_ISR;
VICVectCntl0 = 0x20 | VIC_UART0;
VICIntEnable |= (1<<VIC_UART0);
}
__irq __arm void irq_handler (void)
{
void (*interrupt_function)();
interrupt_function = (void(*)())VICVectAddr;
(*interrupt_function)();
VICVectAddr = 0;
}
__fiq __arm void fiq_handler (void)
{
while(1);
}
void feed (void)
{
PLLFEED=0xAA;
PLLFEED=0x55;
}
void serialtx(char txdata)
{
while(!(U0LSR&0x20));
U0RBR=txdata;
}

RESULT:
12. ACCESSING INTERNAL ADC OF THE ARM PROCESSOR AND TO DISPLAY IN LED
AIM:
Write a C Programs for reading an internal ADC and to display the binary output in LED.
APPARATUS REQUIRED:
1. Personal computer
2. IAR embedded software
3. Embedded kit
4. Connecting cables
PROCEDURE:
1. Open IAR Embedded software in the desktop.
2. Select, project → create new project → C → ok.
3. Create new folder in desktop and save the project.
4. Enter the program in the workspace.
5. Save the program.
6. In options select, general option as core ARM7TDMI-S
7. Select the output converter as intel extended.
8. Select the path for linker.
9. Rebuild all
10. Open wintalk and verify the output.
FLOWCHART:
PROGRAM
#include<nxp/iolpc2148.h>
#include<stdio.h>
#define DESIRED_BAUDRATE 19200
#define CRYSTAL_FREQUENCY_IN_HZ 12000000
#define PCLK CRYSTAL_FREQUENCY_IN_HZ // since VPBDIV=0x01
#define DIVISOR (PCLK/(16*DESIRED_BAUDRATE))

unsigned int ADCresult;


void ADC_init()
{
AD0CR_bit.SEL = 2; //enable AD0.3 only
AD0CR_bit.CLKDIV = 12000000 / 4500000;
AD0CR_bit.BURST = 1; // put A/D into continuous convert mode
AD0CR_bit.CLKS = 0; //11 clocks/10 bit accuracy
AD0CR_bit.PDN = 1; //power up the unit
AD0CR_bit.START = 0x0001; //start 1st cnvrsn immediately
}

void main()
{
PINSEL1 = 0x01000000; //ADC0.1 CHANNEL SELECT

PINSEL2 = 0x00000000;

IO1DIR = 0xff000000; // only P1.24 to p1.31 pin will be configured as Output Pin.

ADC_init(); //ADC INIT FUNCTION


while(1)
{
while(AD0DR_bit.DONE == 0); //wait until conversion done
ADCresult = (AD0DR >>6)& 0x3ff;
ADCresult=ADCresult <<22 ;
IO1PIN=ADCresult;

}
}

RESULT:

You might also like