Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
21 views99 pages

Mod 5

This document covers various interfacing techniques and applications using the ARM LPC2148 microcontroller, including interfacing with LEDs, switches, relays, DC motors, DACs, LCDs, and 4x4 matrix keypads. It provides example code snippets for each interfacing scenario and discusses the functionality of ARM Cortex series processors. The document serves as a comprehensive guide for implementing hardware control using the LPC2148 in embedded systems.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views99 pages

Mod 5

This document covers various interfacing techniques and applications using the ARM LPC2148 microcontroller, including interfacing with LEDs, switches, relays, DC motors, DACs, LCDs, and 4x4 matrix keypads. It provides example code snippets for each interfacing scenario and discusses the functionality of ARM Cortex series processors. The document serves as a comprehensive guide for implementing hardware control using the LPC2148 in embedded systems.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 99

MODULE - 5

ARM Processors Interfacing &


Applications
2 of 37
3 of 37
4 of 37
5 of 37
6 of 37
7 of 37
8 of 37
9 of 37
10 of 37
ARM LPC2148 Interfacing
12 of 37
#include<lpc214x.h>
void delay();
void main()
{
IO0DIR |= 0xFFFFFFFF; //PORT0 is now acting as a output pin
while(1)
{
IOSET0 |= 0xFFFFFFFF; //PORT0's all pins are HIGH now(LED is glowing)
delay();
IOCLR0 |= 0xFFFFFFFF; //PORT0's all pins are LOW (LED is OFF)
delay();
}
}
void delay()
{
unsigned int i;
for(i=0;i<30000;i++);
}
Interface switch with LPC2148
LED & Switch Interfacing to LPC2148
#include<21xx.h>
SWITCH & LED Interfacing with LPC 2148
Char switchstatus
Int main (void)
{ PINSEL0 = 0x00000000;
IO0DIR0 &= 0xFFFFFFFE; //P0.0 Switch
IO0DIR0 |= 0x00000002; //P0.1 Led
while(1)
{
switchstatus =( IOPIN0 & 0x01)
if(switchstatus == 1)
{
IOSET0 |= 0x00000002;
} else
{
IOCLR0 |= 0x 00000002;
}
}
}
Relay Interfacing with LPC 2148
• A relay is an electromagnetic switch , which performs ON & OFF
operations.
Relay Interfacing with LPC 2148
Relay Interfacing with LPC 2148
Relay Program
#include<LPC214x.h>
Void delay()
{
int i ,j;
for(i=0; i<1000; i++)
for(j=0; j<2000; j++);
}
int main(void)
{ PINSEL0 = 0;
IO0DIR 1<<12; //set P0.12 as output pin
while(1)
{
IOSET0 = 1<<12; //send Logic 1 on P0.12 to make RELAY ON
delay();
IOCLR0 = 1<<12; // send Logic 0 on P0.12 to make RELAY OFF
}
}
DAC interfacing with LPC2148
• DAC Features
while(1)
{
for(j=0x00;j<=0x3FF;j++)
{
DACR=(j<<6);
}

for(j=0x3FF;j>=0x00;j--)

{
DACR=(j<<6);
}
}
delay();
return 0;
}
Interfacing Stepper motor with LPC2148
Interfacing Stepper motor with LPC2148
Interfacing Stepper motor with LPC2148
Interfacing Stepper motor with LPC2148
DC MOTOR
Interfacing DC motor with LPC2148
• DC motor converts electrical energy in the form of Direct Current into
mechanical energy.
• In case of a motor, the mechanical energy produced is in the form of
rotational movement of the motor shaft.
• The direction of rotation of the shaft of the motor can be reversed by
reversing the direction of Direct Current through the motor.
• The motor can be rotated at a certain speed by applying a fixed
voltage to it. If the voltage varies, the speed of the motor varies.
• Thus, the DC motor speed can be controlled by applying varying DC
voltage; whereas the direction of rotation of the motor can be
changed by reversing the direction of current through it.
• For applying varying voltage, we can make use of PWM technique.
Interfacing DC motor with LPC2148
Liquid Crystal Display
1. Character LCD
2. Graphical LCD

16 Pin device

Vee –Adjust the contrast of the device

Control lines used to control the LCD

RS- Register select : 1- Data & 0 - Command

Read write pin : 0- writing data to LCD & 1- Read

Enable : Strobe line : To initiate operations of LCD

Command/ Data transmission – D0 to D7


Backlight + & - : Illuminate LCD
HD 44780 – LCD Controller

0x38 -2 lines ( 5x7 Matrix)

0x0C – Display ON, Cursor OFF

0x06 – Write data

0x01 – Clear LCD display

0x0E - Display ON, Cursor ON

0x80 –Cursor Position


Interfacing 4 X 4 Hex keypad and displaying result on LCD

Send Command : RS=0 ; RW=0; EN = High After delay LOW

Send Data : RS=1; RW=0; Data to be displayed


EN = High After delay LOW
////// "LCD DISPLAY" To display the predefined data //////
#include<lpc214x.h>
#include<stdio.h>
//Function prototypes
void lcd_init(void);
void wr_cn(void);
void clr_disp(void);
void delay(unsigned int);
void lcd_com(void);
void wr_dn(void);
void lcd_data(void);

unsigned char temp1;


unsigned long int temp,r=0;
unsigned char *ptr,disp[] = "DSCE ,EIE DEPT.,",disp1[] = "BENGALURU-58";
int main()
{
IO0DIR = 0x000000FC; //configure o/p lines for lcd
IO0PIN = 0X00000000;
delay(3200); //delay
lcd_init(); //lcd intialisation
delay(3200); //delay
clr_disp(); //clear display
delay(3200); //delay

//........LCD DISPLAY TEST.........//


temp1 = 0x80; //Display starting address of
first line 1 th pos
lcd_com();
ptr = disp;
while(*ptr!='\0')
{
temp1 = *ptr;
lcd_data();
ptr ++;
}

temp1 = 0xC0; // Display starting address of second line 4 th


pos
lcd_com();

ptr = disp1;
while(*ptr!='\0')
{
temp1 = *ptr;
lcd_data();
ptr ++;
}
while(1);
} //end of main()
// lcd initialisation routine.
void lcd_init(void)
{
temp = 0x30;
wr_cn();
delay(3200);

temp = 0x30;
wr_cn();
delay(3200);

temp = 0x30;
wr_cn();
delay(3200);

temp = 0x20; // change to 4 bit mode from default 8 bit mode


wr_cn();
delay(3200);
// load command for lcd function setting with lcd in 4 bit mode,
// 2 line and 5x7 matrix display

temp = 0x28;
lcd_com();
delay(3200);

// load a command for display on, cursor on and blinking off


temp1 = 0x0C;
lcd_com();
delay(800);

// command for cursor increment after data dump


temp1 = 0x06;
lcd_com();
delay(800);

temp1 = 0x80; // set the cursor to beginning of line 1


lcd_com();
delay(800);
}
void lcd_com(void)
{
temp = temp1 & 0xf0;
wr_cn();
temp = temp1 & 0x0f;
temp = temp << 4;
wr_cn();
delay(500);
}

// command nibble o/p routine


void wr_cn(void) //write command reg
{
IO0CLR = 0x000000FC; // clear the port lines.
IO0SET = temp; // Assign the value to the PORT
lines
IO0CLR = 0x00000004; // clear bit RS = 0
IO0SET = 0x00000008; // E=1
delay(10);
IO0CLR = 0x00000008;
}
// data nibble o/p routine
void wr_dn(void) ////write data reg
{
IO0CLR = 0x000000FC; // clear the port lines.
IO0SET = temp; // Assign the value to the PORT lines
IO0SET = 0x00000004; // set bit RS = 1
IO0SET = 0x00000008; // E=1
delay(10);
IO0CLR = 0x00000008;
} void clr_disp(void)
{
// data o/p routine which also outputs high nibble first // command to clear lcd display
// and lower nibble next temp1 = 0x01;
void lcd_data(void) lcd_com();
{ delay(500);
temp = temp1 & 0xf0;
temp = temp ;//<< 6; }
wr_dn();
temp= temp1 & 0x0f; void delay(unsigned int r1)
temp= temp << 4; {
wr_dn(); for(r=0;r<r1;r++);
delay(100); }
Interfacing 4 X 4 Hex keypad
Matrix keypad is one of the widely used input
devices. Some of the application includes Mobile
keypad, Telephone dial pad, calculator, ATM etc.
Keypad provides an easy way to allow user to
provide input to any system. In this article, we will
explain how to interface 4x4 matrix keypad with
LPC2148. The pressed key will be displayed on
LCD.
In matrix keypad, keys are connected in rows and
columns. When any switch is pressed, rows and
columns come into contact which is detected by
controller to identify which key has been pressed.
/*Program to demonstrate keyboard operation
Takes a key from key board and displays it on LCD screen*/
#include<lpc21xx.h>
#include<stdio.h>
/******* FUNCTION PROTOTYPE*******/
void lcd_init(void);
void clr_disp(void);
void lcd_com(void);
void lcd_data(void);
void wr_cn(void);
void wr_dn(void);
void scan(void);
void get_key(void);
void display(void);
void delay(unsigned int);
void init_port(void);
unsigned long int scan_code[16]= {0x00EE0000,0x00ED0000,0x00EB0000,0x00E70000,
0x00DE0000,0x00DD0000,0x00DB0000,0x00D70000,
0x00BE0000,0x00BD0000,0x00BB0000,0x00B70000,
0x007E0000,0x007D0000,0x007B0000,0x00770000};

unsigned char ASCII_CODE[16]= {'0','1','2','3',


'4','5','6','7',
'8','9','A','B',
'C','D','E','F'};

unsigned char row,col;


unsigned char temp,flag,i,result,temp1;
unsigned int r,r1;
unsigned long int var,var1,var2,res1,temp2,temp3,temp4;
unsigned char *ptr,disp[] = "4X4 KEYPAD";
unsigned char disp0[] = "KEYPAD TESTING";
unsigned char disp1[] = "KEY = ";
int main()
{
// __ARMLIB_enableIRQ();
init_port(); //port intialisation
delay(3200); //delay
lcd_init(); //lcd intialisation
delay(3200); //delay
clr_disp(); //clear display
delay(500); //delay

//........LCD DISPLAY TEST.........//


ptr = disp;
temp1 = 0x81; // Display starting address
lcd_com();
delay(800);
while(*ptr!='\0')
{
temp1 = *ptr;
lcd_data();
ptr ++;
}

//........KEYPAD Working.........//
while(1)
{
get_key();
display();
}

} //end of main()

void get_key(void) //get the key from the keyboard


{
unsigned int i;
flag = 0x00;
IO1PIN=0x000f0000;
while(1)
{
for(row=0X00;row<0X04;row++) //Writing one for col's
{
if( row == 0X00)
{
temp3=0x00700000;
} var1 = temp3;
else if(row == 0X01) IO1PIN = var1; // each time var1 value
{ is put to port1
temp3=0x00B00000; IO1CLR =~var1; // Once again
} Conforming (clearing all other bits)
else if(row == 0X02) scan();
{ delay(100); //delay
temp3=0x00D00000; if(flag == 0xff)
} break;
else if(row == 0X03) } // end of for
{ if(flag == 0xff)
temp3=0x00E00000; break;
} } // end of while
CORTEX Series Processors
The Cortex M is the famous microcontroller series which is ruling the world with its flexibility in mending with the designer’s
applications.

Cortex M is built on the ARMv7 architecture and the smallest microcontroller Cortex M0+ is built on the ARMv6 architecture.

The first Cortex M was released in 2004 namely Cortex M3 and the latest one in the series is Cortex M35P(2018) in which P
stands for Physically secure
CORTEX A stands for application which help in performance intensive applications
such as Android, Linux and many other applications related to handsets, tablets,
laptops and desktops.

CORTEX R stands for real time application which is used in the safety critical
applications and where we need real time responses of the system such as avionics,
automotive, medical, defense and server side technologies where data related
applications are executed.

CORTEX M stands for microcontroller which is used in most of our daily life
applications also starting from the automation to DSP applications , sensors , smart
displays , IoT applications and many more.
The CORTEX M series is an ocean of possibilities with a large number of
probabilities and configuration.
LCD DISPLAY
LCD Interfacing with LPC2148 Processor

You might also like