EC6711 ES LAB Manual Final
EC6711 ES LAB Manual Final
DEPARTMENT OF ECE
1
COLLEGE OF ENGINEERING AND TECHNOLOGY,
KOTHANDARAMAN NAGAR, DINDIGUL-624622.
2
INSTRUCTION TO THE STUDENTS
3
EC6711 EMBEDDED LABORATORY LTPC
0032
OBJECTIVES:
The student should be made to:
Learn the working of ARM processor
Understand the Building Blocks of Embedded Systems
Learn the concept of memory map and memory interface
Know the characteristics of Real Time Systems
Write programs to interface memory, I/Os with processor
Study the interrupt performance
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..
TOTAL: 45 PERIODS
4
PSNA COLLEGE OF ENGINEERING AND TECHNOLOGY,
Kothandaraman Nagar, DINDIGUL-624622. Tamil Nadu
LIST OF EXPERIMENTS
Sl. Page
Date Name of Experiments Marks Remarks
No No
FIRST CYCLE
2 Flashing of LED‘s
SECOND CYCLE
5
LPC-2378 ARM Development board
Steps to be followed for IAR workbench software
8. Give your File name Eg: DAC.C and click Save Button.
9. Right Click the project name option for select a „C‟ file in
workspace window. Select Add >Add DAC.C Menu.
10. Copy the header files config.h and irq.h and paste it in the project
folder where your „C’ files is located as already created.
11. Select LPC2378>Rebuild all menu, for checking any error in your
‘C’ file. If your „C„file has no error the following window will be
displayed.
12. Select LPC2378 >Options menu
13. Select Linker Category. Enable output option file and give
Filename. hex Eg: LPC2378.hex.
14. Enable Other Menu and select Intelextented option.
15. Select Config Menu. Enable Overide default option and click
Browse button for choosing a LPC2378-Flash-XCL file.
Path: C:\Program Files\IAR Systems\Embedded Workbench 4.0 Kick
Start\Arm\Examples\NxP\LPC23XX\IAR\LPC2378\SK\simple\commo
n\XCL\LPC2378 FlashXCL and click OK button.
16. Select General options category. Enable target option file and
select the device as NXP LPC2378 and click ok.
17. Select LPC2378>Rebuild all menu, for checking any error in your
‘C’ file.
18. If your project has no error, Building completed and Hex file
generated.
Introduction
6
LPC-2378 is an ARM-based microcontroller for applications requiring serial
communications for a variety of purposes. This microcontroller incorporate a 10/100 Ethernet
MAC, USB 2.0 Full Speed interface, four UARTs, two CAN channels, an SPI interface, two
Synchronous Serial Ports (SSP), three I2C interfaces, an I2S interface, and a Mini Bus. It has 8-
bit data/16-bit address parallel bus is available.
LPC2378 Micro-controller is based on a 32/16 Bit ARM7TDMI-s CPU with real time
Emulation and Embedded Trace support that combines with the microcontroller with embedded
high-speed 512KB flash memory. It can work with 16-bit Thumb Mode. The ARM7TDMI-S is
a general- purpose 32-bit microprocessor, which offers high performance and very low power
consumption. The ARM architecture is based on Reduced Instruction Set Computer (RISC)
principles.
7
LPC2377/78 is ideal for multi-purpose serial communication applications. It incorporates
a 10/100 Ethernet Media Access Controller (MAC), USB full speed device with 4 kB of
endpoint RAM (LPC2378 only), four UARTs, two CAN channels (LPC2378 only), an SPI
interface, two Synchronous Serial Ports (SSP), three I2C-bus interfaces, an I 2S-bus interface,
and an External Memory Controller (EMC). This blend of serial communications interfaces
combined with an on-chip 4 MHz internal oscillator, SRAM of 32 kB, 16 kB SRAM for
Ethernet, 8 kB SRAM for USB and general purpose use, together with 2 kB battery powered
SRAM make this device suited for communication gateways and protocol converters. Various
32-bit timers, an improved 10-bit ADC, 10-bit DAC, PWM unit, a CAN control unit, and up to
104 fast GPIO lines with up to 50 edge and up to four level sensitive external interrupt pins
make these microcontrollers suitable for industrial control and medical systems.
Up to 512kB on-chip Flash Program Memory with In-System Programming (ISP) and
In-Application Programming (IAP) capabilities. Single Flash sector or full chip erase in
400ms and 256 bytes programming in 1ms. Flash program memory is on the ARM local
bus for high performance CPU access.
Up to 32KB of SRAM on the ARM local bus for high performance CPU access.
16KB Static RAM for Ethernet interface. CAN also be used as general purpose SRAM.
8KB Static RAM for USB interface. CAN also be used as general purpose SRAM.
Dual AHB system that provides for simultaneous Ethernet DMA, USB DMA, and
program execution from on-chip Flash with no contention between those functions. A
bus bridge allows the Ethernet DMA to access the other AHB subsystem.
External memory controller that supports static devices such as Flash and SRAM.
Processor Range:
ARM offers a wide range of processor cores based on a common architecture, that
deliver high performance together with low power consumption and system cost .
8
The ARM processor range provides solutions for:
Open platforms running complex operating systems for wireless, consumer and imaging
applications.
Embedded real-time systems for mass storage, automotive, industrial and networking
applications.
Secure applications including smart cards and SIMs.
With Useful Implemented peripherals, and a broad set of additional on board Peripherals
various applications are possible such as 10/100Mbps Ethernet, MMC/SD, ADC, DAC, RTC,
USB etc.,.
9
Result:
10
Program
#include <iolpc2378.h>
#include "irq.h"
#include "config.h"
void delay()
{
unsigned int i,j;
for(i=0;i<0x3fff;i++)
for(j=0;j<0xff;j++);
}
while(1)
{
FIO3PIN = 0X000000ff;
delay();
FIO3PIN = 0X00000000;
delay();
}
11
Exp.No: 2
EXPT:2
Date FLASHING OF LEDS
Aim
Components Required:
Theory
LED (Light Emitting Diodes) Light Emitting Diodes (LED) is the most commonly used
components, usually for displaying pins digital states. Typical uses of LEDs include alarm
devices, timers and confirmation of user input such as a mouse click or keystroke . Light
Emitting diodes are most commonly used components, usually for displaying Pin‘s Digital
state. The 8 nos of LED are connected to pin Q0-Q7.The 330 ohm resistor limit the current to
about 4 mA. A low output pin drives current through the LEDs and they will light. Each Led
can be individually enabled or disabled. The digital data sent by the microcontroller is latched
using 74LS273. This latch is selected via 74LS154 decoder.
12
13
PROCEDURE:
14
15
Steps To Be Followed In Flash Magic Software For Embed Into Kit:
Step 5: Directly go to step 5: Start click start for Embed (*.HEX) file to kit.
RESULT:
The C-Language program for interfacing LED and the flashing output was verified on
the LPC2378 development board.
16
Program: Interfacing of DAC with ARM
#include <iolpc2378.h>
#include "irq.h"
#include "config.h"
#include "dac.h"
//Main Function
unsigned int i;
TargetResetInit();
/* Initialize DAC */
DACInit();
while ( 1 )
{
DACR = (i << 6) | DAC_BIAS;
i++;
if ( i == 1024 )
{
i = 0;
}
}
return 0;
}
17
Exp.No: 3 INTERFACING OF ADC & DAC
Date :
Aim
Components Required:
Theory
MCP429x:
The Microchip Technology Inc. MCP492X is 2.7 – 5.5V, low-power, low DNL, 12-Bit
Digital-to-Analog Converters (DACs) with optional 2x buffered output and SPI interface. The
MCP492X are DACs that provide high accuracy and low noise performance for industrial
applications where calibration or compensation of signals is required
Interfacing SPI-DAC:
Fig.4 shows how to interface the SPI-DAC to microcontroller. With an SPI connection
there is always one master device (usually a microcontroller) which controls the peripheral
devices. Typically there are three lines common to all the devices,
Master In Slave Out (MISO) - The Slave line for sending data to the master,
Master Out Slave In (MOSI) - The Master line for sending data to the peripherals,
Serial Clock (SCK) - The clock pulses which synchronize data transmission generated by
the master.
Slave Select pin - the pin on each device that the master can use to enable and disable
specific devices.
18
OUTPUT:
Analog output in Winx talk Software:
19
Interfacing of ADC:
PROCEDURE:
20
Program: Interfacing of ADC with ARM
#include<NXP\iolpc2378.h>
#include "irq.h"
#include "config.h"
send_serial_data(t1000+0x30);
send_serial_data(t100 +0x30);
send_serial_data(t10+0x30);
send_serial_data(t1+0x30);
send_serial_data(0x0d);
send_serial_data(0x0a);
}
void main()
{
unsigned long int val;
unsigned int Fdiv;
TargetResetInit();
PCONP |= (1 << 12);
PINSEL1 = 0X00054000; //AD0.0 AS ANALALOG INPUT
PINSEL0 = 0x00000050; // RxD0 and TxD0
21
9. Right Click the project name option for select a ‗C‘ file in
workspace window. Select Add >Add (DAC.C) Menu.
10. Select LPC2378>Rebuild all menu, for checking any error in your ‗C‘ file. If your
‗C‗file has no error.
11. Select LPC2378>Rebuild all menu, for checking any error in your ‗C‘ file.
12. If your project has no error, Building completed and Hex file generated.
13. This Hex file will be downloaded to the VIARM-2378 controller by Flash Magic
Software
Step 5: Directly go to step 5: Start click start for Embed (*.HEX) file to kit.
22
// AD0CR = 0x01200601; // Start A/D Conversion
AD0CR = ( 0x01 << 1 ) | /* SEL=1,select channel 0~7 on ADC0 */
( ( Fpclk / ADC_CLK - 1 ) << 8 ) | /* CLKDIV = Fpclk / 1000000 - 1 */
( 1 << 16 ) | /* BURST = 0, no BURST, software controlled */
( 0 << 17 ) | /* CLKS = 0, 11 clocks/10 bits */
( 1 << 21 ) | /* PDN = 1, normal operation */
( 0 << 22 ) | /* TEST1:0 = 00 */
( 1 << 24 ) | /* START = 0 A/D conversion stops */
( 0 << 27 ); /* EDGE = 0 (CAP/MAT singal falling,trigger A/D
conversion) */
while(1)
{
while((AD0GDR & 0X80000000)!=0X80000000);
val = (AD0GDR>>6)& 0x3ff ; // convesion data holds AD0DR0[6]
to AD0DR0[15]
adc_serial_tx(val); // 10 bit adc data transmit serial
port.
}
}
23
RESULT:
The C-Language program for displaying the analog to digital output was verified on the
win x talk software. The C-Language program for displaying digital to analog output is verified
in the CRO.
24
Program: Interfacing of Keyboard with ARM
#include <iolpc2378.h>
#include "irq.h"
#include "config.h"
unsigned int k;
unsigned int Read_Key;
unsigned char scan [] = { 0x00000E00,0x00000D00,0x00000B00,0x00000700};
unsigned int i;
void delay()
{
unsigned int i,j;
for(i=0;i<0xff;i++)
for(j=0;j<0xff;j++);
}
while(1)
{
//First Row
FIO4SET = 0X00000e00;
Read_Key = FIO4PIN;
Read_Key = (Read_Key & 0xf000) >> 12 ;
if((Read_Key==0x07))
{
send_serial_data('0');
FIO3PIN = 0X00000000;
}
if((Read_Key==0x0b))
{
send_serial_data('1');
FIO3PIN = 0X00000001;
}
25
Exp.No: 4 INTERFACING OF KEYBOARD WITH ARM
Date :
Aim
Components Required:
Theory
A keypad is a set of buttons arranged in a block or "pad" which usually bear digits,
symbols and usually a complete set of alphabetical letters. If it mostly contains numbers then it
can also be called a numeric keypad. Here we are using 4 X 4 matrix keypad.
Interfacing keypad:
Fig. shows how to interface the 4 X 4 matrix keypad to two ports in microcontroller. The
rows are connected to an output port and the columns are connected to an input port. To detect a
pressed key, the microcontroller grounds all rows by providing 0 to the output latch, and then it
reads the columns. If the data read from the columns is D3-D0=1111, no key has been pressed
and the process continues until a key press is detected.
26
if( (Read_Key==0x0d))
{
send_serial_data('2');
FIO3PIN = 0X00000002;
}
if((Read_Key==0x0e))
{
send_serial_data('3');
FIO3PIN = 0X00000003;
}
FIO4CLR = 0X00000e00;
delay();
//Second Row
FIO4SET = 0X00000d00;
Read_Key = FIO4PIN;
Read_Key = (Read_Key & 0xf000) >> 12 ;
if((Read_Key==0x07))
{
send_serial_data('4');
FIO3PIN = 0X00000004;
}
if((Read_Key==0x0b))
{
send_serial_data('5');
FIO3PIN = 0X00000005;
}
if( (Read_Key==0x0d))
{
send_serial_data('6');
FIO3PIN = 0X00000006;
}
if( (Read_Key==0x0e))
{
send_serial_data('7');
FIO3PIN = 0X00000007;
}
FIO4CLR = 0X00000d00;
delay();
//Third Row
FIO4SET = 0X00000b00;
Read_Key = FIO4PIN;
Read_Key = (Read_Key & 0xf000) >> 12 ;
if((Read_Key==0x07))
{
send_serial_data('8');
FIO3PIN = 0X00000008;
}
if((Read_Key==0x0b))
{
send_serial_data('9');
FIO3PIN = 0X00000009;
}
27
However, if one of the column bits has a zero, this means that a key press has occurred.
For example, if D3-D0=1101, this means that a key in the D1 column has been pressed. After a
key press is detected, the microcontroller will go through the process of identifying the key.
Starting with the top row, the microcontroller grounds it by providing a low to row D0 only;
then it reads the columns.
If the data read is all 1s, no key in that row is activated and the process is moved to the
next row. It grounds the next row, reads the columns, and checks for any zero. This process
continues until the row is identified. After identification of the row in which the key has been
pressed, the next task is to find out which column the pressed key belongs to.
PROCEDURE:
28
if( (Read_Key==0x0d))
{
send_serial_data('a');
FIO3PIN = 0X0000000a;
}
if( (Read_Key==0x0e))
{
send_serial_data('b');
FIO3PIN = 0X0000000b;
}
FIO4CLR = 0X00000b00;
delay();
//Fourth Row
FIO4SET = 0X00000700;
Read_Key = FIO4PIN;
Read_Key = (Read_Key & 0xf000) >> 12 ;
if((Read_Key==0x07))
{
send_serial_data('c');
FIO3PIN = 0X0000000c;
}
if((Read_Key==0x0b))
{
send_serial_data('d');
FIO3PIN = 0X0000000d;
}
if((Read_Key==0x0d))
{
send_serial_data('e');
FIO3PIN = 0X0000000e;
}
if( (Read_Key==0x0e))
{
send_serial_data('f');
FIO3PIN = 0X0000000f;
}
FIO4CLR = 0X00000700;
delay();
// send_serial_data('c');
}
return 0;
}
29
Steps To Be Followed In Flash Magic Software For Embed Into Kit:
Step 5: Directly go to step 5: Start click start for Embed (*.HEX) file to kit
RESULT:
The C-Language program for displaying the Key pressed in the Keyboard is displayed in
the screen and the output was verified on the win x talk software.
30
Program: Interfacing of LCD with ARM
#include <iolpc2378.h>
#include<stdio.h>
31
Exp.No:5 INTERFACING OF LCD WITH ARM
Date :
Aim
Components Required:
Theory:
Liquid Crystal Display also called as LCD is very helpful in providing user interface as
well as for debugging purpose. A liquid crystal display (LCD) is a flat panel display that uses
the light modulating properties of liquid crystals (LCs). LCD Modules can present textual
information to user.
Interfacing LCD
Fig. shows how to interface the LCD to microcontroller. The 2x16 character LCD
interface card with supports both modes 4-bit and 8-bit interface, and also facility to adjust
contrast through trim pot. In 4-bit interface 7 lines needed to create 4-bit interface; 4 data bits
(D0 – D3), three control lines, address bit (RS), read/write bit (R/W) and control signal (E).
32
143,255,255,255,255,255,127, 15, 3,227,249,248,252,255,224,224,
224,230,230,230,230,230,230,230,230,231,231, 7, 7, 15,127,255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,239,225,224,248,254,255,255,255,255,255,255,255,
248,224,224,227,255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,127,127, 63, 31, 0, 0,128, 0,
15, 31, 63,127,127,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,252,224,193, 7, 15, 63,127,127,255,255,
255,255,255,255,255,255,255,127, 63, 31, 15,143,248,192, 0, 3,
31,159,159,143,207,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,252,252,254,254,255,255,255,255,
255,254,254,252,252,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,254,254,254,252,252,252,
249,249,249,249,248,248,252,252,252,254,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255
};
void busy_check()
{
IO0CLR = RS;
IO1CLR = DIOW;
}
33
PROCEDURE:
34
IO0SET = CS1 | CS2; // CS1 AND CS2(P1.23 and P1.24) are enabled.
FIO3PIN = G_lcd;
FIO3SET = LCD_EN; // E->SET.
FIO3CLR = LCD_EN; // E->CLR.
}
void pageclear()
{
int i,y;
IO0SET = CS1 | CS2 ; // CS1 AND CS2(P1.23 and P1.24) are
enabled.
for(i=0xb8;i<0xc0;i++)
{
writecmd(i); // Select Pages.
writecmd(0x40);
for (y=0;y<64;y++)
writedata(0x0); // Clear data in the LCD.
}
}
void clear_display()
{
pageclear();
}
void glcd_init()
{
writecmd(0x3e); // 0x3E turn it Off.
writecmd(0x3f); // 0x3F Display ON.
writecmd(0xc0); // displayed at the top of the screen. Here
it is line 0.
writecmd(0xb8); //
}
void main ()
{
int page,dat;
PINSEL0=0x00000000;
PINSEL1=0x00000000;
PINSEL3=0x00000000;
IO0DIR =0xFFFFFFFF;
IO1DIR =0xFFFFFFFF;
FIO3DIR =0xFFFFFFFF;
35
Steps To Be Followed In Flash Magic Software For Embed Into Kit:
Step 5: Directly go to step 5: Start click start for Embed (*.HEX) file to kit
RESULT:
The C-Language program for displaying the image is displayed in the screen and the
output was verified.
36
Program: Interfacing of EEPROM & Interrupt
#include<iolpc2378.h>
#include "irq.h"
#include "config.h"
int i,temp,Temp1;
int i2c0,i2c1,i2c2,l;
i=100000;
37
Exp.No: 6
Date : INTERFACING OF EEPROM & INTERUPT
Aim
To develop a C-Language program to write and read a data in EEPROM and also to
analyze its performance with the interrupt
Components Required:
Theory:
EEPROM
38
do
{
adc1000=val/i;
send_serial_data(adc1000+0x30);
val=val%i;
i=i/10;
}while(i!=0x00);
send_serial_data(' ');
send_serial_data('-');
send_serial_data('-');
send_serial_data('-');
send_serial_data('>');
}
//START CONDITION
I2C0CONSET=0x60; //0x60 change //start I2C data
transmission when set STA flag.
delay();
temp=I2C0STAT;
while(temp!=0x08)
temp=I2C0STAT;
//SLAVE ADDRESS
I2C0DAT=0xA6;
I2C0CONCLR=0x28;
temp=I2C0STAT;
delay();
while(temp!=0x18)
{
temp=I2C0STAT;
delay();
}
//HIGHER ORDER ADDRESS
I2C0DAT=0x00;
// I2C0DAT=0xff;
I2C0CONCLR=0x08;
temp=I2C0STAT;
while(temp!=0x28)
{
temp=I2C0STAT;//& 0x28;
delay();
}
delay1();
//LOWER ORDER ADDRESS
I2C0DAT=0x10;
I2C0CONCLR=0x08;
temp=I2C0STAT;
while(temp!=0x28)
{
temp=I2C0STAT;//& 0x28;
delay();
}
39
Interfacing I2C - EEPROM
Fig shows how to interface the EEPROM with microcontroller through I2C. I2C is a
Master-Slave protocol. I2C has a clock pulse along with the data. Normally, the master device
controls the clock line, SCL. This line dictates the timing of all transfers on the I2C bus. No data
will be transferred unless the clock is manipulated
. All slaves are controlled by the same clock, SCL. I2c bus supports many devices, each
device is recognized by a unique address—whether it‘s a micro-controller, LCD Driver,
memory or keyboard interface and can operate as transmitter or receiver based on the
functioning of the device. The controller designed controls the EEPROM device through I 2C
protocol. The I2C Controller here acts as a master device and controls EEPROM which acts as a
slave. The read-write operations are accomplished by sending a set of control signals including
the address and/or data bits. The control signals must be accompanied with proper clock signals.
PROCEDURE:
40
//EEPROM DATA
I2C0DAT=0xAA;
I2C0CONCLR=0x08;
temp=I2C0STAT;
while(temp!=0x28)
{
temp=I2C0STAT;//& 0x28;
delay();
}
//STOP CONDITION
I2C0CONSET=0x10;
I2C0CONCLR=0x8;
delay1();
}
void i2c_read()
{
//START CONDITION
I2C0CONSET=0x60; //start I2C data transmission
when set STA flag.
delay();
temp=I2C0STAT;
while(temp!=0x08)
temp=I2C0STAT;
//SLAVE ADDRESS
I2C0DAT=0xA6;
I2C0CONCLR=0x28;
temp=I2C0STAT;
delay();
while(temp!=0x18)
temp=I2C0STAT;
delay();
I2C0DAT=0x00;
I2C0CONCLR=0x8;
temp=I2C0STAT;
while(temp!=0x28)
temp=I2C0STAT;//& 0x28;
delay();
delay1();
//LOW ORDER ADDRESS
I2C0DAT=0x00;
I2C0CONCLR=0x08;
temp=I2C0STAT;
while(temp!=0x28)
temp=I2C0STAT;//& 0x28;
delay();
41
4. Select General options category. Enable target option file and select the device as NXP
LPC2378 and click ok.
5. Select C/C++ Compiler >Select Preprocessor and include (C:\Program Files\IAR
Systems\Embedded Workbench 6.5\arm\inc\c, C:\Program Files\IAR
Systems\Embedded Workbench 6.5\arm\inc\NXP)
6. Enable Output Converter Menu and select output format as Intel extended and Enable
Override default option
7. Select Linker Category. Enable Override default option, click SAVE Button.
8. New>File Menu, for creating a new ‗C ‗file. File>Save As, for saving a file. Give your
File name ( Eg: EEPROM.C) and click Save Button.
9. Right Click the project name option for select a ‗C‘ file in
workspace window. Select Add >Add (EEPROM.C) Menu.
10. Select LPC2378>Rebuild all menu, for checking any error in your ‗C‘ file. If your
‗C‗file has no error.
11. Select LPC2378>Rebuild all menu, for checking any error in your ‗C‘ file.
12. If your project has no error, Building completed and Hex file generated.
13. This Hex file will be downloaded to the VIARM-2378 controller by Flash Magic
Software
42
//STOP CONDITION
I2C0CONSET=0x10;
I2C0CONCLR=0x08;
delay();
I2C0CONSET=0x10;
I2C0CONCLR=0x08;
//RESTART CONDITION
temp=I2C0STAT;
while(temp!=0x08)
temp=I2C0STAT; //0x28 0x08
I2C0DAT=0xa7;
I2C0CONCLR=0x2C;
temp=I2C0STAT;
while(temp!=0x40)
temp=I2C0STAT ;
I2C0CONSET = 0X04;
I2C0CONCLR = 0X08;
//READ
while(1){
I2C0CONCLR=0x08;
temp=I2C0STAT;
while(temp!=0x50)
temp=I2C0STAT;
delay();
temp=I2C0DAT;
display_address(0x000 + l++);
display_data(temp);
//send_serial_data(Temp1+0x30);
I2C0CONCLR = 0X0C;
I2C0CONSET = 0X04;
I2C0CONCLR = 0X08;
}
43
Procedure to see OUTPUT:
1. Compile, Debug & Simulate the above code in IAR.
2. Connect the RS232 cable /USB cable provided to the PC / Laptop and the LPC2378
Development Board,
3. For seeing the output in real-time, select the PROG mode, reset the board and download
the code in VSK-2378 board using Flash Magic through UART0.
4. Now change the Mode-Selection-Switch to EXEC position and reset the board.
5. Open Win X – Talk and select the COM port and the Desired Baud rate as 9600.
6. The main function will execute continuously. The Timer Interrupt function will execute
for every 1 second.
44
//STOP CONDITION
I2C0CONSET=0x10;
I2C0CONCLR=0x8;
delay();
void main()
{
unsigned int Fdiv;
TargetResetInit();
PCONP |= (1 << 12);
PINSEL1 = 0X00004000; //AD0.0 AS ANALALOG INPUT
PINSEL0 = 0x00000050; // RxD0 and TxD0
U0LCR = 0x83; // 8 bits, no Parity, 1 Stop bit
Fdiv = ( Fpclk / 16 ) / 19200 ; //baud rate
U0DLM = Fdiv / 256;
U0DLL = Fdiv % 256;
U0LCR = 0x03; // DLAB = 0
U0FCR = 0x07; // Enable and reset TX and RX FIFO.
PLLCON=0x00;
PINSEL1=0x01400000; //SDA0,SCL0.
I2C0CONCLR=0x6C; //clear I2C0CONCLR register
I2C0CONSET=0x40; //Enable I2C.
I2C0SCLH=110;
I2C0SCLL=90;
i2c_write(0x00);
i2c_write(0x00);
i2c_write(0x00);
while(1){
i2c_read();
}
}
45
RESULT:
Thus C-Language program to write and read a data in EEPROM and also to analyzed its
performance with the interrupt
46
Program: Interfacing of RTC and Serial Port
#include<iolpc2378.h>
#include"..\header\all.h"
void delayv()
{
unsigned int i,j;
for(i=0;i<0xaff;i++)
for(j=0;j<0xff;j++);
}
//START CONDITION
I2C0CONSET=0x60; //start I2C data
transmission when set STA flag.
delay();
Temp=I2C0STAT;
while(Temp!=0x08)
Temp=I2C0STAT;
/SLAVE ADDRESS
I2C0DAT=0xA0;
I2C0CONCLR=0x28;
delay();
Temp=I2C0STAT;
while(Temp!=0x18)
{
Temp=I2C0STAT;
delay();
}
Aim
To develop a C-Language program to interface the real time clock with ARM controller
using serial port.
Components Required:
Theory:
The DS1307 Serial Real-Time Clock is a low-power; full binary-coded decimal (BCD)
clock/calendar plus 56 bytes of NV SRAM. Address and data are transferred serially via a 2-
wire, bi-directional bus. The clock/calendar provides seconds, minutes, hours, day, date, month,
and year information. The end of the month date is automatically adjusted for months with
fewer than 31 days, including corrections for leap year. The clock operates in either the 24-hour
or 12-hour format with AM/PM indicator.
Fig. shows how to interface the RTC with microcontroller through I2C. I2C is a Master-
Slave protocol. I2C has a clock pulse along with the data. The master device controls the clock
line, SCL. This line dictates the timing of all transfers on the I2C bus. No data will be
transferred unless the clock is manipulated. I2c bus supports many devices, each device is
recognized by a unique address—whether it‘s a micro-controller, LCD Driver, memory or
keyboard interface and can operate as transmitter or receiver based on the functioning of the
device.
48
delay();
}
delay();
I2C0DAT=data;
I2C0CONCLR=0x8;
Temp=I2C0STAT;
while(Temp!=0x28)
{
Temp=I2C0STAT;//& 0x28;
delay();
}
//STOP CONDITION
I2C0CONSET=0x10;
I2C0CONCLR=0x8;
delay();
I2C0CONSET=0x10;
I2C0CONCLR=0x8;
delay();
//START CONDITION
I2C0CONSET=0x60; //start I2C data
transmission when set STA flag.
delay();
Temp=I2C0STAT;
while(Temp!=0x08){
Temp=I2C0STAT;//&0x08;
//printf("\n\r Temp");
}
//SLAVE ADDRESS
I2C0DAT=0xA0;
I2C0CONCLR=0x28;
Temp=I2C0STAT;
delay();
while(Temp!=0x18){
Temp=I2C0STAT;//&0x18;
delay();
//printf("\n\r Temp1");
}
49
The controller designed controls the RTC ds1307 device through I2C protocol. The I2C
Controller here acts as a master device and controls RTC ds1307 which acts as a slave. The read
operation is accomplished by sending a set of control signals including the address and/or data
bits. The control signals must be accompanied with proper clock signals.
PROCEDURE:
50
//HIGHER ORDER ADDRESS
I2C0DAT=addr;
I2C0CONCLR=0x8;
Temp=I2C0STAT;
while(Temp!=0x28){
Temp=I2C0STAT;//& 0x28;
delay();
//STOP CONDITION
I2C0CONSET=0x10;
I2C0CONCLR=0x8;
delay();
//RESTART CONDITION
I2C0CONSET = 0X04;
I2C0CONCLR = 0X08;
//READ
//while(1){
for(int i=0;i<0x03;i++)
{
I2C0CONCLR=0x08;
51
7. Select Linker Category. Enable Override default option, click SAVE Button.
8. New>File Menu, for creating a new ‗C ‗file. File>Save As, for saving a file. Give your
File name ( Eg: RTC.C) and click Save Button.
9. Right Click the project name option for select a ‗C‘ file in
workspace window. Select Add >Add (RTC.C) Menu.
10. Select LPC2378>Rebuild all menu, for checking any error in your ‗C‘ file. If your
‗C‗file has no error.
11. Select LPC2378>Rebuild all menu, for checking any error in your ‗C‘ file.
12. If your project has no error, Building completed and Hex file generated.
13. This Hex file will be downloaded to the VIARM-2378 controller by Flash Magic
Software
52
Temp=I2C0STAT;
while(Temp!=0x50)
Temp=I2C0STAT;
delay();
rtc_data[i]=I2C0DAT;
//printf("\n\r Eeprom Data %x",Temp1);
I2C0CONCLR = 0X0C;
I2C0CONSET = 0X04;
I2C0CONCLR = 0X08;
}
//STOP CONDITION
I2C0CONSET=0x10;
I2C0CONCLR=0x8;
delay();
//return(rtc_dat);
}
void send(unsigned char Temp1,int v,int xx)
{
k=k+1;
i2c0=Temp1 & 0xf0;
i2c0=i2c0>>4;
i2c0=i2c0+0x30;
send_serial_data(i2c0);
display(0xbd,v,i2c0);
display1(0xbe,v,i2c0);
53
54
}
void add()
{
a1=(arr[1]-0x30);
a1=a1<<4;
a2=(arr[0]-0x30);
aa=a1+a2;
a3=(arr[3]-0x30);
a3=a3<<4;
a4=(arr[2]-0x30);
bb=a3+a4;
a5=(arr[5]-0x30);
a5=a5<<4;
a6=(arr[4]-0x30);
cc=a5+a6;
}
void rtc()
{
delayv();
delayv();
intlcd();
pageclear1();
for(page =0;page<8;page++)
{
writecmd(0xB8+page);
writecmd(0x40);
clock2(0x00008000,dat+64);
//write_house1(0x80000000,dat + 64);
}
// while(1);
/*
55
56
IO0SET = CS1; // PAGE 1 IS SELECGTED.
IO0CLR = CS2;
for(page =0;page<8;page++)
{
writecmd(0xB8+page);
writecmd(0x40);
clock2(0x00010000,dat + 64);
}
*/
clearpage();
// while(1);
PINSEL1|=0x01400000; //SDA0,SCL0.
read_key1();
add();
i2c_write(0x02,cc);
delay();
i2c_write(0x03,bb);
delay();
i2c_write(0x04,aa);
delay();
PINSEL0 |=0X00000000;
IO0DIR |=0X00000000;
while(1)
{
xx=0;xxs=0;
57
58
IO0SET = CS1;
IO0CLR = CS2 ;
i2c_read(0x02);
send(rtc_data[2],0x50,0x5c); //12
send_serial_data('\t');
send(rtc_data[1],0x74,0x40); //57
send_serial_data('\t');
send(rtc_data[0],0x58,0x64); //30
k=0;
send_serial_data(0x0d);
send_serial_data(0x0A);
if((IO0PIN&0x20000000)!=0x20000000)
break;
}
clear_display();
option_pic();
59
RESULT:
The C-Language program for interfacing the real time clock with serial port and the
output was verified using Win X talk software.
60
Program: Interfacing of Stepper motor in Forward direction
#include <iolpc2378.h>
#include "irq.h"
#include "config.h"
unsigned int k;
unsigned int dat[] = {0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
void delay()
{
unsigned int i,j;
for(i=0;i<0xff;i++)
for(j=0;j<0xff;j++);
}
/**************************************************************************
** Main Function main()
*************************************************************************/
int main (void)
{
TargetResetInit();
// FIO4PIN = 0X0;
// FIO4DIR = 0XFFFFFFFF;
IO0DIR = 0XFFFFFFFF;
while(1)
{
for(k=0;k<10;k++)
{
IO0SET = 0X00000240;
delay();
IO0CLR = 0X00000240;
IO0SET = 0X00000140;
delay();
IO0CLR = 0X00000140;
IO0SET = 0X00000180;
delay();
IO0CLR = 0X00000180;
IO0SET = 0X00000280;
delay();
IO0CLR = 0X00000280;
}
} }
61
Exp.No: 8
Date : INTERFACING OF STEPPER MOTOR (Forward Direction)
Aim
To develop a C-Language program to interface the stepper motor with ARM controller
and also to analyze its performance of rotation in forward direction.
Components Required:
Theory:
Stepper Motor:
A stepper motor is a brushless, synchronous electric motor that converts digital pulses
into mechanical shaft rotation. Every revolution of the stepper motor is divided into a discrete
number of steps, and the motor must be sent a separate pulse for each step.
62
63
Fig. shows how to interface the Stepper Motor to microcontroller. As you can see the
stepper motor is connected with Microcontroller output port pins through a ULN2803A array.
So when the microcontroller is giving pulses with particular frequency to ULN2803A, the
motor is rotated in clockwise or anticlockwise.
PROCEDURE:
64
65
Steps To Be Followed In Flash Magic Software For Embed Into Kit:
RESULT:
The C-Language program for interfacing the stepper motor and running in clockwise
direction output was verified
66
Program: Interfacing of Stepper motor in Reverse direction
#include <iolpc2378.h>
#include "irq.h"
#include "config.h"
unsigned int k;
unsigned int dat[] = {0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
void delay()
{
unsigned int i,j;
for(i=0;i<0xff;i++)
for(j=0;j<0xff;j++);
}
/*************************************************************************
** Main Function main()
*************************************************************************/
int main (void)
{
TargetResetInit();
// FIO4PIN = 0X0;
// FIO4DIR = 0XFFFFFFFF;
IO0DIR = 0XFFFFFFFF;
while(1)
{
for(k=0;k<10;k++)
{
IO0SET = 0X00000280;
delay();
IO0CLR = 0X00000280;
IO0SET = 0X00000180;
delay();
IO0CLR = 0X00000180;
IO0SET = 0X00000140;
delay();
IO0CLR = 0X00000140;
IO0SET = 0X00000240;
delay();
IO0CLR = 0X00000240;
}
} }
67
Exp.No: 9
Date : INTERFACING OF STEPPER MOTOR (Reverse Direction)
Aim
To develop a C-Language program to interface the stepper motor with ARM controller
and also to analyze its performance of rotation in forward direction.
Components Required:
Theory:
Stepper Motor:
A stepper motor is a brushless, synchronous electric motor that converts digital pulses
into mechanical shaft rotation. Every revolution of the stepper motor is divided into a discrete
number of steps, and the motor must be sent a separate pulse for each step.
68
69
Fig. shows how to interface the Stepper Motor to microcontroller. As you can see the
stepper motor is connected with Microcontroller output port pins through a ULN2803A array.
So when the microcontroller is giving pulses with particular frequency to ULN2803A, the
motor is rotated in clockwise or anticlockwise.
PROCEDURE:
70
71
Steps To Be Followed In Flash Magic Software For Embed Into Kit:
RESULT:
The C-Language program for interfacing the stepper motor and running in reverse
direction output was verified
72
Program: Interfacing of LED with Seven Segment Display
#include<iolpc2378.h>
#define DESIRED_BAUDRATE 19200
#define CRYSTAL_FREQUENCY_IN_HZ 12000000
#define PCLK CRYSTAL_FREQUENCY_IN_HZ
#define DIVISOR (PCLK/(16*DESIRED_BAUDRATE))
void start(void)
{
I2C0CONSET=0X20;
status=I2C0STAT;
while(status!=0x08)
{
status=I2C0STAT;
}
}
void device_init(char add)
{
I2C0DAT=add;
I2C0CONCLR=0x28;
status=I2C0STAT;
while(status!=0x18)
{
status=I2C0STAT;
}
}
void data_write(char dat)
{
I2C0DAT=dat;
I2C0CONCLR=0x08;
status=I2C0STAT;
while(status!=0x28)
status=I2C0STAT;
}
void stop(void)
{
I2C0CONSET=0x10;
I2C0CONCLR=0x08;
}
void delay()
{
for(int j=0x00;j<=0xff;j++)
for(int k=0x00;k<=0xff;k++);
}
void main()
{
PLLCON=0x00;
PINSEL1=0x01400000; //SDA0,SCL0.
73
Exp.No: 10
EXPT:2
Date INTERFACING OF LED WITH SEVEN SEGMENT DISPLAY
Aim
To develop a C-Language program to interface the LED with seven segment display in
ARM LPC2378 controller.
Components Required:
So by forward biasing the appropriate pins of the LED segments in a particular order,
some segments will be light and others will be dark allowing the desired character pattern of the
number to be generated on the display.
74
I2C0CONCLR=0x6C;
I2C0CONSET=0x40; //Enable I2C.
I2C0SCLH=110;
I2C0SCLL=90;
while(1)
{
for(int i=0;i<=9;i++)
{
start();
device_init(0x40);
data_write(decimal_data[i]);
stop();
delay();
}
}
}
75
Interfacing Seven Segment LED Display:
Fig. shows how to interface the seven segments with microcontroller. A seven segment
is generally available in ten pin package. While eight pins correspond to the eight LEDs, the
remaining two pins (at middle) are common and internally shorted. These segments come two
configurations, namely, Common cathode (CC) and Common anode (CA).
PROCEDURE:
RESULT:
The C-Language program for interfacing the seven segment LED display was verified on
the LPC2378 development board.
78