SlideShare a Scribd company logo
DR. VIKAS J. DONGRE
HOD ELECTRONICS & TELECOM
GOVERNMENT POLYTECHNIC WASHIM (MS)
EMAIL: DONGREVJ1@GMAIL.COM
Arithmetic operations
• Add +
• Subtract –
• Multiply *
• Divide /
• Mod %
#include <reg51.h>
void main(void)
{
unsigned char a,b,c;
while(1)
{
P1=0xff;
P2=0xff;
a=P1;
b=P2;
c=a+b;
P3=c;
}
}
Logical operations
 Logical operators
 AND (&&), OR (||), and NOT (!)
 Bit-wise operators
 AND (&), OR (|), EX-OR (^), Inverter (~), Shift Right
(>>), and Shift Left (<<)
 These operators are widely used in software
engineering for embedded systems and control
AND OR EX-OR Inverter
A B A&B A|B A^B ~B
0 0 0 0 0 1
0 1 0 1 1 0
1 0 0 1 1
1 1 1 1 0
Bit-wise Logic Operators for C
P1= 0x9A >> 3;
P2= 0x77 >> 4;
P0= 0x6 << 4;
Write an 8051 C program to toggle bits of P1
continuously forever with some delay.
Solution:
//Toggle P1 forever with some delay between “on” and “off”
#include <reg51.h>
void main(void)
{
unsigned int x;
for (;;) //repeat forever
{
p1=0x55;
for (x=0;x<40000;x++); //delay size//unknown
p1=0xAA;
for (x=0;x<40000;x++);
}
}
Write an 8051 C program to toggle all the bits of P1
continuously.
Solution:
//Toggle P1 forever
#include <reg51.h>
void main(void)
{
for (;;)
{
P1=0x55;
P1=0xAA;
}
}
Write an 8051 C program to toggle bit D0 of the
port P1 (P1.0) 50,000 times.
Solution:
#include <reg51.h>
sbit MYBIT=P1^0;
void main(void)
{
unsigned int z;
for (z=0;z<=50000;z++)
{
MYBIT=0;
MYBIT=1;
}
}
To create Time delay --
Three factors that can affect the accuracy of the delay-
1. The 8051 design..
The number of machine cycle
The number of clock periods per machine cycle
2. The crystal frequency connected to the X1 – X2 input pins
3. Compiler choice
C compiler converts the C statements and functions to Assembly
language instructions
Different compilers produce different code
Write an 8051 C program to toggle bits of P1 ports
continuously with a 250 ms.
Solution:
#include <reg51.h>
void MSDelay(unsigned int);
void main(void)
{while (1)
{
P1=0x55;
MSDelay(250);
P1=0xAA;
MSDelay(250);
}
}
void MSDelay(unsigned int itime)
{
unsigned int i,j;
for (i=0;i<itime;i++)
for (j=0;j<1275;j++);
}
Logic Operations in C
#include <reg51.h>
void main (void)
{
P0= 0x35 & 0x0F;
P1= 0x04 | 0x68;
P2= 0x54 ^ 0x78;
P0= ~0x55;
P1= 0x9A >> 3;
P2= 0x77 >> 4;
P0= 0x6 << 4;
}
Arithmetic and Logic instructions in Embedded C
Ad

More Related Content

What's hot (20)

Verilog presentation final
Verilog presentation finalVerilog presentation final
Verilog presentation final
Ankur Gupta
 
8155 PPI
8155 PPI8155 PPI
8155 PPI
ShivamSood22
 
Periodic vs. aperiodic signal
Periodic vs. aperiodic signalPeriodic vs. aperiodic signal
Periodic vs. aperiodic signal
Tahsin Abrar
 
Multiplexers & Demultiplexers
Multiplexers & DemultiplexersMultiplexers & Demultiplexers
Multiplexers & Demultiplexers
Jayanshu Gundaniya
 
Encoder & Decoder
Encoder & DecoderEncoder & Decoder
Encoder & Decoder
Syed Saeed
 
Chapter 7 8051 programming in c
Chapter 7  8051 programming in cChapter 7  8051 programming in c
Chapter 7 8051 programming in c
Abdelrahman Elewah
 
LCD Interacing with 8051
LCD Interacing with 8051LCD Interacing with 8051
LCD Interacing with 8051
Sudhanshu Janwadkar
 
Verilog hdl
Verilog hdlVerilog hdl
Verilog hdl
Muhammad Uzair Rasheed
 
8251 USART
8251 USART8251 USART
8251 USART
ShivamSood22
 
8051 microcontroller
8051 microcontroller 8051 microcontroller
8051 microcontroller
Gaurav Verma
 
8051 Microcontroller PPT's By Er. Swapnil Kaware
8051 Microcontroller PPT's By Er. Swapnil Kaware8051 Microcontroller PPT's By Er. Swapnil Kaware
8051 Microcontroller PPT's By Er. Swapnil Kaware
Prof. Swapnil V. Kaware
 
Properties of fourier transform
Properties of fourier transformProperties of fourier transform
Properties of fourier transform
Nisarg Amin
 
Signals and Systems: Energy and Power Signals
Signals and Systems: Energy and Power SignalsSignals and Systems: Energy and Power Signals
Signals and Systems: Energy and Power Signals
nishtha97
 
8086 micro processor
8086 micro processor8086 micro processor
8086 micro processor
Poojith Chowdhary
 
Verilog VHDL code Decoder and Encoder
Verilog VHDL code Decoder and EncoderVerilog VHDL code Decoder and Encoder
Verilog VHDL code Decoder and Encoder
Bharti Airtel Ltd.
 
Bcd
BcdBcd
Bcd
Talha Fazal
 
Addressing modes of 8086
Addressing modes of 8086Addressing modes of 8086
Addressing modes of 8086
Dr. AISHWARYA N
 
Data flow model -Lecture-4
Data flow model -Lecture-4Data flow model -Lecture-4
Data flow model -Lecture-4
Dr.YNM
 
Keyboard Interfacing .pptx
Keyboard Interfacing .pptxKeyboard Interfacing .pptx
Keyboard Interfacing .pptx
livaunnoor
 
Addressing modes of 8086
Addressing modes of 8086Addressing modes of 8086
Addressing modes of 8086
saurav kumar
 
Verilog presentation final
Verilog presentation finalVerilog presentation final
Verilog presentation final
Ankur Gupta
 
Periodic vs. aperiodic signal
Periodic vs. aperiodic signalPeriodic vs. aperiodic signal
Periodic vs. aperiodic signal
Tahsin Abrar
 
Encoder & Decoder
Encoder & DecoderEncoder & Decoder
Encoder & Decoder
Syed Saeed
 
Chapter 7 8051 programming in c
Chapter 7  8051 programming in cChapter 7  8051 programming in c
Chapter 7 8051 programming in c
Abdelrahman Elewah
 
8051 microcontroller
8051 microcontroller 8051 microcontroller
8051 microcontroller
Gaurav Verma
 
8051 Microcontroller PPT's By Er. Swapnil Kaware
8051 Microcontroller PPT's By Er. Swapnil Kaware8051 Microcontroller PPT's By Er. Swapnil Kaware
8051 Microcontroller PPT's By Er. Swapnil Kaware
Prof. Swapnil V. Kaware
 
Properties of fourier transform
Properties of fourier transformProperties of fourier transform
Properties of fourier transform
Nisarg Amin
 
Signals and Systems: Energy and Power Signals
Signals and Systems: Energy and Power SignalsSignals and Systems: Energy and Power Signals
Signals and Systems: Energy and Power Signals
nishtha97
 
Verilog VHDL code Decoder and Encoder
Verilog VHDL code Decoder and EncoderVerilog VHDL code Decoder and Encoder
Verilog VHDL code Decoder and Encoder
Bharti Airtel Ltd.
 
Addressing modes of 8086
Addressing modes of 8086Addressing modes of 8086
Addressing modes of 8086
Dr. AISHWARYA N
 
Data flow model -Lecture-4
Data flow model -Lecture-4Data flow model -Lecture-4
Data flow model -Lecture-4
Dr.YNM
 
Keyboard Interfacing .pptx
Keyboard Interfacing .pptxKeyboard Interfacing .pptx
Keyboard Interfacing .pptx
livaunnoor
 
Addressing modes of 8086
Addressing modes of 8086Addressing modes of 8086
Addressing modes of 8086
saurav kumar
 

Similar to Arithmetic and Logic instructions in Embedded C (20)

Arithmetic and logic operations in c
Arithmetic and logic operations in cArithmetic and logic operations in c
Arithmetic and logic operations in c
Vikas Dongre
 
Arithmetic and logic operations in c
Arithmetic and logic operations in cArithmetic and logic operations in c
Arithmetic and logic operations in c
Vikas Dongre
 
8051 programming in c
8051 programming in c8051 programming in c
8051 programming in c
Dr. Ritula Thakur
 
Jp
Jp Jp
Jp
vijaydeepakg
 
Intel 8051 Programming in C
Intel 8051 Programming in CIntel 8051 Programming in C
Intel 8051 Programming in C
Sudhanshu Janwadkar
 
8051 programming skills using EMBEDDED C
8051 programming skills using EMBEDDED C8051 programming skills using EMBEDDED C
8051 programming skills using EMBEDDED C
Aman Sharma
 
Embedded C programming based on 8051 microcontroller
Embedded C programming based on 8051 microcontrollerEmbedded C programming based on 8051 microcontroller
Embedded C programming based on 8051 microcontroller
Gaurav Verma
 
Verilogforlab
VerilogforlabVerilogforlab
Verilogforlab
Shankar Bhukya
 
3306617
33066173306617
3306617
shwetakks
 
6 arithmetic logic inst and prog
6 arithmetic logic inst and prog6 arithmetic logic inst and prog
6 arithmetic logic inst and prog
Channabasappa Kudarihal
 
Lenguaje de Programación en C Presentacion
Lenguaje de Programación en C PresentacionLenguaje de Programación en C Presentacion
Lenguaje de Programación en C Presentacion
jicemtec
 
CS3691 ESIOT UNIT 2 EMBEDDED C PROGRAMING 6TH SEM CSE
CS3691 ESIOT UNIT 2 EMBEDDED C PROGRAMING 6TH SEM CSECS3691 ESIOT UNIT 2 EMBEDDED C PROGRAMING 6TH SEM CSE
CS3691 ESIOT UNIT 2 EMBEDDED C PROGRAMING 6TH SEM CSE
PREMKUMARS76
 
Chapter 5
Chapter 5Chapter 5
Chapter 5
EasyStudy3
 
Interesting facts on c
Interesting facts on cInteresting facts on c
Interesting facts on c
Durgadevi palani
 
Instruction Set Architecture
Instruction Set ArchitectureInstruction Set Architecture
Instruction Set Architecture
Dilum Bandara
 
Operators in C programming language.pptx
Operators in C programming language.pptxOperators in C programming language.pptx
Operators in C programming language.pptx
b221382
 
EMBEDDED SYSTEMS 4&5
EMBEDDED SYSTEMS 4&5EMBEDDED SYSTEMS 4&5
EMBEDDED SYSTEMS 4&5
PRADEEP
 
Develop Embedded Software Module-Session 2
Develop Embedded Software Module-Session 2Develop Embedded Software Module-Session 2
Develop Embedded Software Module-Session 2
Naveen Kumar
 
Microprocessor and Microcontroller Lab Manual!
Microprocessor and Microcontroller Lab Manual!Microprocessor and Microcontroller Lab Manual!
Microprocessor and Microcontroller Lab Manual!
PRABHAHARAN429
 
Register transfer &amp; microoperations moris mano ch 04
Register transfer &amp; microoperations    moris mano ch 04Register transfer &amp; microoperations    moris mano ch 04
Register transfer &amp; microoperations moris mano ch 04
thearticlenow
 
Arithmetic and logic operations in c
Arithmetic and logic operations in cArithmetic and logic operations in c
Arithmetic and logic operations in c
Vikas Dongre
 
Arithmetic and logic operations in c
Arithmetic and logic operations in cArithmetic and logic operations in c
Arithmetic and logic operations in c
Vikas Dongre
 
8051 programming skills using EMBEDDED C
8051 programming skills using EMBEDDED C8051 programming skills using EMBEDDED C
8051 programming skills using EMBEDDED C
Aman Sharma
 
Embedded C programming based on 8051 microcontroller
Embedded C programming based on 8051 microcontrollerEmbedded C programming based on 8051 microcontroller
Embedded C programming based on 8051 microcontroller
Gaurav Verma
 
Lenguaje de Programación en C Presentacion
Lenguaje de Programación en C PresentacionLenguaje de Programación en C Presentacion
Lenguaje de Programación en C Presentacion
jicemtec
 
CS3691 ESIOT UNIT 2 EMBEDDED C PROGRAMING 6TH SEM CSE
CS3691 ESIOT UNIT 2 EMBEDDED C PROGRAMING 6TH SEM CSECS3691 ESIOT UNIT 2 EMBEDDED C PROGRAMING 6TH SEM CSE
CS3691 ESIOT UNIT 2 EMBEDDED C PROGRAMING 6TH SEM CSE
PREMKUMARS76
 
Instruction Set Architecture
Instruction Set ArchitectureInstruction Set Architecture
Instruction Set Architecture
Dilum Bandara
 
Operators in C programming language.pptx
Operators in C programming language.pptxOperators in C programming language.pptx
Operators in C programming language.pptx
b221382
 
EMBEDDED SYSTEMS 4&5
EMBEDDED SYSTEMS 4&5EMBEDDED SYSTEMS 4&5
EMBEDDED SYSTEMS 4&5
PRADEEP
 
Develop Embedded Software Module-Session 2
Develop Embedded Software Module-Session 2Develop Embedded Software Module-Session 2
Develop Embedded Software Module-Session 2
Naveen Kumar
 
Microprocessor and Microcontroller Lab Manual!
Microprocessor and Microcontroller Lab Manual!Microprocessor and Microcontroller Lab Manual!
Microprocessor and Microcontroller Lab Manual!
PRABHAHARAN429
 
Register transfer &amp; microoperations moris mano ch 04
Register transfer &amp; microoperations    moris mano ch 04Register transfer &amp; microoperations    moris mano ch 04
Register transfer &amp; microoperations moris mano ch 04
thearticlenow
 
Ad

More from Vikas Dongre (20)

Lcd interfaing using 8051 and assambly language programming
Lcd interfaing using 8051 and assambly language programmingLcd interfaing using 8051 and assambly language programming
Lcd interfaing using 8051 and assambly language programming
Vikas Dongre
 
Job opportunities for electronics engineering
Job opportunities for electronics engineeringJob opportunities for electronics engineering
Job opportunities for electronics engineering
Vikas Dongre
 
Educational video creation: Tools and tips
Educational video creation: Tools and tipsEducational video creation: Tools and tips
Educational video creation: Tools and tips
Vikas Dongre
 
Scope of job education and business after HSC
Scope of job  education and business after HSCScope of job  education and business after HSC
Scope of job education and business after HSC
Vikas Dongre
 
Introduction to digital logic gates
Introduction to digital logic gatesIntroduction to digital logic gates
Introduction to digital logic gates
Vikas Dongre
 
Introduction to binary number system
Introduction to binary number systemIntroduction to binary number system
Introduction to binary number system
Vikas Dongre
 
Timer programming for 8051 using embedded c
Timer programming for 8051 using embedded cTimer programming for 8051 using embedded c
Timer programming for 8051 using embedded c
Vikas Dongre
 
Introduction to Embedded system programming using 8051
Introduction to Embedded system programming using 8051Introduction to Embedded system programming using 8051
Introduction to Embedded system programming using 8051
Vikas Dongre
 
Interrupts programming in embedded C using 8051
Interrupts programming in embedded C using 8051Interrupts programming in embedded C using 8051
Interrupts programming in embedded C using 8051
Vikas Dongre
 
Classification of embedded systems
Classification of embedded systemsClassification of embedded systems
Classification of embedded systems
Vikas Dongre
 
Characteristics of embedded systems
Characteristics of embedded systemsCharacteristics of embedded systems
Characteristics of embedded systems
Vikas Dongre
 
Features of 89c51,pic,avr &amp; arm processors
Features of 89c51,pic,avr &amp; arm processorsFeatures of 89c51,pic,avr &amp; arm processors
Features of 89c51,pic,avr &amp; arm processors
Vikas Dongre
 
Microcontroller architecture
Microcontroller architectureMicrocontroller architecture
Microcontroller architecture
Vikas Dongre
 
2. block diagram and components of embedded system
2. block diagram and components of embedded system2. block diagram and components of embedded system
2. block diagram and components of embedded system
Vikas Dongre
 
1. advantages and applications of embedded system
1. advantages and applications of embedded system1. advantages and applications of embedded system
1. advantages and applications of embedded system
Vikas Dongre
 
Serial communication
Serial communicationSerial communication
Serial communication
Vikas Dongre
 
Innovative improvements in electronic engineering laboratory education using eml
Innovative improvements in electronic engineering laboratory education using emlInnovative improvements in electronic engineering laboratory education using eml
Innovative improvements in electronic engineering laboratory education using eml
Vikas Dongre
 
Devnagari handwritten numeral recognition using geometric features and statis...
Devnagari handwritten numeral recognition using geometric features and statis...Devnagari handwritten numeral recognition using geometric features and statis...
Devnagari handwritten numeral recognition using geometric features and statis...
Vikas Dongre
 
Development of comprehensive devnagari numaral and character database
Development of comprehensive devnagari numaral and character databaseDevelopment of comprehensive devnagari numaral and character database
Development of comprehensive devnagari numaral and character database
Vikas Dongre
 
Devnagari document segmentation using histogram approach
Devnagari document segmentation using histogram approachDevnagari document segmentation using histogram approach
Devnagari document segmentation using histogram approach
Vikas Dongre
 
Lcd interfaing using 8051 and assambly language programming
Lcd interfaing using 8051 and assambly language programmingLcd interfaing using 8051 and assambly language programming
Lcd interfaing using 8051 and assambly language programming
Vikas Dongre
 
Job opportunities for electronics engineering
Job opportunities for electronics engineeringJob opportunities for electronics engineering
Job opportunities for electronics engineering
Vikas Dongre
 
Educational video creation: Tools and tips
Educational video creation: Tools and tipsEducational video creation: Tools and tips
Educational video creation: Tools and tips
Vikas Dongre
 
Scope of job education and business after HSC
Scope of job  education and business after HSCScope of job  education and business after HSC
Scope of job education and business after HSC
Vikas Dongre
 
Introduction to digital logic gates
Introduction to digital logic gatesIntroduction to digital logic gates
Introduction to digital logic gates
Vikas Dongre
 
Introduction to binary number system
Introduction to binary number systemIntroduction to binary number system
Introduction to binary number system
Vikas Dongre
 
Timer programming for 8051 using embedded c
Timer programming for 8051 using embedded cTimer programming for 8051 using embedded c
Timer programming for 8051 using embedded c
Vikas Dongre
 
Introduction to Embedded system programming using 8051
Introduction to Embedded system programming using 8051Introduction to Embedded system programming using 8051
Introduction to Embedded system programming using 8051
Vikas Dongre
 
Interrupts programming in embedded C using 8051
Interrupts programming in embedded C using 8051Interrupts programming in embedded C using 8051
Interrupts programming in embedded C using 8051
Vikas Dongre
 
Classification of embedded systems
Classification of embedded systemsClassification of embedded systems
Classification of embedded systems
Vikas Dongre
 
Characteristics of embedded systems
Characteristics of embedded systemsCharacteristics of embedded systems
Characteristics of embedded systems
Vikas Dongre
 
Features of 89c51,pic,avr &amp; arm processors
Features of 89c51,pic,avr &amp; arm processorsFeatures of 89c51,pic,avr &amp; arm processors
Features of 89c51,pic,avr &amp; arm processors
Vikas Dongre
 
Microcontroller architecture
Microcontroller architectureMicrocontroller architecture
Microcontroller architecture
Vikas Dongre
 
2. block diagram and components of embedded system
2. block diagram and components of embedded system2. block diagram and components of embedded system
2. block diagram and components of embedded system
Vikas Dongre
 
1. advantages and applications of embedded system
1. advantages and applications of embedded system1. advantages and applications of embedded system
1. advantages and applications of embedded system
Vikas Dongre
 
Serial communication
Serial communicationSerial communication
Serial communication
Vikas Dongre
 
Innovative improvements in electronic engineering laboratory education using eml
Innovative improvements in electronic engineering laboratory education using emlInnovative improvements in electronic engineering laboratory education using eml
Innovative improvements in electronic engineering laboratory education using eml
Vikas Dongre
 
Devnagari handwritten numeral recognition using geometric features and statis...
Devnagari handwritten numeral recognition using geometric features and statis...Devnagari handwritten numeral recognition using geometric features and statis...
Devnagari handwritten numeral recognition using geometric features and statis...
Vikas Dongre
 
Development of comprehensive devnagari numaral and character database
Development of comprehensive devnagari numaral and character databaseDevelopment of comprehensive devnagari numaral and character database
Development of comprehensive devnagari numaral and character database
Vikas Dongre
 
Devnagari document segmentation using histogram approach
Devnagari document segmentation using histogram approachDevnagari document segmentation using histogram approach
Devnagari document segmentation using histogram approach
Vikas Dongre
 
Ad

Recently uploaded (20)

DED KOMINFO detail engginering design gedung
DED KOMINFO detail engginering design gedungDED KOMINFO detail engginering design gedung
DED KOMINFO detail engginering design gedung
nabilarizqifadhilah1
 
Machine foundation notes for civil engineering students
Machine foundation notes for civil engineering studentsMachine foundation notes for civil engineering students
Machine foundation notes for civil engineering students
DYPCET
 
Little Known Ways To 3 Best sites to Buy Linkedin Accounts.pdf
Little Known Ways To 3 Best sites to Buy Linkedin Accounts.pdfLittle Known Ways To 3 Best sites to Buy Linkedin Accounts.pdf
Little Known Ways To 3 Best sites to Buy Linkedin Accounts.pdf
gori42199
 
Automatic Quality Assessment for Speech and Beyond
Automatic Quality Assessment for Speech and BeyondAutomatic Quality Assessment for Speech and Beyond
Automatic Quality Assessment for Speech and Beyond
NU_I_TODALAB
 
ML_Unit_VI_DEEP LEARNING_Introduction to ANN.pdf
ML_Unit_VI_DEEP LEARNING_Introduction to ANN.pdfML_Unit_VI_DEEP LEARNING_Introduction to ANN.pdf
ML_Unit_VI_DEEP LEARNING_Introduction to ANN.pdf
rameshwarchintamani
 
Frontend Architecture Diagram/Guide For Frontend Engineers
Frontend Architecture Diagram/Guide For Frontend EngineersFrontend Architecture Diagram/Guide For Frontend Engineers
Frontend Architecture Diagram/Guide For Frontend Engineers
Michael Hertzberg
 
hypermedia_system_revisit_roy_fielding .
hypermedia_system_revisit_roy_fielding .hypermedia_system_revisit_roy_fielding .
hypermedia_system_revisit_roy_fielding .
NABLAS株式会社
 
David Boutry - Specializes In AWS, Microservices And Python.pdf
David Boutry - Specializes In AWS, Microservices And Python.pdfDavid Boutry - Specializes In AWS, Microservices And Python.pdf
David Boutry - Specializes In AWS, Microservices And Python.pdf
David Boutry
 
Control Methods of Noise Pollutions.pptx
Control Methods of Noise Pollutions.pptxControl Methods of Noise Pollutions.pptx
Control Methods of Noise Pollutions.pptx
vvsasane
 
Lecture - 7 Canals of the topic of the civil engineering
Lecture - 7  Canals of the topic of the civil engineeringLecture - 7  Canals of the topic of the civil engineering
Lecture - 7 Canals of the topic of the civil engineering
MJawadkhan1
 
Working with USDOT UTCs: From Conception to Implementation
Working with USDOT UTCs: From Conception to ImplementationWorking with USDOT UTCs: From Conception to Implementation
Working with USDOT UTCs: From Conception to Implementation
Alabama Transportation Assistance Program
 
Design of Variable Depth Single-Span Post.pdf
Design of Variable Depth Single-Span Post.pdfDesign of Variable Depth Single-Span Post.pdf
Design of Variable Depth Single-Span Post.pdf
Kamel Farid
 
Nanometer Metal-Organic-Framework Literature Comparison
Nanometer Metal-Organic-Framework  Literature ComparisonNanometer Metal-Organic-Framework  Literature Comparison
Nanometer Metal-Organic-Framework Literature Comparison
Chris Harding
 
Generative AI & Large Language Models Agents
Generative AI & Large Language Models AgentsGenerative AI & Large Language Models Agents
Generative AI & Large Language Models Agents
aasgharbee22seecs
 
Applications of Centroid in Structural Engineering
Applications of Centroid in Structural EngineeringApplications of Centroid in Structural Engineering
Applications of Centroid in Structural Engineering
suvrojyotihalder2006
 
Agents chapter of Artificial intelligence
Agents chapter of Artificial intelligenceAgents chapter of Artificial intelligence
Agents chapter of Artificial intelligence
DebdeepMukherjee9
 
6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)
6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)
6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)
ijflsjournal087
 
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjjseninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
AjijahamadKhaji
 
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
ajayrm685
 
Jacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia - Excels In Optimizing Software ApplicationsJacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia
 
DED KOMINFO detail engginering design gedung
DED KOMINFO detail engginering design gedungDED KOMINFO detail engginering design gedung
DED KOMINFO detail engginering design gedung
nabilarizqifadhilah1
 
Machine foundation notes for civil engineering students
Machine foundation notes for civil engineering studentsMachine foundation notes for civil engineering students
Machine foundation notes for civil engineering students
DYPCET
 
Little Known Ways To 3 Best sites to Buy Linkedin Accounts.pdf
Little Known Ways To 3 Best sites to Buy Linkedin Accounts.pdfLittle Known Ways To 3 Best sites to Buy Linkedin Accounts.pdf
Little Known Ways To 3 Best sites to Buy Linkedin Accounts.pdf
gori42199
 
Automatic Quality Assessment for Speech and Beyond
Automatic Quality Assessment for Speech and BeyondAutomatic Quality Assessment for Speech and Beyond
Automatic Quality Assessment for Speech and Beyond
NU_I_TODALAB
 
ML_Unit_VI_DEEP LEARNING_Introduction to ANN.pdf
ML_Unit_VI_DEEP LEARNING_Introduction to ANN.pdfML_Unit_VI_DEEP LEARNING_Introduction to ANN.pdf
ML_Unit_VI_DEEP LEARNING_Introduction to ANN.pdf
rameshwarchintamani
 
Frontend Architecture Diagram/Guide For Frontend Engineers
Frontend Architecture Diagram/Guide For Frontend EngineersFrontend Architecture Diagram/Guide For Frontend Engineers
Frontend Architecture Diagram/Guide For Frontend Engineers
Michael Hertzberg
 
hypermedia_system_revisit_roy_fielding .
hypermedia_system_revisit_roy_fielding .hypermedia_system_revisit_roy_fielding .
hypermedia_system_revisit_roy_fielding .
NABLAS株式会社
 
David Boutry - Specializes In AWS, Microservices And Python.pdf
David Boutry - Specializes In AWS, Microservices And Python.pdfDavid Boutry - Specializes In AWS, Microservices And Python.pdf
David Boutry - Specializes In AWS, Microservices And Python.pdf
David Boutry
 
Control Methods of Noise Pollutions.pptx
Control Methods of Noise Pollutions.pptxControl Methods of Noise Pollutions.pptx
Control Methods of Noise Pollutions.pptx
vvsasane
 
Lecture - 7 Canals of the topic of the civil engineering
Lecture - 7  Canals of the topic of the civil engineeringLecture - 7  Canals of the topic of the civil engineering
Lecture - 7 Canals of the topic of the civil engineering
MJawadkhan1
 
Design of Variable Depth Single-Span Post.pdf
Design of Variable Depth Single-Span Post.pdfDesign of Variable Depth Single-Span Post.pdf
Design of Variable Depth Single-Span Post.pdf
Kamel Farid
 
Nanometer Metal-Organic-Framework Literature Comparison
Nanometer Metal-Organic-Framework  Literature ComparisonNanometer Metal-Organic-Framework  Literature Comparison
Nanometer Metal-Organic-Framework Literature Comparison
Chris Harding
 
Generative AI & Large Language Models Agents
Generative AI & Large Language Models AgentsGenerative AI & Large Language Models Agents
Generative AI & Large Language Models Agents
aasgharbee22seecs
 
Applications of Centroid in Structural Engineering
Applications of Centroid in Structural EngineeringApplications of Centroid in Structural Engineering
Applications of Centroid in Structural Engineering
suvrojyotihalder2006
 
Agents chapter of Artificial intelligence
Agents chapter of Artificial intelligenceAgents chapter of Artificial intelligence
Agents chapter of Artificial intelligence
DebdeepMukherjee9
 
6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)
6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)
6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)
ijflsjournal087
 
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjjseninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
AjijahamadKhaji
 
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
ajayrm685
 
Jacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia - Excels In Optimizing Software ApplicationsJacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia
 

Arithmetic and Logic instructions in Embedded C

  • 1. DR. VIKAS J. DONGRE HOD ELECTRONICS & TELECOM GOVERNMENT POLYTECHNIC WASHIM (MS) EMAIL: [email protected]
  • 2. Arithmetic operations • Add + • Subtract – • Multiply * • Divide / • Mod %
  • 3. #include <reg51.h> void main(void) { unsigned char a,b,c; while(1) { P1=0xff; P2=0xff; a=P1; b=P2; c=a+b; P3=c; } }
  • 4. Logical operations  Logical operators  AND (&&), OR (||), and NOT (!)  Bit-wise operators  AND (&), OR (|), EX-OR (^), Inverter (~), Shift Right (>>), and Shift Left (<<)  These operators are widely used in software engineering for embedded systems and control
  • 5. AND OR EX-OR Inverter A B A&B A|B A^B ~B 0 0 0 0 0 1 0 1 0 1 1 0 1 0 0 1 1 1 1 1 1 0 Bit-wise Logic Operators for C
  • 6. P1= 0x9A >> 3; P2= 0x77 >> 4; P0= 0x6 << 4;
  • 7. Write an 8051 C program to toggle bits of P1 continuously forever with some delay. Solution: //Toggle P1 forever with some delay between “on” and “off” #include <reg51.h> void main(void) { unsigned int x; for (;;) //repeat forever { p1=0x55; for (x=0;x<40000;x++); //delay size//unknown p1=0xAA; for (x=0;x<40000;x++); } }
  • 8. Write an 8051 C program to toggle all the bits of P1 continuously. Solution: //Toggle P1 forever #include <reg51.h> void main(void) { for (;;) { P1=0x55; P1=0xAA; } }
  • 9. Write an 8051 C program to toggle bit D0 of the port P1 (P1.0) 50,000 times. Solution: #include <reg51.h> sbit MYBIT=P1^0; void main(void) { unsigned int z; for (z=0;z<=50000;z++) { MYBIT=0; MYBIT=1; } }
  • 10. To create Time delay -- Three factors that can affect the accuracy of the delay- 1. The 8051 design.. The number of machine cycle The number of clock periods per machine cycle 2. The crystal frequency connected to the X1 – X2 input pins 3. Compiler choice C compiler converts the C statements and functions to Assembly language instructions Different compilers produce different code
  • 11. Write an 8051 C program to toggle bits of P1 ports continuously with a 250 ms. Solution: #include <reg51.h> void MSDelay(unsigned int); void main(void) {while (1) { P1=0x55; MSDelay(250); P1=0xAA; MSDelay(250); } } void MSDelay(unsigned int itime) { unsigned int i,j; for (i=0;i<itime;i++) for (j=0;j<1275;j++); }
  • 12. Logic Operations in C #include <reg51.h> void main (void) { P0= 0x35 & 0x0F; P1= 0x04 | 0x68; P2= 0x54 ^ 0x78; P0= ~0x55; P1= 0x9A >> 3; P2= 0x77 >> 4; P0= 0x6 << 4; }