2024-2025 - ESD Lab Manual
2024-2025 - ESD Lab Manual
COURSE INSTRUCTOR
Dr. S. MEYYAPPAN
ASSISTANT PROFESSOR
Marks Split-Up 6
3
6 45
Experiments on PIC Microcontroller
7 Experiments on ARM 65
1
Experiment(s) 1. Interfacing Push buttons with microcontroller.
2
Assignment(s) 1. Design of real-time clock using software interrupt.
3
Demonstration Remote data transmission using both
synchronous and asynchronous communication
protocols.
Experiment 1. I2C based DAC interface and SPI based ADC interface.
2. Remote transmission of field transmitter data to PC.
Assignment 1. Interfacing RTC with microcontroller using I2C
interface.
TOTAL : 90 PERIODS
4
COURSE OUTCOMES
1. Ability to infer the concept of embedded system and its architectural features.
2. Ability to familiarize with the basic concept of Embedded C programming and
itssignificant features.
3. Ability to integrate/interface the real world input devices with
microcontrollers/microprocessors.
4. Ability to integrate/interface the real world displays and actuators with
microcontrollers using relays.
5. Ability to configure and utilize the services of timer for a given application.
6. Ability to understand the Interrupt structure of an architecture and utilize it
forinterfacing switches and serial I/Os.
7. Ability to acquisition of real world signals using suitable data converters for
controlapplications.
8. Ability to identify the need for external memory and explore memory interfacing.
9. Ability to interface peripherals using respective communication protocols.
10. Ability to compare and justify the use of specific wireless communication protocol
forprocess automation.
11. Ability to utilize RTOS for an real time embedded system design.
12. Explore remote data acquisition using IoT.
13. Ability to apply the acquired technical skills in embedded programming and
use it todevelop microcontroller based closed loop control system for a typical
process.
5
MARKS SPLIT-UP
Sl. No. Mode of Assessment Marks Percentage
1 Theory Assessment - I 10 10%
2 Theory Assessment - II 10 10%
3 Mini Project 25 25%
4 Model Practical Examination 15 15%
5 End Semester Practical Examination 40 40%
Total 100 100%
6
RUBRICS FOR COURSE EVALUATION
Rubrics for Performance Evaluation (55% Weightage)
Continuous Assessment based on the performance in Two Theory Assessments (20%) and Mini
Project Development (25%)
Rubrics for Model Practical Examination (20% Weightage)
Ability to understand the Completely understood Understood the Difficulty is in
problem and come up the problem and carried problem and carried out understanding the
with Design/ Program/ out design on their own design with minimal given problem and
Diagrams (10%) and neatly presented support and presented major support required
with minor mistakes. to carry out the design.
Ability to carry out the Independently carried Carried out the Carried out the
experiment independently out the Experiment Experiment with Experiment with major
& without any support. minimal support. support.
Ability to carry out
analysis and come up with Carried out complete Carried out analysis Carried out analysis
meaningful inference analysis and has come up partly and has come up with difficulty and has
(10%) with meaningful with partly correct come up with no
inferences. inference. meaningful inference.
Ability to comprehend Comprehend practical Comprehend practical Comprehension of the
practical concepts (viva) concepts very well. concepts reasonably practical concepts is not
(5%) well. clear.
7
EXPERIMENTS ON
8051
MICROCONTROLLER
8
MICROCONTROLLER
Introduction:
8051 Microcontroller:
The 8051 is an 8-bit microcontroller introduced by Intel Corporation in 1981. It
supports the concept of system on a chip (SoC) as it possesses on-chip memory,
several peripherals, and a serial communication interface, all on a single chip. It gained
rousing reception from system engineers and consequently Intel granted permission to
other manufacturers make and market different flavours of 8051 that remain code
compatible with original 8051 which in turn led to the creation of several versions of
8051. It means that the program written for one flavour of 8051 will run on other
flavours too, regardless of the manufacturer.
Key Features:
4KB bytes of on-chip program memory (ROM)
128 bytes of on-chip data memory (RAM)
128 bytes of on-chip memory for SFRs
Four register banks
8-bit bidirectional data bus
16-bit unidirectional address bus
Four 8-bit ports, (short model have two 8-bit ports)
32 general purpose registers each of 8-bit
16 bit Timers (typically 2, but may have more or less)
Three internal and two external Interrupts
Full duplex serial data receiver/transmitter
9
16-bit registers in the form of program counter and data pointers
10
Ports of 8051:
PORT 0:
Dual-purpose port on pins 32-39
In minimum-component designs acts as general purpose I/O port
For larger designs with external memory, used as multiplexed address and
data bus
PORT 1:
Dedicated I/O port on pins 1-8
Used exclusively for interfacing to External devices
PORT 2:
• Pins 21-28
• Dual purpose port
• General I/O port or as the higher order byte of the address bus with external
code memory
PORT 3:
• Dual-purpose port on pins 10-17
• General-purpose I/O
• Multifunctional
11
Timers of 8051:
The value loaded into the TMOD register determines the modes of operation of
Timers/Counters
TMOD Register
12
Timer/Counter Control Logic
Modes of Operation:
13
Timer 0/1 Mode-1: 16-bit Timer/Counter
14
Timer Mode-3 (Split timer mode): Two 8-bit Timers using Timer0
The Proteus Design Suite is a windows based software solution which unifies
various design aspects of embedded systems that include schematic
capture, simulation and PCB layout.
15
The two most important components of Proteus are:
ISIS is used to draw schematic and simulate the circuit in real time. The Simulation
allows human access during run time, providing real time simulation.
ARES is used for PCB designing. It has the feature of viewing 3D view of the designed
PCB along with components. The designer can also develop 2D drawings in it
Proteus platinum edition is the ultimate Proteus product which contains all of
the product modules sold by the developer that include:
Additional Features:
In addition to the unlimited PCB Layout and VSM Simulation software, the
platinum edition also includes all other supporting modules as standard, including:
16
Integrated Development Environment (IDE):
An IDE enables programmers to unify different aspects of software development.
IDEs increase programmer productivity by combining common activities of writing
software into a single application: editing source code, building executables, and
debugging.
Certain IDEs are dedicated to one language, and so are a better match for a
specific programming paradigm. IntelliJ, for instance, is known primarily as a Java
IDE. Other IDEs have a broad array of supported languages all in one, like the Eclipse
IDE which supports Java, XML, C/C++, Python, and others.
µVision IDE:
The µVision Integrated development Environment (IDE) combines project
management, run-time environment, build facilities, source code editing, and program
debugging in a single powerful environment. µVision is easy-to-use and accelerates
embedded software development. µVision supports multiple screens and enables the
user to create individual window layouts anywhere on the visual surface.
The µVision Debugger provides a single environment through which the user's
application code may be tested, verified, and optimized. The debugger includes
traditional features like simple and complex breakpoints, watch windows, and
execution control and provides full visibility to device peripherals.
17
µVision is a window-based software development platform that combines a
robust and modern editor with a project manager and make facility tool. It integrates
all the tools needed to develop embedded applications including a C/C++ compiler,
macro assembler, linker/locator, and a HEX file generator. µVision helps expedite the
development process of embedded applications by providing the following:
In production, the device to be programmed can be placed on the PCB along with
all other components. ISP can then be used to program it first with test code followed
by final production code which in turn gives flexibility to the testing and quality
process.
Most microcontrollers now have ISP capability, including AVR, PIC, COP8 and
ST7. Serial EEPROMs and flash memory chips can also be used as well as PLD and
CPLD devices so using ISP should be your first choice.
Flash Magic:
Flash Magic is a feature-rich Windows based tool for the downloading of code
into NXP flash microcontrollers. It utilises a feature of the microcontrollers called ISP,
which allows the transfer of data serially between a PC and the target device.
Flash Magic can erase devices, program them, read data and read and set
various configuration information. Rather than providing the basic features of ISP,
Flash Magic includes additional features and intelligence, allowing complex operations
to be performed. For example, erasing can be any collection of pages pages, blocks, the
hex file to be programmed or the entire device. Some devices store the ISP bootloader
18
in flash memory, so Flash magic implements methods to protect this code from being
erased.
Flash Magic has been available for free for over six years and supports all current
8-bit (8051), 16-bit (XA) and 32-bit (ARM) flash microcontrollers from NXP.
Key Features:
19
Operating Procedure of Various Tools Involved in the Study
RIDE:
1. Open Ride software.
2. Click on ‘Project’ menu -> New.
3. In the New Project Dialog Box, enter a name for the project and browse to choose its
location.
4. Select 80C51 as the project Type and Click OK.
5. Click on File -> New -> C Files.
6. Enter the Program for the application in C Language and Save it inside the same
directory as the project, with an extension .C
7. Click on Project -> Add Node Source/Application and select the saved C File.
8. Click on Project -> Build All.
9. Ensure the successful compilation of the project by the automatic generation of the
HEX File in the project directory.
Keil µVision:
1. Open Keil microvision software.
2. Under Project meu, click on new project and save the file in some location.
3. Now navigate to Target -> Source group and right click on it and select add new file
to the group.
4. Select .C file on the popup window and save the file in same location as project file
with same name.
9. Open Proteus and double click on the AT89C51 controller and select the path of the
hex file generated and click ok.
20
Proteus:
1. Open the Proteus software. A window with a menu bar appears.
2. Click the file menu.
3. Select "New design" from the drop-down menu.
4. Click the library menu.
5. Select "pick devices/symbol" from the drop-down menu.
6. Select the relevant comment by double clicking it, so that the electronic components
list appears on the window.
3. Select the appropriate COM port and set the desired baud rate and the oscillator
frequency.
4. Check the Erase blocks used by HEX File option.
5. Browse and choose the generated .Hex file from code.
6. Press reset button.
7. Click Start button in the Step5 section and the code will be written to the
microcontroller, indicated by the Green strip in the status bar.
Note:
Before flashing the hex file, two switches near the Reset switch in the RTOS enabled
8051 Trainer Kit, should be in the following modes.
To begin execution, move switch SW7 to the EXEC Mode and SW8 to the INT Mode
and press the Reset button.
21
Experiments on 8051
Result:
Outpt
Result:
Outpt
22
(iii). 8-Bit Multiplication:
Result:
Outpt
Result:
Outpt
23
Inference
24
Embedded C Programming
#include<reg51.h>
sbit pout = P1^0;
sbit pin = P1^6;
void main()
{
while(1)
{
if (pin == 0)
pout = 1;
//delay(2000);
else
pout = 0;
//delay(1000);
}
}
25
Interfacing of Seven Segment LED Display with 8051:
#include<reg51.h>
void delay()
{
int i,j;
for(i=0;i<=100;i++)
for(j=0;j<=1000;j++);
}
void main()
{
int i,j;
while(1)
{
for(i=0;i<=9;i++)
{
P2 = dig1[i];
delay();
}
for(j=9;j>=0;j--)
{
P2 = dig1[j];
delay();
}
}
}
26
Interfacing of 16x2 LCD Module with 8051:
#include <reg51.h>
#define msec 50
sbit rs = P3^0;
sbit rw = P3^1;
sbit en = P3^6;
27
void display(int val)
{
P2 = val;
rs = 1;
rw = 0;
en = 1;
delay(1);
en = 0;
}
void main()
{
//unsigned char digit[3];
int i,j;
for(i=0;commands[i]!='\0';i++)
{
lcdcmd(commands[i]);
delay(msec);
}
/*digit[0] = (value/0x64)+0x30;
digit[1] = ((value/0x0a)%0x0a)+0x30;
digit[2] = (value%0x0a)+0x30;
for (j=0;j<3;j++)
{
display(digit[j]);
delay(msec);
}*/
28
for(j=0;j<=13;j++)
{
display(name1[j]);
delay(msec);
}
lcdcmd(0xc1);
delay(msec);
for(j=0;j<=13;j++)
{
display(name2[j]);
delay(msec);
}
29
Inference:
30
The 8051 based ON/OFF Control of Field Devices with Software Generated
Predefined Time Delay:
#include<reg51.h>
sbit a = P1^0 ;
Proteus schematic for the 8051 based ON/OFF control of field devices with
software generated predefined time delay
31
The 8051 based ON/OFF Control of Field Devices using Switch:
#include<reg51.h>
sbit a = P1^0 ;
sbit b = P3^0;
void main()
{ a = 0;
while(b == 0)
a = 1;
a = 0;
Proteus schematic for the 8051 based ON/OFF control of field devices using
switch
32
ON/OFF Control of Field Devices using the Timers and Interrupts of 8051:
#include<reg51.h>
sbit pump = P2^0;
void pumpfn()
{
int i,j;
pump = 0;
for(j=0;j<300;j++)
{
TH0 = 0X3C;
TL0 = 0XB0;
TR0 = 1;
while(TF0 == 0);
TF0 = 0;
TR0 = 0;
}
pump = 1;
for(i=0;i<600;i++)
{
TH0 = 0X3C;
TL0 = 0XB0;
TR0 = 1;
while(TF0 == 0);
TF0 = 0;
TR0 = 0;
}
}
void main()
{
while(1)
{
33
TMOD = 0x01;
pump = 0;
pumpfn();
}
Proteus schematic for the ON/OFF control of field devices using the timers and
interrupts of 8051
34
Inference
35
ADC Interface
ADC0809:
The ADC0808, ADC0809 data acquisition component is a monolithic CMOS
device with an 8-bit analog-to-digital converter, 8-channel multiplexer and
microprocessor compatible control logic. The 8-bit A/D converter uses successive
approximation as the conversion technique. The converter features a high impedance
chopper stabilized comparator, a 256R voltage divider with analog switch tree and a
successive approximation register. The 8-channel multiplexer can directly access any
of 8-single-ended analog signals.
The device eliminates the need for external zero and full-scale adjustments. Easy
interfacing to microprocessors is provided by the latched and decoded multiplexer
address inputs and latched TTL TRI-STATE outputs.
The design of the ADC0808, ADC0809 has been optimized by incorporating the
most desirable aspects of several A/D conversion techniques. The ADC0808, ADC0809
offers high speed, high accuracy, minimal temperature dependence, excellent long-
term accuracy and repeatability, and consumes minimal power. These features make
this device ideally suited to applications from process and machine control to consumer
and automotive applications
Key Features:
No Zero or Full-Scale Adjust Required
8-Channel Multiplexer with Address Logic
0V to VCC Input Range
Outputs meet TTL Voltage Level Specifications
Resolution: 8 Bits
Total Unadjusted Error: ±½ LSB and ±1 LSB
Single Supply: 5 VDC
Low Power: 15 mW
Conversion Time: 100 μs
36
Interfacing ADC0809 with 8051 Microcontroller on Proteus
#include <reg51.h>
#define msec 50
37
rs = 1;
rw = 0;
en = 1;
delay(1);
en = 0;
}
void adcinit()
{
adda = 0;
addb = 0;
addc = 0;
ale = 0;
oe = 0;
start = 0;
}
void adcstrtconv()
{
ale = 1;
delay(1);
start = 1;
delay(5);
ale = 0;
start = 0;
}
void adcread()
{
while(eoc!=1);
oe = 1;
}
void main()
{
unsigned char adcdata;
unsigned char digit[3];
38
int i,j;
adcinit();
adcstrtconv();
adcread();
adcdata = P1;
for(i=0;commands[i]!='\0';i++)
{
lcdcmd(commands[i]);
delay(msec);
}
digit[0] = (adcdata/0x64)+0x30;
digit[1] = ((adcdata/0x0a)%0x0a)+0x30;
digit[2] = (adcdata%0x0a)+0x30;
for(j=0;j<3;j++)
{
display(digit[j]);
delay(msec);
}
40
DAC Interface
DAC 0800:
The DAC0800 series are monolithic 8-bit high-speed current-output digital-to-analog
converters (DAC) featuring typical settling times of 100 ns. When used as a multiplying
DAC, monotonic performance over a 40 to 1 reference current range is possible. The
DAC0800 series also features high compliance complementary current outputs to allow
differential output voltages of 20 Vp-p with simple resistor loads. The reference-to-full-
scale current matching of better than ±1 LSB eliminates the need for full-scale trims
in most applications, while the nonlinearities of better than ±0.1% over temperature
minimizes system error accumulations.
The noise immune inputs will accept a variety of logic levels. The performance and
characteristics of the device are essentially unchanged over the ±4.5V to ±18V power
supply range and power consumption at only 33 mW with ±5V supplies is independent
of logic input levels.
Key Features:
Fast Settling Output Current: 100 ns
Full Scale Error: ±1 LSB
Nonlinearity Over Temperature: ±0.1%
Full Scale Current Drift: ±10 ppm/°C
High Output Compliance: −10V to +18V
Complementary Current Outputs
Interface Directly with TTL, CMOS, PMOS and Others
2 Quadrant Wide Range Multiplying Capability
Wide Power Supply Range: ±4.5V to ±18V
41
Interfacing DAC 0800 with 8051 Microcontroller on Proteus
#include<reg51.h>
void delay(int time)
{
int i,j;
for(i=0;i<time;i++)
for(j=0;j<1275;j++);
}
void main()
{
while(1)
{
P1 = 0x00;
delay(50);
P1 = 0x7F;
delay(50);
P1 = 0xFF;
delay(50);
P1 = 0x80;
delay(50);
}
P1 = 0x00;
loop: if (P1<0xff)
P1 = P1+0x01;
else
P1 = 0x00;
goto loop;
42
iii) Triangular Wave Generation:
start: P1 = 0x00;
loop: if (P1<0xff)
P1 = P1+0x01;
goto loop;
P1 = 0xff;
repeat: if (P1>0x00)
P1 = P1-0x01;
goto repeat;
goto start;
43
Inference:
44
EXPERIMENTS ON
PIC MICROCONTROLLER
45
PIC MICROCONTROLLER
Introduction:
The Peripheral Interface Controller (PIC) microcontroller was developed by
General Instruments in 1975. PIC was developed when Microelectronics Division of
General Instruments was testing its 16-bit CPU CP1600. Although the CP1600 had a
good CPU it exhibited low I/O performance. The PIC controller was used to offload the
I/O the tasks from CPU to improve the overall performance of the system.
In 1985, General Instruments converted their Microelectronics Division to
Microchip Technology. The General Instruments used the acronyms Programmable
Interface Controller and Programmable Intelligent Computer for the initial PICs
(PIC1640 and PIC1650). nNow. PIC stands for Peripheral Interface Controller.
In 1993, Microchip Technology launched the 8-bit PIC16C84 with EEPROM
which could be programmed using serial programming method. The improved version
of PIC16C84 with flash memory (PIC18F84 and PIC18F84A) hit the market in 1998.
Since 1998, Microchip Technology continuously developed new high
performance microcontrollers with new complex architecture and enhanced in-built
peripherals. PIC microcontroller is based on Harvard architecture. At present PIC
microcontrollers are widely used for industrial purpose due to its high performance
ability at low power consumption. It is also very famous among hobbyists due to
moderate cost and easy availability of its associated software and hardware tools. The
8-bit PIC microcontroller is divided into following four categories on the basis of
internal architecture:
PIC16F873A
PIC16F874A
PIC16F876A
PIC16F877A
46
Key Features of PICI6F87XA MCUs:
• All single-cycle instructions except for program branches, which are two-
cycle
Peripheral Features:
• Timer0: 8-bit timer/counter with 8-bit prescaler
• Timer1: 16-bit timer/counter with prescaler, can be incremented during
Sleep via external crystal/clock
• Parallel Slave Port (PSP) – 8 bits wide with external RD, WR and CS controls
(40/44-pin only)
Analog Features:
• 10-bit, up to 8-channel Analog-to-Digital Converter (A/D)
• In-Circuit Serial Programming (ICSP) / In-Circuit Debug (ICD) via two pins
• Watchdog Timer (WDT) with its own on-chip RC oscillator for reliable
operation
Analog Features:
• Analog-to-Digital Converter (ADC) module:
10-bit resolution, up to 30 channels
Auto-acquisition capability
Conversion available during Sleep
Fixed Voltage Reference (FVR) channel
independent input multiplexing
49
• Digital-to-Analog Converter (DAC) module:
Fixed Voltage Reference (FVR) with 1.024V, 2.048V and 4.096V output
levels
5-bit rail-to-rail resistive DAC with positive and negative reference
selection
• SR Latch:
Multiple Set/Reset input options
• Two Capture/Compare/PWM (CCP) modules
• Three Enhanced CCP (ECCP) modules:
One, two or four PWM outputs
Selectable polarity
Programmable dead time
Auto-Shutdown and Auto-Restart and PWM steering
50
• Two Host Synchronous Serial Port (MSSP) modules:
MPLAB X IDE:
MPLAB X Integrated Development Environment (IDE) is an expandable, highly
configurable software program that incorporates powerful tools to help the user to
discover, configure, develop, debug and qualify embedded designs for most of PIC
microcontrollers and digital signal controllers. MPLAB X IDE works seamlessly with
the MPLAB development ecosystem of software and tools, many of which are completely
free.
Key Features:
Data Visualizer: No need to purchase extra visualizations tools since real-time
streaming data can be viewed in Data Visualizer
I/O View: Pin states can be verified and manipulated with I/O View for fast
hardware verification
51
Helpful Design Resources: Save time with useful links to software libraries,
datasheets and user guides that are provided automatically
Easy to Use: Register and bit definitions are now just a click away
Includes the MPLAB Integrated Programming Environment (IPE) for production-
level programming.
1. Open the MPLAB X IDE. Go to the menu bar which has file, edit, view,
project and tools option.
2. Select the project option and select the ‘project wired option’ from the drop-
down menu. This will show the project wired window.
3. Select a microcontroller for your project. Here ‘PIC16f877A’ microcontroller
is selected.
4. Select the compiler and path location for your project. Here ‘CCS C
compiler’ is selected for the PIC microcontroller, then select the ‘browse’
option from the project wired window to select the ‘ccsloader’ in the PICC
folder from the program files. A folder with the name ‘source group’ is
created in the ‘target’ folder.
5. Give a name to the project and click on ‘NEXT’ button to save the project.
A folder with the name ‘source group’ is created in the ‘target’ folder. Click
on the ‘file’ menu on the menu bar. Select ‘new file’ from the drop- down
menu.
52
Design of Simple On/Off Control Strategy for a Temperature Process using PIC16F877A:
#include<pic.h>
#include<stdio.h>
void ADC_Initialize()
{
ADCON0 = 0b10100001;
ADCON1 = 0b10000000;
}
int ADCRead()
{
__delay_ms(2);
GO_nDONE = 1;
while(GO_nDONE);
return (ADRESH+ADRESL);
}
void main()
{ int a,b,c,d,e,f,g,h,adc;
int i=0;
unsigned int seg[]={0XC0,0XF9,0XA4,0XB0,0X99,0X92,0X82,0XF8,0X80,0X90};
TRISC=0X00;
TRISD=0x00;
TRISA1=0;
ADC_Initialize();
53
while(1)
{
adc = ADCRead();
i = adc*0.4887586;
a=i%10;
b=i/10;
c=b%10;
d=b/10;
e=d%10;
f=d/10;
g=f%10;
PORTD=seg[g]; s1=1;
__delay_ms(5);s1=0;
PORTD=seg[e];RD7=1;s2=1;
__delay_ms(5); s2=0 ;
PORTD=seg[c];s3=1;
__delay_ms(5); s3=0;
PORTD=seg[a];s4=1;
__delay_ms(5);s4=0;
if(i<=27)
{
RA1=1;
}
else
{
RA1=0;
}
}
}
54
Design of On/Off Control Strategy for a Temperature Process using the Timers of
PIC16F877A:
#include<pic.h>
#include<stdio.h>
int i=0;
unsigned int seg[]={0XC0,0XF9,0XA4,0XB0,0X99,0X92,0X82,0XF8,0X80,0X90};
int a,b,c,d,e,f,g;
int adc;
void ADC_Initialize()
{
ADCON0 = 0b10100001;
ADCON1 = 0b10000000;
}
int ADCRead()
{
__delay_ms(2);
GO_nDONE = 1;
while(GO_nDONE);
return (ADRESH+ADRESL);
}
55
void timedelay()
{
int j;
for(j=0;j<4577;j++)
{
TMR1H = 0X00;
TMR1L = 0X00;
TMR1ON = 1;
while(TMR1IF !=1);
TMR1IF = 0;
a=i%10;
b=i/10;
c=b%10;
d=b/10;
e=d%10;
f=d/10;
g=f%10;
PORTD=seg[g]; s1 = 1;
__delay_ms(1);s1 = 0;
PORTD=seg[e]; s2 = 1;
__delay_ms(1);s2 = 0;
PORTD=seg[c]; s3 = 1;
__delay_ms(1); s3 = 0;
PORTD=seg[a]; s4 = 1;
__delay_ms(1); s4 = 0;
}
}
56
void main()
{
TRISC=0X00;
TRISD=0x00;
TRISA2=0;
INTCON = 0XC0;
PIE1 = 0X01;
ADC_Initialize();
while(1)
{
adc = ADCRead();
i = adc*0.4887586;
timedelay();
if(i<=27)
{
RA2=1;
}
else
{
RA2=0;
}
}
}
57
Proteus schematic of PIC16F877A based On/Off Control Strategy
58
Inference:
59
16x2 LCD Module Interface with PIC18F45K22:
void Move_Delay()
{
Delay_ms(500);
}
void main()
{
ANSELB = 0;
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
60
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(1,6,txt3);
Lcd_Out(2,6,txt4);
Delay_ms(2000);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,txt1);
Lcd_Out(2,5,txt2);
Delay_ms(2000);
while(1)
{
for(i=0; i<8; i++)
{
Lcd_Cmd(_LCD_SHIFT_LEFT);
Move_Delay();
}
for(i=0; i<8; i++)
{
Lcd_Cmd(_LCD_SHIFT_RIGHT);
Move_Delay();
}
}
}
61
Real Time Monitoring of a Temperature Process using PIC18F45K2:
void main()
{
ANSELB = 0;
ANSELE = 0x02;
TRISE1_bit = 1;
ADC_Init();
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(1, 1, "Temperature :");
62
Lcd_Chr(2,8,223);
Lcd_Chr(2,9,'C');
temp_res = 0;
do {
temp_res = ADC_Get_Sample(6);
temp = (temp_res * VREF)/10.23;
FloatToStr(temp, txt);
txt[4] = 0;
Lcd_Out(2,3,txt);
Delay_ms(300);
} while(1);
}
63
Inference:
64
EXPERIMENTS ON
ARM
65
ARM
Introduction:
The history of ARM processor dates back to 1983 in England when Acorn
Computers Ltd officially launched an Acorn RISC Management project after being
inspired to design its own processor by Berkeley RISC, one of the high-impact projects
under ARPA’s (Advanced Research Projects Agency, now converted to DARPA) VLSI
project, dealing with RISC-based microprocessor design led by David Patterson who
coined the term ‘RISC.’
ARM in the beginning was known as Acorn RISC machine. With VLSI Technology
Inc. as its silicon partner, ARM came up with ARM1, the first ARM silicon on April 26,
1985, which was used as a second processor to the BBC Micro to develop the
simulation software to finish work on the support chips (VIDC, IOC and MEMC) and
to increase the operating speed of the CAD software used in development of ARM2.
Apple, whilst developing an entirely new computing platform for its Newton, a personal
digital assistant, found that only Acorn RISC machine was close to the requirements
needed for implementation, but since ARM had no integral memory management unit,
Apple collaborated with Acorn to develop ARM.
The result of this collaboration was that both Acorn Group and Apple Computer,
Inc., with 43 per cent share each, and VLSI Technology, Inc. as an investor, a separate
company, ARM Ltd, was established in 1990. Also, the advanced research and
development section of Acorn was employed here. After that time, ARM became the
acronym for Advanced RISC Machine.
The British multinational semiconductor and software design company, ARM
Holdings plc, offers complete solutions that are essential for the manufacturing
process, but the company does not manufacture ICs. Moreover, it provides software
development tools under the brand Keil and RealView. It also provides ARM
architecture licensing for the companies that want to manufacture ARM-based CPUs
or ‘SoC' products.
The ARM architecture is a simple hardware design allowing things to be left off
the chip. It helps in creating small die-sized chip which helps in considerably reducing
the cost. Its low cost, simple pipeline construction and the freedom to put the design
point where the designer finds it suitable for low-power consumption adds onto the
benefits it provides for embedded applications.
66
Today ARM-based application processors can be found in about 85% of mobile
devices, including smart phones, tablets and laptops. Over the past five years, this
market has grown by an average of 30% per year
LPC408x/7x Devices:
The LPC408x/7x is an Arm Cortex-M4 based digital signal controller for
embedded applications requiring a high level of integration and low power dissipation.
The Arm Cortex-M4 is a next generation core that offers system enhancements
such as low power consumption, enhanced debug features, and a high level of support
block integration. The Arm Cortex-M4 CPU incorporates a 3-stage pipeline, uses a
Harvard architecture with separate local instruction and data buses as well as a third
bus for peripherals, and includes an internal prefetch unit that supports speculative
branching. The Arm Cortex-M4 supports single-cycle digital signal processing and
SIMD instructions. A hardware floating-point processor is integrated in the core for
several versions of the part. The LPC408x/7x adds a specialized flash memory
accelerator to accomplish optimal performance when executing code from flash. The
LPC408x/7x is targeted to operate at up to 120 MHz CPU frequency.
The peripheral complement of the LPC408x/7x includes up to 512 kB of flash
program memory, up to 96 kB of SRAM data memory, up to 4032 byte of EEPROM
data memory, External Memory controller (EMC), Ethernet, USB Device/Host/OTG, an
SPI Flash Interface (SPIFI), a General Purpose DMA controller, five UARTs, three SSP
controllers, three I2C-bus interfaces, a Quadrature Encoder Interface, four general
purpose timers, two general purpose PWMs with six outputs each and one motor
control PWM, an ultra-low power RTC with separate battery supply and event recorder,
a windowed watchdog timer, a CRC calculation engine and up to 165 general purpose
I/O pins.
The analog peripherals include one eight-channel 12-bit ADC, two analog
comparators, and a DAC.
The pinout of LPC408x/7x is intended to allow pin function compatibility with
the LPC24xx/23xx as well as the LPC178x/7x families.
Key Features:
Functional replacement for LPC23xx/24xx and LPC178x/7x family devices
ARM Cortex-M4 processor, running at frequencies of up to 120 MHz
Built-in Memory Protection Unit (MPU) supporting eight regions
67
Built-in Nested Vectored Interrupt Controller (NVIC)
Hardware floating-point unit (not all versions)
Non-Maskable Interrupt (NMI) input
JTAG and Serial Wire Debug (SWD), serial trace, eight breakpoints, and four
watch points
Analog peripherals
12-bit Analog-to-Digital Converter (ADC) with input multiplexing
among eight pins, conversion rates up to 400 kHz, and multiple result
registers
Serial interfaces
Quad SPI Flash Interface (SPIFI) with four lanes and up to 40 MB per
second
Five UARTs with fractional baud rate generation, internal FIFO, DMA
support, and RS-485/EIA-485 support
Three SSP controllers with FIFO and multi-protocol capabilities
68
Three enhanced I2C-bus interfaces, one with a true open-drain
output supporting the full I2C-bus specification and Fast-mode Plus
with data rates of 1 Mbit/s, two with standard port pins
69
Interfacing Switches and LED with LPC4088:
#include "LPC407x_8x_177x_8x.h"
void delay_ms(long ms);
int main(void)
{
LPC_SC->PCONP |= (1<<15);
LPC_IOCON->P4_0 = 0;
LPC_IOCON->P4_1 = 0;
LPC_IOCON->P4_2 = 0;
LPC_IOCON->P4_3 = 0;
LPC_IOCON->P4_4 = 0;
LPC_IOCON->P4_5 = 0;
LPC_IOCON->P4_6 = 0;
LPC_IOCON->P4_7 = 0;
LPC_IOCON->P4_8 = 0;
LPC_IOCON->P4_9 = 0;
LPC_IOCON->P4_10 = 0;
LPC_IOCON->P4_11 = 0;
LPC_IOCON->P4_12 = 0;
LPC_IOCON->P4_13 = 0;
LPC_IOCON->P4_14 = 0;
LPC_IOCON->P4_15 = 0;
LPC_GPIO4->DIR= 0x00FF;
while(1)
{
LPC_GPIO4->PIN >>= 8;
delay_ms(50);
}
}
{
long i,j;
for (i = 0; i < ms; i++ )
for (j = 0; j < 26659; j++ );
}
70
Multi Parameter Data Acquisition using the built-in A/D Module of LPC4088:
#include "LPC407x_8x_177x_8x.h"
#include<stdio.h>
unsigned int CH0, CH1, CH2;
unsigned char Str[5];
int main(void)
{
init_adc();
init_serial();
while(1)
{
CH0=ADC_Getdata(0);
itoa(CH0,Str);
UART0_puts(Str);
UART0_Txmt(' ');
CH1=ADC_Getdata(1);
itoa(CH1,Str);
UART0_puts(Str);
UART0_Txmt(' ');
CH2=ADC_Getdata(2);
itoa(CH2,Str);
UART0_puts(Str);
UART0_Txmt('\r');
delay_ms(500);
}
}
void init_adc(void)
{
LPC_SC->PCONP |= (1 << 12);
LPC_IOCON->P0_23 = 1;
LPC_IOCON->P0_24 = 1;
LPC_IOCON->P0_25 = 1;
LPC_ADC->CR = 0;
LPC_ADC->CR |= ((1<<21) | (1<<9));
}
71
LPC_ADC->CR |= (1<<24) | (1<<channel);
while((LPC_ADC->DR[channel] & 0x80000000)==0);
LPC_ADC->CR &= ~((1<<24) | (1<<channel));
return ((LPC_ADC->DR[channel]>>4)&0xFFF);
}
void init_serial(void)
{
LPC_SC->PCONP |= (1 << 3);
LPC_IOCON->P0_2 |= 1;
LPC_IOCON->P0_3 |= 1;
LPC_UART0->LCR = 0x83;
LPC_UART0->DLL = 195;
LPC_UART0->DLM = 0;
LPC_UART0->LCR = 0x03;
}
str[3] = val%10+'0';
val = val/10;
str[2] = val%10+'0';
val = val/10;
str[1] = val%10+'0';
str[0] = val/10+'0';
str[4] = '\0';
}
72
Clock and Calendar using the built-in RTC of LPC4088:
#include "LPC407x_8x_177x_8x.h"
#include<string.h>
char str[50];
uint8_t hour, min, sec, date, month;
uint16_t year;
int main(void)
{
LPC_SC->PCONP |= (1<<15);
LPC_IOCON->P0_4 = 0;
LPC_IOCON->P0_5 = 0;
LPC_IOCON->P4_28 = 0;
LPC_IOCON->P4_29 = 0;
LPC_IOCON->P4_30 = 0;
LPC_IOCON->P4_31 = 0;
LPC_GPIO0->DIR |= 0x30;
LPC_GPIO4->DIR = (0xF << 28);
lcd_init();
init_rtc();
lcd_command(0x01);
lcd_str("RTC Use Case");
delay_ms(2000);
lcd_command(0x01);
73
lcd_str("Starting...");
delay_ms(2000);
while (1)
{
hour = LPC_RTC->HOUR;
min = LPC_RTC->MIN;
sec = LPC_RTC->SEC;
date = LPC_RTC->DOM;
month = LPC_RTC->MONTH;
year = LPC_RTC->YEAR;
sprintf(str,"%u:%u:%u%u/%u/%u",hour,min,sec,date,month,year);
lcd_command(0x01);
lcd_str(str);
delay_ms(100);
}
}
DATA=cmd<<24;
LPC_GPIO0->PIN |= EN_VAL;
LPC_GPIO0->CLR |= EN_VAL;
DATA=cmd<<28;
LPC_GPIO0->PIN |= EN_VAL;
LPC_GPIO0->CLR |= EN_VAL;
delay_ms(5);
}
DATA=data<<24;
LPC_GPIO0->PIN |= EN_VAL;
LPC_GPIO0->CLR |= EN_VAL;
DATA=data<<28;
LPC_GPIO0->PIN |= EN_VAL;
74
LPC_GPIO0->CLR |= EN_VAL;
delay_ms(5);
}
void lcd_init(void)
{
delay_ms(100);
lcd_command(0x33);
lcd_command(0x32);
lcd_command(0x28);
lcd_command(0x0C);
lcd_command(0x06);
lcd_command(0x01);
delay_ms(200);
}
void delay_ms(long ms)
{
long i,j;
for (i = 0; i < ms; i++ )
for (j = 0; j < 26659; j++ );
}
void lcd_str(char *ch){
while(*ch)
{
lcd_data(*ch);
ch++;
}
}
void init_rtc(void)
{
LPC_SC->PCONP |= (1 << 9);
LPC_RTC->CCR = 0x13;
LPC_RTC->CCR = 0x11;
LPC_RTC->SEC = 00;
LPC_RTC->HOUR = 17;
LPC_RTC->MIN = 31;
LPC_RTC->DOM = 26;
LPC_RTC->MONTH= 05;
LPC_RTC->YEAR = 23;
LPC_RTC->ILR = 0x01;
}
75
Inference:
76
STM32F103XX Devices
The devices operate from a 2.0 to 3.6 V power supply. They are available in both
the –40 to +85 °C temperature range and the –40 to +105 °C extended temperature
range. A comprehensive set of power-saving mode allows the design of low-power
applications. The STM32F103xx medium-density performance line family includes
devices in six different package types: from 36 pins to 100 pins. Depending on the
device chosen, different sets of peripherals are included, the description below gives an
overview of the complete range of peripherals proposed in this family.
Key Features:
STM32CubeIDE
The STM32CubeIDE is an all-in-one multi-OS development tool, which is part of
the STM32Cube software ecosystem. STM32CubeIDE is an advanced C/C++
development platform with peripheral configuration, code generation, code
compilation, and debug features for STM32 microcontrollers and microprocessors. It
is based on the Eclipse®/CDT™ framework and GCC toolchain for the development,
and GDB for the debugging. It allows the integration of the hundreds of existing plugins
that complete the features of the Eclipse IDE.
The STM32CubeIDE includes build and stack analyzers that provide the user
with useful information about project status and memory requirements.
STM32CubeIDE also includes standard and advanced debugging features including
views of CPU core registers, memories, and peripheral registers, as well as live variable
watch, Serial Wire Viewer interface, or fault analyzer.
78
Key Features:
79
Interfacing 20x4 Character LCA Module with STM32F103C8T6 via I2C:
#include "i2c-lcd.h"
int row=0;
int col=0;
MX_GPIO_Init();
MX_I2C1_Init();
lcd_init ();
HAL_Delay(200);
lcd_clear ();
HAL_Delay(200);
lcd_put_cur(0, 0);
lcd_send_string("Welcome To STM World");
HAL_Delay(100);
lcd_put_cur(1, 0);
lcd_send_string("LCD Interface");
HAL_Delay(100);
80
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_SET);
while (1)
{
HAL_ADC_Start(&hadc1);
HAL_ADC_PollForConversion(&hadc1, 0);
AD_RES = HAL_ADC_GetValue(&hadc1);
ad_msb = AD_RES >>8;
ad_lsb = AD_RES;
temp = 0x0A;
HAL_UART_Transmit(&huart2, &ad_msb, 1, 100);
HAL_UART_Transmit(&huart2, &ad_lsb, 1, 100);
HAL_Delay(1000);
}
#include "stdio.h"
#include "string.h"
uint8_t RxData[64];
HAL_UART_Receive(&huart2, RxData, 2, 100);
HAL_UART_Transmit(&huart1, RxData, 2, 100);
int main(void)
{
MX_GPIO_Init();
MX_USART1_UART_Init();
MX_USART2_UART_Init();
while (1)
{
HAL_UART_Receive(&huart2, RxData, 2, 100);
HAL_UART_Transmit(&huart1, RxData, 2, 100);
}
}
static void MX_USART1_UART_Init(void)
81
{
huart1.Instance = USART1;
huart1.Init.BaudRate = 115200;
huart1.Init.WordLength = UART_WORDLENGTH_8B;
huart1.Init.StopBits = UART_STOPBITS_1;
huart1.Init.Parity = UART_PARITY_NONE;
huart1.Init.Mode = UART_MODE_TX_RX;
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
if (HAL_UART_Init(&huart1) != HAL_OK)
{
Error_Handler();
}
}
static void MX_USART2_UART_Init(void)
{
huart2.Instance = USART2;
huart2.Init.BaudRate = 115200;
huart2.Init.WordLength = UART_WORDLENGTH_8B;
huart2.Init.StopBits = UART_STOPBITS_1;
static void MX_USART2_UART_Init(void)
{
huart2.Init.Parity = UART_PARITY_NONE;
huart2.Init.Mode = UART_MODE_TX_RX;
huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart2.Init.OverSampling = UART_OVERSAMPLING_16;
if (HAL_UART_Init(&huart2) != HAL_OK)
{
Error_Handler();
}
}
82
Inference:
83
EXPERIMENTS USING
RTOS & IoT CONCEPTS
84
REAL TIME OPERATING SYSTEM
Introduction:
A Real-Time OS (RTOS) is an OS with special features that make it suitable for
building real time computing applications also referred to as Real-Time Systems (RTS).
An RTS is a (computing) system where correctness of computing depends not only on
the correctness of the logical result of the computation, but also on the result delivery
time. An RTS is expected to respond in a timely, predictable way to unpredictable
external stimuli.
Real-time systems can be categorized as Hard or Soft. For a Hard RTS, the
system is taken to have failed if a computing deadline is not met. In a Soft RTS, a
limited extent of failure in meeting deadlines results in degraded performance of the
system and not catastrophic failure. The correctness and performance of an RTS is
therefore not measured in terms of parameters such as, average number of
transactions per second as in transactional systems such as databases.
A good RTOS is the one that enables bounded (predictable) behaviour under all
system load scenarios. Note however, that the RTOS, by itself cannot guarantee system
correctness, but only is an enabling technology. That is, it provides the application
programmer with facilities using which a correct application can be built. Speed,
although important for meeting the overall requirements, does not by itself meet the
requirements for an RTOS.
µC/OS- II:
µC/OS-II is a free RTOS, easily available on Internet. It is written in ANSI C and
contains small portion of assembly code. The assembly language portion has been kept
to a minimum to make it easy to port it to different processors. To date, µC/OS-II has
been ported to over 100 different processor architectures ranging from 8-bit to 64-bit
microprocessors, microcontrollers, and DSPs. Some important features of µC/OS-II are
highlighted in the following.
µC/OS-II was designed so that the programmer can use just a few of the offered
services or select the entire range of services. This allows the programmer to
minimize the amount of memory needed by µC/OS-II on a per-product basis.
85
µC/OS-II has a fully preemptive kernel. This means that µC/OS-II always
ensures that the highest priority task that is ready would be taken up for
execution.
µC/OS-II allows up to 64 tasks to be created. Each task operates at a unique
priority level. There are 64 priority levels. This means that round-robin
scheduling is not supported. The priority levels are used as the PID (Process
Identifier) for the tasks.
µC/OS-II uses a partitioned memory management. Each memory partition
consists of several fixed sized blocks. A task obtains memory blocks from the
memory partition and the task must create a memory partition before it can be
used. Allocation and deallocation of fixed-sized memory blocks is done in
constant time and is deterministic. A task can create and use multiple memory
partitions, so that it can use memory blocks of different sizes.
µC/OS-II has been certified by Federal Aviation Administration (FAA) for use in
commercial aircraft by meeting the demanding requirements of its standard for
software used in avionics. To meet the requirements of this standard it was
demonstrated through documentation and testing that it is robust and safe.
86
INTERNET OF THINGS
Introduction:
The Internet of Things, simply IoT, refers to the billions of physical devices
around the globe connected to the internet, with the purpose of collecting and sharing
information. Thanks to the arrival of super-cheap computer chips and the ubiquity of
wireless networks, it's possible to accommodate almost everything into a part of the
IoT. Connecting up all these different objects and adding sensors to them adds a level
of digital intelligence to devices that would be otherwise dumb, enabling them to
communicate real-time data without human intervention. The IoT makes the fabric of
the world around us smarter and more responsive, merging the digital and physical
universes.
The Industrial Internet of Things (IIoT) exemplifies the use of IoT technology in
a business set up. Though the concept remains the same as the consumer IoT devices
being used at home, when it comes to IIoT big data analytics and AI assume crucial
significance to realize the true potential of IoT in industrial applications.
If introduced across an entire supply chain, rather than just individual
companies, the impact could be even greater with just-in-time delivery of materials and
the management of production from design phase to shipment. The concept of IIoT
brings new revenue streams for businesses rather than just selling a standalone
product,say, an engine – manufacturers can also sell predictive maintenance of the
engine.
Key Features:
Connectivity: Connectivity refers to establish a proper connection between all the
things of IoT to IoT platform it may be server or cloud. After connecting the IoT devices,
it needs a high speed messaging between the devices and cloud to enable reliable,
secure and bi-directional communication.
Analyzing: After connecting all the relevant things, it comes to real-time analyzing the
data collected and use them to build effective business intelligence. If we have a good
insight into data gathered from all these things, then we call our system has a smart
system.
Integrating: IoT integrating the various models to improve the user experience as well.
87
Artificial Intelligence: IoT makes things smart and enhances life through the use of
data. For example, if we have a coffee machine whose beans have going to end, then
the coffee machine itself order the coffee beans of your choice from the retailer.
Sensing: The sensor devices used in IoT technologies detect and measure any change
in the environment and report on their status. IoT technology brings passive networks
to active networks. Without sensors, there could not hold an effective or true IoT
environment.
88
Stage 1 of an IoT architecture consists of your networked things, typically wireless
sensors and actuators.
Stage 2 includes sensor data aggregation systems and analog-to-digital data
conversion.
Stage 3include edge IT systems perform pre-processing of the data before it moves on
to the data centre or cloud.
Stage 4include the data is analysed, managed, and stored on traditional back-end data
centre systems.
Raspberry Pi
Software developer Eben Upton and Software Engineers Pete Lomas and David
Braden formed the Raspberry Pi foundation in 2006. The main aim of this foundation
was to devise a computer to inspire children. Hence, in order to reduce the cost, the
early prototypes of the Raspberry Pi were based on the 8-bit Atmel ATmega
microcontroller.
On February 29th, 2012, the team started taking the orders for Model B and in
the same year, they started its production run which consisted of around 10,000 units.
These models were manufactured by the founders in China and Taiwan. On February
4th, 2013, they started taking the orders for lower cost Model A. Similarly, on November
10th, 2014, the team launched for even more low-cost Model A+.
The cheapest Raspberry Pi Zero was launched on November 26th, 2015. The
name Raspberry Pi was chosen with “Raspberry” as a tradition of naming early
computer companies after fruit. Here, “Pi” is for Python Programming Language.
89
a Raspberry Pi can do anything a bigger and more power-hungry computer can do,
though not necessarily as quickly.
The Raspberry Pi family was born from a desire to encourage more hands-on
computer education around the world. Its creators, who joined together to form the
non-profit Raspberry Pi Foundation, had little idea that it would prove so popular: the
few thousand built in 2012 to test the waters were immediately sold out, and millions
have been shipped all over the world in the years since. These boards have found their
ways into homes, classrooms, offices, data centres, factories, and even self-piloting
boats and spacefaring balloons.
Various models of Raspberry Pi have been released since the original Model B,
each bringing either improved specifications or features specific to a particular use-
case. The Raspberry Pi Zero family, for example, is a tiny version of the full-size
Raspberry Pi which drops a few features – in particular the multiple USB ports and
wired network port – in favour of a significantly smaller layout and reduced power
requirements.
All Raspberry Pi models have one thing in common, though: they’re compatible,
meaning that software written for one model will run on any other model. It’s even
possible to take the very latest version of Raspberry Pi’s operating system and run it
on an original pre-launch Model B prototype. It will run more slowly, it’s true, but it
will still run.
90
IoT Enabled Real Time Monitoring of a Temperature Process using Raspberry Pi:
import RPi.GPIO as GPIO
import time
import urllib
import http.client as httplib
import sys
IO.setwarnings(False)
key = “ROM76DAI9SZU8DB0"
b0 =0
b1 =0
b2 =0
b3 =0
b4 =0
b5 =0
b6 =0
b7 =0
GPIO.setmode (GPIO.BCM)
GPIO.setup(19, GPIO.IN)
GPIO.setup(13, GPIO.IN)
GPIO.setup(6, GPIO.IN)
GPIO.setup(5, GPIO.IN)
GPIO.setup(22, GPIO.IN)
GPIO.setup(27, GPIO.IN)
GPIO.setup(17, GPIO.IN)
GPIO.setup(4, GPIO.IN)
while 1:
if (GPIO.input(19) == True):
time.sleep(0.001)
if (GPIO.input(19) == True):
b7=1
91
if (GPIO.input(13) == True):
time.sleep(0.001)
if (GPIO.input(13) == True):
b6=1
if (GPIO.input(6) == True):
time.sleep(0.001)
if (GPIO.input(6) == True):
b5=1
if (GPIO.input(17) == True):
time.sleep(0.001)
if (GPIO.input(17) == True):
b1=1
if (GPIO.input(4) == True):
time.sleep(0.001)
if (GPIO.input(4) == True):
b0=1
x = (1*b0)+(2*b1)
x = x+(4*b2)+(8*b3)
x = x+(16*b4)+(32*b5)
x = x+(64*b6)+(128*b7)
93