Ec8711 Embedded Lab Manual
Ec8711 Embedded Lab Manual
Ec8711 Embedded Lab Manual
LABORATORY MANUAL
Regulation – 2017
• To contribute to the development of human resources in the form of professional engineers and
managers of international excellence and competence with high motivation and dynamism, who besides
serving as ideal citizen of our country will contribute substantially to the economic development and
advancement in their chosen areas of specialization.
• To build the institution with international repute in education in several areas at several levels with
specific emphasis to promote higher education and research through strong institute-industry
interaction and consultancy.
To excel in the field of electronics and communication engineering and to develop highly competent
technocrats with global intellectual qualities.
1. Engineering knowledge: Apply the knowledge of mathematics, science, engineering fundamentals, and an
engineering specialization to the solution of complex engineering problems.
2. Problem analysis: Identify, formulate, review research literature, and analyze complex engineering
problems reaching substantiated conclusions using first principles of mathematics, natural sciences, and
engineering sciences.
3. Design/development of solutions: Design solutions for complex engineering problems and design system
components or processes that meet the specified needs with appropriate consideration for the public health and
safety, and the cultural, societal, and environmental considerations.
4. Conduct investigations of complex problems: Use research-based knowledge and research methods
including design of experiments, analysis and interpretation of data, and synthesis of the information to provide
valid conclusions.
5. Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern engineering
and IT tools including prediction and modeling to complex engineering activities with an understanding of the
limitations.
6. The engineer and society: Apply reasoning informed by the contextual knowledge to assess societal, health,
safety, legal and cultural issues and the consequent responsibilities relevant to the professional engineering
practice.
7. Environment and sustainability: Understand the impact of the professional engineering solutions in
societal and environmental contexts, and demonstrate the knowledge of, and need for sustainable development.
8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms of the
engineering practice.
9. Individual and team work: Function effectively as an individual, and as a member or leader in diverse
teams, and in multidisciplinary settings.
10. Communication: Communicate effectively on complex engineering activities with the engineering
community and with society at large, such as, being able to comprehend and write effective reports and design
documentation, make effective presentations, and give and receive clear instructions.
11. Project management and finance: Demonstrate knowledge and understanding of the engineering and
management principles and apply these to one’s own work, as a member and leader in a team, to manage
projects and in multidisciplinary environments.
12. Life-long learning: Recognize the need for, and have the preparation and ability to engage in independent
and life-long learning in the broadest context of technological change.
PSO1: Ability to apply the acquired knowledge of basic skills, mathematical foundations, principles of
electronics, modeling and design of electronics based systems in solving engineering Problems.
PSO2: Ability to understand and analyze the interdisciplinary problems for developing innovative sustained
solutions with environmental concerns.
PSO3: Ability to update knowledge continuously in the tools like MATLAB, NS2, XILINIX and
technologies like VLSI, Embedded, Wireless Communications to meet the industry requirements.
PSO4: Ability to manage effectively as part of a team with professional behavior and ethics.
SYLLABUS
TOTAL: 60 PERIODS
LIST OF EXPERIMENTS
7 Mailbox. 43
9 Flashing of LEDS. 69
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 I2C s and on-chip SRAM of 8 kb up to 40 kb, make these devices very well suited
for communication gateways and protocol converters, soft modems, voice recognition and low
end imaging, providing both large buffer size and high processing power. Various 32-bit timers,
single or dual 10-bit ADC(s), 10-bit DAC, PWM channels and 45 fast GPIO lines with up to nine
edge or level sensitive external interrupt pins make these microcontrollers particularly suitable for
industrial control and medical systems.
2
LPC2148 specification
Features:
16/32-bit ARM7TDMI-S microcontroller in a tiny LQFP64package.
flash sector or full chip erase in 400ms and programming of 256 bytes in 1 ms.
Embedded ICE RT and Embedded Trace interfaces offer real-time debugging with the on-
chip Real Monitor software and high speed tracing of instruction execution.
USB 2.0 Full Speed compliant Device Controller with 2 kb of endpoint RAM. In addition, the
o total of 6/14 analog inputs, with conversion times as low as 2.44μsper channel.
Two 32-bit timers/external event counters (with four capture and four compare channels
Low power real-time clock with independent power and dedicated 32kHz Clock input.
Multiple serial interfaces including two UARTs (16C550), two Fast I2C -bus (400 kbit/s),
SPI and SSP with buffering and variable data length capabilities.
60 MHz maximum CPU clock available from programmable on-chip PLL with settling time of
100μs.
On-chip integrated oscillator operates with an external crystal in range from 1MHz to 30 MHz and
with an external oscillator up to 50MHz.
Individual enable/disable of peripheral functions as well as peripheral clock scaling for additional
power optimization.
Processor wake-up from Power-down mode via external interrupt, USB, Brown-Out Detect
Single power supply chip with Power-On Reset (POR) and BOD circuits:
I/O pads.
4
Pin Configuration:
For further studies about LPC2148 specification refer NXP’s website to download LPC2148
user manual.
5
Result
The evolution, core features, general characteristics and the applications of ARM processors has
been studied and is evaluated.
7
2. Kei l µVision5software.
3. Flash Magic.
4. USB cable.
5. CRO.
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.
8
Procedure
/************************************************************************************/
/* This is a test program to ADC in theARMLPC2148 developmentboard*/
/************************************************************************************/
/***************************************************************************/
LCD.C
/************************************************************************************/
#include <LPC214x.h>
#define SET1
#define OFF0
unsigned int thousands,hundreds,tens,ones;
10
voidwait(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);lcd
cmd(0x28);
lcdcmd(0x0c);
lcdcmd(0x06);
lcdcmd(0x01);
lcdcmd(0x0f);
wait();
}
}
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(charcmd)
{
unsigned charLCDDAT;
LCDDAT = (cmd&0xf0); //higher nibble
IOSET0 =LCDDAT;
IOCLR0 = RS;
IOSET0 = CE;
wait();//(100); //enablelcd
IOCLR0 = CE;
IOCLR0 = 0X00000FFF;
{
unsigned charLCDDAT;
LCDDAT = (cmd&0xf0); //higher nibble
IOSET0 =LCDDAT;
IOSET0 = RS;
IOSET0 = CE;
wait();//(100); //enablelcd
IOCLR0 = CE;
IOCLR0 = 0X00000FFF;
void Wait_Msg(void)
{
lcdcmd(0x01);
printstr(" Please Wait ", 0,0);
}
void Welcome_Msg(void)
{
lcdcmd(0x01);
printstr(" Welcometo ", 0,0);
printstr(" SMMICRRO ", 0,1);
}
12
/*****************************************************************/
ADC_ DRIVER.C
/**************************************************************/
void ADC_StartConversion(void)
{
AD0CR |= (1<<24);
}
void ADC_StopConversion(void)
{
AD0CR &= (~ (1<<24));
}
DAC PROGRAM
/**************************************************************/ DAC.C
/**************************************************************/
This is a test program to DAC in the ARM LPC2148 Development board
/**************************************************************/
#include<LPC214X.H>
int main()
{
wait_long();wai
t_long();
IODIR0 = 0X00000FFF;
IODIR1 = 0XFFFF0000;
IOSET0 = 0XFFFFFFFF;
IOCLR1 = 0XFFFF0000;
PINSEL1 |= 0x00080000; //Enablepin0.25 asDAC
DACR=0X00017FC0; // 000 = 0V (min),7FC = 1.6V,7FF =3.3V(max)
While (1);
}
Result :
The C-Language program for reading an on-chip ADC, convert into decimal and to display
it in PC was written & output is verified with the ADC input is connected to on board
potentiometer
The DAC, convert digital data into analog signal& output is verified with the DAC input and
the square wave has been generated to display it in CRO.
15
Aim
To write a C program for Switch & L ED to activate LED’s and generate a PWM and to vary
the duty cycle .
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
1. Follow the steps to create a New project
2. Type the below code and save it with the name (anyname.c)
3. Follow the steps to create a New Project to compile and build the program
4. Follow the procedures in to download your Hex code to processor using Flash
Magic Software.
16
/****************************************************************************************/
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()
{
while(1)
{
IOCLR1 = 0xFFFF0000; // output pin cleared for enable the led
}
}
/****************************************************************************/
PWM.C
/****************************************************************************/
/* Place lcd.c file into following directories C:\Keil\ARM\INC\Philips.*/
/* This program is used to Generate the PWM, Frequency and Duty cycle can be changed*/
*****************************************************************************/
#include<LPC214x.H>
int main(void
{
/* PWMR0 AND PWMR5 Both Value can change the duty cyle ex : PWMR0 = 10 AND PWMR5 = 2*/
PWMMR0 = 0x00000010; //set cycle rate to sixteen ticks
PWMMR5 = 0x00000008; //set rising edge of PWM2 to 2 ticks
Result
The C code is generated for Switch & LED and output is verified in LED’s by Switches
The C code is generated for PWM and to vary the duty cycle and verified in CRO output.
18
Aim
To develop a C-Language program for reading the RTC, convert into decimal and to display
it.
2. Kei l µVision5software.
3. Flash Magic.
4. USB 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 LPC2141/2/4/6/8,
the RTC can be clocked by a 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.
19
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
1. Follow the steps to create a New project
2. Type the below code and save it with the name (anyname.c)
3. Follow the steps to create a New Project to compile and build the program
4. Follow the procedures in to download your Hex code to processor using Flash
Magic Software.
20
/**************************************************************/
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();clrs
cr(2);
printstr("SM MICRROSYSTEM",0,0);
printstr(" ARMDEVKIT ",0,1);
VPBDIV = 0x00000002; // VPB bus clock is one half of the processor clock(cclk)
lcddat(ones+0x30);
lcddat(':');
split_numbers(sec);lcdd
at(tens+0x30);
lcddat(ones+0x30);
//lcddat(':');
}
}
/* This is a test program to send and receive data via uart0 in theARMLPC2148 */
Development board itself
/************************************************************************************
#include<LPC214x.H> /* LPC214x definitions*/
#include"uart0.h" /* contains prototypes of driverfunctions*/
}
/************************************************************************************/
SERIAL PORT PROGRAM
/****************************************************************************/
/* Uart1 Initialization */
/****************************************************************************/
#include<lpc214x.h>#inc
lude<stdio.h>
#include<stdlib.h>
#include "uart1_driver.c"
int main()
{
unsigned char *a;
//unsigned char *w;
a=malloc(sizeof(100));
inituart1();
sendstring1("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
sendstring1("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
23
sendstring1("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
sendstring1("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
sendstring1("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
/*sendstring1(" * ");
sendstring1(" ** ");
sendstring1(" *** "); s
endstring1(" * *** "); sendstring1(" *
* * * * ");
sendstring1(" SM MICRRO ");
sendstring1(" * * * * * ");
sendstring1(" * *** "); sendstring1("
*** ");
sendstring1(" ** ");
sendstring1(" * "); */
while(1)
{
receivestring1(a);send
string1(a);
}
}
SERIAL PROGRAM
PORTDETAILSUART0
ARM DETAILS
P0.0 TXDO
P0.1 RXDO
UART1
ARM DETAILS
P0.8 TXD1
P0.9 RXD1
Result
The C-Language program for reading RTC and displaying it in LCD was written & output is
verified with running the RTC from a default/specified time.
24
Aim
To develop a C-Language program for displaying the Key pressed in the Keypad in the LCD
module. The display should come in the desired line and column.
2. Kei l µVision5software.
3. Flash Magic.
4. USB cable.
Theory
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.
25
Procedure
1. Follow the steps to create a New project
2. Type the below code and save it with the name (anyname.c)
3. Follow the steps to create a New Project to compile and build the program
4. Follow the procedures in to download your Hex code to processor using Flash
Magic Software.
26
/******************************************************************/
MAIN.C
/***********************************************************************************/
/* Description: This program gets input from Matrix key board and displays
corresponding */
/* Key value in 7segment display. Hence this program demonstratesboth
*/ 7 segment display as well as Matrix keyboard.*/
/* P1.16 to P1.23 are inputs from matrix keyboard,*/
/* P1.24 to P1.31 are outputs to 7 segmentdisplay
*/
/*************************************************************************************
****/
/* ------- matrix key boarddescription----------
*/
/* -- -- -- --
*/
/* 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>
#include "mat_7seg.h"
int main()
{
unsigned int key, last_key, Disp_key;
init_Matrix_7seg(); // Initialize matrix keyboard and 7segment dispaly
clearall_7seg(); // clear 7 segmentdisplay
last_key=0; // Initialize this variable to zero
while(1)
{
key=catch_key(); // scan for a valid keypress
if(key!=0) // zero means no key ispressed
{
if(key!=last_key) // check whether the same key is pressed again(assume this as STEP1)
{
27
/****************************************************************************/
MATRIX SEVEN SEGMENT DRIVER.C
/**************************************************************/
#include <LPC214x.h>
#include "defs.h"
/*******************************Global
variables********************************************/
unsigned int thousands,hundreds,tens,ones;
/*************************************************************************************
******/
void init_Matrix_7seg(void)
{
IODIR1 |= 0xff0f0000; // set 7seg LEDs as output ports and matrix's MSB as
inputs and LSB as outputs
IODIR0|=S7SEG_ENB; // set P0.19 to P0.22 as outputs to drive 7segenable
pins
IOPIN0|=S7SEG_ENB; // since we are using active low 7 seg display,the
enable signals
// should be initially set to HIGH.
}
/*************************************************************************************
*******/
unsigned long scan_row(unsigned int row_num)
{
//unsigned int row,i;
unsigned long val;
IOSET1=ROW_MASK; //clear the previous scan row output ie make all row opshigh
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
//default: row = ERR;
}
// for(i=0;i<=65000;i++);
val=IOPIN1; // read the matrixinputs
val = ((val >> 20) & 0x0000000F)^0x0000000F; // shift the colum value so that it comes to LSB
// XORing is done to take 1's
complement of shifted value.
//
return(val);
}
28
break;
}
case 4: {
IOPIN0=~DIGI4_ENB; // now enable only the digit4 break;
}
}
IOPIN1&=~S7SEG_LED; // make all the 7seg LED pinsLOW
}
/*************************************************************************************
*****/
void Digit_Dispay(int digit_num, unsigned int value)
{
clearDigit_7seg(digit_num);switch(
value)
{
case 0: IOPIN1 |= ZERO;break;
case 1: IOPIN1 |= ONE; break;
case 2: IOPIN1 |= TWO; break;
case 3: IOPIN1 |= THREE; break;
case 4: IOPIN1 |= FOUR; break;
case 5: IOPIN1 |= FIVE; break;
case 6: IOPIN1 |= SIX; break;
case 7: IOPIN1 |= SEVEN; break;
case 8: IOPIN1 |= EIGHT; break;
case 9: IOPIN1 |= NINE; break;
}
}
/*************************************************************************************
*****/
void Alpha_Dispay(int digit_num, unsigned int value)
{
clearDigit_7seg(digit_num);switch(
value)
{
case 1: IOPIN1 |= ZERO;break;
case 2: IOPIN1 |= ONE; break;
case 3: IOPIN1 |= TWO; break;
case 4: IOPIN1 |= THREE; break;
case 5: IOPIN1 |= FOUR; break;
case 6: IOPIN1 |= FIVE; break;
case 7: IOPIN1 |= SIX; break;
case 8: IOPIN1 |= SEVEN; break;
case 9: IOPIN1 |= EIGHT; break;
case10: IOPIN1 |= NINE; break; case
11: IOPIN1 |= AAA; break; case 12:
IOPIN1 |= bbb; break; case 13: IOPIN1 |=
ccc; break; case 14: IOPIN1 |= ddd; break;
case 15: IOPIN1 |= eee; break; case 16:
IOPIN1 |= fff;break;
}
}
/*************************************************************************************
******/
void split_numbers(unsigned int number)
{
thousands = (number /1000);
number %= 1000;
hundreds = (number / 100);
number %= 100;
tens = (number / 10);
number %= 10;
30
ones = number ;
}
/*************************************************************************************
******/
void Display_Number(unsigned int num)
{
unsigned int i;
if(num <= 9999)
{
clearall_7seg();
split_numbers((unsignedint)num);
Digit_Dispay(4, ones);
for(i=0;i<10000;i++);
Digit_Dispay(3, tens);
for(i=0;i<10000;i++);
Digit_Dispay(2,hundreds);
for(i=0;i<10000;i++);
Digit_Dispay(1,thousands);
for(i=0;i<10000;i++);
}
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
31
LCD PROGRAM
/**************************************************************/
LCD.h
/**************************************************************/
/**************************************************************/
LCD.c
/**************************************************************/
#include <LPC214x.h>
#define SET1
#define OFF0
void lcdinit()
{
IODIR0 |= 0x0000FFFF;
IOCLR0 |= 0X00000FFF;
lcdcmd(0x28);lcd
cmd(0x28);
lcdcmd(0x0c);
lcdcmd(0x06);
lcdcmd(0x01);
32
lcdcmd(0x0f);wait();
}
}
void lcdcmd(charcmd)
{
unsigned charLCDDAT;
LCDDAT = (cmd&0xf0); //higher nibble
IOSET0 =LCDDAT;
IOCLR0 = RS;
IOSET0 = CE;
wait();//(100); //enablelcd
IOCLR0 = CE;
IOCLR0 = 0X00000FFF;
IOCLR0 = 0X00000FFF;
}
void Wait_Msg(void)
{
lcdcmd(0x01);
printstr(" PLEASEWAIT ", 0,0);
}
void Welcome_Msg(void)
{
lcdcmd(0x01);
printstr(" WELCOMETO ", 0,0);
printstr("SM MICRRO SYSTEM", 0,1);
}
34
/***********************************************************************/
LCDmain.c
/******************************************************************************************/
/* This is a test program to display strings in LCD module in theARMLPC2148Development board itself*/
/**********************************************************************************************/
#include<LPC214x.H> /* LPC214x definitions*/
#include"lcd.h" /* includes lcd driverfuntions*/
while(1) /*LoopForever*/
{
Result
The C-Language program for displaying the Key pressed in the Keyboard is displayed
in the seven segment display and LCD module and the output was verified on the LCD on the
desires line and column/address.
35
Aim
To develop a C-Language program to write and read a data in EEPROM and also to
analyze its performance with the interrupt
Theory
Serial-interface EEPROM’s are used in a broad spectrum of consumer, automotive,
telecommunication, medical, industrial and PC related markets. Primarily used to store personal
preference data and configuration/setup data, Serial EEPROM’s are the most flexible type of
nonvolatile memory utilized today. Compared to other NVM solutions, Serial EEPROM devices
offer a lower pin count, smaller packages, lower voltages, as well as lower powerconsumption.
36
Procedure
1. Follow the steps to create a New project
2. Type the below code and save it with the name (anyname.c)
3. Follow the steps to create a New Project to compile and build the program
4. Follow the procedures in to download your Hex code to processor using Flash
Magic Software.
EPROM PROGRAM
/******************************************************************************/
I2C .C
/**************************************************************************/
unsigned char r;
wait();
wait();
wait();
wait();
lcdinit();clrsc
r(2);
printstr("SM MICRRO SYSTEM",0,0);
printstr(" ARMDEVKIT ",0,1);
InitI2C ();
StartI2C ();
SendI2C Address(0xa0); // EEPROM device address
WriteI2C (0); // Set the control portvalue
WriteI2C ('B');
38
StopI2C
();wait();
wait();
StartI2C ();
SendI2C Address(0xa0); // EEPROM device address
WriteI2C (0); // Set the control portvalue
StopI2C ();
StartI2C ();
SendI2C Address(0xa1); // Start the read
r=ReadI2C (); // read the result
StopI2C ();
gotoxy(0,1);
split_numbers(r);
lcddat(0x30+hundreds);lcdda
t(0x30+tens);
lcddat(0x30+ones); while(1);
}
/*******************************************************************************************/
LCD.C
/*******************************************************************************************/
void lcdinit()
{
IODIR0 = 0xFFFFFFFF;
IOCLR0 = 0X00000FFF;
lcdcmd(0x28);
lcdcmd(0x28);
lcdcmd(0x0c);
lcdcmd(0x06);
lcdcmd(0x01);
lcdcmd(0x0f);
wait();//(1600);
}
39
}
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(charcmd)
{
unsigned charLCDDAT;
LCDDAT = (cmd&0xf0); //higher nibble
IOSET0 =LCDDAT;
IOCLR0 = RS;
IOSET0 = CE;
wait();//(100); //enablelcd
IOCLR0 = CE;
IOCLR0 = 0X00000FFF;
if(ch==0)
{
printstr(" ",0,0);
gotoxy(0,0);
}
else if(ch ==1)
{
printstr(" ",0,1);
gotoxy(0,1);
}
else
{
lcdcmd(0x01);
//delay(100);
}
}
#include <LPC214x.h>
void init_VIC(void)
{
/* initialize VIC*/
VICIntEnClr =0xffffffff;
VICVectAddr =0;
VICIntSelect =0;
}
void ExtInt_ISR(void)irq
{
//EXTINT=(1<<2); /* clear EINT2 flag by writing HIGH to corespondingbit*/
//IOCLR0 = 0x40000000; /* Trigger the relay*/
IOCLR1 = 0x400f0000; /* P1.18 Trigger the relay*/
//IOPIN1 = 0x00000000;
EXTINT = (1<<2);
VICVectAddr=0; /* Acknowledge Interrupt*/
}
void init_Interrupt(void)
{
PINSEL0=0x80000000; // select P0.15 for EINT2
VICIntEnable = (1<<16); // External interrupt 2(EINT2)
VICVectCntl0=(1<<5)|(16); // set the VIC control reg for EINT2
VICVectAddr0 = (unsignedlong)ExtInt_ISR;
EXTMODE&=~(1<<2); // set VIC for egdse sensitive forEINT2
// EXTPOLAR = ~(1<<2); // set VIC for falling edge sensitive forEINT2
}
void init_ports(void)
{
IODIR0 = 0x40000000;
IODIR1 = 0x400f0000;
IOPIN1 = 0xff010000;
IOSET0 = 0x40000000;
IOSET1 = 0x400f0000;
}
/*void wait_for_turnoffRelay(void)
{
int val;
val=IOPIN1; // read the ports for key board input
while((~(val>>20))!=0); // wait until 1st key in the matrixkeyboard
is pressed
IOCLR0=0x00010000; // switch off therelay
}*/
42
/***********************************************************************************/
XINTR _RELAY.C
/**********************************************************************************/
#include <LPC214x.h>
#include "ext.h"
int main()
{
init_VIC();
init_Interrupt();init_po
rts();
while(1)
{
//wait_for_turnoffRelay();
}
}
INTERRUPT BUZZERPROGRAM
ARM DETAILS
P1.18 TRIGGER THE RELAY
P0.15 EINT2
Result
The C-Language program to write and read a data in EEPROM and also to analyze its
performance with the interrupt is developed and is verified.
43
7. MAILBOX
Aim
To develop a ‘C’code to create a mailbox and to understand the RTOS functions.
2. Kei l µVision5software.
3. Flash Magic.
4. USB cable.
.
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) up on
which the application software will run.
In providing this "abstraction layer" the RTOS kernel supplies five main categories of basic
services to application software
44
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 Inter task 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.
45
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
1. Follow the steps to create a New project
2. Type the below code and save it with the name (anyname.c)
3. Follow the steps to create a New Project to compile and build the program
4. Follow the procedures in to download your Hex code to processor using Flash
Magic Software.
46
/****************************************************************************/
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"
typedefstruct{ /* Messageobjectstructure */
charmsgBuf[MBOX_MSG_BUF_SIZE];
} T_MEAS;
clrscr(10);
printstr(" MailBox ",0,0);
printstr(" Simulation ",0,1);
#ifndef DISABLE_RECV_TASK
mptr =_alloc_box(mpool); /* Allocate a memory forthemessage */
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);
send_string(USE_UART,sSndTskBuf);send
_string(USE_UART,"\n\n\r");
} os_mbx_send (MsgBox, mptr, 0xffff); /* And send it. os_dly_wait
else
{ (100);
} memset (sInputBuf,'\0',MBOX_MSG_BUF_SIZE); cnt
#ifdefDISABLE_RECV_TASK = 0;
send_string(USE_UART,"\n\rMailbox is FULL");
main_menu();
48
#endif /* DISABLE_RECV_TASK */
}
else if ( KEY_SPACE == ch)
{
MsgFree = os_mbx_check (MsgBox); if
(MsgFree == 0)
{
send_string(USE_UART,"\n\rMailboxisFULL. ..................... ");
}
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
PleaseWait. ............ ");
os_dly_wait (100);
main_menu();
}
else if('\0' != ch)
{
sInputBuf[cnt++] = ch;
cnt %= MBOX_MSG_BUF_SIZE;
if(ch == CARRIAGE_RET &&cnt==1) //emptystring
{
cnt = 0;
}
else
{
putcharr (USE_UART,ch);
}
}
}
#ifndef DISABLE_RECV_TASK
/*
* Task 2: RTX Kernel starts this task with os_tsk_create (rec_task,0)
* */
task void rec_task (void)
{
T_MEAS *rptr;
static char sRxTskBuf[MBOX_MSG_BUF_SIZE];
for (;;)
{
os_mbx_wait (MsgBox, (void **)&rptr, 0xffff); /* wait forthemessage */
send_string(USE_UART,"\n\n\n\r************MAILBOXMESSAGE
RECEIVED***************");
49
memset (sRxTskBuf,'\0',MBOX_MSG_BUF_SIZE);
memcpy ( sRxTskBuf, rptr->msgBuf, strlen(rptr->msgBuf) ); send_string(USE_UART,"\n\n\rReceived Mbox: ");
send_string(USE_UART,sRxTskBuf);
send_string(USE_UART,"\n\r***************************************************");
_free_box(mpool,rptr); /* free memory allocatedformessage */
main_menu();
}
}
#endif /* DISABLE_RECV_TASK */
/*
* Main: Initialize and start RTXKernel
* */
int main (void)
{
initserial(USE_UART); /* uart0 initialization*/
/*
* end of file
* */
/***************************************************************/
RTX_CONFIG.C
/*************************************************************/
/*
* RL-ARM -RTX
*
* Name: RTX_CONFIG.C
* Purpose: Configuration of RTX Kernel for NXPLPC21xx
* Rev.: V4.20
*
* This code is part of the RealView Run-TimeLibrary.
* Copyright (c) 2004-2011 KEIL - An ARM Company. All rightsreserved.
* */
#include <RTL.h>
#include<LPC21xx.H> /*LPC21xxdefinitions */
/*
* RTX User configuration partBEGIN
* */
// </h>
// <h>Tick Timer Configuration
// =============================
// <o>Hardware timer <0=> Timer 0 <1=> Timer1
// <i> Define the on-chip timer used as a time-base forRTX.
// <i> Default: Timer 0
#ifndefOS_TIMER
#defineOS_TIMER 1
#endif
// </h>
// <h>SystemConfiguration
//=======================
// <e>Round-Robin Taskswitching
//=============================
// <i> Enable Round-Robin Task switching. #ifndef
OS_ROBIN
#defineOS_ROBIN 1
51
#endif
// </e>
// </h>
//------------- <<< end of configuration section >>> -----------------------
/*
* RTX User configuration partEND
* */
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; /* InterruptAck */
/* WARNING: Using IDLE mode might cause you troubles while debugging.*/ #define_idle_()
PCON =1;
/*
* GlobalFunctions
* */
/* 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 fromthistask. */
for (;;) {
/* HERE: include optional user code to be executed when no task runs.*/
}
}
/* os_tmr_call */
/* 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 (definedinRTL.H). */
#include <RTX_lib.c>
/*
* end offile
* *
/***************************************************************************/
LCD.C
/**************************************************************/
#define SET1
#define OFF0
void lcdinit(void)
{
IODIR0 |= 0x000014f0;
lcdcmd(0x28);
lcdcmd(0x28);
lcdcmd(0x0c);
lcdcmd(0x06);
lcdcmd(0x01);
lcdcmd(0x0f);
wait();//(1600);
}
54
void lcdcmd(charcmd)
{
unsigned charLCDDAT;
LCDDAT = (cmd&0xf0); //higher nibble
IOSET0 |=LCDDAT;
IOCLR0 |= RS;
IOSET0 |= CE;
wait();//(100); //enablelcd
IOCLR0 |= CE;
IOCLR0 |= 0X00000FFF;
/************************************************************/
UART.C
/*************************************************************/
/* This file contains driver functions to send and receive data via uart0inthe */
/* ARM LPC2148 Development board itself */
/************************************************************************************/ #include
<LPC214x.H>
#include "config.h"
#define TEMT (1<<6)
}
}
void putcharr (unsigned char uart, unsignedcharch) /* Writes character to
SerialPort*/
{
if(0 == uart)
{
while (!(U0LSR &TEMT)); U0THR
=ch;
}
else
{
while (!(U1LSR &TEMT)); U1THR
=ch;
}
}
}
else
{
while (!(U1LSR & 0x01));
return (U1RBR);
}
}
char receive(unsigned char uart) /*function for receiving data from sensor (readsbyte by byte & returns value if
exist,else#) */
{
if(0 == uart)
{
if (U0LSR&0x01) /* If U0LSR 1st bit contains valid data, thenreturn value ofU0RBR*/
{
return (U0RBR);
}
return'\0'; /* If other than 0 to 9 data is recievedreturn
#*/
}
else
{
if (U1LSR&0x01) /* If U0LSR 1st bit contains valid data, thenreturn
value of U0RBR*/
{
return (U1RBR);
}
}
}
}
c[i] = '\0';
return(c);
}
57
CONFIG.H
/**************************************************************/
#define MAILBOX_MEMORY_POOL_CNT16
#define MBOX_MSG_BUF_SIZE 100
#defineUSE_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 Message3"
#define LINE_FEED 0x0A #define
CARRIAGE_RET 0x0D #define
KEY_SPACE 0x20 #define
KEY_ESC0x1B
PORTDETAILS UART0
ARM DETAILS
P0.0 TXDO
P0.1 RXDO
UART1
ARM DETAILS
P0.8 TXD1
P0.9 RXD1
LCD PORTDETAILS
ARM DETAILS
PO.10 RS LCD PIN
P1.11 CE LCD PIN
Result
The C-Language program to create a mailbox and to understand the about the RTOS functions
is developed and is verified.
58
Aim
To study about the Interrupt performance characteristics between ARM and FPGA.
Theory
UART implementation FPGA & ARM7
An embedded system typically consists of both hardware and software. During the design phase
of an embedded system the system design Engineer has to choose the components of software and
hardware. In a system, implementing a specified logic or algorithm can be done exclusively using
software alone or hardware alone.
59
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.
Disadvantages: Disadvantages:
i. Complexity of writing code increases i. Designing and writing code in HDL
when the design involves the needs good understanding of digital
operating system. circuit design and a HDL language.
ii. Speed depends on the Hence complex to implement.
microprocessor’s execution speed and ii. The hardware cannot be modified
other application code that club with when there is need to upgrade the
this UART algorithm implemented protocol if it is
iii. Since the software code implemented as ASIC.
depends on processor architecture,
porting the same code in other type of
processor needs modifying code again
and hence itis
not reliable
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.
61
Pictorial representation:
To PC, for
flashing the
program
LPC2148DevelopmentKit TX memory
MA D
B
X
9
232
ARM7
LPC2148/246 RX
8
Data and
control Data driving
logic is
lines implemented in
software and
ARM7
processor
executes it.
26 pin FRC connector
MA D
Data B
X
packing/unpacking 9
232
fro ARTolld
logic is implemented
Th e software wh ich
in hardware and
drives the data RX m ppli river.
FPGA is used for it.
63
Software Part:
1. UART driver i.e. data driving logic is software part in this experiment.
2. This software is written using Embedded Clanguage
3. Keil uVision4 IDE and keil arm compiler is used for compiling the Ccode.
4. Flash Magic tool has been used to download the program in to ARM7 microcontroller.
Hardware part:
Procedure
1.Follow the steps to create a New project
2.Type the below code and save it with the name (anyname.c)
3. Follow the steps to create a New Project to compile and build the program
4. Follow the procedures in to download your Hex code to processor using Flash
Magic Software.
64
/******************************************************/
UART implementation FPGA & ARM7
ARM UART
/*********************************************************************/
#include <LPC214x.h>
void init_ios(void)
{
/*
P1.16toP1.23 --IN -- rx data
P1.24toP1.31 --OUT -- tx data
P0.15 --OUT -- txcmd
P0.16 --IN -- txdone
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 toZero
}
}
void tx_string(unsigned char* stringg)
{
while(*stringg != '\0')
{
tx_char(*stringg);string
g++;
}
tx_char(0x0a);tx_c
har(0x0d);
}
while (1)
{
tx_string("SM MICRRO SYSTEM");
}
}
/**************************************************************/
FPGA UART
/**************************************************************/
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
Connector Details
*/
rx,
lcd_rs,
lcd_en,
//lcd_rw,lcd
_dat,
tx_cmd_i,
tx_data_i,tx_
done_o,rx_da
ta_o,rx_rdy_
o
);
baud b1(
.sys_clk(clk),
.sys_rst_l(rst),
.baud_clk(u_clk)
);
u_xmitt1( .sys_clk(u_clk),
.sys_rst_l(rst),
.uart_xmitH(tx),
.xmitH(tx_cmd_i),
.xmit_dataH(tx_data_i),
.xmit_doneH(tx_done_o)
);
u_recr1( .sys_rst_l(rst),
.sys_clk(u_clk),
.uart_dataH(rx),
.rec_dataH(lcddata_in),
.rec_readyH( rx_rdy)
);
.en(lcd_en),
//.rw(lcd_rw),
.data(lcd_dat),
.wr_sig(rx_rdy),
.data_in(lcddata_in)
);
/*
always @(posedge u_clk or negedge rst) begin
if(~rst)
begin
c1 <= 16'd0;
end
else
begin
c1 <= c1 + 16'd1; if(c1 ==16'd1000)
tx_cm <= 1'b1; if(c1
==16'd1010)
begin
tx_cm <= 1'b0; end
end end
*/
endmodule
/********************************************************************/
FPGA UCF FILE
/**************************************************************/
NET"rx_rdy_o" LOC="p200" ;
NET"tx" LOC="p119" ;
NET "tx_cmd_i" LOC = "p197";
NET "tx_data_i[0]" LOC = "p185" ; NET
"tx_data_i[1]" LOC = "p186" ; NET
"tx_data_i[2]" LOC = "p187" ; NET
"tx_data_i[3]" LOC = "p189" ; NET
"tx_data_i[4]" LOC = "p190" ; NET
"tx_data_i[5]" LOC = "p192" ; NET
"tx_data_i[6]" LOC = "p193" ; NET
"tx_data_i[7]" LOC = "p196" ; NET
"tx_done_o" LOC = "p199";
generated by PACE
Result
The C-Language program for Interrupt performance characteristics between ARM and FPGA and
its characteristics was studied.
69
9. Flashing of LEDS
Aim
To develop a ‘C’ program to make the LED blink (including delay routine). Upon change in
the delay program the speed should vary.
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
1. Follow the steps to create a New project
2. Type the below code and save it with the name (anyname.c)
3. Follow the steps to create a New Project to compile and build the program
4. Follow the procedures in to download your Hex code to processor using Flash
Magic Software.
70
Result
The C-Language program to make the LED blink was developed and output was verified. Upon
change in the delay program the speed variation was verified.
71
Aim
To write C Programs for running stepper motor either in clock- wise or counter-clock- wise and
the direction of the rotation of the stepper motor depends on the variation in the temperature
sensor.
1. What is LM35?
2. List the devices used to sense temperature.
3. What is the purpose of a thermocouple?
4. What is signal conditioning?
5. What is the output voltage of a thermocouple?
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.
72
So when the next electromagnet is turned on and the first willturn 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
1. Follow the steps to create a New project
2. Type the below code and save it with the name (anyname.c)
3. Follow the steps to create a New Project to compile and build the program
4. Follow the procedures in to download your Hex code to processor using Flash
Magic Software.
call_stepper_forw()
{
IOCLR1 = 0X00FF0000;
IOSET1 = 0X00040000;
//wait();
//wait();
wait();
wait();
IOCLR1 = 0X00FF0000;
IOSET1 = 0X00060000;
//wait();
//wait();
73
wait();
wait();
IOCLR1 = 0X00FF0000;
IOSET1 = 0X00070000;
//wait();
//wait();
wait();
wait();
IOCLR1 = 0X00FF0000;
IOSET1 = 0X00050000;
//wait();
//wait();
wait();
wait();
}
/*************************************************************/
MAIN ADC TEST
/*************************************************************/
/* This is a test program to temperature sensor in the ARM LPC2148 developmentboard*/
/************************************************************************************/
#include<LPC214x.H> /* LPC214x definitions*/
#include"ADC_Driver.c" /* contains prototypes of driverfunctions*/ #include"lcd.c"
#include <stdio.h>
}
}
/************************************************************************************/
LCD.C
/************************************************************************************/
#include <LPC214x.h>
#define SET1
#define OFF0
75
void lcdinit()
{
IODIR0 |= 0xFFFFFFFF;
IOCLR0 |= 0X00000FFF;
lcdcmd(0x28);lcd
cmd(0x28);
lcdcmd(0x0c);
lcdcmd(0x06);
lcdcmd(0x01);
lcdcmd(0x0f);
wait();
}
}
void lcdcmd(charcmd)
{
unsigned charLCDDAT;
LCDDAT = (cmd&0xf0); //higher nibble
IOSET0 =LCDDAT;
IOCLR0 = RS;
IOSET0 = CE;
wait();//(100); //enablelcd
IOCLR0 = CE;
IOCLR0 = 0X00000FFF;
{
unsigned charLCDDAT;
LCDDAT = (cmd&0xf0); //higher nibble
IOSET0 =LCDDAT;
IOSET0 = RS;
IOSET0 = CE;
wait();//(100); //enablelcd
IOCLR0 = CE;
IOCLR0 = 0X00000FFF;
void Wait_Msg(void)
{
lcdcmd(0x01);
printstr(" Please Wait ", 0,0);
}
void Welcome_Msg(void)
{
lcdcmd(0x01);
printstr(" Welcometo ", 0,0);
printstr(" SMMICRRO ", 0,1);
}
77
ADC_ DRIVER.C
/**************************************************************/
Result
The C-Language program for running stepper motor either in clock-wise or counter-clock-wise
Depending on the temperature is developed in the sensor LM35 and the output is verified in LCD.
78
Aim
To write C Programs for Zigbee Protocol and verify the communication between Xbee Module
Transmitter and Receiver.
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
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.
To ensure reliable data transmission
Procedure
1. Follow the steps to create a New project
2. Type the below code and save it with the name (anyname.c)
3. Follow the steps to create a New Project to compile and build the program
4. Follow the procedures in to download your Hex code to processor using Flash
Magic Software.
80
/****************************************************************************/
ARM TRANSMITTER
PROGRAMLCD.C
/****************************************************************************/
#include <LPC214x.h>
#include "lcd.h"
#defineRS 0x00000400 /* P0.10 */
#defineCE 0x00001800 /* P1.11 */
#define SET1
#define OFF0
(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);lcd
cmd(0x28);
lcdcmd(0x0c);
lcdcmd(0x06);
lcdcmd(0x01);
lcdcmd(0x0f);
wait();
}
lcddat(str[i]);
}
void lcdcmd(charcmd)
{
unsigned charLCDDAT;
LCDDAT = (cmd&0xf0); //higher nibble
IOSET0 =LCDDAT;
IOCLR0 = RS;
IOSET0 = CE;
wait(); //(100);
//enable lcd
IOCLR0 = CE;
IOCLR0 = 0X00000FFF;
}
void lcddat(char cmd)
{
unsigned charLCDDAT;
LCDDAT = (cmd&0xf0); //higher nibble
IOSET0 =LCDDAT;
IOSET0 = RS;
IOSET0 = CE;
wait();//(100); //enablelcd
IOCLR0 = CE;
IOCLR0 = 0X00000FFF;
void Wait_Msg(void)
{
lcdcmd(0x01);
printstr(" Please Wait ", 0,0);
}
void Welcome_Msg(void)
{
lcdcmd(0x01);
printstr(" Welcometo ", 0,0);
printstr(" SMMICRRO ", 0,1);
}
/***********************************************************************************/
LCD.h
/***********************************************************************************/
/**************************************************************/
UART_1.C
/**************************************************************/
#include <LPC214X.H>
#include "lcd.c"
#define TEMT0X40
void uart_1(void);
voiddelay(void);
void putcharr (unsignedcharch); /* Writes character to Serial Port*/
void tx_string(charstr);
int main(void)
{
uart_1();
lcdinit();dela
y();
delay();
83
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*/
}
int main(void)
{
char rx_data;
uart_1();
lcdinit();
printstr("SM MICRRO SYSTEM",0,0);
while(1)
{
84
Result
The C-Language program for Zigbee Protocol is written and the communication between
Xbee Module Transmitter and Receiver is verified.
84
Aim
To simulate a multivibrator using Proteus Software and
check its functionality by verifying its output with an simulated
LED.
Procedure
Step1:
Start All Programs Proteus xx Professional
ISIS xxProfessional
85
Note:
The MenuBar
TheToolbars
Command Toolbars
86
Mode Selector Toolbar
Orientation Toolbar
Simulation Toolbar
Construct the following multivibrator circuit using analog and digital components and
simulate it,
87
The Components needed are,
Step 2:
Step 3
Then choose the all require components and put into the main window.
89
Following the same procedure, place all the required components to main window
91
Step 4
Connect all the components as the above circuit diagram by using connecting lines. We can
get connecting lines by selectingendsofthecomponentsasshowsinfollowingfigure.
Step 5
Now make sure all the components correctly connected. Then go the simulation tool bar.
Result
Thus the Multivibrator is simulated using Proteus Software and the output is
observed.
94
95
Aim
To simulate a simple calculator using 8051microcontroller in Proteus Software.
Procedure
The calculator we are going to design is quite basic calculator, it will only perform 4 tasks, which
are as follows:
When you press the (+) button then it will add the two digits. For example, you want to
add 2 and 3 then you need to press 2 + 2 = these four buttons in sequence and when you
press the = button it will automatically will give you the sum.
When you press (-) button it will subtract the two digits like 3 – 2 = and it will give you
the result.
When you press (x) button it will multiply the two digits.
When you press the (/) button it will simply divide the two digits.
Whenever you press the (=) button, it will give you the output
depending on the function you used before and if you press (=) in the start then it will give
“Wrong Input”.
Finally,there’s(ON/C)button on the Calculator, when you press this it will simply reset the
code and will clear theLCD.
So,that’show this calculator is goanna work. More over, it will always reset when you try
to calculate new value.
As its a simple calculator, so its only limited to 1 digit, means it will only apply the
operation on single digit input like 2+3 but it won’t work on more than 1 digit like 12 +13.
After that, we will do the coding part for calculator with 8051 Microcontroller.
So, now let’s get started with Proteus Simulation.
96
ProteusSimulation
TheProteusSimulationofthisCalculatorwith8051 Microcontroller and is shown in
belowfigure:
ProgrammingCode
1 while(1)
2 {
3 //getnumb1
4 key =get_key();
5 writecmd(0x01); //cleardisplay
6 writedata(key); //Echo the key pressed toLCD
7 num1=get_num(key); //Get int number from char value, it checksfor
8
9 wrong input as well
10 if(num1!=Error) //if correct input then proceed,num1==Error
11 means wrong input
12 {
13 //getfunction
14 key =get_key();
15 writedata(key); //Echo the key pressed toLCD
16 func=get_func(key); //it checks for wrong func 17
18 if(func!='e') //if correct input thenproceed,
19 func=='e' means wrong input 20
{
21 //getnumb2
22 key =get_key();
23 writedata(key); //Echo the key pressed toLCD
24 num2=get_num(key); //Get int number fromchar
25 value, it checks for wrong input as well 26
27 if(num2!=Error) //if correct inputthen
28 proceed, num2==Error means wronginput
97
29 {
30 //get equal sign key =
get_key();
31
writedata(key); //Echo the key pressed to LCD if(key=='=')
32
33
//if = is pressedthen
34
35 proceed
36 {
switch(func) //switch onfunction
37
{
38
39 case '+': disp_num(num1+num2); break; case '-':
40 disp_num(num1-num2); break; case 'x':
41 disp_num(num1*num2); break; case '/':
disp_num(num1/num2); break;
42
}
43
}
44
else //key other then=
45
As you can see in the above function, first check for thefirst keypress.
When you pressed the first key on keypad then I get this key and converter it tointeger.
AfterthatIwaitedforthenextkeywhichmustbesomeoperation keylike+–
Xor/otherwiseitwillgeneratetheerrormessage.
After that code is waiting for the third key which should be
somenumericaldigitandthenItconvertsittointegeragainand if you entered some invalid key
then it will generate theerror.
Finally waiting for the = sign. When you press the = sign it will automatically perform the
required operation which Iplaced in the switch caseloop.
It will calculate the value and then print out the result and
onnextkeypressitwillfirstclearthescreenandthengetthe value and willcontinue.
Below is the detailed code for the project withcomments
1 #include<reg51.h>
2 #include<string.h>3
4 //DefineMacros
5 #defineError 13 // Any value other than 0 to 9 is good here 6
7 //Functiondeclarations
8 voidcct_init(void);
9 voiddelay(int);
10 voidlcdinit(void);
98
11 voidwritecmd(int);
12 voidwritedata(char);
13 voidwriteline(char[]);
14 voidReturnHome(void);
15 charREAD_SWITCHES(void);
16 charget_key(void);
17 intget_num(char);
18 charget_func(char);
19 voidDispError(int);
20 voiddisp_num(int);
21 void WebsiteLogo();
22 22
23 /
24 //Pindescription
25 /*
26 P2 is databus
27 P3.7 isRS
28 P3.6 isE
29 P1.0 to P1.3 are keypad rowoutputs
30 P1.4 to P1.7 are keypad column inputs 31
*/
32 //********************
33 // DefinePins
34 //********************
35 sbit RowA = P1^0; //RowA
36 sbit RowB = P1^1; //RowB
37 sbit RowC = P1^2; //RowC
38 sbit RowD = P1^3; //RowD
39
40 sbit C1 = P1^4; //Column1
41 sbit C2 = P1^5; //Column2
42 sbit C3 = P1^6; //Column3
43 sbit C4 = P1^7; //Column4
44
45 sbit E = P3^6; //E pin for LCD
46 sbit RS = P3^7; //RS pin for LCD
47
48 //***********************************************************
49 // Mainprogram
50 //
51 intmain(void)
52 {
53 charkey; //key char for keeping record ofpressed
54 key
55 int num1=0; //Firstnumber
56 char func='+'; //Function to be performed amongtwo
57 numbers
58 int num2=0; //Second number 59
60 cct_init(); //Make input and output pins asrequired
61 lcdinit(); //InitilizeLCD
62 WebsiteLogo();
63 while(1)
64 {
65 WebsiteLogo();
66 //getnumb1
67 key =get_key();
68 writecmd(0x01); //cleardisplay
69 WebsiteLogo();
70 writedata(key); //Echo the key pressed toLCD
71 num1=get_num(key); //Get int number from char value, itchecks
72 for wrong input as well 73
74 if(num1!=Error) //if correct input then proceed,num1==Error
75 means wrong input 76
{
77 //getfunction
78 key =get_key();
79 writedata(key); //Echo the key pressed toLCD
80 func=get_func(key); //it checks for wrong func 81
99
82 if(func!='e') //if correct input thenproceed,
83 func=='e' means wrong input
84 {
85 //get numb2
86 key = get_key();
87 writedata(key); //Echo the key pressed toLCD
88 num2=get_num(key); //Get int number fromchar
89 value, it checks for wrong input as well
90
91 if(num2!=Error) //if correct inputthen
92 proceed, num2==Error means wrong input
93 {
94 //get equal sign
95 key = get_key();
96 writedata(key); //Echo the key pressedto
97 LCD
98
99 if(key=='=') //if = is pressedthen
100 proceed
101 {
102 switch(func) //switch onfunction
103 {
104 case '+': disp_num(num1+num2); break;
105 case '-': disp_num(num1-num2); break;
106 case 'x': disp_num(num1*num2); break;
107 case '/': disp_num(num1/num2); break;
108 }
109 }
110 else //key other then=
111 here means error wrong input
112 {
113 if(key=='C') //if clear screenis
114 pressed then clear screen and reset
115 {
116 writecmd(0x01); //Clear Screen
117 WebsiteLogo();
118 }
119 else
120 {
121 DispError(0); //Display wrong
122 input error
123 WebsiteLogo();
124 }
125 }
126 }
127 }
128 }
129 }
130 }
131
132 void WebsiteLogo()
133 {
134 writecmd(0x95);
135 writedata('w'); //write
136 writedata('w'); //write
137 writedata('w'); //write
138 writedata('.'); //write
139 writedata('T'); //write
140 writedata('h'); //write
141 writedata('e'); //write
142 writedata('E'); //write
143 writedata('n'); //write
144 writedata('g'); //write
145 writedata('i'); //write
146 writedata('n'); //write
147 writedata('e'); //write
148 writedata('e'); //write
149 writedata('r'); //write
150 writedata('i'); //write
151 writedata('n'); //write
152 writedata('g'); //write
100
153
154 writecmd(0xd8);
155
156 writedata('P'); //write
157 writedata('r'); //write
158 writedata('o'); //write
159 writedata('j'); //write
160 writedata('e'); //write
161 writedata('c'); //write
162 writedata('t'); //write
163 writedata('s'); //write
164 writedata('.'); //write
165 writedata('c'); //write
166 writedata('o'); //write
167 writedata('m'); //write
168 writecmd(0x80);
169 }
170
171 voidcct_init(void)
172 {
173 P0=0x00; //notused
174 P1=0xf0; //used for generating outputs and taking inputs fromKeypad
175 P2=0x00; //used as data port forLCD
176 P3=0x00; //used for RS andE
177 }
178
179 void delay(inta)
180 {
181 inti;
182 for(i=0;i<a;i++); //nullstatement
183 }
184
185 void writedata(chart)
186 {
187 RS=1; // This isdata
188 P2=t; //Datatransfer
189 E =1; // => E = 1
190 delay(150);
191 E =0; // => E = 0
192 delay(150);
193 }
194
195
196 void writecmd(int z)
197 {
198 RS = 0; // This is command
199 P2=z; //Datatransfer
200 E =1; // => E =1
201 delay(150);
202 E =0; // => E =0
203 delay(150);
204 }
205
206 void lcdinit(void)
207 {
208 ///////////// Reset process from datasheet /////////
209 delay(15000);
210 writecmd(0x30);
211 delay(4500);
212 writecmd(0x30);
213 delay(300);
214 writecmd(0x30);
215 delay(650);
216 /////////////////////////////////////////////////////
217 writecmd(0x38); //functionset
218 writecmd(0x0c); //display on,cursor off,blinkoff
219 writecmd(0x01); //cleardisplay
220 writecmd(0x06); //entry mode, setincrement
221 }
222 voidReturnHome(void) /* Return to 0 cursor location*/
101
223
224 {
225 writecmd(0x02);
226 delay(1500);
227 WebsiteLogo();
228 }
229
230 void writeline(char Line[])
231 {
232 int i;
233 for(i=0;i<strlen(Line);i++)
234 {
235 writedata(Line[i]); /* Write Character*/
236 }
237
238 ReturnHome(); /* Return to 0 cursor position*/
239 }
240
241 char READ_SWITCHES(void)
242 {
243 RowA = 0; RowB = 1; RowC = 1; RowD = 1; //Test Row A
244
245 if (C1 == 0) { delay(10000); while (C1==0); return '7'; }
246 if (C2 == 0) { delay(10000); while (C2==0); return '8'; }
247 if (C3 == 0) { delay(10000); while (C3==0); return '9'; }
248 if (C4 == 0) { delay(10000); while (C4==0); return '/'; }
249
250 RowA = 1; RowB = 0; RowC = 1; RowD = 1; //Test Row B
251 if (C1 == 0) { delay(10000); while (C1==0); return '4'; }
252 if (C2 == 0) { delay(10000); while (C2==0); return '5'; }
253 if (C3 == 0) { delay(10000); while (C3==0); return '6'; }
254 if (C4 == 0) { delay(10000); while (C4==0); return 'x'; }
255
256
257 RowA = 1; RowB = 1; RowC = 0; RowD = 1; //Test Row C
258
259 if (C1 == 0) { delay(10000); while (C1==0); return '1'; }
260 if (C2 == 0) { delay(10000); while (C2==0); return '2'; }
261 if (C3 == 0) { delay(10000); while (C3==0); return '3'; }
262 if (C4 == 0) { delay(10000); while (C4==0); return '-'; }
263
264 RowA = 1; RowB = 1; RowC = 1; RowD = 0; //Test Row D
265
266 if (C1 == 0) { delay(10000); while (C1==0); return 'C'; }
267 if (C2 == 0) { delay(10000); while (C2==0); return '0'; }
268 if (C3 == 0) { delay(10000); while (C3==0); return '='; }
269 if (C4 == 0) { delay(10000); while (C4==0); return '+'; }
270
271 return'n'; // Means no key has beenpressed
272 }
273
274 charget_key(void) //get key fromuser
275 {
276 char key='n'; //assume no key pressed 277
278 while(key=='n') //wait untill a key ispressed
279 key=READ_SWITCHES(); //scan the keys again and again 280
281 returnkey; //when key pressed then return itsvalue
282 }
283
284 int get_num(char ch) //convert char into int
285 {
286 switch(ch)
287 {
288 case '0': return 0; break;
289 case '1': return 1; break;
290 case '2': return 2; break;
291 case '3': return 3; break;
292 case '4': return 4; break;
293 case '5': return 5; break;
294 case '6': return 6; break;
102
Result