Es - It - 2022
Es - It - 2022
COMMUNICATION TECHNOLOGY
       Embedded Systems
         Lab Manual
          [ICT 3164]
         Semester: V
         B. Tech (IT)
                                       CONTENTS
2 ARITHMETIC PROGRAMS 14
9 PWM INTERFACING 50
APPENDIX A 62
APPENDIX B 65
APPENDIX C 69
                                            i
Course Objectives
     To develop skills in real world interfacing circuits.
     To efficiently design software for embedded systems.
     To design software for IoT applications.
Course Outcomes
At the end of this course, students will be able to
     Design real world interfacing circuits to a microcontroller
     Develop software for embedded systems.
     Propose architectural solutions for IoT applications.
     Develop software for IoT applications.
                                        iii
ES LAB MANUAL                                             Start up Keil U Vision4
Before you start up, you are recommended that you create a folder to hold all your project
files. For example: you can create a folder "FirstARM-Project" ready before hand.
Step1:
You can start up uVision4 by clicking on the icon         from the desktop or from the
"Start" menu or "All Programs" on a lab PC. The following screen is what you will see:
To create a project, click on the "Project" menu from the uVision4 screen and select "New
uVision Project...".
1|Page
ES LAB MANUAL                                          Start up Keil U Vision4
From the "Select Device for Target" window, select "NXP" as the vendor. In that select
LPC1768 ARM controller , then click on OK button
2|Page
ES LAB MANUAL                                           Start up Keil U Vision4
Make sure you click on "NO" for the following pop up window.
From the "File" menu, select "New", you will see the "Text1*" text edit window. That is
the place you will write your ARM Assembly language program. You can write the
program into this window. (Note: give a tab space at the beginning)
3|Page
ES LAB MANUAL                                         Start up Keil U Vision4
Save the program by clicking on the "Save" or "Save As" from the "File" menu and give
it a name.
4|Page
ES LAB MANUAL                                               Start up Keil U Vision4
Right click on the "Source Group 1", select "Add Files to Group 'Source Group 1'".
Select "Files of type" as "asm Source file (*.s*;*.src*;*.a*), then select the file
"FirstARM.s" for example. Click on "Add", and then click on "Close".
Click on the "+" beside the "Source Group 1", you will see the program "FirstARM.s".
Click on the "Build" button or from the "Project" menu, you will see the following screen.
5|Page
ES LAB MANUAL                                        Start up Keil U Vision4
Click on "OK" for the pop up window showing "EVALUATION MODE, Running with
Code Size Limit: 32K".
Open uVision4 to full screen to have a better and complete view. The left hand side
window shows the registers and the right side window shows the program code. There
are some other windows open. Adjust the size of them to have better view.
Run the program step by step; observe the change of the values in the registers.
6|Page
ES LAB MANUAL                                              Start up Keil U Vision4
To trace the program use the Step Over button or click on Step Over from the Debug
menu. It executes the instructions of the program one after another. To trace the program
one can use the Step button, as well. The difference between the Step Over and Step is
in executing functions. While Step goes into the function and executes its instructions
one by one, Step Over executes the function completely and goes to the instruction next
to the function. To see the difference between them, trace the program once with Step
Over and then with Step. When PC executing the function and want the function to be
executed completely one can use Step Out. In the case, the instructions of the function
will be executed, it returns from the function, and goes to the instruction which is next to
the function call.
7|Page
ES LAB MANUAL                                          Start up Keil U Vision4
Click on the "Start/Stop Debug Session" again to stop execution of the program.
These are:
8|Page
ES LAB MANUAL                                              Start up Keil U Vision4
Application entry
The ENTRY directive declares an entry point to the program. It marks the first instruction
to be executed. In applications using the C library, an entry point is also contained within
the C library initialization code. Initialization code and exception handlers also contain
entry points.
Application execution
The application code begins executing at the label start, where it loads the decimal values
10 and 3 into registers R0 and R1. These registers are added together and the result placed
in R0.
Program end
The END directive instructs the assembler to stop processing the source file. Every
assembly language source module must finish with an END directive on a last line. Any
lines following the END directive are ignored by the assembler.
9|Page
ES LAB MANUAL                  LAB 1: Data Transfer and Arithmetic Programs
                                   Lab 1
                   Data Transfer and Arithmetic Programs
Question: Write a ARM assembly language program to copy 16 bit variable from code
memory to data memory.
   __Vectors
        DCD 0x10001000         ; stack pointer value when stack is empty
       DCD Reset_Handler ; reset vector
ALIGN
   Reset_Handler
10 | P a g e
ES LAB MANUAL                  LAB 1: Data Transfer and Arithmetic Programs
END
Observations to be made
    1. Data storage into the memory: Click on Memory window you get label
       Memory1 option type address pointed by R0 in address space and observe how
       the data are stored into the memory.
    2. Data movement from one memory to another memory: Click on Memory
       window you get label Memory2 option type address pointed by R1 in address
       space and observe data movement to another location before execution and after
       execution.
   Exercise questions
    1. Write an ARM assembly language program to transfer block of ten 32 bit numbers
        from one memory to another
                    a. When the source and destination blocks are non-overlapping
                    b. When the source and destination blocks are overlapping
       Hint: Use Register indirect addressing mode or indexed addressing mode
11 | P a g e
ES LAB MANUAL                               Lab 2: Arithmetic Programs
                                    Lab 1
                              Arithmetic Programs
   __Vectors
        DCD 0x40001000       ; stack pointer value when stack is empty
       DCD Reset_Handler ; reset vector
        ALIGN
   AREA mycode, CODE, READONLY
        ENTRY
        EXPORT Reset_Handler
   Reset_Handler
        LDR R0, =VALUE1      ;pointer to the first value1
        LDR R1,[R0]          ;load the first value into R1
        LDR R0,=VALU2        ;pointer to the second value
        LDR R3, [R0]         ;load second number into r3
        ADDS R6, R1,R3       ;add two numbers and store the result in r6
        LDR R2, =RESULT
        STR R6,[R2]
   STOP
        B STOP
   VALUE1 DCD 0X12345678            ; First 32 bit number
   VALUE2 DCD 0XABCDEF12            ; Second 32 bit number
        AREA data, DATA, READWRITE
   RESULT DCD 0
12 | P a g e
ES LAB MANUAL                              Lab 2: Arithmetic Programs
Exercise questions
       1. Write a program to add ten 32 bit numbers stored in code segment and store
          the result in data segment
       2. Write a program to add two 128 bit numbers stored in code segment and store
          the result in data segment.
          Hint: Use indexed addressing mode.
       3. Write a program to subtract two 128 bit numbers
13 | P a g e
ES LAB MANUAL                                Lab 2: Arithmetic Programs
                                      Lab 2
                                Arithmetic Programs
   __Vectors
        DCD 0x40001000          ; stack pointer value when stack is empty
       DCD Reset_Handler ; reset vector
ALIGN
   Reset_Handler
                LDR R0, =VALUE1       ;pointer to the first value1
                LDRH R1,[R0]          ;load the first value into r1
                LDR R0,=VALU2         ;pointer to the second value
                LDRH R3, [R0]         ;load second number into r3
                MUL R6, R1,R3         ;Multiply the values from R1 and R3 and store
                                      ;least significant 32 bit number into R6.
                LDR R2, =RESULT
                STR R6,[R2]           ; store result in r6
        STOP
                B STOP
14 | P a g e
ES LAB MANUAL                               Lab 2: Arithmetic Programs
   __Vectors
        DCD 0x40001000         ; stack pointer value when stack is empty
        DCD Reset_Handler ; reset vector
        ALIGN
        AREA mycode, CODE, READONLY
        ENTRY
        EXPORT Reset_Handler
   Reset_Handler
                MOV R2,#00
                LDR R0, =VALUE1      ;pointer to the first value1
                LDR R1,[R0]          ;load the first value into r1
                LDR R0,=VALUE2       ;pointer to the second value
                LDR R3, [R0]         ;load second number into r3
        up      SUB R1, R3           ;Subtract two numbers
                ADD R2,#01           ;increment a counter
                CMP R1,R3            ;compare two numbers
                BCS up               ;check R1is greater than R3 or not, if yes loop
                LDR R6, =RESULT      ;Quotient
                STR R2,[R6,#4]
                STR R1,[R6]          ;Store remainder.
        STOP
15 | P a g e
ES LAB MANUAL                              Lab 2: Arithmetic Programs
               B STOP
        VALUE1 DCD 0x200000000 ;First 32 bit number
        VALUE2 DCD 0x00050000     ;Second 16 bit number
               AREA data, DATA, READWRITE
        RESULT DCD 0,0
Exercise questions
} Return (a);
16 | P a g e
ES LAB MANUAL                              Lab 2: Arithmetic Programs
17 | P a g e
ESLAB MANUAL                                   LAB3: Code Conversion Programs
                                    Lab 3
                           Code Conversion Programs
   __Vectors
        DCD 0x40001000         ; stack pointer value when stack is empty
       DCD Reset_Handler ; reset vector
        ALIGN
        AREA mycode, CODE, READONLY
        ENTRY
        EXPORT Reset_Handler
Reset_Handler
                LDR R0,=NUM
                LDR R3,=RESULT
                LDRB R1,[R0]         ; load hex number into register R1
                AND R2,R1,#0x0F      ; mask upper 4 bits
                CMP R2,#09           ; compare the digit with 09
                BLO DOWN             ; if it is lower than 9 then jump to down
                                     ; lable
                ADD R2,#07           ;else add 07 to that number
        DOWN
                ADD R2,#0x30         ; Add 30H to the number, Ascii value of first
                STRB R2,[R3]         ; digit
                AND R3,R1,#0xF0      ; Mask the second digit
                MOV R3,R3,LSR#04 ; Shift right by 4 bits
                CMP R3,#09           ; check for >9 or not
                BLO DOWN1
18 | P a g e
ESLAB MANUAL                               LAB3: Code Conversion Programs
               ADD R3,#07
        DOWN1
               ADD R3,#0x30         ; Ascii value of second digit
               STRB R3,[R2,#01]
               END
        NUM DCD 0x000003A
               AREA data, DATA, READWRITE
        RESULT DCD 0
Exercise programs
Additional Exercise
19 | P a g e
ES LAB MANUAL                            LAB5: Interfacing LED to ARM Controller
                                  Lab 4
                  Programs on Sorting, Searching and Stack
   __Vectors
               DCD 0x40001000       ; stack pointer value when stack is empty
               DCD Reset_Handler ; reset vector
               ALIGN
               AREA ascend, code, readonly
               ENTRY
        Reset_Handler
               mov r4,#0
               mov r1,#10
               ldr r0, =list
               ldr r2, =result
        up     ldr r3, [r0,r4]
               str r3, [r2,r4]
               add r4, #04
               sub r1,#01
               cmp r1,#00
               bhi up
               ldr r0, =result
                                           ; inner loop counter
               mov r3, #10
               sub r3, r3, #1
               mov r9, r3                  ; R9 contain no of passes
                                           ; outer loop counter
        outer_loop
               mov r5, r0
20 | P a g e
ES LAB MANUAL                                LAB5: Interfacing LED to ARM Controller
Exercise questions:
Additional Exercise
    1. Assume that ten 32 bit numbers are stored in registers R0-R10. Sort these numbers
       in the fully ascending stack using selection sort and store the sorted array back
       into the registers. Use STM and LDMDB instructions wherever necessary.
    2. Repeat the above question (4) for fully descending stack using STMDB and LDM
       instruction wherever necessary.
21 | P a g e
ES LAB MANUAL                              LAB5: Interfacing LED to ARM Controller
                                   Lab 5
                  Interfacing LED to ARM Microcontroller
Aim: Interface LEDs to the ARM cortex LPC1768 microcontroller using ALS interfacing
 board.
Steps to be followed:
Project Creation in Keil uvision4 IDE:
    • Create a project folder before creating NEW project.
    • Use separate folder for each project
    • Open Keil uVision4 IDE software by double clicking on “Keil Uvision4” icon.
    • Select “Project” then to “New Project” and save it with a name in the respective
       Project folder, which is already you created.
    • Select the device as “NXP (founded by Philips)” Select “LPC1768” then Press
       “OK” and then press “YES” button to add “system_LPC17xx.s” file.
    • Go to “File” select “New” to open an editor window. Create a source file and use
       the header file “LPC17xx.h” in the source file and save the file. Color syntax
       highlighting will be enabled once the file is saved with a Recognized extension
       such as “.C “.
    • Right click on “Source Group 1” and select the option “Add Files to Group 'Source
       Group 1' “add the. C source file(s) to the group.
    • Again right click on Source Group 1 and select the option “Add Files to
       Group        'Source         Group        1'      “add          the       file     -
       C:Keil\ARM\startup\NXP\LPC17xx\system_LPC17xx.c
    • Any changes made to this file at current project will directly change the
       source system_LPC17xx.C file. As a result other project settings may get
       altered. So it is recommended to copy the file
       C:Keil\ARM\startup\NXP\LPC17xx\system_LPC17xx.c to the project folder
       and add to the source group.
    • Important: This file should be added during each project creation.
    • Select “Project” then select “Translate” to compile the File (s).
    • Select “Project” , select “Build Target” for building all source files such as
       “.C”,”.ASM”, “.h”, files, etc…This will create the hex file if there are no warnings
       & no errors.
22 | P a g e
ES LAB MANUAL                          LAB5: Interfacing LED to ARM Controller
Note: Before writing the program please check GPIO port pins available in the kit
(Refer Appendix C.)
#include <LPC17xx.h>
               int main(void)
               {
                 SystemInit()            ;Add these two function for its
;internal operation
SystemCoreClockUpdate();
                LPC_GPIO0->FIODIR |= 0x00000FF0;
                                      ;Configure P0.4-P0.11 as output
                                      ;port
                while(1)
                    {
                         LED = 0x00000010; Initial value on LED
                         for(i=1;i<9;i++)     //On the LED's serially
                         {
                           LPC_GPIO0->FIOSET = LED;
23 | P a g e
ES LAB MANUAL                         LAB5: Interfacing LED to ARM Controller
;unit.
LED = 0x00000010;
                    }
               }
       In Project Window Right click “TARGET1” and select “options for target
        ‘TARGET1’ select to option “Target” in that select
               1. XTAL 12.0MHz
               2. Select IROM1 (starting 0×0 size 0×8000).
               3. Select IRAM1 (starting 0×10000000 size 0×8000).
       Then go to option “Output”
               Select “Create Hex file”.
       Then go to option “Linker”
               Select use memory layout from target dialog
24 | P a g e
ES LAB MANUAL                             LAB5: Interfacing LED to ARM Controller
        • There are three clock sources for CPU. Select Oscillator clock out of three.
          This selection is done by CLKSRCSEL register.
        • If we disable the PLL0 System clock will be bypassed directly into CPU clock
          divider register.
        • Use CCLKCFG register for choosing the division factor of 4 to get 3MHz out
          of 12 MHz Oscillator frequency
        • For any other peripherals use the PCLK same as CCLK.
   Components required
   • ALS-SDA-ARMCTXM3-01 :                                  1 No.
   • Power supply (+5V) :                                   1 No.
   • Cross cable for programming and serial communication : 1 No
   • One working USB port in the host computer system and PC for
   downloading the software.
   • 10 core FRC cables of 8 inch length                    2 No
   • USB to B type cable                                    1 No
26 | P a g e
ES LAB MANUAL                            LAB5: Interfacing LED to ARM Controller
               Oscillator:     12MHz
        b. ERASE:
               Select “Erase Blocks Used by Hex File”.
        c. Hex file:
           Browse and select the Hex file which you want to download.
        d. Options:
               Select “Verify After Programming”.
        Go to Options -> Advanced Options->communications.
               Do not select High Speed Communications, keep baud rate 115200.
        Options -> Advanced Options->Hardware config
                       Select Use DTR & RTS to control RST & ISP Pin.
                       Select Keep RTS asserted while COM Port open.
                       T1 = 50ms. T2 = 100ms.
        Step5.Start:
              Click “Start” to download the hex file to the controller.
        Step6. Connect one end of 10 pin FRC cable to CNA1, Short other end to CNA
        Step7. Press reset controller switch SW1 and Check output on the LEDs
               connected to CNA1.
  Exercise Questions:
  1. Write a C program to display 8-bit binary up counter on the LEDs.
  2. Write a C program to read a key and display an 8-bit up/down counter on the LEDs.
      Hint: Use key SW2(if SW2=1, up counter else down counter), which is available
      at CNB1 pin 7. Connect CNB1 to any controller connector like CNB, CNC etc.
      Configure corresponding port pin as GPIO using corresponding PINSEL register
      and input pin using corresponding FIODIR register.
Additional Exercise:
  3. Write a program to simulate an 8- bit ring counter with key press (SW2).
27 | P a g e
ES LAB MANUAL                         LAB6: Programs on multiplexed seven segment
                                   Lab 6
               Programs on Multiplexed Seven Segment Display
Aim: To interface and understand the working of multiplexed seven segments display.
   Introduction:
   There are four multiplexed 7-segment display units (U8, U9, U10 and U11) on the
   board. Each display has 8-inputs SEG_A (Pin-7), SEG_B (Pin-6), SEG_C (Pin-4),
   SEG_D (Pin-2), SEG_E (Pin-1), SEG_F (Pin-9), SEG_G (Pin-10) and SEG_H (Pin-
   5) and the remaining pins pin-3 & pin-8 are Common Cathode CC. These
   segments are common cathode type hence active high devices.
   At power on all the segments are pulled up. A four bits input through CNB2 is used
   for multiplexing operation. A 1-of-10 Decoder/Driver U7 is used to accept BCD inputs
   and provide appropriate outputs for enabling the required display.
   8 bits data is provided in this block using CNA2. All the data lines are taken buffered
   at U12 before giving to the displays.
28 | P a g e
ES LAB MANUAL                         LAB6: Programs on multiplexed seven segment
At controller end any 2 connector are required for interfacing this block.
29 | P a g e
ES LAB MANUAL                                  LAB6: Programs on multiplexed seven segment
 #include <LPC17xx.h>
 #include <stdio.h>
 int main(void)
 {
     SystemInit();
     SystemCoreClockUpdate();
30 | P a g e
ES LAB MANUAL                  LAB6: Programs on multiplexed seven segment
        while(1)
        {
             Delay();
             dig_count +=1;
             if(dig_count == 0x05)
                  { dig_count = 0x00;
                                            }
               if(one_sec_flg == 0xFF)
               {
                    one_sec_flg = 0x00;
                    dig1 +=1;
                    if(dig1 == 0x0A)
                    {
                         dig1 = 0;
                         dig2 +=1;
                         if(dig2 == 0x0A)
                         {
                              dig2 = 0;
                              dig3+=1;
                               if(dig3 == 0x0A)
                               {
                                    dig3 = 0;
                                    dig4 += 1;
                                       if(dig4 == 0x0A)
                                       {
                                            dig4 = 0;
                                       } //end of dig4
} //end of dig3
                         } //end of dig2
31 | P a g e
ES LAB MANUAL                   LAB6: Programs on multiplexed seven segment
} //end of dig1
} //end of one_sec if
Display();
} //end of while(1)
}//end of main
        }
        temp1 &= 0x0F;
        temp2 = array_dec[temp1]; // Decoding to 7-segment
        temp2 = temp2 << 4;
        LPC_GPIO0->FIOPIN = temp2; // Taking Data Lines for 7-Seg
32 | P a g e
ES LAB MANUAL                      LAB6: Programs on multiplexed seven segment
        for(i=0;i<500;i++);
        LPC_GPIO0->FIOCLR = 0x00000FF0;
//      LPC_GPIO1->FIOPIN = DISABLE_ALL;//disable all the segments
 }
Void delay(void)
 { unsigned int i;
     For(i=0;i<1000;i++);
     if(twenty_count ==1000)               //multiplied by 500x2msec for
                                           //1 Sec
        {
               one_sec_flg = 0xFF;
               twenty_count = 0x00;
        }
        else twenty_count += 1;
Components required
  • ALS-SDA-ARMCTXM3-01 :                                  1 No.
  • Power supply (+5V) :                                   1 No.
  • Cross cable for programming and serial communication : 1 No
  • One working USB in the host computer system and PC for downloading
  the software.
  • 10 core FRC cables of 8 inch length                    2 No
  • USB to B type cable                                    1 No
Hardware setup: Connect a 10 core FRC cable from CNA to CNA2 and CNB to CNB2.
Working procedure: After software download and hardware setup, press the reset,
Observe the count from 0000 to 9999 on the display.
Exercise Questions:
  1. Write a C program for 4 digit BCD up/down counter on seven segment using a
      switch and timer with a delay of 1-second between each count.
Additional Exercise:
   1. Write a C program to simulate a 4 digit BCD down counter. Use timer for a delay
33 | P a g e
ES LAB MANUAL                       LAB6: Programs on multiplexed seven segment
    2. Write a program for 4 digit Hexadecimal up/down counter on seven segment using
       a switch and timer with a delay of 1-second between each count.
34 | P a g e
       ES LAB MANUAL                 LAB 7: LCD and KEYBOARD Interfacing
                                  Lab 7
         Liquid Crystal Display (LCD) and Keyboard Interfacing
Aim: To interface and understand the working of LCD and matrix keyboard.
Introduction:
LCD: A 16×2 alphanumeric LCD can be used to display the message from controller.
16 pin small LCD has to be mounted to the connector CN11. 10 pin connector CNAD is
used to interface this LCD from controller. Only higher 4 data lines are used among the
8 LCD data lines. Use POT3 for contrast adjustment and Short the jumper JP16 to use
this LCD. LCD connector CN11 is described in this table. CN11 is single row 16 pin
female berg.
35 | P a g e
       ES LAB MANUAL   LAB 7: LCD and KEYBOARD Interfacing
36 | P a g e
       ES LAB MANUAL              LAB 7: LCD and KEYBOARD Interfacing
#include <lpc17xx.h>
void   lcd_init(void);
void   wr_cn(void);
void   clr_disp(void);
void   delay_lcd(unsigned int);
void   lcd_com(void);
void   wr_dn(void);
void   lcd_data(void);
void   clear_ports(void);
void   lcd_puts(unsigned char *);
int main(void)
{
     unsigned long adc_temp;
     unsigned int i;
     float in_vtg;
     unsigned char vtg[7],dval[7];
     unsigned char Msg3[11] = {"MIT"};
     unsigned char Msg4[12] = {"Department of ICT:"};
        SystemInit();
        SystemCoreClockUpdate();
        lcd_init();
        temp1 = 0x80;
             lcd_com();
             delay_lcd(800);
             lcd_puts(&Msg3[0]);
               temp1 = 0xC0;
               lcd_com();
               delay_lcd(800);
               lcd_puts(&Msg4[0]);
37 | P a g e
       ES LAB MANUAL          LAB 7: LCD and KEYBOARD Interfacing
     }
//lcd initialization
 void lcd_init()
 {
     /* Ports initialized as GPIO */
    LPC_PINCON->PINSEL3 &= 0xFC003FFF;     //P0.23 to P0.28
      clear_ports();
       delay_lcd(3200);
        temp2 = (0x30<<19);
        wr_cn();
        delay_lcd(30000);
        temp2 = (0x30<<19);
        wr_cn();
        delay_lcd(30000);
        temp2 = (0x30<<19);
        wr_cn();
        delay_lcd(30000);
        temp2 = (0x20<<19);
        wr_cn();
        delay_lcd(30000);
        temp1 = 0x28;
        lcd_com();
        delay_lcd(30000);
        temp1 = 0x0c;
        lcd_com();
        delay_lcd(800);
        temp1 = 0x06;
        lcd_com();
        delay_lcd(800);
        temp1 = 0x01;
38 | P a g e
       ES LAB MANUAL        LAB 7: LCD and KEYBOARD Interfacing
        lcd_com();
        delay_lcd(10000);
       temp1 = 0x80;
       lcd_com();
       delay_lcd(800);
      return;
 }
 void lcd_com(void)
 {
     temp2 = temp1 & 0xf0;//move data (26-8+1) times : 26 - HN
                           //place, 4 - Bits
     temp2 = temp2 << 19; //data lines from 23 to 26
     wr_cn();
     temp2 = temp1 & 0x0f; //26-4+1
     temp2 = temp2 << 23;
     wr_cn();
     delay_lcd(1000);
    return;
 }
 void clr_disp(void)
 {
     temp1 = 0x01;
     lcd_com();
     delay_lcd(10000);
    return;
 }
 void clear_ports(void)
 {
    /* Clearing the lines at power on */
     LPC_GPIO0->FIOCLR = DT_CTRL; //Clearing data lines
     LPC_GPIO0->FIOCLR = RS_CTRL; //Clearing RS line
     LPC_GPIO0->FIOCLR = EN_CTRL; //Clearing Enable line
      return;
 }
40 | P a g e
        ES LAB MANUAL                 LAB 7: LCD and KEYBOARD Interfacing
       while(buf1[i]!='\0')
       {
            temp1 = buf1[i];
         lcd_data();
               i++;
            if(i==16)
               {
                    temp1 = 0xc0;
                    lcd_com();
               }
          }
       return;
 }
     Components required
     • ALS-SDA-ARMCTXM3-01 :                                 1 No.
     • Power supply (+5V) :                                  1 No.
     • Cross cable for programming and serial communication: 1 No
     • One working USB port in the host computer system and PC for downloading
       the software.
     • 10 core FRC cables of 8 inch length                   2 No
     • USB to B type cable                                   1 No
     Hardware setup:
     Connect 10 pin FRC cable from CND to CNAD. Short the jumper JP16 & JP5.
     Use POT3 for contrast adjustment.
     Working procedure: After software download and hardware setup, press the
     reset. A fixed message will display on LCD.
     Exercise Questions:
     1. Simulate DIE tossing on LCD
         Hint: Program reads the external interrupt using the key SW2. A random number
         between 0-6 should be displayed on the LCD upon keypress.
41 | P a g e
       ES LAB MANUAL                 LAB 7: LCD and KEYBOARD Interfacing
42 | P a g e
       ES LAB MANUAL               LAB 7: LCD and KEYBOARD Interfacing
Sample program: To read a key from the matrix keyboard and display its key code on
the LCD.
   #include <LPC17xx.h>
      void scan(void);
temp = var1;
                            LPC_GPIO2->FIOCLR = 0x00003C00;
                            LPC_GPIO2->FIOSET = var1;
                            flag = 0;
                            scan();
43 | P a g e
       ES LAB MANUAL              LAB 7: LCD and KEYBOARD Interfacing
                          if(flag == 1)
                          break;
} //end for(row=1;row<5;row++)
                    if(flag == 1)
                    break;
} //2nd while(1)
void scan(void)
      {
           unsigned long temp3;
               temp3 = LPC_GPIO0->FIOPIN;
               temp3 &= 0x0780000;
               if(temp3 != 0x00000000)
               {
                          flag = 1;
                    if (temp3 ==0x0080000)
                          col=0;
                    else if (temp3==0x0100000)
                          col=1;
                    else if (temp3==0x00200000)
                          col=2;
                    else if (temp3==0x0400000)
                          col=3;
   Hardware setup: Connect 10 core FRC cable from CNB to CNB3, short JP4(1, 2)
   Connect another 10 core FRC cable from CND to CNAD, Short the jumper JP16
   & JP5. Use POT3 for contrast.
   Working procedure: After software download and hardware setup, use the reset.
   Identity of key pressed (0 to F) will be displayed on LCD.
   Exercise questions:
   1. Write a program to input an expression of the type A operator B =, from the key
      board, where A and B are the single digit BCD numbers and operator may be + or
      - .Display the result on the LCD.
45 | P a g e
ES LAB MANUAL                                 LAB 9: PWM Interfacing
                                    Lab 8
                      Analog to Digital Convertor (ADC)
   Sample program: To configure and read analog data from ADC channel no 5, and
   display the digital data on the LCD
        #include<LPC17xx.h>
        #include<stdio.h>
        #include"AN_LCD.h"
        #define    Ref_Vtg          3.300
        #define    Full_Scale 0xFFF                        //12 bit ADC
int main(void)
     {
     unsigned long adc_temp;
     unsigned int i;
     float in_vtg;
     unsigned char vtg[7],dval[7];
     unsigned char Msg3[11] = {"ANALOG IP:"};
     unsigned char Msg4[12] = {"ADC OUTPUT:"};
        SystemInit();
        SystemCoreClockUpdate();
46 | P a g e
ES LAB MANUAL                           LAB 9: PWM Interfacing
SystemCoreClockUpdate();
        temp1 = 0x80;
        lcd_com();
        delay_lcd(800);
        lcd_puts(&Msg3[0]);
        temp1 = 0xC0;
        lcd_com();
        delay_lcd(800);
        lcd_puts(&Msg4[0]);
     while(1)
     {
           LPC_ADC->ADCR = (1<<5)|(1<<21)|(1<<24);//0x01200001;
     //ADC0.5, start conversion and operational
           //for(i=0;i<2000;i++);     //delay for conversion
           while((adc_temp = LPC_ADC->ADGDR) == 0x80000000);
     //wait till 'done' bit is 1, indicates conversion complete
           adc_temp = LPC_ADC->ADGDR;
           adc_temp >>= 4;
           adc_temp &= 0x00000FFF;               //12 bit ADC
           in_vtg = (((float)adc_temp *
(float)Ref_Vtg))/((float)Full_Scale); //calculating input analog
                                      //voltage
           sprintf(vtg,"%3.2fV",in_vtg);
//convert the readings into string to display on LCD
           sprintf(dval,"%x",adc_temp);
           for(i=0;i<2000;i++);
               temp1 = 0x8A;
               lcd_com();
               delay_lcd(800);
               lcd_puts(&vtg[0]);
               temp1 = 0xCB;
               lcd_com();
               delay_lcd(800);
               lcd_puts(&dval[0]);
               for(i=0;i<200000;i++);
47 | P a g e
ES LAB MANUAL                                   LAB 9: PWM Interfacing
               for(i=0;i<7;i++)
               vtg[i] = dval[i] = 0x00;
               adc_temp = 0;
               in_vtg = 0;
        }
}
    Components required
    ALS-SDA-ARMCTXM3-01 :                                  1 No.
    Power supply (+5V) :                                   1 No.
    Cross cable for programming and serial communication : 1 No
    One working COM port (Ex: COM1) in the host computer system and PC
     for downloading the software.
    10 core FRC cables of 8 inch length                    2 No
    USB to B type cable                                    1 No
    Exercise question
    a. Write a c program to display the digital value representing the difference in analog
       voltages at ADC channel 4 and channel 5 on LCD.
48 | P a g e
ES LAB MANUAL                                 LAB 9: PWM Interfacing
                                 Lab 9
                Pulse Width Modulation (PWM) Interfacing
Introduction: The PWM is based on the standard Timer block and inherits all of
its features, although only the PWM function is pinned out on theLPC1768. The Timer
is designed to count cycles of the system derived clock and optionally switch pins,
generate interrupts or perform other actions when the specified timer values occur, based
on seven match registers. The PWM function is in addition to these features, and is based
on match register events. A PWM output from the controller can be observed as an
intensity variation of the LED LD10.
int main(void)
{
       SystemInit();
       SystemCoreClockUpdate();
       pwm_init();
       while(1)
       {
       for(i=0;i<=1000;i++); // delay
  }//end of while
49 | P a g e
ES LAB MANUAL                             LAB 9: PWM Interfacing
}//end of main
void pwm_init(void)
{
       LPC_SC->PCONP |= (1<<6);     //PWM1 is powered
       LPC_PINCON->PINSEL3 &= ~(0x0000C000);      //cleared if any other
                                                 //functions are enabled
       LPC_PINCON->PINSEL3 |= 0x00008000; //pwm1.4 is selected for the pin
                                          //P1.23
        NVIC_EnableIRQ(PWM1_IRQn);
        return;
}
void PWM1_IRQHandler(void)
{
      LPC_PWM1->IR = 0xff; //clear the interrupts
        if(flag == 0x00)
          {
                LPC_PWM1->MR4 += 100;
                LPC_PWM1->LER = 0x000000FF;
               {
                   flag1 = 0xff;
        flag = 0xff;
        LPC_PWM1->LER = 0x000000fF;
                 }
        }
         else if(flag1 == 0xff)
          {
                 LPC_PWM1->MR4 -= 100;
                 LPC_PWM1->LER = 0x000000fF;
Exercise question:
  Write a program to set the following intensity levels to the LED connected to PWM
  output. Use ROW-0 of keyboard for intensity variation
       Intensity level                             Key pressed
       10%                                         0
       25%                                         1
       50%                                         2
       75%                                         3
51 | P a g e
ES LAB MANUAL              LAB 10, LAB11: Familiarization with ARM mbed Board
                                 Lab 10 , Lab11
               Familiarization with ARM mbed Prototyping Board
Aim: Familiarize with ARM mbed NXP LPC1768 prototyping board by interfacing with
LEDs.
52 | P a g e
ES LAB MANUAL             LAB 10, LAB11: Familiarization with ARM mbed Board
Components Required:
 • An mbed microcontroller
 • A USB cable for connecting the microcontroller and PC.
 • A PC with one working USB port for flashing the code.
To build the programs either using the ARM mbed Online Compiler or ARM mbed Studio
could be used.
Steps to be followed for using the online compiler:
   1. Connect the mbed microcontroller to a PC. The status light will glow, indicating
       power on.The PC will recognize the mbed microcontroller as a standard USB
       drive.
   2. Go to the new USB drive, and click on MBED.HTML to open it in a web browser.
   3. Create an mbed account using your learner id (Username: your registration
       number). To use the online compiler, you will need to verify your email address.
       URL: https://os.mbed.com/account/signup/
   4. Click on the “Compiler” tab in the dashboard page, as shown in Figure 12.2.
    5. Create a new program by selecting “New Program” in the “New” tab of the online
       IDE. As shown in Figure 12.3, type in the program name and click “OK”.
53 | P a g e
ES LAB MANUAL             LAB 10, LAB11: Familiarization with ARM mbed Board
    6. In the Program Workspace, a main.cpp file will be created. Clicking on that file
       will reveal a sample program to blink a LED. Insert your own code in place of
       that. Alternatively, you could import your code into the workspace. Save your
       program.
    7. Compile the code by clicking on the “Compile” tab, or press CTRL-D. The Online
       Compiler compiles the code into an executable file, which will be downloaded.
       When prompted, save the file(.bin) in mbed board's USB device folder.
    8. Press reset switch on the board to complete the flashing/programming process.
54 | P a g e
ES LAB MANUAL          LAB 10, LAB11: Familiarization with ARM mbed Board
Sample Question: Write a CPP program to blink all four LEDs in the mbed LPC1768
board.
//******************************************************
// Program written using C++ for mbed LPC1768 board.
// Program to blink all four onboard LEDs.
// Author: *****
// Date: DD-Mon-YYYY
//******************************************************
#include "mbed.h"
DigitalOut myled1(LED1);
DigitalOut myled2(LED2);
DigitalOut myled3(LED3);
DigitalOut myled4(LED4);
int main()
{
   while(1) {
      //turn on LED1 through LED4
      myled1 = 1;
      myled2 = 1;
      myled3 = 1;
      myled4 = 1;
      wait(0.5); // delay of 0.5 seconds
      //turn off LED1 through LED4
      myled1 = 0;
      myled2 = 0;
      myled3 = 0;
      myled4 = 0;
      wait(0.5); //delay of 0.5 seconds
   }
}
55 | P a g e
ES LAB MANUAL            LAB 10, LAB11: Familiarization with ARM mbed Board
Exercise Programs
   1. Write a CPP program to display a 4-bit binary up counter on the LEDs.
   2. Write a CPP program to display a 4-bit binary down counter on the LEDs.
   3. Write a CPP program to display a ring counter on the LEDs.
56 | P a g e
ES LAB MANUAL                                                          Appendix A
Appendix A: Instructions
57 | P a g e
ES LAB MANUAL                                                         Appendix A
58 | P a g e
ES LAB MANUAL                                                         Appendix A
A conditional instruction is only executed on match of the condition flags in the Program
Status Register. For example, the BEQ (B instruction with EQ condition) branches only
if the Z flag is set. If the {cond} field is empty the instruction is always executed.
 {cond} Suffix         Tested Status Flags                Description
 EQ                    Z set                              equal
 NE                    Z clear                            not equal
 CS/HS                 C set                              unsigned higher or same
 CC/LO                 C clear                            unsigned lower
 MI                    N set                              negative
 PL                    N clear                            positive or zero
 VS                    V set                              overflow
 VC                    V clear                            no overflow
 HI                    C set and Z clear                  unsigned higher
 LS                    C clear or Z set                   unsigned lower or same
 GE                    N equals V                         signed greater or equal
 LT                    N not equal to V                   signed less than
 GT                    Z clear AND (N equals V)           signed greater than
 LE                    Z set OR (N not equal to V)        signed less than or equal
 AL                    (ignored)                          always (usually omitted)
The instructions LDM and STM provide four different addressing modes. The addressing
mode specifies the behavior of the base register and is explained in the following table.
Examples:
      STMDB      R2!,{R4,R5,LR}
      LDMIA      R0!,{R1-R5}
      STMDB      R6!,{R0,R1,R5}
59 | P a g e
ES LAB MANUAL                                                             Appendix B
Literal Addressing
 In this addressing mode data is a part of instruction. ‘#’ symbol is used to indiacate the
data. ARM and Thumb instructions can only be 32 bits wide. You can use a MOV or
MVN instruction to load a register with an immediate value from a range that depends on
the instruction set. Certain 32-bit values cannot be represented as an immediate operand
to a single 32-bit instruction, although you can load these values from memory in a single
60 | P a g e
ES LAB MANUAL                                                           Appendix B
instruction. you can load any 32-bit immediate value into a register with two instructions,
a MOV followed by a MOVT. Or, you can use a pseudo-instruction, MOV32, to construct
the instruction sequence for you. You can also use the LDR pseudo-instruction to load
immediate values into a register
        Examples                  Meaning
----------------------------------------------------------------------
        CMP R0, #22            ;Compare Register content R0 with 22
----------------------------------------------------------------------
        ADD R1, R2, #18        ;Add the content of R2 and 18 then store
                                ;the result in R1
----------------------------------------------------------------------
        MOV R1, #30            ;copy the data 30 into register R1
----------------------------------------------------------------------
        MOV R1, #0Xff          ;copy the data ff in hexadecimal into R1
----------------------------------------------------------------------
        MOV R2, #0xFF0000FF
----------------------------------------------------------------------
        AND R0, R1, #0xFF000000
----------------------------------------------------------------------
        CMN R0, #6400          ; update the N, Z, C and V flags
----------------------------------------------------------------------
        CMPGT SP, R7, LSL #2   ; update the N, Z, C and V flags
----------------------------------------------------------------------
   MOV can load any 8-bit immediate value, giving a range of 0x0-0xFF (0-255). It can
    also rotate these values by any even number. These values are also available as
    immediate operands in many data processing operations, without being loaded in a
    separate instruction.
   MVN can load the bitwise complements of these values. The numerical values are -
    (n+1), where n is the value available in MOV.
    A MOVT instruction that can load any value in the range 0x0000 to 0xFFFF into the
    most significant half of a register, without altering the contents of the least significant
    half.
   The LDR Rd,=const pseudo-instruction generates the most efficient single instruction
    to load any 32-bit number
Register indirect addressing mode requires three read operations to access an operand. It
is very important because the content of the register containing the pointer to the operand
can be modified at runtime. Therefore, the address is a vaiable that allows the access to
the data structure like arrays.
62 | P a g e
ES LAB MANUAL                                                           Appendix B
This is used to facilitate the reading of sequential data in structures such as arrays, tables,
and vectors. A pointer register is used to hold the base address. An offset can be added to
achieve the effective address. For example,
This is similar to the above, but it first accesses the operand at the location pointed by the
base register, then increments the base register. For example,
Register R15 is the program counter. If you use R15 as a pointer register to access
operand, the resulting addressing mode is called PC relative addressing. The operand is
specified with respect to the current code location. Please look at this example,
63 | P a g e
ES LAB MANUAL
                                      APPENDIX C
GPIO extension connectors:
There are four 10 pin FRC type male connectors, they extends the controllers
general purpose port lines for the use of user requirements. Details on each connector is
given below:
CNA –10 pin male box type FRC connector. Port lines P0.4 to P0.11 from controller are
terminated in this connector. They can be extended to interface few on board or external
peripherals. The pins mentioned in the above table are configured to work as a GPIO's at
power on. Other alternate functions on those pins needs to be selected using
respective PINSEL registers.
CNB – 10 pin male box type FRC connector. Port lines fromP1.23 to P1.26 and P2.10
to
64 | P a g e
ES LAB MANUAL
CNC – 10 pin male box type FRC connector. Port lines fromP0.15 to P0.22 and P2.13
are terminated in this connector.
65 | P a g e
ES LAB MANUAL
CND – 10 pin male box type FRC connector. Port lines fromP0.23 to P0.28 and P2.0 to
P2.1 are terminated in this connector.
66 | P a g e