Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
1
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
EX NO: DATE:
AIM
To verify and validate the given applications using industry standard open source
ECLIPSE IDE.
LED blinking, RGB Pattern, Switch, UART and PLL
TOOLS REQUIRED:
1 Eclipse IDE
2 LM Flash Programmer
HARDWARE REQUIRED:
2
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
PROGRAM Switch
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/gpio.h"
#include "driverlib/sysctl.h"
int main(void)
{
SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_8MHZ);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
GPIOPinTypeGPIOOutput(GPIO_PORTC_BASE, GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7);
GPIOPinTypeGPIOInput(GPIO_PORTE_BASE,GPIO_PIN_0);
GPIOPinTypeGPIOInput(GPIO_PORTE_BASE,GPIO_PIN_1);
GPIOPadConfigSet(GPIO_PORTE_BASE, GPIO_PIN_0, GPIO_STRENGTH_2MA,
GPIO_PIN_TYPE_STD_WPU);
GPIOPadConfigSet(GPIO_PORTE_BASE, GPIO_PIN_1, GPIO_STRENGTH_2MA,
GPIO_PIN_TYPE_STD_WPU);
GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7,
GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7);
while(1)
{
if(GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_0)==GPIO_PIN_0)
{
GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_6, GPIO_PIN_6);
}
if(GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_1)==GPIO_PIN_1)
{
GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_5, GPIO_PIN_5);
}
if(GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_0)==0)
{
GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_6, 0);
}
if(GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_1)==0)
{
GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_5, 0);
}
}
}
3
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
4
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
PROGRAM UART
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/gpio.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
int main(void)
{
SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
UARTConfigSetExpClk(UART0_BASE,
8000000, 115200,(UART_CONFIG_ WLEN _8 |
UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
while(1)
{
if(UARTCharsAvail(UART0_BASE))
{
UARTCharPut(UART0_BASE,(unsigned char)(UARTCharGet(UART0_BASE)+1));
}}}
PROGRAM PLL
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/gpio.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
#include "driverlib/interrupt.h"
#include "utils/uartstdio.h"
void UartInit(void)
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
UARTStdioInit(0);
}
int main(void)
{
SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_8MHZ);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
GPIOPinTypeGPIOOutput(GPIO_PORTC_BASE, GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7);
GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7,
GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7);
UartInit();
while(1)
{
UARTprintf("Oscillator used= %4d\r", SysCtlClockGet());
GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7,
GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7);
SysCtlDelay(SysCtlClockGet() / 12);
GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7, 0);
SysCtlDelay(SysCtlClockGet() / 12);
}}
5
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
ALGORITHM PLL
PROCEDURE
Goto File -> New -> C Project. Enter the project name. Select project type -> empty
project and select tool chain -> ARM Windows GCC (Sourcery G++ lite). Click Next.
Select Debug and Release. Then, press Finish.
Go to File -> Import -> General -> File System. Press Next.
Browse and select the project from Softwares_Stellaris. Press Finish.
Or
Create the source files namely main.c, startup_gcc.c, main.ld and readme.text by clicking
FILE-> NEW-> SOURCE FILE.
Go to Project Properties. Under C\C++ build -> settings -> Tool Settings -> target
processor -> choose cortex M3.
ARM Sourcery Windows GCC C Compiler -> preprocessor -> add source -> type gcc
and give ok.
ARM Sourcery Windows GCC C Compiler -> Directories.
add source -> file system -> select C:\stellarisware.,
add source -> file system -> select C:\stellarisware\driverlib.
add source -> file system -> select C:\stellarisware\utils.
add source -> file system -> select C:\stellarisware\inc.
Setting up code optimization -> select function sections.
Including the linker. ARM Sourcery Windows GCC C Linker -> General. Browse
main.ld file and select do not use standard start files, do not use default libraries and
remove unused sections.
Add the libraries. ARM Sourcery Windows GCC C Linker ->Libraries.
add source -> file system -> select C:\stellarisware.
add source -> file system -> select C:\stellarisware\driverlib\gcc_ cm3.
In the Project Properties window, go to C/C++ General -> Paths and Symbols -> Source
Location -> Link Folder.
Include the driverlib and utils folder that contain the C source files.
In the Project Properties window, go to C/C++ Build -> Settings -> Build Steps -> Post
Build Steps Command and type the following.
6
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
Result:
Thus the above applications are verified and validated using open source eclipse IDE for
ARM Cortex M3 LM3s608 Microcontroller.
7
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
a) BUZZER
P0.7 Buzzer
b) LED
1 P0.15 LED 8
2 P0.16 LED 7
3 P0.17 LED 6
4 P0.18 LED 5
5 P0.19 LED 4
6 P0.20 LED 3
7 P0.21 LE0 2
8 P0.22 LED 1
c) RELAY
Port Pin No Description
P1.26 Relay
d) 7 SEGMENT
1 P1.16 A
2 P1.17 B
3 P1.18 C
4 P1.19 D
5 P1.20 E
6 P1.21 F
7 P1.22 G
8 P1.23 . (dp)H
9 P0.28 S1
10 P1.24 S2
11 P0.25 S3
12 P0.11 S4
8
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
EXNO: DATE:
TOOLS REQUIRED:
1 Triton IDE
HARDWARE REQUIRED:
2 DC source (0-12)V 1
ALGORITHM:
a) BUZZER
9
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
a) BUZZER
#include<LPC21xx.h>
#include<board.h>
void delay();
void main()
{
*IODIR0=0X00000080;
while (1)
{
*IOSET0 = 0X00000080; delay(); *IOCLR0= 0X00000080; delay();
}}
void delay()
{
int i,j;
for(i=1;i<15000;i++);
}
b) LED PROGRAM
#include<LPC21xx.h>
#include<BOARD.H>
void delay();
void main()
{
*IODIR0=0x007F8000;
while(1)
{
*IOSET0=0x007F8000; delay(); *IOCLR0=0x007F8000; delay();
} }
void delay()
{
unsigned int i,j;
for (i=1;i<150000;i++); }
C)RELAY PROGRAM
#include<LPC21xx.H>
#include<BOARD.H>
void delay();
void main()
{
*IODIR1=0x04000000;
while(1)
{
*IOSET1=0x04000000; delay(); *IOCLR1=0x04000000; delay();
}
}
void delay()
{
int i,j;
for(i=1;i<15000;i++);
for(j=0;j<15000;j++);
}
10
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
b)LED
c) RELAY
11
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
d) 7 SEGMENT PROGRAM
#include<lpc21xx.h>
#include<BOARD.H>
void delay()
{
int i;
for(i=0;i<=200000;i++);
}
main()
{
*IOSET0 = 0x12000800; //select Seven Segment S1 ,S3,S4
//*IOSET1 = 0X01000000; //Select Seven Segment S2
*IODIR1=0X00FF0000;
while(1)
{
*IOSET1=0X003F0000; delay(); *IOCLR1=0X003F0000; delay();
*IOSET1=0X00060000; delay(); *IOCLR1=0X00060000; delay()
*IOSET1=0X005B0000; delay(); *IOCLR1=0X005B0000; delay();
*IOSET1=0X004F0000; delay(); *IOSET1=0X004F0000; delay();
*IOSET1=0X00660000; delay(); *IOCLR1=0X00660000; delay();
*IOSET1=0X006D0000; delay(); *IOCLR1=0X006D0000; delay();
*IOSET1=0X003C0000; delay(); *IOCLR1=0X003C0000; delay();
*IOSET1=0X00070000; delay(); *IOCLR1=0X00070000; delay();
*IOSET1=0X007F0000; delay(); *IOCLR1=0X007F0000; delay();
*IOSET1=0X00670000; delay(); *IOCLR1=0X00670000; delay();
*IOSET1=0X00770000; delay(); *IOCLR1=0X00770000; delay();
*IOSET1=0X007F0000; delay(); *IOCLR1=0X007F0000; delay();
*IOSET1=0X00390000; delay(); *IOCLR1=0X00390000; delay();
*IOSET1=0X003F0000; delay(); *IOCLR1=0X003F0000; delay();
*IOSET1=0X00790000; delay(); *IOCLR1=0X00790000; delay();
*IOSET1=0X00710000; delay(); *IOCLR1=0X00710000; delay();
}}
e) LCD interfacing
Include the header file <LPC21XX.H>. & <BOADR.H>.
Configure the Input Output Direction One register (IODIR 1) for selecting output port
operation of Port1 pins (P1.16 P1.23) to send the datas (D0-D7)
Configure the Input Output Direction Zero register (IODIR 0) for selecting output port
operation of Port0 pins (P0.28 P0.29) to select the Register bank Selection(RS) & Enable
signal to the LCD
Send the command words to the LCD through Input Output Set One register (IOSET1) and
give the appropriate control signals through IOSET0 Register
Call the delay program , while giving high to low enable signal
Send the data words to the LCD through Input Output Set One register (IOSET1) and give
the appropriate control signals through IOSET0 Register
12
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
f) UART PROGRAMMING
UART Transmitter
Include the <LPC214X.h> & <BOADR.H>.header file.
Configure the Port0 pin for UART0 TXD and RXD function for transmitting and receiving
the data.
Load the value 83 on the UART Zero Line Control Register (U0LCR) to frame the
message format.
Load the Device Latch LSB register (DLL) & Device Latch MSB register (DLM) register
to select the baud rate.
Load the value 0x03 on the UART Zero Line Control Register (U0LCR) to latch the baud
rate selection values.
load the data in to Transmit Holding Register (U0THR) for data transmission
UART Receiver
Include the <LPC214X.h> & <BOADR.H>.header file.
Configure the Port0 pin for UART0 TXD and RXD function for transmitting and receiving
the data. Load the value 83 on the UART Zero Line Control Register (U0LCR) to frame
the message format.
Load the Device Latch LSB register (DLL) & Device Latch MSB register (DLM) register
to select the baud rate. Load the value 0x03 on the UART Zero Line Control Register
(U0LCR) to latch the baud rate selection values.
Copy the received data from Receiver Buffer Register (U0RBR).
ADC INTERFACE
Include the < LPC214x.H> & <BOADR.H>.header file.
Load the value in ADCR (ADC control register) for the given specifications
[7:0] selection pin is used to select the ADC channel 1.
[15:8]select the clock divider value as 3
[16] Repeated data conversion
[19:17] select 000 for 11 clock 10 bits.
[21] Set to 1 to Analog to Digital converter is in operation mode .
[23:22] pin are used for device testing.
[24] Set to 1 to start the conversion (SOC).
[27] Set to 0 to indicate start of conversion on a falling edge.
Check the ADDR (ADC data register) [31] pin for End of conversion, when this register is
read and when the ADCR is return. If the ADCR is return, while a conversion still is
progress. This bit is set and a new conversion is started.
g) ADC Programming
#include<LPC21XX.H>
#include<BOARD.H>
int main()
{
unsigned int adcdata;
*PINSEL1= *PINSEL1 & 0XFCFFFFFF;
*PINSEL1= *PINSEL1 | 0X01000000;
*ADCR=0X01210302;
while(1)
{
if(*ADDR & 0X80000000)
{
adcdata=(*ADDR & 0X0000FFC0);
adcdata=adcdata>>6;
q_printf("%x\n",adcdata); }}}
13
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
e) LCD interfacing
#include<lpc21xx.h>
#include<BOARD.H>
void command(unsigned int comm);
void lcdout(unsigned int data);
void delay_lcd(void);
#define RS 0X20000000;
#define DIOW 0x10000000;
int main(void)
{
*IODIR1=0X00FF0000;
*IODIR0=0X30000000;
command(0x38); command(0x0c); command(0x01);
14
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
f) UART Transmitter
#include<LPC21xx.h>
#include<board.h>
int main(void)
{
char a[ ]="ECE";
int i;
*PINSEL0=0x01; /* Programming 0.0th Pin - Transmit data Pin */
*U0LCR=0x83; /* 8 -> Device lab = 1 , 3 -> 8 bit transmission*/
*U0DLM=0x00; /* Device latch MSB = 0 */
*U0DLL=0x18; /* Sets Baud rate */
*U0LCR=0x03;
while(1)
{
while(!(*U0LSR & 0x20));
for(i=0;a[i]!='\0';i++)
*U0THR= a[i]; }
return 0; }
Receiver
#include<LPC21xx.h>
#include<board.h>
void delay(void)
{
int j; for (j=0;j<50000;j++);
}
int main(void) {
unsigned int ALL;
*IODIR0=0x007f8000;
*PINSEL0 = 0x05; /* Programming 0.0th Pin - Transmit data Pin */
*U0LCR=0x83; /* 8 -> Device lab = 1 , 3 -> 8 bit transmission*/
/* Device latch MSB = 0 */
*U0DLL=0x61; /* Sets Baud rate */
*U0LCR=0x03;
while(1)
{
while (!(*U0LSR&0x01));
{
ALL=*U0RBR;
*IOSET0=ALL<<15;
delay();
*IOCLR0=ALL<<15;
delay();
}}}
RESULT
Thus the C language program was written and ported it on the ARM 7 core for the
following interfacing
Buzzer, LED, Relay, 7-segments LED, 2x16 LCD, ADC, and UART.
15
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
STATE DIAGRAM
RESET=1
S0
S1
S2
S3
S4
S5
S6
6
S7
RTL DIAGRAM
16
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
EXNO: DATE:
HARDWARE REQUIRED:
1 FPGA Device
spartan3 architecture,
xc3s400 device
pq208 package
-4 speed grade
THEORY
Finite-state machines can model a large number of problems, among which are electronic design
automation, communication protocol design, parsing and other engineering applications. In
biology and artificial intelligence research, state machines or hierarchies of state machines are
sometimes used to describe neurological systems
17
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
18
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
count=0;
end
`STATE6:begin
next_cnt=`STATE7;
count=0;
end
`STATE7:begin
next_cnt=`STATE0;
count=0;
end
default:next_cnt=`STATE0;
endcase
end
end
end
endmodule
RESULT:
Thus the FSM chart based 3 bit counter was verified and implemented successfully.
19
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
111 1 10 100 1
111 110 1
LFSR CODING
modulePPG(clk,reset,sin,sout);
inputclk;
input reset;
input [2:0]sin;
output[6:0] sout;
reg [2:0]a;
reg [2:0]b;
reg [2:0]c;
reg [2:0]d;
reg[6:0]temp;
always@(posedgeclk)
begin
if(reset)
temp=0;else
a[2:0]<=sin[2:0];
temp[0]=a[2]^a[0];
temp[1]=a[1]^a[0];
b[2]<=temp[0];
b[1]<=temp[1];
b[0]<=a[0];
temp[2]=b[2]^b[0];
temp[3]=b[1]^b[0];
c[0]<=b[0];
c[1]<=temp[3];
c[2]<=temp[2];
temp[4]=c[2]^c[0];
temp[5]=c[1]^c[0];
d[2]<=temp[4];
d[1]<=temp[5];
d[0]<=c[0];
temp[6]=d[2]^d[0];end
assign s out=temp;
endmodule
20
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
EXNO: DATE:
AIM
To implement multiple output parallel LFSR using Xilinx FPGA and verify the mono
alphabetic encryption & decryption algorithm using ARM 7 LPC 2148 microcontroller
TOOLS REQUIRED
1 Triton IDE
HARDWARE REQUIRED
2 FPGA Device 1
spartan3 Architecture,
xc3s400 Device number
pq208 Package
-4 Speed grade
3 DC Source (0-12)v 1
THEORY
A LFSR is a shift-register where the output bit is an XOR function of some input bits. The
initial value of the LFSR is called the seed. The outputs that influence the inputs are called taps. A
LFSR is represented as a polynomial mod 2. The coefficients of the polynomial are either 1s or 0s.
For example, if the taps are at the 1st, 3rd bits, the polynomial is x3+ x+1. The structure shown is
n
called a serial architecture. If a polynomial is primitive, the corresponding LFSR can produce 2 -1
distinct patterns.
21
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
RESET
MULTIPLE OUTPUT PARALLEL LFSR LOGIC DESIGN
CLOCK
Xilinx FPGA XC3S400
SIN [2:0]
SOUT [6:0]
LPC2148
BUFFER
BIT SHIFTER
MASKING UNIT
ENCRYPTING UART
MESSAGE
ALGORITHM TRANSMITTER TXD
22
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
PARALLEL LFSR
The parallel architecture of an LFSR reduces dynamic power consumption and can
generate more than one bit output per clock cycle. Here only one flip-flop is updated every clock
cycle and instead of the bits moving from left to right in each clock cycle, the taps of the XOR
tree move from right to left
The parallel architecture considers x3+ x+1 polynomial for obtaining multiple outputs in a
single clock cycle. The control signal Ti (i = 1, 2 ... N), which is used to connect the shift register
to the output tap, is a sequentially occurring waveform. The control signal is high for only i mod
N clock cycle, where N is the length of the LFSR The operations (1, 2) and (3, 1) are performed at
T1, where (x, y) denotes XOR operation of x and y. These values are stored in flip-flop 2 and flip-
flop 3 respectively. The overall operations can be summarized as shown in Table I. With the
multiple output architecture, a polynomial, of the form 1+xk1+xk2+xk3++xN7 can generate
outputs in a single clock cycle. In the case of x3+ x+1, 2 outputs can be obtained in a single clock
PRIMITIVE POLYNOMIAL
1 A polynomial over a unique factorization domain (such as the integers) whose greatest
common divisor of its coefficients is one.
2 The minimal polynomial of a primitive element of the extension field GF (pm).
MAXIMUM LENGTH SEQUENCE PROPERTIES:
When the PN sequence generated by linear feed back shift register has the length of 2 r-1, it is
called as maximum length sequence.
2 The length of the PN sequence generated by a primitive polynomial should be 2r-1. If the output
sequence satisfies this property, the polynomial is called as primitive. So the most secured
communication is achieved.
3. The number of ones is always one more than the number of zeros in each period of the
maximum length sequence whereas in truly randomsequence ones and zeros are equally
probable.Maximal length sequence:Tc , Tb=NTc
0 0 1 1 0 1 1
23
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
RESET
MULTIPLE OUTPUT PARALLEL LFSR LOGIC DESIGN
CLOCK
Xilinx FPGA XC3S400
SIN [2:0]
SOUT [6:0]
LPC2148
BUFFER
BIT SHIFTER
MASKING UNIT
UART
DECRYPTION
RXD RECEIVER MESSAGE
ALGORITHM
TO LEDS
24
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
RUN PROPERTY:
The m n means the sub sequence of identical symbols 1s or 0s.With in one period of the
sequence. The length of the run is equal to the length of the subsequence. When the maximum
length sequence is generated by linear feed back shift register of lengthr, total number of turns is
2r-1.In each period ofthe maximum length sequence there are one half runs of ones and zeros
having length 1.There can be one fourth runs of ones and zeros having length 2 or there can be
one eighth runs of ones and zeros having length 3 and so on.
CRYPTO SYSTEM
Key generation
Nonces
Salts in certain signature schemes, including ECDSA, RSASSA-PSS.
One-time pads
The "quality" of the randomness required for these applications varies. For the generation of a
nonce, only uniqueness might be required. For the generation of a master key, a higher quality is
needed. And in the case of one-time pads, the information-theoretic guarantee of unbreakable
cryptography only holds if the random stream is obtained from a true random source.
CRYPTOSYSTEM TRANSMITTER
Most stream ciphers work by generating a pseudorandom stream of bits that are XORed
with the message; this stream can often be used as a good CSPRNG Here the PN sequence is
masked to generate the secured key then the message (01000100=0x41) is added with the masked
key sequence (00000011=0x03). So we can get the encrypted bits of (01000100=0x44). This
encrypted data is transmitted through UART module of LPC 2148 microcontroller.
The receiver also performs the same XOR operation but here the encrypted received data
(01000100=0x44) called cipher text is subtracted with the masked key value (00000011=0x03).
Hence we can get the original message signal (01000100=0x41) which is nothing but the original
plain text.
25
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
ENCRYPTION ALGORITHM
#include<lpc21xx.h>
#include<BOARD.h>
void delay()
{unsigned int i;
for(i=0;i<=20000;i++);
}
int main(void)
{
unsigned int j,k,rt,t;
*IODIR0=0x007f8000;
*PINSEL0=0x01;/*programming0.0th pin- transmit data pin*/
*U0LCR=0x83;/*8->Device lab=1,3->8 bit transmission*/
*U0DLM=0x00;/*Device latch MSB=0*/
*U0DLL=0x18;/*Set baud rate*/
*U0LCR=0x03;
while (1)
{
j=*IOPIN0;
k=((j& 0x000003fc)>>2);
//delay();
rt=(k&0x0000000f);
while(!(*U0LSR&0x20));
//for(i=0;a[i]!=\0;i++)
{
t=(0x41+rt);
*U0THR=t;
*IOSET0=t<<15;
delay();
delay();
*IOCLR0=t<<15;
}}
return 0; }
26
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
DECRYPTION ALGORITHM
28
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
EXNO: DATE:
SPEED CONTROL OF STEPPER MOTOR
AIM
To develop an application to control the Stepper motor speed using LPC 2148
microcontroller.
TOOLS REQUIRED:
1 Triton IDE
HARDWARE REQUIRED:
2 DC source (0-12)V 1
ALGORITHM:
for(i=0;i<=20000;i++);
}
int sendchar0(int ch)
{
while(!(*U0LSR&0x20));
return(*U0THR=ch);
}
int main()
{
unsigned int l;
//*VICVectCntl0=0x20 |6;
*PINSEL0=0x00000005;
*U0LCR=0x83; /* 8 -> Device lab = 1 , 3 -> 8 bit transmission*/
*U0DLM=0x00; /* Device latch MSB = 0 */
*U0DLL=0x18; /* Sets Baud rate */
*U0LCR=0x03;
//*U0IER=0X02;
*PINSEL2= *PINSEL2 & 0xFFFFFFF3;
*IODIR1 = 0X01fF0000;
*IODIR0=0x007f83fc;
*IOCLR0=0x007f8000;
{
while(1)
{
*IOCLR0=0x00000DFF;
*IOSET0=0x00000200;
30
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
*IOSET0=0x0000A000;
delay();delay();
*IOCLR0=0x0000A000;
*IOSET0=0x00009000;
delay();delay();
*IOCLR0=0x00009000;
*IOSET0=0x00005000;
delay();delay();
*IOCLR0=0x00005000;
*IOCLR1 = 0Xff0000;
}
else if((*IOPIN0&0x0000003C)==0x00000010)
{
sendchar0('4');
*IOSET1 = 0x660000; //Display 4
*IOSET0=0x00006000;
delay();delay();delay();
*IOCLR0=0x00006000;
*IOSET0=0x0000A000;
delay();delay();delay();
*IOCLR0=0x0000A000;
*IOSET0=0x00009000;
delay();delay();delay();
*IOCLR0=0x00009000;
*IOSET0=0x00005000;
delay();delay();delay();
*IOCLR0=0x00005000;
*IOCLR1 = 0Xff0000;
}
else if((*IOPIN0&0x0000003C)==0x00000020)
{
sendchar0('0');
*IOSET1 = 0x3F0000; //Display 0
*IOSET0=0x00006000;
delay();delay();delay();delay();
*IOCLR0=0x00006000;
*IOSET0=0x0000A000;
delay();delay();delay();delay();
*IOCLR0=0x0000A000;
*IOSET0=0x00009000;
delay();delay();delay();delay();
*IOCLR0=0x00009000;
*IOSET0=0x00005000;
delay();delay();delay();delay();
*IOCLR0=0x00005000;
*IOCLR1 = 0Xff0000;
}
*IOCLR0=0x00000EFF;
*IOSET0=0x00000100;
if((*IOPIN0&0x0000003C)==0x00000004)
{
31
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
sendchar0('D');
*IOSET1 = 0x5E0000;
delay1(); //Display D
*IOCLR0=0x0ff0000;
}
else if((*IOPIN0&0x0000003C)==0x00000008)
{
sendchar0('9');
*IOSET1 = 0x6f0000; //Display 9
delay1();
*IOCLR1 = 0Xff0000;
}
else if((*IOPIN0&0x0000003C)==0x00000010)
{
sendchar0('5');
*IOSET1 = 0x6d0000; //Display 5
delay1();
*IOCLR1 = 0Xff0000;
}
else if((*IOPIN0&0x0000003C)==0x00000020)
{
sendchar0('1');
*IOSET1 = 0x060000; //Display 1
delay1();
*IOCLR1 = 0Xff0000;
}
*IOCLR0=0x00000F7F;
*IOSET0=0x00000080;
if((*IOPIN0& 0x0000003C)==0x00000004)
{
sendchar0('E');
*IOSET1 = 0x790000; //Display E
delay1();
*IOCLR1 = 0xff0000;
}
else if((*IOPIN0&0x0000003C)==0x00000008)
{
sendchar0('A');
*IOSET1 = 0x770000; //Display A
delay();
*IOCLR1 = 0xff0000; }
else if((*IOPIN0&0x0000003C)==0x00000010)
{ sendchar0('6');
*IOSET1 = 0x7d0000; //Display 6
delay();
*IOCLR1 = 0Xff0000;
}
else if((*IOPIN0&0x0000003C)==0x00000020)
{
sendchar0('2');
*IOSET1 = 0x5b0000; //Display 2
32
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
delay();
*IOCLR1 = 0Xff0000;
}
*IOCLR0=0x00800FBF;
*IOSET0=0x00000040;
if((*IOPIN0&0x0000003C)==0x00000004)
{
sendchar0('F');
*IOSET1 = 0x710000; //Display F
delay();
*IOCLR1 = 0xff0000;
}
else if((*IOPIN0&0x0000003C) == 0x00000008)
{
sendchar0('B');
*IOSET1 = 0x7c0000; //Display B
delay();
*IOCLR1 = 0xff0000;
}
else if((*IOPIN0&0x0000003C)==0x00000010)
{
sendchar0('7');
*IOSET1 = 0x070000; //Display 7
delay();
*IOCLR1 = 0Xff0000;
}
else if((*IOPIN0&0x0000003C)==0x00000020)
{
sendchar0('3');
*IOSET1 = 0x4f0000;
delay();
*IOCLR1 = 0Xff0000;
}}}}
RESULT
Thus the Stepper motor speed was controlled by using ARM 7 - LPC 2148 RISC
microcontroller.
33
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
SWITCH INTERFACING
#include<LPC21xx.H>
int main()
{
IODIR1=0X00FF0000;
while(1)
{
IOCLR1=0x00FF0000;
IOSET1= ((IOPIN0&0X0000FF00)<<0X08);
} }
STEPPER MOTOR INTERFACING:
#include<LPC21xx.H>
void delay()
{
unsigned int i;
for(i=0;i<=10000;i++);
}
int main()
{
IODIR0=0X000000FF;
for(;;)
{
IOSET0=0X00000051; delay(); IOCLR0=0x00000051;
IOSET0= 0x00000062; delay(); IOCLR0=0x00000062;
IOSET0= 0x00000094; delay(); IOCLR0=0x00000094;
IOSET0= 0x000000A8; delay(); IOCLR0=0x000000A8;
} }
34
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
APPENDIX A
EX NO: DATE:
VERIFICATION AND VALIDATION USING Keil IDE
AIM
To verify and validate the given applications using industry standard Integrated Development
Environment Keil vision ARM-MDK.
Rolling LED Display, Stepper motor, Switch interfacing.
TOOLS REQUIRED:
ALGORITHM:
STEPPER MOTOR INTERFACING:
SWITCH INTERFACING
Include the < LPC214X.H> header file
Configure the Port 0 pins (P0.16 to P0.23) as GPI0 using Pin Selection one Register (PINSEL1).
Configure the Input Output Direction zero register (IODIR 0) for selecting input and output
operation of Port0 pins (P0.16 to P0.23) as per hardware pins schematic.
Based on the IO interfacing, make the corresponding port pins to active high through Input Output
Set zero Register (IOSET0) register.
Call the delay program
To reset the output port pin, make corresponding port pin to active high through Input Output Clear
Zero Register ( IOCLR0)
PROCEDURE:
35
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
LED DISPLAY
#include<LPC21xx.H>
void delay()
{
unsigned int i;
for(i=0;i<=10000;i++);
}
int main()
{
IODIR0=0X000000FF;
for(;;)
{
IOSET0=0X000000FF; delay();
IOCLR0=0x000000FF;
} }
36
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
RESULT:
Thus the switch, stepper motor interfacing programs were verified and validated successfully.
37
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
APPENDIX B
MULTITASKING PROGRAM
#include <LPC21xx.H> /* LPC21xx definitions */
#include <ucos.h>
#include <board.h>
#define TASK_STK_SIZE 100 /* Size of each task's stacks (# of WORDs) */
#define NO_TASKS 3 /* Number of identical tasks */
char TaskData[NO_TASKS];
OS_STK TaskStk[NO_TASKS][TASK_STK_SIZE]; /* Tasks stacks */
OS_STK TaskStartStk[TASK_STK_SIZE];
extern void init_timer (void);
void Task2 (void *data)
{
int n, i;
data = data; // avoid compiler warning
while(1)
{
for (n = 0x00080000; n <= 0x04000000; n <<= 1)
{
*IOSET0 = n; /* Blink LED 5, 6 ,7 ,8*/ /* Turn on LED */
OSTimeDly(10); /* Wait one second */
*IOCLR0 = n; /* Turn off LEDs */
OSTimeDly(10); /* Wait one second */
i++;
q_printf("LoPrio "); } } }
void Task1 (void *data)
{ int n, i;
data = data; // avoid compiler warning
while(1)
{
for (n = 0x00008000; n <= 0x00040000; n <<= 1)
{
*IOSET0 = n; /* Blink LED 1,2, 3, 4 */
q_printf("Task1 LEDON ");
OSTimeDly(10); /* Wait one second */
q_printf("Task1 LEDOFF ");
*IOCLR0 = n; /* Turn off LEDs */
OSTimeDly(10); /* Wait one second */
q_printf("%s", "HiPrioTsk ");
i++;
} } }
void startTask(void *data)
{
init_timer();
TaskCreate(Task1, (void *)&TaskData[0], "HiPrioTsk", 1);
TaskCreate(Task2, (void *)&TaskData[1], "LoPrioTsk", 2);
while (1)
{ OSTimeDly(1000); }}
int main (void)
{
*IODIR0 = 0x007F8000;
OSInit(); /* Initialize uC/OS-II */
init_timer();
TaskCreate(startTask, (void *)0, "VHiPrioTsk", 0);
OSStart(); /* Start multitasking */
return 0; // Actually we should never come here }
38
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
EX NO: DATE:
TOOLS REQUIRED:
1 Triton IDE
HARDWARE REQUIRED:
2 DC source (0-12)V 1
ALGORITHM
MULTITASKING
Include the header file LPC21xx.h , Board.h and ucos.h
Define the Stack size and number of tasks
Initialize the Task Stack size and number of task
Call the Timer function initialization
With in the main function, initialize the C-OS-II kernel
Call the Timer function initialization
Crate the Start Up Task
To start the multitasking call the function OSStart.
Terminate the main program
With in the startup creation, initialize the timer function call and create the remaining tasks named
as task1 and task1
Give the time delay for the task
With in the task 1 and task 2 write the LED control operation code with time delay
39
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
40
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
RESULT:
Thus the multitasking and message queue programs were verified and validated successfully.
41
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
APPENDIX C
2) Enter the new project name and configure the remaining settings
42
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
3) Select debug, Release , Show all project types and show all configurations then give Next
4) This will open a new Project workspace. There you open the C file and type program. In case of
RTOS, select the OS as MCOS-II
43
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
5) Right Click on the project folder to Select the Build mode in Active build configurations, Build and
Rebuild operations
44
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
1) After performing the above operation hex file will be created under the release folder. To download
the hex file , open Release folder and right click on the hex file then select download .
Make sure that, controller kit must be in ISP mode for programming
45
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
APPENDIX D:
Selected Function
Binary Value
00 First alternate function Primary (default) function (always GPIO)
01 Second Alternate function
10 Third Alternate function
11fourth alternate function
PINSEL0 Register Lower order two bytes
46
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
PINSEL2 Register
47
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
48
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
Clock frequency / (16 * baud rate) = decimal Hex DLM & DLL
49
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
user software should not write ones to reserved bits. The value read
31:28 from a NA
Reserved,
- reserved bit is not defined.
50
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
APPENDIX E
Step 2: Select Debug and Release as shown in Figure. Then, press Finish.
51
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
Step 4: Press Next. Browse and select the project from Softwares_Stellaris . Press Finish.
Or
Create the source files namely main.c, startup_gcc.c, main.ld and readme.text by clicking
FILE-> NEW-> SOURCE FILE.
52
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
Step 5: Go to Project Properties. Under C\C++ build -> settings -> Tool Settings -> target
processor -> choose cortex M3.
Step 6: ARM Sourcery Windows GCC C Compiler -> preprocessor -> add source -> type
gcc and give ok.
53
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
Step 7: Go to Project Properties. Under Settings -> Tool Settings -> ARM Sourcery
Windows GCC C Compiler -> Directories.
54
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
Step 10: Including the linker. In the Project Properties window, go to Tool Setting -> ARM
Sourcery Windows GCC C Linker -> General.
55
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
Step 11: Add the libraries. In the Project Properties window go to Tool Setting -> ARM
Sourcery Windows GCC C Linker ->Libraries.
56
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
Step 12: In the Project Properties window, go to C/C++ General -> Paths and Symbols ->
Source Location -> Link Folder.
Step 13: Include the driverlib and utils folder, which contain the C source files.
57
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
Step 14 : In the Project Properties window, go to C/C++! Build -> Settings ->
Build Steps -> Post Build Steps Command and type the following.
58
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
Step 15: Right click on the project opened in the workspace, go to Build Configurations and
build and clean the project.
Step 16: Go to Run -> External Tools -> External Tools Configuration
59
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
Step 17: In the window, set the location to LMFlash.exe located under C:/Program
Files/Texas Instruments/ and click run.
Step 18: After clicking Run, a window similar to below should display on the screen. In the
configuration tab, choose the COM port depending on the port the device is attached to.
60
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
Step 19: Go to the Program tab, and select the .bin file by browsing to your project in the
Eclipse workspace folder. Make sure the address offset is 0800.
Step 20: Clicking on Program starts transferring the application binary file to the Stellaris
Guru board.
61
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
Circuit Diagram:
Fig. switch
Fig. LED
62
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
VIVA QUESTIONS
2) What are the advantages of open source product over licensed product?
Low cost and no license fees.
Open standards that facilitate integration with other Systems.
It is easily customizable.
63
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
In debug mode, many of the compiler optimizations are turned off which allow the
generated executable match up with the code. This allows breakpoints to be set
accurately and allows a programmer to step through the code one line at a time.
Debugging information is also generated help the debugger figure out where it is in
the source code.
In release mode, most of the compiler's optimizations are turned on. Chunks of
your code could be completely deleted, removed, or rewritten. The resulting
executable will most likely not match up with your written code. However,
normally release mode will run faster then debug mode due to the optimizations.
6) What is the need for header files?
System header files declare the interfaces to parts of the operating system. It should be
included in our program to supply the definitions and declarations that need to invoke
system calls and libraries.
Header files contain declarations for interfaces between the source files of our program.
Each time a group of related declarations and macro definitions all or most of which are
needed in several different source files, it is a good idea to create a header file for them.
7) What is the need for driver library?
The Driver Library includes drivers for all classes of Stellaris microcontrollers.
This directory contains the source code for the drivers.
8) What is the need for inc file?
This directory holds the part specific header files used for the direct register access
programming model.
9) What is the use of GNU MAKE?
It converts .elf file to .bin file.
10) What are the different header files used in our program and mention it uses?
Header files, one per peripheral that describe all the registers and the bit fields within
those registers for each peripheral. These header files are used by the drivers to directly
access a peripheral, and can be used by application code to bypass the peripheral driver
library API.
64
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
65
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
67
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
If we add the UART programming with the existing code, the data can be transmitted
/received through either TXD/RXD. We can easily interface wireless modules with LPC
2148 microcontroller.
4. Draw the circuit diagram of LM 35 Temperature Sensor?
To evaluate the analog to digital conversion capabilities of the microcontroller, a LM35
temperature sensor(IC6) and a thumbwheel potentiometer(POT1) are provided on the board. The
two are connected to the same analog channel,ADC7 of the microcontroller. Either can be selected
by using jumper J2. The LM35 is powered by +5V coming from the USB bus.
68
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
69
SEC - ECE EMBEDDED SYSTEMS LAB RECORD
5. What is encryption?.
Encryption is the process of translating plain text data (plain text) into something that
appears to be random and meaningless (cipher text)
6. What is decryption and symmetric encryption?
Decryption is the process of converting cipher text back to plaintext. To encrypt more than
a small amount of data, symmetric encryption is used. A symmetric key is used during
both the encryption and decryption processes. To decrypt a particular piece of cipher text,
the key that was used to encrypt the data must be used.
7. What are the properties of maximum length sequence?
7 clock cycles to repeat
maximal length = 2n-1
the number of ones in the sequence are greater than the number of zero.
_ the rail occurs as 2(n-1)-1
70