Pages

Thursday 26 April 2018

ARM-LPC1768-Interface a simple Switch and display its status through Relay, Buzzer and LED.


Program:
/* Connections */
/* Switch = P2.5
 * led = P2.0
 * buzzer = P2.1
 * relay = P2.2
 */

#include <lpc17xx.h>
#include "blink.h"
 
#define Switch 5
#define Led    0
#define buzzer 1
#define relay  2

/* start the main program */
int main()
{
uint32_t switchStatus;

/* Initialize the output pins for led, buzzer and relay */
GPIO_Init_Output(buzzer);
GPIO_Init_Output(Led);
GPIO_Init_Output(relay);

/* Initialize the input pin */
GPIO_Init_Input(Switch);

LED_OFF(Led);
LED_OFF(buzzer);
LED_OFF(relay);

while(1)
{
/* Turn On all the leds and wait for one second */
switchStatus = GPIO_Read(Switch);  /* Read the switch status */

if(switchStatus == 1)               /* Turn ON/OFF LEDs depending on switch status */

LED_ON(Led);
LED_ON(buzzer);
LED_ON(relay);
}
else
{
LED_OFF(Led);
LED_OFF(buzzer);
LED_OFF(relay);
}     
}
}


Hardware Connection
Connect P2.5 to switch (development board)
Connect P2.0 to led (development board)
Connect P2.0 to led (development board)
Connect P2.0 to led (development board)

Output
When the switch is pressed LED is ON, buzzer is ON and relay is ON.
When the switch is not pressed LED is OFF, buzzer is OFF and relay is OFF.

 FOR DETAIL INFORMATION ABOUT ARM CORTEX DEVELOPMENT KIT : CLICK HERE

ARM-1768-LPCDisplay the Hex digits 0 to F on a 7-segment LED with an appropriate delay in between

Program:
/** Connections
  * A(development board) -> P2.0
* B(development board) -> P2.1
* C(development board) -> P2.2
* D(development board) -> P2.3
* E(development board) -> P2.4
* F(development board) -> P2.5
* G (development board) -> P2.6
* DIG1/DIG2/DIG3/DIG4(devp board) -> P2.7
  */

#include <lpc17xx.h> 
#include "7segment.h"
#include "delay.h"

/* Initialize the character to be displayed on the 7 segment display */
uint8_t ch[] = {'0', '1', '2', '3', '4', '5', '6', '7',
              '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};

uint8_t i = 0;

/* start the main program */   
int main()

uint8_t data;

/* Initialize the 7 Segment display */
//A,B,C,D,E,F,G,DIG
  SEG_INIT(2,3,4,5,6,7,8,9);

  while(1)
  {
    for(i = 0; i < 16; i++)
{
switch(ch[i])
{
case '0' : data = 0x40; break;
case '1' : data = 0x79; break;
case '2' : data = 0x24; break;
case '3' : data = 0x30; break;
case '4' : data = 0x19; break;
case '5' : data = 0x12; break;
case '6' : data = 0x02; break;
case '7' : data = 0x78; break;
case '8' : data = 0x00; break;
case '9' : data = 0x18; break;
case 'A' : data = 0x08; break;
case 'B' : data = 0x00; break;
case 'C' : data = 0x46; break;
case 'D' : data = 0x40; break;
case 'E' : data = 0x06; break;
case 'F' : data = 0x0E; break;
default  : data = 0x40; break;
}

/* Display the character on seven segment LED */
Display(data);
DELAY_ms(50);
}
  }
}

Hardware Connection
Connect R5 (development board) to P2.0 (segment ‘a’)
Connect R6 (development board) to P2.1 (segment ‘b’)
Connect R7 (development board) to P2.2 (segment ‘c’)
Connect R8 (development board) to P2.3 (segment ‘d’)
Connect R9 (development board) to P2.4 (segment ‘e’)
Connect R10 (development board) to P2.5 (segment ‘f’)
Connect R11 (development board) to P2.6 (segment ‘g’)
Connect DIG /DIG2/DIG3/DIG4 (development board) to P2.7


Output
The 7Segment Display starts displaying the characters from 0 – F.

 FOR DETAIL INFORMATION ABOUT ARM CORTEX DEVELOPMENT KIT : CLICK HERE

ARM-LPC1768-Demonstrate the use of an external interrupt to toggle an LED On/Off

Program:
/* Connections
 * Connect P2.11 to switch(development board)
 * Connect P2.3 to led(development board)
 * When switch is pressed led = ~led
 */

#include <lpc17xx.h> 
#include "ExtInt.h"

/* LED assigned to P2.3, pin number can be changed */
#define    LED    3   

/* Interrupt Handler */
void EINT1_IRQHandler(void)
{
/* Toggle the LED (P2_3) */
GPIO_PinToggle(LED);
}
     
int main()
{
/* Initialize the external interrupt 1 */
ExtInt_Init();

/* Initalize the GPIO pin as output */
GPIO_Init(LED);

/* Enable the EINT1 interrupts */
  NVIC_EnableIRQ(EINT1_IRQn);               

/* Infinite loop */
while(1)
{
// Do nothing
}     
}

Hardware Connection
Connect P2.11 to switch (development board)
Connect P2.3 to led (development board)

Output
When switch is pressed led = ~led

 FOR DETAIL INFORMATION ABOUT ARM CORTEX DEVELOPMENT KIT : CLICK HERE

ARM-LPC1768-Using the Internal PWM module of ARM controller, generate PWM and vary its duty cycle


Program:
/**
  * @brief Generate PWM on P2.0
  * DutyCycle varies from 0-100% and back from 100%- 0%.
  */

#include <lpc17xx.h>
#include "pwm.h"

/* variable to hold dutycycle value */
uint8_t dutyCycle;

int main(void)
{
/* Initialize the PWM Peripheral */
  PWM_Init();

/* Infinite loop */
while(1)
{
/* Increase dutycycle for from 0 to 100% */
for(dutyCycle = 0; dutyCycle < 100; dutyCycle++)
{
/* Set the PWM */
PWM_Set_Duty(dutyCycle);

/* set delay */
DELAY_ms(5);
}

for(dutyCycle = 100; dutyCycle > 0; dutyCycle--)
{
/* Set the PWM */
PWM_Set_Duty(dutyCycle);
/* set delay */
DELAY_ms(5);
}
}
}

Hardware Connections:
Connect positive of the CRO to pin P2.0
Connect negative of the CRO to the GND (development board)

Output:
A square wave is seen on CRO who pulse width varies from 0% - 100% and from 100% - 0%

 FOR DETAIL INFORMATION ABOUT ARM CORTEX DEVELOPMENT KIT : CLICK HERE

Wednesday 18 April 2018

ARM-LPC1768-Interface a 4x4 keyboard and display the key code on an LCD


ARM-Interface a 4x4 keyboard and display the key code on an LCD


Program
 /** @brief When key is pressed, corresponding key is displayed on LCD
* @Connections :
  * D0 (LCD) -> P1.19
* D1 (LCD) -> P1.20
* D2 (LCD) -> P1.21
* D3 (LCD) -> P1.22
* D4 (LCD) -> P1.23
  * D5 (LCD) -> P1.24
  * D6 (LCD) -> P1.25
  * D7 (LCD) -> P1.26
  * RS (LCD) -> P1.27
* EN (LCD) -> P1.28
  * C1 (Keypad) -> P2.0
* C2 (Keypad) -> P2.1
* C3 (Keypad) -> P2.2
* C4 (Keypad) -> P2.3
  * R1 (Keypad) -> P2.4
* R2 (Keypad) -> P2.5
* R3 (Keypad) -> P2.6
* R4 (Keypad) -> P2.7
*/

#include <lpc17xx.h>
#include "LCD.h"
#include "keypad.h"

char keypad(void);
char c;

/* start the main program */
int main()
{
/* Initialize the GPIO pins for LCD */
/* PORT1 D0,                D7, RS, EN */
LCD_Init(19, 20, 21, 22, 23, 24, 25, 26, 27, 28);
delay(100);

/* Initialize the GPIO pins for Keypad */
/* PORT2    C1         R1         */
Keypad_Init(0, 1, 2, 3, 4, 5, 6, 7);
delay(100);

/* Set LCD parameters like contrast, backlight, cursor position etc */
CMD_WRT(0x38); 
CMD_WRT(0x0f);                         
CMD_WRT(0x06); 
CMD_WRT(0x01);

delay(100);

CMD_WRT(0X01);
CMD_WRT(0X80);
LCD_WRT("----RDL--");
CMD_WRT(0XC0);

  while(1)
  {
/* get the key pressed */
c = keypad();

/* write the key to LCD */
DATA_WRT(c);

delay(100);
}
}

Hardware Connection
D0 (LCD) -> P1.19
D1 (LCD) -> P1.20
D2 (LCD) -> P1.21
D3 (LCD) -> P1.22
D4 (LCD) -> P1.23
D5 (LCD) -> P1.24
D6 (LCD) -> P1.25
D7 (LCD) -> P1.26
RS (LCD) -> P1.27
EN (LCD) -> P1.28             
                                C1 (Keypad on development board) -> P2.0
C2 (Keypad on development board) -> P2.1
C3 (Keypad on development board) -> P2.2
C4 (Keypad on development board) -> P2.3
R1 (Keypad on development board) -> P2.4
R2 (Keypad on development board) -> P2.5
R3 (Keypad on development board) -> P2.6
R4 (Keypad on development board) -> P2.7
Output
When the Key is pressed, Corresponding key is displayed on the LCD. For example, if key ‘1’ is pressed, on LCD it should show “Key Pressed is 1”


 FOR DETAIL INFORMATION ABOUT ARM CORTEX DEVELOPMENT KIT : CLICK HERE

ARM-LPC1768-Interface a Stepper motor and rotate it in clockwise and anti-clockwise direction.

Interface a Stepper motor and rotate it in clockwise and anti-clockwise direction.


Program

/**
  * @brief Run steeper motor Clockwise when switch = 1 and reverse direction when switch = 0
  * @Connection
  * SDA  ------------------>  P2.0
  * SCL  ------------------>  P2.1
  * TX   ------------------>  P2.2
  * RX   ------------------>  P2.3
* 5V(FRC) --------------->  5V on board (without this, stepper motor produces jerk)
  * switch ---------------->  P2.5
  */

#include <lpc17xx.h> 
#include "stepper.h"
#include "blink.h"

#define    Switch  5       /* switch is connected to P2.5 */
uint16_t i;

int main()
{
  uint32_t switchStatus;

  /* Configure GPIO pins for steeper motor windings */
  Stepper(0,1,2,3);

  while(1)
  {
    /* Turn On all the leds and wait for one second */
    switchStatus = GPIO_Read(Switch);  /* Read the switch status */
 
    if(switchStatus == 1)    /* If switch == 1, motor runs in clockwise direction */
    { 
      /* for sometime run tghe motor in forward direction */
      for(i = 10; i > 0; i--)
        Motor_Forward_Direction();
    }
    else
    {
      /* for sometime run tghe motor in forward direction */ 
      for(i = 10; i > 0; i--)
        Motor_Reverse_Direction();
    }
  }
}
Hardware Connection
ENA (L298 driver) to 5V
IN1 (L298 driver) to P2.1
IN2 (L298 driver) to P2.2
ENB (L298 driver) to 5V
IN4 (L298 driver) to P2.3
IN5 (L298 driver) to P2.4
VMS (L298 driver) to Vin (12Volts, development board)
GND (L298 driver) to
FRC of Stepper Motor to FRC of L298 driver
Output
Stepper Motor runs in forward direction for some time and runs in reverse direction in some time. This repeats continuously.

FOR DETAIL INFORMATION ABOUT ARM CORTEX DEVELOPMENT KIT : CLICK HERE

ARM-LPC1768 -Interface and Control a DC Motor.


Interface and Control a DC Motor.


Program

/**
  * @brief Run DC motor clockwise when switch is 1
*        and rum anticlockwise when switch is 0.
*        The Speed of the DC Motor can be changed using dutyCycle (using PWM technique).
* SDA  ------------------>  P2.2
* SCL  ------------------>  P2.3
  * 5V   ------------------>  P2.0
* switch ---------------->  P2.5
  */

#include <lpc17xx.h>     
#include "dcmotor.h" 
#include "pwm.h"  
#include "blink.h"

/* switch is connected to P2.5 */
#define    Switch  5    
#define    Pin_1   2 
#define    Pin_2   3 

uint8_t dutyCycle = 50;


/* start the main program */
int main() 
{   
uint32_t switchStatus;

/* Initialize the DC Motor */
  DC_Motor_Init(Pin_1, Pin_2);
  
/* Initialize PWM for Motor Speed Control */
PWM_Init();

/* Set PWM for Motor Speed Control, 100 = Max Speed, 1 = Min Speed */
PWM_Set_Duty(dutyCycle);

while(1)
  {  
/* Turn On all the leds and wait for one second */ 
switchStatus = GPIO_Read(Switch);  /* Read the switch status */

if(switchStatus == 1)                 /* If switch == 1, motor runs in clockwise direction */
Motor_Rotate_Clockwise(Pin_1, Pin_2); 

else                              /* If switch == 0, motor runs in anticlockwise direction */
Motor_Rotate_AntiClockwise(Pin_1, Pin_2); 

  }

}

Hardware Connection
ENA (L298 driver) to P2.0 (PWM pin)
IN1 (L298 driver) to P2.2
IN2 (L298 driver) to P2.3
VMS (L298 driver) to Vin (12Volts, development board)
GND (L298 driver) to
Any one of the screw connector of MOTOR A (L298 driver) to one of the DC motor pin
Another screw connector of MOTOR A (L298 driver) to another DC motor pin

Output
DC Motor starts running with the speed given by dutycycle in the function “PWM_Set_Duty(dutyCycle)”. With respect to the code above, motor runs with full speed as the dutycycle = 100.

FOR DETAIL INFORMATION ABOUT ARM CORTEX DEVELOPMENT KIT : CLICK HERE

ARM-LPC1768 program to display hello world


1.1.          Display “Hello World” message using Internal UART




Hardware Connection
An USB cable (mini USB) needs to be connected from development board to the PC

.
Output
Output could be seen either on a serial monitor or on a simulator.
§  Using Serial Monitor
1.       Open any serial monitor (like Tera Term, Hyper Term or Docklight etc…).
2.       Set the baud rate to 9600 (if the baud rate is different in your program, change it according).
3.       Now “Hello World” should be displayed continuously.

§  Using inbuilt simulator
1.      Click on “start debugging”
2.       Hit Run

3.       Click on View -> Serial Windows -> UART #1
4.       Watch the output in the UART window.


Monday 16 April 2018

Introduction to Keil






1.  Installation

1.1.       How to install Keil uVision 4

Follow the steps below to install Keil uVision 4 on your system.
1.        Run setup file MDK-ARM V4.13a.exe (Double click the file icon).
2.        Setup Window appears....

3.       Click Next.



4.       Click Checkbox of agreement in order to proceed and click Next

 
5.       In folder selection window, select suitable directory for the installation and press next (default directory should work fine!)




6.       Enter customer information and click next

7.       The setup should begin. Setup status window will show installation of different files. Wait until it gets installed completely.



8.       Once the installation gets over, message should appear with text File installation Completed”, Click Next without making any changes anywhere in the window.
9.      Next message will confirm “Keil uVision 4 Setup completed”. Click Finish

10.   This will lead you to the webpage of Keil Development Suit for ARM. This will provide you release notes for Keil Development kit. This document gives you the brief idea of which microcontrollers are being added in the Keil uVision 4. 

11.   Run “Keil uVision 4” by double clicking the "Keil uVision 4" icon from the desktop. Same can be done from Start menu.

1.2         How to install FTDI driver

1.       Visit FTDI’s VCP Drivers page (http://www.ftdichip.com/Drivers/VCP.htm) for the latest download of the Windows FTDI Driver executable and clicking on the Window’s “Available as a setup executable” link. Make sure to unzip the executable before proceeding to the next step.



2.       Choose ‘Run’ once it is has finished downloading, or find the file you just downloaded “CDM21228_Setup.exe” and double-click it to run it.


  1. Choose ‘Extract’ and continue through the installation until it finishes.


  1. If everything was successful, you should see some nice green check marks, indicating success!

1.3         How to install Flash Magic Utility

1.        Visit FlashMagic website http://www.flashmagictool.com/ and download the file FlashMagic.exe.
2.       Execute the downloaded file FlashMagic.exe, and follow the instructions.
3.       Start Flash Magic by selecting it from the Start Menu. In the Flash Magic windows select Options > Advanced Options ... menu item. In the window that appears enable the check box that says Use DTR and RTS to control RST and P0.14, and click on Ok.
When this option is enabled, during code download, the flashing tool will automatically switch the device into ISP mode. For more information on this, see the board user manual.



2.  Library Files (LibFiles)

Basically “LibFiles” contains “system_lpc17xx.c” and “.h” files.
Before executing lab programs it is important to have this library files in our system as we are going to link our programs to this folder.
Place “LibFiles” folder in a common path in all the computers. (ex: C->Documents->ARM->LibFiles)

1.       Open the Keil software and select “Project-> New µvision project” as shown below.





2.       Browse to your project folder (/Create a folder) and provide the project name and click on save.
      

3.       Once the project is saved a new pop up “Select Device for Target” opens, Select the controller (NXP:LPC1768) and click on OK.
    

4.       Select the controller (NXP:LPC1768) and click on OK.
  

5.       As LPC1768 needs the startup code, click on Yes option to include the LPC17xx Startup file.

   


6.       Create a new file to write the program.





7.       Type the code or Copy paste the below code snippet.


8.       After typing the code save the file as main.c.




9.       Add the recently saved file to the project.




10.   Add the “main.c” along with system_LPC17xx.c.



11.   Build the project and fix the compiler errors/warnings if any.




12.     Code is compiled with no errors. The .hex file is still not generated. Follow section 4 (how to enable Hex  


 4.  How to Enable Hex File Generation
1.       Click on Target Options (or right click on “Target 1” and select “Options for Target ‘Target 1’…) to select the option for generating .hex file.




2.       Set IROM1 start address as 0x0000.




3.       Enable the option to generate the .hex file




4.       Hex file is generated after a rebuild.



5.       Check the project folder for the generated .hex file.

Once the “.hex” file is generated in keil, we need to upload the hex file to the hardware. We use Flash Magic Tool for the same.
Open the flash magic software and follow the below steps.
1.     Select the IC “LPC1768” from Select Menu.
2.     Select the COM Port. Check the device manager for detected Com port.
3.     Select Baud rate from 9600-115200
4.     Select None [ISP] Option for Interface.
5.     Oscillator Frequency 12.000000(12Mhz).
6.     Check the Erase blocks used by Hex file option
7.     Browse and Select the hex file.
8.     Check the Verify After Programming Option.
9.     If DTR and RTS are used then go to Options->Advanced Options-> Hardware Config and select the Use DTR and RTS Option.
10. Hit the Start Button to flash the hex file.
11. Once the hex file is flashed, reset the board. Now the controller should run your application code.