Seca3019 Unit 4
Seca3019 Unit 4
[Interfacing the peripherals to LPC2148: GSM and GPS using UART, on-chip ADC using
interrupt (VIC), EEPROM using I2C, SD card interface using SPI, on-chip DAC for waveform
generation]
89
4.1 GSM MODULE INTERFACING WITH LPC2148
GSM (Global System for Mobile Communications) is the technology that underpins
most of the world's mobile phone networks.
GSM is an open, digital cellular technology used for transmitting mobile voice and data
services.
GSM operates in the 900MHz and 1.8GHz bands GSM supports data transfer speeds
of up to 9.6 kbps, allowing the transmission of basic data services such as SMS.
The SIM300 module is a Triband GSM/GPRS solution in a compact plug in module
featuring an industry-standard interface
90
SIM7600EI is a complete multi-band LTE/EDGE/GPRS/GSM module solution in LCC
type which supports LTE CAT1 up to 10Mbps for downlink and 5Mbps for uplink data
transfer.
A GSM mobile is a complete system in itself with embedded processors that are
dedicated to provide an interface between the user and the mobile network.
The AT commands are served between the processors of the mobile termination and
the terminal equipment.
The mobile handset can also be equipped with a USB interface to connect with a
computer, but it may or may not support AT commands from the computer or an
external processor/controller.
The GSM/GPRS module, on the other hand, always needs a computer or external
processor/controller to receive AT commands from.
GSM/GPRS module itself does not provide any interface between the user and the
network, but the computer to which module is connected is the interface between user
and network.
An advantage that GSM/GPRS modules offer is that they support concatenated SMS
which may not be supported in some GSM mobile handsets
91
Applications of GSM/GPRS module The GSM/GPRS module demonstrates the use of
AT commands. They can feature all the functionalities of a mobile phone through
computer like making and receiving calls, SMS, MMS etc. These are mainly employed
for computer based SMS and MMS services.
4.1.3 AT Commands
These commands come from Hayes commands that were used by the Hayes smart
modems.
The Hayes commands started with AT to indicate the attention from the MODEM.
The dial up and wireless MODEMs need AT commands to interact with a computer.
AT commands with a GSM/GPRS MODEM
ATD Dial
92
Figure 4.3: UART data format
Figure 4.4 shows interfacing of LPC2148 with GSM modem using UART protocol. MAX232
IC is used for voltage level shifting from 0V/5V to -12V/+12V.
TXD-0 P0.0
UART0 (P1) ISP PGM
RXD-0 P0.1
TXD-1 P0.8
UART1 (P2)
RXD-1 P0.9
93
Algorithm for GSM module interfacing with LPC2148
1) Start
while(!(U0LSR&0X20));//Monitor TI flag
6) To transmit a single character use PUTCH function & to transmit a string use PUTS
function
7) END
/**************************************************************************/
/* Project Name:- GSM Module Interfacing with LPC2148 using UART module */
/* Device:- LPC2148 */
/* Compiler:- KeilUvision4 */
/* Language:- Embedded C */
/**************************************************************************
****************/
#include<lpc21xx.h> //Includes LPC2148 register definitions
#include "serial.h"
unsigned char GsmSendMsg(unsigned char *msgStr);
void DelayMs(unsigned int count);
int main(void)
{
Uart0Init();
Uart0PutS("AT\r\n");
94
DelayMs(500);
Uart0PutS("ATE0\r\n"); //Turn echo off
DelayMs(500);
Uart0PutS("ATD9503XXXXXX;\r\n"); //replace xxxxxxxxxx with number to call
DelayMs(20000);
Uart0PutS("ATH0\r\n"); //disconnect call
DelayMs(3000);
GsmSendMsg("WIKINOTE FOUNDATION");
while(1);
}
The SKG13BL is a complete GPS engine module that features super sensitivity, ultra
low power and small form factor. The GPS signal is applied to the antenna input of module,
and a complete serial data message with position, velocity and time information is presented at
the serial interface with NMEA protocol or custom protocol.
95
small form factor and low power consumption make the module easy to integrate into portable
device like PNDs, mobile phones, cameras and vehicle navigation systems.
QZSS,SBAS(WAAS,EGNOS,MSAS,GAGAN)
Applications
96
4.2.2 Interfacing of GPS Module
TXD-0 P0.0
UART0 (P1) ISP PGM
RXD-0 P0.1
TXD-1 P0.8
UART1 (P2)
RXD-1 P0.9
1) Start
3) Receive GPS Message of location and longitude through UART module using
function UARTGetch()
97
4) Store single character in Variable GPSData
GPSDATA=Uart0Getch();
7) END
#include <lpc214x.h>
#include "serial.h"
#include "lcd.h"
unsigned int j;
unsigned char Gpsdata; // for incoming serial data
unsigned int finish =0; // indicate end of message
unsigned int pos_cnt=0; // position counter
unsigned int lat_cnt=0; // latitude data counter
unsigned int log_cnt=0; // longitude data counter
unsigned int flg =0; // GPS flag
unsigned int com_cnt=0; // comma counter
unsigned char lat[20]; // latitude array
unsigned char lg[20]; // longitude array
unsigned int i=0;
unsigned int fg=0;;
void gps(void);
int main(void)
{
lcd_init();
Uart0Init();
while(1)
{
gps();
lcdcmd(0x80);
DisplayLCD1("LT:");
DisplayLCD1(lat);
DisplayLCD1("N");
lcdcmd(0xC0);
DisplayLCD1("LG:");
DisplayLCD1(lg);
DisplayLCD1("E");
}
}
98
void gps()
{
while(finish==0){
Gpsdata = Uart0GetCh();
flg = 1;
if( Gpsdata=='$' && pos_cnt == 0) // finding GPRMC header
pos_cnt=1;
if( Gpsdata=='G' && pos_cnt == 1)
pos_cnt=2;
if( Gpsdata=='P' && pos_cnt == 2)
pos_cnt=3;
if( Gpsdata=='R' && pos_cnt == 3)
pos_cnt=4;
if( Gpsdata=='M' && pos_cnt == 4)
pos_cnt=5;
if( Gpsdata=='C' && pos_cnt==5 )
pos_cnt=6;
if(pos_cnt==6 && Gpsdata ==','){ // count commas in message
com_cnt++;
flg=0;
}
99
}
}
finish = 0;
pos_cnt = 0;
}
///////$GPRMC,194530.000,A,3051.8007,N,10035.9989,W,1.49,111.67,310714,,,A*74
Note:- As we need to send AT Commands using UART , we need to add Program for
Serial Communication. Hence Add Serial.c and Serial.h file
Note:- As we want to display Lattitude and Longitude values on LCD we have to add
LCD.c and LCD.h files in our keil Project
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
-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. There is one more term important to
understand while dealing with ADC and it is 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.
So in this case we can measure minimum 2.23 mV (Approx.) with our microcontroller. This
is how step size defines an accuracy of ADC circuit.
100
Conversion time: 2.44 micro-seconds
Max. clock frequency is 4.5 MHz, (by programming ADC Control (ADxCON
Register)
101
AD1.1 Channel 1 P0.8
Useful for Selection of analog input channel, clock frequency to ADC, Resolution,
conversion mode, method of issue of SoC, edge for conversion
23- 19-
31-28 27 26-24 21 20 16 15-8 7-0
22 17
15-8 CLKDIV: Clock Division factor Value:- The APB clock (PCLK) is
divided by (this value plus one) to produce the clock for the A/D
102
converter, which should be less than or equal to 4.5 MHz
Typically, software should program the smallest value in this
field that yields a clock of 4.5 MHz or slightly less, but in certain
cases (such as a high-impedance analog source) a slower clock
may be desirable.
completed.
Clocks:- This field selects the number of clocks used for each
conversion in Burst mode, and the number of bits of accuracy of
the result in the RESULT bits of ADDR, between 11 clocks (10
bits) and 4 clocks (3 bits).
103
100 7 clocks/ 6 bits
Power Down
21 PDN
PDN=1 The A/D converter is operational.
PDN=0 The A/D converter is in power-down mode.
26-24
START
000 No start of Conversion
(In use only when START field contains Values from 010 TO
27 Edge
111)
15-8 CLKDIV: The APB clock (PCLK) is divided by (this value plus one) to produce
the clock for the A/D converter, which should be less than or equal to 4.5 MHz
Typically, software should program the smallest value in this field that yields a clock
of 4.5 MHz or slightly less, but in certain cases (such as a high-impedance analog
source) a slower clock may be desirable.
o The A/D Converters on the LPC2148 is also called as The conversion speed is
selectable by the user.
o A/D Clock frequency= [Pclk/(CLKDIV+1)] .....................<=4.5 MHz
104
2. A/D Global Start Register (ADxGSR)
Contains most recent converted data and EoC (Done) status on respected channel
29-28-
31 30 26-25-24 23-16 15-6 5-0
27
105
For accurate results, you need to wait until this value is 1 before reading the RESULT bits.
(Please note that this value is cleared when you read this register.)
While not relevant to the examples used in this tutorial, this value with be 1 if the results
of one or more conversions were lost when converting in BURST mode. See the User's Manual
for further details. (As with DONE, this bit will be cleared when you read this register.)
If DONE is 1 (meaning the conversion is complete), these 10 bits will contain a binary
number representing the results of our analog to digital conversion. It works by measuring the
voltage on the analog input pin divided by the voltage on the Vref pin.
Zero means that the voltage on the analog input pin was less than, equal to or close to
GND (Vssa), and 0x3FF (or 0011 1111 1111) indicates that the voltage on the analog input pin
was close to, equal to or greater than the the voltage on the Vref pin. Anything value between
these two extremes will be returned as a 10-bit number (between 0 and 1023).
Select ADC-0, Channel-1, Clock frequency 3.75 MHz (let PCLK is 15 MHz), burst mode
repeated conversion) and 10-bit resolution. Power-up ADC and issue start of conversion.
106
Solution: AD0CR = 0x01210302; // configure SEL, CLKDIV, BURST CLKS & PDN bit
fields set START, signal start of conversion
1. Select ADC 1, Channels 0 to 7, clock frequency 4.5 MHz (assume PCLK is 30 MHz),
burst mode repeated conversion, 8-bit resolution.
#include <lpc214x.h>
#include "serial.h"
#include <stdio.h>
void delay(void);
void ADC_ISR(void) __attribute__ ((interrupt("IRQ")));
int adcdata;
float voltage;
unsigned char volt[3];
int i;
int main(void)
{
PINSEL0 = 0x00000005;
PINSEL1 = 0x01000000;
PINSEL2 = 0x00000000;
Uart0Init();
Uart0PutS("\n ADC o/p : ");
107
AD0INTEN = 0x00000002; ///On completion of AD conversion channel1 will generate
an Interrupt
VICVectAddr0 = (unsigned int)ADC_ISR;
VICVectCntl0 = 0x20 | 18; //// VIRQ and Assign AD0 interrupt Slot0
VICIntEnable = 1 << 18; ///Enable AD0 interrupt channel of VIC
AD0CR = 0X01200402; // Channel AD0.1 , Clock 3Mhz, Burst Mode, 11 clocks per 10 bit ,
//AD conversion is operational, start conversion
while(1){
return 0;
}
void ADC_ISR()
{
if(AD0DR1 & 0x80000000) ///Monitor EOC bit from AD Data Register of Channel0
{
adcdata=(AD0DR1 & 0x0000FFC0);
adcdata=adcdata>>6; ///Right shift Digital Result by 6 bits
voltage=((adcdata/1023.0)*3.3);
sprintf(volt, "%.1f", voltage); ////Buffer, decimal value. 1 digit fractional value, float
volatage value
Uart0PutS(volt); ///print buffer on Hyperterminal
}
delay();
AD0INTEN = 0; ////Disable ADO Interrupr
VICVectAddr=0; ///End of ISR
}
void delay(void)
{
int i,j;
for(i=0;i<1000;i++)
for(j=0;j<10000;j++);
}
#include<lpc214x.h>
#include<stdio.h>
#include "serial.h"
void delay(void);
108
int main()
{
int adcdata;
float voltage;
unsigned char volt[3];
PINSEL0=0X00000000;
PINSEL1=0X01000000; //Select P0.28 pin function as Analog i/p
Uart0Init();
AD0CR=0x00210402; ///CHANNEL1 OF ADC0, ad freq=3MHz,
while(1)
{
if(AD0DR1 & 0x80000000) ////EOC bit monitoring
{
adcdata=(AD0DR1 & 0x0000FFC0);
adcdata=adcdata>>6;
voltage=((adcdata/1023.0)*3.3);
sprintf(volt, "%.1f", voltage); ADC o/p=1.2
Uart0PutS("\n ADC o/p : ");
Uart0PutS(volt);
delay();
}
}
}
void delay(void)
{
int i,j;
for(i=0;i<1000;i++)
for(j=0;j<10000;j++);
}
109
supported in hardware (LPC2144/6/8 only).
110
U0FCR (FIFO Control Register)
FIFO TX RX
FIFO
U0FCR Control - - - - - FIFO FIFO
Enable
Register Reset Reset
UART0 Line Control Register (U0LCR - address 0xE000 C00C) bit description
Reset
Bit Symbol Value Description
Value
Word Length
1:0 01 6 bit character length 0
Select
0 1 stop bit
2 Stop Bit Select 0
111
0 Disable parity generation and checking
3 Parity Enable 0
6 Break Control 0
Enable break transmission. Output pin
1 UARTO TXD Is forced to logic 0 when
UOLCR[6] Is active high.
One high-low pulse across DLAB bit indicates baud rate is successfully loaded.
112
U0LSR (Line Status Register)
Reset
Bit Symbol Value Description
value
113
parity error detection is dependent on
U0FCR(0).
114
1 Break interrupt status is active.
1 U0THR is empty.
115
DLR (Divisor Latch Register)
116
4.4.2 Algorithm for UART serial communication
1) Start
2) Initialise UART0 serial interface using following instruction
117
void Uart0PutS(unsigned char *str) //A function to send a string on UART0
{
while(*str)
{
Uart0PutCh(*str++);
}
}
unsigned char Uart0GetCh (void) // Read character from Serial Port
{
while (!(U0LSR & 0x01));
return (U0RBR);
}
int main()
{
unsigned char a;
Uart0Init();
while(1)
{
a=Uart0GetCh();
Uart0PutCh(a);
}
}
118
I2C communication protocol involves communication between a slave and a master.
The device which initiates the communication and which provides the clock is referred to as a
master device. The devices which receive the clock signal and receive/transmit data according
to the clock signal is termed as a slave device. Each device on the bus is accessed using its
slave address.
START condition
STEP-1) First the MCU will issue a START condition. The devices connected to the
bus will listen to the START condition and will stay ready to begin the communication
process.
STEP-2) Then MCU will send the address of the device with which it needs to
communicate. Master indicates the action to be performed with the device whether to
read or write along with the address.
STEP-3) All devices connected to the bus will receive the address and will compare it
with its own address. If the addresses match with each other, the device will send back
an ACKNOWLEDGEMENT signal to the master device. If they
match they will simply wait for the bus to be released with a STOP condition.
STEP-4) Once the MCU sends the address and corresponding device acknowledges,
the MCU can start transmitting or receiving data.
STEP-5) When the data transmission or reception is complete, the MCU will stop
communicating by sending a STOP condition.
STOP condition
STEP-6) STOP condition indicates that the bus is released and it can be used by any
other master (if any) connected to the I2C bus.
After a master generate a start condition I2C bus will solely belong to it. The bus will
be freed only if the master generate a STOP condition. Any other master connected to
the bus can access the bus after a STOP is identified on the bus.
If the master device which uses the bus needs to communicate with a different slave it
should generate a RESTART. Instead if it tries to stop current communication and then
start again it may lose access to the bus. RESTART is nothing but a start signal without
a stop in the bus.
119
4.5.1 Features of I2C module in LPC2148
Applications
120
Table 4.13 I2C Registers
121
whether a slave responds to
the general call address.
0-1 -- Reserved
122
Assert Acknowledge
2 AA
AA=1; request an acknowledge
STOP
4 STO
STO=1; sends stop condition
START
5 STA
STA=1; sends START condition
7 - Reserved
The AT24C512 provides 524,288 bits of serial electrically erasable and programmable
read only memory (EEPROM) organized as 65,536 words of 8 bits each.
cascadable feature allows up to four devices to share a common two-wire
bus.
The device is optimized for use in many industrial and commercial applications where
low power and low-voltage operation are essential.
The devices are available in space saving8-pin PDIP, 8-lead EIAJ SOIC, 8-lead JEDEC
SOIC, 8-lead TSSOP, 8-lead Leadless Array (LAP), and 8-lead SAP packages. In
addition, the entire family is available in 2.7V (2.7V to 5.5V) and 1.8V (1.8V to 3.6V)
versions.
123
Figure 4.11 Pin details of EEPROM IC
1) Start
124
I2CCONSET=0X40;////I2CEN=1
I2CCONSET=0X20;//STA=1
12) After successful transmission of data , master wil transmit STOP condition
I2CCONSET=0X10;//STO=1
I2CCONCLR=0X40; //I2CENC=1
14) END
Example Program
#include <LPC214x.h>
#include <stdio.h>
#include "serial.h"
125
PINSEL0 |= 0x00000050; //P0.2 -> SCL0 P0.3 -> SDA0 I2C0CONCLR =
I2C_ENABLE | I2C_START | I2C_STOP | I2C_SI | I2C_AACK; //clear all the bits in
CONTROL register
//set I2C clock to work at 100Khz
I2C0SCLH = 0x4B ; //set the high time of i2c clock; (15mhz / 100khz / 2)
I2C0SCLL = 0x4B ; //set the low time of i2c clock;
126
}
int main()
{
unsigned int i,j;
Uart0Init(); //initialize UART with 9600 baudrate
Uart0PutS("\r\nI2C EEPROM\r\n");
I2CInit(); //initialize I2C
/* Write Sequence */
Uart0PutS("\r\n Writing Data.....\r\n");
I2CStart(); //Assert START
I2Csend(EEPROM_Addr | I2Cwrite); //Device address with LSB bit 0
I2Csend(0x13); //Address higher byte
I2Csend(0x49); //Address lower byte
for(i=0;i<10;i++)
I2Csend(write_array[i]); //write the array to EEPROM
I2CStop();
//Assert STOP
for(i=0;i<10;i++)
{
sprintf(val,"%d",write_array[i]); //display read data
Uart0PutS(val);
Uart0PutS("\r\n");
}
/* Read Sequence */
Uart0PutS("\r\n Reading.....\r\n");
I2CStart(); //Assert START
I2Csend(EEPROM_Addr | I2Cwrite); //Device address with LSB bit 0 (Dummy Write)
I2Csend(0x13); //Address higher byte
I2Csend(0x49); //Address lower byte
I2CStart(); //Assert Restart
I2Csend(EEPROM_Addr | I2Cread); //Device address with LSB bit 1
for(i=0;i<10;i++)
read_array[i] = I2Cget(); //Read EEPROM
I2CStop(); //Assert STOP
127
for(i=0;i<10;i++)
{
sprintf(val,"%d",read_array[i]); //display read data
Uart0PutS(val);
Uart0PutS("\r\n");
}
while(1); //stop here forever
return 0;
}
128
Table 4.16 SPI Registers
Read
S0SPSR SPI Status Register. This register shows the status of the SPI.
Only
The S0SPCR register controls the operation of the SPI0 as per the configuration bits setting.
Bit
Sym Reser BI SPI LS MS CP CP
Enab
bol ved TS E BF TR OL HA - -
le
0-1 Reserved -
129
0; The data is sampled on first clock edge
1; The data is sampled on second clock edge
Clock Polarity
4 CPOL 0; Serial Clock (SCK) is active High
1; Serial Clock (SCK) is active High
15-
RESERVED Reserved
12
130
SPI STATUS REGISTER(S0SPSR)
The S0SPSR register controls the operation of the SPI0 as per the configuration bits setting.
Bits 7 6 5 4 3 2 1 0
0-2 Reserved -
Slave abort.
3 ABRT When 1, this bit indicates that a slave abort has occurred. This bit
is cleared by reading this register.
Mode fault.
when 1, this bit indicates that a Mode fault error has occurred.
4 MODF
This bit is cleared by reading this register, then writing the SPI
control register.
Read overrun.
5 ROVR When 1, this bit indicates that a read overrun has occurred. This
bit is cleared by reading this register.
Write collision.
When 1, this bit indicates that a write collision has occurred. This
6 WCOL
bit is cleared by reading this register, then accessing the SPI data
register.
131
transfer. When a slave, this bit is set on the last data sampling
edge of the SCK. This bit is cleared by first reading this register,
then accessing the SPI data register.
This bi-directional data register provides the transmit and receive data for the SPI.Transmit
data is provided to the SPI by writing to this register. Data received by the SPI can be read
from this register. When a master, a write to this register will start a SPI data transfer. Writes
to this register will be blocked from when a data transfer starts to when the SPIF status bit is
set, and the status register has not been read.
Data
7-0
Low
If bit 2 of the SPCR is 1 and bits 11:8 are other than 1000, some or
15- Data all of these bits contain the additional transmit and receive bits.
8 HIGH When less than 16 bits are selected, the more significant among
these bits read as zeroes.
132
4.6.2 SD Cards
digital camera. Their small size, relative simplicity, low power consumption and low cost make
them an ideal solution for many applications.
133
Table 4.20 SD card pin details
SD Memory interfaces to the host point-to-point (in Fig. an ARM microcontroller is the host).
This type of interfacing is very popular in the industry. In serial peripheral interface (SPI)
mode, you can use following signals of the host:
134
1. CS: Host to card chip-select signal
3. MOSI (master -out slave-in): Host to card single bit data signal
Now many companies are manufacturing suitable hosts for the SD bus interface.
For example, Philips is manufacturing LPC2148 microcontroller with MOSI and MISO
All communications between the host and the card are controlled by the host.
Messages in the spi bus protocol consist of commands, responses and tokens.
The card returns a response to every command received and also a data response token
for every write command
The sd card wakes up in sd card mode, and it will enter the spi mode if its cs (chip
select or slave select) line is held low. When a reset command is sent to the card
The card can only be returned to the sd mode after a power down and power up
sequence then the spi mode is entered.
The card is in the non protected mode where CRC checking is not used CRC checking
can be turned on and off by sending command CRC_on_off command name cmd59 to
the card.
135
Figure 4.15 Algorithm for R/W operation with SD card
/********************************/
Function for initializing SPI
/********************************/
void spi_init()
{
PINSEL0=0X00001505;// Select MOSI=P0.6, MISO=P0.5, SCK=P0.4,SSEL=P0.7
S0SPCCR=0X08; // clock is divided by 8 ( SPI Clock freq = PCLK / S0SPCCR Value)
S0SPCR=0X0020; // select as master mode
}
/********************************/
Function for sending a char
/********************************/
void spi_master(char a)
{
S0SPDR=a;
while(!(S0SPSR & 0X80)); // wait till SPIF=1 i.e., complete transfer of data
}
/********************************/
Function for receiving a char
/********************************/
136
char spi_slave(void)
{
while(!(S0SPSR & 0X80)); // wait till SPIF=1 i.e., complete reception of data
Reset
Bit Symbol Value Description
value
137
Reserved, user software should not write ones
5:0 - to reserved NA bits. The value read from a NA
reserved bit is not defined.
Configure DAC register for generating with 3.3V VREF & Select 350 micro AMPERE settling
time.
1. 0V,
2. 1.65V,
3. 3.3V
Solution:
138
Figure 4.16 Configuring internal DAC of LPC2148
#include <lpc214x.h>
#include <stdint.h>
void delay_ms(uint16_t j)
{
uint16_t x,i;
for(i=0;i<j;i++)
{
for(x=0; x<6000; x++); /* loop to generate 1 milisecond delay with Cclk = 60MHz */
}
}
139
uint8_t i;
i = 0;
PINSEL1 = 0x00080000; /* P0.25 as DAC output */
uint16_t sin_wave[42] = {
512,591,665,742,808,873,926,968,998,1017,1023,1017,998,968,926,873,808,742,665,591,51
2,
436,359,282,216,211,151,97,55,25,6,0,6,25,55,97,151,211,216,282,359,436 };
while(1)
{
while(i !=42)
{
value = sin_wave[i];
DACR = ( (1<<16) | (value<<6) );///Bias bit=1, Digital Value left shifted by 6 bits
delay_ms(1);
i++;
}
i = 0;
}
}
#include <lpc214x.h>
#include <stdint.h>
void delay_ms(uint16_t j)
{
uint16_t x,i;
for(i=0;i<j;i++)
{
for(x=0; x<6000; x++); /* loop to generate 1 milisecond delay with Cclk = 60MHz */
}
}
140
DACR = ( (1<<16) | (value<<6) );
value++;
}
while ( value != 0 )
{
DACR = ( (1<<16) | (value<<6) );
value--;
}
}
#include <lpc214x.h>
#include <stdint.h>
void delay_ms(uint16_t j)
{
uint16_t x,i;
for(i=0;i<j;i++)
{
for(x=0; x<6000; x++); /* loop to generate 1 milisecond delay with Cclk = 60MHz */
}
}
141
TEXT / REFERENCE BOOKS
1. Tularam M Bansod " Microcontroller Programming (8051, PIC, ARM7 ARM Cortex)",
1st Edition, Shroff Publishers,2017
2. A Getting Started Guide for MDK Version 5- Reference Manual, Keil, 2015
3. Steve Furber, "ARM System-on-
Exercise Questions
142