0% found this document useful (0 votes)
14 views118 pages

Record ESID With Content Beyond White Removed

Uploaded by

siranjeevi22ec
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views118 pages

Record ESID With Content Beyond White Removed

Uploaded by

siranjeevi22ec
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 118

EXP NO:

BASIC ARITHMETIC AND LOGICAL OPERATIONS USING 8051

DATE: A. 8 BIT ADDITION

AIM:

To write a pro gram to add two 8-bit numbers using 8051 microcontrollers.

ALGORITHM:

1. Clear Pro gram Status Word.


2. Select Register b ank b y giving proper values to RS1 & RS0 of PSW.
3. Load accumulator A with any desired 8-bit data.
4. Load the register R 0 with the second 8- bit data.
5. Add these two 8-bit numbers.
6. Store the result.
7. Stop the pro gram.

3
FLOW CHAR T:
Start

Clear PS W

Select Register

Load A and R0 with 8 – bit da ta‟s

ADD A & R0

Store the sum

Stop

4
PROGRAM:

Label Address Mnemonics Hex code Comments


Opcode Operand
START: 4100 CLR C C3 Clear CY Flag
4101 MOV A,#0A 74 0A Get the data1 in Accumulator
4103 ADDC A,#10 34 10 Add the data1 with data 2
4105 MOV DPTR,#4500 90 45 00 Initialize the memor y location
4108 MOVX @DPTR,A F0 Store the result in memory location
L1 4109 SJMP L1 80 FE Stop the pro gram

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

Clear Ca rry Flag

Get 1‟st Operation in ACCR

Subtract the 2‟nd opera nd from


ACCR

IS
CF=1

Incre ment the Borrow Register

Store Result in Memo ry

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:

1. Clear the carr y fla g.


2. Initialize the register for borrow.
3. Get the first operand into the accumulator.
4. Subtract the second operand from the accumulator.
5. If a borrow results increment the carr y register.
6. Store the result in memory.

PROGRAM:

Label Address Mnemonics Hex code Comments


Opcode Operand
START: 4100 CLR C C3 Clear CY Flag
4101 MOV A,#0A 74 0A Get the data1 in Accumulator
4103 SUBB A,#05 94 05 Subtract data2 from data1
4105 MOV DPTR,#4500 90 45 00 Initialize memor y locatio n
4108 MOVX @DPTR,A F0 Store the difference in memor y location
L1 4109 SJMP L1 80 FE Stop the pro gram

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

Get Multiplier in ACCR

Get Multiplicand in B Register

Multiply A with B

Store Result in Memory

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:

1. Get the multiplier in the accumulator.


2. Get the multiplicand in the B register.
3. Multiply A with B.
Store the product in memory
PROGRAM:

Label Address Mnemonics Hex code Comments


Opcode Operand
START: 4100 MOV A,#05 74 05 Store data1 in accumulator
4102 MOV B,#03 75 F0 03 Store data2 in B register
4105 MUL AB A4 Multiply both
4106 MOV DPTR,#4500 90 45 00 Initialize memor y locatio n
4109 MOVX @DPTR,A F0 Store lower order result
410A INC DPTR A3 Go to next memory location
410B MOV A,B E5 F0 Store higher o rder result
410D MOVX @DPTR,A F0
L1 410E SJMP L1 80 FE Stop the pro gram

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

Get Dividend in ACCR

Get Divisor in B Register

Divide A by B

Store Quotient & Rema inder in


Memo ry

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:

1. Get the Dividend in the accumulator.


2. Get the Divisor in the B register.
3. Divide A b y B.
Store the Q uotient and Remainder in memor y

PROGRAM:

Label Address Mnemonics Hex code Comments


Opcode Operand
START: 4100 MOV A,#15 74 15 Store data1 in accumulator
4102 MOV B,#03 75 F0 03 Store data2 in B register
4105 DIV AB 84 Divide
4106 MOV DPTR,#4500 90 45 00 Initialize memor y locatio n
4109 MOVX @DPTR,A F0 Store remainder
410A INC DPTR A3 Go to next memory location
410B MOV A,B E5 F0 Store quotient
410D MOVX @DPTR,A F0
L1 410E SJMP L1 80 FE Stop the pro gram

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

Get the first data

Get the second data

Logically AND first data with


second data

Initia lize the memo ry

Move the resultant value into memo ry

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.

APPARATUS REQUIR ED:


8051 microcontroller kit

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:

Label Address Mnemonics Hex code Comments


Opcode Operand
START 4100 MOV A,#87 74 87
4102 ANL A,#7E 54 7E
4104 MOV DPTR,#4500 90 45 00
4107 MOVX @DPTR,A F0
L1 4108 SJMP L1 80 FE

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

Get the input value

Get the complement

Initialize the data pointe r value

Move the data to data pointer

Incre ment the da ta value and


data point memo ry

Move the value to the memo ry

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.

a) 1’s and 2’s co mplement


PROGRAM:
Label Address Mnemonics Hex code Comments
Opcode Operand
4100 MOV A, #02 74, 02 Get the initial value
4102 CPL A F4 Complement the value
4103 MOV DPTR, # 4200 90, 42, 00 Initialize the memor y
4106 MOVX @ DPTR, A F0 Move the data to memory
4107 INC A 04 Increment Accumula tor
4108 INC DPTR A3 Increment the memor y
4109 MOVX @ DPTR, A F0 Move the value to memory
ECE: 410A SJMP ECE 80, FE Continue 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: -

(i) Start the pro gram


(ii) Make CS=0 and send a low to high pulse to W R pin to start the conversion n.
(iii ) Now keep checking the INTR pin. INTR will be 1 if conversion is not finished and INTR will
be 0 if conversion is finis hed.
(i v) If conversion is not finished (IN TR=1) , poll until it is finished.
(v) If conversion is finished (INTR=0), go to the next step.
(v i) Make CS=0 and send a high to low pulse to RD pin to read the data from the ADC
(v ii) Stop the pro gram
PROCEDURE:

(i) Place jumper J2 in C position


(ii) Place jumper J5 in A position
(iii ) Enter and execute the pro gram
(i v) Vary the analo g input (us ing trim pot) and view the corresponding digital value
in LED displa y,

20
FLOWCHART:

START

Make CS=0

keep checking the INTR pin

If conversion is not finis hed


(INTR=1)

If conversion is finished (INTR=0)

STOP

21
PROGRAM:

Label Address Mnemonics Comments


1000 MOV P1,#11111111B ; initiates P1 as the input port
MAIN : CLR P3.7 ; makes CS=0
1003 SETB P3.6 ;makes RD high
CLR P3.5
1005 ;makes W R low
SETB P3.5
WAIT: 1008 JB P3.4, W AIT ;low to high pulse to WR for starting
CLR P3.7 ;polls until IN TR=0
CLR P3.6 conversion
MOV A,P1 ;ensures CS=0
100A CPL A MOV ;high to low pulse to RD for reading
P0,A SJMP the data from ADC
MAIN END ;moves the digital data to
accumulator
;complements the digital data
100D ;outputs the data to P0 for the LEDs
;J ump to program
100F ;End

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:

S.No Hardware & Software Requirements Quantity


1 8051 Trainer K it 1No
2 Power C hord 1No

3 DAC interfacing board 1 No


4 CRO 1 No

24
CIRCUIT DIAGRAM :

WAVEFORMS:

25
PROGRAM FOR SQUAR E WAVE:

ADDRESS LAB EL MNEMONICS OPCODE COMMENTS


4100 MOV DP TR, # E0C0 90,FF,C8 Move the immediate
Data EOCO
4103 ST A RT MOV A, # 00 74,00 Initialize the Accumulator
4105 MOVX @ DP TR, A F0 To zero
Long call the d ela y
4106 LCALL DELAY 12,41,12 Move the content of
4109 MOV A, # FF 74,FF Accumulator to FF
Long call dela y
410B MOVX @ DP TR, A F0
Long jump to start
410C LCALL DELAY 12,41,12 Move the 05 data
410F LJMP S TART 02,41,03 To R register
Decrement J ump NON zero
4112 DELAY MOV R1, # 05 79,05 Return to main pro gram
4114 LOOP MOV R2, # FF 74,FF Short jump to start

4116 HE R E DJNZ R2, HERE DA,FE


4118 DJNZ R1, LOOP D9,FA
411A RET 22
411C SZMP S TART 80,E3

OBSERVATION:

AMPLITUDE TIME PERIOD

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:

1. Initialize TMOD with 20H


2. Set the values for TCON and SCON
3. Set the input address to DPTR
4. Based on the bit value on SCON store the data in SBUF
5. Increment DPTR and check for the loop end value

29
FLOW CHAR T:
Start

Clear PS W

Select Register

Load A and R0 with 8 – bit da ta‟s

ADD A & R0

Store the sum

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

Algorithm for Transmitter:


1. Initialize TMOD with 20H
2. Set the values for TCON and SCON
3. Set the input address to DPTR
4. Based on the bit value on SCON store the data in SBUF and move the data to register
„A‟.
5. Increment DPTR and check for the loop end value
PROGRAM FOR TRANSMITTER:
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 Input
4112 RELOAD 7D 05 MOV R5, #05H
4114 REPEAT E0 MOVX A, @DPTR
4115 F5 99 MOV SBUF, A
4117 CHECK 30 99 FD JNB SCON.1, CHECK
411A C2 99 CLR SCON.1
411C A3 INC DPTR
411D B4 3F F2 CJNE A, #3FH,
RELOAD
4120 DD F2 DJNZ R5, REPEAT
4122 E4 CLR A

31
4123 12 00 20 LCALL 0020H

SAMPLE INPUT AND OUTPUT:


Sl.No Transmitter Input (Hex Values) Receiver Output (Hex Values)
Input Address 4500
1 00 00

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:

 Full- featured source code editor



 Device database for configuring the developme nt tool setting

 Project manager for creating and maintaining your projects 

 Integrated mak e facility for assembling, compiling, and linking your embedded applications 

 Dialogs for all d evelopment tool settings 

 True integrated source- level Debugger with high-speed CPU and peripheral s imulator

 Advanced GDI interface for so ftware debugging in the target hardware and for connection
to Keil ULINK

 Flash pro gramming utility fo r downloading the application pro gram into Flash ROM

 Links to development tools manuals, device datasheets & user‟s guides

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:

1. Double click on Keil µvision 4.exe file.


2. Then click on Next.
3. Tick the check box towards to license agreements and click Next.
4. Select Destination folder and click Next.
5. Fill the necessar y text boxes and click Next.
6. Finally click on Finish.

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”.

STEP 2 : Go to the “Pro ject” and click on “New µ vision Project ”

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.

STEP 6 : W ithin the NXP founded b y P hilips select LPC2148.

36
STEP 7 : A dd Startup file to the project by c licking “Yes”.

STEP 8 : Next go to “File” and click “Ne w”.

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.

STEP 10 : Can be start to write *.asm/c code on the editor window.

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.

STEP 19: Then go to Listing menu and select C preprocessor Listing.

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:

Installation steps are given below:

1. Double click on Flas h Magic.exe.


2. Then click on Next.
3. Next accept the agreement and click on Next.
4. Select the destination folders and click on Next then Install.
5. Finally click on Finis h.

Programming ng wi th communi cati on port (COM1):

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:

Installation Procedure for USB Cable Driver:

The installation steps are given below:

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.

STEP 5: Then right click on M y Computer and select manage.

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.

STEP 7 : Repeat the S TEP from 22 to 28

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.

1. The device LPC2148 from NXP.


2. 12.00 MHz Crystal Oscillator Device speed.
3. 32.768 KHz crystal oscillator for RTC clock.
4. VREF jumper setting for ADC external Voltage reference.
5. 5V Red LED indic ation.
6. 3V3 Green LED indication.
7. Batter y fo r RTC back up running.
8. Power ON/OFF switch.
9. 9VDC input Power Jack.
10. Input switch for externa l interrupt.
Optional: can be use for ISP manual P ro gramming Mode.
11. Input switch for Reset the device.
12. ART1 connectivity.

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

F RC CONNE CTION DETAILS:

S.No Expe rime nt FRC1 FRC2 FRC3 FRC4 FRC5


ADC
1 ADC L CD
(Change mode )
2 DAC DAC
3 LED LED
ADC
4 PWM LED
(Change mode )
5 RTC L CD
6 EPROM K eyp ad L CD EP R O M
7 Inte rrupt LED
Ste ppe r
8 Ste ppe r Motor
M ot o r
ADC
9 Te mpe rature Se nsor L CD
(Change mode )
10 Zigbee Trans mitte r K eyp ad L CD Zigb ee
11 Zigbee Receive r LED Zigb ee
S even
12 Seve n Segme nt Dis play
Segme nt
Toogle
13 Switch with LED LED
Switch
Toogle DC
14 DC Motor
Switch M ot o r
15 LCD L CD
16 Ke ypad K eyp ad L CD

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.

HARDWARE & S OFTWARE TOOLS REQUIRED:

S.No Hardware & Software Requirements Quantit y


1 ARM P rocessor board 1
2 USB/FRC Connector few
3 LED Module 1
4 Power S upply adaptor (5V, DC) 1
5 Keil & flash magic Software 1

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

#include <lpc214 x.h>


int i;
int main()
{
IODIR0=(1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1 <<5)|(1<<6)|(1<<7 );
while(1)
{ IOSET0= (1<<0);
for(i=0;i<120000;i++);
IOCLR0=(1<<0 );
for(i=0;i<120000;i++);
IOSET0= (1<<1);
for(i=0;i<120000;i++);
IOCLR0=(1<<1);
for(i=0;i<120000;i++ );
IOSET0= (1<<2);
for(i=0;i<120000;i++);
IOCLR0=(1<<2);
for(i=0;i<120000;i++);
IOSET0= (1<<3);
for(i=0;i<120000;i++);
IOCLR0=(1<<3);
for(i=0;i<120000 ;i++);
IOSET0= (1<<4);
for(i=0;i<120000;i++);
IOCLR0=(1<<4);
for(i=0;i<120000;i++);
IOSET0=(1<<5);
for(i=0;i<120000;i++);
IOCLR0=(1<<5);
for(i=0;i<120000;i++);
IOSET0= (1<<6);
for(i=0;i<120000;i++);
IOCLR0=(1<<6);
for(i=0;i<120000;i++);
IOSET0=(1<<7);
for(i=0;i<120000;i++);
IOCLR0=(1<<7);
for(i=0;i<120000;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.

HARDWARE & S OFTWARE TOOLS REQUIRED:

S.No Hardware & Software Requirements Quantit y


1 ARM Processor board 1
2 USB/FRC Connector few
3 LED Module 1
4 Power S upply adap tor (5V, DC) 1
5 Keil & flash magic So ftware 1

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.

HARDWARE & S OFTWARE TOOLS REQUIRED:

S.No Hardware & Software Re quire me nts Quantit y

1 ARM P rocessor board 1


2 USB/FRC Connector few
3 LCD Module 1
4 Power S upply adaptor (5V, DC) 1
5 Keil & flash magic Software 1
6 Matrix Keypad Module 1

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

KEYB OARD INTERFACING:

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

executed successfully (LPC2148) processor


EXP NO:
INTERFACING OF STEPPER MOTOR
DATE

AIM:
To write and e xecute the pr ogram f or Stepper Motor w ith ARM7 (LPC2148) proce ssor.

HARDWARE & S OFTWARE TOOLS REQUIRED:

S.No Hardware & Software Requirements Quantit y


1 ARM P rocessor board 1
2 USB/FRC Connector few
3 Stepper Motor Module 1
4 Power S upply adaptor (5V, DC) 1
5 Keil & flash magic So ftware 1

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

STEPPER MOTOR: (FOR WARD ROTATION)


CIRCUIT DI AGRAM :

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

STEPPER MOTOR: (REVERS E ROTATION)


CIRCUIT DI AGRAM :

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

successfully (LPC2148) processor

85
EXP NO: INTERFACING ADC AND DAC
DATE:

AIM:
To write and execute the program for Interfacing ADC and DAC with ARM LPC2148
microcontroller

EQUIPMENT AND COMPONENTS REQUIRED:

1. PC with supporting software Keil.C


2. Developer Kit LPC2148
3. Power card & connecters

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.

Fig: ADC interfacing

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

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[] = {" ADC Example 1 "};
unsigned char msg1[]= {"~~~~~~~~~~~~~~~~"};

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);

}
}

Digital to Analog Converter

Theory:

 Single 10-bit DAC provides variable analog output (LPC2142/44/46/48 only).

 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:

1. Compile the program using KEIL software.


2. Burn the HEX code into the microcontroller using FLASH MAGIC.
3. Using the programming and reset switch execute the program.

Connection:

VIN (+) - P0.25

Program: Digital to Analog converter

#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();
}

int main (void)


{
unsigned int i = 0;
DacInit(); //Initialize the DAC
IODIR1|=0xFFFF0010; //Clear all the LEDs on board
IOPIN1&=~(0xFFFF0000);
while (1)
{
for(i=0;i<1023;i++)
{
DacOut(i);
i=i+15;
}
for(;i>0;i--)
{
DacOut(i);
i=i-15;
}
}
}
void DacInit( void )

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:

To apply the knowled ge, the y gained in doing the experiments.

Team constitution:

A team size ma y be from 3 to 4 students.

Guidelines :

1.Students shall from a group and can do their mini project.

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.

5.If required students need to present their wo rk as presentation.

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

Buttons & S witches

Screws & Bolts

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

Cables and Connectors

Diodes

PCB and Breadboards

LED

Transformer/Adapter

Push Buttons

Switch 100
IC

IC Sockets

Connector S haft

Bed Frame

Tubes

Screws & Joints

Supporting Frame

Software Specifications

Progra mming Language :

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

Cables and Connectors

Diodes

PCB and Breadboards

LED

Transformer/Adapter

Push Buttons

Switch

IC

IC Sockets
Software Specif ications

Linux

Programming Language: P ython

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

Reference: https ://www.researchgate.net/publication/367087623_Sma rt_Door_Locking_System_Using_ IoT

105
1

Experi ment No: …………….


Da te: ……. /……. /……………

Interfacing temperature sensor.

AIM: To interfacing temperature sensor using ARM7 LPC2148 microcontroller.

EQUIPMENT AND COMPONENTS REQUIRED:

1. PC with supporting software Keil.C


2. Developer Kit LPC2148
3. Power card & connecters

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:

1. Compile the program using KEIL software.


2. Burn the HEX code into the microcontroller using FLASH MAGIC.
3. Using the programming and reset switch execute the program.

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

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 |= 0x04000000; //Configure P0.28 as AD0.2 ->PIN 13
AD0CR = 0x00210F04; // bust mode on
// AD0CR = 0x00200F04;
/*
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
//Delay(100000);
do
{
adc_data = AD0DR2; // AD0 -> Channel_2 -> Data Register.

}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)
6

{
unsigned int adc_data;
unsigned char ones,tens,hundreds,thousands;

PINSEL0 = 0x00000000; // P0.0 ... P0.15 --> IS GPIO


PINSEL1 = 0x040fff00; // P0.16 ...P0.31 --> AD0.2 (PIN-14) & LCD

PINSEL2 = 0x00000000; // P1.16 ...P1.31 --> IS GPIO


IODIR0 = 0Xffffffff; // P0.0 .... P0.31 --> O/P --> 1 MEANS O/P ; O MEANS I/P
IODIR1 = 0x00000000; // P0.31 to P0.28 -> 0/P ; -> OTHERS PINS ARE -> I/P
lcd_initialize();
lcd_display();
ADC_Init();
delay(1000);
while(1)
{
// 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);

}
}

RESULT:
7

Experi ment No: …………….


Da te: ……. /……. /……………

Interfacing Real Time Clock and Serial Port

AIM: To interfacing Real time clock and serial communication using ARM7 LPC2148
microcontroller.

EQUIPMENT AND COMPONENTS REQUIRED:


1. PC with supporting software Keil.C
2. Developer Kit LPC2148
3. Power card & connecters
Theory:

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.

PIN DETAILS : connect J6 & J10 us ing 10 pin FRC cable


8

LCD PO RT PIN C O NFIGURATIO N


LCD_D4 P 0.19 uC P IN -> 54
LCD_D5 P 0.20 uC P IN -> 55
LCD_D6 P 0.21 uC P IN -> 1
LCD_D7 P 0.22 uC P IN -> 2
LCD_EN P 0.18 uC P IN -> 53
LCD_RW P 0.17 uC P IN -> 47
LCD_RS P 0.16 uC P IN -> 46

Procedure:

1. Compile the program using KEIL software.


2. Burn the HEX code into the microcontroller using FLASH MAGIC.
3. Using the programming and reset switch execute the program.

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

Program: RTC interfacing with LPC2148

#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

#define HH 16 // Set Hour


#define DD 15 // Set Date
#define MM 8 // Set Month
#define YY 2014// Set Year
void lcd_cmd (unsigned char);
void lcd_data (unsigned char);
void lcd_initialize (void);
void lcd_display (void);
void LCD4_Convert(unsigned char);
void delay_ms(unsigned int count);
void delay_us(unsigned int count);
void init_RTC(void);
void set_RTC(void);

const unsigned char cmd[4] = {0x28,0x0c,0x06,0x01};


unsigned char msg[] = {" Real time clock"};
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);
}
void lcd_initialize(void)
10

{
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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy