Professional Documents
Culture Documents
Advanced
Microcontroller
(EC16406)
Semester V
Email: gpmumbai@gpmumbai.ac.in
LIST OF EXPERIMENTS AND PROGRESSIVE ASSESSMENT
ACADEMIC YEAR 20.... 20
.
principal
Experiment No-1
Objective:
Learning outcome:
Apparatus:
Theory:
Arithmetic instructions are very basic and frequently used in your ARM
programming. Here is a table that demonstrates the usage of the ARM
processor's arithmetic instructions with examples.
Program
AREA RESET, DATA, READONLY
ENTRY
STOP B STOP
END
ENTRY
STOP B STOP
END
References:
1. http://arantxa.ii.uam.es/~gdrivera/sed/docs/ARMBook.pdf
2. http://courses.cs.tamu.edu/rabi/cpsc617/resources/ARM%20Lab
%20Mannual.pdf
3. https://blueskytechi.blogspot.com/2017/02/basic-arm-lpc218-assembly-
programs.html
Questions:
1. State the types of arithmetic instructions.
2. Explain the addition instruction with example.
3. Explain the subtraction instruction with example.
4. Explain the multiplication instruction with example.
5. Explain the division instruction with example.
2 4 4 10 Sign
Experiment No-2
Aim: Simulate soft delay in assembly language.
Objective:
Learning Outcome:
Apparatus:
Theory
C2148 Timer/Counter
Timer is a specific type of clock which is used to measure the time intervals. It
provides/measures the time interval by counting the input clocks. Every timer
needs a clock to work. We can provide/measure any time interval if we know the
time of one clock period.
e.g. lets say we have 1 kHz input clock frequency for the timer unit, then,
We can calculate time of one clock period as,
Time of one clock period = 1 / clock frequency
= 1 / 1000
= 1milliSecond
i.e. 1000 clock counts provide a time interval of 1 second, and hence we can
provide 1 second delay with these 1000 clock counts.
Now, once we have the time period of one clock, we can use this time period to
generate delays that are integer multiples of it. We can also use the time period
to measure the time interval between specific events of a received signal.
Counter is the unit which is similar to Timers but works in a reverse manner to
the timers. It counts the external events or we can say external clock ticks. It is
mostly used to measure frequency from the counts of clock ticks.
e.g. Lets say Counter is measuring counts of external clock ticks, and frequently
its count reaches 2000 in one second i.e. 2000 clock ticks/second.
Then, we can calculate external clock frequency as,
External clock frequency = count of clocks / one second
= 2000 / 1
= 2 kHz
Hence, we can measure such external clock/event frequencies using counter.
Example
Lets write a code for generating a delay of 100msec and blink LEDs using LPC2148
Timer.
PCLK = 30MHz
Hence, we will load T0PR with a value 29, so that the TC will increment after every
30 PCLK rising edges.
30MHz/30 = 1MHz, which gives 1µsec time.
To get 100msec time, we will have to load T0MR with 100000 (1 µsec * 1000 =
1msec, 1msec * 100 = 100msec. Hence, 1000 * 100 = 100000)
This will give us a delay of 100msec.
Here we are using timer interrupt MR0. On each compare match between MR0
and TC, the ISR for Timer0 will be executed where we are toggling the pin
connected to the LED.
ALGORITHM:
Step 2: Set the port pin value as 1 to produce logic 1 level output.
Step 4: Clear the port pin value as 0 to produce logic 0 level output.
PROCEDURE:
➢ Compile, Debug & Simulate the above code in IAR, and see the output in
register view window. ➢ Follow to Steps given below to see/verify the output:
General Options: Target >> Processor variant >> Core >> ARM7TDMI
b. C:\ProgramFiles\IARSystems\Embedded Workbench
5.40\arm\config\linker\NXP\LPC2148.icf
c. After doing above setting click OK to save/ exit from the option window.
a. Project >> Rebuild all (if you get 0 errors & 0 warnings then only got to next
step.)
b. Project >> Debug without Downloading.( Here debugging will start &
Disassembly window will open.) Open the other required window also (e.g.
Register Window) for visualizing the output. c. Project >> Make & Restart
Debugger. (Here the debugging process is ready to check the output by step by
step execution of the code).
Program:
#include <lpc214x.h>
int main(void)
while (1)
delay_ms (1000);
//return 0;
}
void initTimer0(void)
void initClocks(void)
PLLOFEED = 0XSS;
PLLOFEED = 0X55;
Result:
2. https://www.exploreembedded.com/wiki/LPC2148_Timers
Questions:
Experiment No-3
To develop and verify the interfacing LED with ARM DEVELOPMENT KIT
microcontroller using embedded c program.
Objective:
Learning outcome:
1. Write the LED blinking program.
Apparatus:
Theory: GPIO lines of any microcontroller can be used mainly to perform two
things. One is to generate digital signal and second one is to read a digital signal.
In LPC2148 microcontroller most of port pins are multiplexed, this means they re
allowed to provide multiple functions. Configuring GPIO to use different function
is out of the scope of this tutorial. Just keep in mind that by default: all functional
pins i.e. Pins on PORT0 and PORT1 are set to be as GPIO so we can directly use
them in our example project.
Here weve listed some GPIO related registers and its functions. We need to
replace x with the port number to get the register name. Say for example:
IOxPIN register becomes IO0PIN when used for PORT0 and IO1PIN when used for
PORT1. These all register names defined in the header file lpc2148.h Register
names defined in the header file are nothing but a pointer GPIO Related Registers
In LPC2148
IOxPIN: This register can be used to read or write values directly to the pins.
Regardless of the direction set for the particular pins. It gives the current state of
GPIO pin when read.
IOxDIR: This is the GPIO direction control register. Setting a bit to 0 in this
register will configure the corresponding pin to be used as input while setting it to
1 will configure it as output.
IOxSET: This register can be used to drive an output configured pin to logic 1 i.e.
HIGH. Writing zero does not have any effect and hence it can t be used to drive a
pin to Logic 0 i.e. LOW. For driving pins LOW IOxCLR is used which is explained as
below:
IOxCLR: This register can be used to drive an output configured pin to logic 0 i.e.
LOW. Writing zero does not have any effect and hence it can t be used to drive a
pin to Logic 1. Which holds the address of actual register in LPC2148? ( x
represent port number).
Program
#include <lpc214x.h>
int delay;
int main(void)
While(1)
Result:
Thus the interfacing of LED with ARM DEVELOPMENT KIT was done by using
embedded C program.
References:
1. https://www.instructables.com/id/Blinking-LED-Using-ARM7-LPC2148-
Microcontroller/
2. https://binaryupdates.com/blink-led-with-arm7-lpc2148/
3. https://electrosome.com/blinking-led-using-lpc2148-arm-microcontroller/
2 4 4 10 Sign
Experiment No-4
Objective:
Learning outcome:
Apparatus:
Sr. No. Apparatus Range Quantity
1. ARM Development Kit LPC2148 1
Theory:
Program
#include <lpc214x.h>
int delay;
int main(void)
{
PINSEL0 =0x00000000; //GPIO
IO0DIR = 0x000000f0; //Configure Pin P0 as Output
while(l)
{
IOPIN0= IOPIN0^0x000000f0;
for (delay=0); delay<=5; delay++);
}
}
Result:
Thus I/O port configuration of ARM processor has done successfully.
References:
2 4 4 10 Sign
Experiment No-5
Objective:
Learning outcome:
Apparatus:
Theory: A seven segment display is the most basic electronic display device that
can display digits from 0-9. The most common configuration has an array of eight
LEDs arranged in a special pattern to display these digits. They are laid out as a
squared-off figure 8.
Interfacing Seven Segment Display
Fig. 1 shows how to interface the seven segments with microcontroller. A seven
segment is generally available in ten pin package. While eight pins correspond to
the eight LEDs, the remaining two pins (at middle) are common and internally
shorted. These segments come in two configurations, namely, Common cathode
(CC) and Common anode (CA).
We now want to display a four digit number in LPC2148 Advanced Development
Board by using seven segment displays. The seven segment display is connected
with LPC2138 controller.
Pin Assignment
P0.0-a
P0.1-b
P0.2-c
P0.3-d
P0.4-e
P0.5-f
P0.6-g
Program
#include <lpc2114x.h>
int delay;
int i;
unsigned char a[ ]=[0x3f,0x06,0x5b,0xif,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
int main(void)
{
PINSEL0 =0x00000000; //GPIO
IOODIR = 0xffffffff; //Configure Pin P0 as Output
while(l)
{
For(i-0;1<-9;1++)
{
IO0SET = a(i); // TURN ON LED
for (delay-0; delay<-5; delay++);
IO0CLR = a(I);. //TURN LED OFF
For (delay-0; delay<-5; delay++);
}
}
}
Result:
Thus seven segment interfacing with ARM DEVELOPMENT KIT processor has been
done successfully.
References:
1. LPC 214x User manual (UM10139).
2. https://circuitdigest.com/microcontroller-projects/interfacing-7-segment-
display-with-arm7-lpc2148-development-board
3. ARM System Developers Guide Designing and Optimizing System
Software- Andrew Sloss, Dominic Symes, Chris Wright.
2 4 4 10 Sign
Experiment No-6
AIM: To write a program for realizing the timer peripheral in ARM by polling
method and verify the output using LPC2148 kit.
Objective:
Learning outcome:
Apparatus:
Theory:
Timer is a specific type of clock which is used to measure the time intervals. It
provides/measures the time interval by counting the input clocks. Every timer
needs a clock to work. We can provide/measure any time interval if we know the
time of one clock period.
e.g. lets say we have 1 kHz input clock frequency for the timer unit, then,
We can calculate time of one clock period as,
Time of one clock period = 1 / clock frequency
= 1 / 1000
= 1milliSecond
i.e. 1000 clock counts provide a time interval of 1 second, and hence we can
provide 1 second delay with these 1000 clock counts.
There are many applications for which we can use these timers and counters in
real world.
LPC2148 Timer& Counter
LPC2148 has two 32-bit timers/counters: Timer0/Counter0 & Timer1/Counter1.
LPC2148 Timer has input of peripheral clock (PCLK) or an external clock. It counts
the clock from either of these clock sources for its operation.
LPC2148 Timer/Counter can generate an interrupt signal at specified time
value.
LPC2148 has match registers that contain count value which is continuously
compared with the value of the Timer register. When the value in the Timer
register matches the value in the match register, specific action (timer
reset, or timer stop, or generate an interrupt) is taken.
Also, LPC2148 has capture registers which can be used to capture the timer
value on a specific external event on capture pins. For information about
LPC2148 capture operation refer Input Capture Mode.
Here, we will see how to use timer 0 registers to configure the timer 0.
Timer 1 can be used in a similar manner by using its corresponding
registers.
Timer0 Registers
1. T0IR (Timer0 Interrupt Register)
It is an 8-bit read-write register.
Consists of 4 bits for match register interrupts and 4 bits for compare
register interrupts.
Writing a 1 to any bit of this register will reset that interrupt. Writing a 0
has no effect.
3. T0CTCR (Timer0 Counter Control Register)
It is an 8-bit read-write register.
Note : If counter mode is selected for a certain capture (CAP) input, then
the corresponding 3 bits in the T0CCR register must be programmed as
000. Capture and/or interrupt can be selected for other CAP inputs.
1. T0TC (Timer0 Timer Counter)
· It is a 32-bit timer counter.
· It is incremented when the Prescale Counter (PC) reaches its maximum value
held by Prescaler Register (PR).
Note : When TC overflow occurs, it does not generate any overflow interrupt.
Alternatively, we can use match register to detect overflow event if needed.
4. T0PR (Timer0 Prescale Register)
It is a 32-bit register.
It holds the maximum value of the Prescale Counter.
5. T0PC (Timer0 Prescale Counter Register)
It is a 32-bit register.
It controls the division of PCLK by some constant value before it is applied
to the Timer Counter.
6. T0MR0-T0MR3 (Timer0 Match Registers)
These are 32-bit registers.
The values stored in these registers are continuously compared with the
Timer Counter value.
When the two values are equal, the timer can be reset or stop or an
interrupt may be generated. The T0MCR controls what action should be
taken on a match.
7. T0MCR (Timer0 Match Control Register)
It is a 16-bit register.
It controls what action is to be taken on a match between the Match
Registers and Timer Counter.
T0MCR (Timer0 Match Control Register)
Bit 0 MR0I (Match register 0 interrupt)
0 = This interrupt is disabled
1 = Interrupt on MR0. An interrupt is generated when MR0 matches the
value in TC (Timer Counter)
Bit 1 MR0R (Match register 0 reset)
0 = This feature is disabled
1 = Reset on MR0. The TC (Timer Counter) will be reset if MR0 matches it
MR1, MR2 and MR3 bits function in the same manner as MR0 bits.
ALGORITHM:
Step 1: Start
Step 2: Initialize timer registers.
Step 3: Set the prescale register and match register values.
Step 4: Enable the Timer operation.
Step 5: Output will be displayed in LPC2148 kit.
Step 6: Stop.
PROCEDURE:
➢ Compile, Debug & Simulate the above code in IAR, and see the output in
register view window. ➢ Follow to Steps given below to see/verify the output :
Step-1: Open the IAR workspace. Step-2: Go to project >> option and do the
following settings: General Options: Target >> Processor variant >> Core >>
ARM7TDMI S.
a. Output Converter: Output >> Generate additional output: (Output format >>
Intel extended) and (Output file >> Override default >> project_name.hex)
b.Linker >> Linker configurations file,and browse/provide path for the linker file
as
follows:C:\ProgramFiles\IARSystems\EmbeddedWorkbench5.40\arm\config\linke
r\NXP\LPC2148.icf
c. After doing above setting click OK to save/ exit from the option window. Step-3:
Now execute the following:EXP
a. Project >> Rebuild all (if you get 0 errors & 0 warnings then only got to next
step.)
Step 4: Flash the program in LPC2148 kit.
Step 5: Verify the output using LEDs.
PROGRAM:
#include<nxp\iolpc2148.h>
unsigned int timer_delay = 1000 ;
void timer_init()
{
VPBDIV = 1;
T0PR = 12000*timer_delay ;
T0MR0 = 1;
T0MCR = 2;
T0TCR = 1;
}
int main(void)
{
IO1DIR = 0xFF000000;
timer_init();
while(1)
{
if( T0TC==0 )
{
IO1PIN = 0xF0000000;
while(T0TC==0);
}
else
IO1PIN = 0x0F000000;
}
}
RESULT: Thus the program for realizing the Timer peripheral in ARM by polling
method was written and the output was verified using LPC2148 kit.
References:
Experiment No-7
AIM: To write a program for realizing the timer peripheral in ARM by interrupt
driven method and verify the output using LPC2148 kit.
Objective:
1. To write embedded C program for timer peripheral.
Learning outcome:
Apparatus:
Theory:
Also, LPC2148 has capture registers which can be used to capture the timer
value on a specific external event on capture pins. For information about
LPC2148 capture operation refer Input Capture Mode.
Here, we will see how to use timer 0 registers to configure the timer 0.
Timer 1 can be used in a similar manner by using its corresponding
registers.
Timer0 Registers
2. T0IR (Timer0 Interrupt Register)
Writing a 1 to any bit of this register will reset that interrupt. Writing a 0
has no effect.
3. T0CTCR (Timer0 Counter Control Register)
Note : If counter mode is selected for a certain capture (CAP) input, then
the corresponding 3 bits in the T0CCR register must be programmed as
000. Capture and/or interrupt can be selected for other CAP inputs.
1. T0TC (Timer0 Timer Counter)
· It is a 32-bit timer counter.
· It is incremented when the Prescale Counter (PC) reaches its maximum value
held by Prescaler Register (PR).
Note : When TC overflow occurs, it does not generate any overflow interrupt.
Alternatively, we can use match register to detect overflow event if needed.
4. T0PR (Timer0 Prescale Register)
It is a 32-bit register.
It holds the maximum value of the Prescale Counter.
5. T0PC (Timer0 Prescale Counter Register)
It is a 32-bit register.
It controls the division of PCLK by some constant value before it is applied
to the Timer Counter.
6. T0MR0-T0MR3 (Timer0 Match Registers)
These are 32-bit registers.
The values stored in these registers are continuously compared with the
Timer Counter value.
When the two values are equal, the timer can be reset or stop or an
interrupt may be generated. The T0MCR controls what action should be
taken on a match.
7. T0MCR (Timer0 Match Control Register)
It is a 16-bit register.
It controls what action is to be taken on a match between the Match
Registers and Timer Counter.
MR1, MR2 and MR3 bits function in the same manner as MR0 bits.
ALGORITHM:
Step 1: Start
Step 2: Initialize VIC registers [enable reg, address reg, and control reg]
Step 3: Initialize timer registers.
Step 4: Set the presale register and match register values.
Step 5: Call interrupt service routine.
Step 6: Output will be displayed in LPC2148 kit.
Step 7: Stop.
PROCEDURE:
➢ Compile, Debug & Simulate the above code in IAR, and see the output in
register view window. ➢ Follow to Steps given below to see/verify the output :
Step-1: Open the IAR workspace. Step-2: Go to project >> option and do the
following settings: General Options: Target >> Processor variant >> Core >>
ARM7TDMI S.
a. Output Converter: Output >> Generate additional output: (Output format
>> Intel extended) and ( Output file >> Override default >>
project_name.hex )
b. Linker >> Linker configurations file, and browse/provide path for the linker
file as follows:
C:\ProgramFiles\IARSystems\EmbeddedWorkbench5.40\arm\config\linker\NX
P\LPC2148.icfc. After doing above setting click OK to save/ exit from the option
window.
Step-3: Now execute the following: a. Project >> Rebuild all (if you get 0 errors
& 0 warnings then only got to next step.)
Step 4: Flash the program in LPC2148 kit. Step 5: Verify the output using LEDs.
PROGRAM:
#include<nxp\iolpc2148.h>
unsigned int timer_delay = 1000 ;
void Timer0_Init(void);
__irq void T0ISR(void);
int main(void)
{
VPBDIV = 0x01;
IO1DIR = 0xFF000000;
Timer0_Init();
while(1)
{
IO1PIN = 0x55000000; // LED glow in this pattern (0x55)in default ( when no
interrupt )
}
}
void Timer0_Init(void)
{
T0PR = 12000*timer delay;
T0MR0 = 1;
T0MCR = 3;
T0TCR = 1;
VICIntEnable = 0x10;
VICVectAddr4 = (unsigned) T0ISR;
VICVectCntl4 = 0x20 | 4;
}
__irq void T0ISR(void)
{
long int regVal;
regVal = T0IR;
IO1PIN ^= 0xFF000000;
T0IR = regVal;
VICVectAddr = 0x0;
}
RESULT: Thus the program for realizing the Timer peripheral in ARM by interrupt
driven method was written and the output was verified using LPC2148 kit.
References:
2 4 4 10 Sign
Experiment No-8
Apparatus:
Theory:
STOP bit: This usually is one or two bits in length. It is sent after data bits packet
to indicate the end of frame. Stop bit is always logic high.
Algorithm:
Step 1: Start
Step 2: Initialize UART registers.
Step 3: Transmit the characters through serial port.
Step 4: Receive the characters through serial port.
Step 4: Output will be displayed in monitor.
Step 5: Stop.
PROCEDURE:
➢ Compile, Debug & Simulate the above code in IAR, and see the output in
register view window. ➢ Follow to Steps given below to see/verify the output :
Step-1: Open the IAR workspace.
Step-2: Go to project >> option and do the following settings:
General Options: Target >> Processor variant >> Core >> ARM7TDMI S. a. Output
Converter: Output >> Generate additional output: (Output format >> Intel
extended) and ( Output file >> Override default >> project_name.hex )
b.Linker >> Linker configurations file, and browse/provide path for the linker file
as follows:
C:\ProgramFiles\IARSystems\EmbeddedWorkbench5.40\arm\config\linker\NXP\L
PC2148.icf
c. After doing above setting click OK to save/ exit from the option window.
Step-3: Now execute the following: a. Project >> Rebuild all (if you get 0 errors &
0 warnings then only got to next step.)
Step 4: Flash the program in LPC2148 kit.
➢ Open the Hyper Terminal window as shown below : (Start >> All Programs >>
Accessories >> Communications>> Hyper Terminal) Enter any arbitrary name,
select the correct COM Port and do the following settings: • Bits per second :
9600, Data bits : 8, Parity : None, Stop bit : 1, Flow Control : None ➢ Now
observe the texts/message in hyper terminal, it should display “Enter the Data:
“now press any key on the computer keyboard, you should see the corresponding
letters in the Hyper Terminal. ➢ i.e. When you will press the key the
corresponding data will be received by the LPC2148 board and the same will be
transmitted back by the LPC2148 board to the Hyper Terminal.
Step 5: Verify the output in monitor.
Program:
#include<nxp/iolpc2148.h>
#define f 12000000 // PCLKFREQ ( controller frequency )
void serial_Init(void) // Function to initialise the serial port
{
unsigned int baudrate ;
PINSEL0=0X00000005;
VPBDIV=0X01;
baudrate = (f/(9600*16)); // Baudrate setting (9600 bps)
U0LCR=0X80;
U0DLL = baudrate & 0X00FF;
U0DLM=( baudrate >>8) & 0X00FF;
U0LCR=0X03;
}
char serialrx(void) // Function to receive the data serially
{
unsigned char rxdata;
while(!(U0LSR&0x01));
rxdata=U0RBR;
return rxdata;
}
void serialtx(char txdata) // Function to transmit the data serially
{
while(!(U0LSR&0x20));
U0RBR=txdata;
}
void main()
{
unsigned char msg[]="\r\nEnter the Data : ";
unsigned int i,rxdata;
for(i=0;msg[i]!='\0';i++)
{ serialtx(msg[i]); } // Transmits the enter message to hyperterminal (PC)
}
}
Result: Thus the program for serial transmission and reception of a character in C
by polling method was written and the output was verified.
References:
1. LPC 214x User manual (UM10139)
2. ARM System Developers Guide Designing and Optimizing System
Software- Andrew Sloss, Dominic Symes, Chris Wright
3. https://www.electronicwings.com/arm7/lpc2148-uart0
2 4 4 10 Sign
Experiment No-9
Learning outcome:
Interrupt method.
Apparatus:
Sr. No. Apparatus Range Quantity
1. ARM Development Kit LPC2148 1
Theory:
LPC2148 has two inbuilt UARTs available i.e. UART0&UART1. So, we can connect
two UART enabled devices (GSM module, GPS module, Bluetooth module etc.)
with LPC2148 at a time.
UART0 and UART1 are identical other than the fact that UART1 has modem
interface included.
UART0 Registers
1. U0RBR (UART0 Receive Buffer Register)
It is an 8-bit read only register.
This register contains the received data.
If the character received is less than 8 bits, the unused MSBs are padded
with zeroes.
The Divisor Latch Access Bit (DLAB) in U0LCR must be zero in order to
access the U0RBR. (DLAB = 0)
The Divisor Latch Access Bit (DLAB) in U0LCR must be zero in order to
access theU0THR. (DLAB = 0)
UART0 Divisor Latch holds the value by which the PCLK(Peripheral Clock)
will be divided. This value must be 1/16 times the desired baud rate.
The Divisor Latch Access Bit (DLAB) in U0LCR must be one in order to access
the UART0 Divisor Latches. (DLAB = 1)
Bit 0 - RBR Interrupt Enable. It also controls the Character Receive Time-
Out interrupt.
0 = Disable Receive Data Available interrupt
1 = Enable Receive Data Available interrupt
Bit 1 - THRE Interrupt Enable
0 = Disable THRE interrupt
1 = Enable THRE interrupt
6. U0IIR (UART0 Interrupt Identification Register)
It is a 32-bit read only register.
It provides a status code that denotes the priority and source of a pending
interrupt.
It must be read before exiting the Interrupt Service Routine to clear the
interrupt.
Bit 7:6 - FIFO Enable These bits are equivalent to FIFO enable bit in FIFO
Control Register,
0 = If FIFOs are disabled
1 = FIFOs are enabled
7. U0LCR (UART0 Line Control Register)
It is an 8-bit read-write register.
It determines the format of the data character that is to be transmitted or
received.
Bit 7 : TXEN
0 = Transmission disabled
1 = Transmission enabled
PROGRAM:
#include <NXP/iolpc2148.h>
#include <intrinsics.h> // Header Files
#include <stdio.h>
/*--------------------- User-defined Function Declaration -------------------------*/
void UART0_ISR(); // UART-0 Interrupt Service Routine function
declaration
void UART0_init(); // UART-0 Initialisation function declaration
void feed (void); // PLL-FEED function declaration
void serialtx(char txdata); // UART-0 Serial Transmitter function declaration
/*--------------------- Main Function Starts Here -------------------------*/
void main(void)
{
unsigned char msg[]="\r\n UART0 Interrupt Program. ";
PINSEL2 = 0X00000000; // ( Optional )
IO1DIR = 0xff000000; // data bits configuration as I/O
UART0_init(); // UART0 Initialisation Function
__enable_interrupt(); // Global interrupt enable
for(int i=0;msg[i]!='\0';i++)
{ serialtx(msg[i]); } // Transmits the enter message to hyperterminal (PC)
while(1)
{
IO1PIN = 0x55000000;
}
}
// void main() End .
/*--------------------- Function Definition -------------------------*/
void UART0_ISR() // Interrupt Serice routine for TIMER0 interrupt.
{
int temp,buf;
__disable_interrupt(); // Global interrupt disable.
IO1PIN = 0xAA000000; // LED glow in this pattern (0xAA)when there is an
interrupt.
for(int i = 0; i < 10000; ++i) // few ms Delay
Result: Thus the program for serial transmission and reception of a character in C
by polling method was written and the output was verified.
References:
1. LPC 214x User manual (UM10139)
2. ARM System Developers Guide Designing and Optimizing System
Software- Andrew Sloss, Dominic Symes, Chris Wright
3. https://www.electronicwings.com/arm7/lpc2148-uart0
2 4 4 10 Sign
Experiment No-10
Aim: To write a program for accessing the ADC data from ARM processor and also
display the same in LCD display.
Objective:
To write embedded C program for accessing the ADC data from ARM Processor.
Learning outcome:
processor.
Apparatus:
Theory:
In this experiment we display input voltage signal on AD0.1 (P0.28) into digital
signal. We will convert the digital value to equivalent voltage value and display it
on an LCD. We can compare this voltage with actual voltage measured on a digital
millimeter.
ALGORITHM:
Step 1: Start
Step 2: Initialize LCD
Step 3: Send command signals [RS=0, R/W=0, En=1].
Step 4: Send data signals [RS=1, R/W=0, En=1].
Step 5: Set the control register value for clock frequency and bits.
Step 6: Set the control register value for Conversion start.
Step 7: Stop.
PROCEDURE:
➢ Compile, Debug & Simulate the above code in IAR, and see the output in
register view window. ➢ Follow to Steps given below to see/verify the output :
Step-1: Open the IAR workspace. Step-2: Go to project >> option and do the
following settings: General Options: Target >> Processor variant >> Core >>
ARM7TDMI S. a. Output Converter: Output >> Generate additional output:
(Output format >> Intel extended) and (Output file >> Override default >>
project_name.hex)
b.Linker >> Linker configurations file, and browse/provide path for the linker file
as follows:
C:\ProgramFiles\IARSystems\EmbeddedWorkbench5.40\arm\config\linker\NXP\
LPC2148.icf
c.After doing above setting click OK to save/ exit from the option window. Step-3:
Now execute the following: a. Project >> Rebuild all (if you get 0 errors & 0
warnings then only got to next step.)
Step 4: Flash the program in LPC2148 kit. Step 5: Verify the output using LCD.
PROGRAM:
#include<nxp\iolpc2148.h>
#define EN 0x800
#define RW 0X200
#define RS 0x100
#define DONE 0x80000000
#define START 0x01000000
#define PRESET 0x00230600
void delay(void)
{
unsigned int i;
for(i=0;i<0x1fff;i++);
}
void EN_Pulse(void)
{
IO0SET = EN ;
delay();
IO0CLR = EN ;
}
int main(void)
{
int num,i,d1,d2,d3,d4;
unsigned long Val;
IO0CLR = RW;
AD0CR = PRESET | 0x02;
AD0CR |= START;
lcd_initialize();
send_cmd(0x80); delay();
for(i=0;i<=15; i++)
{
send_data(display[i]);
}
while(1)
{
do
{
Val = AD0GDR;
}
#include <lpc214x.h>
#include <stdint.h>
#include "LCD-16x2-8bit.h"
#include <stdio.h>
#include <string.h>
int main(void)
{
uint32_t result;
float voltage;
char volt[18];
LCD_Init();
PINSEL1 = 0x01000000; /* P0.28 as AD0.1 */
AD0CR = 0x00200402; /* ADC operational, 10-bits, 11 clocks for conversion
*/
while(1)
{
AD0CR = AD0CR | (1<<24); /* Start Conversion */
while ( !(AD0DR1 & 0x80000000) ); /* Wait till DONE */
result = AD0DR1;
result = (result>>6);
result = (result & 0x000003FF);
voltage = ( (result/1023.0) * 3.3 ); /* Convert ADC value to
equivalent voltage */
LCD_Command(0x80);
sprintf(volt, "Voltage=%.2f V ", voltage);
LCD_String(volt);
memset(volt, 0, 18);
}
}
Result: Thus the program for accessing the ADC value from ARM processor was
written and the output was verified in LCD display.
References:
1. https://www.electronicwings.com/arm7/lpc2148-adc-analog-to-digital-
converter
2. LPC 214x User manual (UM10139)
3. ARM System Developers Guide Designing and Optimizing System
Software- Andrew Sloss, Dominic Symes, Chris Wright
2 4 4 10 Sign
Experiment No-11
AIM: Display Hello World string on LCD of Raspberry Pi using python program.
Objective:
1. To write python program for display string on LCD of Raspberry Pi.
Learning outcome:
Apparatus:
2. LCD Display - 1
3. Serial port cable - 1
Theory:
In 4 bit mode, each byte of data is sent to the LCD in two sets of 4 bits, one after
the other, in what are known as the upper bits and lower bits. Although 8 bit
mode transfers data about twice as fast as 4 bit mode, it takes a longer time for
the LCD driver to process each byte than it takes to transmit the byte.
Procedure:
1. We can download WiringPi using Git. Your Pi may have Git already installed (if
so skip this step), but if not, enter this at the command prompt:
./build
5. Test the installation by entering:
gpio -v
Followed by:
gpio readall
Program:
#include <wiringPi.h>
#include <lcd.h>
int main()
{
int lcd;
wiringPiSetup();
lcd = lcdInit (2, 16, 8, LCD_RS, LCD_E, LCD_D0, LCD_D1, LCD_D2, LCD_D3, LCD_D4,
LCD_D5, LCD_D6, LCD_D7);
Result:
The String of character is displayed on LCD screen.
References:
1. https://www.digikey.in/en/maker/blogs/2018/how-to-connect-a-
raspberry-pi-to-a-16-x-2-lcd-display
2. LPC 214x User manual (UM10139)
3. ARM System Developers Guide Designing and Optimizing System
Software- Andrew Sloss, Dominic Symes, Chris Wright
2 4 4 10 Sign
Experiment No-12
AIM: Interface of LM 35 temperature sensor.
Objective:
Learning outcome:
Theory:
The LM35 is an integrated circuit sensor that can be used to measure
temperature with an electrical output proportional to the temperature (in degree
centigrade).The LM35 device has an advantage over linear temperature sensors
calibrated in Kelvin, as the user is not required to subtract a large constant
voltage from the output to obtain convenient Centigrade scaling.
Its measurement range is from -55°C to 150°C having typical accuracy(s) of 0.25°C
at room temperature and 0.75°C for full range. LM35 also supports a wide range
of supply voltage from 4V to 30V and is available in 4 different packages viz. TO-
CAN, TO-92, SOIC and TO-220.
Program
#include<lpc214x.h>
#include<stdio.h>
#define adc_sel 27 //for pinsel
#define clkdiv 8
#define ch0 0
#define burst_mode 16
#define pdn 21
#define start 24
#define done 31
#define lcdport IO0SET
#define lcdportclr IOCLR0
#define rs 12
#define en 13
#define TEMP_PIN (1<<29) //P0.29 as Input to Temperature Sensor
#define TEMP_PIN_DIR (1<<26) //Bit 27:26 of PINSEL1 register
#define _PDN_BIT 1<<21
#define _ADCR_START_MASK 7<<24
#define _ADCR_SEL_MASK 0x000000FF
#define _ADC0_START 1<<24
void delay(int t)
{
int i,j;
for(i=0;i<t;i++)
for(j=0;j<5000;j++);
}
void cmnd()
{
lcdportclr=(1<<rs);
//lcdportclr = (1<<rw);
lcdport = (1<<en);
delay(40);
lcdportclr=(1<<en);
}
void lcdcmd(char ch)
{
lcdport = ((ch&0xf0)<<13);
cmnd();
lcdportclr = ((ch&0xf0)<<13);
lcdport = (((ch<<4)&0xf0)<<13);
cmnd();
lcdportclr = (((ch<<4)&0xf0)<<13);
}
void daten()
{
lcdport=(1<<rs);
//lcdportclr = (1<<rw);
lcdport = (1<<en);
delay(40);
lcdportclr=(1<<en);
}
void lcddata(char ch)
{
lcdport = ((ch&0xf0)<<13);
daten();
lcdportclr = ((ch&0xf0)<<13);
lcdport = (((ch<<4)&0xf0)<<13);
daten();
lcdportclr = (((ch<<4)&0xf0)<<13);
}
void lcdstring(char *str)
{
int j;
for(j=0;str[j]!='\0';j++)
{
lcddata(str[j]);
}
}
void lcd_init()
{
lcdcmd(0x02);
lcdcmd(0x28);
lcdcmd(0x01);
lcdcmd(0x0e);
}
void io_init()
{
PINSEL0=0X000;
IODIR0=0xffffff;
}
void Adc0Init(unsigned char clk)
{
PCONP |= 0x00001000;//Power on the A/D converter 0
//configure the A/D control register of A/D 0
AD0CR =((unsigned long)(clk+1)<<8 ) | _PDN_BIT ;
}
unsigned int Adc0Read(unsigned char channel)
{
static unsigned val;
AD0CR &= ~(_ADCR_START_MASK|_ADCR_SEL_MASK); //stop the A/D
converter by masking the
//sta
rt bits and channel selection bit
AD0CR |=((unsigned long)(1)<<channel); //Select the A/D
channel
AD0CR |=_ADC0_START;
while(!(AD0GDR & (0x80000000))); //Wait for the
conversion to get over
//by
monitoring the 28th bit of A/D data register
AD0CR &= ~(_ADCR_START_MASK|_ADCR_SEL_MASK); //Stop the
conversion by masking the start bits
val = AD0GDR;
val = ((val>>6 & 0x03FF)); //Extract A/D result
return(val);
}
int main()
{
float temperature=0.0;
char result[5];
PINSEL1 |= TEMP_PIN_DIR; //Bit 27:26 of PINSEL1 register
IODIR0 &= ~(TEMP_PIN); //Select the AD0.3 of P0.28 as Input
io_init();
lcd_init();
lcdcmd(0x84);
lcdstring("Temperature");
Adc0Init(10);
while(1)
{
temperature = (((float)Adc0Read(2)/1023.0)*3.3*100);
lcdcmd(0xc5);
sprintf(result,"%f",temperature);
lcdstring(result);
lcddata(0xDF); //for degree character
lcddata('C');
delay(100);
}
}
2 4 4 10 Sign