Record ESID With Content Beyond White Removed
Record ESID With Content Beyond White Removed
AIM:
To write a pro gram to add two 8-bit numbers using 8051 microcontrollers.
ALGORITHM:
3
FLOW CHAR T:
Start
Clear PS W
Select Register
ADD A & R0
Stop
4
PROGRAM:
Address Output
4500 1A(LSB)
4501 00(MSB)
RESULT:
Thus the 8051 Assembly Language Program for addition of two 8 bit numbers was
executed.
5
FLOW CHAR T:
Start
IS
CF=1
Stop
6
B. 8 BIT SUBTRACTION
AIM:
To perfo rm subtraction o f two 8 bit data and store the result in memor y.
ALGORITHM:
PROGRAM:
Address Output
4500 05
RESULT:
Thus the 8051 Assembly Language Pro gram for subtraction of two 8 bit numbers was
executed.
7
FLOW CHAR T:
Start
Multiply A with B
Stop
8
C. 8 BIT MULTIPLICATION
AIM:
To perfo rm multiplicatio n of two 8 bit data and store the result in memor y.
ALGORITHM:
Address Output
4500 0F(LSB)
4501 00(MSB)
RESULT:
Thus the 8051Assembly Language Program for multiplication of two 8 b it numbers was
executed.
9
FLOW CHAR T:
Start
Divide A by B
Stop
10
D. 8 BIT DIVISION
AIM:
To perfo rm division of two 8 bit data and store the result in memo r y.
ALGORITHM:
PROGRAM:
Input Output
Memo ry Location Data Memo ry Location Data
4500 (dividend) 0F 4502 (re mainder) 05
4501 (divisor) 03 4503 (quotient) 00
RESULT:
Thus the 8051 8051Assembly Language Program for division of two 8 bit numbers was
executed.
11
FLOW CHAR T:
START
STOP
12
D. MASKING BITS IN AN 8 – BIT NUMBER
AIM:
To write an assembly language pro gram to mask b its o and 7 of an 8 – bit number and
store the result in memory using 8051 microcontrollers.
ALGORITHM:
Masking bits in a 8 bit number
Start the process
Get the two data values
Get the second data
Logically „AND‟ the two data values.
Initialize the memo r y value and store the result in memor y.
Start the process
PROGRAM:
Output
Memo ry Location Data
4500 06
RESULT:
Thus the 8051assembly language program for masking bits was executed and verified
13
a) 1’s and 2 ’s complement
START
STOP
14
EXP NO: SQUAR E AND CUBE PROGRAM, FIND 2’S
COMPLEMENT OF A NUMBER
DATE
AIM:-
To write an assembly language to perform arithmetic, logical and bit manipulation instruction using
8051.
ALOGRITHM:
a) 1’s and 2’s co mplement
Get the value
Get the complement value of data.
Initialize the data pointer value as memor y.
Move the complemented value to memor y of data pointer.
Increment the value and memor y.
Store the result in memory.
Stop the process.
15
1‟s and 2‟s complement
Output
Memo ry Location Data
4200 FD (1‟s complement
4201 FE(2‟S Co mplement)
Square of a number
Input Output
Memo ry Location Data Memo ry Location Data
4200 89 4201 51
4202 49
16
b) SQUAR E PROGRAM FOR 8051
$MOD51
ORG 4100H
MOV DP TR,#4200H
MOVX A,@ DPTR
MOV B,A
MUL AB
INC DPTR
MOVX @DP TR,A
INC DPTR
MOV A,B
MOVX @DP TR,A
L:SJ MP L
*****************************************************************************
C). CUBE PROGRAM FOR 8051
$MOD51
ORG 4100H
MOV DP TR,#4200H
MOVX A,@ DPTR
MOV B,A
MOV R7,A
MUL AB
MOV R0,A
MOV R1,B
MOV A,R7
ANL A,#0F H
MOV B,A
MOV A,R0
MUL AB
MOV R2,A
MOV R3,B
MOV A,R1
MOV B,A
MOV A,R7
ANL A,#0F H
MUL AB
MOV R4,A
MOV R5,B
MOV A,R3
MOV B,R4
ADD A,B
MOV R3,A
17
MOV A,R0
MOV B,A
MOV A,R7
ANL A,#0F0H
SWAP A
MUL AB
MOV R4,A
MOV R6,B
MOV A,R7
ANL A,#0F0 H
SWAP A
MOV B,R1
MUL AB
MOV R0,A
MOV R1,B
MOV A,R6
MOV B,R0
ADD A,B
MOV R0,A
MOV R7,A
MOV A,R4
SWAP A
ANL A,#0F0 H
MOV R6,A
MOV A,R0
SWAP A
ANL A,#0F0 H
MOV R0,A
MOV A,R4
SWAP A
ANL A,#0F H
MOV R4,A
MOV B,R0
ADD A,B
MOV R4,A
MOV A,R1
SWAP A
MOV B,A
MOV A,R7
SWAP A
ANL A,#0F H
ADD A,B
MOV R0,A
MOV A,R6
MOV B,R2
ADD A,B
MOV R6,A
MOV A,R3
MOV B,R4
ADDC A,B
MOV R3,A
18
MOV A,R0
MOV B,R5
ADDC A,B
MOV R0,A
MOV DP TR,#4500H
MOV A,R6
MOVX @DP TR,A
INC DPTR
MOV A,R3
MOVX @DP TR,A
INC DPTR
MOV A,R0
MOVX @DP TR,A
L:SJ MP L
Cube of a numbe r
Input Output
Memo ry Location Data Memo ry Location Data
4200 89 4500 56
4501 3C
4502 27
RESULT:
Thus the assembly language pro gram to find 2‟s complement, Square and cube of a number
was executed and verified successfully using 8051 microcontroller
19
EXP NO:
PROGRAMMING USING ON – CHIP PORTS IN 8051
DATE A/D INTERFACE WITH 8051
AIM:
To write an assembly language program for interfacing of ADC with 8051.
ALGORITHM: -
20
FLOWCHART:
START
Make CS=0
STOP
21
PROGRAM:
Jumper Details:-
Fro m s witch CH3
B B
Software A CH0 A
SOC C ALE C CH
Fro m la tch
Box
22
RESULT:
Thus, the assembly language program for performing the interfacing of ADC with 80 51 has
been verified.
23
EXP NO:
GENERATION OF SQUARE WAVEFORM USING
DATE: INTERFACING OF DAC WITH 8051
AIM:
To interface the DAC with 8051 microcontroller and generate the square wave, saw tooth wave
and triangular wave.
REQUIR EMENTS:
24
CIRCUIT DIAGRAM :
WAVEFORMS:
25
PROGRAM FOR SQUAR E WAVE:
OBSERVATION:
RESULT:
Thus the Generation of Square Waveform Using Interfacing of DAC With 8051 assembly language program was
successfully executed.
26
EXP NO: DESIGN OF A DIGITAL L CLOCK USING TIMERS/COUNTERS IN 8051
DATE:
AIM:-
To display the digital clock specifically b y displa ying the hours, minutes
and seco nds using 8051 kits
PROGRAM:
27
Observation:
Input
1200 00
1201 00
1202 00
1203 00
1204 00
Outp ut:
Time is displa yed in the RTC board as
! Hour ŀ Minutes ŀ seconds ŀ
X 0 0 0 5 9
X 0 0 1 0 0
RESULT:
Thus Assembly Language Program for the Design of a Digital Clock Using Timers/Counters In 8051 was
successfully executed
28
EXP NO:
PROGRAMMING USING SERIAL PORTS IN 8051
DATE:
AIM:
To write an assembly language program (using serial ports in 8051) Transmitting and Receiving the data
between two kits.
ALGORITHM:
29
FLOW CHAR T:
Start
Clear PS W
Select Register
ADD A & R0
Stop
30
PROGRAM FOR RECEIVER:
Memory Label Opcode Mnemonics Comments
Location
4100 75 89 20 MOV TMOD, #20H
4103 75 8D A0 MOV TH1, #0A0H
4106 75 8B 00 MOV TL1, #00H
4109 75 88 40 MOV TCON, #40H
410C 75 98 58 MOV SCON, #58H
410F 90 45 00 MOV DPTR, #4500H Output
4112 RELOAD 7D 05 MOV R5, #05H
4114 CHECK 30 98 FD JNB SCON.0, CHECK
4117 C2 98 CLR SCON.0 MOV SCON,#50
4119 E5 99 MOV A, SBUF
411B F0 MOVX @DPTR, A
411C A3 INC DPTR
411D B4 3F F2 CJNE A, #3FH,
RELOAD
4120 DD F2 DJNZ R5, CHECK
4122 E4 CLR A
4123 12 00 20 LCALL 0020H
31
4123 12 00 20 LCALL 0020H
2 11 11
3 22 22
4 33 33
RESULT:
Thus the assembly language program (using serial ports in 8051) Transmitting and Receiving the
data between two kits was executed successfully and output was verified.
32
INTRODUCTION TO KEIL µ VISION 4 SOF TWARE
The µ Vision 4 IDE is a W indows-based software development platfo rm that
combines a robust editor, project manager, and makes facilit y. µ Vision 4 integrates all tools including the
C compiler, ma cro assembler, linke r/locator, and HEX file generator. µ Vision 4 helps expedite the
development process of your embedded applicatio ns b y providing the following:
The µ Vision 4 IDE offers numerous features and advantages that help you quickly and
successfully develop embedded applications. The y are eas y to use and are guaranteed to help you
achieve your design goals.
The installation steps for keil softw are are gi ven bel ow:
Softw are Fl ow
First open the icon keil µ vision 4 and the follow the steps are given below. The menu
bar provides you with menus for editor operations, project maintenance, development tool option
settings, pro gram debugging, external tool control , window selection and manipulation, and on- line help.
The toolbar buttons allow you to rapidly execute µ Vision4 commands. A Status Bar provides ed itor and
debugger information. The various toolbars and the status bar can be enabled or disabled from the View
Menu commands.
33
Creati ng a New Project
Below mentioned p roced ures will explains the steps required to setup a simple application and to generate
HEX output.
STEP 1 : Go to “Pro ject” and close the current project “Close Pro ject”.
34
STEP 3 : A small window will pop up with name “Create New Project ” and can be create and select
destination path.
STEP 4 : Create a folder and give a proper name that can be related to the Project.
35
STEP 5: A small window will pop up with name “Select Device for Target „Target 1‟ ”, and select the
data base NXP founded b y P hilips.
36
STEP 7 : A dd Startup file to the project by c licking “Yes”.
37
STEP 9 : There are the main three windows are available in the keil IDE. F ir st one is Project Workspace,
second one is Editor W indow and third one is Output W indow.
38
STEP 11 : Can be save the f ile, if the pr ogra m is in “C” save as “file name .C” or else save as “file name .ASM ”.
STEP 12 : Add this source file to Group1, Go to the “Project Wo rkspace ” drag the +mark “Ta rget 1 ” in
that right click on “Source Gro up1 ” and click on “Add Files to Group “Source Group1””.
39
STEP 13: A small window will pop up with name “Add Files to Group Source Group1”, b y default, the
Files of type will be in C source Files (*.C). If the pro gram is in C, have to select C source Files (*.C) o r
select ASM Source file (*.s,*.src,*.a*).
STEP 14 : Then go to “Project” click on “B uild Target” or F7. Output window will displa y related erro r and
warning messages.
40
Si mulation
Part:
STEP 15 : Go to “Project” menu, click on “Rebuild all target Files” and start Debug. From View menu can
get M emory Window and from Peripherals can get I/O ports, Serial etc. For access internal memor y t ype
i:0x_ memo ry location example: i:0x30 and for external and pro gram memor y x:0x_ memory location,
c:0x_ memo ry location respectively. From Register window we can edit and access the values also.
41
HEX fil e creation:
STEP 16 : Follow the S TEP up to 14, then go to “Pro ject” and click on “Option for Group „Source
Group1 ‟”. There a small window will open with name “Option for Target „Ta rget1‟”. In that window, go to
first menu “Device”, can be select LPC2148.
STEP 17 : Next go to Target menu, set clock freq uenc y as 12.0 MHz and select Thumb mode in the code
generation selection box.
42
STEP 18: Then go to Output menu and click on create HEX file.
43
STEP 20: Finally in the Linker menu, click on use memor y la yout from target dialo g and click ok.
STEP 21 : For creating Hex file go to “Project” menu and click on “Rebuild all ta rget Files ”
44
FLASH MAGIC
Introduction :
NXP Semiconductors produce a range o f Microcontrollers that feature both on-chip F lash
memor y and the ability to be repro grammed using In-S ystem P ro gramming technolo gy. F lash Magic is
W indows software fro m the Embedded S ystems Academy that allows eas y access to all the ISP features
provided b y the devices.
These features include:
Erasing the Flash memory (individual blocks or the whole device)
Programming the F lash memor y
Modifying the Boot Vector and Status Byte
Reading F lash memor y
Performing a blank check on a section of Flash memory
Reading the signature b ytes
Reading and writing the s ecurity bits
Direct load of a new baud rate (high speed communications)
Sending commands to place device in Bootloader mode
Flash Magic p rovides a clear and simple user interface to these features and more as described in
the following sections. Under W indows, only o ne application ma y have access the COM Port at any one time,
preventing other applications from using the COM Port. F lash Magic only obtains access to the selected COM
Port when ISP operations are being performed. This means that other applications that need to use the COM
Port, such as debugging tools, ma y be used while Flash Magic is loaded. Note that in this manual third part y
Compilers are listed alphabetically. No preferences are indicated o r implied.
45
Install ati on Procedure for Fl ash M agi c softw are:
STEP 22: For pro gramming with communication port, first select the device LPC2148 in ARM 7 categor y,
COM port will be COM 1, baud rate 9600, interface None [ISP ], Osc illator frequenc y 12.0 MHz and click on
erase of flash cod e Rd plot.
46
STEP 23: Under the menu Options, go to Advanced options.
STEP 24: Under the menu Advanced options, go to Hardware configuration, click on the Use DTR and RTS
to control RS T and ISP p in.
47
STEP 25: Next browse the path o f hex file and select the file.
STEP 26: After selecting ISP mode on the Hard ware K it and click on start.
48
STEP 27: After the above steps device will start to pro gram.
STEP 28: Finally can be see the f inished indication and Reset the device into running mode.
49
Programmi ng through USB:
STEP 1 : Connect the USB cable between ARM-7 LPC2148 Trainer K it and PC. Connect the power supply to
the trainer kit and power up. After can see a popup window with name “Found New Hardware CP2102 USB
to UAR T Bride Controller“.
STEP 2 : Select on Install from a list or specific location (Advanced) and click “Next”.
50
STEP 3: Browse for the driver file location and select the folder, click next.
51
STEP 4: After that can see New Hardware wizard, and then click on finish.
52
STEP 6: Then go to device manager, in that we have to select ports (COM and LPT). There
we have to find the COM port which has been selected for US B cable. The same COM has to
be select for Flash Magic.
53
ARM 7 LPC2148 TRAINER K IT
Introductio n:
Thank you for using ARM 7 LPC2148 Trainer K it designed for educational training p urpose and
the embedded device fro m NXP. This document is a User‟s guide which describes the complete
hardware design o f the ARM 7 LPC2148 Trainer K it.
54
13. UART0 connectivity.
Optional: Can be use fo r ISP pro gramming mode.
14. LEDs for PWM outp ut.
15. PWM enable switch.
16. USB connector for ISP pro gramming and Serial port connectivit y.
17. LED indication fo r to confirm the US B connection has been established.
18. Switch selection for ISP /UART. The selection will be for ISP if the switch has
been pressed else for UART.
19. Switch for to enable the ISP.
20. I/O port 10 pin FRC connec tor (F RC5).
21. I/O port 10 pin FRC connector (F RC4).
22. I/O port 10 pin FRC connector (F RC3).
23. I/O port 16 pin FRC connector (F RC2).
24. I/O port 10 pin FRC connector (F RC1).
25. LPC2148 Device Daughter card.
26. USB ISP pro grammer daughter card.
Note: For In S ystem Pro gramming (ISP), the switch which has been mentioned in
the description line 18 and 19 has to be pressed.
Fe atures :
1. Device daughter card, eas y and flexible to up grade the device.
2. Four 10 pin individual digital or analo g I/O ports are available.
3. One16 pin digital I/O port is available.
4. Inbuilt LEDs are available for PWM output.
5. Inbuilt push to on switch for Reset.
6. Inbuilt push to on switch for External Interrupt.
7. USB ISP p ro grammer inbuilt.
8. On board Serial to US B brid ge is available
55
Device Daughte r Board Deta ils:
CN6
PIN NO: N N O:
1.3
P0.22/AD1.7/CAP0.0/MAT0.0 3
RTCX1
P1.19/TRACEPKT3 2
RTCX2 1
VSS
P1.18/TRACEPKT2 1
P0.25/AD0.4/AOUT
P1.17/TRACEPKT1 0
P0.28/AD0.1/CAP0.2/MAT0.2
P0.29/AD0.2/CAP0.3/MAT0.3
3
P1.16/TRACEPKT0
CN7
N O: N N O:
P0.31/UP_LED/CONNECT
VSS
P0.0/TXD0/PWM1
T MS
0
0.0
1.3
P1.26/RTCK K
VSS
1
P0.4/SCK0/CAP0.1/AD0.6
0
P0.5/MISO0/MAT0.1/AD0.7
1.0
P0.7/SSEL0/PWM2/EINT2
P1.24/TRACECLK O
56
F RC P IN DE TAILS:
FRC 1 FRC 2 FRC 3
PIN NO: D ES C R I PTI O N PIN NO: D ES C R I PTI O N PIN NO: DESCRIPTION
1 P0.16 1 P 0.8 1 P 0.3(S D A 0)
2 P0.17 2 P 0.9 2 P0.2(SCL0)
3 P0.18 3 P 0.10 3 P0.14(SDA1)
4 P0.19 4 P 0.11 4 P0.11(SCL1)
5 P0.20 5 P 1.16 5 P 0.16 E N T 1
6 P0.21 6 P 1.17 6 P 0.15 E N T 2
7 P0.22 7 P 1.18 7 RS 232 T X 0
8 P0.23 8 P 1.19 8 RS232 RX0
9 + 5V 9 P 1.20 9 +5V
10 GND
10 P 1.21 10 GND
FRC 11 P 1.22
FRC
PIN N 12 P 1.23
PIN N
13 + 5V
14 NA
15 +3V3
GN
16 D
RS232
1
57
INTERFACE CARD DETAILS:
LED MODULE MATRIX KEYPAD STEPPER MOTOR
PIN NO DESCRIPTION PIN N PIN N
1 Le d1
2 Le d2
3 Le d3
4 Le d4
5 Le d5
6 Le d6
7 Le d7
8 Le d8
9 +5V
10 G ND
ADC / TEMPERATURE
PIN PIN NO D ES C R I PTI O N PIN N
1 NA
2 A D 01
3 NA
4 NA
5 NA
6 NA
7 NA
8 NA
9 +5V
10 GND
LCD
PIN NO DESCRIPTION PIN N
RS
EN
+5V
-5V
+3V3
58
TOGGLE SWITCH DC SEVEN
PIN NO N N PIN N
T1 SHIFT
E DATA
LATCH
T2
+5V
GND 10
59
ET3491 EMBEDDED AND IOT LAB
EXP NO:
LED & FLASHING OF LED’S
DATE
AIM:
To write and execute the pro gram for LED & Flas hing Led‟s with ARM7
(LPC2148) processor.
PROCEDURE
1. Create a New project, Go to “Project” and close the curre nt project “C lose Project”.
2. Next Go to the Project New μ vision Project Create New P roject Select Device fo r Target.
3. Select the data base NXP LPC2148.
4. Add Startup file and Next go to “File” and click “New”.
5. Write a pro gram on the edito r window and save as “Main.c”.
6. Add this source file to Group and click on “Build Target” or F7.
7. Create a Hex file from “Project” menu and click on “Rebuild all target Files ”.
8. Open Flash magic and select the device LPC2148 in ARM 7 categor y, Choose the
hardware connected COM port, baud rate 9600, interface None [ISP], Oscillator frequenc y
12.0 MHz and click on erase of flash code Rd plot.
9. Next browse the path of hex file and select the file.
10. After selecting ISP mode on the Hardware K it and click on start then device will start to
program
11. Finally can be see the finished indication and values in SPJ Terminal and Reset the
device into running mode.
60
ET3491 EMBEDDED AND IOT LAB
LED INTERFACING:
CIRCUIT DI AGRAM :
61
ET3 4 9 1 EM B ED D ED A ND IOT L A B
P ROGRA M:
#include <lpc214x.h>
int i;
int main()
{
IODIR0=(1<<3);
while(1)
{ IOSET0= (1<<3);
for(i=0;i<120000;i++);
IOCLR0=(1<<3);
for(i=0;i<120000;i++);
}
}
62
|
ET3491 EMBEDDED AND IOT LAB
FLASHING O F LED:
CIRCUIT DI AGRAM :
63
|
ET3491 EMBEDDED AND IOT LAB
PROGRAM:
TYPE-I:
#include <lpc214x.h>
int i;
int main()
{
IODIR0=0x000000FF;
while(1)
{
IOSET0=0x000000AA;
for(i=0;i<120000;i++);
IOCLR0=0x000000AA;
for(i=0;i<120000;i++);
}
}
TYPE-II :
#include <lpc214x.h>
int i,b;
int main()
{
IODIR0=0x000000FF;
while(1)
{
for(b=0;b <8;b++)
{ IOSET0= (1<<b);
for(i=0;i<120000;i++);
IOCLR0=(1<<b);
for(i=0;i<120000;i++);
}
}
}
64
|
ET3491 EMBEDDED AND IOT LAB
TYPE-II I
65
|
ET3 4 9 1 EM B ED D ED A ND IOT L A B
F R O N T A N D BA C K L E D :
#include <lpc214x.h>
int b,i;
int main()
{
IODIR0=0x000000FF;
while(1)
{
for(b=0;b <8;b++)
{ IOSET0= (1<<b);
for(i=0;i<120000;i++);
IOCLR0=(1<<b);
for(i=0;i<120000;i++);
}
for(b=7;b >=0;b--)
{ IOSET0= (1<<b);
for(i=0;i<120000;i++);
IOCLR0=(1<<b);
for(i=0;i<120000;i++);
}
}
}
66
|
ET3 4 9 1 EM B ED D ED A ND IOT L A B
SWI TCH CONTROLLED LED (1-S WITCH):
CIR C U I T DIA G R A M :
67
|
ET3 4 9 1 EM B ED D ED A ND IOT L A B
P ROGRA M:
#include <lpc214x.h>
int i,b;
int main()
{
IODIR0=0x000000FF;
IODIR0=~(1<<16);
while(1)
{
if((IOPIN0&(1<<16))==0)
{
for(b=0;b <8;b++)
{ IOSET0= (1<<b);
for(i=0;i<120000;i++);
IOCLR0=(1<<b);
for(i=0;i<120000;i++);
}
}
else
{
IOCLR0=0x000000FF;
}
}
}
68
|
ET3 4 9 1 EM B ED D ED A ND IOT L A B
SWI TCH CONTROLLED LED (2-S WI TCH):
CIR C U I T DIA G R A M :
69
|
ET3491 EMBEDDED AND IOT LAB
PROGRAM:
#include <lpc214x.h>
int i,b;
int main()
{ IODIR0=0x000000FF;
IODIR0=~(1<<16)&~(1<<23);
while(1)
{
if((IOPIN0&(1<<16))==0)
{
for(b=0;b <8;b++)
{ IOSET0= (1<<b);
for(i=0;i<120000;i++);
IOCLR0=(1<<b);
for(i=0;i<120000;i++);
}
}
else if((IOPIN0&(1<<23))==0)
{
for(b=7;b >=0;b--)
{ IOSET0=(1<<b);
for(i=0;i<120000;i++);
IOCLR0=(1<<b);
for(i=0;i<120000;i++);
}
}
else
{
IOCLR0=0x000000FF;
}
}
}
70
ET3491 EMBEDDED AND IOT LAB
RESULT:
Thus the Interfacing LED with ARM LPC2148 microcontroller was executed successfully
71
ET3491 EMBEDDED AND IOT LAB
EXP NO:
INTERFACING OF LCD
DATE
AIM:
To write and execute the program f or LCD w it h ARM7 ( LPC2148) processor.
PROCEDURE
1. Create a New project, Go to “Project” and close the current project “C lose Project”.
2. Next Go to the Project New μ vision Pro ject Create New Project Selec t Device fo r Target.
3. Select the data base NXP LPC2148.
4. Add Startup file and Next go to “File” and click “New”.
5. Write a pro gram on the edito r window and save as “Main.c ”.
6. Add this source file to Group and click on “Build Target” or F7.
7. Create a Hex file from “Project” menu and click on “Rebuild all target Files ”.
8. Open F lash magic and select the device LPC2148 in ARM 7 catego r y, COM port will be
COM 3, baud rate 9600, interface None [ISP], Oscillator frequenc y 12.0 MHz and c lick on
erase of flash code Rd plot.
9. Next browse the path of hex file and select the file.
10. After selecting ISP mode on the Hardware K it and click on start then device will start to
program
11. Finally can be see the finished indication and values in SPJ Ter minal and Reset the
device into running mode. 72
ET3491 EMBEDDED AND IOT LAB
INTERFACING LCD:
CIRCUIT DI AGRAM :
73
ET3491 EMBEDDED AND IOT LAB
PROGRAM:
#include <lpc214x.h>
#include <lcd.h>
int main()
{
LCD_INIT();
LCDS TR(0x00000084,"JIT ");
LCDS TR(0x000000C2,"Institute");
while(1)
{
}
}
LCD LAYOUT:
80 81 82 83 84 85 86 87 88 89 8A 8B 8C 8D 8E 8F
C0 C C2 C3 C4 C5 C6 C C8 C9 CA CB CC CD CE CF
74
ET3491 EMBEDDED AND IOT LAB
OUTPUT(in LCD):
J I T
I N S T I T U T E
RESULT:
Thus the Interfacing LCD with ARM LPC2148 microcontroller was executed successfully
75
ET3491 EMBEDDED AND IOT LAB
EXP NO:
INTERFACING OF MATRIX KEYBOARD
DATE
AIM:
To write and e xecute the pr ogram f or Matr ix Keyboar d with AR M7 (LPC2148) pr ocessor.
PROCEDURE
1. Create a New project, Go to “Project” and close the current project “C lose Project”.
2. Next Go to the Project New μ vision Project Create New P roject Select Device fo r Target.
3. Select the data ba se NXP LPC2148.
4. Add Startup file and Next go to “File” and click “New”.
5. Write a pro gram on the edito r window and save as “Main.c ”.
6. Add this source file to Group and click on “Build Target” or F7.
7. Create a Hex file from “Project” menu and click on “Rebuild all target Files”.
8. Open F lash magic and select the device LPC2148 in ARM 7 catego r y, COM port will be
COM 3, baud rate 9600, interface None [ISP], Oscillator frequenc y 12.0 MHz and click on
erase of flash cod e Rd plot.
9. Next browse the path of hex file and select the file.
10. After selecting ISP mode on the Hardware K it and click on start then device will start to
program
11. Finally can be see the finished indication and values in SPJ Terminal and Reset the
device into running mode.
76
ET3491 EMBEDDED AND IOT LAB
CIRCUIT DI AGRAM :
ET3491 EMBEDDED AND IOT LAB
PROGRAM:
#include <lpc214x.h>
#include <lcd.h>
#include <ke yboard.h>
int main()
{
LCD_INIT();
LCDS TR(0x00000080,"Matrix Keypad ");
LCDS TR(0x000000C0,"Ke y Pressed: ") ;
while(1)
{
IO0CLR = C LR;
IO0SET = C1;
dela y_ms(10);
if(scan(R1)) LCDS TR(0x000000CC,"0 "); //K1
if(scan(R2)) LCDS TR(0x000000CC,"4 "); //K5
if(scan(R3)) LCDS TR(0x000000CC,"8 "); //K9
if(scan(R4)) LCDS TR(0x000000CC,"C "); //K13
IO0CLR = C LR;
IO0SET = C2;
if(scan(R1)) LCDS TR(0x000000CC,"1 "); //K2
if(scan(R2)) LCDS TR(0x000000CC,"5 "); //K6
if(scan(R3)) LCDS TR(0x000000CC,"9 "); //K10
if(scan(R4)) LCDS TR(0x000000CC,"D"); //K14
IO0CLR = C LR;
IO0SET = C3;
if(scan(R1)) LCDS TR(0x000000CC,"2 "); //K3
if(scan(R2)) LCDS TR(0x000000CC,"6 "); //K7
if(scan(R3)) LCDS TR(0x000000CC,"A"); //K11
if(scan(R4)) LCDS TR(0x000000CC,"E"); //K15
IO0CLR = C LR;
IO0SET = C4;
if(scan(R1)) LCDS TR(0x000000CC,"3 "); //K4
if(scan(R2)) LCDS TR(0x000000CC,"7 "); //K8
if(scan(R3)) LCDS TR(0x000000CC,"B"); //K12
if(scan(R4)) LCDS TR(0x000000CC,"F "); //K16
}
}
78
|
ET3491 EMBEDDED AND IOT LAB
RESULT:
Thus the Interfacing MATRIX KEYBOARD with ARM LPC2148 microcontroller was
AIM:
To write and e xecute the pr ogram f or Stepper Motor w ith ARM7 (LPC2148) proce ssor.
PROCEDURE
1. Create a New project, Go to “Project” and close the current project “C lose Project”.
2. Next Go to the Project New μ vision Project Create New P roject Se lect Device fo r Target.
3. Select the data base NXP LPC2148.
4. Add Startup file and Next go to “File” and click “New”.
5. Write a pro gram on the edito r window and save as “Main.c ”.
6. Add this source file to Group and click on “Build Target” or F7.
7. Create a Hex file from “Project” menu and click on “Rebuild all target Files ”.
8. Open F lash magic and select the device LPC2148 in ARM 7 catego r y, COM port will be
COM 3, baud rate 9600, interface None [ISP], Oscillator frequenc y 12.0 MHz and click on
erase of flash cod e Rd plot.
9. Next browse the path of hex file and select the file.
10. After selecting ISP mode on the Hardware K it and click on start then device will start to
program
11. Finally can be see the finished indication and values in SPJ Terminal and Reset the
device into running mode.
ET3491 EMBEDDED AND IOT LAB
Pin No
0.16 0.17 0.18 0.19
C l o ck
81
E T3 4 9 1 E M B ED D ED A ND IOT L A B
PROGRA M:
#include <lpc214x.h>
#include <dela y. h>
int main()
{
IODIR0=(1<<16)|(1<<17)|(1<<18)|(1<<19);
while(1)
{
//FORW ARD DIREC TION
IOCLR0=(1<<16 );
IOCLR0=(1<<17 );
IOSET0= (1<<18);
IOSET0=(1<<19);
dela y_ms(10);
IOCLR0=(1<<16 );
IOSET0= (1<<17);
IOSET0= (1<<18);
IOCLR0=(1<<19 );
dela y_ms(10);
IOSET0= (1<<16);
IOSET0= (1<<17);
IOCLR0=(1<<18 );
IOCLR0=(1<<19 );
dela y_ms(10);
IOSET0= (1<<16);
IOCLR0=(1<<17 );
IOCLR0=(1<<18 );
IOSET0=(1<<19);
dela y_ms(10);
}
}
82
ET3491 EMBEDDED AND IOT LAB
Pin No
0.16 0.17 0.18 0.19
C l o ck
83
ET3491 EMBEDDED AND IOT LAB
PROGRAM:
#include <lpc214x.h>
#include <dela y. h>
int main()
{
IODIR0=(1<<16)|(1<<17)|(1<<18)|(1<<19);
while(1)
{
//REVERS E DIREC TION
IOSET0= (1<<16);
IOCLR0=(1<<17 );
IOCLR0=(1<<18 );
IOSET0= (1<<19);
dela y_ms(10);
IOSET0=(1<<16);
IOSET0= (1<<17);
IOCLR0=(1<<18 );
IOCLR0=(1<<19 );
dela y_ms(10);
IOCLR0=(1<<16 );
IOSET0= (1<<17);
IOSET0= (1<<18);
IOCLR0=(1<<19 );
dela y_ms(10);
IOCLR0=(1<<16 );
IOCLR0=(1<<17 );
IOSET0= (1<<18);
IOSET0= (1<<19);
dela y_ms(10);
}
}
84
RESULT:
Thus the Interfacing stepper motor with ARM LPC2148 microcontroller was executed
85
EXP NO: INTERFACING ADC AND DAC
DATE:
AIM:
To write and execute the program for Interfacing ADC and DAC with ARM LPC2148
microcontroller
THEORY:
Basic clocking for the A/D converters is provided by the VPB clock. A programmable
divider is included in each converter, to scale this clock to the 4.5 MHz (max) clock needed by the
successive approximation process. A fully accurate conversion requires 11 of these clocks.
In ARM214X Kit, for testing on-board analog input, port lines P0.29 and P0.30
connected through 10K potentiometer selected by jumpers. The signals P0.29 and P0.30 can be
used as general purpose pins if the analog inputs are not used and in this case the analog voltages
can easily be removed by removing the two jumpers on JP4 and JP5.
86
Analog/digital conversion requires sampling the analog input before converting it to digital form. A
control signal causes the A/D converter to take a sample and digitize it.
There are several different types of A/D converter circuits, some of which take a constant amount of
time, while the conversion time of others depends on the sampled value. Variable -time converters
provide a done signal so that the microprocessor knows when the value is ready.
A typical A/D interface has, in addition to its analog inputs, two major digital inputs. A data port allows
A/D registers to be read and written, and a clock input tells when to start the next conversi on.
Features
10 bit successive approximation analog to digital converter (two in LPC2148).
Input multiplexing among 8 pins.
Power-down mode | Measurement range 0 to 3 V.
10 bit conversion time ≥ 2.44 μs.
Burst conversion mode for single or multiple inputs.
Optional conversion on transition on input pin or Timer Match signal.
Global Start command for both converters (LPC2148 only).
Connection:
LCD PORT
LCD_D4 P0.19
LCD_D5 P0.20
LCD_D6 P0.21
LCD_D7 P0.22
LCD_EN P0.18
LCD_RW P0.17
LCD_RS P0.16
(ADC) P0.28
AD0.1
87
Program: Analog to Digital Converter
#include <lpc214x.h>
#include <stdio.h>
#define RS 0x10000
#define RW 0x20000
#define EN 0x40000
#define r1 (1<<24) //// P1.24
#define r2 (1<<25) //// P1.25
#define r3 (1<<26) //// P1.26
#define r4 (1<<27) //// P1.27
#define c1 (1<<28) //// P1.28
#define c2 (1<<29) //// P1.29
#define c3 (1<<30) //// P1.30 //PIN= 52
#define c4 (1<<31) //// P1.31 //PIN= 20
88
void delay(unsigned int n)
{
unsigned int i,j;
for(i=0;i<n;i++)
{
for(j=0;j<12000;j++);
}
}
void lcd_cmd(unsigned char data)
{
IOCLR0 |= RS; // 0x1000; //RS
IOCLR0 |= RW; // 0x2000; //RW
LCD4_Convert(data);
}
void lcd_initialize(void)
{
int i;
for(i=0;i<4;i++)
{
IOCLR0 = 0xF << 19; //IOCLR 0/1
lcd_cmd(cmd[i]);
delay(15);
}
}
void lcd_data (unsigned char data)
{
IOSET0 |= RS; //0x1000; //RS
IOCLR0 |= RW; //0x2000; //RW
LCD4_Convert(data);
89
}
void LCD4_Convert(unsigned char c)
{ if(c & 0x80) IOSET0 = 1 << 22; else IOCLR0 = 1 << 22;
if(c & 0x40) IOSET0 = 1 << 21; else IOCLR0 = 1 << 21;
if(c & 0x20) IOSET0 = 1 << 20; else IOCLR0 = 1 << 20;
if(c & 0x10) IOSET0 = 1 << 19; else IOCLR0 = 1 << 19;
IOSET0 = EN; // LCD_EN -> uCPIN -> 18
delay(8);
IOCLR0 = EN; // LCD_EN -> uCPIN -> 18
if(c & 0x08) IOSET0 = 1 << 22; else IOCLR0 = 1 << 22;
if(c & 0x04) IOSET0 = 1 << 21; else IOCLR0 = 1 << 21;
if(c & 0x02) IOSET0 = 1 << 20; else IOCLR0 = 1 << 20;
if(c & 0x01) IOSET0 = 1 << 19; else IOCLR0 = 1 << 19;
IOSET0 = EN; // LCD_EN -> uCPIN -> 18
delay(8);
IOCLR0 = EN; // LCD_EN -> uCPIN -> 18
}
void lcd_display (void)
{
char i; /* first line message */
lcd_cmd(0x80);
delay(15); i=0;
while(msg[i]!='\0')
{
delay(5);
lcd_data(msg[i]);
i++;
}
90
delay(15); /* second line message */
lcd_cmd(0xc0);
delay(15); i=0;
while(msg1[i]!='\0')
{
delay(5);
lcd_data(msg1[i]);
i++;
}
delay(15);
}
void ADC_Init()
{
PINSEL1 |= 0x01000000; //Configure P0.28 as AD0.2 ->PIN 13
AD0CR = 0x00200F02;
/*
SEL = 0x02 as AD0.1 is Choosen
CLKDIV = 0x0F
CLKS and BURST = 0x0 means that 11 Intruction Cycles
used,resulting in 10-Bit Data
And Don't Start the Conversion Now
*/
}
unsigned int Read_ADC()
{
unsigned int adc_data;
AD0CR |= 0x01000000; //Start the ADC Conversion
91
//Delay(100000);
do
{
adc_data = AD0DR1;
}while(!(adc_data & 0x80000000));
//Wait untill the DONE bits Sets
AD0CR &= ~0x01000000; /* Stop A/D Conversion
*/
//AD0CR &= 0xFE000000; //Stop the ADC Conversion
adc_data = adc_data>>6;
adc_data = adc_data & 0x3FF; //Clearing all other Bits
return (adc_data);
}
int main(void)
{
unsigned int adc_data;
unsigned char ones,tens,hundreds,thousands;
// PINSEL1 = 0; // all P1 IS GPIO
// IODIR0 = 0xFF << 16; // OUPUT
PINSEL0 = 0x0000ff00; // P0.0 ... P0.15 --> IS GPIO
IODIR0 = 0Xffffffff; // P0.0 .... P0.31 --> O/P
PINSEL1 = 0x00000000; // P0.16 ... P0.31 --> IS GPIO
IODIR1 = 0xf0000000; // P0.31 to P0.28 -> 0/P ; -> OTHERS PINS ARE -> I/P
lcd_initialize();
lcd_display();
ADC_Init();
delay(1000);
while(1)
{
92
// lcd_data(keypad());
adc_data = Read_ADC();
ones = adc_data % 10;
adc_data = adc_data / 10;
tens = adc_data % 10;
adc_data = adc_data / 10;
hundreds = adc_data % 10;
adc_data = adc_data / 10;
thousands = adc_data % 10;
lcd_cmd(0xC0); //Second Row
lcd_data(thousands | 0x30);
lcd_data(hundreds | 0x30);
lcd_data(tens | 0x30);
lcd_data(ones | 0x30);
delay(100000);
delay(100000);
delay(100000);
delay(100000);
}
}
Theory:
D/A conversion is relatively simple, so the D/A converter interface generally includes only
the data value. The input value is continuously converted to analog form.
93
Procedure:
Connection:
#include <LPC214x.h>
//**********************End of INCLUDES*****************************************
//**********************User Setting*******************************
// DAC_BIAS Setting:
// 0 The settling time of the DAC is 1 µs max, and the maximum
// current is 700 µA.
// 1 The settling time of the DAC is 2.5 µs and the maximum
// current is 350 µA.
#define DAC_BIAS 0
//*******************End of User Setting***************************
//*******Public Protoype***********************
void DacInit( void );
void DacOut( unsigned int val );
void _Delay45Us(void);
//*****End of Public Protoype//**************
94
void delay(void)
{
int i;
for(i=0;i<100;i++)
_Delay45Us();
}
95
{
PINSEL1 |= 0x00080000; //set P0.25 to DAC output
}
void DacOut( unsigned int val )
{
DACR = (val << 6) | (DAC_BIAS<<16);
}
void _Delay45Us(void)
{
volatile unsigned int k;
for(k=0;k<409;k++)
{
asm
{
nop;
}
}
}
RESULT:
Thus the Interfacing ADC and DAC with ARM LPC2148 microcontroller were executed successfully.
96
Miniprojects for IOT:
1. Garbage Segregator and Bin Level Indicator
2. Colour based Product Sorting
3. Image Processing based Fire Detection
4. Vehicle Number Plate Detection
5. Smart Lock Syste m
Objective:
Team constitution:
Guidelines :
2.Student must buy their own hardware setup for doing Miniprojects.
3.If the y are utilizing the college resource, the y should get approval from HoD.
4.At the end, a report alo ng with hardware must be submitted to college.
97
Ga rbage Segregator and Bin Level Indicator
IDEA:
W ith progress in human technolo gy we have seen a substantial progress in the amount o f waste
generated. Rec ycling is the only wa y to manage this huge amount of waste. But rec ycling requires
garb age to be segregated. W ithout segregation garbage cannot be rec ycled because different t ype
of garbage requires different rec ycling p rocesses.
Also It is important to educate users and instruct them ever y time the y co me near the dustbin
about instructions about throwing the trash. For this purpose we design a garbage disposal s ystem
that uses multiple dustbins with a voice based s ystem that speaks to the user each time he she
stands before the dustbin.
The s ystem makes use o f a camera to detect presence if any person in front of the dustbin. If a
person is detected, the s ystem issues voice instructions to the user about throwing right garbage in
the right bin. In case the dustbin is full it instructs the user to find another dustbin to throw
garb age in.
To develop this s ystem we make use of a raspb err y P i controller. The co ntroller is interfaced with
a camera a nd a voice speaker fo r detection and communication. The controller gets d ustbin level
input using ultrasonic level sensors each having LED indicators interfaced to it. The level senso rs
are used to constantly feed the raspberr y pi with bin levels.
The raspberr y pi is also interfaced with a W ifi module to transmit the level data over the internet.
The Level sensor panels are made to be easily mounted over any dustbin. This allows the s ystem
to be easily screwed over any dustbin for instant installation.
The data is transmitted over IO T to IOT gecko platform which displa ys the bin level data over
internet. This indication can be used to alert the authorities that the garbage bins need to be
emptied. Thus the s ystem automates garbage segregation and level monitoring to help counter the
garb age crisis using IO T.
Note: The Dustbins are not included in this kit. The sensors can be mounted over any op en
dustbins.
Components
Raspberr y P i
W ifi Module
Ultrasonic Level Sensors
LED Indicators
Camera
Speaker
W iring
Supporting Frame
Resistors
Capacitors
Diodes
IC‟s
Transistors
Connectors
PCB
99
DATE: Colour base d Product Sorting
IDEA:
Color Based Object Sorting has a wide usage in fruit sorting as well as cand y so rting industries.
This system puts forward a mechanism to detect color and sort items through ima ge processing.
Once identified a mechanism is used to sort the candies into particular bins baskets. We here
demonstrate this mechanism using a camera with electronic circuitr y along with sorting
mechanism using 3 bins. The s ystem uses raspberr y pi connected to a controller circuit to achieve
this task. The controller circuit consists o f a camera attached to it that detects color o f a sma ll
object in front of it. A motor is used to feed an object to the camera chamber. As soon is the color
is detected a signal is sent to the sorter mechanism which uses a moto r to position the sorting tube
towards respective sectio n. A feeder is then used to push the object towards the tubs so that it gets
sorted and next object is pulled in b y the feeder. The action details are sent to the IOT server
using iotgecko platform to keep track o f the number o f objects sorted in each section. Thus, we
achieve a co mpletely automated IOT b ased sorting s ystem.
Hardware Specifications
Raspberr y P i 3
Camera Servo
Motor LCD
Displa y
Resistors
Capacitors
Transistors
Diodes
LED
Transformer/Adapter
Push Buttons
Switch 100
IC
IC Sockets
Connector S haft
Bed Frame
Tubes
Supporting Frame
Software Specifications
Python
IOTGecko
BLOCK DIAGRAM:
100
DATE:
Image Processing based Fire De tection
IDEA:
The main advantage o f Image Pro cessing Based F ire Detection S ystem is the early
warning benefit. This s ystem can be installed just about anywhere in a commercial
building, malls and at many more public places for fire d etection. This s ystem uses camera
for detecting fires. So we do not need any other sensors to detect fire. S ystem processes
the camera input and then processor processes it to detect fires. The heat signatures and
fire illumination pa tterns are detected in images to determine if it is a fire and take actio n
accordingly. On detecting fire s ys tem goes into emergenc y mode and sounds an alarm.
Also displa ys the status o n the LCD displa y informing about the s ystem.
Hardware Specifications
Raspberr y P i 3
Camera
Buzzer
LCD Displa y
Resistors
Capacitors
Transistors
Diodes
LED
Transformer/Adapter
Push Buttons
Switch
IC
IC Sockets
Software Specif ications
Linux
BLOCK DIAGRAM:
102
Vehicle Number Plate Detection
IDEA:
103
104
SMART LOCKS YS TEM
DATE:
IDEA:
From connected cars to connected wearables to home security, the Internet of Things is rapidly marking its presenc e in
every field. Now we have IoT enabled home automation and securit y devices that can be controlled from anywhere
in the world us ing the Internet of Things. There are many kinds of Wi-Fi door lock available in the market which makes
your home more secure and saves time in f inding the keys. Here we are also building a s imilar Wi-Fi door lock which
can be controlled from the Smartphone
So in this project, we are going to make an IOT based Door Lock System using NodeMCU, Solenoid Lock,
and Adafruit IO . Here NodeMCU will act as the main controller and connect the user to the door lock system
using the Internet. This allows the user to lock/unlock his Home‟s door lock by us ing a smartphone from anywhere
in the wor ld.
Components Required
NodeMCU ESP8266
Solenoid Lock
Rela y Module
Buzzer
105
1
TEMPERATURE SENSOR
THEORY:
TEMP SECTION
The LM35 series are precision integrated-circuit temperature sensors, whose output
voltage is linearly proportional to the Celsius (Centigrade) temperature. The LM35 thus has an
advantage over linear temperature sensors calibrated in ° Kelvin, as the user is not required to
subtract a large constant voltage from its output to obtain convenient Centigrade scaling.
2
The LM35 does not require any external calibration or trimming to provide typical
accuracies of ±¾°C at room temperature and ±¼°C over a full -55 to +150°C temperature range. Low
cost is assured by trimming and calibration at the wafer level. It can be used with single power
supplies, or with plus and minus supplies. The LM35 is rated to operate over a -55° to +150°C
temperature range, while the LM35C is rated for a -40° to +110°C range (-10° with improved
accuracy).
Features
Calibrated directly in ° Celsius (Centigrade)
Linear + 10.0 mV/°C scale factor
0.5°C accuracy guarantee-able (at +25°C)
Rated for full -55° to +150°C range
Operates from 4 to 30 volts.
JUMPER DETAILS: connect J27 & J28 using 10 pin FRC cable
PORT PIN
CONFIGURATION
LCD_D4 P0.19 uC PIN -> 54
LCD_D5 P0.20 uC PIN -> 55
LCD_D6 P0.21 uC PIN -> 1
LCD_D7 P0.22 uC PIN -> 2
LCD_EN P0.18 uC PIN -> 53
LCD_RW P0.17 uC PIN -> 47
LCD_RS P0.16 uC PIN -> 46
(TEMP) AD0.2 P0.28 uC PIN -> 14
3
PROCEDURE:
Program:
#include <lpc214x.h>
#include <stdio.h>
#define RS 0x10000
#define RW 0x20000
#define EN 0x40000
#define r1 (1<<24) //// P1.24
#define r2 (1<<25) //// P1.25
#define r3 (1<<26) //// P1.26
#define r4 (1<<27) //// P1.27
#define c1 (1<<28) //// P1.28
#define c2 (1<<29) //// P1.29
#define c3 (1<<30) //// P1.30 //PIN= 52
#define c4 (1<<31) //// P1.31 //PIN= 20
void lcd_cmd (unsigned char);
void lcd_data (unsigned char);
void lcd_initialize (void);
void lcd_display (void);
void LCD4_Convert(unsigned char);
void ADC_Init(void);
unsigned int Read_ADC(void);
const unsigned char cmd[4] = {0x28,0x0c,0x06,0x01};
unsigned char msg[] = {" LM335 Temp "};
unsigned char msg1[]= {"~~~~~~~~~~~~~~~~"};
void delay(unsigned int n)
{
unsigned int i,j;
for(i=0;i<n;i++)
{
for(j=0;j<12000;j++);
} }
void lcd_cmd(unsigned char data)
{
IOCLR0 |= RS; // 0x1000; //RS
IOCLR0 |= RW; // 0x2000; //RW
LCD4_Convert(data);
}
4
void lcd_initialize(void)
{
int i;
for(i=0;i<4;i++)
{
IOCLR0 = 0xF << 19; //IOCLR 0/1
lcd_cmd(cmd[i]);
delay(15);
}
}
void lcd_data (unsigned char data)
{
IOSET0 |= RS; //0x1000; //RS
IOCLR0 |= RW; //0x2000; //RW
LCD4_Convert(data);
}
void LCD4_Convert(unsigned char c)
{ if(c & 0x80) IOSET0 = 1 << 22; else IOCLR0 = 1 << 22;
if(c & 0x40) IOSET0 = 1 << 21; else IOCLR0 = 1 << 21;
if(c & 0x20) IOSET0 = 1 << 20; else IOCLR0 = 1 << 20;
if(c & 0x10) IOSET0 = 1 << 19; else IOCLR0 = 1 << 19;
IOSET0 = EN; // LCD_EN -> uCPIN -> 18
delay(8);
IOCLR0 = EN; // LCD_EN -> uCPIN -> 18
if(c & 0x08) IOSET0 = 1 << 22; else IOCLR0 = 1 << 22;
if(c & 0x04) IOSET0 = 1 << 21; else IOCLR0 = 1 << 21;
if(c & 0x02) IOSET0 = 1 << 20; else IOCLR0 = 1 << 20;
if(c & 0x01) IOSET0 = 1 << 19; else IOCLR0 = 1 << 19;
IOSET0 = EN; // LCD_EN -> uCPIN -> 18
delay(8);
IOCLR0 = EN; // LCD_EN -> uCPIN -> 18
}
void lcd_display (void)
{
char i; /* first line message */
lcd_cmd(0x80);
delay(15);
i=0;
while(msg[i]!='\0')
{
delay(5);
lcd_data(msg[i]);
i++;
}
5
{
unsigned int adc_data;
unsigned char ones,tens,hundreds,thousands;
}
}
RESULT:
7
AIM: To interfacing Real time clock and serial communication using ARM7 LPC2148
microcontroller.
RTC is a low power serial real-time clock (RTC) device with two programmable time-of-day
alarms and a programmable square-wave output. Address and data are transferred serially through
an I2C bus. The device provides seconds, minutes, hours, day, date, month, and year information.
The date at the end of the month is automatically adjusted for months with fewer than 31 days,
including corrections for leap year. The clock operates in either the 24-hour or 12-hour format with
AM/PM indicator.
Procedure:
Connection:
PORT
LCD_D4 P0.19
LCD_D5 P0.20
LCD_D6 P0.21
LCD_D7 P0.22
LCD_EN P0.18
LCD_RW P0.17
LCD_RS P0.16
#include <lpc214x.h>
#include <stdio.h>
#define RS 0x10000
#define RW 0x20000
#define EN 0x40000
#define SS 0 // Set seconds
#define MN 8 // Set Minutes
9
{
int i;
for(i=0;i<4;i++)
{
IOCLR0 = 0xF << 19; //IOCLR 0/1
lcd_cmd(cmd[i]);
delay(15);
}
}
void lcd_data (unsigned char data)
{
IOSET0 |= RS; //0x1000; //RS
IOCLR0 |= RW; //0x2000; //RW
LCD4_Convert(data);
}
void LCD4_Convert(unsigned char c)
{ if(c & 0x80) IOSET0 = 1 << 22; else IOCLR0 = 1 << 22;
if(c & 0x40) IOSET0 = 1 << 21; else IOCLR0 = 1 << 21;
if(c & 0x20) IOSET0 = 1 << 20; else IOCLR0 = 1 << 20;
if(c & 0x10) IOSET0 = 1 << 19; else IOCLR0 = 1 << 19;
IOSET0 = EN;
delay(8);
IOCLR0 = EN;
if(c & 0x08) IOSET0 = 1 << 22; else IOCLR0 = 1 << 22;
if(c & 0x04) IOSET0 = 1 << 21; else IOCLR0 = 1 << 21;
if(c & 0x02) IOSET0 = 1 << 20; else IOCLR0 = 1 << 20;
if(c & 0x01) IOSET0 = 1 << 19; else IOCLR0 = 1 << 19;
IOSET0 = EN;
delay(8);
11
IOCLR0 = EN;
}
void lcd_display (void)
{
char i; /* first line message */
lcd_cmd(0x80);
delay(15); i=0;
while(msg[i]!='\0')
{
delay(5);
lcd_data(msg[i]);
i++;
}
delay(15); /* second line message */
lcd_cmd(0x90);
delay(15); i=0;
while(msg1[i]!='\0')
{
delay(5);
lcd_data(msg1[i]);
i++;
}
delay(15);
}
void init_RTC(void)
{
PCONP |= 0x00000200;
12
CCR = 0x00000002;
CIIR = 0x00000000;
AMR = 0x000000FF;
ILR = 0x00000003;
CCR = 0x00000011;
}
void set_RTC(void)
{
CCR = 0x00000002;
YEAR = YY;
MONTH = MM;
DOM = DD;
HOUR = HH;
MIN = MN;
SEC = SS;
CCR = 0x00000011;
}
void number_lcd(int num) // function to display 2 digit decimal value to lcd
{
lcd_data( (num / 10) + 0x30);
lcd_data( (num % 10) + 0x30);
}
void delay_us (unsigned int count)
{
volatile unsigned int j,k;
for (j=0;j<count;j++)
{
for (k=0;k<10;k++)
{
13
asm
{
nop;
}
}
}
}
void delay_ms(unsigned int count)
{
volatile unsigned int j,k;
for (j=0;j<count;j++)
{
for (k=0;k<6000;k++)
{
asm
{
nop;
nop;
}
}
}
}
int main(void)
{
init_RTC();
PINSEL1 = 0;
IODIR0 = 0xFF << 16;
lcd_initialize();
lcd_display();
14
while(1)
{
// cmd_lcd(0xc4);
lcd_cmd(0xc4);
number_lcd(HOUR);
lcd_data(':');
number_lcd(MIN);
lcd_data(':');
number_lcd(SEC);
delay_ms(500);
}
Result