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- indus tr y
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 engineer ing
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 enginee r ing
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 engineer ing
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 engineer ing
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
List of Experiments:
1. Study of ARM evaluation system
2. Interfacing ADC and DAC.
3. Interfacing LED and PWM.
4. Interfacing real time clock and serial port.
5. Interfacing keyboard and LCD.
6. Interfacing EPROM and interrupt.
7. Mailbox.
8. Interrupt performance characteristics of ARM and FPGA.
9. Flashing of LEDS.
10. Interfacing stepper motor and temperature sensor.
11. Implementing zigbee protocol with ARM.
Course Outcome:
At the end of the course, the student should be able to:
Write programs in ARM for a specific Application
Interface memory, A/D and D/A convertors with ARM system
Analyze the performance of interrupt
Write program for interfacing keyboard, display, motor and sensor.
Formulate a mini project using embedded system
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 applicatio ns
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 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 LQFP64 package.
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 instructio n 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μs per 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 32 kHz Clock input.
Multiple serial interfaces including two UARTs (16C550), two Fast I2C-bus (400 kbit/s), SPI
60 MHz maximum CPU clock available from programmable on-chip PLLwith 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 additiona l
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
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 the ARM LPC2148 development board */
/************************************************************************************/
/***************************************************************************/
LCD.C
/************************************************************************************/
#include <LPC214x.h>
#define SET 1
#define OFF 0
unsigned int thousands,hundreds,tens,ones;
10
void lcdinit()
{
IODIR0 |= 0xFFFFFFFF;
IOCLR0 |= 0X00000FFF;
lcdcmd(0x28);
lcdcmd(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(char cmd)
{
unsigned char LCDDAT;
LCDDAT = (cmd & 0xf0); //higher nibble
IOSET0 = LCDDAT;
IOCLR0 = RS;
IOSET0 = CE;
wait();//(100); //enable lcd
IOCLR0 = CE;
IOCLR0 = 0X00000FFF;
{
unsigned char LCDDAT;
LCDDAT = (cmd & 0xf0); //higher nibble
IOSET0 = LCDDAT;
IOSET0 = RS;
IOSET0 = CE;
wait();//(100); //enable lcd
IOCLR0 = CE;
IOCLR0 = 0X00000FFF;
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);
}
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();
wait_long();
IODIR0 = 0X00000FFF;
IODIR1 = 0XFFFF0000;
IOSET0 = 0XFFFFFFFF;
IOCLR1 = 0XFFFF0000;
PINSEL1 |= 0x00080000; //Enable pin 0.25 as DAC
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 Sw itch & 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(voi d
{
/* 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.
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();
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)
lcddat(ones+0x30);
lcddat(':');
split_numbers(sec);
lcddat(tens+0x30);
lcddat(ones+0x30);
//lcddat(':');
}
}
PORT INBUILT
22
/**************************************************************/
/* 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 */
#include "uart0.h" /* contains prototypes of driver functions*/
}
/************************************************************************************/
SERIAL PORT PROGRAM
/****************************************************************************/
/* Uart1 Initialization */
/***************************************** ***********************************/
#include<lpc214x.h>
#include<stdio.h>
#include<stdlib.h>
#include "uart1_driver.c"
int main()
{
unsigned char *a;
//unsigned char *w;
a=malloc(sizeof(100));
inituart1();
sendstrin g1( "A BC D E FG H IJK L M N O P Q RST U V W X Y Z ");
sendstrin g1( "A BC D E FG H IJK L M N O P Q RST U V W X Y Z ");
23
while(1)
{
receivestring1(a);
sendstring1(a);
}
}
DETAILS UART 0
ARM DETAILS
P0.0 TXDO
P0.1 RXDO
UART 1
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.
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 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>
#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 segment display
last_key = 0; // Initialize this variable to zero
while(1)
{
key = catch_key(); // scan for a valid key press
if(key != 0) // zero means no key is pressed
{
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
variable s*** *** *** *** *** *** *** *** *** *** *** *** *** *** **/
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 7seg enable
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 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
//default: row = ERR;
}
// for(i=0;i<=65000;i++);
val = IOPIN1; // read the matrix inputs
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 pins LOW
}
/*************************************************************************************
*****/
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;
case 10: 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((unsigned int)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 SET 1
#define OFF 0
void lcdinit()
{
IODIR0 |= 0x0000FFFF;
IOCLR0 |= 0X00000FFF;
lcdcmd(0x28);
lcdcmd(0x28);
lcdcmd(0x0c);
lcdcmd(0x06);
lcdcmd(0x01);
32
lcdcmd(0x0f); wait();
}
}
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;
IOCLR0 = 0X00000FFF;
}
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 SYSTEM", 0, 1);
}
34
/************************************************************* **********/
LCD main.c
/******************************************************************************************/
/* This is a test program to display strings in LCD module in the ARM LPC2148 Development board itself */
/*********************************************************************************** ********** */
#include <LPC214x.H> /* LPC214x definitions */
#include "lcd.h" /* includes lcd driver funtions*/
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 power consumption.
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
/**************************************************************************/
void InitI2C(void);
void SendI2CAddress(unsigned char Addr_S); void
WriteI2C(unsigned char Data);
void StopI2C(void); void
StartI2C(void);
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
}
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 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');
38
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
/*******************************************************************************************/
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(char cmd)
{
unsigned char LCDDAT;
LCDDAT = (cmd & 0xf0); //higher nibble
IOSET0 = LCDDAT;
IOCLR0 = RS;
IOSET0 = CE;
wait();//(100); //enable lcd
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 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 matrix keyboard
is pressed
IOCLR0 = 0x00010000; // switch off the relay
}*/
42
/***********************************************************************************/
XINTR _RELAY.C
/**********************************************************************************/
#include <LPC214x.h>
#include "ext.h"
int main()
{
init_VIC();
init_Interrupt();
init_ports();
while(1)
{
//wait_for_turnoffRelay();
}
}
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. MAIL BOX
Aim
To develop a ‘C’ code to create a mailbox and to understand the RTOS functions.
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) 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
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 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 applicatio n
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"
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',M BOX_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
#ifdef = 0;
DISABLE_RECV_TASK
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\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);
}
}
}
#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 for the message */
send_string(USE_UART,"\n\n\n\r************MAILBOX MESSAGE
RECEIVED***************");
49
send_string(USE_UART,"\n\r***************************************************");
_free_box (mpool, rptr); /* free memory allocated for message */
main_menu();
}
}
#endif /* DISABLE_RECV_TASK */
/*
* Main: Initialize and start RTX Kernel
* */
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 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
* */
// </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
// </h>
// <h>System Configuration
// =======================
// <e>Round-Robin Task switching
// =============================
// <i> Enable Round-Robin Task switching. #ifndef
OS_ROBIN
#define OS_ROBIN 1
51
#endif
// </e>
// </h>
//------------- <<< end of configuration section >>> -----------------------
/*
* RTX User configuration part END
* */
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 */
/* 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 */
/* os_error */
#include <RTX_lib.c>
/*
* end of file
* *
/***************************************************************************/
LCD.C
/**************************************************************/
#define SET 1
#define OFF 0
void lcdinit(void)
{
IODIR0 |= 0x000014f0;
lcdcmd(0x28);
lcdcmd(0x28);
lcdcmd(0x0c);
lcdcmd(0x06);
lcdcmd(0x01);
lcdcmd(0x0f);
wait();//(1600);
}
54
/************************************************************/
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 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);
56
}
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);
}
}
}
}
c[i] = '\0';
return(c);
}
57
CONFIG.H
/**************************************************************/
#define MAILBOX_M EMORY_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
DETAILS UART 0
ARM DETAILS
P0.0 TXDO
P0.1 RXDO
UART 1
ARM DETAILS
P0.8 TXD1
P0.9 RXD1
LCD PORT DETAILS
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 functio ns
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.
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
This involves feeding and obtaining the actual data to be packed to the data packing/ unpacking
logic.
Pictorial representation:
To PC, for
flashing the
program
LPC2148 Development Kit 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
ARM 7
processor
executes it.
26 pin FRC connector
MA D
Data B
X
packing/unpacking 9
232
fro ARTolld
logic is implemented
Th e insoftware
hardware and which 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 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:
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.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_string(unsigned char* stringg)
{
while(*stringg != '\0')
{
tx_char(*stringg);
stringg++;
}
tx_char(0x0a);
tx_char(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_data_o,
rx_rdy_o
);
baud b1(
.sys_clk(clk),
.sys_rst_l(rst),
.baud_clk(u_clk)
);
.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
/**************************************************************/
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
/* This is a test program to make the LEDs L2 and L3 Blink in the ARM LPC2148 */
development board itself
/************************************************************************************/
#include <LPC214x.H> /* LPC214x definitions */
void wait (void) /* wait function */
{
int d;
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 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
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 development board*/
/****** **** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** **/
#include <LPC214x.H> /* LPC214x definitions */
#include "ADC_Driver.c" /* contains prototypes of driver functions*/ #include
"lcd.c"
#include <stdio.h>
}
}
/************************************************************************************/
LCD.C
/****** **** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** **/
#include <LPC214x.h>
#define SET 1
#define OFF 0
75
void lcdinit()
{
IODIR0 |= 0xFFFFFFFF;
IOCLR0 |= 0X00000FFF;
lcdcmd(0x28);
lcdcmd(0x28);
lcdcmd(0x0c);
lcdcmd(0x06);
lcdcmd(0x01);
lcdcmd(0x0f);
wait();
}
}
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;
{
unsigned char LCDDAT;
LCDDAT = (cmd & 0xf0); //higher nibble
IOSET0 = LCDDAT;
IOSET0 = RS;
IOSET0 = CE;
wait();//(100); //enable lcd
IOCLR0 = CE;
IOCLR0 = 0X00000FFF;
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);
}
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.
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
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
(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();
}
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;
}
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;
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
/***********************************************************************************/
/****** **** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
UART_1.C
/**************************************************************/
#include <LPC214X.H>
#include "lcd.c"
int main(void)
{
uart_1();
lcdinit();
delay();
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 xx Professional
85
Note:
The Toolbars
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
3. Next click on OK
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 selecting ends of the components as shows in following figure.
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 8051 microcontroller 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 the LCD.
So, that’s how this calculator is gonna work. Moreover, 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
Proteus Simulation
The Proteus Simulation of this Calculator with 8051 Microcontroller and is shown in
below figure:
Programming Code
1 while(1)
2 {
3 //get numb1
4 key = get_key();
5 writecmd(0x01); //clear display
6 writedata(key); //Echo the key pressed to LCD
7 num1 = get_num(key); //Get int number from char value, it checks for
8
9 wrong input as well
10 if(num1!=Error) //if correct input then proceed, num1==Error
11 means wrong input
12 {
13 //get function
14 key = get_key();
15 writedata(key); //Echo the key pressed to LCD
16 func = get_func(key); //it checks for wrong func 17
18 if(func!='e') //if correct input then proceed,
19 func=='e' means wrong input 20
{
21 //get numb2
22 key = get_key();
23 writedata(key); //Echo the key pressed to LCD
24 num2 = get_num(key); //Get int number from char
25 value, it checks for wrong input as well 26
27 if(num2!=Error) //if correct input then
28 proceed, num2==Error means wrong input
97
{
29
//get equal sign key =
30
get_key();
31
writedata(key); //Echo the key pressed to LCD if(key ==
32
33
'=') //if = is pressed then
34
35 proceed
{
36
switch(func) //switch on function
37
{
38
case '+': disp_num(num1+num2); break; case '-':
39
disp_num(num1-num2); break; case 'x':
40
disp_num(num1*num2); break; case '/':
41
disp_num(num1/num2); break;
42
}
43
}
44
else //key other then =
45
As you can see in the above function, first check for the first key press.
When you pressed the first key on keypad then I get this key and converter it to integer.
After that I waited for the next key which must be some operation key like + – X or / otherwise
it will generate the error message.
After that code is waiting for the third key which should be some numerical digit and then
It converts it to integer again and if you entered some invalid key then it will generate the
error.
Finally waiting for the = sign. When you press the = sign it will automatically perform the
required operation which Iplaced in the switch case loop.
It will calculate the value and then print out the result and on next key press it will first clear
the screen and then get the value and will continue.
Below is the detailed code for the project with comments
1 #include<reg51.h>
2 #include<string.h> 3
4 //Define Macros
5 #define Error 13 // Any value other than 0 to 9 is good here 6
7 //Function declarations
8 void cct_init(void);
9 void delay(int);
10 void lcdinit(void);
98
11 void writecmd(int);
12 void writedata(char);
13 void writeline(char[]);
14 void ReturnHome(void);
15 char READ_SWITCHES(void);
16 char get_key(void);
17 int get_num(char);
18 char get_func(char);
19 void DispError(int);
20 void disp_num(int);
21 void WebsiteLogo();
22 22
23 /
24 //Pin description
25 /*
26 P2 is data bus
27 P3.7 is RS
28 P3.6 is E
29 P1.0 to P1.3 are keypad row outputs
30 P1.4 to P1.7 are keypad column inputs 31
*/
32 //********************
33 // Define Pins
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 // Main program
50 //
51 int main(void)
52 {
53 char key; //key char for keeping record of pressed
54 key
55 int num1 = 0; //First number
56 char func = '+'; //Function to be performed among two
57 numbers
58 int num2 = 0; //Second number 59
60 cct_init(); //Make input and output pins as required
61 lcdinit(); //Initilize LCD
62 WebsiteLogo();
63 while(1)
64 {
65 WebsiteLogo();
66 //get numb1
67 key = get_key();
68 writecmd(0x01); //clear display
69 WebsiteLogo();
70 writedata(key); //Echo the key pressed to LCD
71 num1 = get_num(key); //Get int number from char value, it checks
72 for wrong input as well 73
74 if(num1!=Error) //if correct input then proceed, num1==Error
75 means wrong input 76
{
77 //get function
78 key = get_key();
79 writedata(key); //Echo the key pressed to LCD
80 func = get_func(key); //it checks for wrong func 81
99
82 if(func!='e') //if correct input then proceed,
83 func=='e' means wrong input
84 {
85 //get numb2
86 key = get_key();
87 writedata(key); //Echo the key pressed to LCD
88 num2 = get_num(key); //Get int number from char
89 value, it checks for wrong input as well
90
91 if(num2!=Error) //if correct input then
92 proceed, num2==Error means wrong input
93 {
94 //get equal sign
95 key = get_key();
96 writedata(key); //Echo the key pressed to
97 LCD
98
99 if(key == '=') //if = is pressed then
100 proceed
101 {
102 switch(func) //switch on function
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 screen is
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 void cct_init(void)
172 {
173 P0 = 0x00; //not used
174 P1 = 0xf0; //used for generating outputs and taking inputs from Keypad
175 P2 = 0x00; //used as data port for LCD
176 P3 = 0x00; //used for RS and E
177 }
178
179 void delay(int a)
180 {
181 int i;
182 for(i=0;i<a;i++); //null statement
183 }
184
185 void writedata(char t)
186 {
187 RS = 1; // This is data
188 P2 = t; //Data transfer
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; //Data transfer
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); //function set
218 writecmd(0x0c); //display on,cursor off,blink off
219 writecmd(0x01); //clear display
220 writecmd(0x06); //entry mode, set increment
221 }
222 void ReturnHome(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 been pressed
272 }
273
274 char get_key(void) //get key from user
275 {
276 char key = 'n'; //assume no key pressed 277
278 while(key=='n') //wait untill a key is pressed
279 key = READ_SWITCHES(); //scan the keys again and again 280
281 return key; //when key pressed then return its value
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