Unit 2_8051 Programming
Unit 2_8051 Programming
1
Assembly Language Programming
2
Syntax:
[label:] Mnemonic [operands] [;comments]
Label: Allows the program to refer to a
line of code by name.
The Mnemonic, operand fields perform the
real work of the program
The comment field begins with ‘;’. Just for
understanding or to remember what
programmer wrote.
Assembling & Running an 8051
Program
3
Editor Program
MS-DOS Editor in windows used to create
ORG (Origin)
Indicate the beginning of the address
assembler
8051 Programming in ‘C’
6
Advantages
It is easier and less time consuming
‘C’ is easier to modify and update
You can use code available in function libraries
‘C’ code is portable to other microcontrollers with
little modification or no modification
Disadvantages:
It produces hex file size is much larger than the hex
file that is produced if we program in assembly
‘C’ Data types
7
Unsigned Char
8-bit data type that can takes a value in the range of
0-255 (00-FFH)
Signed Char
Also 8-bit data type, gives the values in the range of -
128 to +127.
Default is “Signed”
Signed int
16 – bit data type
Can takes a value in the range of -32768 to +32767
Sbit
Used to define a single bit
It allows access to the bits of SFR’s which are bit addressable.
Ex: sbit mybit = P0^0;
Bit
This data type allows access to single bit of bit addressable RAM 20
– 2FH.
Sfr
Used to access the byte size SFRs
‘C’ Data types (Contd..)
9