Embedded System Lab Manual: B.Tech (Cse) Vi Semester
Embedded System Lab Manual: B.Tech (Cse) Vi Semester
EMBEDDED SYSTEM
LAB MANUAL
B.TECH (CSE)
VI SEMESTER
LIST OF EXPERIMENTS
7. Buzzer Interface
13. Mailbox
3
AIM
The principle feature of the ARM 7 microcontroller is that it is a register based load-and-store
architecture with a number of operating modes. While the ARM7 is a 32 bit microcontroller, it is
also capable of running a 16-bit instruction set, known as ―THUMB‖. This helps it achieve a
greater code density and enhanced power saving. While all of the register-to-register data
processing instructions are single-cycle, other instructions such as data transfer instructions, are
multi-cycle. To increase the performance of these instructions, the ARM 7 has a three-stage
pipeline. Due to the inherent simplicity of the design and low gate count, ARM 7 is the industry
leader in low-power processing on a watts per MIP basis. Finally, to assist the developer, the
ARM core has a built-in JTAG debug port and on-chip ―embedded ICE‖ that allows programs to
be downloaded and fully debugged in-system.
The LPC2148 micro-controllers are based on a 32/16 bit ARM7TDMI-S CPU core. They have
real-time emulation and embedded trace support, that combines the micro-controller with
embedded high speed flash memory of 512 kB. A 128-bit wide memory interface and a unique
accelerator architecture enable 32-bit code execution at the maximum clock rate. For critical
code size applications, the alternative 16-bit Thumb mode (16bit instruction set)reduces code by
more than 30 % with minimal performance penalty.
Due to their tiny size and low power consumption, LPC2148 are ideal for applications where
miniaturization is a key requirement, such as access control systems and point-of-sale systems. It
has serial communications interfaces ranging from a USB 2.0 Full Speed device, multiple
UARTS, SPI, SSP to I2Cs. It has on-chip SRAM of 8 kB up to 40 kB. This makes 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, dual 10-bit ADC(s), single 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.
5
USB 2.0 Full Speed compliant Device Controller with 2 kB of endpoint RAM.
In addition, the LPC2146/8 provide 8 kB of on-chip RAM accessible to USB by DMA.
One or two (LPC2141/2 vs. LPC2144/6/8) 10-bit A/D converters provide a total of 6/14
analog inputs, with conversion times as low as 2.44 µs per channel.
When in a privileged mode, it is also possible to load / store the (banked out) user mode registers
to or from memory.
Connector Details
40-Pin Expansion Connector
8
JTAG Connector
Power Supply
The external power can be AC or DC, with a voltage between (9V/12V,1A output) at 230V AC
input. The ARM board produces +5V using an LM7805 voltage regulator, which provides
supply to the peripherals. LM1117 Fixed +3.3V positive regulator used for processor &
processor related peripherals. USB socket meant for power supply and USB communication,
user can select either USB or Ext power supply through JP14. Separate On/Off Switch (SW24)
for controlling power to the board.
NXP Semiconductors produce a range of Microcontrollers that feature both on-chip Flash
memory and the ability to be reprogrammed using In-System Programming technology.
Program/Execution Mode
RS-232 Communication
•
RS-232 communication enables point-to-point data transfer. It is commonly used in data
acquisition applications, for the transfer of data between the microcontroller and a PC.
• The voltage levels of a microcontroller and PC are not directly compatible with those of
RS-232, a level transition buffer such as MAX3232 be used.
10
TXD-0 P0.0
UART0(P1)
ISP PGM RXD-0 P0.1
TXD-1 P0.8
UART1
(P2) RXD-1 P0.9
RESULT
Thus the ARM LPC 2148 Processor Kit was studied.
11
AIM
Write a Assembly Program to do the simple computational problem such as addition,
subtraction, division, multiplication
REQUIREMENTS
ARM LPC2148 KIT
RS232 CABLE
POWER CHORD.
SOFTWARE SPECIFICATION
KEIL COMPILER
FLASH MAGIC
ALGORITHM
PROGRAM
GLOBAL __main
AREA main, CODE, READONLY
EXPORT __main
EXPORT __use_two_region_memory
__use_two_region_memory EQU 0
BX LR
ENTRY
;Main loop begins
__main
LDR R0,=0X11111111 ;load first input
LDR R1,=0X22222222 ;load second input
ADD r2,r0,r1
12
stop B stop
end
ALGORITHM
1. Start the program
2. Create the Startup file
3. Initialize the necessary registers
4. Pass the required value to the registers
5. Execute the subtraction operation using assembly code
6. Print the result.
7. Stop the program
PROGRAM
GLOBAL __main
AREA main, CODE, READONLY
EXPORT __main
EXPORT __use_two_region_memory
__use_two_region_memory EQU 0
BX LR
ENTRY
MULTIPLICATION
ALGORITHM
PROGRAM
GLOBAL __main
AREA main, CODE, READONLY
EXPORT __main
EXPORT __use_two_region_memory
__use_two_region_memory EQU 0
BX LR
ENTRY
;Main loop begins
__main
MUL r2,r0,r1
stop B stop
end
14
PROCEDURE
RESULT
AIM
Write a Simple assembly Program for System Calls, Loops, Branches, GPIO Communication,
Communication between External Peripherals and Target Board execute the output on the target
board.
REQUIREMENTS
ALGORITHM
1. Start the program
2. Create the Startup file
3. Initialize the necessary registers
4. Execute the Assembly code
5. Create the required HEX code.
PROGRAM
This ASM code blinks 8 LEDs at the rate define by delay_on and delay_off
; Crystal:12Mhz
; LED lines: P1.16 to P1.23;
GLOBAL __main
AREA main, CODE, READONLY
EXPORT __main
EXPORT __use_two_region_memory
__use_two_region_memory EQU 0
BX LR
ENTRY
16
;Addresses of Registers
IO1DIR EQU 0xE0028018
IO1PIN EQU 0xE0028010
IO1CLR EQU 0xE002801C
IO1SET EQU 0xE0028014
PINSEL2 EQU 0xE002C014
__main
ldr r1,=PINSEL2 ;P1.16 to P1.25 are
GPIO's, P1.26 to P1.31 are debug port
ldr r2,=0x00000000
str r2, [r1]
loop
ldr r1,=IO1PIN ;Write high on LED lines
ldr r2,[r1]
mov r2,r2,lsr #8
and r2,#0x00FF0000
str r2, [r1]
B loop
END
17
PROCEDURE
RESULT
Thus the Simple assembly Program for System Calls, Loops, Branches, GPIO
Communication, Communication between External Peripherals and Target Board execute the
output on the target board.
18
AIM
Write a ‗C‘ Program to switch off and switch On the Led‘s connected to Port 1 for 1
SECOND delay using Timer.
REQUIREMENTS
ARM LPC2148 KIT
RS232 CABLE
POWER CHORD.
SOFTWARE SPECIFICATION
KEIL COMPILER
FLASH MAGIC
ALGORITHM
PROGRAM
#include <LPC214x.h>
void Timer0_Init(void);
void Timer0_Run(void);
19
int main(void)
{
VPBDIV = 0x01; //PCLK=60Mhz
IO1DIR = 0x00FF0000; //P1.16 to P1.23 are output
Timer0_Init(); //Initialize Timer0
while(1)
{
Timer0_Run();
}
}
void Timer0_Init(void)
{
/*Assuming that PLL0 has been setup with CCLK = 60Mhz and PCLK also = 60Mhz.*/
T0CTCR = 0x0;
T0PR = PRESCALE-1;
//(Value in Decimal!) - Increment T0TC at every 60000 clock cycles
//Count begins from zero hence subtracting 1
//60000 clock cycles @60Mhz = 1 mS
T0MR0 = DELAY_MS-1;
//(Value in Decimal!) Zero Indexed Count - hence subtracting 1
T0MCR = 3;
//Set bit0 & bit1 to High which is to : Interrupt & Reset TC on MR0
T0TCR = 0x02; //Reset Timer
T0TCR = 0x01; //Enable timer
}
void Timer0_Run(void)
PROCEDURE
RESULT
Thus the ―C‖ Program was written to generate delay using timer was executed and
verified successfully.
21
AIM
Write a ‗C‘ Program to demonstrate a simple interrupt handler and setting up a Timer.
REQUIREMENTS
ALGORITHM
PROGRAM
#include <LPC214x.h>
void Timer0_Init(void);
int main(void)
while(1);
void Timer0_Init(void)
/*Assuming that PLL0 has been setup with CCLK = 60Mhz and PCLK also = 60Mhz.*/
VICVectCntl4 = 0x20 | 4; //0x20 (i.e bit5 = 1) -> to enable Vectored IRQ slot
//0x4 (bit [4:0]) -> this the source number - here its timer0 which has VIC channel mask # as 4
//You can get the VIC Channel number from Lpc214x manual R2 - pg 58 / sec 5.5
PROCEDURE
RESULT
Thus the ―C‖ Program was written to demonstrate a simple interrupt handler and setting
up a Timer was executed and verified successfully.
24
AIM
REQUIREMENTS
ALGORITHM
PROGRAM
#include<lpc214x.h>
int main()
while(1)
}
26
PROCEDURE
RESULT
Thus the ―C‖ Program was written to interface 8 bit LED and switch interface was
executed and verified successfully.
27
EX NO 7 BUZZER INTERFACE
AIM
REQUIREMENTS
ALGORITHM
PROGRAM
#include <LPC214x.h>
#define BUZZ (1<<7)
void Delay(unsigned int n)
{
unsigned int i,j;
for(i=0;i<n;i++)
for(j=0;j<10000;j++);
}
int main()
{
IODIR0 |= BUZZ; //Configure Port0.7 as OutPut pin
28
while(1)
{
IOSET0 = BUZZ; // Buzzer On
Delay(100);
IOCLR0 = BUZZ; // Buzzer Off
Delay(100);
}
}
PROCEDURE
RESULT
Thus the ―C‖ Program was written to implement Buzzer interface on IDE environment
was executed and verified successfully.
29
AIM
REQUIREMENTS
ALGORITHM
PROGRAM
#include <lpc214x.h>
#define RS (1<<16)
#define RW (1<<17)
#define EN (1<<18)
#define D0 (1<<19)
#define D1 (1<<20)
#define D2 (1<<21)
#define D3 (1<<22)
unsigned char cmd[8] = {0x33,0x32,0x28,0x0C,0x06,0x01};
void lcd_cmd(unsigned char);
void lcd_data(unsigned char);
void lcd_Init(void);
void lcd_Convert(unsigned char);
30
while(1)
{
lcd_cmd(0x82);
lcd_puts("ARM7 LPC2148 KIT");
lcd_cmd(0xC0);
lcd_puts(" 16x2 LCD DEMO");
DelayMs(10000);
lcd_cmd(0x01);
}
}
void lcd_Init(void)
//LCD Initialize
{
unsigned int i;
IO0DIR = 0xFF0000;
for(i=0;i<6;i++)
{
lcd_cmd(cmd[i]);
DelayMs(5);
}
}
void lcd_cmd(unsigned char data) // LCD Command
Mode
{
IO0CLR = RS;
31
IO0CLR = RW;
lcd_Convert(data);
}
void lcd_data (unsigned char data) // LCD Data Mode
{
IOSET0 = RS;
IOCLR0 = RW;
lcd_Convert(data);
}
void lcd_Convert(unsigned char c)
{
if(c & 0x80) IOSET0 = D3; else IOCLR0 = D3;
if(c & 0x40) IOSET0 = D2; else IOCLR0 = D2;
if(c & 0x20) IOSET0 = D1; else IOCLR0 = D1;
if(c & 0x10) IOSET0 = D0; else IOCLR0 = D0;
IO0SET = EN; DelayMs(8); IO0CLR = EN;
PROCEDURE
RESULT
Thus the ―C‖ Program was written to display a message in a 2 line X 16 characters LCD
display was executed and verified successfully.
33
AIM
REQUIREMENTS
ARM LPC2148 KIT
RS232 CABLE
POWER CHORD.
SOFTWARE SPECIFICATION
KEIL COMPILER
FLASH MAGIC
THEORY
A seven segment display is the most basic electronic display device that can display digits from
0-9. They find wide application in devices that display numeric information like digital clocks, radio,
microwave ovens, electronic meters etc. The most common configuration has an array of eight LEDs
arranged in a special pattern to display these digits. They are laid out as a squared-off figure ‗8‘. Every
34
LED is assigned a name from 'a' to 'h' and is identified by its name. Seven LEDs 'a' to 'g' are used to
display the numerals while eighth LED 'h' is used to display the dot/decimal.
A seven segment is generally available in ten pin package. While eight pins correspond to the eight LEDs,
the remaining two pins (at middle) are common and internally shorted. These segments come in two
configurations, namely, Common cathode (CC) and Common anode (CA). In CC configuration, the
negative terminals of all LEDs are connected to the common pins. The common is connected to ground
and a particular LED glows when its corresponding pin is given high. In CA arrangement, the common
pin is given a high logic and the LED pins are given low to display a number.
ALGORITHM
1. Start the program
2. Load the required header files
3. Initialize the variables, array and for loop
4. Define main(),assign values to the variables SDA0, SCL0
5. Use FOR loop for incrementing the counter
6. Display the counter in seven segment display.
7. Stop the program.
PROGRAM
#include <LPC214x.h>
#include <stdio.h>
#defineI2C0CON_AA 2
#defineI2C0CON_SI 3
#defineI2C0CON_STO 4
#defineI2C0CON_STA 5
#defineI2C0CON_I2EN 6
int main()
{
DelayMs(300);
VPBDIV = 0x02;
PINSEL0 = 0x00000055; // P0.3 - SDA0 and P0.2
- SCL0
PINSEL2 = 0x00000004;
I2C_Init();
DelayMs(100);
while(1)
{
for(count=0;count<9999;count++)
{
Count_digit(count);
Write_SAA1064(0x70,Buff[2],Buff[3],Buff[1],Buff[0]);
}
}
}
void I2C_Init (void)
{
I2C0SCLH=150;//50%duty cycle ..... I2C Frequency ->100 KHz for PCLK = 30MHz
I2C0SCLL = 150;
I2C0CONSET =1 << I2C0CON_I2EN; //Enable I2C 0
I2C0CONCLR=1 << I2C0CON_SI;
}
Buff[2] = CC[(Val/10)];
Buff[3] = CC[(Val%10)];
}
void DelayMs(unsigned int ms) //Delay Definition passing ms delay at 30Mhz frequency
{
long i,j;
for (i = 0; i < ms; i++ )
for (j = 0; j < 6659; j++ );
}
PROCEDURE
RESULT
Thus the ―C‖ Program was written to demonstrate I2C interface on IDE environment by
communicating with Seven Segment Display was executed and verified successfully.
38
AIM
REQUIREMENTS
ARM LPC2148 KIT
RS232 CABLE
POWER CHORD.
SOFTWARE SPECIFICATION
KEIL COMPILER
FLASH MAGIC
THEORY
The I2C (Inter-IC) bus is a bi-directional two-wire serial bus that provides a communication link between
integrated circuits (ICs).I2C is a synchronous protocol that allows a master device to initiate
communication with a slave device. Data is exchanged between these devices .
I2C is a Master-Slave protocol. I2C has a clock pulse along with the data. Normally, the master device
controls the clock line, SCL. This line dictates the timing of all transfers on the I2C bus. No data will be
transferred unless the clock is manipulated. All slaves are controlled by the same clock, SCL.
I2C bus supports many devices, each device is recognized by a unique address—whether it‘s a micro-
controller, LCD Driver, memory or keyboard interface and can operate as transmitter or receiver based on
the functioning of the device. The controller designed controls the EEPROM device
through I2C protocol. The I2C Controller here acts as a master device and controls EEPROM which acts
as a slave. The read-write operations are accomplished by sending a set of control signals including the
address and/or data bits. The control signals must be accompanied with proper clock signals.
39
ALGORITHM
PROGRAM:
#include <lpc214x.h> //Includes LPC2148 register definitions
#define MAX_BUFFER_SIZE 16
#define DEVICE_ADDR 0xA0
#define BLK_0 0x00
#define BLK_1 0x02
#define MAX_BLOCK_SIZE 256
void Send_Start()
{
I2C1CONSET=0x20;
}
void Send_Stop()
{
I2C1CONSET=0x10;
}
{
Send_Start();
if(I2C_Status(0x08)) //Start has been transmitted
{
return 1;
}
I2C1DAT=BLOCK_ADDR;
if(I2C_Status(0x28)) //Block address has been transmitted
{
43
return 1;
}
void I2C_Init()
{
PINSEL0|=0x30C00000;
I2C1CONCLR=0x6C;
I2C1CONSET=0x40;
I2C1SCLH =80;
I2C1SCLL =70;
}
44
int main(void)
{
PINSEL2 = 0;
IO1DIR = (1<<19) | (1<<18) | (1<<17) | (1<<16); // Set P1.16, P1.17, P1.18, P1.19 as Output
IO1DIR &= 0xfC7fffff;
LED1_OFF();LED2_OFF();LED3_OFF();LED4_OFF();
UART0_Init(9600);
I2C_Init();
UART0_puts("\033[2J");
UART0_puts ("********* ARM Primer LPC-2148 I2C EEPROM Demo **********\n\n\r");
UART0_puts
(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n\n\r");
UART0_puts ("[~] Turn SW 20 ON to Write default data to EEPROM! \n\r");
UART0_puts ("[~] Turn SW 21 ON to Read and Display data from EEPROM! \n\r");
UART0_puts ("[~] Turn SW 22 ON to Erase data from EEPROM \n\r");
45
while(1)
{
if ((IOPIN1 & SW3) == 0) /*...To Load the Default Data to the EEPROM ...*/
{
LED1_ON(); //Write Indicator
if(Page_Write(BLK_1,0x00,I2C_WR_Buf))
{
UART0_puts("Write Failed");
LED4_ON();
}
Delay(50);
LED1_OFF();
UART0_puts("Data Written Successfully\r\n");
while (!(IOPIN1 & SW3));
}
else if ((IOPIN1 & SW4) == 0) /*..To Read the Data Stored in the EEPROM...*/
{
LED2_ON(); //Read indicator
if(Page_Read(BLK_1,0x00))
{
UART0_puts("Read Failed");
LED4_ON();
}
else
{
UART0_puts("Data Read:");
UART0_puts(I2C_RD_Buf);
UART0_puts("\r\n");
}
Delay(50);
LED2_OFF();
while (!(IOPIN1 & SW4));
}
else if ((IOPIN1 & SW5) == 0)
{
LED3_ON(); //Write Indicator
if(Page_Write(BLK_1,0x00,I2C_ER_Buf))
{
UART0_puts("Write Failed");
LED4_ON();
}
Delay(50);
LED3_OFF();
UART0_puts("Data Erase Successfully\r\n");
while (!(IOPIN1 & SW5));
46
}
}
}
PROCEDURE
RESULT
Thus the ―C‖ Program was written to demonstrate I2C interface with serial EEPROM was
executed and verified successfully.
47
EX NO 11 SERIAL COMMUNICATION
AIM
REQUIREMENTS
ARM LPC2148 KIT
RS232 CABLE
POWER CHORD.
SOFTWARE SPECIFICATION
KEIL COMPILER
FLASH MAGIC
ALGORITHM
PROGRAM
#include <LPC214x.H>
#define PCLK 30000000 // PCLK for configuration
baudrate
void UART0_Init(unsigned int baudrate);
void UART0_PutC(char c);
void UART0_PutS(char *p);
unsigned int getchar (void);
int main(void)
{
VPBDIV = 0x02; //Divide Pclk by two
UART0_Init(9600);
48
while(1)
{
UART0_PutS("Pressed Key is: ");
UART0_PutC(getchar());
UART0_PutS("\r\n");
}
}
PROCEDURE
RESULT
Thus the ―C‖ Program was written to demonstrate I2C interface with serial EEPROM was
executed and verified successfully.
50
AIM
Write an application to that creates Multi tasking with RTOS Control for two different
task of rolling led with time delay.
REQUIREMENTS
ARM LPC2148 KIT
RS232 CABLE
POWER CHORD.
SOFTWARE SPECIFICATION
KEIL COMPILER
FLASH MAGIC
ALGORITHM
PROGRAM
#include "config.h"
#include "stdlib.h"
//unsigned int i;
0x00100000,0x00200000,0x00400000,0x00800000};
IO1DIR |= 0x00FF0000;
for(i=0;i<16;i++)
if(i<8)
IO1SET |= ((LED[7-i]));
OSTimeDly(60);
IO1CLR |= ((LED[7-i]));
else
IO1SET |= ((LED[i-8]));
OSTimeDly(60);
IO1CLR |= ((LED[i-8]));
PROCEDURE
RESULT
Thus the application to an application to that creates Multi tasking with RTOS Control
for two different task of rolling led with time delay was executed and verified
successfully.
53
EX NO 13 MAIL BOX
AIM
REQUIREMENTS
ARM LPC2148 KIT
RS232 CABLE
POWER CHORD.
SOFTWARE SPECIFICATION
KEIL COMPILER
FLASH MAGIC
ALGORITHM
PROGRAM
for (;;) {
os_mbx_wait (MsgBox, (void **)&rptr, 0xffff); /* wait for the message */
printf ("\nVoltage: %.2f V\n",rptr->voltage);
printf ("Current: %.2f A\n",rptr->current);
printf ("Number of cycles: %d\n",rptr->counter);
_free_box (mpool, rptr); /* free memory allocated for message */
}
56
/*----------------------------------------------------------------------------
* Main: Initialize and start RTX Kernel
*---------------------------------------------------------------------------*/
int main (void) { /* program execution starts here */
PROCEDURE
RESULT
Thus the application to send and receive mail from mail box was executed and verified
successfully.