Sei sulla pagina 1di 44

Development of the ARM

Architecture
ARM has introduced many processors. Each set or groups of processors
are having different core and different Features. Development of the ARM
Architecture is started with 26 bit processors and nowadays it reach upto
64 bit. we can not classify general development of ARM products on any
particular fact, there is only one way to understand ARM based products is
on its Architectural version profile.

ARM Classic series

The classical ARM series refers to processors starting from ARM7 to


ARM11. This is the series which gives market boost to ARM because of its
core features like Data Tightly Coupled memory, cache, MMU, MPU, etc.
Typical examples of this series are ARM7TDMI, ARM926EJ-S, ARM11
MPCore, etc.

Cortex-A series: A-profile, the Application profile


In this Cortex architecture, we port different embedded OS and
design embedded system by OS system programming. The core feature of
this profile is Highest performance at low power, TrustZone and JazelleRCT for a safe and extensible system. Practical development platform of
this types of profile is FriendlyARM, Raspberry Pi, etc.

Cortex-R series: R-profile, the Real-time profile:

This is Cortex architecture which mostly used for real time purpose where
application abort is critical situation contain core features like Protected
memory (MPU), Low latency and predictability real-time needs.

Cortex-M series: M-profile, the Microcontroller profile:


This profile is specially dedicated for microcontroller purpose only. The
core feature of this profile is like Lowest gate count entry point,
Deterministic and predictable behavior a key priority, Deeply embedded
use. Typical example of this kind of profile architecture is Hercules
TMS470M, STM32F429, etc.

Processor Modes

All these mode indicates its special work and execute under certain
condition with its own stack and a different subset of registers. Modes
other than User mode are collectively known as privileged modes. your
program or application generally runs under User mode. Privileged modes
are used to service interrupts or exceptions, or to access protected
resources.

The ARM Register Set

CPSC Current program status register


SPSR Saved program status register
LR Link register
SP Stack Pointer
PC Program Counter

Current/State Program
Status Register (CPSR /
SPSR)

Condition code flags (Bit 28 to 31)

V = ALU operation oVerflowed

C = ALU operation Carried out

Z = Zero result from ALU

N = Negative result from ALU


Sticky Overflow flag Q flag (Bit
27)

Architecture 5TE and later only

Indicates if saturation has


occurred
J bit (Bit 24)

Architecture 5TEJ and later only

J = 1: Processor in Jazelle state

T Bit (Bit 5)

T = 0: Processor in ARM state

T = 1: Processor in Thumb state

Introduced in Architecture 4T
Mode bits (Bit 0 to 4)

Specify the processor mode


New bits in V6 (Bit 10 to 19)

GE[3:0] used by some SIMD


instructions

E bit controls load/store endianness

A bit disables imprecise data aborts

IT [abcde] IF THEN conditional

execution of Thumb-2 instruction

Interrupt Disable bits (Bit 6 Bit 7)

I = 1: Disables IRQF = 1:
Disables FIQ

groups

ARM Instruction Set

All instructions are 32 bits long / many execute in a single cycle


Instructions are conditionally executed
A load / store architecture
Example data processing instructions

SUB r0,r1,#5

r0 = r1 5

ADD r2,r3,r3,LSL #2

r2 = r3 + (r3 * 4)

ADDEQ r5,r5,r6

IF EQ condition true r5 = r5 + r6

Example branching instruction

B <Label>

Branch forwards or backwards relative to current PC (+/32MB range)

Example memory access instructions

LDR r0,[r1]

Load word at address r1 into r0

STRNEB r2,[r3,r4]

IF NE condition true, store bottom byte of r2 to address


r3+r4

STMFD sp!,{r4-r8,lr}

Store registers r4 to r8 and lr on stack. Then update


stack pointer

Thumb Instruction Set

Thumb is a 16-bit instruction set


Optimized for code density from C code (~65% of ARM code size)
Improved performance from narrow memory
Subset of the functionality of the ARM instruction set
Thumb is not a regular instruction set because that targeted at
compiler generation, not hand coding.

An application code compiled in Thumb is 30% smaller on average


than the same code compiled in ARM and normally 30% faster when
using narrow 16-bit memory systems.

Thumb-2 Instruction Set

Thumb-2 is a major extension to the Thumb ISA


Adds 32-bit instructions to implement almost all of the ARM ISA
functionality
Retains the complete 16-bit Thumb instruction set
Compiler automatically selects mix of 16 and 32 bit instructions

The Instruction Pipeline


The ARM7TDMI uses a 3-stage pipeline in order to increase the speed of
the flow of instructions to the processor which allows several operations to
be performed simultaneously, rather than sequentially. The basic steps of
any operation is

Fetch :- Instruction fetched from memory


Decode :- Decoding of registers used in instruction
Execute :- Register(s) read from Register Bank, Shift
operation, Write register(s) back to Register Bank.

and

ALU

In ARM architecture, pipe-lining is possible because of its RISC feature in


which all instruction size is same so we can take advantage of pipe-lining.

As you can see on above figure when ADD instruction is executing we


fetched and start decoding next instruction SUB and at the same time we
fetched the ORR instruction. So in the time of single instruction execution,
we performing 3 instruction. Therefore, this is called three stage pipelining.

Exception Handling

When an exception occurs, the core:

Copies CPSR into SPSR_<mode>

Sets appropriate CPSR bits

Change to ARM state

Change to exception mode

Disable interrupts (if appropriate)

Stores the return address in LR_<mode>

Sets PC to vector address

To return, exception handler needs to:

Restore CPSR from SPSR_<mode>

Restore PC from LR_<mode>

Terms
ARM

associated

with

EmbeddedICE
In order to provide a powerful debugging environment for ARM-based
applications the EmbeddedICE logic was developed and integrated into
the ARM core architecture. It is a set of registers providing the ability to
set hardware breakpoints or watch-points on code or data.
The EmbeddedICE logic monitors the ARM core signals every cycle to
check
if
a
break-point
or watch-point
has
been
hit.
Communication with the EmbeddedICE logic from the external
world is provided via the test access port or TAP, controller and a standard
IEEE 1149.1 JTAG connection. The advantage of on-chip debug solutions is
the ability to rapidly debug software, especially when the software resides
in ROM or Flash.

AMBA Bus
The Advanced Micro-controller Bus Architecture on-chip bus is freely
available from ARM and offers an established, open specification that
serves as a framework for SoC designs.

Reference www.arm.com
The design of the AMBA bus specification is focused on low power
consumption and high performance. A typical AMBA-based SoC consists of
an advanced high-performance system bus(AHB), and an advanced low
power peripheral bus(APB). As seen in above pic

On the performance critical side of the bus is the ARM core, Memory

Controller, Test Interface Controller (TIC), the LCD Controller, on-chip IP,
custom logic, and specialized functions.
On the low power side of the bus is the Smart Card interface, audio

codec, UART, PWM, Timers, GPIO, etc.


This is an excellent example of how the AHB and APB buses work in

conjunction to provide a complete system solution.


These bus protocols are independent of the ARM processor
and generalized for SoC application. The AMBA test methodology provides
a mechanism to give an external tester access to the on-chip AMBA bus.
This enables the tester to take control of the bus and check each
component separately.

MMU
The Memory Management Unit works with the cache memory system to
control accesses to and from external memory. The MMU also controls the
translation of Virtual Addresses to physical addresses and access

permission checks for the instruction and data ports of Processors. An


MMU mitigates the problem of fragmentation of memory too.

MPU
A separate Memory Protection Unit feature has been introduced in ARM
by Cortex-M3 cores which provide a way to control memory access rights
to applications. This prevents a bug within a process from affecting other
processes, or the operating system itself, and instead results in a
segmentation fault or storage violation exception, generally causing
termination of the process. In ARM core, separate registers are provided
by which you can configure certain portion of memory and its access
rights.

Why beginning with LPC2148 to start ARM ?

ARM7 is greatest success family in embedded system application.

So here we learn ARM7TDMI based NXPs controller.


ARM7 is balance between new Cortex series and old start up. it is

neither too old technology nor latest


ARM7 family is excellent for beginners as per my opinion, because it
gives real depth idea about hardware and software implementation &
integration by using appropriate IDE.

Features of LPC2148

LPC2148 is the widely used IC from ARM-7 family. It is manufactured by


Philips (NXP) and it is pre-loaded with many inbuilt peripherals making it
more efficient and a reliable option for the beginners as well as high end
application developer.

8 to 40 kB of on-chip static RAM


32 to 512 kB of on-chip flash program memory.
128 bit wide interface/accelerator enables high speed 60 MHz

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

loader software.
Embedded ICE RT and Embedded Trace interfaces offer real-time

debugging with the on-chip Real Monitor software and high speed
tracing of instruction execution.
USB 2.0 Full Speed compliant Device Controller with 2 KB of

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


accessible to USB by DMA.
One or two (LPC2141/2 vs. LPC2144/6/8) 10-bit A/D converters

provide a total of 6/14analog inputs, with conversion times as low as


2.44
us
per
channel.
Single 10-bit D/A converter provides variable analog output.
Two 32-bit timers/external event counters (with four capture and

four compare channels each), PWM unit (six outputs) and watchdog.
Low power real-time clock with independent power and dedicated

32 kHz clock input.

Multiple serial interfaces including two UARTs (16C550), two Fast

I2C-bus(400 kbps), SPI and SSP with buffering and variable data length
capabilities.
Vectored interrupt controller with configurable priorities and vector

addresses.
Up to 45 of 5 V tolerant fast general purpose I/O pins in a tiny

LQFP64 package.
Up to nine edge or level sensitive external interrupt pins available.
Power saving modes include Idle and Power-down.
Processor wake-up from Power-down mode via external interrupt,

USB, Brown-Out Detect (BOD) or Real-Time Clock (RTC).


Single power supply chip with Power-On Reset (POR) and BOD

circuits: CPU operating voltage range of 3.0 V to 3.6 V (3.3 V 10 %)


with
5
V
tolerant
I/O
pads.

Pin-out of LPC 2148

ARM identification

For Example : ARM 7 TDMI (LPC2148)

ARM 7 modes
1.
2.

User mode all normal application run under this mode


FIQ mode all fast interrupt data transfer or channel process service
provided under this mode
3.
IRQ mode vectored(priority based) interrupt handler
4.
Supervision mode protected mode for the operating system
5.
System mode all operating related task
6.
Abort mode entered after a data or instruction Pre-fetch Abort
exception
7.
Undefined mode entered when an undefined instruction is
executed.
All these mode indicates its special work and execute
under certain condition. Modes other than User mode are collectively
known as privileged modes. your program or application generally runs
under User mode. Privileged modes are used to service interrupts or
exceptions, or to access protected resources.

Interfacing ARM7 with LED:


Circuit Diagram:

#include<lpc21xx.h> // header file for lpc2148 controller


void delay(); // initialization of delay function
int main()
{
PINSEL0=0X00000000; // SELECT PORT0 PIN0 TO PIN 15 AS GPIO
MODE
IO0DIR=0XFFFFFFFF; // MAKE PORT0 PIN AS OUTPUT MODE
while(1)
{
IO0SET=0XFFFFFFFF; // SET THE PORT0 PINS
delay();
// HAULT FOR SOME TIME
IO0CLR=0XFFFFFFFF; // CLEAR THE PORT0 PINS
delay();
//HAULT FOR SOME TIME
}
}
void delay() // initialization of delay function
{
int i,j;

for(i=0;i<1000;i++)
for(j=0;j<1000;j++);
}

Interfacing seven segment display:

#include<LPC21XX.H> // header file for lpc2148


void delay(); // delay function
unsigned int i,j,k; // globle variable
unsigned int
ar[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90 }; // array
data
int main()
{
PINSEL0=0X00000000; // select port0 as gpio mode
IO0DIR =0X000000FF; // make starting 8 pin as output and other as
input of port0
while(1)
{
for(i=0;i<10;i++)
{

IO0SET =ar[i];
delay();
IO0CLR =ar[i];
}
}
return 0;
}
void delay()
{
for(j=0;j<1000;j++)
for(k=0;k<400;k++);
}

Interfacing LCD with ARM7:

#include<lpc21xx.h>
#define
#define
#define
#define
void
void
void
void

LCD (0xff<<16)
RS (1<<13)
RW (1<<14)
EN (1<<15)

delay_fv(unsigned int x,int y);


lcd_display(unsigned int x);
cmd(unsigned char m);
lcd_ini();

int main()

{
PINSEL0=0X00000000;
IO0DIR=0XFFFFFFFF;
lcd_ini();
while(1)
{
lcd_ini();
lcd_display(' ');
lcd_display('W');
delay_fv(1000,400);
lcd_display('E');
delay_fv(1000,400);
lcd_display('L');
delay_fv(1000,400);
lcd_display('C');
delay_fv(1000,400);
lcd_display('O');
delay_fv(1000,400);
lcd_display('M');
delay_fv(1000,400);
lcd_display('E');
delay_fv(1000,400);
lcd_display(' ');
delay_fv(1000,400);
lcd_display('T');
delay_fv(1000,400);
lcd_display('O');
delay_fv(1000,400);
cmd(0x0c0);
lcd_display('F');
delay_fv(1000,400);
lcd_display('I');
delay_fv(1000,400);
lcd_display('R');
delay_fv(1000,400);
lcd_display('M');
delay_fv(1000,400);
lcd_display('C');
delay_fv(1000,400);
lcd_display('O');
delay_fv(1000,400);
lcd_display('D');
delay_fv(1000,400);
lcd_display('E');
delay_fv(1000,400);
lcd_display('S');
delay_fv(1000,400);
lcd_display('.');
delay_fv(1000,400);
lcd_display('C');
delay_fv(1000,400);
lcd_display('O');
delay_fv(1000,400);
lcd_display('M');

delay_fv(1000,400);
}
}
void delay_fv(unsigned int x,int y)
{
unsigned int i,j;
for(i=0;i<x;i++)
for(j=0;j<y;j++);
}
void lcd_display(unsigned int x)
{
IO0CLR|=(RS|RW|EN|LCD);
IO0SET|=(x<<16);
IO0SET|=RS;
IO0CLR|=RW;
IO0SET|=EN;
delay_fv(100,10);
IO0CLR|=EN;
delay_fv(10,10);
}
void cmd(unsigned char m)
{
IO0CLR|=(RS|RW|EN|LCD);
IO0SET|=(m<<16);
IO0CLR|=RS;
IO0CLR|=RW;
IO0SET|=EN;
delay_fv(100,100);
IO0CLR|=EN;
delay_fv(100,10);
}
void lcd_ini()
{
cmd(0X38);
cmd(0X0e);
cmd(0X06);
cmd(0X01);
cmd(0X80);
}

Interfacing switch with ARM7:

#include<lpc21xx.h>
#define switch_1 (IO0PIN&0X01)
#define led (0xff<<1)
void delay();
int main()
{
PINSEL0=0X00000000;
IO0DIR=0Xfffffffe;
IO0CLR=led;
while(1)
{
if(switch_1==1)
{
IO0SET=led;
delay();
IO0CLR=led;
delay();
}
}
}
void delay()
{
int i,j;

for(i=0;i<100;i++)
for(j=0;j<600;j++);
}

7 segment Display + LED


#include<lpc21xx.h>
#define switch_1 (IO0PIN&(1<<0))
#define switch_2 (IO0PIN&(1<<1))
#define led (0xff<<2)
void delay();
int data1[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90 }; // array
data
int main()
{
int i=0;
PINSEL0=0X0000000;
IO0DIR=0XFFFFFFFD;
while(1)
{
if(switch_1==1)
{
IO0SET=led;
delay();
delay();
IO0CLR=led;
delay();
}
if(switch_2==0)
{
if(i==10)
i=0;
IO0SET=(data1[i]<<12);
delay();
delay();
delay();
delay();
delay();
delay();
delay();
delay();
IO0CLR=(data1[i]<<12);
i++;
}
}
}
void delay()
{

int i,j;
for(i=0;i<100;i++)
for(j=0;j<600;j++);
}

RS232 with ARM 7

#include<lpc21xx.h>
unsigned char rec;
void pll();
void serial_ini();
void serial_transmit(unsigned char x);
void delay(int x);
int main()
{
PINSEL0 = 0x00000005;
IO0DIR=0XFFFFFFFF;
serial_ini();
pll();
while(1)
{

serial_transmit('W'); // call transmit function


delay(100);
// calling of delay function
serial_transmit('W'); // call transmit function
delay(100);
// calling of delay function
serial_transmit('W'); // call transmit function
delay(100);
// calling of delay function
serial_transmit('.'); // call transmit function
delay(100);
// calling of delay function
serial_transmit('F'); // call transmit function
delay(100);
// calling of delay function
serial_transmit('I'); // call transmit function
delay(100);
// calling of delay function
serial_transmit('R'); // call transmit function
delay(100);
// calling of delay function
serial_transmit('M'); // call transmit function
delay(100);
// calling of delay function
serial_transmit('C'); // call transmit function
delay(100);
// calling of delay function
serial_transmit('O'); // call transmit function
delay(100);
// calling of delay function
serial_transmit('D'); // call transmit function
delay(100);
// calling of delay function
serial_transmit('E'); // call transmit function
delay(100);
// calling of delay function
serial_transmit('S'); // call transmit function
delay(100);
// calling of delay function
serial_transmit('.'); // call transmit function
delay(100);
// calling of delay function
serial_transmit('C'); // call transmit function
delay(100);
// calling of delay function
serial_transmit('O'); // call transmit function
delay(100);
// calling of delay function
serial_transmit('M'); // call transmit function
delay(100);
// calling of delay function
serial_transmit(0x0d); // call transmit function
delay(400);
delay(400);
}
}
void pll()
{
/*PLL IS CONFIGURED TO GET 60HZ pCLK*/
PLLCFG=0X24;
// SET PSEL=2 AND MSEL=5
PLLCON=0X01;
//PLL IS ACTIVE BUT NOT YET CONNECT
PLLFEED=0XAA;
//FEED SEQUENCE
PLLFEED=0X55;
//FEED SEQUENCE
while((PLLSTAT & 0X400)==0); //WAIT FOR FEED SEQUENCE TO BE
INSERTED
PLLCON=0X03;
// PLL HAS BEEN ACTIVE AND BEING CONNECTRD
VPBDIV=0X00;
// SET PCLK SAME AS FCCLK
PLLFEED=0XAA;
//FEED SEQUENCE
PLLFEED=0X55;
//FEED SEQUENCE

}
/* SERIAL INITILIZATION*/
void serial_ini()
{
U0LCR =0x83;
U0DLM=0X00;
U0DLL=0X5e;
U0FDR=0X52;
U0LCR =0x03;
}
void serial_transmit(unsigned char x)
{
U0THR =x;
// LOAD DATA IN U0THR REGISTER
while ((U0LSR & 0x40)==0); // WAIT FOR DATA TRANSMISSION
U0LSR|=0X40;
}
void delay(int x)
{
int i,j;
x=x*10;
for(i=0;i<x;i++)
for(j=0;j<350;j++);
}

#include<lpc21xx.h>
#define
#define
#define
#define

LCD (0xff<<16)
RS (1<<13)
RW (1<<14)
EN (1<<15)

void delay_fv(unsigned int x,int y);


void lcd_display(unsigned int x);
void cmd(unsigned char m);
void lcd_ini();
unsigned char rec;
void pll();
void serial_ini();
char serial_re();
int main()
{
PINSEL0 = 0x00000005;
PINSEL1 = 0x00000000;
IO0DIR=0XFFFFFFFF;
serial_ini();

pll();
lcd_ini();
while(1)
{
serial_re();
lcd_display(rec);
}
}
void delay_fv(unsigned int x,int y)
{
unsigned int i,j;
for(i=0;i<x;i++)
for(j=0;j<y;j++);
}
void lcd_display(unsigned int x)
{
IO0CLR|=(RS|RW|EN|LCD);
IO0SET|=(x<<16);
IO0SET|=RS;
IO0CLR|=RW;
IO0SET|=EN;
delay_fv(100,10);
IO0CLR|=EN;
delay_fv(10,10);
}
void cmd(unsigned char m)
{
IO0CLR|=(RS|RW|EN|LCD);
IO0SET|=(m<<16);
IO0CLR|=RS;
IO0CLR|=RW;
IO0SET|=EN;
delay_fv(100,100);
IO0CLR|=EN;
delay_fv(100,10);
}
void lcd_ini()
{
cmd(0X38);
cmd(0X0e);
cmd(0X06);
cmd(0X01);
cmd(0X80);
}
void pll()
{
/*PLL IS CONFIGURED TO GET 60HZ pCLK*/
PLLCFG=0X24;
// SET PSEL=2 AND MSEL=5
PLLCON=0X01;
//PLL IS ACTIVE BUT NOT YET CONNECT

PLLFEED=0XAA;
//FEED SEQUENCE
PLLFEED=0X55;
//FEED SEQUENCE
while((PLLSTAT & 0X400)==0); //WAIT FOR FEED SEQUENCE TO BE
INSERTED
PLLCON=0X03;
// PLL HAS BEEN ACTIVE AND BEING CONNECTRD
VPBDIV=0X00;
// SET PCLK SAME AS FCCLK
PLLFEED=0XAA;
//FEED SEQUENCE
PLLFEED=0X55;
//FEED SEQUENCE
}
void serial_ini()
{
U0LCR =0x83;
U0DLM=0X00;
U0DLL=0X5e;
U0FDR=0X52;
U0LCR =0x03;
}
char serial_re()
{
while ((U0LSR & 0x01)==0); // wait untill complete data is received
rec=U0RBR;
return rec;
}

Interfacing timer with ARM7:

#include<lpc21xx.h>
# define PRESCALAR 60000

// define prescalar as 60000

void pll();
void timer0_ini();
void delay(unsigned long int ms);
int main()
{
PINSEL0=0x00000000; // select gpio pin
IO0DIR=0XFFFFFFFF; // make gpio as output pin
pll();
// calling pll function
timer0_ini();
// calling timer function
while(1)
{
IO0SET=0XFFFFFFFF; // led on
delay(0x000000fF); // delay using timer 0
IO0CLR=0XFFFFFFFF; // led off
delay(0x000000fF); // delay using timer 0
}
return 0;
}
void pll()
{
//PLL IS CONFIGURED TO GET 60HZ pCLK
PLLCFG=0X24;
// SET PSEL=2 AND MSEL=5
PLLCON=0X01;
//PLL IS ACTIVE BUT NOT YET CONNECT
PLLFEED=0XAA;
//FEED SEQUENCE
PLLFEED=0X55;
//FEED SEQUENCE
while((PLLSTAT & 0X400)==0); //WAIT FOR FEED SEQUENCE
TO BE INSERTED
PLLCON=0X03;
// PLL HAS BEEN ACTIVE AND BEING
CONNECTRD
VPBDIV=0X00;
// SET PCLK SAME AS FCCLK
PLLFEED=0XAA;
//FEED SEQUENCE
PLLFEED=0X55;
//FEED SEQUENCE
}
void timer0_ini()
{
T0TCR=0X0; // to stop timer
T0PR=PRESCALAR-1; //load the timer value
T0TCR=0X02;
//reset timer
}
void delay(unsigned long int ms)
{
T0TC=0x00000000; // t0 reset timer counting
T0TCR=0X02; // reset the timer
T0TCR=0X01; // start timer
while(T0TC<=ms); // check the condition

T0TCR=0X00; // stop timer


}

SQUARE WAVE
#include<lpc21xx.h>
# define PRESCALAR 60000

// define prescalar as 60000

void pll();
void timer0_ini();
void delay(unsigned long int ms);
int main()
{
PINSEL0=0x00000000; // select gpio pin
IO0DIR=0XFFFFFFFF; // make gpio as output pin
pll();
// calling pll function
timer0_ini();
// calling timer function
while(1)
{
IO0SET=0X01; // high level
delay(0x0000000F); // delay using timer 0
IO0CLR=0X01; // low level
delay(0x0000000F); // delay using timer
0
}
return 0;
}
void pll()
{
//PLL IS CONFIGURED TO GET 60HZ pCLK
PLLCFG=0X24;
// SET PSEL=2 AND MSEL=5
PLLCON=0X01;
//PLL IS ACTIVE BUT NOT YET CONNECT
PLLFEED=0XAA;
//FEED SEQUENCE
PLLFEED=0X55;
//FEED SEQUENCE
while((PLLSTAT & 0X400)==0); //WAIT FOR FEED SEQUENCE TO BE
INSERTED
PLLCON=0X03;

// PLL HAS BEEN ACTIVE AND BEING

VPBDIV=0X00;
PLLFEED=0XAA;
PLLFEED=0X55;

// SET PCLK SAME AS FCCLK


//FEED SEQUENCE
//FEED SEQUENCE

CONNECTRD

}
void timer0_ini()
{
T0TCR=0X0; // to stop timer
T0PR=PRESCALAR-1; //load the timer value

T0TCR=0X02;

//reset timer

}
void delay(unsigned long int ms)
{
T0TC=0x00000000; // t0 reset timer counting
T0TCR=0X02; // reset the timer
T0TCR=0X01; // start timer
while(T0TC<=ms); // check the condition
T0TCR=0X00; // stop timer
}

Interfacing ADC with ARM7

#include<lpc213x.h>
#define
#define
#define
#define

LCD (0xff<<16)
RS (1<<13)
RW (1<<14)
EN (1<<15)

void delay_fv(unsigned int x,int y);


void lcd_display(unsigned int x);
void cmd(unsigned char m);
void lcd_ini();

void lcd_pos(int line, int pos);


void lcd_str(unsigned char *x);
void pll();
void adc_ini();
unsigned long int adc_data();
int main()
{
unsigned long temp;
unsigned char first,second,third,fourth,fifth;
PINSEL0=0X00000000;
IO0DIR=0XFFFFFFFF;
pll();
adc_ini();
lcd_ini();
lcd_str("TEMP VALUE IS");
lcd_pos(2,6);
lcd_display('C');
while(1)
{
temp=adc_data();
temp=temp*3300;
temp=temp/1023;
first=temp%10+'0';
temp=temp/10;
second=temp%10+'0';
temp=temp/10;
third=temp%10+'0';
temp=temp/10;
fourth=temp%10+'0';
temp=temp/10;
lcd_pos(2,0);
lcd_display(fourth);
lcd_display(third);
lcd_display(second);
lcd_display('.');
lcd_display(first);
}
}
void delay_fv(unsigned int x,int y)
{
unsigned int i,j;
for(i=0;i<x;i++)
for(j=0;j<y;j++);
}
void lcd_display(unsigned int x)
{
IO0CLR|=(RS|RW|EN|LCD);
IO0SET|=(x<<16);
IO0SET|=RS;

IO0CLR|=RW;
IO0SET|=EN;
delay_fv(100,200);
IO0CLR|=EN;
delay_fv(10,10);
}
void cmd(unsigned char m)
{
IO0CLR|=(RS|RW|EN|LCD);
IO0SET|=(m<<16);
IO0CLR|=RS;
IO0CLR|=RW;
IO0SET|=EN;
delay_fv(100,10);
IO0CLR|=EN;
delay_fv(100,10);
}
void lcd_ini()
{
cmd(0X38);
cmd(0X0e);
cmd(0X06);
cmd(0X01);
cmd(0X80);
}
void lcd_pos(int line, int pos)
{
if(line==1)
cmd(0x80+pos);
else if(line==2)
cmd(0xc0+pos);
}
void lcd_str(unsigned char *x)
{
while(*x!='\0')
{
lcd_display(*x);
x++;
}
}
void pll()
{
/*PLL IS CONFIGURED TO GET 60HZ pCLK*/
PLLCFG=0X24;
// SET PSEL=2 AND MSEL=5
PLLCON=0X01;
//PLL IS ACTIVE BUT NOT YET
CONNECT
PLLFEED=0XAA;
PLLFEED=0X55;

//FEED SEQUENCE
//FEED SEQUENCE

while((PLLSTAT & 0X400)==0); //WAIT FOR FEED SEQUENCE


TO BE INSERTED
PLLCON=0X03;
BEING CONNECTRD
VPBDIV=0X00;
PLLFEED=0XAA;
PLLFEED=0X55;
}

// PLL HAS BEEN ACTIVE AND


// SET PCLK 1/4th of FCCLK
//FEED SEQUENCE
//FEED SEQUENCE

void adc_ini()
{
AD0CR = 1<<21; //A/D is Operational
AD0CR = 0<<21; //A/D is in Power Down Mode
PINSEL1 = 0x01000000;//P0.28 is Configured as Analog to Digital
Converter Pin AD0.1
AD0CR = 0x00200802; //CLKDIV=4,Channel-0.1
Selected,BURST=0,EDGE=0
/*PDN=0
A/D Clock = PCLK /(CLKDIV+1);*/
}
unsigned long int adc_data()
{
unsigned long rec;
AD0CR |= (1<<24);
//Start Conversion
while(!(AD0GDR & 0x80000000));
/*Wait untill the DONE bits Sets*/
rec = AD0GDR;
AD0CR &= ~0x01000000;
//Stops the A/D
Conversion
rec = rec >> 6; // data is present after 6 bit
rec = rec & 0x3FF; //Clearing all other Bits
return (rec);
}

SPI with ARM7

www.firmcodes.com
DEVELOPED BY:- FIRMWARE DEVELOPER
WHAT PROGRAM DO:- Program Of Multiplex 8 Seven Segment Using
Max7221 And Controlled With ARM(LPC21XX) Using SPI Protocol
******************************************************/
#include<lpc21xx.h>
unsigned char spi_rec;
void spi_ini();
void spi_tr1(unsigned int x);
char spi_re();
void spi_tr(unsigned char cmd,unsigned char data);
void spi_str(unsigned char *str);
int ar[10]={ 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f };
int ar1[8]={0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08};
void pll();
void delay_ms(unsigned int x);

int main()
{
int i,a,b,c,d,e,f,g,h;
a=b=c=d=e=f=g=h=0;
PINSEL0=0X00000000;
IO0DIR=0XFFFFFFFF;
pll();
spi_ini();
spi_tr(0x0a,0xf);
spi_tr(0x0b,0xf);
for(i=0;i<9;i++)
{
spi_tr(ar1[i],ar[0]);
delay_ms(100);
}
spi_tr(0x0c,0x01);
while(1)
{
spi_tr(ar1[7],ar[a]);
spi_tr(ar1[6],ar[b]);
spi_tr(ar1[5],ar[c]);
spi_tr(ar1[4],ar[d]);
spi_tr(ar1[3],ar[e]);
spi_tr(ar1[2],ar[f]);
spi_tr(ar1[1],ar[g]);
spi_tr(ar1[0],ar[h]);
a++;
if(a==10)
{
a=0;
b++;
}
if(b==10)
{
a=b=0;
c++;
}
if(c==10)
{
a=b=c=0;
d++;
}
if(d==10)
{
a=b=c=d=0;
e++;
}
if(e==10)
{
a=b=c=d=e=0;
f++;
}

if(f==10)
{
a=b=c=d=e=f=0;
g++;
}
if(g==10)
{
a=b=c=d=e=f=g=0;
h++;
}
if(h==10)
{
a=b=c=d=e=f=g=h=0;
}
delay_ms(3000);
}
}
void pll()
{
/*PLL IS CONFIGURED TO GET 60HZ pCLK*/
PLLCFG=0X24;
// SET PSEL=2 AND MSEL=5
PLLCON=0X01;
//PLL IS ACTIVE BUT NOT YET
CONNECT
PLLFEED=0XAA;
//FEED SEQUENCE
PLLFEED=0X55;
//FEED SEQUENCE
while((PLLSTAT & 0X400)==0); //WAIT FOR FEED SEQUENCE
TO BE INSERTED
PLLCON=0X03;

// PLL HAS BEEN ACTIVE AND BEING

VPBDIV=0X00;
PLLFEED=0XAA;
PLLFEED=0X55;

// SET PCLK SAME AS FCCLK


//FEED SEQUENCE
//FEED SEQUENCE

CONNECTRD

}
void spi_ini()
{
PINSEL0 |=0x1500;
/* P0.4, P0.5, P0.6, P0.7 are set as SCK,
MISO, MOSI and GPIO */
//IODIR0 |= 0X80;
/* SSEL is output */
//IOSET0 |=0X80;
/* set SSEL to high */
S0SPCCR=8;
/* SPI clock
prescale register minimum value is 8. */
S0SPCR=0x0030;
/* Device select as
master, Set data to 8-bit, CPOL = 0, CPHA = 0*/
}
void spi_tr1(unsigned int x)
{
S0SPDR =x;
while ( !(S0SPSR & 0x80) );
trabsfer complete */
}

/* Wait until the SPIF bit is set to indicate

char spi_re()
{
while ( !(S0SPSR & 0x80) );
trabsfer complete */
spi_rec= S0SPDR;
return spi_rec;
}

/* Wait until the SPIF bit is set to indicate

void spi_str(unsigned char *str)


{
while(*str!='\0')
{
spi_tr1(*str);
str++;
}
}
void spi_tr(unsigned char cmd,unsigned char data)
{
IO0CLR=(1<<7); //enable transmission
spi_tr1(cmd);
spi_tr1(data);
IO0SET=(1<<7); // disable transmission
}
void delay_ms(unsigned int x)
{
int i;
while(x--)
{
for(i=0;i<100;i++);
}
}

RTC with ARM7:

#include<lpc21xx.h>
#define
#define
#define
#define

LCD (0xff<<16)
RS (1<<13)
RW (1<<14)
EN (1<<15)

void delay_fv(unsigned int x,int y);


void
void
void
void
void

lcd_display(unsigned int x);


cmd(unsigned char m);
lcd_pos(int line,int pos);
lcd_ini();
lcd_str(unsigned char *x);

unsigned char flag=0;


void init_rtc();
void main()
{
unsigned int i,j,k,l,m,n;
PINSEL0=0X00000000;
PINSEL1=0X00000000;
IO0DIR=0XFFFFFFFF;

lcd_ini();
init_rtc();
lcd_str("CLOCK:- 24");
cmd(0xc0);
lcd_str("00:00:00");
while(1)
{
if(flag)
{
flag=0;
lcd_pos(2,0);
lcd_display(HOUR/10 + '0');
lcd_display(HOUR%10 + '0');
lcd_display(':') ;
lcd_display(MIN/10 + '0');
lcd_display(MIN%10 + '0');
lcd_display(':') ;
lcd_display(SEC/10 + '0');
lcd_display(SEC%10 + '0');
}
}
}
void delay_fv(unsigned int x,int y)
{
unsigned int i,j;
for(i=0;i<x;i++)
for(j=0;j<y;j++);
}
void lcd_display(unsigned int x)
{
IO0CLR|=(RS|RW|EN|LCD);
IO0SET|=(x<<16);
IO0SET|=RS;
IO0CLR|=RW;
IO0SET|=EN;
delay_fv(100,10);
IO0CLR|=EN;
delay_fv(10,10);
}
void cmd(unsigned char m)
{
IO0CLR|=(RS|RW|EN|LCD);
IO0SET|=(m<<16);
IO0CLR|=RS;
IO0CLR|=RW;
IO0SET|=EN;
delay_fv(100,250);
IO0CLR|=EN;
delay_fv(10,10);
}

void lcd_pos(int line,int pos)


{
if(line==1)
cmd(0x80+pos);
else if(line==2)
cmd(0xc0+pos);
}
void lcd_ini()
{
cmd(0X38);
cmd(0X0e);
cmd(0X06);
cmd(0X01);
cmd(0X80);
}
void lcd_str(unsigned char *x)
{
while(*x!='\0')
{
lcd_display(*x);
x++;
}
}
void rtc_int(void)__irq
{
ILR = 0X01;
flag = 1;
VICVectAddr = 0X00000000;
}
void init_rtc()
{
ILR = 0X01;
CCR = 0X13;
CCR = 0X11;
CIIR = 0X01;
SEC = 0X00;
HOUR = 12;
MIN = 11;
VICIntEnable = 0x00002000;
VICVectCntl0 = 0x0000002D;
VICVectAddr0 = (unsigned)rtc_int;
}

Interrupts on ARM7:

#include <lpc21xx.h> // header file of arm controller


#include "delay.h" // delay header file
#include "lcd4bit.h" // header file of lcd
int ar[10]={ 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f };// common
cathode code
int count=0; // varible of type int
void interrupt_ini(); // interrupt intilization
int main()
{

// start of main program


PINSEL0=0X00000000;
PINSEL1=0X00000000;

// port0.0 to port0.15 used as gpio mode


// port0.16 to port0.31 used as gpio

PINSEL2=0X00000000;

// port1.16 to port1.32 used as gpio

mode
mode
IO0DIR=0X0fFFFFFF;
// direction of port0.0 to port0.31 worked
as output mode
IO1DIR=0XFFFFFFFF;
// direction of port1.0 to port1.31 worked
as output mode
lcd_ini();
// lcd initilization function
interrupt_ini();
// interrupt intilization function

while(1)
{
IO1SET|=(ar[count]<<16);
delay_fv(1000,1000);
IO1CLR|=(ar[count]<<16);
count++;
if(count==10)
count=0;
}
return 0;
}
void interrupt_0()__irq // interrupt 0
{
EXTINT=0X01;
IO0SET|=(0XFF<<16);
delay_fv(500,1000);
IO0CLR|=(0XFF<<16);
delay_fv(500,1000);
}
void interrupt_1()__irq // interrupt 1
{
EXTINT=0X02;
cmd(0x01);
lcd_str("WELCOME TO");
cmd(0xc0);
lcd_str("FIRMCODES.COM");
delay_fv(1000,1000);
}
void interrupt_ini()
{
/* intialize interrupt 0*/
PINSEL0|=0x0c;
VICVectAddr0=(unsigned)interrupt_0;
VICVectCntl0=0x20|14;
VICIntEnable=1<<14;
// delay_fv(1000,100);
/* intialize interrupt 1*/
PINSEL0|=0xc0;
VICVectAddr1=(unsigned)interrupt_1;
VICVectCntl1=0x20|15;
VICIntEnable=1<<15;
}
DELAY.H HEADER FILE
***********************************************************************/
void delay_ff()
{

unsigned int b,v;


for(b=0;b<600;b++)
for(v=0;v<100;v++);
}
void delay_pf(unsigned int x)
{
unsigned int i,j;
for(i=0;i<x;i++)
for(j=0;j<153;j++);
}
void delay_fv(unsigned int x,int y)
{
unsigned int i,j;
for(i=0;i<x;i++)
for(j=0;j<y;j++);
}
void delay_ms(int count)
{
int j=0,i=0;
for(j=0;j<count;j++)
{
/* At 60Mhz, the below loop introduces
delay of 10 us */
for(i=0;i<35;i++);
}
}
LCD4BIT.H HEADER FILE
*********************************************************************/
#define LCD (0xf<<11)
#define RS (1<<8)
#define RW (1<<9)
#define EN (1<<10)
void lcd_display(unsigned char x)
{
unsigned int temp;
delay_ms(1000);
IO0CLR|=(RS|RW|EN|LCD);
temp=(x>>4)&0x0f;
//delay_ms(10);
IO0SET|=RS;
IO0CLR|=RW;
IO0SET|=EN;
IO0CLR|=LCD;
IO0SET|=(temp<<11);
delay_ms(100);
IO0CLR|=EN;

delay_fv(10,10);
IO0CLR|=(RS|RW|EN|LCD);
temp=x&0x0f;
//delay_ms(1000);
IO0SET|=RS;
IO0CLR|=RW;
IO0SET|=EN;
IO0CLR|=LCD;
IO0SET|=(temp<<11);
delay_ms(100);
IO0CLR|=EN;
delay_ms(100);
}
void cmd(unsigned char x)
{
unsigned int temp;
delay_ms(100);
temp=(x>>4)&0x0f;
IO0CLR|=(RS|RW|EN);
IO0CLR|=RS;
IO0CLR|=RW;
IO0SET|=EN;
IO0CLR|=LCD;
IO0SET|=(temp<<11);
delay_ms(100);
IO0CLR|=EN;
delay_fv(100,10);
IO0CLR|=(RS|RW|EN);
temp=x&0x0f;
IO0SET|=(temp<<11);
IO0CLR|=RS;
IO0CLR|=RW;
IO0SET|=EN;
IO0CLR|=LCD;
IO0SET|=(temp<<11);
delay_ms(100);
IO0CLR|=EN;
delay_fv(100,100);
}
void lcd_ini()
{
PINSEL0|=(0XFF<<8);
IO0DIR|=(0XF<<8);
cmd(0X02);
cmd(0X28);
// cmd(0X02);
cmd(0x0e);
cmd(0X06);
cmd(0X01);
cmd(0X80);
}

void lcd_str(unsigned char *str)


{
while(*str!='\0')
{
lcd_display(*str);
str++;
}
}

Potrebbero piacerti anche