Rtos & Embedded Lab Record

Download as pdf or txt
Download as pdf or txt
You are on page 1of 94

INDEX

Sl.
No.
Date Experiment Name Marks Signature
1 27-02-2014

Stepper motor interfacing


2 06-03-2014
ADC interfacing

3 13-03-2014

Keyboard display interfacing

4 13-03-2014

Serial port interfacing


5 10-04-2014
LCD interfacing

6 17-04-2014
CAN serial controller


VERILOG PROGRAMMING
7 24-04-2014
Design and implementation of simple
combinational and sequential circuits


8 24-04-2014
Design with programmable logic devices
using xilinx FPGA & CPLD


RTOS
9 02-05-2014
Intertask synchronization
using semaphore on ARM 7


10 02-05-2014
Implementation of event control
blocks on ARM 7


11 08-05-2014
Intertask communication
using mailbox


12 08-05-2014
Intertask synchronization
using mutex


ADSP 2181
13 22-5-2014 Vector addition
14 29-05-2014 ADSP program to blink a LED
15 29-05-2014 Convolution





Ex.No:01
Date: 27-02-2014
STEPPER MOTOR INTERFACING

AIM:
To write a C- Program to interface the stepper motor to LPC2148 processor through MCB2140
kit.

APPARATUS REQUIRED:
KEIL Software.
Keil MCB2140 Microcontroller board.
Stepper motor.

ALGORITHM:
Step 1: Initialize P1.16-19pin as output pins.
Step 2: Give 1000 to P1.19 to P1.16
Step 3: Call a software delay routine
Step 4: Give 0100 to P1.19 to P1.16
Step 5: Call a software delay routine
Step 6: Give 0010 to P1.19 to P1.16
Step 7: Call a software delay routine
Step 8: Give 0001 to P1.19 to P1.16
Step 9: Call a software delay routine
Step 10: Go to Step 2




PROCEDURE :

Step 1: Open the keil software.
Step 2: Click on the project and create a new project.
Step 3: Create a new C file and type the program.
Step 4: Create the necessary header files and add to the project.
Step 5: Connect the Stepper Motor Interface to MCB 2140 using ESA Interface Adapter
for MCB 2140
Step 6: Download the Stepper Motor Interface Program usingKeil ULINK debugger.
Step 7: Compile the C file and debug the code.
Step 8: Run the program.
















FLOWCHART:
Delay function: Variable count is taken as Argument







False


True

No


True







Start
Initialize i=0,j=0
Check
i<=count
Stop
Check
j<=50
Increment j
by 1
Increment j
by 1

Main function:























Start
Initialize GPIO 16 to 19
of port1 as output
Make P1.<19:16> =1000
Call delay function
Clear the Port1 pins
Make P1.<19:16> =0100
Call delay function
A
B

























Clear the port1 pins
Make P1.<19:16> =0010

Clear the port1 pins
Make P1.<19:16> =0001

Call the delay function
Call the delay function
Clear the port1 pins
A B

PROGRAM:
#include <LPC214X.H>

void delay(unsigned int count)
{
unsignedinti ,j= 0;
for(i = 0; i<= count; i ++)
for(j = 0; j <= 50; j ++);
}
unsigned long i;
int main()
{
IODIR1 = 0x00FF0000;
i = 0x00110000;
while(1)
{
IOSET1 = 0x00080000;
delay(1000);
IOCLR1 = 0x000F0000;
IOSET1 = 0x00040000;
delay(1000);
IOCLR1 = 0x000F0000;
IOSET1 = 0x00020000;
delay(1000);
IOCLR1 = 0x000F0000;
IOSET1 = 0x00010000;
delay(1000);
IOCLR1 = 0x000F0000;
}
/* Anti clock rotation
while(1)
{
IOSET1 = 0x00110000;
delay(10000);
IOCLR1 = 0x00FF0000;
IOSET1 = 0x00220000;
delay(10000);
IOCLR1 = 0x00FF0000;
IOSET1 = 0x00440000;
delay(10000);
IOCLR1 = 0x00FF0000;
IOSET1 = 0x00880000;
delay(10000);
IOCLR1 = 0x00FF0000;
}*/
}





RESULT:
Thus the C program for interfacing stepper motor with LPC2148 Processor was written and
executed.
Ex.No:02
Date: 06-03-2014
ADC INTERFACING
AIM:
To write a C Program for ADC interfacing with LPC2148 processor by using MCB2140
evaluation board .

APPARATUS REQUIRED:
KEIL Software.
Keil MCB2140 Microcontroller board.
ULINK2 JTAG Debugger.


ALGORITHM:
Step 1: Select the pin functionality for UART1,TXD&RXD and analog channel1
Step 2:Initialize UART1 with 9600 baud rate,1stop bit,no parity,8 data bits.
Step 3:configure ADC channel as 1,ADC clock as 3MHz.
Step 4:Start ADC conversion
Step 5:.At the end of 10 bit ADC conversion get the result and calculate the analog input voltage.
Step 6: Transmit 10 bit ADC result and analog input voltage through UART1
Step 7: Go to step4






PROCEDURE:
Step 1: Open the keil software.
Step 2: Click on the project and create a new project.
Step 3: Create a new C file and type the program.
Step 4: Create the necessary header files and add to the project.
Step 5: Compile the C file and debug the code.
Step 6: Now the LPC2148 device is to be connected to PC with the help of RS232 cable.
Step 7 : Open the HYPERTERMINAL window in PC.
Step 8: Run the program.


















FLOWCHART:

















No

yes






Start
Select the UART1 TXD,RXD and analog
channel1 pin functionality
Configure UART1 with following baud
rate 9600,stop bit 1,data bits 8,no
parity
Configure ADC with following.ADC
channel1,ADC clock 3MHz
Start ADC conversion
Get 10 bit ADC result from ADDR&
calculate analog input voltage
Transmit 10 bit ADC result and analog
input voltage to UART 1
Is ADC
conversion
completed?
PROGRAM:
#include <stdio.h>
#include <LPC21xx.H>
void wait (void) {
int d;
for (d = 0; d < 1000000; d++);
}
#define VREF 3
unsigned int val;
int main (void) {
PINSEL0 = 0x00050000;
PINSEL1 |= 0x01000000;
U1LCR = 0x83;
U1DLL = 97;
U1LCR = 0x03;
IODIR1 = 0x00FF0000;
printf ("ADC INTERFACING\n");
ADCR = 0x00210602;
while (1)
{
ADCR |= 0x01000000;
while ((ADDR & 0x80000000) == 0);
val = ((ADDR >> 6) & 0x03FF);
printf("Val is %d\r\n",val);
printf("Voltage is %f\r\n",(((float)val/1023.0)*3.3));
wait ();
wait ();
wait ();
wait ();
wait ();
}
}




















RESULT:
Thus the C program for interfacing ADC with LPC2148 Processor has been executed.


Ex.No:03
Date: 13-03-2014
KEYBOARD DISPLAY INTERFACING
AIM:
To write a C Program for keyboard display interfacing with LPC2148 Processor by using
MCB2140 Evaluation board.

APPARATUS REQUIRED:
KEIL Software.
Keil MCB2140 Microcontroller board.
ULINK2 JTAG Debugger


ALGORITHM:
Step 1: Start the program.
Step 2: Configure four port 0 pins as output pins (P0.15-P0.18) and five port1 pins (P1.16-P1.20)
as input pins for keyboard interface.
Step 3: Configure P0.2 and P0.3 as output for display interfacing.
Step 4: Give serial input to shift register to clear all six 7-segment display.
Step 5: Scan the keyboard to get the number .
Step 6: If AC key has been pressed, then clear the display and go to step 4.
Step 7: otherwise display the number corresponding to key pressed.
Step 8: Go to step 4.
Step 13: Stop the program.



PROCEDURE:
Step 1: Open the keil software.
Step 2: Click on the project and create a new project.
Step 3: Create a new C file and type the program.
Step 4: Create the necessary header files and add to the project.
Step 5: Connect the Key Board Display Interface to MCB 2140 using ESA Interface Adapter
for MCB 2140.
Step 6: Download the Key Board Display Program using Keil ULINK /LPC Flash
Programmer Utility.
Step 7: Compile the C file and debug the code.
Step 8: Press reset to Run the program / Enter debug mode and press run.
















FLOWCHART:











NO


YES


NO

YES
NO

YES



START
Configure port pins input output functionality to
interface keyboard and display
Give six 0xff serially to shift
register to clear the display.
Clear all 7 segment Display
If any key has
been pressed?
If pressed key
is = AC?
If pressed key
is number
Display the number

PROGRAM:
#include <LPC214X.H>
void DispChar(unsigned char ch);
void ClrLED(void);
void delay(unsigned int i);
unsigned char getkey(void);
unsigned char getnum(void);
main()
{
unsigned char n1;
unsigned char NumTab[10] = { 0x0c0,0x0f9,0x0a4,0xb0,0x99,0x92,0x82,0x0f8,0x80,0x90 };

PINSEL2 = PINSEL2 & 0xFFFFFFF7;
IODIR0 = 0x007F800C;
IODIR1 = 0x00000000;
ClrLED(); /* Clear the 7 segment display */
while(1)
{
n1=getnum(); /* Get the 1st number */
if(n1==0x13)
{
ClrLED(); /* If pressed key is "AC",then Clear LED */
continue;
}
DispChar(NumTab[n1]); /* Display the number */
delay(30000);
delay(30000);
delay(30000);
}
}
void DispChar(unsigned char ch) /* Function to display the charecter on 7 segment */
{
unsigned char i,tmp;
IOCLR0 = 0x003F8000; /* For all bits */
for(i=0;i<8;i++)
{
tmp = ch & 0x80;
if(tmp) /* write data depending on MSB */
IOSET0 |= 0x00000008;
else
IOCLR0 |= 0x00000008;
IOCLR0 |= 0x00000004; /* Give Clk Pulse for synchronization */
IOSET0 |= 0x00000004;

ch = ch << 1; /* Get next bit */
}
}
void ClrLED()
{
unsigned char i;
for(i=0;i<6;i++)
DispChar(0x0ff); /* 0xff for clear segment */

}

unsigned char getkey()
{
unsigned char j,indx;
unsigned long i,s=00;
while(1)
{
indx = 0x00; /* Index for storing the first value of scanline */
for(i=0x00008000;i<=0x00080000;i<<=1) /* For 4 scanlines */
{
IOCLR0 = 0x00078000;
IOSET0 = i; /* write data to scanline */
delay(500);
s = 0x001F0000 & IOPIN1; /* Read readlines connected to P0*/
s >>= 16;

if(s > 0) /* If key press is true */
{
for(j=0; j<=4; j++)
{ /* Check for 5 lines */
s >>=1;
if(s==0) /* If get pressed key*/
{
return(indx+j); /* Return index of the key pressed */
}
}
}
indx += 5; /* If no key pressed increment index */
}
}
}
unsigned char getnum() /* Function to get the number */
{
unsigned char tmp;
while(1)
{
tmp = getkey();
if(tmp < 0x0a || tmp==0x13) /* If pressed key is number, return */
return(tmp);
}
}
void delay(unsigned int i)
{
unsigned int j;
for(j=0;j<=i;j++); /* Delay function */
}




RESULT:
Thus the C program for interfacing Keyboard display with LPC2148
Processor has been executed.

Ex.No:04
Date: 13-03-2014
SERIAL PORT INTERFACING
AIM:
To write a C Program for serial port interfacing with LPC2148 controller by using ARM
processor.
APPARATUS REQUIRED:
KEIL Software.
Keil MCB2140 Microcontroller board.
ULINK2 JTAG debugger.
ALGORITHM:
Step 1:Initialize the UART1 with the following settings-
Baudrate-9600; 1stop bit; 8 data bits; no parity.
Step 2: Configure the TxD1, RxD1 pin.
Step 3: Wait for data input from PC to LPC2148s UART1.
Step 4: After getting the UART1 input, give that character as output through UART1.
Step 5: Go to step 3.

PROCEDURE:
Step 1: Open the keil software.
Step 2: Click on the project and create a new project.
Step 3: Create a new C file and type the program.
Step 4: Create the necessary header files and add to the project.
Step 5: Connect the MCB 2140 to the PC using RS232 port.
Step 6: Compile the C file and debug the code.
Step 7: Download the serial port Interface Program using ULINK2 JTAG debugger to the
MCB2140 board.
Step 8: Run the program and check the required output using hyperterminal Connection.
FLOWCHART:
Configure TxD1, RxD1 pins.

Initialize UART1 with Baud Rate: 9600, 1 Stop
bit, 8 data bits, No Parity

Get the Received data from UART1 Receive
buffer
Transmit that data through UART1
Start
Is
U1LSRs
LSB =1?
No
Yes

PROGRAM:
#include <stdio.h>
#include <LPC21xx.H>
#define CR 0x0D
int sendchar (int ch)
{
if (ch == '\n')
{
while (!(U1LSR & 0x20));
U1THR = CR;
}
while (!(U1LSR & 0x20));
return (U1THR = ch);
}
int getkey (void)
{
while (!(U1LSR & 0x01));
return (U1RBR);
}
int main (void)
{
char c;
PINSEL0 = 0x00050000;
U1LCR = 0x83;
U1DLL = 97;
U1LCR = 0x03;

while (1)
{
c =(char) getkey();
// printf ("The char is %c\n", c);
sendchar('v');
sendchar('a');
sendchar('l');
sendchar('=');
sendchar(c);
sendchar('\n');
}
}











RESULT:
Thus the C program for serial port interfacing with LPC2148 Processor has been
executed.
Ex.No:05
Date:-10-04-2014
LCD INTERFACING
AIM:
To write a C Program to interface LCD with LPC2919 processor through MCB2900 Evaluation
Kit.
APPARATUS REQUIRED:
KEIL Software.
Keil MCB2900 Microcontroller board.
ULINK2 JTAG Debugger
ALGORITHM:
1. Initialize LCD to work with 4 bit mode.
2. Initialize the serial port with the following settings. Baud rate-9600,stop bit-1,data bits-
8,parity-none.
3. Clear display & return the cursor to home in LCD.
4. Print two lines in LCD.
5. Get the input from USART0,until 0x0d has been given
6. Accumulate the input characters in a character array
7. Clear display & return the cursor to home
8. Display the character array content in the first line.
9. Go to step5.
PROCEDURE:
Step 1: Open the keil software.
Step 2: Click on the project and create a new project.
Step 3: Create a new C file and type the program.
Step 4: Create the necessary header files and add to the project.
Step 5: Connect the MCB 2900 to the pc using RS232 port.
Step 6: Compile the C file and debug the code.
Step 7: Download the LCD Program using flash magic/JTAG Debugger to the MCB2900 board.
Step 8: Run the program and give input through hyper terminal and check the output in LCD.
FLOW CHART:-












no











Initialise LCD to 4 bit mode
Initialize serial port with BR=9600,stop
bit=1,data bits=8,no parity.

Clear the display& return cursor to home.
Print the 2 lines in LCD
Put Null Character at the end of the array
Clear the display & cursor of 1
st
line in home
Display the character array contents in 1
st
line
Start
Whether serial
I/P is given as
0x0D?
Accumulate the input
character in an array
Yes
PROGRAM:
#include <LPC29xx.H>
#include "LCD.h"
//- DB4 = P0.28 - DB5 = P0.29 - DB6 = P0.30 - DB7 = P0.31 - E = P0.3 - RW = P0.4 -
RS = P0.5 */
#define PIN_E (1 << 3)
#define PIN_RW (1 << 4)
#define PIN_RS (1 << 5)
#define PINS_DATA (0x0FUL << 28)
/* pin E setting to 0 or 1 */
#define LCD_E(x) ((x) ? (GPIO0_OR |= PIN_E) : (GPIO0_OR &= ~PIN_E) );
delay(10);
/* pin RW setting to 0 or 1 */
#define LCD_RW(x) ((x) ? (GPIO0_OR |= PIN_RW) : (GPIO0_OR &= ~PIN_RW));
delay(10);
/* pin RS setting to 0 or 1 */
#define LCD_RS(x) ((x) ? (GPIO0_OR |= PIN_RS) : (GPIO0_OR &= ~PIN_RS));
delay(10);
/* Reading DATA pins */
#define LCD_DATA_IN ((GPIO0_PINS >> 28) & 0xF)
/* Writing value to DATA pins */
#define LCD_DATA_OUT(x) GPIO0_OR = (GPIO0_OR & ~PINS_DATA) | ((x & 0xF)
<< 28); delay(10);
/* Setting DATA pins to input mode */
#define LCD_DATA_DIR_IN GPIO0_DR &= ~PINS_DATA; delay(10);
/* Setting DATA pins to output mode */
#define LCD_DATA_DIR_OUT GPIO0_DR |= PINS_DATA; delay(10);

static void delay (intcnt) {
cnt<<= 6;
while (cnt--);
}
extern void LCD_print (unsigned char DDRAM_addr_cmd, unsigned char *string);
extern void init_serial (void);

int main (void)
{
int i;
unsigned char c;
unsigned char str[20] ;
init_serial ();
LCD_init ();
lcd_write_cmd(0x01);
lcd_write_cmd(0x80);
LCD_print (0x80, " cdac ");
LCD_print (0xA8, " Vel Tech Univ ");
for (i = 0; i < 12000000; i++);
for (;;)
{
i=0;
do
{
c =(unsigned char)getkey();
str[i] =c;
i= (i+1)%16;
}
while(c != 0x0d);
str[i-1] =0x00;
lcd_write_cmd(0x01);
lcd_write_cmd(0x80);
LCD_print (0x80, str);
}

}

LCD.C

void lcd_write_4bit (unsigned char c)
{
LCD_RW(0)
LCD_E(1)
LCD_DATA_OUT(c&0x0F)
delay(10);
LCD_E(0)
delay(10);
}
void lcd_write_cmd (unsigned char c)
{
delay(1000);
LCD_RS(0)
lcd_write_4bit(c>>4);
lcd_write_4bit(c);
}

static void lcd_write_data (unsigned char c)
{
delay(1000);
LCD_RS(1)
lcd_write_4bit(c>>4);
lcd_write_4bit(c);
}

void LCD_init (void)
{
inti;
GPIO0_DR |= 0xF0000038;
delay (15000);
LCD_RS(0)
lcd_write_4bit(0x3); /* Select 4-bit interface */
delay (4100);
lcd_write_4bit(0x3);
delay (100);
lcd_write_4bit(0x3);
lcd_write_4bit(0x2);
lcd_write_cmd(0x28); /* 2 lines, 5x8 character matrix */
lcd_write_cmd(0x0C); /* Display ctrl:Disp=ON,Curs/Blnk=OFF */
lcd_write_cmd(0x06); /* Entry mode: Move right, no shift */
lcd_write_cmd(0x80); /* Set DDRAM address counter to 0 */

}

void LCD_print (unsigned char DDRAM_addr_cmd, unsigned char *string)
{
lcd_write_cmd(DDRAM_addr_cmd);
while (*string)
lcd_write_data (*string++);

}
Serial.c
#include <stdio.h>
#include <LPC21xx.H>
int getkey (void)
{
while (!(U1LSR & 0x01));
return (U1RBR);
}


RESULT:
Thus the C program for LCD interfacing with LPC2148 Processor has been executed.
Ex.No:06
Date:17-04-2014
CAN SERIAL CONTROLLER

AIM:
To write a C Program for CAN serial in LPC2919 by using MCB2900 Evaluation Board.

APPARATUS REQUIRED:
Keil software
MCB2900 Microcntroller board
ULINK2 JTAG debugger

ALGORITHM:
Step 1: Select the UART0 & CAN0 pin functionality.
Step 2: Configure the UART0 with baud rate: 9600; 1stop bit; 8 data bits; no parity.
Step 3: Initialize the TIMER0 which gives the interrupts at every 10ms.
Step 4: Start TIMER0.
Step 5: Enable CAN0 RX interrupt.
Step 6: Enable the serial port for transmitting the data.
Step 7: Wait for clock1S flag to be 1. (This flag is made as 1 for every 1sec in Timer0 ISR).
Step 8: Transmit the Tx data through CAN0.
Step 9: Transmit, transmitted & received data of CAN0 through UART0.
Step10: Increment ASCII value of Tx data from A to Z.
Step11: go to step No.7.



PROCEDURE:
Step 1: Open the Keil software.
Step 2: Click on the project and create a new project.
Step 3: Create a new C file and type the program.
Step 4: Create the necessary header files and add to the project.
Step 5: Connect the LPC2919 device to the PC using RS232 port.
Step 6: Compile the C file and debug the code.
Step 7: Download the CAN serial port Program to LPC2919 Processor with the help of ULINK2
JTAG Debugger.
Step 8: Run the program.
Step9 : Check the required output using Hyperterminal window.




















PROGRAM:
#include <stdio.h>
#include <LPC29xx.H>
#define TMR_CLK 80000000
volatile unsigned char Clock1s;
volatile unsigned char Rx_Data;
volatile unsigned char Tx_Data;
extern void init_serial (void);
int main (void) {
int i;
GPIO1_DR |= (0x3F << 24);
SFSP1_30 = (0x03 << 2);
SFSP1_31 = (0x03 << 2);
GPIO1_DR &= ~(0x03UL << 30);
MSCSS_CLK_CONF = (2UL << 24) | (1 << 11) | (1 << 2);
MTIM0_PR = (80000000 / 1000) - 1; /* Prescaler to drive timer with 1 ms */
MTIM0_MR2 = (10 - 1); /* Match value = 10 * 1ms = 10 ms */
MTIM0_MCR = (1 << 4); /* On Match 2 event reset timer */
MTIM0_EMR |= (3 << 8); /* Match 2 event generate logic 1 */
MTIM0_TCR = 1; /* Start Timer 0 */
TMR_CLK_CONF = (2UL << 24) | (1 << 11) | (1 << 2);
INT_REQUEST_2 = (1 << 28) | /* Enable setting of priority level */
(1 << 27) | /* Enable setting interrupt target */
(1 << 26) | /* Write enable of new settings */
(1 << 16) | /* Enable interrupt request */
(1 << 8) | /* Interrupt target is IRQ interrupt */
(15 << 0) ; /* Priority level 15, disable nesting */
TIM0_PR = (TMR_CLK / 1000) - 1; /* Prescaler to drive timer with 1 ms */
TIM0_MR0 = (10 - 1); /* Match value = 10 * 1ms = 10 ms */
TIM0_MCR = 1; /* On Match 0 event reset timer */
TIM0_INT_SET_ENABLE = 1; /* Enable Match 0 to generate interupt*/
TIM0_TCR = 1; /* Start Timer 0 */
init_serial();
IVNSS_CLK_CONF = (2UL << 24) | (1 << 11) | (1 << 2);
SFSP0_0 = 0x06; /* Configure P0.0 as CAN0 TxD */
SFSP0_1 = 0x06; /* Configure P0.1 as CAN0 RxD */
CAN0MOD = 1; /* Start in Reset Mode */
CAN0BTR = ((7-1)<<16) | /* TSEG1=7 */
((6-1)<<20) |
((1-1)<<14) |
((80000000/100000/(7+6+1))-1);
#ifdef CAN_LOOPBACK
CAN0MOD = 4;
#else
CAN0MOD = 0;
#endif
INT_REQUEST_37 = (1 << 28) |
(1 << 27) |
(1 << 26) |
(1 << 16) |
(1 << 8) |
(1 << 0) ;
CAN0IER = 1;
CAN_AFMR = 2;
Tx_Data ='a';
for (;;) {
if (Clock1s) {
Clock1s = 0;
CAN0TFI1 = 1 << 16; /* FF=0, RTR=0, DLC=1, TXPRIO=1 */
CAN0TID1 = 0x123; /* ID=0x123 */
CAN0TDA1 = Tx_Data; /* Tx Data Byte */
#ifdef CAN_LOOPBACK
CAN0CMR = 0x30; /* Transmit (Buffer 1) with Loopback */
#else
CAN0CMR = 0x21; /* Transmit (Buffer 1) */
#endif
for (i = 0; i < 120000; i++);
printf("Tx=%c Rx=%c\r\n", Tx_Data, Rx_Data);
Tx_Data++;
if(Tx_Data >'z')
Tx_Data ='a';
}
}
}
IRQ.C
#include <LPC29xx.H>
extern volatile unsigned char Clock1s;
extern volatile unsigned char Rx_Data;

__irq void Timer0_Handler (void) { /* Timer 0 Interrupt Handler */
static unsigned char cnt1s;

if (cnt1s++ >= 99) { /* Set Clock1s each 1 second */
cnt1s = 0;
Clock1s = 1;
}

TIM0_INT_CLR_STATUS = 1; /* Clear Timer 0 interrupt status */
}

__irq void CAN0_Rx_Handler (void) { /* CAN0 Rx Interrupt Handler */
volatile unsigned long dummy;

dummy = CAN0ICR; /* Read and clear interrupt status */
Rx_Data = CAN0RDA; /* Read Data Byte */
CAN0CMR = 4; /* Release receive buffer */
}







RESULT:
Thus the program for CAN SERIAL CONOTROLLER has been executed.

Ex:No: 7
Date :24-04-2014

DESIGN AND IMPLEMENTATION OF SIMPLE COMBINATIONAL AND
SEQUENTIAL CIRCUITS

Aim:
To Write verilog code for half adder, full adder, MUX, D Flip-Flop and simulate
and synthesis.
Required:
Xilinx software
Procedure:
1. write the Verilog codings for half adder, full adder, MUX in Xilinx.
2. Read the input values.
3. Check for the syntax errors.
4. Simulate the codings and assign input values for the wave form in test
bench.
5. Verify the output waveform.

PROGRAM:
HALF ADDER
module ha(a,b,s,c);
input a,b;
output s,c;
and(c,a,b);
xor(s,a,b);
end module

FULL ADDER

module ha(a,b,c,s,c);
input a,b,c;
output s,c;
wire d,e,f;
xor(d,a,b)
xor(s,d,c);
and(e,d,c);
and(f,a,b);
or(c,e,f);
end module










SIMULATION RESULTS:
HALF ADDER:




FULL ADDER:










PROGRAM :
MULTIPLEXER
module mux(i0,i1,i2,i3,y);
input i0,i1,i2,i3;
output y;
input s0,s1;
wire w1,w2,a,b,c,d;
and(a,i0,w1,w2);
and(b,i1,w1,s1);
and(c,i2,s0,w2);
and(d,i3,s0,s1);
end module;
SIMULATION RESULTS:
MULTIPLEXER:

D FLIP FLOP
module dff_sync_reset ( data , clk , reset, q );
input data, clk, reset ;
output q;
reg q;
always @ ( posedge clk)
if (~reset) begin
q <= 1'b0;
end else begin
q <= data;
end
endmodule

SIMULATION OUTPUT:
D FLIP FLOPF with synchronous reset


RESULT :
Thus the output waveform is obtained and verified.


Ex:No: 8
Date : 24-04-2014
DESIGN WITH PROGRAMMABLE LOGIC DEVICES USING XILINX
FPGA & CPLD

Aim:
To design Programmable Logic Devices using xilinx FPGA & CPLD
Required :
Xilinx software, FPGA Kit.
Procedure:
1. Write the Verilog codings for Programmable Logic Devices in Xilinx.
2. Read the input values.
3. Check for the syntax errors.
4. Simulate the codings and assign input values for the wave form in test bench.
5. Verify the output waveform.
6. Download the coding to FPGA kit and check the logic.

Program :

module PAL(a,b,c,f0,f1,f2,f3);
input a,b,c;
output f0,f1,f2,f3;
wire d,e,f,g,h,i,j,k;
not (e,b);
not (f,c);
and (g,a,b);
and(h,e,c);
and(i,a,f);
and(j,e,f);
and(k,a,c);
or(f0,j,k);
or(f1,i,g);
or(f2,j,g);
or(f3,k,h);
end module




















































Result:

Thus the design and implement ion of PAL device using Xilinx FPGA & CPLD is
done.



Ex.No.9
Date : 2-05-2014

INTERTASK SYNCHRONIZATION USING SEMAPHORE ON ARM 7

Aim :

To write a program to perform intertask synchronization using semaphore using
RTX kernel on ARM7.

Requirement :

Keil uVision V4

Procedure :

1. Open keil Uvison V4.
2. Create a new project.
3. Type the program files.
4. Create the necessary header files and add to the project.
5. Save and build the file.
6. Debug and execute the program.
7. Check the results using UART2 serial windows.












Flow Chart :

Main :








init task :















START
INITIALIZE KERNAL
START INIT TASK
INITIALIZE SERIAL PORT
CREATE TASK 1 WITH PRIORITY 10
CREATE TASK 2 WITH PRIORITY 1

DELETE INIT TASK
STOP
START
Task 1:
























START
WAIT FOR 30MS
WAIT 1 TICK FOR SEMAPHORE
PRINT TASK1
RELEASE SEMAPHORE

Task 2:




N

Y
Y

















START
PRINT TASK2
RELEASE SEMAPHORE
WHETHER
SEMAPHORE
IS RECEVIED?
?

Program :

/* Semaphore.c */
/*----------------------------------------------------------------*/

#include <RTL.h> /* RTX kernel functions & defines */
#include <LPC21xx.H> /* LPC21xx definitions */
#include <stdio.h>
extern void init_serial (void); /* Initialize Serial Interface */
OS_TID tsk1, tsk2;
OS_SEM semaphore1;
__task void task1 (void)
{
OS_RESULT ret;
while (1)
{
/* Pass control to other tasks for 3 OS ticks */
os_dly_wait(3);
/* Wait 1 ticks for the free semaphore */
ret = os_sem_wait (semaphore1, 1);
if (ret != OS_R_TMO) {
/* If there was no time-out the semaphore was aquired */
printf ("Task 1\n");
/* Return a token back to a semaphore */
os_sem_send (semaphore1);
}
}
}


__task void task2 (void)
{
while (1)
{
/* Wait indefinetly for a free semaphore */
os_sem_wait (semaphore1, 0xFFFF);
/* OK, the serial interface is free now, use it. */
printf ("Task 2 \n");
/* Return a token back to a semaphore. */
os_sem_send (semaphore1);
}
}




__task void init (void)
{
/* Initialize the UART */
init_serial ();
/* Initialize the Semaphore before the first use */
os_sem_init (semaphore1, 1);
/* Create an instance of task1 with priority 10 */
tsk1 = os_tsk_create (task1, 10);
/* Create an instance of task2 with default priority 1 */
tsk2 = os_tsk_create (task2, 0);
/* Delete the init task */
os_tsk_delete_self ();
}

int main (void) {
/* Initialize RTX and start init */
os_sys_init (init);
}






/*Serial.c */
/*----------------------------------------------------------------*/

#include <LPC213x.H> /* LPC21xx definitions */
#include <stdio.h>
#define CR 0x0D
void init_serial (void) {
PINSEL0 = 0x00050000; /* Enable RxD1 and TxD1 */
U1LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
U1DLL = 97; /* 9600 Baud Rate @ 15MHz VPB Clock */
U1LCR = 0x03; /* DLAB = 0 */
}

int fputc (int ch, FILE *f) {
if (ch == '\n') {
while (!(U1LSR & 0x20));
U1THR = CR; /* output CR */
}
while (!(U1LSR & 0x20));
return (U1THR = ch);
}

















SIMULATION OUTPUT:







Result :

Thus the program for intertask synchronization using semaphore is done and the
output is verified in UART window.
Ex.No:10
Date : 02-05-2014
IMPLEMENTATION OF EVENT CONTROL BLOCKS ON ARM7

Aim :

To write a program to implement a Event Control Blocks in ARM7
using RTX kernel.

Requirement :

Keil uVision V4

Procedure :

1. Open keil Uvison V4.
2. Create a new project.
3. Type the program files.
4. Create the necessary header files and add to the project.
5. Save and build the file.
6. Debug and execute the program.
7. Check the results using PORT1 window.








Flow Chart :
Main :




















START
INITIALIZE PORT 1 PINS 16 TO 23 AS OUTPUT PINS

START INITIAL TASK
TASK1
STOP
TASK 1:










N

Y









SET THE PORT 1.23 PIN
CLEAR THE PORT 1.23 PIN
Set the port 1.23
pin
WAIT FOR 50ms
START
SET EVENT FLAG 0X0004 FOR
TASK 2
CREATE TASK 2 WITH
PRIORITY 10
WHETHER EVENT
FLAG 0X0004 IS
SET BY TASK2?
Task 2 :







N

Y














START
SET THE PORT 1.16
CLEAR THE PORT 1.16
WAIT FOR 20ms
SET EVENT 0X0004

WHETHER EVENT
FLAG 0X0004 IS
SET?

Program :
#include <RTL.h> /* RTX kernel functions & defines */
#include <LPC21xx.h>
/* id1, id2 will contain task identifications at run-time */
OS_TID id1, id2;

/* Forward reference */
__task void task1 (void);
__task void task2 (void);

__task void task1 (void)
{
/* Obtain own system task identification number */
id1 = os_tsk_self ();
/* Assign system identification number of task2 to id2 */
id2 = os_tsk_create (task2, 10);
for (;;) { /* do-this */
/* Indicate to task2 completion of do-this */
os_evt_set (0x0004, id2);
/* Wait for completion of do-that (0xffff means no time-out)*/
IOSET1 =0x00800000;
os_evt_wait_or (0x0004, 0xffff);
IOCLR1 =0x00800000;
/* Wait now for 50 ms */
os_dly_wait (5);
}
}
__task void task2 (void)
{
//int i;
for (;;) {
/* Wait for completion of do-this (0xffff means no time-out) */
IOSET1 =0x00010000;
os_evt_wait_or (0x0004, 0xffff); /* do-that */
IOCLR1 =0x00010000;
/* Pause for 20 ms until signaling event to task1 */
os_dly_wait (2);
/* Indicate to task1 completion of do-that */
//i=5;
os_evt_set (0x0004, id1);
}
}

int main (void) {
IODIR1 = 0xFF0000; /* P1.16..22 defined as Outputs */
os_sys_init (task1);
}


SIMULATION OUTPUT:







Result:
Thus the program to implement an event control blocks is executed & output
is verified using PORT 1 from peripheral window.

Ex.No:11
Date :08-05-2014
INTERTASK COMMUNICATION USING MAILBOX

Aim :

To write a program for intertask communication using Mailbox on ARM7
using RTX kernel.

Requirement :

Keil uVision V4

Procedure :

1. Open keil Uvison V4.
2. Create a new project.
3. Type the program files.
4. Create the necessary header files and add to the project.
5. Save and build the file.
6. Debug and execute the program.
7. Check the results using UART window.











Flow Chart :
MAIN :























START
INITIALISE THE KERNAL
INITIALISE THE PORT 1.16 TO PORT 1.23 AS OUTPUT PINS
INITIALISE THE SERIAL COMMUNICATION PORT
START THE SEND TASK
CREATE A MEMORY BLOCK
STOP

SEND_TASK :























START
DECLARE mptr AS STRUCTURE POINTER OF MESSAGE STRUCTURE
INITIALISE MAILBOX
CREATE res_task WITH PRIORTY 1
WAIT FOR 50ms
ALLOCATE MEMORY FOR MEMORY POOL & GET THE STARTING ADDRESSE AT mptr
INITALISE A MESSAGE VALUE TO MAILBOX
SEND MESSAGE TO MAILBOX
SET THE PIN PORT 1.16
WAIT FOR 1 SECOND
DELETE THE TASK

REC_TASK :






N


Y











START
DECLARE rptr AS STRUCTURE POINTER
PRINT VOLTAGE,CURRENT AND COUNTER VALUES
MAKE THE MAILBOX FREE
WHETHER
MAILBOX IS
RECEVIED?
Program :
#include <RTL.h> /* RTX kernel functions & defines */
#include <LPC21xx.H> /* LPC21xx definitions */
#include <stdio.h>
OS_TID tsk1; /* assigned identification for task 1 */
OS_TID tsk2; /* assigned identification for task 2 */
typedef struct { /* Message object structure */
float voltage; /* AD result of measured voltage */
float current; /* AD result of measured current */
U32 counter; /* A counter value */
} T_MEAS;
os_mbx_declare (MsgBox,16); /* Declare an RTX mailbox */
_declare_box (mpool,sizeof(T_MEAS),16);/* Dynamic memory pool */
__task void send_task (void);
__task void rec_task (void);
void init_serial () {
PINSEL0 = 0x00050000; /* Enable RxD1 and TxD1 */
U1LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
U1DLL = 97; /* 9600 Baud Rate @ 15MHz VPB Clock */
U1LCR = 0x03; /* DLAB = 0 */
}


__task void send_task (void) {
T_MEAS *mptr;
tsk1 = os_tsk_self (); /* get own task identification number */
tsk2 = os_tsk_create (rec_task, 0); /* start task 2 */
os_mbx_init (MsgBox, sizeof(MsgBox));/* initialize the mailbox */
os_dly_wait (5); /* Startup delay for MCB21xx */
mptr = _alloc_box (mpool); /* Allocate a memory for the message */
mptr->voltage = 223.72; /* Set the message content */
mptr->current = 17.54;
mptr->counter = 120786;
os_mbx_send (MsgBox, mptr, 0xffff); /* Send the message to the mailbox */
IOSET1 = 0x10000;
os_dly_wait (100);

os_tsk_delete_self (); /* We are done here, delete this task */
}
__task void rec_task (void) {
T_MEAS *rptr;
for (;;) {
os_mbx_wait (MsgBox, (void **)&rptr, 0xffff); /* wait for the message */
printf ("\nVoltage: %.2f V\n",rptr->voltage);
printf ("Current: %.2f A\n",rptr->current);
printf ("Number of cycles: %d\n",rptr->counter);
_free_box (mpool, rptr); /* free memory allocated for message */
}
}
int main (void) { /* program execution starts here */
IODIR1 = 0xFF0000; /* P1.16..22 defined as Outputs */
init_serial (); /* initialize the serial interface */
_init_box (mpool, sizeof(mpool), /* initialize the 'mpool' memory for */
sizeof(T_MEAS)); /* the membox dynamic allocation */
os_sys_init (send_task); /* initialize and start task 1 */
}













SIMULATION OUTPUT:






Result :
Thus the program to implement mailbox in tasks on ARM 7 is performed
and the output is verified using UART window.
Ex.No:12
Date : 15-05-2014
INTERTASK SYCHRONIZATION USING MUTEX

Aim :

To write a program to implement a Mutex in ARM7 using RTX kernel.

Requirement :

Keil uVision V4

Procedure :

1. Open keil Uvison V4.
2. Create a new project.
3. Type the program files.
4. Create the necessary header files and add to the project.
5. Save and build the file.
6. Debug and execute the program.
7. Check the results using UART window.












Flow Chart :
Main :








Init Task :














START
INITIALIZE KERNAL
START INIT TASK
INITIALIZE SERIAL COMMUNICATION PORT
INITIALIZE MUTEX 1
CREATE TASK 1 WITH PRIORITY 10
CREATE TASK 2 WITH PRIORITY 1

DELETE THE TASK

STOP
START

Task 1:








N


Y











START
WAIT FOR 30MS
PRINT TASK1
RELEASE THE MUTEX
WHETHER
MUTEX IS
RELEASED ?
Task 2 :






N


Y














START
PRINT TASK2
RELEASE THE MUTEX
WHETHER
MUTEX IS
RELEASED BY
TASK1 ?
Program :
/* Mutex .c /*
/*----------------------------------------------------------------------------
#include <RTL.h> /* RTX kernel functions & defines */
#include <LPC21xx.H> /* LPC21xx definitions */
#include <stdio.h>
extern void init_serial (void); /* Initialize Serial Interface */
OS_TID tsk1, tsk2;
OS_MUT mutex1;
__task void task1 (void) {
while (1) {
/* Pass control to other tasks for 3 OS ticks */
os_dly_wait(3);
/* Wait indefinitely for mutex */
os_mut_wait (&mutex1, 0xffff);
printf ("Task 1\n");
/* Return a mutex */
os_mut_release (&mutex1);
}
}
__task void task2 (void) {
while (1) {
/* Wait indefinetly for a free mutex */
os_mut_wait (&mutex1, 0xFFFF);
/* OK, the serial interface is free now, use it. */
printf ("Task 2 \n");
/* Return a Mutex. */
os_mut_release (&mutex1);
}
}
__task void init (void) {
/* Initialize the UART */
init_serial ();
/* Initialize the Semaphore before the first use */
os_mut_init (&mutex1);
/* Create an instance of task1 with priority 10 */
tsk1 = os_tsk_create (task1, 10);
/* Create an instance of task2 with default priority 1 */
tsk2 = os_tsk_create (task2, 0);
/* Delete the init task */
os_tsk_delete_self ();
}

int main (void) {
/* Initialize RTX and start init */
os_sys_init (init);
}



/* serial.c /*
/*----------------------------------------------------------------------------
#include <LPC213x.H> /* LPC21xx definitions */
#include <stdio.h>
#define CR 0x0D
void init_serial (void) {
PINSEL0 = 0x00050000; /* Enable RxD1 and TxD1 */
U1LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
U1DLL = 97; /* 9600 Baud Rate @ 15MHz VPB Clock */
U1LCR = 0x03; /* DLAB = 0 */
}

int fputc (int ch, FILE *f) {
if (ch == '\n') {
while (!(U1LSR & 0x20));
U1THR = CR; /* output CR */
}
while (!(U1LSR & 0x20));
return (U1THR = ch);
}




SIMULATION OUTPUT:







Result :
Thus the program to implement mutex in ARM 7 is done using keil
uVision4 and the result is verified using UART window.
Ex.No: 13
Date : 22-05-2014
VECTOR ADDITION
Aim:
To perform addition of two arrays by writing an assembly language
program for ADSP 2181 using Visual DSP++ software.

Requirement :
Visual DSP++ software.
Procedure :

1. Open visual DSP++ version 3.5.
2. Choose the ADSP-2181 simulation session.
3. Create a new project.
4. Type the program in a new file.
5. Save the file with .asm extension.
6. Add file to the project.
7. Bulid the project.
8. Debug and run the project.
9. Verify the output in the address location 0x100 in I/O memory.




Program :
#define n 10
#define z_out 0x100
.section/data data1;
.VAR x_input[n] = "xin.dat";
.section/pm pm_da;
.VAR y_input[n] = "yin.dat";
.section/pm interrupts;
__reset: JUMP start; nop; nop; nop; /* 0x0000: Reset vector*/
RTI; nop; nop; nop; /* 0x0004: IRQ2*/
RTI; nop; nop; nop; /* 0x0008: IRQL1*/
RTI; nop; nop; nop; /* 0x000C: IRQL0*/
RTI; nop; nop; nop; /* 0x0010: SPORT0 transmit*/
RTI; nop; nop; nop; /* 0x0014: SPORT0 receive*/
RTI; nop; nop; nop; /* 0x0018: IRQE*/
RTI; nop; nop; nop; /* 0x001C: BDMA*/
RTI; nop; nop; nop; /* 0x0020: SPORT1 transmit*/
RTI; nop; nop; nop; /* 0x0024: SPORT1 receive*/
RTI; nop; nop; nop; /* 0x0028: Timer*/
RTI; nop; nop; nop /* 0x002C: Power down*/

.section/pm program;
start: I2=x_input; /*pointer to x input buffer*/
L2=0; /*noncircular buffer*/
I6=y_input; /*pointer to y input buffer*/
L6=0;
M0=1; L0=0;
M5=1; L5=0;
CNTR=n-1;
AX0=DM(I2,M0), AY0=PM(I6,M5); /*Get first data*/
DO add_loop UNTIL CE;
AR=AX0+AY0, AX0=DM(I2,M0), AY0=PM(I6,M5);
add_loop: io(z_out)=AR; /*Write output*/
AR=AX0+AY0;
io(z_out)=AR;
IDLE;










Flow chart :
























START
STORE n WITH 10
DECLARE OUTPUT ADDRESS AS Z_OUT = 0X100
INITIALISE 16BIT DAT BUFFER AS X_INPUT[n]= XIN.DAT
Y DATA IS LOADED INTO Y_INPUT[n]
THE ADDRESS OF FIRST NUMBER IS LOADED INTO I2(THE INDEX REGISTER OF DAG1)
DECLARE LENGTH REGISTER L2 AS 0 TO INDICATE IT AS A LINEAR BUFFER
THE ADDRESS OF FIRST NUMBER FROM Y_INPUT IS LOADED INTO I6
(THE INDEX REGISTER OF DAG2)
DECLARE LENGTH REGISTER L6 AS 0 TO INDICATE IT AS A LINEAR BUFFER
DECLARE MODIFY REGISTER M0 & M3 TO GET AN OFFSET OF ONE
LOAD COUNTER(cntr) WITH VALUE 9
LOAD FIRST X_INPUT VALUE IN AX0 AND FIRST Y_INPUT VALUE IN AY0







Y

N















ADD AX0 AND AY0
THE RESULT IS SHARED IN I0 MEMORY 0X100
WHETHER
COUNTER(cntr)
EXPIRES ?
LOAD AX0 AND AY0 WITH NEXT DATA USING INDEX
AND MODIFY REGISTER
PROCESSOR GOES TO POWER DOWN MODE
STOP
Simulation Output :






Result :
The addition of two arrays has been perfomed using VDSP++ software and
the output verified.

Ex.No:14
Date :29-05-2014
ADSP Program to control a LED
Aim:
To write a program to simulate the blinking of a LED at regular intervals in
ADSP 2181 using Visual software.

Requirement :
Visual DSP++ software.
Procedure :

1. Open visual DSP++ version 3.5.
2. Choose the ADSP-2181 simulation session.
3. Create a new project.
4. Type the program in a new file.
5. Save the file with .asm extension.
6. Add file to the project.
7. Bulid the project.
8. Debug and run the project.
9. Verify the output in flag register.




Program :

.section/pm interrupts;
_reset: JUMP start; nop; nop; nop; /* 0x0000: Reset vector*/
RTI; nop; nop; nop; /* 0x0004: IRQ2*/
RTI; nop; nop; nop; /* 0x0008: IRQL1*/
RTI; nop; nop; nop; /* 0x000C: IRQL0*/
RTI; nop; nop; nop; /* 0x0010: SPORT0 transmit*/
RTI; nop; nop; nop; /* 0x0014: SPORT0 receive*/
RTI; nop; nop; nop; /* 0x0018: IRQE*/
RTI; nop; nop; nop; /* 0x001C: BDMA*/
RTI; nop; nop; nop; /* 0x0020: SPORT1 transmit*/
RTI; nop; nop; nop; /* 0x0024: SPORT1 receive*/
nop; nop; nop; nop; /* 0x0028: Timer*/
RTI; nop; nop; nop; /* 0x002C: Power down*/
.section/pm program;
start:
imask=0x001;
ena timer;
again:
toggle f11;
entr=0x2;
do loop1 until ce;
entr=0xfff;
do loop2 until ce;
nop;
loop2:nop;
loop1:nop;
jump again;
















Flow chart :






















FILL INTERRUPT VECTOR LOCATION WITH RTI
REMOVE MASK INTERRUPT FOR TIMER 1
ENABLE TIMER
TOGGLE FLAG 1
LOAD CNTR WITH 0X2
DELAY
LOAD CNTR WITH 0XFF
DELAY
Simulation Output :







Result :
A program has been written to blink a LED assumed to be a FL1 at
different ime intervals using visual DSP++ program.
Ex.No:15
Date : 29-05-2014
CONVOLUTION
Aim:
To write a program to perform convolution in ADSP2181 using visual
DSP++ software.

Requirement :
Visual DSP++ software.
Procedure :
1. Open visual DSP++ version 3.5.
2. Choose the ADSP-2181 simulation session.
3. Create a new project.
4. Type the program in a new file.
5. Save the file with .c extension.
6. Add file to the project.
7. Bulid the project.
8. Debug and run the project
9. Verify the output in data memory.





Program :

void main()
{
int m,n,i,j;
int x[10]={1,1,1,1};
int h[10] ={1,2,3};
static int y[20];
m =4;
n =3;
for(i=m;i<m+n;i++)
x[i]=0;
for(i=n;i<m+n;i++)
h[i]=0;
for(i=0;i<n+m-1;i++)
{
y[i]=0;
for(j=0;j<m;j++)
{
if(i-j>=0)
{
y[i] =y[i]+x[j]*h[i-j];
}
}
}

for(;;);
}


















Flow chart :
























Start
DECLARE M,N,I,J,AS INTEGER
CHECK WHETHER
i-j>=0

INITIALISE J=0
DECLARE X[10] SEQUENCE (INPUT)
INITIALISE i=0
DECLARE H[10] SEQUENCE (IMPULSE)
DECLARE OUTPUT SEQUENCE AS Y[20]
STORE M VALUE AS 4 & N AS 3
MAKE X[4] TO X[7] AS ZERO & H[3] TO
H[7] AS ZERO
Y[i]=0
CALCULATE Y[i] = Y[i]+X[j]+H[i-j]
A
B
C



NO


YES


NO

YES












INCREMENT
J & CHECK IF
j<M

INCREMENT i
& CHECK IF
i<M+N-1


WAIT IN INFINITE LOOP
Stop
A
B C
Simulation Output :







Result :
The convolution program in ADSP 2181 in visual DSP is performed and
output verified.

You might also like