Cycle 3
Cycle 3
Cycle 3
: 4
DATE:
TRANSMISSION AND RECEPTION OF DATA
THROUGH SERIAL PORT
AIM:
To write an Embedded C program to perform transmission and reception of data
through serial port using ARM Microcontroller
KIT REQUIRED:
• LPC2148 Microcontroller
SOFTWARE REQUIRED:
• Flash Magic
• Keil uVision 4 IDE
ALGORITHM:
STEP 1: Start
STEP 2: Initialize UART 1
STEP 3: Set the baud rate and enable processor clock and set the frequency as 60
MHz
STEP 4: Transmit and receive the data continuously using Send_String() function
STEP 5: Stop
SOURCE CODE:
#include <LPC214x.H>
void UART1_Init()
{
PINSEL0 = 0x00050000; /* lower 4bit selected for UART1 and remaining
all bits selected for GPIO's.*/
/* frist LSB 2bit(0 and 1 bits) selected 01b for UART0 Tx.*/
/* LSB bit(2 and 3 bits) selected 01b for UART0 Rx.*/
U1LCR = 0x83; /* 0x83: enable Divisor Latch access, set 8-bit word
length,no Parity,1 Stop bit*/
VPBDIV = 0x01; /* VPBDIV: VPB bus clock divider 0x01: PCLK =
processor clock*/
U1DLL = 0x86;
U1DLM = 0x01;
U1LCR = 0x03; /* 0x03: same as above, but disable Divisor Latch
access.*/
}
unsigned char Send_Char(unsigned char ch)
{
if (ch == '\n')
{
while(!(U1LSR & 0x20));
U1THR='\r'; /* output CR */
}
while(!(U1LSR & 0x20));
RESULT:
Thus, an Embedded C program to perform transmission and reception of data
through serial port using ARM Microcontroller
EXP. NO.: 3
DATE:
TIME DELAY PROGRAM USING BUILT IN
TIMER/COUNTER FEATURE
AIM:
To write an Embedded C program to perform time delay program using built in
timer/counter feature using ARM Microcontroller
KIT REQUIRED:
• LPC2148 Microcontroller
SOFTWARE REQUIRED:
• Flash Magic
• Keil uVision 4 IDE
ALGORITHM:
STEP 1: Start
STEP 2: Initialize CPU and peripheral clock as 60 MHz
STEP 3: Initialize Timer 0
STEP 4: Configure P0.10 pin as output port
STEP 5: Set the delay for 0.5 sec and 1 sec between each time the LED starts to glow
STEP 6: Stop
SOURCE CODE:
#include <lpc214x.h>
void initClocks(void); // Setup PLL and Clock Frequency
void initTimer0(void); // Setup and Initialize Timer0
void delay_ms(unsigned int counts); // Generate delay
int main(void)
{
initClocks(); //Initialize CPU and Peripheral Clocks @ 60Mhz
initTimer0(); //Initialize Timer0
IO0DIR = (1<<10); //Configure Pin P0.10 as Output
while(1)
{
IO0SET = (1<<10); //Turn ON LED
delay_ms(1000);
IO0CLR = (1<<10); //Turn LED OFF
delay_ms(1000);
}
//return 0;
}
void initTimer0(void)
{
T0CTCR = 0x0; //Set Timer 0 into Timer Mode
T0PR = 59999; //Increment T0TC at every 60000 clock cycles
//Count begins from zero hence subtracting 1
//60000 clock cycles @60Mhz = 1 mS
T0TCR = 0x02; //Reset Timer
}
void delay_ms(unsigned int counts) //Using Timer0
{
T0TCR = 0x02; //Reset TimerT0TCR =
0x01; //Enable timer
while(T0TC < counts);//wait until TC reaches the desired delay
T0TCR = 0x00; //Disable timer
}
void initClocks(void)
{
PLL0CON = 0x01; //Enable PLL
PLL0CFG = 0x24; //Multiplier and divider setup
PLL0FEED = 0xAA; //Feed sequence PLL0FEED
= 0x55;
while(!(PLL0STAT & 0x00000400)); //is locked?
PLL0CON = 0x03; //Connect PLL after PLL is locked
PLL0FEED = 0xAA; //Feed sequence
PLL0FEED = 0x55;
VPBDIV = 0x01; // PCLK is same as CCLK i.e.60 MHz
}
RESULT:
Thus, an Embedded C program to perform time delay program using built in
timer/counter feature using ARM Microcontroller was performed and Output is
verified.
EXP. NO.: 1
DATE:
LED AND SWITCH INTERFACE
AIM:
To write an Embedded C program to perform LED and switch interface using
ARM Microcontroller.
KIT REQUIRED:
• LPC2148 Microcontroller
SOFTWARE REQUIRED:
• Flash Magic
• Keil uVision 4 IDE
ALGORITHM:
STEP 1: Start
STEP 2: Configure P0.8 - P0.15 pins as output and P1.8 – P1.15 pins as input
STEP 3: Connect the LEDs in P0.8 – P0.15 pins and switches in P1.8 – P1.15 pins
STEP 4: If the input from switches in P1.8 – P1.15 pins is “High” the corresponding
LEDs in P0.8 – P0.15 will start to glow and vice versa
STEP 5: Stop
SOURCE CODE:
#include<lpc214x.h>
int main(void)
{
IO1DIR = (0x00000000); //configure the input port at port 1.8 – port 1.15
IO0DIR =(0x0000FF00); //configure the output port at port 0.8 – port 0.15
while(1)
{
IO0CLR = (0x0000FF00); //turn off the led that is at port 0.8 – port 0.15
}
else
{
IO0SET= (0x0000FF00); //turn on the led that is at port 0.8 – port 0.15
}
}
}
RESULT:
Thus, an Embedded C program to perform LED and switch interface using
ARM Microcontroller was performed and Output is verified.
EXP. NO.: 2
DATE:
BUZZER, RELAY AND STEPPER MOTOR INTERFACE
AIM:
To write an Embedded C program to perform Buzzer, Relay and Stepper motor
interface using ARM Microcontroller
KIT REQUIRED:
• LPC2148 Microcontroller
SOFTWARE REQUIRED:
• Flash Magic
• Keil uVision 4 IDE
ALGORITHM:
STEP 1: Start
STEP 2: Configure P1.16 pin as input port and P0.10 pin as output port
STEP 3: Connect the switch in P1.16 and Buzzer/Relay in P0.10 pins respectively
STEP 4: If the input from switch in P1.16 pin is “High” the corresponding
Buzzer/Relay is activated and vice versa
STEP 5: Stop
STEP 1: Start
STEP 2: Configure P0.4 – P0.7 pins as output port
STEP 3: Load the values in the port to have the 360 degree clockwise and
anticlockwise direction with appropriate delay after each step
STEP 4: Repeat the step 3 for continuous rotation stepper motor
STEP 5: Stop
SOURCE CODE:
BUZZER/RELAY INTERFACE:
#include<lpc214x.h>
int main(void)
{
IO1DIR = ~(0x00010000); //configure the input port at port 1.16
while(1)
{
int X= IO1PIN & (0x00010000);
if(X==0) //condition for open circuit
{
else
{
RESULT:
Thus, an Embedded C program to perform Buzzer, Relay and Stepper
motor interface using ARM Microcontroller was performed and Output is verified.