EC6711 Embedded Lab Student Manual 19-20 Odd Sem PDF
EC6711 Embedded Lab Student Manual 19-20 Odd Sem PDF
DEPARTMENT OF
ELECTRONICS AND COMMUNICATION ENGINEERING
June 2019
VISION
To initiate high quality technical education and to nurture young minds towards creative
thinking that inspires them to undertake innovations in the field of Electronics and
Communication Engineering (ECE) and be competent in the global market.
To Emphasize on the student body to carry out research for the service of our Nation and to
the Society at large.
MISSION
Constantly upgrade engineering pedagogy that caters to the growing challenges of the
Industry.
Develop conceptual learning that leads towards critical and innovative thinking.
Establish good harmony with industry that fills the gap between academia and the outside
world enabling the students to prepare for diverse and competitive career paths.
To endorse higher studies and pursue research in the ECE discipline with sensitivity towards
societal requirements.
b. Ability to identify, formulate and to analyze complex real time technical problems and infer
conclusions by using their knowledge.
c. Ability to design and synthesis complex electronic circuits, digital systems , Communication
system components and processes that meet specific demands with the awareness of societal,
ecological, cultural and safety considerations.
d. Ability to conduct experiments specific to core domain, interpret resultant information and
infer correct solutions.
e. Ability to select appropriate modeling techniques, software and hardware tools and usage of
resources to create relevant solutions for complex ECE applications.
f. Ability to understand their role in society including safety, health and legal issues and the
consequent responsibilities relevant to professional engineering.
COURSE OUTCOME
CO PO 1 PO 2 PO 3 PO 4 PO 5 PO 6 PO 7 PO 8 PO 9 PO 10 PO 11
EC6711.1 3 3 3 3 3 2 - - - - 3
EC6711.2 3 3 3 3 3 - - - - - -
EC6711.3 3 2 3 2 2 - - 2 - 3 2
EC6711.4 3 2 3 2 2 - - 2 - 3 2
EC6711.5 3 3 3 3 3 2 2 2 3 3 3
Average 3 2.6 3 2.6 2.6 0.8 0.4 1.2 0.6 1.4 2.0
INDEX
LIST OF EXPERIMENTS
S.No EQUIPMENTS
1 ARM LPC2148 Trainer Kit
2 ZIGBEE Kit
3 Stepper Motor for Interfacing with ARM Kit
GENERAL PROCEDURE
1) To create a new project, choose Project → Create New µvision Project. The Create New
Project dialog box appears which lets you base your new project on a project template.
2) In the standard Save As dialog box that appears, specify where you want to place your
project file, that is, in your newly created projects directory. Type your project name in the
File name box, and click Save to create the new project. Eg. LED.
3) For selecting the ARM microcontroller, type ‘LPC2148’ in the search option available. The
microcontroller ‘LPC2148’ will appear below the NXP option. Select it and click ‘OK’.
6) To Creating your Application C file, Choose FILE menu and select NEW → File.
8) To Save your ‘C’ file, Choose File → Save As. In the standard Save As dialog box that
appears, specify where you want to place your project file, that is, in your project directory.
Type your filename in the Filename box, and click Save to create the new project. Eg. Led.c
10) In the Workspace window, select the destination to which you want to add a source file; a
group or, as in this case, directly to the project.
11) Right Click on source group and select ‘Add existing Files to the Source Group’ to open a
standard browse dialog box. Locate the files led.c select them in the file selection list, and
click ‘Add’ to add them to the project.
12) To save your work space, Choose File → Save Workspace and specify where you want to
place your workspace file. In this tutorial, you should place it in your newly created project
directory. Type LED in the File name box, and click save button.
First you will set the general options to suit the processor configuration in this tutorial.
Because these options must be the same for the whole build configuration, they must be set on
the project node.
1. Select the project folder icon LED - Debug in the Workspace window and choose
Project>Options.
2. Then select Output Converter in the Category list to display the linker option
pages. The Output options are used for specifying details about the output format
and the level of debugging information included in the output file. Select “option”
on the popup menu.
4. Select output format as “Intel Extended”, output file in the format of .hex format.
5. Select the linker file menu, linker configuration file available at project directory.
6. Choose Project>Rebuild ALL If your project has no error Building completed and
Hex file generated
7. For Creating the Hex file, we choose output file format as given below.
ISP Utility:
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.
Flash Magic is Windows software that allows easy access to all the ISP features provided by the
devices.
Under Windows, only one application may have access the COM Port at any one time,
preventing other applications from using the COM Port.
Flash Magic only obtains access to the selected COM Port when ISP operations are being
performed.
This means that other applications that need to use the COM Port, such as debugging tools, may
be used while Flash Magic is loaded.
Note that in this manual third party Compilers are listed alphabetically.
No preferences are indicated or implied.
Procedure to down load and run this program:
* Select the COM Port
* Select the Baud Rate Select Device ( Eg.LPC2148)
* Interface – None ISP
* Select Osc. Frequency – 12Mhz
* Enable “ Erase Blocks used by Hex files”
* Select the Hex File to be downloaded.
Exp. No. 1 Study of ARM evaluation system
Date:
Aim
To learn about the evolution, core features, general characteristics and applications of
ARM processors.
Theory
The LPC2148 microcontrollers 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 architecture enable 32-bit code execution at the maximum clock rate. For
critical code size applications, the alternative 16-bit Thumb mode 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 and point- of-sale. A blend of
serial communications interfaces ranging from a USB 2.0 Full Speed device, multiple UARTS,
SPI, SSP to I2Cs and onchip SRAMs of 8Kb to 40 KB on the devices which are 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.
SPECIFICATIONS:
Viva-voce
1) What are the basic units of ARM 7?
2) What is the address system supported by ARM?
3) Define RISC.
4) What are the instructions used to access the memory in ARM?
5) How are the instructions encoded in ARM machines?
6) What are the basic units of Microprocessor?
7) What is an Instruction?
8) What is clock cycle?
9) Define - RTOS
10) Define - Pipelining
11) What is cache bus?
12) What is cache miss?
13) What is meant by memory mapped I/O?
14) Define – interrupt
15) What is the function of device driver?
16) What is meant by Exception?
17) What is meant by little – endian mode?
18) What is meant by big – endian mode?
19) What is the function of CPSR?
20) What is register - indirect addressing?
Exp. No. 2 Flashing of LEDs
Date:
Aim
Equipment Required
Theory
LEDs are based on the semiconductor diode. When the diode is forward biased (switched on),
electrons are able to recombine with holes and energy is released in the form of light. This effect is called
electroluminescence and the color of the light is determined by the energy gap of the semiconductor.
Procedure:
/* This is a test program to make the LEDs L2 and L3 Blink in the ARM LPC2148 development board*/
/************************************************************************************/
Conclusion
Thus the program for flashing the Leds has been written and executed successfully.
Aim
To Interface ADC and DAC with ARM Processor and measure temperature.
Equipment Required
Theory
The LPC 2148 has 10-bit successive approximation analog to digital converter. Basic clocking for the
A/D converters is provided by the VPB clock. A programmable divider is included in each converter, to scale
this clock to the 4.5 MHz (max) clock needed by the successive approximation process. A fully accurate
conversion requires 11 of these clocks. The ADC cell can measure the voltage on any of the ADC input
signals.
ARM Board has one potentiometer for working with A/D Converter. Potentiometer outputs are in the
range of 0V to 3.3V. Switch select in right position for reading the Potentiometer value by ADC.
Procedure
/************************************************************************************/
/* This is a test program to ADC in the ARM LPC2148 development board
*/
/************************************************************************************/
/***************************************************************************/
LCD.C
/************************************************************************************/
#include <LPC214x.h>
#define RS 0x00000400 /* P0.10 */
#define CE 0x00001800 /* P1.11 */
void clrscr(char ch);
void lcdinit(void);
void lcdcmd(char);
void lcddat(char);
void gotoxy(char,char); //x,y ; x-char position(0 - 16) y-line number 0 or 1
void printstr(unsigned char *,char,char); //string,column(x),line(y)
void wait (void);
void split_numbers(unsigned int number);
#define SET 1
#define OFF 0
unsigned int thousands,hundreds,tens,ones;
void wait (void)
{ /* wait function */
int d;
for (d = 0; d < 100000; d++); /* only to delay for LED flashes */
}
void lcdinit()
{
IODIR0 |= 0xFFFFFFFF;
IOCLR0 |= 0X00000FFF;
lcdcmd(0x28);
lcdcmd(0x28);
lcdcmd(0x0c);
lcdcmd(0x06);
lcdcmd(0x01);
lcdcmd(0x0f);
wait();
}
void gotoxy(char x, char y)
{
if(y == 0)
lcdcmd(0x80+x);
else
lcdcmd(0xc0+x);
}
void printstr(unsigned char *str, char x, char y)
{
char i;
gotoxy(x,y);
wait(); //(500);
for(i=0;str[i]!='\0';i++)
lcddat(str[i]);
}
void lcdcmd(char cmd)
{
unsigned char LCDDAT;
LCDDAT = (cmd & 0xf0); //higher nibble
IOSET0 = LCDDAT;
IOCLR0 = RS;
IOSET0 = CE;
wait(); //(100); //enable lcd
IOCLR0 = CE;
IOCLR0 = 0X00000FFF;
LCDDAT = ((cmd<<0x04) & 0xf0); //lower nibble
IOSET0 = LCDDAT;
IOCLR0 = RS;
IOSET0 = CE;
wait(); //(100); //enable lcd
IOCLR0 = CE;
IOCLR0 = 0X00000FFF;
}
void lcddat(char cmd)
{
unsigned char LCDDAT;
LCDDAT = (cmd & 0xf0); //higher nibble
IOSET0 = LCDDAT;
IOSET0 = RS;
IOSET0 = CE;
wait(); //(100); //enable lcd
IOCLR0 = CE;
IOCLR0 = 0X00000FFF;
LCDDAT = ((cmd<<0x04) & 0xf0); //lower nibble
IOSET0 = LCDDAT;
IOSET0 = RS;
IOSET0 = CE;
wait (); //(100); //enable lcd
IOCLR0 = CE;
IOCLR0 = 0X00000FFF;
}
void clrscr(char ch)
{
if(ch==0)
{
printstr(" ",0,0);
gotoxy(0,0);
}
else if(ch == 1)
{
printstr(" ",0,1);
gotoxy(0,1);
}
else
{
lcdcmd(0x01);
// delay(100);
}
}
void split_numbers(unsigned int number)
{
thousands = (number
/1000); number %= 1000;
hundreds = (number /
100); number %= 100;
tens = (number / 10);
number %= 10; ones
= number ;
}
void Wait_Msg(void)
{
lcdcmd(0x01);
printstr(" Please Wait ", 0, 0);
}
void Welcome_Msg(void)
{
lcdcmd(0x01);
printstr(" Welcome to ", 0, 0);
printstr(" SMMICRRO ", 0, 1);
}
/**************************************************************/
ADC_ DRIVER.C
/**************************************************************/
#include<LPC214X.H>
void wait_long (void)
{
int d;
for (d = 0; d < 1000000; d++); /* only to delay */
}
int main()
{
wait_long();
wait_long();
PINSEL1 |= 0x00080000; //Enable pin 0.25 as DAC
DACR = 0x00017FC0;
while(1);
}
Conclusion
Thus the program for interfacing ADC and DAC has been written and executed
successfully
Aim
Equipment Required
Theory
The PWM is based on the standard timer block and inherits all of its features, although only the PWM
function is pinned out on the LPC2148. The timer is designed to count cycles of the peripheral clock (PCLK)
and optionally generate interrupts or perform other actions when specified timer values occur, based on seven
match registers. The PWM function is also based on match register events.
Procedure
Open Keil µvision software and create a new project.
Add a new file to the source group and click on c file. Give the file a name and click on
OK.
Type in the program and save it.
Build the project and check for errors.
Right click on Target1 and click on Options for target1.
In the output tab check create hex file. Build the project.
The created hex file is loaded onto the processor kit using Flash Magic tool.
Program
/**************************************************************/
SWITCH AND LED PROGRAM
/************************************************************************************/
/* Description: This program gets DIP switch inputs and switches ON corresponding LED */
/* P1.16 to P1.31 are output switch */
/************************************************************************************/
#include<LPC214x.H>
int main()
{
IO1DIR = 0xFFFF0000; // P1.16 TO P1.31 OUTPUT PIN
while(1)
{
IOCLR1 = 0xFFFF0000;
}
}
ARM DETAILS
P1.16 S&L ENABALE PIN
P1.17 S&L ENABALE PIN
P1.18 S&L ENABALE PIN
P1.19 S&L ENABALE PIN
P1.20 S&L ENABALE PIN
P1.21 S&L ENABALE PIN
P1.22 S&L ENABALE PIN
P1.23 S&L ENABALE PIN
P1.24 S&L ENABALE PIN
P1.25 S&L ENABALE PIN
P1.26 S&L ENABALE PIN
P1.27 S&L ENABALE PIN
P1.28 S&L ENABALE PIN
P1.29 S&L ENABALE PIN
P1.30 S&L ENABALE PIN
P1.31 S&L ENABALE PIN
/****************************************************************************/
PWM.C
/****************************************************************************/
/* Place lcd.c file into following directories C:\Keil\ARM\INC\Philips.********/
/* This program is used to Generate the PWM.You can change the Freq and DutyCycle*/
/* If you want. ***************************************************************/
#include<LPC214x.H>
int main(void)
{
PINSEL1 |= 0x00000400; //Enable pin0.7 as PWM2
PWMPR = 0x00000100; //Load prescaler (to vary the frequency can modify here)
PWMPCR = 0x00002000; //PWM channel single edge control, output enabled
PWMMCR = 0x00000003; //On match with timer reset the counter
/* PWMR0 AND PWMR5 Both Value can change the duty cycle
ex : PWMR0 = 10 AND PWMR5 = 2*/
PWMMR0 = 0x00000010; //set cycle rate to sixteen ticks
PWMMR5 = 0x00000008; //set rising edge of PWM2 to 2 ticks
PWMLER = 0x00000021; //enable shadow latch for match 0 - 2
PWMTCR = 0x00000002; //Reset counter and prescaler
PWMTCR = 0x00000009; //enable counter and PWM, release counter from reset
while(1) // main loop
{
}
}
ARM DETAILS
P0.7 PWM2
Conclusion
Thus the program to generate PWM has been written and executed successfully.
Aim
To Program the ARM processor to get and put characters to and from PC hyper terminal using serial
port and RTC.
Equipment Required
LPC2148 ARM evaluation kit, RS232 serial port cable.
Theory
The Real Time Clock (RTC) is a set of counters for measuring time when system power is on and
optionally when it is off. It uses little power in Power-down mode. On the LPC2148 the RTC can be clocked
by separate 32.768 KHz oscillator, or by a programmable prescale divider based on the VPB clock. Also, the
RTC is powered by its own power supply pin, VBAT, which can be connected to a battery or to the same 3.3
V supply used by the rest of the device.
Serial Communication
Serial communication takes a byte of data and transmits the 8 bits in the byte one at a time. The
advantage is that a serial port needs only one wire to transmit the 8 bits (while a parallel port needs 8). The
disadvantage is that it takes 8 times longer to transmit the data than it would if there were 8 wires. Serial ports
lower cable costs and make cables smaller.
Procedure
Program
/**************************************************************/
RTC.C
/**************************************************************/ /*
Place lcd.c file into following directories C:\Keil\ARM\INC\Philips.******/
/* This program is used to interface the RTC.You can change the date and time*/
/* If you want. This Program can both Read and write data into RTC.RTC has a*/
/* Battery backup for continuous Running. ************************************/
/*
pclk = 30,000,000 Hz
PREINT = (int)(pclk/32768)-1
PREFRAC = pclk - ((PREINT+1) x 32768)
*/
#include<LPC214X.H>
#include “lcd.c”
int main()
{
unsigned int hrs,min,sec;
wait();
wait();
wait();
wait();
lcdinit();
clrscr(2);
printstr("SM MICRRO SYSTEM",0,0);
printstr(" ARM DEV KIT ",0,1);
VPBDIV = 0x00000002; // VPB bus clock is one half of the processor clock(cclk)
PREINT = 0x00000392; // Set RTC prescaler for 30MHz Pclk
// PREINT = (int) (30,000,000/32768(RTC crystal))-1 = 914
PREFRAC = 0x00004380;
CIIR = 0x00000001; // Enable seconds counter
interrupt CCR = 0x00000001; // Start the RTC
YEAR = 2009; // Year
MONTH = 11; // Month
DOM = 25; // Day of month
DOY = 0; // Day of year
DOW = 0; // Day of week
HOUR = 18; // Hours
MIN = 30; //
Minutes SEC = 30;
printstr(" ",0,1);
while(1)
{
gotoxy(0,1);
hrs = HOUR;
min = MIN;
sec = SEC;
split_numbers(hrs);
lcddat(tens+0x30);
lcddat(ones+0x30);
lcddat(':');
split_numbers(min);
lcddat(tens+0x30);
lcddat(ones+0x30);
lcddat(':');
split_numbers(sec);
lcddat(tens+0x30);
lcddat(ones+0x30);
//lcddat(':');
}
}
Serial Port Program
/**************************************************************/ /*
Uart0 Initialization */
/* This is a test program to send and receive data via uart0 in the ARM LPC2148 */
development board itself
/************************************************************************************/
#include <LPC214x.H> /* LPC214x definitions */
#define TEMT (1<<6)
#define LINE_FEED 0x0A
#define CARRIAGE_RET 0x0D
void initserial(void)
{
PINSEL0 = 0x00000005;
U0LCR = 0x83;
U0FDR = 0x00000010;
U0DLL = 98;
U0LCR = 0x03; /* DLAB = 0 Line control register*/
U0IER = 0x01; /* Enable reciever data available interrupt*/
}
}
c[i] = '\0';
return(c);
}
int main (void)
{
unsigned char *s1;
initserial(); /* uart0 initialization */
send_string("********************************************");
send_string(" SM Micrro System ");
send_string(" Tambaram ");
send_string(" Chennai ");
send_string("********************************************");
send_string("");send_string("");
send_string("This program Echos the string entered by user.");
send_string("So,type some strings and press ENTER key");
}
Serial Program Port Details
UART 0
ARM DETAILS
P0.0 TXDO
P0.1 RXDO
UART 1
ARM DETAILS
P0.8 TXD1
P0.9 RXD1
Conclusion
Thus the program for implementing Real Time Clock and for interfacing UART has been
written and executed successfully
Aim
To program the ARM processor to display the message typed in keyboard on LCD.
Equipment Required
LPC2148 ARM evaluation kit, 2X16 LCD display, 4x4 matrix keyboard.
Theory
Keyboard
The Matrix keyboard is used to minimize the number of I/O lines. Normally it is possible to connect
only one key or switch with an I/O line. If the number of keys in the system exceeds the more I/O lines are
required. To reduce the number of I/O lines the keys are connected in the matrix circuit. Keyboards use a
matrix with the rows and columns made up of wires. Each key acts like a switch. When a key is pressed a
column wire makes contact with row wire and completes a circuit. For example 16 keys arranged in a matrix
circuit uses only 8 I/O lines.
Procedure
Open Keil µvision software and create a new project.
Add a new file to the source group and click on c file. Give the file a name and click
on OK.
Type in the program and save it.
Build the project and check for errors.
Right click on Target1 and click on Options for target1.
In the output tab check create hex file. Build the project.
The created hex file is loaded onto the processor kit using Flash Magic tool.
Program
/**************************************************************/
MAIN.C
/***********************************************************************************/
/* Description: This program gets input from Matrix key board and displays corresponding */
/* Key value in 7segment display. Hence this prohram demonstrates both */
/* 7 segment display as well as Matrix key board. */
/* P1.16 to P1.23 are inputs from matrix key board, */
/* P1.24 to P1.31 are outputs to 7 segment display */
/***************************************************************************************
**/
/* ------- matrix key board description---------- */
/* -- -- -- -- */
/* row1 -- | c |-- -- | d |-- --| e |-- -- | F |-- (SW1,SW2,SW3,SW4) */
/* -- -- -- -- */
/* -- -- -- -- */
/* row2 -- | 8 |-- -- | 9 |-- -- | A |-- -- | b |-- (SW5,SW6,SW7,SW8) */
/* -- -- -- -- */
/* -- -- -- -- */
/* row3 -- | 4 |-- -- | 5 |-- -- | 6 |-- -- | 7 |-- (SW9,SW10,SW11,SW12) */
/* -- -- -- -- */
/* -- -- -- -- */
/* row4 -- | 0 |-- -- | 1 |-- -- | 2 |-- -- | 3 |-- (SW13,SW14,SW15,SW16) */
/* -- -- -- -- */
/***************************************************************************************
**/
#include <LPC214x.h>
#define ROW1 0x00010000;
#define ROW2 0x00020000;
#define ROW3 0x00040000;
#define ROW4 0x00080000;
#define ROW_MASK 0x000F0000;
#define S7SEG_ENB 0x00B80000;
#define DIGI4_ENB 0x00800000;
//DIGI1_ENB 0x00080000;DIGI2_ENB 0x00100000; DIGI3_ENB 0x00200000;
#define S7SEG_LED 0xff000000;
void init_Matrix_7seg(void)
{
IODIR1 |= 0xff0f0000;
IODIR0 |= S7SEG_ENB;
IOPIN0 |= S7SEG_ENB;
}
return(val);
}
{
Disp_key = key;
last_key = key;
}
}
Alpha_Dispay(Disp_key);
}
}
Matrix Seven Segment Program Port Detail
ARM DETAILS
P0.19 SEGMENT ENABLE PIN
P0.21 SEGMENT ENABLE PIN
P0.22 SEGMENT ENABLE PIN
P1.16 KEY BOARD INPUT
P1.17 KEY BOARD INPUT
P1.18 KEY BOARD INPUT
P1.19 KEY BOARD INPUT
P1.20 KEY BOARD INPUT
P1.21 KEY BOARD INPUT
P1.22 KEY BOARD INPUT
P1.23 KEY BOARD INPUT
P1.24 OUTPUT SEGMENT
P1.25 OUTPUT SEGMENT
P1.26 OUTPUT SEGMENT
P1.27 OUTPUT SEGMENT
P1.28 OUTPUT SEGMENT
P1.29 OUTPUT SEGMENT
P1.30 OUTPUT SEGMENT
Conclusion
Thus the program for interfacing keypad and 7 segment led has been written and executed
successfully.
Exercise: To program the ARM processor to display the message Sin 7 Segment LED
Viva-voce
1) What is Matrix keypad?
2. What is the concept behind keypad interface?
4. What is key de bouncing?
5. List the steps involved when the key in a 4 x 4 keyboard matrix is being pressed.
6. What is the value obtained if no key is pressed?
7. What kind of interrupt is generated if a key has to be operated in an interrupt mode?
8. How will you identify that the key is pressed?
9. What are the steps involved in Keyboard Interfacing?
10. List the registers used to store the keyboard, display modes and other operations programmed by
CPU.
11. Name the mode of operation for a de bounce logic.
12. Name the mode when a data is entered from the left side of the display unit.
13. How many rows and columns are present in a 16 x 2 alphanumeric LCD?
14. How many data lines are there in a 16 x 2 alphanumeric LCD?
15. Which pin of the LCD is used for adjusting its contrast?
16. Which command of an LCD is used to shift the entire display to the right?
17. Which command is used to select the 2 lines and 5 x 7 matrix of an LCD?
18. What changes are to be made to send data to an LCD?
19. For reading operation from an LCD what changes in the software are introduced?
20. Which instruction is used to select the first row first column of an LCD?
Exp.No. 7 INTERFACING EPROM AND INTERRUPT
Date:
Aim
Program the ARM processor to study the external interrupts in LPC2148 and read/write data in
EPROM memory.
Equipment Required
Theory
Procedure
Open Keil µvision software and create a new project.
Add a new file to the source group and click on c file. Give the file a name and click on
OK.
Type in the program and save it.
Build the project and check for errors.
Right click on Target1 and click on Options for target1.
In the output tab check create hex file. Build the project.
The created hex file is loaded onto the processor kit using Flash Magic tool.
Program
EPROM PROGRAM
/*************************************************************/
I2C.C
/*************************************************************/
/* This Program For I2C Interface */
#include<LPC214x.H>
#include "lcd.c"
void InitI2C(void);
void SendI2CAddress(unsigned char Addr_S);
void WriteI2C(unsigned char Data);
void StopI2C(void);
void StartI2C(void);
#define STA 0x20
#define SIC 0x08
#define SI 0x08
#define STO 0x10
#define STAC 0x20
#define AA 0x04
void InitI2C(void)
{
I2C0CONCLR = 0xFF;
PINSEL0 |= 0x50; // Set pinouts as scl and sda
I2C0SCLL =19; //speed at 100Khz for a VPB Clock Divider = 4 at 12 MHz
I2C0SCLH =19;
I2C0CONSET = 0x40; //Active Master Mode on I2C bus
}
void SendI2CAddress(unsigned char Addr_S)
{
while(I2C0STAT!=0x08); // Wait for start to be completed
I2C0DAT = Addr_S; // Charge slave Address
I2C0CONCLR = SIC | STAC; // Clear i2c interrupt bit to send the data
while(!( I2C0CONSET & SI)) ; // wait till status available
}
unsigned char ReadI2C(void)
{
unsigned char r;
I2C0CONCLR = SIC;
I2C0CONSET = 0x04; // clear SIC;
while(!(I2C0CONSET & 0x8)); // wait till status available
r=I2C0STAT;
wait(); // check for error
if (r == 0x50) // look for "Data byte has been received; ACK has been returned"
{
lcdcmd(0x01);
printstr("Read Sucess",0,0);
}
return I2C0DAT;
}
void WriteI2C(unsigned char Data)
{
unsigned char r;
I2C0DAT = Data; // Charge Data
I2C0CONCLR = 0x8; // SIC; Clear i2c interrupt bit to send the data
while(!(I2C0CONSET & 0x8)); // wait till status available
r=I2C0STAT;
if (r == 0x28)
{ // look for "Data byte in S1DAT has been transmitted; ACK has been received"
lcdcmd(0x01);
printstr("Write Sucess",0,0);
}
}
void StopI2C(void)
{
I2C0CONCLR = SIC;
I2C0CONSET = STO;
while((I2C0CONSET&STO)); // wait for Stopped bus I2C
}
void StartI2C(void)
{
I2C0CONCLR = 0xFF; // clear I2C - included if User forgot to "StopI2C()"
// else this function would hang.
I2C0CONSET = 0x40; // Active Master Mode on I2C bus
I2C0CONSET = 0x00000020; // Start condition
}
int main()
{
unsigned char
r; wait();
wait();
wait();
wait();
lcdinit();
clrscr(2);
printstr("SM MICRRO SYSTEM",0,0);
printstr(" ARM DEV KIT ",0,1);
InitI2C();
StartI2C();
SendI2CAddress(0xa0); // EEPROM device address
WriteI2C(0); // Set the control port value
WriteI2C('B');
StopI2C();
wait();
wait();
StartI2C();
SendI2CAddress(0xa0); // EEPROM device address
WriteI2C(0); // Set the control port value
StopI2C();
StartI2C();
SendI2CAddress(0xa1); // Start the read
r=ReadI2C(); // read the result
StopI2C();
gotoxy(0,1);
split_numbers(r);
lcddat(0x30+hundreds);
lcddat(0x30+tens);
lcddat(0x30+ones);
while(1);
}
/************************************************************************************/
LCD.C
/****************************************************************************/
#define RS 0x00000400 /* P0.10 */
#define CE 0x00001800 /* P1.11 */
void clrscr(char ch);
void lcdinit(void);
void lcdcmd(char);
void lcddat(char);
void gotoxy(char,char); //x,y ; x-char position(0 - 16) y-line number 0 or 1
void printstr(char *,char,char); //string,column(x),line(y)
void wait (void);
void split_numbers(unsigned int number);
#define SET 1
#define OFF 0
unsigned int thousands,hundreds,tens,ones;
void wait (void)
{ /* wait function */
int d;
for (d = 0; d < 100000; d++); /* only to delay for LED flashes */
}
void lcdinit()
{
IODIR0 = 0xFFFFFFFF;
IOCLR0 = 0X00000FFF;
lcdcmd(0x28);
lcdcmd(0x28);
lcdcmd(0x0c);
lcdcmd(0x06);
lcdcmd(0x01);
lcdcmd(0x0f);
wait();//(1600);
}
void gotoxy(char x, char y)
{
if(y == 0)
lcdcmd(0x80+x);
else
lcdcmd(0xc0+x);
}
void printstr(char *str, char x, char y)
{
char i;
gotoxy(x,y);
wait(); //(500);
for(i=0;str[i]!='\0';i++)
lcddat(str[i]);
}
void lcdcmd(char cmd)
{
unsigned char LCDDAT;
LCDDAT = (cmd & 0xf0); //higher nibble
IOSET0 = LCDDAT;
IOCLR0 = RS;
IOSET0 = CE;
wait(); //(100); //enable lcd
IOCLR0 = CE;
IOCLR0 = 0X00000FFF;
LCDDAT = ((cmd<<0x04) & 0xf0); //lower nibble
IOSET0 = LCDDAT;
IOCLR0 = RS;
IOSET0 = CE;
wait(); //(100); //enable lcd
IOCLR0 = CE;
IOCLR0 = 0X00000FFF;
}
void lcddat(char cmd)
{
unsigned char LCDDAT;
LCDDAT = (cmd & 0xf0); //higher nibble
IOSET0 = LCDDAT;
IOSET0 = RS;
IOSET0 = CE;
wait(); //(100); //enable lcd
IOCLR0 = CE;
IOCLR0 = 0X00000FFF;
LCDDAT = ((cmd<<0x04) & 0xf0); //lower nibble
IOSET0 = LCDDAT;
IOSET0 = RS;
IOSET0 = CE;
wait(); //(100); //enable lcd
IOCLR0 = CE;
IOCLR0 = 0X00000FFF;
}
void clrscr(char ch)
{
if(ch==0)
{
printstr(" ",0,0);
gotoxy(0,0);
}
else if(ch == 1)
{
printstr(" ",0,1);
gotoxy(0,1);
}
else
{
lcdcmd(0x01);
//delay(100);
}
}
void split_numbers(unsigned int number)
{
thousands = (number /1000);
number %= 1000;
hundreds = (number / 100);
number %= 100;
tens = (number / 10);
number %= 10;
ones = number ;
}
ARM DETAILS
PO.10 RS LCD PIN
P1.11 CE LCD PIN
P0.11 SCL
P0.14 SDA
#include <LPC214x.h>
void init_VIC(void);
void init_Interrupt(void);
void init_ports(void);
void wait_for_turnoffRelay(void);
void delay(int count);
void init_VIC(void)
{
/* initialize VIC*/
VICIntEnClr = 0x00010000;
VICVectAddr = 0; //no address of ISR
VICIntSelect = 0;
}
}
int main() /*press sw10 single big switch for making interrupt*/
{
init_VIC();
init_Interrupt();
IODIR0 = 0x80002000; /* P0.13 and P0.31 defined as Outputs */
IODIR1 = 0x00040000; /* p1.16 BUZZER direction output*/
IOSET1 = 0x00040000; /* p1.16 BUZZER OFF*/
while(1)
{
IOCLR0 = 0x80002000;
delay(100000);
IOSET0 = 0x80002000;
delay(100000);
}
}
for(j=0;j<count;j++)
{
/* At 60Mhz, the below loop introduces
delay of 10 us */
for(i=0;i<35;i++);
}
}
Interrupt Buzzer Program
ARM DETAILS
P1.18 TRIGGER THE RELAY
P0.15 EINT2
Conclusion
Thus the program for interfacing I²C and implementing interrupt has been written and
executed successfully.
Viva-voce
1) How does I2C protocol work?
2) What is EEPROM?
3) What is meant by master slave mode?
4) What is meant by non-volatile memory?
5) What is an interrupt?
6) How does an interrupt request works?
7) What is a nested interrupt?
8) What are the registers used for enabling an interrupt?
9) What is PROM?
10) What is EPROM?
11) What is mask ROM?
12) Which memory allows simultaneous read and write operations?
13) Which memory has the shortest access times?
14) Which interrupt has the highest priority?
15) What is non maskable interrupt?
16) Which is the first level of memory access by the microprocessor?
17) List the types of cache memories.
18) What is the use of an interrupt?
19) What is the use of converting an interrupt to threads in a microprocessor?
20) What are the bits used to control an external interrupts?
Exp.No. 8 Interrupt Performance Characteristics of ARM
Date: and FPGA
Aim
To interface FPGA with ARM processor and study the interrupt performance characteristics of ARM
processor.
Equipment Required
Theory
Implementing a logic or algorithm using only with software involves low cost but delivers only low
performance. Implementing the same logic or algorithm only with hardware involves high performance but
with low cost.
Hence, from the above graphical analysis it is clear that while designing an embedded system the
design engineer must choose a heterogeneous methodology which involves both hardware and software. In
this heterogeneous method the engineer has to decide which part of the logic to be implemented in software
and which other part to be implemented in software based on performance. So from this experiment a student
can learn how to design an embedded system based on performance characteristics.
The aim of this experiment is to implement a UART serial communication algorithm as an embedded
system by which to learn hardware-software partitioning based on performance characteristics.
Hence in this experiment we are going to follow the heterogeneous approach to implement the UART
algorithm. So it involves both software part and as well as hardware part. Every protocol has two basic
techniques:
i. Data driving logic and
ii. Data packing/ unpacking logic
This involves feeding and obtaining the actual data to be packed to the data packing/ unpacking logic.
Data packing/unpacking logic:
This involves packing the data or unpacking the data and error checking as per the protocol specification.
In this experiment, to design UART communication
a) Data driving logic is implemented in Software. The reason for choosing this logic to be
implemented in software is
i) The data is user dependent
ii) Initiating the data transfer is also user dependent iii) Software design can easily be changed
based on the user requirement
b) Data packing/unpacking logic is implemented in hardware. The reason for choosing this logic to
be implemented in hardware is
i) Since the protocol specification is fixed one and the packing/ unpacking logic involved
designing algorithm for the protocol alone
ii) Data packing/ unpacking speed is high
Software Part:
1. UART driver i.e. data driving logic is software part in this experiment.
2. This software is written using Embedded C language
3. Keil uVision4 IDE and keil arm compiler is used for compiling the C code.
4. Flash Magic tool has been used to download the program in to ARM7 micro controller.
Hardware part:
Program
/*****************************************************************/
UART implementation FPGA & ARM7
ARM UART
/********************************************************************/
#include <LPC214x.h>
void init_ios(void)
{
/*
P1.16 to P1.23 -- IN -- rx data
P1.24 to P1.31 -- OUT -- tx data
P0.15 -- OUT -- tx cmd
P0.16 -- IN -- tx done
P0.17 -- IN -- rx_rdy
*/
IODIR1 = 0xff000000; // tx data made as output
IODIR0 = 0x00008000; // tx cmd made as output
IOCLR0 = 0xff008000; // Default both the outputs to Zero
}
void tx_char(unsigned char data)
{
char tx_done;
unsigned int i;
tx_done = ((IOPIN0>>16) & 0x00000001);
if(tx_done)
{
IOPIN1 &= ~0xff000000; // clr data port
IOPIN1 |= data<<24; // place data on port
for(i=0;i<1000;i++); // wait
IOSET0 = 1<<15; // enable tx command
for(i=0;i<9000;i++); // wait
IOCLR0 = 1<<15; // Disable tx command
while(!tx_done)
tx_done = ((IOPIN0>>16) & 0x00000001);
}
}
void tx_string(unsigned char* stringg)
{
while(*stringg != '\0')
{
tx_char(*stringg);
stringg++;
}
tx_char(0x0a);
tx_char(0x0d);
}
int main (void)
{
char i;
init_ios();
for(i=0;i<100;i++);
while (1)
{
tx_string("SM MICRRO SYSTEM");
}
}
/**************************************************************/
FPGA UART
/**************************************************************/
/* S/G Name Port in arm Data Direction in FPGA
___________________________________________________________
tx_cmd -- P0.15 IN
tx_data[0] -- P1.24 IN
tx_data[1] -- P1.25 IN
tx_data[2] -- P1.26 IN
tx_data[3] -- P1.27 IN
tx_data[4] -- P1.28 IN
tx_data[5] -- P1.29 IN
tx_data[6] -- P1.30 IN
tx_data[7] -- P1.31 IN
tx_done -- P0.16 OUT
____________________________________________________________
rx_data[0] -- P1.16 OUT
rx_data[1] -- P1.17 OUT
rx_data[2] -- P1.18 OUT
rx_data[3] -- P1.19 OUT
rx_data[4] -- P1.20 OUT
rx_data[5] -- P1.21 OUT
rx_data[6] -- P1.22 OUT
rx_data[7] -- P1.23 OUT
rx_rdy -- P0.17 OUT
________________________________
Connector Details
P0.18 - P113 P1.24- P116 |
P0.17 - P59 P1.25- P66 |
P0.16 - P112 P1.26- P91 |
P0.15 - P92 P1.27- P93 |
P0.19 - P94 P1.28- P98 |
P0.20 - P97 P1.29- P106 |
P0.21 - P105 P1.30- P103 |
P0.23 - P104 P1.31- P96 |
+5v - GND - |
P1.16 - P135 P1.23- P134 |
P1.17 - P132 P1.22- P131 |
P1.18 - P130 P1.21- P117 |
P1.19 - P139 P1.20- P126 |
---------------------------
*/
module uart_top( clk, rst, tx, rx, lcd_rs, lcd_en, //lcd_rw, lcd_dat, tx_cmd_i, tx_data_i, tx_done_o,
rx_data_o, rx_rdy_o );
/***********8 I/O Declecration**********/
input clk;
input rst;
input rx;
output tx;
input tx_cmd_i;
input [7:0]tx_data_i;
output lcd_rs; output
lcd_en; //output
lcd_rw; output
[3:0]lcd_dat; output
tx_done_o;
output [7:0]rx_data_o;
output rx_rdy_o;
/* Local Wire and reg decleration for I/Os */
wire u_clk;
wire tx_done;
reg [7:0] dat = 8'h31;
//reg tx_cm;
//reg [15:0]c1;
wire [3:0]lcddata_in;
wire rx_rdy;
baud b1(
.sys_clk(clk),
.sys_rst_l(rst),
.baud_clk(u_clk) );
/*
Conclusion
Thus the FPGA and ARM are interfaced and their interrupt characteristics have been
studied.
Exp.No. 9 Interfacing Stepper Motor and Temperature Sensor
Date:
Aim
To interface stepper motor with ARM processor for running stepper motor either in clock-wise or
counter-clock-wise direction.
Equipment Required
LPC2148 ARM evaluation kit, stepper motor interface board, stepper motor
Theory
Stepper motors, effectively have multiple "toothed" electromagnets arranged around a central metal
gear. To make the motor shaft turn, first one electromagnet is given power, which makes the gear's teeth
magnetically attracted to the electromagnet's teeth. When the gear's teeth are thus aligned to the first
electromagnet, they are slightly offset from the next electromagnet.
So when the next electromagnet is turned on and the first will turn off, the gear rotates slightly to align
with the next one and from there the process is repeated. Each of those slight rotations is called a "step." In
that way, the motor can be turned to a précised angle. There are two basic arrangements for the
electromagnetic coils: bipolar and unipolar.
Procedure
ARM DETAILS
P1.16 STEP 1
P1.17 STEP 2
/*************************************************************/
MAIN ADC TEST
/*************************************************************/
/* This is a test program to temperature sensor in the ARM LPC2148 development board*/
/************************************************************************************/
/**************************************************************/
ADC_ DRIVER.C
/**************************************************************/
#include <LPC214x.H> /* LPC214x definitions */
void ADCInit (void)
{
PINSEL1 |= 0x04000000; /*For Channel AD0.2 is P0.29*/
IODIR0 |= ~(0x04000000);
AD0CR |= 0x00200204; /*0x04 selects AD0.2 to mux output, 0x20 makes ADC in operational*/
AD0GDR; /*A read on AD0GDR clears the DONE bit*/
}
void ADC_StartConversion(void)
{
AD0CR |= (1<<24);
}
void ADC_StopConversion(void)
{
AD0CR &= (~(1<<24));
}
unsigned int ADC_ReadChannel(void)
{
// unsigned int i;
unsigned long ADC_Val, t;
ADC_StartConversion();
while((AD0DR2&0x80000000)==0); /*wait until ADC conversion completes*/
if(AD0STAT & 0x00000400)
{
//printstr("OVR",0,1);
return(0);
}
t = AD0DR2;
ADC_Val = ((t>>6) & 0x000003FF);
//(AD0DR2 & 0x000003FF);
//((AD0CR>>6) & 0x000003FF);
ADC_StopConversion();
return(ADC_Val);
}
ARM DETAILS
P0.29 ADC0.2
PO.10 RS LCD PIN
P1.11 CE LCD PIN
Conclusion
Thus the program to interface stepper motor and temperature sensor has been written
and executed successfully
EXERCISE: To interface stepper motor with ARM processor for running stepper motor either
in clock-wise or counter-clock-wise direction with different delays.
Viva-voce
1) Define GPIO.
2) What is the function of ULN2803?
3) How LPC2148 control stepper motor?
4) Which I/O port lines used to rotate stepper motor?
5) How stepper motor reacts for each pulse it receives?
6) What is serial communication?
7) What is parallel communication?
8) What is stepper motor & why it is named so?
9) How can be step angle is calculated?
10) What are the advantages and disadvantages of parallel communication?
11) What does instruction-pipelining mean?
12) What is the power supply required for ARM processor?
13) Why LM35 is used to Measure Temperature?
14) What is operating the operating temperature range in LM35?
15) What is RPM rating for a DC motor?
Exp.No. 10 Interfacing zigbee Tx/Rx with ARM
Date:
Aim
To implement Zigbee protocol with ARM and to transmit and receive data
Equipment Required
Theory
The X Bee/X Bee-PRO ZNet 2.5 (formerly known as Series 2 and Series 2 PRO) RF Modules were
directed to operate within the ZigBee protocol. The modules provide reliable delivery of data between remote
devices. Zigbee is the communication protocol like wifi and Bluetooth. Xbee is the module using Zigbee
protocol
The addressing space allows of extreme node density—up to 18,450,000,000,000,000,000 devices (64
bit IEEE address)
Using local addressing, simple networks of more than 65,000 nodes can be configured, with reduced
address overhead
The radios use direct-sequence spread spectrum coding, which is managed by the digital stream into
the modulator.
Program
/****************************************************************************/
ARM TRANSMITTER
PROGRAM LCD.C
/****************************************************************************/
#include <LPC214x.h>
#include "lcd.h"
#define RS 0x00000400 /* P0.10 */
#define CE 0x00001800 /* P1.11 */
#define SET 1
#define OFF 0
unsigned int thousands,hundreds,tens,ones;
void wait (void)
{ /* wait function */
int d;
for (d = 0; d < 100000; d++); /* only to delay for LED flashes */
}
void lcdinit()
{
IODIR0 |= 0xFFFFFFFF;
IOCLR0 |= 0X00000FFF;
lcdcmd(0x28);
lcdcmd(0x28);
lcdcmd(0x0c);
lcdcmd(0x06);
lcdcmd(0x01);
lcdcmd(0x0f);
wait();
}
void gotoxy(char x, char y)
{
if(y == 0)
lcdcmd(0x80+x);
else
lcdcmd(0xc0+x);
}
void printstr(char *str, char x, char y)
{
char i;
gotoxy(x,y);
wait();//(500);
for(i=0;str[i]!='\0';i++)
lcddat(str[i]);
}
void lcdcmd(char cmd)
{
unsigned char LCDDAT;
LCDDAT = (cmd & 0xf0); //higher nibble
IOSET0 = LCDDAT;
IOCLR0 = RS;
IOSET0 = CE;
wait(); //(100); //enable lcd
IOCLR0 = CE;
IOCLR0 = 0X00000FFF;
LCDDAT = ((cmd<<0x04) & 0xf0); //lower nibble
IOSET0 = LCDDAT;
IOCLR0 = RS;
IOSET0 = CE;
wait(); //(100); //enable lcd IOCLR0 = CE;
IOCLR0 = 0X00000FFF;
}
void lcddat(char cmd)
{
unsigned char LCDDAT;
LCDDAT = (cmd & 0xf0); //higher nibble
IOSET0 = LCDDAT;
IOSET0 = RS;
IOSET0 = CE;
wait(); //(100); //enable lcd
IOCLR0 = CE;
IOCLR0 = 0X00000FFF;
LCDDAT = ((cmd<<0x04) & 0xf0); //lower nibble
IOSET0 = LCDDAT;
IOSET0 = RS;
IOSET0 = CE;
wait(); //(100); //enable lcd
IOCLR0 = CE;
IOCLR0 = 0X00000FFF;
}
void clrscr(char ch)
{
if(ch==0)
{
printstr(" ",0,0);
gotoxy(0,0);
}
else if(ch == 1)
{
printstr(" ",0,1);
gotoxy(0,1);
}
else
{
lcdcmd(0x01);
// delay(100);
}
}
void split_numbers(unsigned int number)
{
thousands = (number /1000);
number %= 1000;
hundreds = (number / 100);
number %= 100;
tens = (number / 10);
number %= 10;
ones = number ;
}
void Wait_Msg(void)
{
lcdcmd(0x01);
printstr(" Please Wait ", 0, 0);
}
void Welcome_Msg(void)
{
lcdcmd(0x01);
printstr(" Welcome to ", 0, 0);
printstr(" SM MICRRO ", 0, 1);
}
/***********************************************************************************/
LCD.H
/**************************************************************/
void clrscr(char ch);
void lcdinit(void);
void lcdcmd(char);
void lcddat(char);
void gotoxy(char,char); //x,y ; x-char position(0 - 16) y-line number 0 or 1
void printstr(char *,char,char); //string,column(x),line(y)
void wait (void);
void split_numbers(unsigned int
number); void Wait_Msg(void);
void Welcome_Msg(void);
/**************************************************************/
UART_1.C
/**************************************************************/
#include <LPC214X.H>
#include "lcd.c"
#define TEMT 0X40
void uart_1(void);
void delay(void);
void putcharr (unsigned char ch); /* Writes character to Serial Port*/
void tx_string(char str);
int main(void)
{
uart_1();
lcdinit();
delay();
delay();
delay();
delay();
printstr("SM MICRRO SYSTEM",0,0);
while(1)
{
tx_string('C');
gotoxy(7,1);
lcddat('C');
delay();
delay();
delay();
delay();
while(1);
}
}
void uart_1(void)
{
PINSEL0 = 0x00050000;
U1LCR = 0x83;
U1FDR = 0x00000010;
U1DLL = 98;
U1LCR = 0x03;
U1IER = 0x01;
}
void delay(void)
{
int d;
for (d = 0; d < 100000; d++); /* only to delay for LED flashes */
}
void tx_string(char str)
{
putcharr(str);
}
void putcharr (unsigned char ch) /* Writes character to Serial Port*/
{
while (!(U1LSR & TEMT)); /* U1LSR --> Status register */
U1THR = ch;
}
/**************************************************************/
ARM RECEIVER PROGRAM
/**************************************************************/
#include <LPC214X.H>
#include "lcd.c"
void uart_1(void);
void delay(void);
unsigned char getcharr (void); /* Reads character from Serial Port*/ int
main(void)
{
char rx_data;
uart_1();
lcdinit();
printstr("SM MICRRO SYSTEM",0,0);
while(1)
{
rx_data = getcharr(); /* Reads character from Serial Port*/
gotoxy(7,1);
lcddat(rx_data);
}
}
void uart_1(void) /* UART Installation */
{
PINSEL0 = 0x00050000;
U1LCR = 0x83;
U1FDR = 0x00000010;
U1DLL = 98;
U1LCR = 0x03;
U1IER = 0x01;
}
void delay(void)
{
int d;
for (d = 0; d < 100000; d++); /* only to delay for LED flashes */
}
unsigned char getcharr (void) /* Reads character from Serial Port*/
{
while (!(U1LSR & 0x01));
return (U1RBR);
}
ARM DETAILS
P0.8 TXD1
P0.9 RXD1
P0.10 RS LCD PIN
P1.11 CE LCD PIN
Receiver Program
ARM DETAILS
P0.8 TXD1
P0.9 RXD1
P0.10 RS LCD PIN
P1.11 CE LCD PIN
Conclusion
Thus the program to interface Zigbee with ARM processor has been written and
executed successfully.
Viva Voce
Aim
Equipment Required
LPC2148 Development board.
Theory
Real-time and embedded systems operate in constrained environments in which computer memory and
processing power are limited. They often need to provide their services within strict time deadlines to their
users and to the surrounding world. It is these memory, speed and timing constraints that dictate the use of
real-time operating systems in embedded software.
The "kernel" of a real-time operating system ("RTOS") provides an "abstraction layer" that hides from
application software the hardware details of the processor (or set of processors) upon which the application
software will run. In providing this "abstraction layer" the RTOS kernel supplies five main categories of basic
services to application software.
The most basic category of kernel services is Task Management. This set of services allows
application software developers to design their software as a number of separate "chunks" of software -- each
handling a distinct topic, a distinct goal, and perhaps its own real-time deadline. Each separate "chunk" of
software is called a "task." The main RTOS service in this category is the scheduling of tasks as the embedded
system is in operation.
The second category of kernel services is Intertask Communication and Synchronization. These
services make it possible for tasks to pass information from one to another, without danger of that information
ever being damaged. They also make it possible for tasks to coordinate, so that they can productively
cooperate with one another. Without the help of these RTOS services, tasks might well communicate
corrupted information or otherwise interfere with each other.
Since many embedded systems have stringent timing requirements, most RTOS kernels also provide
some basic Timer services, such as task delays and time-outs. Many (but not all) RTOS kernels provide
Dynamic Memory Allocation services. This category of services allows tasks to "borrow" chunks of RAM
memory for temporary use in application software. Often these chunks of memory are then passed from task
to task, as a means of quickly communicating large amounts of data between tasks. Some very small RTOS
kernels that are intended for tightly memory-limited environments, do not offer Dynamic memory allocation.
Many (but not all) RTOS kernels also provide a "Device I/O Supervisor" category of services. These
services, if available, provide a uniform framework for organizing and accessing the many hardware device
drivers that are typical of an embedded system.
Procedure
Open Keil µvision software and create a new project.
Add a new file to the source group and click on c file. Give the file a name and click on
OK.
Type in the program and save it.
Build the project and check for errors.
Right click on Target1 and click on Options for target1.
In the output tab check create hex file. Build the project.
The created hex file is loaded onto the processor kit using Flash Magic tool.
Program
/****************************************************************************/
MAILBOX.C
/****************************************************************************/
#include <string.h>
#include <stdio.h>
#include <RTL.h>
#include <LPC214x.H> /* LPC214x definitions */
#include "config.h"
#include "uart.h"
#include "lcd.h"
OS_TID tsk1; /* assigned identification for task 1 */
OS_TID tsk2; /* assigned identification for task 2 */
typedef struct
{ /* Message object structure */
char msgBuf[MBOX_MSG_BUF_SIZE];
} T_MEAS;
os_mbx_declare (MsgBox,MAILBOX_MEMORY_POOL_CNT); /* Declare an RTX mailbox */
_declare_box (mpool,sizeof(T_MEAS),MAILBOX_MEMORY_POOL_CNT);/* Dynamic memory pool
*/ __task void send_task (void);
__task void rec_task (void);
void main_menu()
{
send_string(USE_UART,"\n\r\n\n********************************************");
send_string(USE_UART,"\n\r SM Micrro System, Tambaram, Chennai ");
send_string(USE_UART,"\n\r MailBox Message Simulation "); send_string(USE_UART,"\n\r
MAIN MENU");
send_string(USE_UART,"\n\r********************************************");
send_string(USE_UART,"\n\n\r");
send_string(USE_UART,"\n\rThis program simulates MailBox IPC mechanism.");
send_string(USE_UART,"\n\rPlease Follow Below Commands");
send_string(USE_UART,"\n\r - Type any string and press enter to send");
send_string(USE_UART,"\n\r the string using mailbox. ");
send_string(USE_UART,"\n\r - Press SPACE Key to check available Mailbox Count");
send_string(USE_UART,"\n\r - Press ESC Key to reset the input string");
send_string(USE_UART,"\n\n\r");
}
/*----------------------------------------------------------------------------
* Task 1: RTX Kernel starts this task with os_sys_init (send_task)
*---------------------------------------------------------------------------*/
__task void send_task (void)
{
T_MEAS *mptr;
static unsigned char sInputBuf[MBOX_MSG_BUF_SIZE];
int cnt=0;
char sSndTskBuf[30];
char ch;
int MsgFree = 0;
tsk1 = os_tsk_self (); /* get own task identification number */
#ifndef DISABLE_RECV_TASK
tsk2 = os_tsk_create (rec_task, 0); /* start task 2 */
#endif /* DISABLE_RECV_TASK */
os_mbx_init (MsgBox, sizeof(MsgBox)); /* initialize the mailbox */
os_dly_wait (5); /* Startup delay for MCB21xx */
lcdinit();
clrscr(10);
printstr(" MailBox ",0,0);
printstr(" Simulation ",0,1);
#ifndef DISABLE_RECV_TASK
mptr = _alloc_box (mpool); /* Allocate a memory for the message */
memset (mptr->msgBuf,'\0',MBOX_MSG_BUF_SIZE); memcpy
( mptr->msgBuf, STD_MSG1, sizeof(STD_MSG1) );
os_mbx_send (MsgBox, mptr, 0xffff); /* Send the message to the mailbox */
os_dly_wait (100);
mptr = _alloc_box (mpool);
memset (mptr->msgBuf,'\0',MBOX_MSG_BUF_SIZE); memcpy
( mptr->msgBuf, STD_MSG2, sizeof(STD_MSG2) );
os_mbx_send (MsgBox, mptr, 0xffff); /* And send it. */
os_tsk_pass (); /* Cooperative multitasking */
os_dly_wait (100);
mptr = _alloc_box (mpool);
memset (mptr->msgBuf,'\0',MBOX_MSG_BUF_SIZE); memcpy
( mptr->msgBuf, STD_MSG3, sizeof(STD_MSG3) );
os_mbx_send (MsgBox, mptr, 0xffff); /* And send it. */
os_dly_wait (100);
#endif /* DISABLE_RECV_TASK */
memset (sInputBuf,'\0',MBOX_MSG_BUF_SIZE);
cnt = 0;
main_menu();
while(1)
{
ch = receive(USE_UART);
if(ch == CARRIAGE_RET && cnt > 0)
{
send_string(USE_UART,"\n\n\n\r************SENDING MAILBOX
USER MESSAGE***************");
MsgFree = os_mbx_check
(MsgBox); if (MsgFree != 0)
{
mptr = _alloc_box (mpool);
memset (mptr->msgBuf,'\0',MBOX_MSG_BUF_SIZE);
memcpy ( mptr->msgBuf, sInputBuf, strlen((const char *)sInputBuf) );
sprintf (sSndTskBuf, "\n\ros_mbx_send by Task ID: %d ", tsk1);
send_string(USE_UART,sSndTskBuf);
send_string(USE_UART,"\n\n\r");
os_mbx_send (MsgBox, mptr, 0xffff); /* And send it. */ os_dly_wait
(100);
memset (sInputBuf,'\0',MBOX_MSG_BUF_SIZE);
cnt = 0;
}
else
{
send_string(USE_UART,"\n\rMailbox is FULL");
}
#ifdef DISABLE_RECV_TASK
main_menu();
#endif /* DISABLE_RECV_TASK */
}
else if ( KEY_SPACE == ch)
{
MsgFree = os_mbx_check
(MsgBox); if (MsgFree == 0)
{
send_string(USE_UART,"\n\rMailbox is FULL....");
}
else
{
sprintf (sSndTskBuf, "\n\rMailBox Free Count : %d ", MsgFree);
send_string(USE_UART,sSndTskBuf);
send_string(USE_UART,"\n\n\r");
}
os_dly_wait (100);
main_menu();
}
else if ( KEY_ESC == ch)
{
cnt = 0;
memset (sInputBuf,'\0',MBOX_MSG_BUF_SIZE);
send_string(USE_UART,"\n\rClearing Buffer Please
Wait...."); os_dly_wait (100);
main_menu();
}
else if('\0' != ch)
{
sInputBuf[cnt++] = ch;
cnt %= MBOX_MSG_BUF_SIZE;
if(ch == CARRIAGE_RET && cnt ==1) //empty string
{
cnt = 0;
}
else
{
putcharr (USE_UART,ch);
}
}
}
// os_tsk_delete_self (); /* We are done here, delete this task */
}
}
}
#endif /* DISABLE_RECV_TASK */
/*----------------------------------------------------------------------------
* Main: Initialize and start RTX Kernel
*---------------------------------------------------------------------------*/
int main (void)
{
initserial(USE_UART); _init_box /* uart0 initialization */
(mpool, sizeof(mpool), /* initialize the 'mpool' memory for */
sizeof(T_MEAS)); /* the membox dynamic allocation */
os_sys_init (send_task); /* initialize and start task 1 */
}
/*----------------------------------------------------------------------------
* end of file *---------------------------------------------------------------------------
*/
/*************************************************************/
RTX _CONFIG.C
/*************************************************************/
/*----------------------------------------------------------------------------
* RL-ARM - RTX *----------------------------------------------------
------------------------
* Name: RTX_CONFIG.C
* Purpose: Configuration of RTX Kernel for NXP LPC21xx
* Rev.: V4.20
*----------------------------------------------------------------------------
* This code is part of the RealView Run-Time Library.
* Copyright (c) 2004-2011 KEIL - An ARM Company. All rights reserved.
*---------------------------------------------------------------------------*/
#include <RTL.h>
#include <LPC21xx.H> /* LPC21xx definitions */
/*----------------------------------------------------------------------------
* RTX User configuration part BEGIN
*---------------------------------------------------------------------------*/
//-------- <<< Use Configuration Wizard in Context Menu >>> -----------------
//
// <h>Task Configuration
// =====================
//
// <o>Number of concurrent running tasks <0-250>
// <i> Define max. number of tasks that will run at the same time.
// <i> Default: 6
#ifndef OS_TASKCNT
#define OS_TASKCNT 6
#endif
// <o>Number of tasks with user-provided stack <0-250>
// <i> Define the number of tasks that will use a bigger stack.
// <i> The memory space for the stack is provided by the user.
// <i> Default: 0
#ifndef OS_PRIVCNT
#define OS_PRIVCNT 0
#endif
// <o>Task stack size [bytes] <20-4096:8><#/4>
// <i> Set the stack size for tasks which is assigned by the system.
// <i> Default: 200
#ifndef OS_STKSIZE
#define OS_STKSIZE
50 #endif
// <q>Check for the stack overflow
// ===============================
// <i> Include the stack checking code for a stack overflow.
// <i> Note that additional code reduces the RTX
performance. #ifndef OS_STKCHECK
#define OS_STKCHECK 1
#endif
// </h>
// <h>Tick Timer Configuration
// =============================
// <o>Hardware timer <0=> Timer 0 <1=> Timer 1
// <i> Define the on-chip timer used as a time-base for RTX.
// <i> Default: Timer 0
#ifndef OS_TIMER
#define OS_TIMER 1
#endif
// <o>Timer clock value [Hz] <1-1000000000>
// <i> Set the timer clock value for selected timer.
// <i> Default: 15000000 (15MHz at 60MHz CCLK and VPBDIV = 4)
#ifndef OS_CLOCK
#define OS_CLOCK 15000000
#endif
// <o>Timer tick value [us] <1-1000000>
// <i> Set the timer tick value for selected timer.
// <i> Default: 10000 (10ms)
#ifndef OS_TICK
#define OS_TICK
10000 #endif
// </h>
// <h>System Configuration
// =======================
// <e>Round-Robin Task switching
// =============================
// <i> Enable Round-Robin Task
switching. #ifndef OS_ROBIN
#define OS_ROBIN 1
#endif
// <o>Round-Robin Timeout [ticks] <1-1000>
// <i> Define how long a task will execute before a task switch.
// <i> Default: 5
#ifndef OS_ROBINTOUT
#define OS_ROBINTOUT 5
#endif
// </e>
// <o>Number of user timers <0-250>
// <i> Define max. number of user timers that will run at the same time.
// <i> Default: 0 (User timers disabled)
#ifndef OS_TIMERCNT
#define OS_TIMERCNT 0
#endif
// <o>ISR FIFO Queue size<4=> 4 entries <8=> 8 entries
// <12=> 12 entries <16=> 16 entries
// <24=> 24 entries <32=> 32 entries
// <48=> 48 entries <64=> 64 entries
// <96=> 96 entries
// <i> ISR functions store requests to this buffer,
// <i> when they are called from the IRQ handler.
// <i> Default: 16 entries
#ifndef OS_FIFOSZ
#define OS_FIFOSZ 16
#endif
// </h>
//------------- <<< end of configuration section >>> -----------------------
// Standard library system mutexes
// ===============================
// Define max. number system mutexes that are used to protect
// the arm standard runtime library. For microlib they are not used.
#ifndef OS_MUTEXCNT
#define OS_MUTEXCNT 8
#endif
/*----------------------------------------------------------------------------
* RTX User configuration part END
*--------------------------------------------------------------------------- */
#if (OS_TIMER == 0) /* Timer 0 */
#define OS_TID_ 4 /* Timer ID */
#define TIMx(reg) T0##reg
#elif (OS_TIMER == 1) /* Timer 1 */
#define OS_TID_ 5 /* Timer ID */
#define TIMx(reg) T1##reg
#else
#error OS_TIMER invalid
#endif
#define OS_TIM_ (1 << OS_TID_) /* Interrupt Mask */
#define OS_TRV ((U32)(((double)OS_CLOCK*(double)OS_TICK)/1E6)-1)
#define OS_TVAL TIMx(TC) /* Timer Value */
#define OS_TOVF (TIMx(IR) & 1) /* Overflow Flag */
#define OS_TFIRQ() VICSoftInt = OS_TIM_; /* Force Interrupt */
#define OS_TIACK() TIMx(IR) = 1; /* Interrupt Ack */ \
VICSoftIntClr = OS_TIM_; \
VICVectAddr = 0;
#define OS_TINIT() TIMx(MR0) = OS_TRV; /* Initialization */ \
TIMx(MCR) = 3; \
TIMx(TCR) = 1; \
VICDefVectAddr = (U32)os_def_interrupt; \
VICVectAddr15 = (U32)os_clock_interrupt; \
VICVectCntl15 = 0x20 | OS_TID_;
#define OS_IACK() VICVectAddr = 0; /* Interrupt Ack */
#define OS_LOCK() VICIntEnClr = OS_TIM_; /* Task Lock */
#define OS_UNLOCK() VICIntEnable = OS_TIM_; /* Task Unlock */
/* WARNING: Using IDLE mode might cause you troubles while debugging.
*/ #define _idle_() PCON = 1; /*---------------------------------------------------------
-------------------
* Global Functions
*---------------------------------------------------------------------------*/
/*--------------------------- os_idle_demon ---------------------------------*/
__task void os_idle_demon (void) {
/* The idle demon is a system task, running when no other task is ready */
/* to run. The 'os_xxx' function calls are not allowed from this task. */
for (;;) {
/* HERE: include optional user code to be executed when no task runs.*/
}
}
/*--------------------------- os_tmr_call -----------------------------------*/
void os_tmr_call (U16 info) {
/* This function is called when the user timer has expired. Parameter
*/ /* 'info' holds the value, defined when the timer was created. */
/* HERE: include optional user code to be executed on timeout. */
}
/*--------------------------- os_error --------------------------------------*/
void os_error (U32 err_code) {
/* This function is called when a runtime error is detected. Parameter
*/ /* 'err_code' holds the runtime error code (defined in RTL.H). */
/* HERE: include optional code to be executed on runtime error. */
for (;;);
}
/*----------------------------------------------------------------------------
* RTX Configuration Functions
*---------------------------------------------------------------------------*/
static void os_def_interrupt (void) __irq {
/* Default Interrupt Function: may be called when timer ISR is disabled
*/ OS_IACK();
}
#include <RTX_lib.c> /*------------------------------------------------
----------------------------
* end of file *-------------------------------------------------------------
--------------*
/***************************************************************************/
LCD.C
/**************************************************************/
#include <LPC214x.H> /* LPC214x definitions */
#define RS 0x00000400 /* P0.10 */
#define CE 0x00001000 /* P1.11 */
#define SET 1
#define OFF 0
void lcdcmd(char cmd);
void lcddat(char cmd);
void printstr(unsigned char *str, char x, char y);
void wait (void)
/* wait function */
{
int d;
for (d = 0; d < 100000; d++); /* only to delay for LED flashes */
}
void lcdinit(void)
{
IODIR0 |= 0x000014f0;
lcdcmd(0x28);
lcdcmd(0x28);
lcdcmd(0x0c);
lcdcmd(0x06);
lcdcmd(0x01);
lcdcmd(0x0f);
wait();//(1600);
}
void gotoxy(char x, char y)
{
if(y == 0)
lcdcmd(0x80+x);
else
lcdcmd(0xc0+x);
}
void printstr(unsigned char *str, char x, char y)
{
char i;
gotoxy(x,y);
wait();//(500);
for(i=0;str[i]!='\0';i++)
lcddat(str[i]);
}
void lcdcmd(char cmd)
{
unsigned char LCDDAT;
LCDDAT = (cmd & 0xf0); //higher
nibble IOSET0 |= LCDDAT;
IOCLR0 |= RS;
IOSET0 |= CE;
wait();//(100); //enable lcd
IOCLR0 |= CE;
IOCLR0 |= 0X00000FFF;
LCDDAT = ((cmd<<0x04) & 0xf0); //lower
nibble IOSET0 |= LCDDAT;
IOCLR0 |= RS;
IOSET0 |= CE;
wait();//(100); //enable
lcd IOCLR0 |= CE;
IOCLR0 |= 0X00000FFF;
}
void lcddat(char cmd)
{
unsigned char LCDDAT;
LCDDAT = (cmd & 0xf0); //higher
nibble IOSET0 |= LCDDAT;
IOSET0 |= RS;
IOSET0 |= CE;
wait();//(100); //enable
lcd IOCLR0 |= CE;
IOCLR0 |= 0X00000FFF;
LCDDAT = ((cmd<<0x04) & 0xf0); //lower
nibble IOSET0 |= LCDDAT;
IOSET0 |= RS;
IOSET0 |= CE;
wait();//(100); //enable
lcd IOCLR0 |= CE;
IOCLR0 |= 0X00000FFF;
}
void clrscr(char ch)
{
if(ch==0)
{
printstr(" ",0,0);
gotoxy(0,0);
}
else if(ch == 1)
{
printstr(" ",0,1);
gotoxy(0,1);
}
else
{
lcdcmd(0x01);
// delay(100);
}
}
/**********************************************************************************/
UART.C
/*************************************************************/
/* This file contains driver functions to send and receive data via uart0 in the
*/ /* ARM LPC2148 development board itself */
/************************************************************************************/
#include <LPC214x.H>
#include "config.h"
#define TEMT (1<<6)
void initserial(unsigned char uart)
{
if(0 == uart)
{
PINSEL0 = 0x00000005; /* Make pins 19 and 21 to function as TXD0 and RXD0 for
UART0*/
U0LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
U0FDR = 0x00000010; /* DIVADDVAL = 0; MULVAL = 1 */
U0DLL = 98; /* 9600 Baud Rate @ 15MHz VPB Clock; = 97.65=98 */
U0LCR = 0x03; /* DLAB = 0 */
U0IER = 0x01; /* Enable reciever data available interrupt*/
}
else
{
PINSEL0 = 0x00050000; /* Make pins 19 and 21 to function as TXD0 and RXD0
for UART0*/
U1LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
U1FDR = 0x00000010; /* DIVADDVAL = 0; MULVAL = 1 */
U1DLL = 98; /* 9600 Baud Rate @ 15MHz VPB Clock; = 97.65=98 */
U1LCR = 0x03; /* DLAB = 0 */
U1IER = 0x01; /* Enable reciever data available interrupt*/
}
}
void putcharr (unsigned char uart, unsigned char ch) /* Writes character to Serial Port*/
{
if(0 == uart)
{
while (!(U0LSR & TEMT));
U0THR = ch;
}
else
{
while (!(U1LSR & TEMT));
U1THR = ch;
}
}
unsigned char getcharr (unsigned char uart) /* Reads character from Serial Port*/
{
if(0 == uart)
{
while (!(U0LSR & 0x01));
return (U0RBR);
}
else
{
while (!(U1LSR & 0x01));
return (U1RBR);
}
}
char receive(unsigned char uart) /*function for receiving data from sensor (reads byte
by byte & returns value if exist, else #) */
{
if(0 == uart)
{
if (U0LSR & 0x01) /* If U0LSR 1st bit contains valid data, then return value of
U0RBR*/
{
return (U0RBR);
}
return '\0'; /* If other than 0 to 9 data is recieved return #*/
}
else
{
if (U1LSR & 0x01) /* If U0LSR 1st bit contains valid data,
then return value of U0RBR*/
{
return (U1RBR);
}
return '\0'; /* If other than 0 to 9 data is recieved return #*/
}
}
void send_string(unsigned char uart,char* cpr) /* Writes string to serial port */
{
while(*cpr != '\0')
{
putcharr (uart,*cpr);
cpr++;
}
}
unsigned char* receive_string(unsigned char uart) /* Reads string to serial port */
{
static unsigned char c[30];
unsigned char i=0;
c[i] = getcharr(uart);
while(c[i] != CARRIAGE_RET)
{
i++;
c[i] = getcharr(uart);
}
c[i] = '\0';
return(c);
}
/**************************************************************/
CONFIG.H
/**************************************************************/
#define MAILBOX_MEMORY_POOL_CNT 16
#define MBOX_MSG_BUF_SIZE 100
#define USE_UART 0
/****************************************************************/
/* Enable below macro to disable the the recv task to check mailbox full */
//#define DISABLE_RECV_TASK
/****************************************************************/
#define STD_MSG1 "MailBox Test Message 1"
#define STD_MSG2 "MailBox Test Message 2"
#define STD_MSG3 "MailBox Test Message 3"
#define LINE_FEED 0x0A
#define CARRIAGE_RET 0x0D
#define KEY_SPACE 0x20
#define KEY_ESC 0x1B
Mail Program Program Port Details
UART 0
ARM DETAILS
P0.0 TXDO
P0.1 RXDO
UART 1
ARM DETAILS
P0.8 TXD1
P0.9 RXD1
ARM DETAILS
PO.10 RS LCD PIN
P1.11 CE LCD PIN
Conclusion
Thus the program to send and receive message in mail using RTOS has been
written and executed successfully
CONTENT BEYOND
SYLLABUS
Ex.No. 12 Alarm Clock
Date:
Aim:
To write a program for an alarm clock using ARM processor.
Equipment Required:
ARM Development Kit.
Theory:
The Real Time Clock (RTC) is a set of counters for measuring time. On the
LPC2148 the RTC can be clocked by separate 32.768 KHz oscillator, or by a programmable
prescale divider based on the VPB clock. Alarm is set for a particular time and the buzzer is
enabled. When the clock tick reaches the programmed time, the buzzer goes ON and rings for a
minute. It can be manually disabled by turning OFF the switch to buzzer.
Procedure:
Program:
#include <LPC214X.H>
#include "lcd.c"
int main()
{
unsigned int hrs,min,sec;
wait();
wait();
wait();
wait();
lcdinit();
clrscr(2);
printstr("ALARM CLOCK",0,0);
printstr(" ARM DEV KIT ",0,1);
VPBDIV = 0x00000002;
PREINT = 0x00000392;
PREFRAC = 0x00004380;
CIIR = 0x00000001;
CCR = 0x00000001;
YEAR = 2016; // Year
MONTH = 10; // Month
DOM = 7; // Day of month
DOY = 0; // Day of year
DOW = 0; // Day of week
HOUR = 9; // Hours
MIN = 29; // Minutes
SEC = 30;
printstr(" ",0,1);
IODIR1 = 0x00040000;
IOSET1 = 0x00040000;
while(1)
{
gotoxy(0,1);
hrs = HOUR;
min = MIN;
sec = SEC;
split_numbers(hrs);
lcddat(tens+0x30);
lcddat(ones+0x30);
lcddat(':');
split_numbers(min);
lcddat(tens+0x30);
lcddat(ones+0x30);
lcddat(':');
split_numbers(sec);
lcddat(tens+0x30);
lcddat(ones+0x30);
//lcddat(':');
if(hrs==9)
{
if(min==30)
{
IOCLR1 |= 0x00040000; // Turn ON Buzzer
}
if(min!=30)
{
IOSET1 = 0x00040000; // Turn OFF Buzzer
}}
}
}
Result:
Thus the program for an alarm clock using ARM processor is written and executed.
Ex.No. 13 Door Lock Program
Date:
Aim:
To write a program for unlocking a door using four digit pin combination using ARM
processor.
Equipment Required:
ARM Development Kit.
Theory:
A four digit combination is used as a password to unlock the door. The 4x4 matrix
Keypad has numbers from 0 to 9 and an Enter button. The 4 digit combination is entered and the
enter switch is pressed. If the typed in password matches with the original password, door will be
unlocked. If it doesn’t match, the LCD displays “Wrong!!”. After resetting the kit, the password
can be tried again.
Procedure:
Program:
#include <LPC214x.h>
#include "lcd.c"
#define ROW1 0x00010000;
#define ROW2 0x00020000;
#define ROW3 0x00040000;
#define ROW4 0x00080000;
#define ROW_MASK 0x000F0000;
unsigned int thousands,hundreds,tens,ones;
void init_Matrix_7seg(void)
{
IODIR1 |= 0xff0f0000;
}
unsigned long scan_row(unsigned int row_num)
{
unsigned long val;
IOSET1 = ROW_MASK; //clear the previous scan row output ie make all row ops
high
switch(row_num)
{
case 1: IOCLR1 = ROW1;break; // make P1.16 low
case 2: IOCLR1 = ROW2;break; // make P1.17 low
case 3: IOCLR1 = ROW3;break; // make P1.18 low
case 4: IOCLR1 = ROW4;break; // make P1.19 low
}
val = IOPIN1; // read the matrix inputs
val = ((val >> 20) & 0x0000000F)^0x0000000F; // shift the colum value so that it
comes to LSB
return(val);
}
unsigned int catch_key(void)
{
unsigned long v;
v = scan_row(1); //scan row 1
switch(v)
{
case 1: return(13);
case 2: return(14);
case 4: return(15);
case 8: return(16);
}
v = scan_row(2); //scan row 2
switch(v)
{
case 1: return(9);
case 2: return(10);
case 4: return(11);
case 8: return(12);
}
v = scan_row(3); //scan row 3
switch(v)
{
case 1: return(5);
case 2: return(6);
case 4: return(7);
case 8: return(8);
}
v = scan_row(4); //scan row 4
switch(v)
{
case 1: return(1);
case 2: return(2);
case 4: return(3);
case 8: return(4);
default: return(0);
}
}
void Alpha_Dispay3(unsigned int value)
{
switch(value)
{
case 1: printstr("1"); break;
case 2: printstr("2"); break;
case 3: printstr("3"); break;
case 4: printstr("4"); break;
case 5: printstr("5"); break;
case 6: printstr("6"); break;
case 7: printstr("7"); break;
case 8: printstr("8"); break;
case 9: printstr("9"); break;
case 10: printstr("0"); break;
case 11: printstr("-"); break;
case 12: printstr("-"); break;
case 13: printstr("-"); break;
case 14: printstr("-"); break;
case 15: printstr("-"); break;
case 16: printstr("Enter"); break;
}
}
int main()
{
unsigned int key, Disp_key,n=0,a,b,c,d;
init_Matrix_7seg();
wait();
wait();
wait();
wait();
lcdinit();
clrscr(2);
gotoxy(0,0);
printstr("Door Lock");
key = catch_key();
for(n=0;n<=7;n++)
{
key = catch_key();
while(!key)
{
key = catch_key();
}
if(key != 0)
{
if(n==0)
{
a=key; gotoxy(0,1); Alpha_Dispay3(key);
}
else if(n==1)
{
b=key; gotoxy(1,1); Alpha_Dispay3(key);
}
else if (n==2)
{
c=key; gotoxy(2,1); Alpha_Dispay3(key);
}
else if (n==3)
{
d=key; gotoxy(3,1); Alpha_Dispay3(key);
}
wait();wait();wait();wait();
wait();wait();wait();wait();
gotoxy(0,0);
if(key == 16)
{ if(a==9)
{ if(b==8)
{ if(c==7)
{ if(d==6)
{ printstr("Door Unlocked"); }
else printstr("Wrong!!");
} else printstr("Wrong!!");
} else printstr("Wrong!!");
} else printstr("Wrong!!");
}
}
}
}
Result:
Thus the program for unlocking a door using four digit pin combination using ARM
processor is written and executed.
EXERCISE PROGRAMS
MINI PROJECTS
DATASHEETS
LPC2148 Pin Diagram
Out of these 32 pins, 28 pins can be configured as either general purpose input or output.
1 of these 32 pins (P0.31) can be configured as general-purpose output only.
3 of these 32 pins (P0.24, P0.26 and P0.27) are reserved. Hence, they are not available for use. Also, these
pins are not mentioned in pin diagram.
PORT1 is also a 32-bit port. Only 16 of these 32 pins (P1.16 – P1.31) are available for use as general-purpose
input or output.
Almost every pin of these two ports has some alternate function available. For example, P0.0 can be configured as
the TXD pin for UART0 or as PWM1 pin as well. The functionality of each pin can be selected using the Pin
Function Select Registers.
1. IOxPIN (GPIO Port Pin value register): This is a 32-bit wide register. This register is used to read/write the
value on Port (PORT0/PORT1). But care should be taken while writing. Masking should be used to ensure write to
the desired pin.
Examples :
a) Writing 1 to P0.4 using IO0PIN IO0PIN = IO0PIN | (1<<4)
2. IOxSET (GPIO Port Output Set register) : This is a 32-bit wide register. This register is used to make pins of
Port (PORT0/PORT1) HIGH. Writing one to specific bit makes that pin HIGH. Writing zero has no effect.
3. IOxDIR (GPIO Port Direction control register) : This is a 32-bit wide register. This register individually
controls the direction of each port pin. Setting a bit to ‘1’ configures the corresponding pin as an output pin. Setting
a bit to ‘0’ configures the corresponding pin as an input pin.
4. IOxCLR (GPIO Port Output Clear register) : This is a 32-bit wide register. This register is used to make
pins of Port LOW. Writing one to specific bit makes that pin LOW. Writing zeroes has no effect.
Examples :
a) Configure pin P0.0 to P0.3 as input pins and P0.4 to P0.7 as output pins.
IO0DIR = 0x000000F0;
IO0SET = (1<<4);
IO0CLR = (1<<4);
ADC0 Registers
1. AD0CR (ADC0 Control Register)
AD0CR
(ADC0 Control Register)
Bits 7:0 – SEL
These bits select ADC0 channel as analog input. In software-controlled mode, only one of these bits should
be 1.e.g. bit 7 (10000000) selects AD0.7 channel as analog input.
Bits 15:8 – CLKDIV
The APB(ARM Peripheral Bus)clock is divided by this value plus one, to produce the clock for ADC. This
clock should be less than or equal to 4.5MHz.
Bit 16 – BURST
0 = Conversions are software controlled and require 11 clocks
1 = In Burst mode ADC does repeated conversions at the rate selected by the CLKS field for the analog
inputs selected by SEL field. It can be terminated by clearing this bit, but the conversion that is in progress
will be completed.
When Burst = 1, the START bits must be 000, otherwise the conversions will not start.
Bits 19:17 – CLKS
Selects the number of clocks used for each conversion in burst mode and the number of bits of accuracy of
Result bits of AD0DR.
e.g. 000 uses 11 clocks for each conversion and provide 10 bits of result in corresponding ADDR register.
000 = 11 clocks / 10 bits
001 = 10 clocks / 9 bits
010 = 9 clocks / 8 bits
011 = 8 clocks / 7 bits
100 = 7 clocks / 6 bits
101 = 6 clocks / 5 bits
110 = 5 clocks / 4 bits
111 = 4 clocks / 3 bits
Bit 20 – RESERVED
Bit 21 – PDN
0 = ADC is in Power Down mode
1 = ADC is operational
Bit 23:22 – RESERVED
Bit 26:24 – START
When BURST bit is 0, these bits control whether and when A/D conversion is started
000 = No start (Should be used when clearing PDN to 0)
001 = Start conversion now
010 = Start conversion when edge selected by bit 27 of this register occurs on CAP0.2/MAT0.2 pin
011= Start conversion when edge selected by bit 27 of this register occurs on CAP0.0/MAT0.0 pin
100 = Start conversion when edge selected by bit 27 of this register occurs on MAT0.1 pin
101 = Start conversion when edge selected by bit 27 of this register occurs on MAT0.3 pin
110 = Start conversion when edge selected by bit 27 of this register occurs on MAT1.0 pin
111 = Start conversion when edge selected by bit 27 of this register occurs on MAT1.1 pin
Bit 27 – EDGE
This bit is significant only when the Start field contains 010-111. In these cases,
0 = Start conversion on a rising edge on the selected CAP/MAT signal
1 = Start conversion on a falling edge on the selected CAP/MAT signal
Bit 31:28 – RESERVED
AD0 Data
Registers Structure
Bit 5:0 – RESERVED
Bits 15:6 – RESULT
When DONE bit is set to 1, this field contains 10-bit ADC result that has a value in the range of 0 (less
than or equal to VSSA) to 1023 (greater than or equal to VREF).
Bit 29:16 – RESERVED
Bit 30 – Overrun
This bit is set to 1 in burst mode if the result of one or more conversions is lost and overwritten before the
conversion that produced the result in the RESULT bits.
This bit is cleared by reading this register.
Bit 31 – DONE
This bit is set to 1 when an A/D conversion completes. It is cleared when this register is read.