SlideShare a Scribd company logo
1 of 6
Download to read offline
Programming
1. Introduction
Programming is important and fruitful only when both the programmer and interpreter
know the same language. In a microcontroller, the language that the man and
microcontroller use to communicate is assembly language. Assembly language and the
assembler are two different notations. Assembly language is the language that the
programmer uses to write a programme for a microcontroller whereas assembler
translates the assembly language into zeros and one on a computer. This language of
zeros and ones is called as machine language.
2. Assembly language elements
Basic elements of assembly language are the following:
 Labels
A label is a textual designation for a line in a programme or a section of a programme
where the microcontroller can jump to. A label should always start with an alphabet
or an underline and should always start in the first column. It should never start with a
number. The length of the label can be up to 32 characters.
 Instructions
The way we write an instruction is also called as instruction syntax.
The pic microcontroller does not recognise the instructions movlp or gotto
 Operands
Operands are the instruction elements for which the instruction is being executed.
They are usually stored in registers, variables, or constants.
 Directives
It is similar to an instruction but unlike instruction, it is independent of a
microcontroller and represents the characteristics of the assembly language itself.
 Comments
Comment is a series of words that a programmer writes to make the programme more
clear and legible. It is placed after an instruction and must start with a semi-colon (;)
3. Writing a simple programme
In order to function properly, some microcontroller parameters must be defined such as
 Type of oscillator
 Whether watchdog timer is turned on or
 Whether internal reset circuit is enabled or not
All this is defined by the following directive:
_CONFIG_CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC
When all the needed elements have been defined, we can start writing a programme.
4. Control directives
Control
directives
Syntax Description Example
define #define <text> [<another text>]
(exchange one part of text for another)
Each time <text>
appears in the
programme, it will
be exchanged for
<another text>
#define turned_on 1
#define turned_off 0
include #include <file_name>
#include "file_name"
(include an additional file in a
programme)
An application of
this directive has the
effect as though the
entire file was
copied to a place
where the include
directive was found
#include <regs.h>
#include "subprog.asm"
constant constant <name> = <value>
gives a constant numeric value to a
textual designation
Each time <name>
appears in the
programme, it will
be replaced by
<value>
constant MAXIMUM = 100
constant LENGTH = 30
variable Variable <name> = <value>
Gives a variable numeric value to a
textual designation
Textual designation
changes with
particular value.
variable level = 30
variable time = 13
set <name_variable> set <value>
Defining assembler variable
Name of a variable
can be redefined
following a
definition
level set 0
length set 12
level set 45
equ <name_constant> set <value>
Defining assembler constant
To the name of the
constant
<name_constant> is
added value <value>
five equ 5
six equ 6
seven equ 7
org <label> org <value>
Defines an address from which the
programme is stored in microcontroller
memory
We define where
some part of the
programme will start
on the programme
memory
start org 0x00
movlw 0xFF
movwf PORTB
end end
end of programme
At the end of the
programme it is
necessary to place
end
.
.
.
movlw 0xFF
movwf PORTB
end
if If <conditional_term>
Conditional programming term
If condition in
<conditional_term>
if level = 100
goto FILL
is met, instructions
following are
executed others not
else
goto DISCHARGE
endif
else else
the alternative to IF programme block
with conditional term
Used with IF
directive as an
alternative if
conditional term is
incorrect
If time < 50
goto SPEED UP
else
goto SLOW DOWN
endif
endif endif
end the conditional programme section
This directive is
written at the end of
conditional block
if level =100
goto LOADS
else
goto UNLOADS
endif
while While <condition>
.
.
endw
execution of programme section as long
as condition is met
Programme between
while and endw will
be executed as long
as condition is met
while I < 10
i = i + 1
endw
endw endw
end of conditional part of the
programme
This instruction is
written at the end of
conditional while
block
while i< 10
i = i +1
endw
ifdef ifdef <designation>
execution of a part of a programme if
symbol was defined
If designation
<designation> was
previously defined,
instruction which
follow would be
executed until ELSE
or ENDIF directive
are not reached
#define test
.
.
ifdef test ; how the test was defined
…. ; instruction from these lines would be
executed
Endif
ifndef ifndef <designation>
execution of a part of a programme if
symbol was defined
#define test
……..
#undefine test
……..
ifndef test ; how the test was defined
…. ; instruction from these lines would be
executed
endif
cblock cblock [<term>]
<label> [:<increment>],
<label> [:<increment>],…
endc
This directive is
used to give values
to named constant.
Each following term
receives a value
greater than its
precursor. If
<increment >
parameter is also
given, then value
cblock 0x02
first, second, third ; first =
0x02, second = 0x03, third =
0x04
endc
cblock 0x02
first: 4; second : 2; third; first =
0x06, second = 0x08, third =
0x09
given in
<increment>
parameter is added
to the following
constant. Value of
the <term>
parameter is the
starting value. If it is
not given, it is
considered to be
zero.
endc
endc endc
end of constant block
Directive was used
at the end of
definition of a block
of constants so
assembly translator
could know that
there are no more
constants.
cblock 0x02
first, second, third ; first =
0x02, second = 0x03, third =
0x04
endc
db [<label>]db<term>[<term>,….,<term>]
Defining one byte data
Similar with dt and de
This directive
reserves a one byte
in programme
memory
Db ‘t’, 0x0f, ‘e’, ‘s’, 0x12
CONFIG _ _config<term> or _
_config<address>,<term>
Setting the configuration bits
Oscillator, watchdog
timer application
and internal reset
circuit is defined
before using this
directive the
processor must be
defined using
PROCESSOR
directive
_CONFIG _CP _OFF &
_WDT_OFF & _PWRTE_ON
& _XT_OSC
Processor Processor <microcontroller_type>
Defining microcontroller model
Instruction sets the
type of
microcontroller
where programming
is done
Processor 16F84
Advantages of PIC Microcontroller:
o PIC microcontrollers are consistent and faulty of PIC percentage is very less. The
performance of the PIC microcontroller is very fast because of using RISC
architecture.
o When comparing to other microcontrollers, power consumption is very less and
programming is also very easy.
o Interfacing of an analog device is easy without any extra circuitry
Disadvantages of PIC Microcontroller:
o The length of the program is high due to using RISC architecture (35 instructions)
o One single accumulator is present and program memory is not accessible

More Related Content

What's hot (20)

Basic construction of c
Basic construction of cBasic construction of c
Basic construction of c
 
Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java Programming
 
Compiler
Compiler Compiler
Compiler
 
Advanced Java Topics
Advanced Java TopicsAdvanced Java Topics
Advanced Java Topics
 
Unit iv functions
Unit  iv functionsUnit  iv functions
Unit iv functions
 
Modular programming in qbasic
Modular programming in qbasicModular programming in qbasic
Modular programming in qbasic
 
Fundamentals of programming with C++
Fundamentals of programming with C++Fundamentals of programming with C++
Fundamentals of programming with C++
 
Java tutorials
Java tutorialsJava tutorials
Java tutorials
 
Lecture13 control statementswitch.ppt
Lecture13 control statementswitch.pptLecture13 control statementswitch.ppt
Lecture13 control statementswitch.ppt
 
Notes part5
Notes part5Notes part5
Notes part5
 
Basic Information About C language PDF
Basic Information About C language PDFBasic Information About C language PDF
Basic Information About C language PDF
 
C programming-apurbo datta
C programming-apurbo dattaC programming-apurbo datta
C programming-apurbo datta
 
Programming Fundamentals lecture 2
Programming Fundamentals lecture 2Programming Fundamentals lecture 2
Programming Fundamentals lecture 2
 
BERT
BERTBERT
BERT
 
SDD Translation
SDD  TranslationSDD  Translation
SDD Translation
 
Peephole optimization techniques in compiler design
Peephole optimization techniques in compiler designPeephole optimization techniques in compiler design
Peephole optimization techniques in compiler design
 
Lecture 4 assembly language
Lecture 4   assembly languageLecture 4   assembly language
Lecture 4 assembly language
 
[ITP - Lecture 03] Introduction to C/C++
[ITP - Lecture 03] Introduction to C/C++[ITP - Lecture 03] Introduction to C/C++
[ITP - Lecture 03] Introduction to C/C++
 
Aniket tore
Aniket toreAniket tore
Aniket tore
 
Notes on attention mechanism
Notes on attention mechanismNotes on attention mechanism
Notes on attention mechanism
 

Similar to Programming

Assembler directives and basic steps ALP of 8086
Assembler directives and basic steps ALP of 8086Assembler directives and basic steps ALP of 8086
Assembler directives and basic steps ALP of 8086Urvashi Singh
 
Assembly level language
Assembly level languageAssembly level language
Assembly level languagePDFSHARE
 
Basic structure of c programming
Basic structure of c programmingBasic structure of c programming
Basic structure of c programmingTejaswiB4
 
Basic structure of c programming
Basic structure of c programmingBasic structure of c programming
Basic structure of c programmingTejaswiB4
 
Std 10 computer chapter 10 introduction to c language (part1)
Std 10 computer chapter 10 introduction to c language (part1)Std 10 computer chapter 10 introduction to c language (part1)
Std 10 computer chapter 10 introduction to c language (part1)Nuzhat Memon
 
C programming language tutorial for beginers.pdf
C programming language tutorial for beginers.pdfC programming language tutorial for beginers.pdf
C programming language tutorial for beginers.pdfComedyTechnology
 
6 preprocessor macro header
6 preprocessor macro header6 preprocessor macro header
6 preprocessor macro headerhasan Mohammad
 
Algorithm and pseudo codes
Algorithm and pseudo codesAlgorithm and pseudo codes
Algorithm and pseudo codeshermiraguilar
 
over all view programming to computer
over all view programming to computer over all view programming to computer
over all view programming to computer muniryaseen
 
Algorithm and c language
Algorithm and c languageAlgorithm and c language
Algorithm and c languagekamalbeydoun
 
INTRODUCTION TO C PROGRAMMING MATERIAL.pdf
INTRODUCTION TO C PROGRAMMING MATERIAL.pdfINTRODUCTION TO C PROGRAMMING MATERIAL.pdf
INTRODUCTION TO C PROGRAMMING MATERIAL.pdfSubramanyambharathis
 

Similar to Programming (20)

Assembler directives and basic steps ALP of 8086
Assembler directives and basic steps ALP of 8086Assembler directives and basic steps ALP of 8086
Assembler directives and basic steps ALP of 8086
 
Assembly level language
Assembly level languageAssembly level language
Assembly level language
 
Cp week _2.
Cp week _2.Cp week _2.
Cp week _2.
 
Basic structure of c programming
Basic structure of c programmingBasic structure of c programming
Basic structure of c programming
 
Basic structure of c programming
Basic structure of c programmingBasic structure of c programming
Basic structure of c programming
 
unit 2.pptx
unit 2.pptxunit 2.pptx
unit 2.pptx
 
Mp lab manual
Mp lab manualMp lab manual
Mp lab manual
 
Preprocessor
PreprocessorPreprocessor
Preprocessor
 
C++ Constructs.pptx
C++ Constructs.pptxC++ Constructs.pptx
C++ Constructs.pptx
 
Std 10 computer chapter 10 introduction to c language (part1)
Std 10 computer chapter 10 introduction to c language (part1)Std 10 computer chapter 10 introduction to c language (part1)
Std 10 computer chapter 10 introduction to c language (part1)
 
C programming language tutorial for beginers.pdf
C programming language tutorial for beginers.pdfC programming language tutorial for beginers.pdf
C programming language tutorial for beginers.pdf
 
Translators(Compiler, Assembler) and interpreter
Translators(Compiler, Assembler) and interpreterTranslators(Compiler, Assembler) and interpreter
Translators(Compiler, Assembler) and interpreter
 
C Language Presentation.pptx
C Language Presentation.pptxC Language Presentation.pptx
C Language Presentation.pptx
 
Unit-2.pptx
Unit-2.pptxUnit-2.pptx
Unit-2.pptx
 
6 preprocessor macro header
6 preprocessor macro header6 preprocessor macro header
6 preprocessor macro header
 
Algorithm and pseudo codes
Algorithm and pseudo codesAlgorithm and pseudo codes
Algorithm and pseudo codes
 
over all view programming to computer
over all view programming to computer over all view programming to computer
over all view programming to computer
 
Algorithm and c language
Algorithm and c languageAlgorithm and c language
Algorithm and c language
 
SPOS UNIT1 PPTS (1).pptx
SPOS UNIT1 PPTS (1).pptxSPOS UNIT1 PPTS (1).pptx
SPOS UNIT1 PPTS (1).pptx
 
INTRODUCTION TO C PROGRAMMING MATERIAL.pdf
INTRODUCTION TO C PROGRAMMING MATERIAL.pdfINTRODUCTION TO C PROGRAMMING MATERIAL.pdf
INTRODUCTION TO C PROGRAMMING MATERIAL.pdf
 

More from Jamia Hamdard

More from Jamia Hamdard (8)

Unit v
Unit vUnit v
Unit v
 
Embedded system software
Embedded system softwareEmbedded system software
Embedded system software
 
Wireless sensor network
Wireless sensor networkWireless sensor network
Wireless sensor network
 
Registers
RegistersRegisters
Registers
 
Interrupts
InterruptsInterrupts
Interrupts
 
Instructions
InstructionsInstructions
Instructions
 
Pic microcontroller architecture
Pic microcontroller architecturePic microcontroller architecture
Pic microcontroller architecture
 
Introduction to vlsi design
Introduction to vlsi designIntroduction to vlsi design
Introduction to vlsi design
 

Recently uploaded

Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAbhinavSharma374939
 

Recently uploaded (20)

Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog Converter
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 

Programming

  • 1. Programming 1. Introduction Programming is important and fruitful only when both the programmer and interpreter know the same language. In a microcontroller, the language that the man and microcontroller use to communicate is assembly language. Assembly language and the assembler are two different notations. Assembly language is the language that the programmer uses to write a programme for a microcontroller whereas assembler translates the assembly language into zeros and one on a computer. This language of zeros and ones is called as machine language. 2. Assembly language elements Basic elements of assembly language are the following:  Labels A label is a textual designation for a line in a programme or a section of a programme where the microcontroller can jump to. A label should always start with an alphabet or an underline and should always start in the first column. It should never start with a number. The length of the label can be up to 32 characters.  Instructions The way we write an instruction is also called as instruction syntax. The pic microcontroller does not recognise the instructions movlp or gotto  Operands
  • 2. Operands are the instruction elements for which the instruction is being executed. They are usually stored in registers, variables, or constants.  Directives It is similar to an instruction but unlike instruction, it is independent of a microcontroller and represents the characteristics of the assembly language itself.  Comments Comment is a series of words that a programmer writes to make the programme more clear and legible. It is placed after an instruction and must start with a semi-colon (;) 3. Writing a simple programme In order to function properly, some microcontroller parameters must be defined such as  Type of oscillator  Whether watchdog timer is turned on or  Whether internal reset circuit is enabled or not All this is defined by the following directive: _CONFIG_CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC
  • 3. When all the needed elements have been defined, we can start writing a programme. 4. Control directives Control directives Syntax Description Example define #define <text> [<another text>] (exchange one part of text for another) Each time <text> appears in the programme, it will be exchanged for <another text> #define turned_on 1 #define turned_off 0 include #include <file_name> #include "file_name" (include an additional file in a programme) An application of this directive has the effect as though the entire file was copied to a place where the include directive was found #include <regs.h> #include "subprog.asm" constant constant <name> = <value> gives a constant numeric value to a textual designation Each time <name> appears in the programme, it will be replaced by <value> constant MAXIMUM = 100 constant LENGTH = 30 variable Variable <name> = <value> Gives a variable numeric value to a textual designation Textual designation changes with particular value. variable level = 30 variable time = 13 set <name_variable> set <value> Defining assembler variable Name of a variable can be redefined following a definition level set 0 length set 12 level set 45 equ <name_constant> set <value> Defining assembler constant To the name of the constant <name_constant> is added value <value> five equ 5 six equ 6 seven equ 7 org <label> org <value> Defines an address from which the programme is stored in microcontroller memory We define where some part of the programme will start on the programme memory start org 0x00 movlw 0xFF movwf PORTB end end end of programme At the end of the programme it is necessary to place end . . . movlw 0xFF movwf PORTB end if If <conditional_term> Conditional programming term If condition in <conditional_term> if level = 100 goto FILL
  • 4. is met, instructions following are executed others not else goto DISCHARGE endif else else the alternative to IF programme block with conditional term Used with IF directive as an alternative if conditional term is incorrect If time < 50 goto SPEED UP else goto SLOW DOWN endif endif endif end the conditional programme section This directive is written at the end of conditional block if level =100 goto LOADS else goto UNLOADS endif while While <condition> . . endw execution of programme section as long as condition is met Programme between while and endw will be executed as long as condition is met while I < 10 i = i + 1 endw endw endw end of conditional part of the programme This instruction is written at the end of conditional while block while i< 10 i = i +1 endw ifdef ifdef <designation> execution of a part of a programme if symbol was defined If designation <designation> was previously defined, instruction which follow would be executed until ELSE or ENDIF directive are not reached #define test . . ifdef test ; how the test was defined …. ; instruction from these lines would be executed Endif ifndef ifndef <designation> execution of a part of a programme if symbol was defined #define test …….. #undefine test …….. ifndef test ; how the test was defined …. ; instruction from these lines would be executed endif cblock cblock [<term>] <label> [:<increment>], <label> [:<increment>],… endc This directive is used to give values to named constant. Each following term receives a value greater than its precursor. If <increment > parameter is also given, then value cblock 0x02 first, second, third ; first = 0x02, second = 0x03, third = 0x04 endc cblock 0x02 first: 4; second : 2; third; first = 0x06, second = 0x08, third = 0x09
  • 5. given in <increment> parameter is added to the following constant. Value of the <term> parameter is the starting value. If it is not given, it is considered to be zero. endc endc endc end of constant block Directive was used at the end of definition of a block of constants so assembly translator could know that there are no more constants. cblock 0x02 first, second, third ; first = 0x02, second = 0x03, third = 0x04 endc db [<label>]db<term>[<term>,….,<term>] Defining one byte data Similar with dt and de This directive reserves a one byte in programme memory Db ‘t’, 0x0f, ‘e’, ‘s’, 0x12 CONFIG _ _config<term> or _ _config<address>,<term> Setting the configuration bits Oscillator, watchdog timer application and internal reset circuit is defined before using this directive the processor must be defined using PROCESSOR directive _CONFIG _CP _OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC Processor Processor <microcontroller_type> Defining microcontroller model Instruction sets the type of microcontroller where programming is done Processor 16F84
  • 6. Advantages of PIC Microcontroller: o PIC microcontrollers are consistent and faulty of PIC percentage is very less. The performance of the PIC microcontroller is very fast because of using RISC architecture. o When comparing to other microcontrollers, power consumption is very less and programming is also very easy. o Interfacing of an analog device is easy without any extra circuitry Disadvantages of PIC Microcontroller: o The length of the program is high due to using RISC architecture (35 instructions) o One single accumulator is present and program memory is not accessible