0% found this document useful (0 votes)
141 views76 pages

ARM7

A microcontroller is a small computer contained on a single integrated circuit chip that includes a processor core, memory, and programmable input/output peripherals. It is used widely in embedded systems to make intelligent decisions. The key difference between a microcontroller and microprocessor is that a microcontroller has memory, I/O ports, timers, and other peripherals integrated on a single chip, while a microprocessor requires external components connected to function. ARM stands for Advanced RISC Machines and designs low-power processors commonly used in mobile and embedded devices due to their low cost and power efficiency. The LPC2148 is an ARM7 microcontroller with features such as 40kB RAM, 512kB flash memory, USB

Uploaded by

Bajrang sisodiya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
0% found this document useful (0 votes)
141 views76 pages

ARM7

A microcontroller is a small computer contained on a single integrated circuit chip that includes a processor core, memory, and programmable input/output peripherals. It is used widely in embedded systems to make intelligent decisions. The key difference between a microcontroller and microprocessor is that a microcontroller has memory, I/O ports, timers, and other peripherals integrated on a single chip, while a microprocessor requires external components connected to function. ARM stands for Advanced RISC Machines and designs low-power processors commonly used in mobile and embedded devices due to their low cost and power efficiency. The LPC2148 is an ARM7 microcontroller with features such as 40kB RAM, 512kB flash memory, USB

Uploaded by

Bajrang sisodiya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
You are on page 1/ 76

WHAT IS A MICROCONTROLLER?

A microcontroller (sometimes
abbreviated µC or MCU) is a small
computer on a single IC containing
a processor core, memory, and
programmable input/output
peripherals.

Itis a decision making device


used widely in embedded systems
and all intelligent devices.
DIFFERENCE BETWEEN MICROCONTROLLER
AND MICROPROCESSOR
 Microcontroller has I/O ports, Memory, timers etc
all integrated on a single chip itself

 In Microprocessors, I/O ports, memory, timer etc


are to be connected externally
BLOCK DIAGRAM TO SHOW THE
DIFFERENCE
ARM

 ARM stands for Advanced RISC Machines

 An ARM processor is basically any 16/32bit microprocessor


designed and licensed by ARM Ltd, a microprocessor
design company headquartered in England, founded in 1990
by Herman Hauser

 A characteristic feature of ARM processors is their low


electric power consumption, which makes them particularly
suitable for use in portable devices.

 It is one of the most used processors currently on the market


WHY ARM?

 The ARM is a 32-bit reduced instruction set


computer (RISC).

 It was known as the Advanced RISC Machine,


and before that as the Acorn RISC Machine

 ARM processors made them suitable for low


power applications.

 This has made them dominant in the mobile and


embedded electronics market as relatively low
cost.
FEATURES OF LPC2148
 PACKAGE:

 16/32-bit ARM7TDMI-S microcontroller in a tiny LQFP64


package.

 MEMORY:

 40 kB of on-chip static RAM

 512 kB of on-chip flash program memory.

 SPEED:

 128 bit wide interface/accelerator enables high speed 60 MHz


operation.
 In-System / In-Application Programming (ISP/IAP) via on-chip
boot-loader software.

 Single flash sector or full chip erase in 400 ms and programming


of 256 bytes in 1ms.

 USB 2.0 Full Speed compliant Device Controller with 2kB of


endpoint RAM.

 In addition, the LPC2146/8 provides 8kB of on-chip RAM


accessible to USB by DMA.
 ADC:

 Two 10-bit A/D converters(AD0 and AD1) provide a total


of 14 analog inputs

 Conversion times as low as 2.44μs per channel.

 DAC:

 Single 10-bit D/A converter provides variable analog output.


 OSCILLATOR:

 On-chip integrated oscillator operates with an external crystal


in range from 1 MHz to 30 MHz and with an external
oscillator up to 50 MHz

 POWER SAVING MODES:

 Idle mode

 Power-down mode

 CPU operating voltage range of 3.0 V to 3.6 V (3.3 V ± 10 %)


with 5 V tolerant I/O pads.
PIN DIAGRAM
FUNCTIONALITY OF PINS
 Pin selection register are used to select the different
functionalities of LPC2148 i/o pins.

 PINSEL0 Pin function select


 Read/Write 0x0000 0000 (P0.0-P0.15)

 PINSEL1 Pin function select


 Read/Write 0x0000 0000 (P0.16-P0.31)

 PINSEL2 Pin function select


 Read/Write 0x0000 0000 (P1.16-P1.31)
PIN FUNCTION SELECT REGISTER 0
(Pin of
Select Port Pin sélection Function
Résister) line
 1:0 P0.0 00 GPIO Port 0.0
01 TXD (UART0)
10 PWM1
11 Reserved

 3:2 P0.1 00 GPIO Port 0.1


01 RxD (UART0)
10 PWM3
11 EINT0
INPUT OUTPUT PINS

 P0.0-P0.31 used as general purpose input/output pin


 Not pin P0.24, P0.26, P0.27 are not use as I/O

 P1.16-P1.31 used as general purpose input/output pin


 Not pin P1.0-P1.15 are not physically present
GPIO

 GPIO, or General Purpose Input / Output, is the easiest way


for you to interact with basic peripherals like buttons, LEDs,
switches, and other components.

 In order to get started with GPIO, you need to understand the


four 'registers' that control it: IODIR, IOSET, IOCLR and
IOPIN.
IODIR
• IODIR controls the 'direction' of the GPIO pin.
• For example

• To set GPIO 0.10 output IODIR0 = (1 << 10);


• To set GPIO 0.10 input IODIR0 = ~ (1 << 10);

Advance Technology
• To set several pins to output at once

• Set GPIO 0.10, 0.11, and 0.15 to output


IODIR 0 = (1 << 10) | (1 << 11) | (1 << 15);

• Set GPIO 0.10, 0.11, and 0.15 to output using


hexadecimal
IODIR0 = 0x00008C00;
IODIR, IOSET, IOCLR and IOPIN
• GPIO 0.10 and 0.11 set to output
IODIR0 = (1 << 10) | (1 << 11);

• Clearing GPIO 0.10 and 0.11


IOCLR0 = (1 << 10) | (1 << 11);

• Setting GPIO 0.10 and 0.11 high


IOSET0 = (1 << 10) | (1 << 11);

Advance Technology
• Read the current state of all pins in GPIO block 0
portdata_0 = IOPIN0;

• Read the value of ‘Pin Number’


int pinState;
pinState = (IOPIN0 & (1 << pinNumber))
KEIL
ARM VCC
Micro-controller HEX FILE 3.3v
LPC200
Flash Utility

RESET

LCD
MOTOR MD ROM

MAX CPU`
AVR
COMP BUZZER
232

SWITCH
RAM
INTERRUPT
ARM7 LED

O
GND S
C
ARM Microcontroller Programing

Input file
For
MCU
ARM
Microcontroller
Transferring file Compiling &
Using
Suitable medium
Building
Like USB or Of the Code
RS-232cable

Source Code
In
C- Language
Let’s check how to put brain in our
device
Light Emitting Diodes (LEDs) interface
Function
LEDs emit light when an
electric current passes
through them.

Advance Technology
Circuit symbol:
Program LED BLINK
#include<lpc214x.h>
void delay()
{
unsigned long int i;
for(i=0;i<=300000;i++);
}

int main()

Advance Technology
{
IODIR0=0XFFFFFFFF;
while(1)
{
IOCLR0=0XFFFFFFFF;
delay();
IOSET0=0XFFFFFFFF;
delay();
}
}
Switch Circuitry

A switch generates a
high to low pulse.
The pulse acts as
input to
microcontroller.
Microcontroller
senses the transition
and perform
appropriate task.

Advance Technology
PROGRAM FOR LED AND SWITCH

#include<lpc214x.h>
int main()
{
IODIR0&=~(1<<10);
IODIR0|=(1<<16);

while(1)
{
if(IOPIN0&(1<<10))
IOSET0|=(1<<16);
else
IOCLR0|=(1<<16);

}
}
LED Displays
LEDs can be combined together in a single
package to produce displays such as bar
graphs, strips, arrays and 7-segment displays.

Bar 7-segment Starburst Dot matrix


graph Advance Technology
7-segment Display

There are two important


types of
7-segment LED digital
display.

Advance Technology
The Common Cathode The Common Anode
Display (CCD) Display (CAD)
All cathodes are common All anodes are
and ground is being common and VCC is
provided.
being provided.

Advance Technology
Interfacing common anode
display

Advance Technology
PROGRAM(0-9 count)
#include<lpc214x.h>
void delay(unsigned long int h)
{
unsigned long int i,j;
for(j=0;j<h;j++)
for(i=0;i<5000;i++);
}
int main()
{
int a;
unsigned char arr[] = {0xbf, 0x86, 0xdb, 0xcf, 0xe6, 0xed, 0xfd, 0x87, 0xff, 0xef};
IODIR0 = 0xffffffff;
while(1)
{
for(a=0;a<=9;a++)
{
IOCLR0 = 0xffffffff;
IOSET0 = arr[a];
delay(1000);
}}}
#include"lpc214x.h" COUNT (00 to 99)
void delay(unsigned long int h)
{
unsigned long int i,j;
for(j=0;j<h;j++)
for(i=0;i<5000;i++);
}
int main()
{
int c,d,e;
unsigned char arr[] = {0xbf, 0x86, 0xdb, 0xcf, 0xe6, 0xed, 0xfd, 0x87, 0xff, 0xef};
IODIR0 = 0xffffffff;
while(1)
{ for(c=0;c<=9;c++)
{ for(d=0;d<=9;d++)
{ for(e=0;e<=100;e++)
{ IOCLR0 = 0xFFFFFFFF;
IOSET0 = arr[d]<<16 | 0x0100;
delay(5);
IOCLR0 = 0xFFFFFFFF;
IOSET0 = arr[c]<<16 | 0x0200;
delay(5);
} }}} }
Liquid Crystal Display
Liquid Crystal Displays
HD44780(LCDs)
 cheap and easy way to
display text, Displays
numbers, letters and fixed

Advance Technology
symbols
Various configurations (1
Line, 2 Line or 4 Line LCDs ).
Integrated controller
Data lines (DB7-DB0) used
to transfer data and
commands
Inside LCD
DDRAM - Display Data RAM
Display data RAM (DDRAM) stores display data
represented in 8-bit character codes.

Advance Technology
CGRAM - Character Generator
RAM
CGRAM area is used to create custom characters
in LCD. In the character generator RAM, the user
can rewrite character patterns by program.
Inside LCD
Instruction Register (IR)
Instruction register corresponds to
the register where you send commands to
LCD e.g. LCD shift command, LCD clear,
LCD address etc.

Advance Technology
Data Register (DR)
Data register is used for storing data
which is to be displayed on LCD.
Pin Information of LCD:

Advance Technology
UNDERSTANDING LCD Pins
8 data pins D7:D0
Bi-directional data/command pins.
Alphanumeric characters are sent in ASCII
format.

Advance Technology
LCD Initialization Commands:
1.Specify function set:
Send 38H for 8-bit,double line and 5x7 dot character
format.

2.Display On-Off control:


Send 0EH for display and blink cursor on.

Advance Technology
3.Entry mode set:
Send 06H for cursor in increment position and shift
is invisible.
4. Clear display:
Send 01H to clear display and return cursor to home
position.
Advance Technology
LCD Commands:
Algorithm to send data to LCD:

1. Place data byte on data register


2. Make RS=0 ;if data byte is command
RS=1 ;if data byte is data

Advance Technology
3. Pulse on E (HIGH to LOW)
4. Repeat the steps to send another
data byte
LCD CONNECTION

LCD data lines PO.0 to P0.8

LCD control lines PO.8 to P0.15


Program LCD INTERFACING

#include<lpc214x.h> void data_lcd(char dat)


#define RS (1<<8) {
#define E (1<<9)
void delay(unsigned long int h)
IOCLR0=0xffffffff;
{ IOSET0|= dat;
unsigned long int i,j; IOSET0|=RS;
for(j=0;j<h;j++) IOSET0|=E; delay(20);
for(i=0;i<500;i++); IOCLR0|=E;
}
void cmd_lcd(char dat)
}
{ IOCLR0=0xffffffff; void init_lcd()
IOSET0 |= dat; { cmd_lcd(0x38);
IOCLR0|=RS; cmd_lcd(0x0e);
IOSET0|=E; delay(20); cmd_lcd(0x06);
IOCLR0|=E;
}
cmd_lcd(0x01);
}
int main()
{
IODIR0=0xffffffff;
init_lcd();
while(1)
{
cmd_lcd(0x80);
data_lcd('A');
data_lcd('N');
data_lcd('K');
data_lcd('I');
data_lcd('T');
delay(100);
}
}
INTERNAL ADC

 LPC2148 has an inbuilt 10-bit Successive


Approximation ADC which is multiplexed among
6/8 input pins of ADC0/ADC1
 As LPC2148 works on 3.3 volts, this will be the
ADC reference voltage.
Now the $$resolution of ADC = 3.3/(2^{10}) =
3.3/1024 =0.003222 = 3.2mV$$
void init_rtc()
{ void main()
CCR=0x02; // to reset the {
counter,will increment the clock IODIR0=0xffffffff;
init_lcd();
SEC=10; init_rtc();
MIN=16; while(1)
HOUR=11; {
DOM = 2; // Update date x=HOUR; y=(x/10)+48; z=(x%10)+48;
value p=MIN; s=(p/10)+48; r=(p%10)+48;
MONTH = 15; // Update month a=SEC; h=(a/10)+48; m=(a%10)+48;
value cmd_lcd(0x80); data_lcd(y);
YEAR = 2017; // Update year cmd_lcd(0x81); data_lcd(z);
value cmd_lcd(0x82); data_lcd(s);
CCR=0x11; // to enable counter cmd_lcd(0x83); data_lcd(r);
n clk connect to oscillator cmd_lcd(0x84); data_lcd(h);
} cmd_lcd(0x85); data_lcd(m);
ADC(ANALOG TO DIGITAL CONVERTER)

Interfacing analog sensors using ADC is simple and


efficient technique to read data from sensor.
What is ADC & its Resolution?

Analog to Digital Converter (ADC) is used to


convert analog signal/voltage into its equivalent
digital number so that microcontroller can process
that numbers and make it human readable.
The ADC characterized by resolution.
The resolution of ADC indicates the number of
digital values

EXAMPLE:-In LPC2148 microcontroller we have


in-built 10-bit ADC.
So for 10-bit ADC resolution is 10-bit and
maximum value will be 210=1024.
This means our digital value or discrete level lies
between 0 to 1023
STEP SIZE

Step size is the minimum change in input


voltage which can be resolved by ADC. The
concept of step size is closely associated with the
resolution of ADC.
INTRODUCTION: ADC IN LPC2148 ARM7
MICROCONTROLLER

The ADC in LPC2148 ARM7 Microcontroller is 10-bit successive


approximation analog to digital converter. The features are listed as:

LPC2148 has two inbuilt ADC Modules, named as ADC0 & ADC1.
ADC0 has 6-Channels (AD0.1-AD0.6).
ADC1 has 8-Channels (AD1.0-AD1.7).
ADC operating frequency is 4.5 MHz (max.), operating frequency decides
the conversion time.
Supports power down mode.
Burst conversion mode for single or multiple inputs.

There are several registers associated with ADC feature but we will mainly
discussing about ADC Control Register (ADCR) & ADC Global Data
Register (ADGDR).
ADC RELATED PINS
egister Name Function

A/D Control Register: The ADCR register must be written to select the operating mode before
ADCR A/D conversion can occurs.

A/D Global Data Register: This register contains ADC’s DONE bit and the result of the most
ADGDR recent A/D conversion.

A/D Status Register: This register contains DONE and OVERRUN flag for all the A/D
ADSTAT Channels, as well as the A/D interrupt flag.

A/D Global Start Register: This address can be written (in the AD0 address range) to start
ADGSR conversions in both A/D converters simultaneously.

A/D Interrupt Enable Register: This register contains enable bits that allow the DONE flag
ADINTEN of each A/D channel to be included or excluded from contributing to the generation of an A/D
interrupt.

ADDRx A/D Channel x Data: ‘x’ varies from 0 to 7


#include<lpc214x.h>
#include"delay.h"
#include"lcd.h"
#include"adc.h"
#define ADC_PIN (3<<10) //P0.5 as Input to Sensor
#define ADC_PIN_DIR (1<<5) //Bit 5 of PINSEL0 register
#define ADC_CHANNEL 7 // CHANNEL NUMBER
int main()
{
unsigned int val;
PINSEL0 |= ADC_PIN; //Select the AD0.1 of P0.28
IODIR0 &= ~ ADC_PIN_DIR;
init_lcd();
string_lcd("ADC test");
init_adc0(10); //pass clkdiv value to Operate at 3MHz
while(1)
{
val=read_adc0(ADC_CHANNEL);// pass channel number
cmd_lcd(0xc0);
number_lcd(val); //display the result for some amount of time
delay_ms(100);
}
}
Internal RTC
PIN DESCRIPTION

UART0 pin description

Pin Type Description

RXD0 Input Serial Input. Serial receive data.

TXD0 Output Serial Output. Serial transmit data.


Registers Description: UART in LPC2148 ARM7
i

Registers Description/Function

U0THR
Transmit Hold Register: This register contains 8-bit write data which can be transmitted
through UART0. This is write only register.
Receive Buffer Register: This register contains 8-bit received data from UART0. This data
U0RBR is nothing but top most byte of Rx FIFO. When we use 5, 6 or 7-bit data then remaining bits
are padded with 0’s by default. This is read only register.

Line Control Register: The value or settings in this register configure the UART0 block. As
this is an 8-bit register. There are several parameters configured through this register such
U0LCR
as word length, stop bit, parity enable, parity select, break control, divisor latch access bit.
This register setting plays important role while initializing UART0 before using it.

U0DLL & U0DLM are standard UART0 baud rate generator divider registers. Each of this
U0DLL & register holds 8-bit values. Together these registers form a 16-bit divisor value which will be
U0DLM used for baud rate generation. This will be discussed further while code explanation with
respect to real world example.

Fractional Divider Register: This is another very important register, which plays
significant role in baud rate generation. In this 8-bit register, first four bits i.e. Bit[3 to 0]-
U0FDR
DIVADDVAL: This is the Prescale Divisor value. If this value is 0 then fractional baud rate
generator have no effect on UART0 baud rate. The remaining 4-bits i.e. Bit[4 to 7]-
MULVAL: This defines Prescale Multiplier value. Even if fractional baud rate generator is not
used the value in this register must be more than or equal to ‘1’.
UART0 REGISTER MAP
 U0LCR- Line Control Reg
• 8-BIT byte addressable reg
• Line control reg is used to select the length of char

• LSB two bits are char length selection bits.


• 0 0 – 5(xxx00000)
• 0 1 – 6(xx000000)
• 1 0 – 7(x0000000)
• 1 1 – 8(00000000)
U0LCR=0X83
BAUD RATE
U0CLR=0X03
DLAB(Divisor Latch Buffer)
 one high-low pulse across DLAB bit indicates baud
rate is successfully loaded.
 DLAB=1 baud rate is loading

 DLAB=0 After loading baud rate DLAB must be zero.


 Divisor Latch Reg
• DLR is 16-bit reg
• Used to load baud rate
• As the baud rate is 8-bit value, divide DLR into
two parts
• DLM & DLL(8-bit each)
• For 9600 baud rate
• U0DLL=0x83(12mhz)
• U0DLM=0x00

BAUD RATE=CLK/16*9600
 U0RBR(UART0 Receive buffer reg)
 8-bit byte addressable reg

 Data can be loading into U0RBR, whenever


receiving data.
 a=U0RBR----like SBUF
 U0THR(Transmit hold reg)
• 8-bit byte addressable reg
• Data can be loading to U0THR, whenever
transmitting data
• U0THR=‘A’----like SBUF
• THR buffer reg is used only for transmitting
 U0LSR(UART0 line status reg)

 8-bit byte addressable reg


 Consists of diff flag bits… TI interrupt & RI interrupt
flag bit
 0th bit of LSR is RI flag bit
 6th bit of LSR is TI flag bit
 Monitoring TI bit syntax
 While(!(U0LSR&0x40));
 Monitoring RI bit syntax
 While(!(U0LSR&0x10));
#define PCLK 15000000UL

void init_uart0 (unsigned int Baud_Rate) // Initialize Serial Interface


{
PINSEL0 |= 0x00000005; //Enable RxD0 and TxD0
U0LCR = 0x83; // 8 bits, no Parity, 1 Stop bit
U0DLM = 0x00;
U0DLL = PCLK /(16*Baud_Rate); // Baud Rate @ 15MHz Pclk Clock as default setting
U0LCR = 0x03; / / DLAB = 0
}

void trans_uart0 (unsigned char ch) // Write character to Serial Port


{
while (!(U0LSR & 0x20));
U0THR = ch;
}
unsigned char rec_uart0 (void) // Read character from Serial Port
{
while (!(U0LSR & 0x01));
return (U0RBR);
}

void string_uart0(unsigned char *str) //A function to send a string on UART0


{
while(*str)
{
trans_uart0(*str++);
}
}
#include <LPC214X.H>
#include"uart0.h"

int main()
{
init_uart0(9600);
string_uart0("SERIAL COMMUNICATION TEST
WITH ARM\n\r");
while(1)
{
trans_uart0(rec_uart0());
}
}
RFID interface
Radio-Frequency Identification (RFID) is the use of a
wireless non-contact system that uses radio-frequency
electromagnetic fields to transfer data from a tag attached to
an object, for the purposes of automatic identification and
tracking.
COMPONENTS OF RFID
 There are two main components of RFID

 The RF reader (known also as the base


station or interrogator)

 The RF tag (or transponder)


TAGS
 There are two main components present
in the RFID tag
• Firstly, a small silicon chip or
integrated circuit which contains a
unique identification number (ID).

• Secondly, an antenna that can send


and receive radio waves.
READERS
 An RFID reader is a device that is used to
interrogate an RFID tag. The reader has an
antenna that emits radio waves; the tag responds
by sending back its data.

 The reader has two basic components –


 A scanning antenna
 A transceiver with a decoder to interpret the data
RFID CONNECTION
Connection:
 LCD data lines -> P1(16-23)
 LCD control Lines -> P1(24-31)
 RFID is connection -> P0(8-15)
 Relay -> P0(16-23)
output:
 In this demo code
 Two RFID card are used to control two device 1
and 2 connected with relay
 if you swap card one time then device is on and on
the second time device is off
ZIGBEE INTRODUCTION

 ZigBee is a specification for wireless personal area


networks (WPANs) operating at 868 MHz, 902-928 MHz,
and 2.4 GHz.
 A WPAN is a personal area network (a network for
interconnecting an individual's devices) in which the device
connections are wireless.
 Using ZigBee, devices in a WPAN can communicate at
speeds of up to 250 Kbps while physically separated by
distances of up to 50 meters in typical circumstances and
greater distances in an ideal environment.
 ZigBee is based on the 802.15 specification approved by
the Institute of Electrical and Electronics Engineers
Standards Association (IEEE-SA).
 ZigBee is used in applications that require only a low data rate,
long battery life, and secure networking. ZigBee has a defined
rate of 250 kbit/s, best suited for periodic or intermittent data or
a single signal transmission from a sensor or input device

 Applications include wireless light switches, electrical meters


with in-home-displays, traffic management systems, and other
consumer and industrial equipment that requires short-range
wireless transfer of data at relatively low rates.
ZIGBEE CONNECTION
Connection:
 1st Xbee module -> converter module
 converter module -> first box header of
converter module with ARM daughter card P0(8-
15)
 and second box header of converter module
with first xbee module
 2nd Xbee module -> computer
 LED module -> P1(16-23)
Thank You

You might also like