ARM Embedded Processor Interfacing_v4 0
ARM Embedded Processor Interfacing_v4 0
Embedded Processor
Interfacing
Embedded Programming (ARM)
2
ARM 7 PIN Diagram
3
Features of the ARM Microcontroller
Feature Quantit
y
ROM 512K
Bytes
RAM 40k
Bytes
Timer 2
I/O Ports 2
Serial Port 2
Interrupt Sources 32
4
ARM Board Interface
HEX FROM
HOST MACHINE SEVEN SEGMENT PORT DISPLAY LCD GSM
PROGRAMMER IC KEYBOARD
ARM
I2C I2C
ARM Interface
5
ARM Board
6
GPIO Ports (Contd.).
• Can send or receive 32 bit data through ports
• Data’s are ASCII, binary and BCD form
• Can send bit pattern through ports.
IODIR1 |= 0x00FF0000;
7
GPIO Ports (Contd.).
/* P1.24to P1.31 directions are configured as Outputs */
IODIR1 |= 0xFF000000;
8
GPIO Port Read / Write
/* switching on individual LEDs with a software delay */
#include <LPC214X.H>
void delay(void)
{
unsigned int i;
{
;
}
}
void main(void)
{
IODIR1=0XFFFFFFFF;
while(1)
{
IOSET1=0XFF<<24;
delay();
IOCLR1=0XFF<<24;
delay();
}
}
9
Display Devices
10
7 Segment LED Displays:
Interfacing
a
a Common Anode ‘0’
== ON
ff b
b
g
g
Common Cathode ‘1’ ==
e
e cc ON
d
d
h
h
Examples:
‘E’ ®10000110 (CA)
h g f e d c b a
‘’ ®01111001 (CC)
7 6 5 4 3 2 1 0
11
Interfacing (Contd.).
#include <LPC214X.H>
SEG[]={0x3f,0x6,0x5b,0x4f,0x66,0x6d,0x7d,0x7,0x7f,0x67,0x77,0x7c,0x39,0
x5e,0x79,0x71};
const char NUM[]={0,1,2,3}; //NUMBER TO BE DISPLAYED
int main()
{
unsigned char j;
j=00;
IODIR1=0XFFFFFFFF;
IODIR0=3<<16;
//IODIR0=0XF0000000;
while(1)
{
IOSET0=3<<16; //0FF
12
Interfacing (Contd.).
switch(j) //J IS DIGIT COUNTER
{
case 0:
IOCLR1=0XFF<<16;
delay();
delay();
delay();
delay(); //DISPLAY DELAY
break;
case 1:
IOCLR1=0XFF<<16;
IOSET1=(~SEG[NUM[3]])<<16;
IOCLR0=1<<17; //CLEAR P1.17 MODIFY DIGIT SELECT 1
break;
13
LCD Display
HD 44780
0X80 0X87 0X8F
ABC 2 x 16
LCD Lines Char
RSRW EN
Data
15
LCD Initialization
• 0X38 4 Times to
Enable LCD
• 0X06 Auto
Increment
• 0X80 Start
Location
• Data
16
LCD
void Lcd_Initialize(void)
{
IODIR1 |= 0xFFFF0000; /* GPIO Port as 1 */
IODIR0 |= 0x000F0000; /* GPIO Port as 1 */
//IODIR1 |=0X3F<<16;
CMD_WRITE(0x38);
CMD_WRITE(0x38);
CMD_WRITE(0x38);
CMD_WRITE(0x38);
CMD_WRITE(0xe);
CMD_WRITE(0x1);
CMD_WRITE(0x06);
CMD_WRITE(0x80);
17
LCD (Contd.).
void DATA_WRITE(unsigned char dat)
{
IOCLR1 |= 0x00FF0000; /* /* P1.16 to p1.23 is connected LCD
Data pins */
IOSET1 |= dat << 16;
IOSET0 |=0x00010000; /* rs=1 */
IOCLR0 |=0x00020000; /* r/w=0 */
IOSET0 |=0x00040000; /* EN=1 */
delay1();
IOCLR0 |=0x00040000; /* EN=0 */
delay1();
}
18
LCD (Contd.).
void CMD_WRITE(unsigned char dat)
{
IOCLR1 |= 0x00FF0000; /* P1.16 to p1.23 is connected LCD
Data pins */
IOSET1 |= dat << 16;
IOCLR0 |=0x00010000; /* rs=0 */
IOCLR0 |=0x00020000; /* r/w=0 */
IOSET0 |=0x00040000; /* en=1 */
delay1();/*10 ms delay */
IOCLR0 |=0x00040000; /* en=0 */
delay1(); /*10 ms delay */
}
19
Interfacing a Keypad
• A 16-key keypad is built as shown in the figure below.
– 16 keys arranged as
a 4X4 matrix.
– Must “activate”
each column by placing
a 0 on its C output.
R1
• Then the Row R2
output is read. R3
• If there is a 0 on R4
one of the Row
bits, then the button
at the column/row
intersection has
been pressed. C1
• Otherwise, try next column. C2
C3
– Repeat constantly. C4
20
Interfacing a Keypad (Contd.).
• Algorithm:
– Drive a “0” on a columns
– Read all the row
– If any key had been pressed, its row will be “0”, else 1
– Keep repeating in a loop for each successive column
21
Interfacing a Keypad (Contd.).
#include <LPC214X.H>
clm0_lookup[]={0,0,0,0,0,0,0,0xC,0,0,0,0x8,0,4,0,0};
const clm1_lookup[]={0,0,0,0,0,0,0,0xD,0,0,0,0x9,0,5,1,0};
const clm3_lookup[]={0,0,0,0,0,0,0,0xF,0,0,0,0xB,0,7,3,0};
const clm2_lookup[]={0,0,0,0,0,0,0,0xE,0,0,0,0xA,0,6,2,0};
unsigned char NUM[]={0,0,0,0};
22
Interfacing a Keypad (Contd.).
void COLM0_E(void)
{
IOCLR1=CLM0;
IOCLR1=CLM1;
IOCLR1=CLM2;
IOCLR1=CLM3;
IOSET1=CLM1;
IOSET1=CLM2;
IOSET1=CLM3;
23
Interfacing a Keypad (Contd.).
unsigned char key_scan(unsigned char clm_control)
{
//VICIntEnClr =0x10;
if((clm_control==0))
{
COLM0_E();
}
24
Interfacing a Keypad (Contd.).
int main(void)
{
IODIR0=0X200;
IODIR1=0XFFF0FFfF;
key_buf=0xff;
while(1)
{
if((k=key_scan(0))!=0xff)
{
IOCLR1=0XFF<<24;
IOSET1=~k<<24;
}}
}
25
Serial port and Communication
26
RS232 C
SERIAL PORT
COM 1 – 9 PINS
COM 2 – 25 PINS
SYNCRONOUS
BASIC
USART COMMUNICATI
ON TECHNIQUE
MP - 8251 SIMPLEX
PC
HALF DUPLEX
MC - 8250 ASYNCRONOUS FULL DUPLEX
MC - 16450
MC - 16550
TX TX
PC PC
RX RX
1 2
GND NULL MODEM GND
27
Setting the Baud rate
28
Steps to Transmit a Byte
PINSEL0 |=0x5; //UART0
U0LCR =0x83; //DLB DIV latch buf 1
Fdiv=(Fpclk/16)/baud_rate;
U0DLM =Fdiv/256; //Latch MSB
U0DLL=Fdiv % 256;//Latch LSB
U0LCR =0x3; // Line -Word length
U0FCR =0x07; //FIFO
29
Serial data transmission
#include <LPC214X.H>
PINSEL0 |=0x5;
U0LCR =0x83;
Fdiv=(Fpclk/16)/baud_rate;
U0DLM =Fdiv/256;
U0DLL=Fdiv % 256;
U0LCR =0x3;
U0FCR =0x07;
30
Serial data transmission (Contd.).
int main(void)
{
INIT_PLL();
UART_INIT(9600);
while(1)
{
while(!(U0LSR & 0X20));
{
U0THR='F';
}
}
}
31
Interrupt Priority
• Default Priority
32
Interrupt Priority (Contd.).
Main()
{
Enable interrupt
While(1)
{
----
-----
}
CPU EXT3
int(void) interrupt()
{
}
33
Inter-Integrated Circuit (I2C)
Protocol
• Inter-Integrated Circuit Protocol
• I2C is a low-bandwidth, short-distance, two-wire interface for
communication amongst ICs and peripherals
• Originally developed by Philips for TV circuits
• Currently, many devices are available that have hardware
interfaces compatible with this protocol
• Figure shows example connection of devices based on this
protocol.
34
I2C Features
• Only two bus lines are required
– The SDA(for data) and
– SCL(for clock)
• Each device connected to the bus is software addressable.
• Simple master-slave relation amongst devices (either can
be receiver or transmitter)
• Serial, 8-bit oriented, bi-directional data transfer can be
achieved up to100 kbit/s (and up to 3.4Mbit/s in the high
speed mode).
35
I2C Start/Stop Conditions
• START condition: Signals begin of transfer (occupies the
bus)
– A HIGH to LOW transition on the SDA line while the SCL is HIGH
• STOP condition: Signals end of transfer (releases the bus)
– A LOW to HIGH transition on the SDA line while the SCL is HIGH
• Both these are always generated by the Master
• Repeated START condition is allowed
– Repeated start is used for changing the slave, or changing the
direction of data transfer (Send/Receive) for the same slave.
36
I2C
Master Slave 1
SA = 0X40(W)
PCF 8574
ARM SA = 0X41(R)
Slave 2
SA1 = 0X48(W)
PCF 8574
SA1 = 0X49(R)
SDA
SCL
37
Data Transfer
• In Master-Transmitter to Slave-Receiver Data Transfer the
transmission direction never changes. The set-up and
transfer is straight-forward.
38
I2C
I2C Write
0X40
I2C Read
0X41
39
I2C Seven Segment
40
Thank You