Embedded system lab manual

embedded system lab manual for ece and embedded system tools reference manual
KomalMittal Profile Pic
KomalMittal,India,Teacher
Published Date:13-07-2017
Your Website URL(Optional)
Comment
LABORATORY MANUAL EMBEDDED SYSTEMS M. Tech – I Year – II Sem – R13 DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGG. BALAJI INSTITUTE OF TECHNOLOGY & SCIENCE Laknepally, Narsampet, Warangal 1 M. Tech – I Year – II Sem. (DIGITAL SYSTEMS & COMPUTER ELECTRONICS) EMBEDDED SYSTEMS LABORATORY (R13) Note: A. The following programs are to be implemented on ARM based Processors/Equivalent. B. Minimum of 10 programs from Part –I and 6 programs from Part -II are to be conducted. PART- I: The following Programs are to be implemented on ARM Processor 1. Simple Assembly Program for a. Addition Subtraction Multiplication Division b. Operating Modes, System Calls and Interrupts c. Loops, Branches 2. Write an Assembly programs to configure and control General Purpose Input/Output (GPIO) port pins. 3. Write an Assembly programs to read digital values from external peripherals and execute them with the Target board. 4. Program for reading and writing of a file 5. Program to demonstrate Time delay program using built in Timer / Counter feature on IDE environment 6. Program to demonstrates a simple interrupt handler and setting up a timer 7. Program demonstrates setting up interrupt handlers. Press button to generate an interrupt and trace the program flow with debug terminal. 8. Program to Interface 8 Bit LED and Switch Interface 9. Program to implement Buzzer Interface on IDE environment 10. Program to Displaying a message in a 2 line x 16 Characters LCD display and verify the result in debug terminal. 11. Program to demonstrate I2C Interface on IDE environment 12. Program to demonstrate I2C Interface – Serial EEPROM 13. Demonstration of Serial communication. Transmission from Kit and reception from PC using Serial Port on IDE environment use debug terminal to trace the program. 14. Generation of PWM Signal 15. Program to demonstrate SD-MMC Card Interface. PART- II: Write the following programs to understand the use of RTOS with ARM Processor on IDE Environment using ARM Tool chain and Library: 1. Create an application that creates two tasks that wait on a timer whilst the main task loops. 2. Write an application that creates a task which is scheduled when a button is pressed, which illustrates the use of an event set between an ISR and a task 3. Write an application that Demonstrates the interruptible ISRs(Requires timer to have higher priority than external interrupt button) 4. a).Write an application to Test message queues and memory blocks. b).Write an application to Test byte queues 5. Write an application that creates two tasks of the same priority and sets the time slice period to illustrate time slicing. Interfacing Programs: 6. Write an application that creates a two task to Blinking two different LEDs at different timings 7. Write an application that creates a two task displaying two different messages in LCD display in two lines. 8. Sending messages to mailbox by one task and reading the message from mailbox by another task. 9. Sending message to PC through serial port by three different tasks on priority Basis. 10. Basic Audio Processing on IDE environment. 2 1. Simple Assembly Program for a. Addition Subtraction Multiplication Division b. Operating Modes, System Calls and Interrupts c. Loops, Branches Addition of 4 numbers : Total = A+B+C+D Program: start MOV r0, r1; Make the first number the subtotal ADD r0, r0, r2; Add the second number to the subtotal ADD r0, r0, r3; Add the third number to the subtotal ADD r0, r0, r4; Add the fourth number to the subtotal stop B ; stop SUBTRACTION of 4 numbers : Total = A-B-C-D Program: start MOV r0, r1; Make the first number the subtotal SUB r0, r0, r2; Add the second number to the subtotal SUB r0, r0, r3; Add the third number to the subtotal SUB r0, r0, r4; Add the fourth number to the subtotal stop B ; stop MULTIPLIATION of 4 numbers : Total = A X B X C X D Program: start MOV r0, r1; Make the first number the subtotal MUL r0, r0, r2; Add the second number to the subtotal MUL r0, r0, r3; Add the third number to the subtotal MUL r0, r0, r4; Add the fourth number to the subtotal stop B ; stop DIVISION of 4 numbers : Total = A/B/C/D Program: start MOV r0, r1; Make the first number the subtotal DIV r0, r0, r2; Add the second number to the subtotal DIV r0, r0, r3; Add the third number to the subtotal DIV r0, r0, r4; Add the fourth number to the subtotal stop B ; stop 3 2 Write an assembly language program to compute ... 4x + 3x, . if xis stored in r1. Store the result in r0 start MUL r0, r1, r1; result x x LDR r2, =4; tmp 4 MUL r0, r2, r0; result 4 x x LDR r2, =3; tmp 3 MUL r2, r1, r2; tmp x tmp ADD r0, r0, r2; result result + tmp stop B stop II) Computing the greatest common divisor of two numbers using Euclid's GCD algorithm using branch instructions. MOV R0, 40 ; R0 is a MOV R1, 25 ; R1 is b again CMP R0, R1 SUBGT R0, R0, R1 SUBLT R1, R1, R0 BNE again halt B halt b)write a program to add numbers in an array using loop instruction addInts MOV R4, 0 addLoop LDR R2, R0 ADD R4, R4, R2 ADD R0, R0, 4 SUBS R1, R1, 1 BNE addLoop 4 2. Write an Assembly programs to configure and control General Purpose Input/Output (GPIO) port pins. / Examples Program For "CP-JR ARM7 USB-LPC2148" / / Target MCU : Philips ARM7-LPC2148 / / : X-TAL : 12.00 MHz / / : Run Speed 60.00 MHz (With PLL) / / : PLL Setup = M(5),P(2) / / : VPB Clock = CPU Clock = 60.00 MHz / / Keil Editor : uVision3 V3.03a / / Compiler : Keil CARM V2.50a / / Function : Example Used Fast GPIO Function / // // Connect P1.24 to LED For Test ON / OFF (Blink) include "LPC214x.H" // LPC2148 MPU Register / pototype section / void delay(unsigned long int); // Delay Time Function int main(void) // Enable GPIO Function //SCS = 0x00000001; // Enable GPIO0 = Fast GPIO Mode SCS = 0x00000002; // Enable GPIO1 = Fast GPIO Mode // xxxx xxx1 xxxx xxxx xxxx xxxx xxxx xxxx 5 FIO1MASK = 0xFEFFFFFF; // Enable GPIO124 = Fast GPIO Mode FIO1DIR = 0x01000000; // Set GPIO-124 = Output FIO1SET = 0x01000000; // Set GPIO-124 Output Pin(OFF LED) // Loop Test Output GPIO1.24 while(1) // Loop Continue FIO1CLR = 0x01000000; // Clear Output GPIO124 Pin (ON LED) delay(1000000); // Display Delay FIO1SET = 0x01000000; // Set Output GPIO124 Pin (OFF LED) delay(1000000); // Display Delay // / Delay Time Function / / 1-4294967296 / // void delay(unsigned long int count1) while(count1 0) count1; // Loop Decrease Counter 6 3. Write an Assembly programs to read digital values from external peripherals and execute them with the Target board. ( write a program to read digital values from eternal peripherals and execute them with the target board.) / Examples Program For "CP-JR ARM7 USB-LPC2148" / / Target MCU : Philips ARM7-LPC2148 / / : X-TAL : 12.00 MHz / / : Run Speed 60.00 MHz (With PLL) / / : PLL Setup = M(5),P(2) / / : VPB Clock = CPU Clock = 60.00 MHz / / Keil Editor : uVision3 V3.03a / / Compiler : Keil CARM V2.50a / / Function : Example Used DAC Generate Sinewave / // // P0.25 = DAC Output = Sinewave Signal include "LPC214x.H" // LPC2148 MPU Register include stdio.h // For Used Function printf int main(void) const static unsigned short table_sine64 = // Sine Function Table(12Bit) 0x07FF, 0x08C8, 0x098E, 0x0A51, 0x0B0F, 0x0BC4, 0x0C71, 0x0D12, 0x0DA7, 0x0E2E, 0x0EA5, 0x0F0D, 0x0F63, 0x0FA6, 0x0FD7, 0x0FF5, 0x0FFF, 0x0FF5, 0x0FD7, 0x0FA6, 0x0F63, 0x0F0D, 0x0EA5, 0x0E2E, 0x0DA7, 0x0D12, 0x0C71, 0x0BC4, 7 0x0B0F, 0x0A51, 0x098E, 0x08C8, 0x07FF, 0x0736, 0x0670, 0x05AD, 0x04EF, 0x043A, 0x038D, 0x02EC, 0x0257, 0x01D0, 0x0159, 0x00F1, 0x009B, 0x0058, 0x0027, 0x0009, 0x0000, 0x0009, 0x0027, 0x0058, 0x009B, 0x00F1, 0x0159, 0x01D0, 0x0257, 0x02EC, 0x038D, 0x043A, 0x04EF, 0x05AD, 0x0670, 0x0736 ; int i = 0; // Pointer // Initial DAC (GPIO-0.25) By Set PINSEL119:18=10 // xxxx xxxx xxxx 10xx xxxx xxxx xxxx xxxx PINSEL1 &= 0xFFF3FFFF; // Select DAC Pin Connect P0.25 PINSEL1 = 0x00080000; while(1) // Loop Continue // 10-Bit Data = xxxx xxxx xxxx xxxx DDDD DDDD DDxx xxxx DACR = ((table_sinei/4) 6); // Update DAC Sine Output //DACR = ((i 16) 6); // Update DAC SAW Output i++; // Next Pointer i &= 0x3F; // 0..63 8 5. Program to demonstrate Time delay program using built in Timer / Counter feature on IDE environment. (demonstrate Time delay program using built in timer/Counter feature on IDE environment) Timer functionality: include LPC214X.H main() // T0PR = 0x00000003; PINSEL0=0x00000020; T0CCR=0x00000004; T0TCR = 0x00000001; //T0MCR = 0x00000020; //T0MR1 = 0X0000000f; while(1); Counter functionality: include LPC214X.H void main() PINSEL0=0X00000020; T0TCR=0X01; T0CTCR=0X03; 9 7. Program to demonstrate setting up interrupt handlers. Press button to generate an interrupt and trace the program flow with debug terminal. / File Name : main.c Purpose : - This program describes the usage of GPIO pins to activate external interrupt pins Author : NTIL Engineers Date : Monday, November 01, 2004 Copyright or License : Monday, November 01, 2004 NTIL Algorithms : NONE Hardware notes : arm7TDMI controller Microcontroller : PHILIPS ARM 2104 Operating Speed : 14.7456 MHz - Revision History : Version 1.1.1 - Table Of Contents : main int0ISR int1ISR int2ISR ledOn ledOff ledInit delay ....HEADER FILES.... LPC210x.h 10 irq.h Description : Building and Running To run from FLASH: make flash connect to Philips UTILITY Download the program To run from RAM: make ram connect to GDB Download the program / include "LPC210x.h" include "irq.h" / Interrupt Servce Routine for Ecternal Interrupt0 / static void int0ISR(void) __attribute__ ((interrupt ("IRQ"))); / Interrupt Servce Routine for Ecternal Interrupt1 / static void int1ISR(void) __attribute__ ((interrupt ("IRQ"))); / Interrupt Servce Routine for Ecternal Interrupt2 / static void int2ISR(void) __attribute__ ((interrupt ("IRQ"))); / To make LED's On / static void ledOn(unsigned long int led); / To make LED's Off / static void ledOff(unsigned long int led); / Interrupt Servce Routine for Ecternal Interrupt0 / static void int0ISR(void); / Interrupt Servce Routine for Ecternal Interrupt1 / static void int1ISR(void); / Interrupt Servce Routine for Ecternal Interrupt2 / static void int2ISR(void); 11 / Configuring P0.0-P0.7 for LED's / static void ledInit(void); / To create Delay / static void delay(void); / Function name : Main Arguments : void Return Values : integer type Description : Program starts here / int main(void) / Configuring PINSEL0 register for Ext. Interrupts / PINSEL0=0XA0000000; PINSEL1=0X00000001; / Int0 is an IRQ interrupt / VICIntSelect &= 0x4000; / Enable Int0 interrupt / VICIntEnable = 0x4000; / Use slot 0 for Int0 interrupt / VICVectCntl0 = 0x2E; / Set the address of ISR for slot 0 / VICVectAddr0 = (unsigned int)int0ISR; / Int1 interrupt is an IRQ interrupt / VICIntSelect &= 0x8000; / Enable Int1 interrupt / VICIntEnable = 0x8000; / Use slot 1 for Int1 interrupt / 12 VICVectCntl1 = 0x2F; / Set the address of ISR for slot 1 / VICVectAddr1 = (unsigned int)int1ISR; / Int2 interrupt is an IRQ interrupt / VICIntSelect &= 0x10000; / Enable Int2 interrupt / VICIntEnable = 0x10000; / Use slot 2 for Int2 interrupt / VICVectCntl2 = 0x30; / Set the address of ISR for slot 2 / VICVectAddr2 = (unsigned int)int2ISR; / Function to Initialize LEDs / ledInit(); / Macro for Handling IRQ / enable_irq(); while (1) / End of MAIN Function / / Function name : int0ISR Arguments : void Return Values : void Description : Service Routine to Handle Int0 IRQ / static void int0ISR(void) ledOn(0x00000001); delay(); 13 ledOff(0x00000001); / Clear the Int0 interrupt / EXTINT=0X01; / Update VIC priorities / VICVectAddr = 0; / End of 'int0ISR' function / / Function name : int1ISR Arguments : void Return Values : void Description : Service Routine to Handle Int1 IRQ / static void int1ISR(void) ledOn(0x00000002); delay(); ledOff(0x00000002); / Clear the Int1 interrupt / EXTINT=0X02; / Update VIC priorities / VICVectAddr = 1; / End of 'int1ISR' function / / Function name : int2ISR Arguments : void 14 Return Values : void Description : Service Routine to Handle Int2 IRQ / static void int2ISR(void) ledOn(0x00000004); delay(); ledOff(0x00000004); / Clear the Int2 interrupt / EXTINT=0X04; / Update VIC priorities / VICVectAddr = 2; / End of 'int2ISR' function / / Function name : ledOn Arguments : unsigned long int Return Values : void Description : To make LEDs On / static void ledOn(unsigned long int led) / Makes LED ON / IOCLR = led; / End of 'ledOn' function / / Function name : ledOff 15 Arguments : unsigned long int Return Values : void Description : To Make LEDs Off / static void ledOff(unsigned long int led) / Makes LED Off / IOSET = led; / End of 'ledOff' function / / Function name : ledInit Arguments : void Return Values : void Description : To Configure I/O lines for LEDs / static void ledInit() / Making P0.0-P0.7 as Output Lines / IODIR = 0x000000FF; IOSET = 0x000000FF; / End of 'ledInit' function / / Function name : delay Arguments : void Return Values : void 16 Description : To create Delay / static void delay(void) int i,j; for(i=0;i500;i++) for(j=0;j100;j++); / End of 'delay' function / /End of File/ 17 8. Write a Program to Interface 8 Bit LED and Switch Interface. includelpc214x.h ///////////////////////////// Delay Function ////////////////////////// void main_delay( unsigned int value ) unsigned int ui_temp1,ui_temp2; // Delay Variables for(ui_temp1=0;ui_temp1value;ui_temp1++) //Delay loop for(ui_temp2=0;ui_temp25000;ui_temp2++); //Delay loop int main() IODIR0 = 0xffffffff; IODIR1 = 0xffffffff; while(1) IOSET0= 0xffffffff; IOSET1= 0xffffffff; main_delay(5000); IOCLR0= 0xffffffff; IOCLR1= 0xffffffff; main_delay(5000); 18 9. Program to implement Buzzer Interface on IDE environment includelpc214x.h define buzz 0x00000001 define buzz_on IOCLR0=buzz define buzz_off IOSET0=buzz void delay( unsigned int value ) unsigned int ui_temp1,ui_temp2; for(ui_temp1=0;ui_temp1value;ui_temp1++) for(ui_temp2=0;ui_temp25000;ui_temp2++); int main() IODIR0 =buzz; while(1) buzz_on; delay(2000); buzz_off; delay(2000); 19 10. Program to Displaying a message in a 2 line x 16 Characters LCD display and verify the result in debug terminal. includelpc214x.h // LPC2148 MPU Registers // Define LCD PinIO Mask define LCD_RS 0x00010000 // P1.16(0000 0000 0000 000x 0000 0000 0000 0000) define LCD_EN 0x00020000 // P1.17(0000 0000 0000 00x0 0000 0000 0000 0000) define LCD_D4 0x00040000 // P1.18(0000 0000 0000 0x00 0000 0000 0000 0000) define LCD_D5 0x00080000 // P1.19(0000 0000 0000 x000 0000 0000 0000 0000) define LCD_D6 0x00100000 // P1.20(0000 0000 000x 0000 0000 0000 0000 0000) define LCD_D7 0x00200000 // P1.21(0000 0000 00x0 0000 0000 0000 0000 0000) ///////////////////////////// Delay Function ////////////////////////// void main_delay( unsigned int value ) unsigned int ui_temp1,ui_temp2; // Delay Variables for(ui_temp1=0;ui_temp1value;ui_temp1++) //Delay loop for(ui_temp2=0;ui_temp25000;ui_temp2++); //Delay loop /////////////////////// LCD Command Sending Function///////////////////// void lcd_cmd(unsigned char val) unsigned int lcd_ch; // LCD Initial Data unsigned int lcd_i; // LCD Initial Delay Count IOCLR1 = LCD_RS ; // RS = 0 lcd_ch=((val4)&0x0F); // Strobe 4-Bit High-Nibble to LCD IOCLR1 = (LCD_D7LCD_D6LCD_D5LCD_D4); // Reset 4-Bit Pin Data IOSET1 = (lcd_ch18); // Data Send to Respective Pins IOSET1 = LCD_EN ; // EN = 1 (Enable) for (lcd_i=0;lcd_i10000;lcd_i++); //delay IOCLR1 = LCD_EN ; // EN = 0 (Disable) lcd_ch=(val&0x0F); // Strobe 4-Bit Low-Nibble to LCD IOCLR1 = (LCD_D7LCD_D6LCD_D5LCD_D4); // Reset 4-Bit Pin Data IOSET1 = (lcd_ch18); // EN,0,RW,RS:DDDD:0000:0000:0000:0000:0000:0000 IOSET1 = LCD_EN ; // EN = 1 (Enable) for (lcd_i=0;lcd_i10000;lcd_i++); //delay 20