Processor Architecture Lab Manual Updated24-25
Processor Architecture Lab Manual Updated24-25
SE-IT
LABORATORY MANUAL
Semester – II
CERTIFICATE
Place:
Date:
INDEX
Marks
Sr. Date of Date of Signature
Title of Experiment Obtaine
No perfor Submis of Faculty
d (10)
mance sion
Study of Embedded C programming language
1
(Overview, syntax, One simple program like
addition of two numbers).
Write an Embedded C program to add array of n
2 numbers
Group
3 A Write an Embedded C program to transfer
elements from one location to another
4 Write an Embedded C program for sorting the
numbers in ascending and descending order.
5 Write an Embedded C program to interface
PIC 18FXXX with LED & blinking it using
specified delay
Group
6 Write an Embedded C program for Timer
B
programming ISR based buzzer on/off.
7 Write an Embedded C program for External
interrupt input switch press,output at relay
Write an Embedded C program for LCD
8
interfacing with PIC 18FXXX
Marks: / 10
Title: Study of Embedded C programming language (Overview, syntax, One simple program like
addition of two numbers).
Theory:
Embedded C programming plays a key role to make the microcontroller run & perform the preferred
actions. At present, we normally utilize several electronic devices like mobile phones, washing machines,
security systems, refrigerators, digital cameras, etc. The controlling of these embedded devices can be done
with the help of an embedded C program. For example, in a digital camera, if we press a camera button to
capture a photo then the microcontroller will execute the required function to click the image as well as to
store it.
Embedded C programming builds with a set of functions where every function is a set of statements that
are utilized to execute some particular tasks. Both the embedded C and C languages are the same and
implemented through some fundamental elements like a variable, character set, keywords, data types,
declaration of variables, expressions, statements. All these elements play a key role while writing an
embedded C program.
In embedded system programming C code is preferred over other language. Due to the following reasons:
• Easy to understand
• High Reliability
• Portability
• Scalability
Embedded Systems consists of both Hardware and Software. If we consider a simple Embedded System,
the main Hardware Module is the Processor. The Processor is the heart of the Embedded System and it can
be anything like a Microprocessor, Microcontroller, DSP, CPLD (Complex Programmable Logic Device)
or an FPGA (Field Programmable Gated Array).
All these devices have one thing in common: they are programmable i.e. we can write a program (which
is the software part of the Embedded System) to define how the device actually works.
Embedded Software or Program allow Hardware to monitor external events (Inputs / Sensors) and control
external devices (Outputs) accordingly. During this process, the program for an Embedded System may
have to directly manipulate the internal architecture of the Embedded Hardware (usually the processor)
such as Timers, Serial Communications Interface, Interrupt, Handling and I/O Ports etc.
From the above statement, it is clear that the Software part of an Embedded System is equally important
as the Hardware part. There is no point in having advanced Hardware Components with poorly written
programs (Software).
There are many programming languages that are used for Embedded Systems like Assembly (low-level
Programming Language), C, C++, JAVA (high-level programming languages), Visual Basic, JAVA Script
(Application level Programming Languages), etc.
In the process of making a better embedded system, the programming of the system plays a vital role and
hence, the selection of the Programming Language is very important.
• Make use of library functions to reduce the complexity of the main code
• You can easily port the code to other architecture with very little modifications
Introduction to Embedded C Programming Language
Before going in to the details of Embedded C Programming Language and basics of Embedded C Program,
we will first talk about the C Programming Language.
The C Programming Language, developed by Dennis Ritchie in the late 60’s and early 70’s, is the most
popular and widely used programming language. The C Programming Language provided low level
memory access using an uncomplicated compiler (a software that converts programs to machine code) and
achieved efficient mapping to machine instructions.
The C Programming Language became so popular that it is used in a wide range of applications ranging
from Embedded Systems to Super Computers.
Embedded C Programming Language, which is widely used in the development of Embedded Systems, is
an extension of C Program Language. The Embedded C Programming Language uses the same syntax and
semantics of the C Programming Language like main function, declaration of datatypes, defining variables,
loops, functions, statements, etc.
The extension in Embedded C from standard C Programming Language include I/O Hardware Addressing,
fixed point arithmetic operations, accessing address spaces, etc.
There is actually not much difference between C and Embedded C apart from few extensions and the
operating environment. Both C and Embedded C are ISO Standards that have almost same syntax,
datatypes, functions, etc.
Embedded C is basically an extension to the Standard C Programming Language with additional features
like Addressing I/O, multiple memory addressing and fixed-point arithmetic, etc.
C Programming Language is generally used for developing desktop applications, whereas Embedded C is
used in the development of Microcontroller based applications.
Now that we have seen a little bit about Embedded Systems and Programming Languages, we will dive in
to the basics of Embedded C Program. We will start with two of the basic features of the Embedded C
Program: Keywords and Data types.
Keywords in Embedded C
A Keyword is a special word with a special meaning to the compiler (a C Compiler for example, is a
software that is used to convert program written in C to Machine Code).
following are some of the keywords:
bit
sbit
sfr
small
large
Data Types in C Programming Language (or any programming language for that matter) help us declaring
variables in the program. There are many data types in C Programming Language like signed int, unsigned
int, signed char, unsigned char, float, double, etc.
The next thing to understand in the Basics of Embedded C Program is the basic structure or Template of
Embedded C Program. This will help us in understanding how an Embedded C Program is written. The
following part shows the basic structure of an Embedded C Program.
Comments:
Comments are readable text that are written to help us (the reader) understand the code easily. They are
ignored by the compiler and do not take up any memory in the final code (after compilation).There are two
ways you can write comments: one is the single line comments denoted by // and the other is multiline
comments denoted by /*….*/.
Preprocessor Directive:
A Preprocessor Directive in Embedded C is an indication to the compiler that it must look in to this file
for symbols that are not defined in the program.
In C Programming Language (also in Embedded C), Preprocessor Directives are usually represented using
# symbol like #include… or #define….
In Embedded C Programming, we usually use the preprocessor directive to indicate a header file specific
to the microcontroller, which contains all the SFRs and the bits in those SFRs.
In case of 8051, Keil Compiler has the file “reg51.h”, which must be written at the beginning of every
Embedded C Program.
Global Variables:
Global Variables, as the name suggests, are Global to the program i.e., they can be accessed anywhere in
the program.
Local Variables:
Local Variables, in contrast to Global Variables, are confined to their respective function.
Main Function:
Every C or Embedded C Program has one main function, from where the execution of the program begins.
Till now, we have seen a few Basics of Embedded C Program like difference between C and Embedded
C, basic structure or template of an Embedded C Program and different components of the Embedded C
Program.
Program Size
Every programming language occupies some memory where embedded processor like microcontroller
includes an extremely less amount of random-access memory.
The programming language should be very fast, so should run as quickly as possible. The speed of
embedded hardware should not be reduced because of the slow-running software.
Portability
For the different embedded processors, the compilation of similar programs can be done.
• Simple Implementation
• Simple Maintenance
• Readability
Advantages
• The cost of the hardware used in the embedded c is typically so much low.
Disadvantages
• At a time, it executes only one task but can’t execute the multi-tasks
The programming language used in the applications is speed checker on the highway, controlling of traffic
lights, controlling of street lights, tracking the vehicle, artificial intelligence, home automation, and auto
intensity control.
What is MPLAB?
MPLAB is a software program that runs on your PC to provide a development environment for your
embedded system design. In other words, it is a program package that makes writing and developing a
program easier. It could best be described as developing environment for a standard program language that
is intended for programming microcontrollers.
➢ Right Click on the Source Files folder (for a C file) and Header
files (for a .h file).
➢ New - > C Source file / or C Header File.
Step7: Opening an existing project.
➢ Go to the File Tab.
➢ Select Open Project.
Browse to the location and select the project name.Xfile
(project file). Click on Open Project
#include<pic18f4550.h>
void delay(int);
sbit a=PB^2;
sbit b=PB^3;
sbit c=PB^4;
sbit d=PB^5;
void main()
{
TRISB=0x00;
a=b=c=d=0x00;
delay(10);
a=b=c=d=0xFF;}
void delay(int a)
{
unsigned char c;
for(c=0;c<a;c++)
for(c=0;c<250;c++);
}
Conclusion: Based on the understanding of the basic concepts of Embedded C Programming along
with its environment setup used in a simple program for addition of two numbers.
Name of the Student: Roll no:
Marks: / 10
Theory:
There is actually not much difference between C and Embedded C apart from fewextensions and the
operating environment. Both C and Embedded C are ISO Standards that have almost same syntax,
datatypes, functions, etc.
Embedded C is basically an extension to the Standard C Programming Language with additional
features like Addressing I/O, multiple memory addressing and fixed- point arithmetic, etc. C
Programming Language is generally used for developing desktop applications, whereas Embedded C
is used in the development of Microcontroller based applications.
C arrays are declared in the following form type name [number of elements];
For example, if we want an array of five integers , we write in C:
int numbers[5];
For a five character array char letters[5];
type name [number of elements] = {comma-separated values}
For example, if we want to initialize an array with five integers, with 1, 3, 5, 0, 9, as the initial values:
int number[5]={1,3,5,0,9};
Let’s see the logic to calculate the sum of the array elements. Suppose arr is an integer array of size
N (arr[N] ), the task is to write the C Program to sum the elements of an array.
Algorithm :
5. After each addition check whether carry is generated, if yes then increment carry counter by one.
8. Go on adding numbers in internal memory till counter becomes zero. If not then go to step 4.
Flowchart :
Marks: / 10
Aim: Write an Embedded C program to transfer elements from one location toanother for
following:
• Internal to internal memory transfer
• Internal to external memory transfer
Theory:
1. Program Memory
2. Data Memory
3. Data EEPOM
Program Memory type
This is common which have all the microcontroller and its purposes is to store the
instructions.it consist of further four different types of memory.
0
1. ROM (Read only memory)
2. EPROM (Erasable programmable read only memory)
3. OTP (On time programmable)
4. FLASH EEPROM (Electrical erasable programmable read only
memory)
ROM
In microcontrollers first type memory is ROM and during the manufacturing process once the
program codes are set in ROM that can’t be changed after the manufacturing process, therefore
it is called read only memory mean just read thecode but can’t be changed. Due to this reason
the microcontrollers which have theROM memory are considers best for that applications where
there is no need of program change only need of program read. These microcontrollers are less
expensive as compared to the microcontrollers which have the OTP or FLAS programmable
memory and these are ordered in large quantities.
EPROM
The second type is erasable programmable read only and this is used in two different type of
packages. When EPROM is used in ceramic package with quartzwindow then microcontroller
can be erased the program many times by using ultraviolet eraser and erase time depends upon
the intensity of light. Normally theerase time is in between 5 and 30 minutes. In this the
microcontroller can also reprogrammed the program. It is very expensive due to the high cost
of the windowed ceramic package.
OTP
The one-time programmable memory used the same type of die as the EPROP windowed
packaged devices. Its packaging makes it unique. These microcontrollers are in an opaque
plastic packing and its program can’t be erase through ultraviolet light. The OTP devices are
first transfer to customer side then these are programmed therefore these devices are called one
time programmable.
Flash EPROM
This the type which provides the alternate flexibility because its program can be erased
electrically and also reprogram in few seconds. It’s no need of any ultraviolet light to erase the
program. Once the program is erased the program can reprogramwith new code. The devices
0
which have the flash memory can also be self-program by using some special sequence of
instructions. These devices also contain a small amount non-volatile data EPROM and that can
be written thousands of time. In these devices “F” is denoted by part number
Algorithm :
Code:
Conclusion: Transfer and exchange of elements from one memory location to other is checked.
0
Name of the Student: Roll no:
Marks: / 10
Aim: Write an Embedded C program for sorting the numbers in ascending anddescending order.
Algorithm :
1. Initialized ptr to point to first element in array stored in internal program memory.
2. Initialize R0 to point to location 30h in internal data memory
3. Initialize count to number of elements to transfer from internal program memory to internal data memory.
4. Transfer data byte by byte from internal program memory to internal data memory for count number of
times
5. Initialize outer loop counter for sorting (bubble sort)
6. Initialize internal loop counter for number of comparisons
7. Initialize R0 to point to 30H internal data memory location
8. Transfer first number in b and second number in a register
9. Compare a and b register contents, if equal goto step 12
10. If a register contents are greater then goto step 12
11. If b register contents are greater then swap contents of a and b register
0
12. Decrement internal comparison count. If not zero goto step 8
13. Decrement outer loop counter. If it is not zero goto step 6
Flowchart:
0
Name of the Student: Roll no:
Title: Write an Embedded C program to interface PIC 18FXXX with LED & blinking it using
specified delay.
Objective: Connect LED to the microcontroller and it should start blinking.
Lab facility: MPLAB X IDE simulator, XC8 Compiler, PIC18FXXX microcontrollerkit, Proteus,
LED
Theory: Timer is used to control the output on a bit of a port.
There are 4 timers in PIC18. Each have corresponding timer registers TMRxH and
TMRxL where x is the timer number that ranges from 0 to 3
There is a control register correspond to every timer TxCON. In this program Timer0 is
used. Following is the T0CON register.
0
The program is written such that a LED is connected to a pin of any port (PORTB) and that pin is toggled after
a cycle controlled by the timer. This is repeated for infinite time. Thus when the port bit is 0, LED is off and
when it is 1, LED is on. Sothe LED blinks after every cycle.
ALGORITHM
1. As LED connected to PORTD configure these pins as output by writing 0x00 to the
appropriated TRES register.
2. As buttons are connected to RB.4 and RB.5 so configure these pins as input by
writing 1 to the appropriated bits of TRES register.
3. Check the status of RB.4, if it is zero then move 1bit of PORTB from right to left.
4. Else check the status of RB.5, if it is zero then move 1 bit of PORTB from left to
right.
5. Repeat step 3 to 4
Interfacing Diagram:
0
Name of the Student: Roll no:
Marks: / 10
Aim: Write an Embedded C program for Timer programming ISR based buzzer on/off.
D7 D6 D5 D4 D3 D2 D1 D0
not used
0
1 = Do not synchronize external clock input
0 = Synchronize external clock input
1 = Do not synchronize external clock input
0 = Synchronize external clock input
The program is written such that a buzzer is connected to a pin of any port (PORTB) and that pin is
set when the switch is pressed. The duration for which thepin should be set is controlled by the timer.
This is repeated for infinite time.
ALGORITHM:
Step1: Reset TRISB so that PORTB is in output mode
Step2: Reset PORTB
Step3: check the switch is pressed
Step4: if yes then
Step5: Set
PORTB Step6:
Call the delay
Step7:end if
Step8: goto
Step3
Conclusion: The student is able to understand the working of the timer, buzzer,and
ports.
0
Name of the Student: Roll no:
Aim: Write an Embedded C program for External interrupt input switch press,output at relay.
Outcome: When PIC18 is interrupted, using RB0, the data at PORTD will betoggled
Theory:
Sometimes External devices are connected with microcontroller. If that external device has to send
some information to microcontroller, then microcontroller needsto know about this situation to get that
information. An example of such an external device is the digital thermometer. It measures the
temperature and at the end ofmeasurements transmits results to the microcontroller. Now the purpose
of this article to explain the fact that how does the microcontroller knows to get the required
information from an external device.
Types of interrupts
There are two methods of communication between the microcontroller and the external
device:
• By using Polling
• By using Interrupts
INTERRUPTS
Interrupt is the signal which is sent to the microcontroller to mark the eventthat requires
immediate attention. This signal requests the microcontroller to stopto perform the current program
temporarily time to execute a special code. It means when external device finishes the task imposed on
it, the microcontroller willbe notified that it can access and receive the information and use it.
0
The request to the microcontroller to stop to perform the current program temporarily can
come from various sources:
• Through external hardware devices like pressing specific key on the keyboard, which sends
Interrupt to the microcontroller to read the information of the pressed key.
• During execution of the program, the microcontroller can also send interrupts to itself to report an
error in the code. For example, division by 0 will causesan interrupt.
• In the multi-processor system, the microcontrollers can send interrupts to each other to
communicate. For example, to divide the work between themthey will send signals between them.
There are 2 types of interrupts for PIC microcontroller that can cause break.
Software Interrupt: It comes from a program that is executed by microcontrolleror we can say that
it is generated by internal peripherals of the microcontroller andrequests the processor to hold the
running of program and go to make an interrupt. Hardware Interrupt: These interrupts are sent
by external hardware devices atcertain pins of microcontroller.
Following interrupts sources are present in PIC18F452
• PORTB Change interrupts (any one of the upper four Port B pins. RB4-RB7)
These are the registers for interrupt operation and minimum 1 register can be usedto control the
interrupt operation in PIC18F452 which are:
• IPEN bit to enable interrupt priority scheme, 1= enable priority level on interrupts
• Other bits used to indicate the cause of resetRI (Reset Instruction flag),
TO (Watchdog Time Out flag), PD (Power on Detection flag), POR (Power on Reset status) and
BOR (Brown Out Reset status bit)
INTCON Register:
• 3 Interrupt control registers INTCON, INTCON2, INTCON3
• Readable and writable register which contains various enable and flag bits
• Contain enable, priority and flag bits for external interrupt, port B pin changeand TMR0
overflow interrupt
PIE Register:
• Peripheral Interrupt Enable register
• May be multiple register (PIE1, PIE2), depending on the number ofperipheral interrupt
sources
• Contain the individual bits to enable/disable Peripheral interrupts for use
PIR Register:
• Peripheral Interrupt Flag register
• May be multiple register (PIR1, PIR2), depending on the number ofperipheral interrupt
sources
• Contain bits to identify which interrupt occurs (flags)
INTCON registers are just used to configure the external PIC interrupts.
INTCON REGISTER:
0
GIE: Global Interrupt Enable
This bit is set high to enable all interrupts of PIC18F452.1 = Enable all interrupts
0 = Disable all interrupts
0
0 = None of RB7:RB4 pins have changed the state
ALGORITHM:
In this program, we configure the External Interrupt 0 (INT0). PORT D is used asoutput port
and it is monitored through a set of 8 LEDs. Reset is given through pin 1. Push button is connected
to RB0 for external interrupt source.
Step1: Enable the External Interrupt 0 by setting INT0IE bit high (INTCON=0x10).
Step2: Set the interrupt on falling edge by setting the INTEDG0 in INTCON2 to zero(INTCON2=0)
Step3: Set the Global Interrupt Enable in INTCON to high (INTCON.GIE=1)
Step4: Initialize PORTD with certain value (LATD=0xAA)
Step5: Write the ISR (Interrupt Service Routine) for the interrupt
Step6: Clear the INT0IF bit of INTCON (INTCON.INT0IF=0)
Step7: Invert or toggle the value at PORTD (LATD=~LATD)
Step8: go to step3.
Conclusion: The student is able to understand the working of the interrupts andable
to write the ISR (Interrupt Service Routine).
0
Name of the Student: Roll no:
Marks: / 10
Aim : To implement an Embedded C program for LCD interfacing with PIC 18FXXX
Objective: -
To understand LCD interfacing
Theory:
ALGORITHM
General steps for programming of LCD
[IMP]
Before start writing LCD for Display of information it is necessary to check for busy flag.
0
8. Check for busy flag (D7) bit
9. RS=0, and R/W=1, D7=1 -- LCD is busy taking care of internal operations and not accept any data.
10. RS=0, and R/W=1, D7=0 -- LCD is ready to accept any data.
11. For command RS=0 is passed through port line
12. For Data RS=1 is passed through port line
13. Send high to low pulse to ‘E’ pin to enable the internal latch of LCD
14. Call delay for completion of internal operations
15. Send different command words
16. Pass data to be displayed [ On any line ]
You can use subroutine for checking busy flag or just a big (and safe) delay.
17. Set R/W Pin of the LCD HIGH(read from the LCD)
18. Select the instruction register by setting RS pin LOW
19. Enable the LCD by Setting the enable pin HIGH
20. The most significant bit of the LCD data bus is the state of the busy flag (1=Busy,0=readyto
accept instructions/data). The other bits hold the current value of the address counter.
If the LCD never come out from”busy" status because of some problems, The program will”hang," waiting
for DB7 to go low. So in real applications it would be wise to put some kind of time limit on the delay--for
example, a maximum of 100 attempts to wait for the busy signal to go low. This would guarantee that even
if the LCD hardware fails, the program would not lockup.
0
The above figure shows the hex codes and their corresponding instruction to LCD register. The
characters are sent ot the LCD without checking the busy flag. We need to wait 5-10 ms between
issuing each character to the LCD. In programmingan LCD we need a long delay for the power-up
process.
• rw=0; Read/write Pin is also for writing the command to the LCD.
• en=1; enable pin is high.
0
Input: Make all the connections and start
Output: two input strings are displayed on the LCD.
Conclusion: The student is able to understand the working of the PIC18 with LCDand able to
write the codes for the initialization of LCD, writing to LCD etc.
Name of the Student: Roll no:
Marks: / 10
Objective: -
Program to Generate PWM signal for DC Motor control.
Theory:
.
Pulse Width Modulation (PWM) is a technique by which the width of a pulse isvaried while
keeping the frequency of the wave constant.
A period of a pulse consists of an ON cycle (5V) and an OFF cycle (0V). Thefraction for
which the signal is ON over a period is known as a duty cycle.
E.g. A pulse with a period of 10ms will remain ON (high) for 2ms.Therefore, the dutycycle will be
Through the PWM technique, we can control the power delivered to the load by using the ON-OFF
signal. The PWM signals can be used to control the speed of DCmotors and to change the intensity of
0
the LED. Moreover, it can also be used to generate sine signals.
Pulse Width Modulated signals with different duty cycle are shown below
PIC18F4550 controller has an in-built 10-bit PWM module known as the CCP module. The pin
CCP1 (RC2) is used for generating PWM signals. It needs to be configured as an output.
The PWM feature allows us to create pulses with variable widths. Although, timers can beused to create PWM,
the CCP modules makes the programming much easier and less tedious. PWM is widely used in industrial
controls such as DC motor control. Indeed, PWM is so widely used, that Microchip has enhanced PWM
capabilities as Enhanced CPP, where motor can be connected through H bridge.The CCP module uses Timer 2
and its associated registers, PR2 for the PWM time base whichmeans that the frequency of the PWM is a fraction
of the Fosc, the crystal frequency. It uses the PR2 register to set the PWM period as follows:
Steps in Programming PWM The following steps are taken to program the PWM features of the CCPModule:
34
1. Set the PWM period by writing to the PR2 register
2. Set the PWM duty cycle by writing to CCP1L for the higher 8 bits
6. Configure the CCP1CON register for PWM and set DC1B2:DC1B1 bits for the decimal portion ofthe
duty cycle
7. Start Timer 2
A motor driver L293D is provided on the Micro- PIC18F board for the user. The user can connect DCmotor or
stepper motor to connector CN9. In order to use DC motor put switch SW26 in position 2-3,while to use stepper
motor put switch26 in position 1-2
Input: Make all the connections and start
35
Name of the Student: Roll no:
Aim:
Study of Arduino board and understand the OS installation process onRaspberry-pi.
Objective: 1) To study different Arduino families and Arduino UNO.
2) To study OS installation process on Raspberry-pi.
Theory:
• Arduino boards are able to read analog or digital input signals from different sensors and turn it
into an output such as activating a motor, turning LED on/off, connect to the cloud and many other
actions.
• You can control your board functions by sending a set of instructions to the microcontroller on the
board via Arduino IDE (referred to as uploading software).
36
• Unlike most previous programmable circuit boards, Arduino does not need an extra piece of
hardware (called a programmer) in order to load a new code onto the board. You can simply use a
USB cable.
• Additionally, the Arduino IDE uses a simplified version of C++, making it easier to learn to
program.
• Finally, Arduino provides a standard form factor that breaks the functions of the micro-controller
into a more accessible package.
Board Types
• Various kinds of Arduino boards are available depending on different microcontrollers used.
However, all Arduino boards have one thing in common: they are programed through the Arduino
IDE.
• The differences are based on the number of inputs and outputs (the number of sensors, LEDs, and
buttons you can use on a single board), speed, operating voltage, form factor etc. Some boards are
designed to be embedded and have no programming interface (hardware), which you would need to
buy separately. Some can run directly from a 3.7V battery, others need at least 5V.
1) Power USB
Arduino board can be powered by using the USB cable from your computer. All you need to do is
connect the USB cable to the USB connection (1).
37
Power (Barrel Jack)
Arduino boards can be powered directly from the AC mains power supply by connecting it to the
Barrel Jack (2).
3)Voltage Regulator
The function of the voltage regulator is to control the voltage given to the Arduino board and
stabilize the DC voltages used by the processor and other elements.
4)Crystal Oscillator
The crystal oscillator helps Arduino in dealing with time issues. How does Arduino calculate time?
The answer is, by using the crystal oscillator. The number printed on top of the Arduino crystal is
16.000H9H. It tells us that the frequency is 16,000,000 Hertz or 16 MHz.
5) Arduino Reset
You can reset your Arduino board, i.e., start your program from the beginning. You can reset the
UNO board in two ways. First, by using the reset button (17) on the board. Second, you can connect
an external reset button to the Arduino pin labelled RESET (5)
7) Analog pins
The Arduino UNO board has six analog input pins A0 through A5. These pins can read the signal
from an analog sensor like the humidity sensor or temperature sensor and convert it into a digital
value that can be read by the microprocessor.
38
8)Main microcontroller
Each Arduino board has its own microcontroller (11). You can assume it as the brain of your
board. The main IC (integrated circuit) on the Arduino is slightly different from board to board.
The microcontrollers are usually of the ATMEL Company. You must know what IC your board
has before loading up a new program from the Arduino IDE. This information is available on
the top of the IC. For more details about the IC construction and functions, you can refer to the
data sheet.
9)ICSP pin
Mostly, ICSP (12) is an AVR, a tiny programming header for the Arduino consisting of MOSI,
MISO, SCK, RESET, VCC, and GND. It is often referred to as an SPI (Serial Peripheral
Interface), which could be considered as an "expansion" of the output. Actually, you are
slaving the output device to the master of the SPI bus.
This LED should light up when you plug your Arduino into a power source to indicate that
your board is powered up correctly. If this light does not turn on, then there is something
wrong with the connection.
On your board, you will find two labels: TX (transmit) and RX (receive). They appear in two
places on the Arduino UNO board. First, at the digital pins 0 and 1, to indicate the pins
responsible for serial communication. Second, the TX and RX led (13). The TX led flashes
with different speed while sending the serial data. The speed of flashing depends on the baud
rate used by the board. RX flashes during the receiving process.
12)Digital I/O
The Arduino UNO board has 14 digital I/O pins (15) (of which 6 provide PWM (Pulse Width
Modulation) output. These pins can be configured to work as input digital pins to read logic
values (0 or 1) or as digital output pins to drive different modules like LEDs, relays, etc. The
39
pins labeled “~” can be used to generate PWM.
13) AREF
AREF stands for Analog Reference. It is sometimes, used to set an external reference voltage
(between 0 and 5 Volts) as the upper limit for the analog input pins.
Raspberry Pi recommend the use of Raspberry Pi Imager to install an operating system on your
SD card. You will need another computer with an SD card reader toinstall the image.
Using an SD card of 8GB or greater capacity with Raspberry Pi OS. If you are usingthe lite version of
Raspberry Pi OS, you can use a 4GB card. Other operating systems have different requirements: for
example, LibreELEC can run from a smaller card. Please check with the supplier of the operating system to
find out whatcapacity of card they recommend.
Download the latest version of Raspberry Pi Imager and install it. If you want to useRaspberry Pi Imager from
a second Raspberry Pi, you can install it from a terminal using sudo apt install rpi-imager. Then:
• Connect an SD card reader with the SD card inside.
• Open Raspberry Pi Imager and choose the required OS from the listpresented.
• Review your selections and click on the Write button to begin writing data tothe SD Card.
40
Downloading an Image
If you are using a different tool than Raspberry Pi Imager to write to your SD Card, most
require you to download the image first, then use the tool to write it to the card.Official images
for recommended operating systems are available to download fromthe Raspberry Pi website
downloads page. Alternative operating systems for Raspberry Pi computers are also
available from some third-party vendors.
You may need to unzip the downloaded file (.zip) to get the image file (.img) youneed to write
to the card.
If you have not already configured your operating system using the Advanced Menu of
Raspberry Pi Imager when Raspberry Pi OS starts up for the first time youwill be guided
through initial setup.
The Raspberry Pi OS configuration wizard will run on the first boot. The wizardstarts off by
allowing you to configure international settings and your timezone information.
After hitting "Next" you’ll be prompted to create a user account. Here you canchoose
your username, and a password.
If you want to you can set your username to the old default username of pi, whichwas used on
older versions of Raspberry Pi OS.
However, if you do choose to create this account you will trigger a warning message,
and we’d advise you to avoid the old default password of raspberry.
After creating an user account you can configure your screen, and your wirelessnetwork.
Once your wireless network is configured and your Raspberry Pi has access to theInternet you
will be prompted to update the operating system to the latest version. This will automatically
download any patches and updates needed to bring your new operating system right up to
date.Once the operating system is updated you will be prompted to reboot yourRaspberry Pi.
Conclusion: The student is able to understand different families kits, boards andshields of
Arduino and installation of OS on Raspberry-Pi SBC.
41
Name of the Student: Roll no:
Aim: Write simple program using Open-source prototype platform like Raspberry-
Pi/Beagle board/Arduino for digital read/write using LED and switch Analog read/write
using sensor and actuators.
Objective: 1) To study Arduino / Raspberry-pi GPIO programming
Theory :
To program the
Arduino,1.Click on
Code
42
use Blocks + Text.
a. This allows you to see the C++ code generated corresponding to your blocks.
b. You can copy this code later into Arduino IDE to program the real Arduino, rather
than having to write it from scratch.
c. You can also download the code as an Arduino-compatible .ino file.
2. You can code by selecting the blocks and connecting them appropriately.
Debugging -
More often than not, the code written by a programmer does not work as expectedthe very first time
he/she runs it. We need to find out the logical flaws in our code and fix them before we are able to
achieve full functionality. Figuring out flaws usually boil down to inspecting variable values at
various points in our code, andcomparing it with the expected values at those points based on the
program logic and data inputs. The usual way Arduino programmers do it is by printing out the
variable values to Serial console.
Tinkercard allows for debugging without having to print the values you want toinspect through Serial.
43
The example below shows debugging of the Ultrasonic Distance Sensor example.
1.Select the line(s) where you want the execution is to be paused. Such a line whereyou wish to
pause execution is called a breakpoint.
3. Hover over the variable values you want to inspect, and determine if the valuesare along the
expected lines. If not, there is something wrong, and use your logic todetermine what could be
wrong.
4.You can press the Resume execution button to run until the next breakpoint. 5.You can also step
44