ES Record
ES Record
Pulse width modulation (PWM) is a powerful technique for controlling analog circuits with a
processor's digital outputs. PWM is employed in a wide variety of applications, ranging from
measurement and communications to power control and conversion.
Interfacing PWM
Figure 1 shows four different PWM signals. One is PWM output at a 25% duty cycle. That is, the
signal is on for 25% of the period and off the other 75%. Next shows PWM output at 50%, 75%
and 100% duty cycles, respectively. These three PWM outputs encode three different analog
signal values, at 10%, 50%, and 90% of the full strength.
Pin Assignment with LPC2148
The Interfacing LM35 with LPC2148 program is very simple and straight forward, that reading
temperature from temperature sensor LM35 and it display into PC through serial port. The C
programs are written in Keil software. Some delay is occurring when a single data is sent to PC.
LED (Light Emitting Diodes)
Light Emitting Diodes (LED) is the most commonly used components, usually for displaying
pins digital states. Typical uses of LEDs include alarm devices, timers and confirmation of user
input such as a mouse click or keystroke.
Interfacing LED
Fig. 1 shows how to interface the LED to microcontroller. As you can see the Anode is connected
through a resistor to GND & the Cathode is connected to the Microcontroller pin. So when the
Port Pin is HIGH the LED is OFF & when the Port Pin is LOW the LED is turned ON.
The ARM7 LPC2148 Primer board has eight numbers of point LEDs, connected with I/O Port
lines (P1.16 – P1.23) to make port pins high.
LPC2148
Point LEDs Lines LED Selection
LD1 P1.16
LD2 P1.17
LD3 P1.18
LD4 P1.19
LD5 P1.20
LD6 P1.21
DIGITAL
LD7 P1.22
OUTPUTSLD8 P1.23
void delay(int x)
{
unsigned int k,l;
for(k = x;k > 0;k--)
for(l = 0;l < x;l++);
}
Keypad
A keypad is a set of buttons arranged in a block or "pad" which usually bear digits, symbols and
usually a complete set of alphabetical letters. If it mostly contains numbers then it can also be
called a numeric keypad. Here we are using 4 X 4 matrix keypad.
Interfacing keypad
Fig. 1 shows how to interface the 4 X 4 matrix keypad to two ports in microcontroller. The rows
are connected to an output port and the columns are connected to an input port.
To detect a pressed key, the microcontroller grounds all rows by providing 0 to the output latch,
and then it reads the columns. If the data read from the columns is D3-D0=1111, no key has been
pressed and the process continues until a key press is detected. However, if one of the column
bits has a zero, this means that a key press has occurred. For example, if D3-D0=1101, this
means that a key in the D1 column has been pressed.
After a key press is detected, the microcontroller will go through the process of identifying the
key. Starting with the top row, the microcontroller grounds it by providing a low to row D0 only;
then it reads the columns.
If the data read is all 1s, no key in that row is activated and the process is moved to the next row.
It grounds the next row, reads the columns, and checks for any zero. This process continues until
the row is identified. After identification of the row in which the key has been pressed, the next
task is to find out which column the pressed key belongs to.
Fig. 1 Interfacing keypad to Microcontroller
Interfacing keypad with LPC2148
Scan a keypad in LPC2148 Primer Board. In case of 4X4 matrix Keypad both the ends of
switches are connected to the port pin i.e. four rows and four columns. So in all sixteen switches
have been interfaced using just eight lines.
1Keypads arranged by matrix format, each row and column section pulled by high or low by
selection J5, all row lines(P1.24 – P1.27) and column lines(P1.28 to P1.31) connected directly by
the port pins.
4x4 MatrixLPC2148
Lines Lines 4x4 Matrix Keypad
ROW-0 P1.24
ROW-1 P1.25
ROW-2 P1.26
ROW ROW-4 P1.27
COLUMN-0 P1.28
COLUMN-1 P1.29
COLUMN-2 P1.30
COLUMN COLUMN-3 P1.31
Circuit Diagram to Interface keypad with LPC2148
The Interfacing keypad with LPC2148 program is very simple and straight forward, that scan a
keypad rows and columns. When the rows and columns are detected then it will display in PC
through UART0. The C programs are developed in Keil software.
#include <LPC214x.h>
#include <stdio.h>
#include "Keypad.h"
#include "UART_Utility.c"
void main(void)
{
VPBDIV = 0x02;
UART0_Init (9600);
PINSEL2 |= 0x0;
UART0_PutS ("\nPS-Primer ARM LPC2148 Keypad Demo\n\r");
UART0_PutC (0xB8);
UART0_PutS (" Pantech Solutions Pvt Ltd., \n\r");
UART0_PutS (" www.pantechsolutions.net\n\r");
UART0_PutS ("----------------------------------------- \n\n\r");
UART0_PutS ("Keypad Ports : P1.24 - P1.31 \n\n\n\r");
UART0_PutS
("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n\r");
while (1)
{
Delay();
Delay();
KeyScan(&IOPIN1,24,&Row_Data,&Col_Data);
UART0_PutS ("The Key You Pressed is : ");
if (Row_Data < 4 && Col_Data < 4)
{
U0THR = Msg[Row_Data][Col_Data];
Delay();
Delay();
U0THR = '\r';
}
}
}
void Delay(void)
{
unsigned int i,j;
for(i=0;i<35;i++)
for(j=0;j<1234;j++);
}
Liquid Crystal Display also called as LCD is very helpful in providing user interface as well as
for debugging purpose. A liquid crystal display (LCD) is a flat panel display that uses the light
modulating properties of liquid crystals (LCs). LCD Modules can present textual information to
user.
Interfacing LCD
Fig. 1 shows how to interface the LCD to microcontroller. The 2x16 character LCD interface
card with supports both modes 4-bit and 8-bit interface, and also facility to adjust contrast
through trim pot. In 4-bit interface 7 lines needed to create 4-bit interface; 4 data bits (D0 – D3),
three control lines, address bit (RS), read/write bit (R/W) and control signal (E).
Fig. 1 Interfacing 4 bit LCD to Microcontroller
Interfacing 4 bit LCD with LPC2148
We now want to display a text in LPC2148 Primer Board by using 4 bit LCD module.
The ARM7 LPC2148 Primer board has seven numbers of LCD connections are needed to create
4-bit interface; connected with 4 data bits (P0.19 – P0.22, D4-D7), address bit (RS-P0.16),
read/write bit (R/W-P0.17) and control signal (E-P0.18) to make LCD display.
LCD LPC2148
MODULE LINES 2x16 LCD Selection
RS P0.16
RW P0.17
CONTROLE P0.18
D0-D3 NC
D4 P0.19
D5 P0.20
DATA
D6 P0.21
LINES D7 P0.22
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.
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.
Register
Function
Name
A/D Global Start Register: This address can be written (in the
ADGSR AD0 address range) to start conversions in both A/D converters
simultaneously.
Example Project: In this example project we will be using 10K POT to provide analog input
at ADC Channel 0 i.e. Pin P0.28 of LPC2148 Microcontroller. To read ADC count from POT
we will configure UART0 of LPC2148 and read data on terminal emulator (PuTTY). When we
vary resistance of POT the change in ADC count will reflect on PuTTY terminal in real time.
The circuit connection shown as:
CIRCUIT DIAGRAM: ADC in LPC2148 ARM7 Microcontroller
Circuit: ADC in LPC2148 ARM7 Microcontroller
#include <lpc214x.h>
#include "serial.h"
#include <stdio.h>
char Newline[]="\n\r\n";
char adcreading[16] ;
}
unsigned int ADC_GetAdcReading()
AD0CR = 0x01200302 ; // Select AD0.1, Select clock for ADC, Start of conversion
while(!((adcdata = AD0GDR) & 0x80000000)) // Check end of conversion (Done bit) and
read result
int main(void)
initUART0();
ADC_Init() ;
Send_String(String);
while(1)
adc = ADC_GetAdcReading();
Send_String(adcreading);
Send_String(Newline);
Bit 19 18
Analog Output AOUT Value 1 0
PINSEL1= 0x00008000
DAC Register: The DAC Register is only register used to control and configure of LPC2148
DAC. The purpose is to receive digital value from LPC2148 microcontroller and give output on
output AOUT (Pin No. 9 in case of LPC2148).
Sample code to use the internal RTC of LPC 2138/48 is given below. Here seconds, minutes &
hour are initialized to 0. Time gets updated every second and is displayed on LCD in the
format hh:mm:ss.
Changing the initial time : To change the initial time, just load the desired values into the
corresponding registers HOUR, MIN & SEC.
Running the RTC : If you want to run the RTC forever after loading the initial values, follow
these steps
i. Ensure that the RTC battery is placed in battery holder.
iii. Comment the lines which load the initial values of time.
#include<lpc21xx.h>
void RTC_int(void)__irq
{
ILR = 0X01; /* Clears counter increment interrupt */
flag = 1; /* Set flag on interrupt */
VICVectAddr = 0X00000000;
}
void RTC_Init()
{
ILR = 0X03; /* Interrupt from counter increment block */
CCR = 0X11; /* RTC Time counters enable */
CIIR = 0X01; /* Interrupt generated in each second */
SEC = 0x00; /* Load initial value into seconds register*/
MIN = 0x00; /* Load initial value into minutes register*/
HOUR = 0x00; /* Load initial value into hour register */
VICIntEnable = 0x00002000; /* RTC interrupt enabled */
VICVectCntl0 = 0x0000002D; /* RTC interrupt assigned to slot0 */
VICVectAddr0 = (unsigned)RTC_int;
}
void LCD_Init(void)
{
IO1DIR |= 0x00FE0000; /* Set P1.17-P1.23 as output */
Delay(200000) ;
Write_Command(0x30 << 16);
Delay(100000);
Write_Command(0x30 << 16);
Delay(100000);
Write_Command(0x30 << 16);
Delay(100000);
Write_Command(0x20 << 16); /* Enable 4 bit mode */
int main(void)
{
LCD_Init(); /* Initialize LCD module */
RTC_Init(); /* Initialize RTC module */
while(1)
{
if(flag)
{
LCD_Command(0x80); /* 1st row, 1st location */
flag=0; /* Clear flag */
LCD_Data(HOUR/10 + '0'); /* Display hour */
LCD_Data(HOUR%10 + '0');
LCD_Data(':') ;
LCD_Data(MIN/10 + '0'); /* Display Minute */
LCD_Data(MIN%10 + '0');
LCD_Data(':') ;
LCD_Data(SEC/10 + '0'); /* Display Second */
LCD_Data(SEC%10 + '0');
}
}
}