Monday, July 25, 2011

Absolute division using loop

;program to divide absolute value like 20/5 = 4 etc.
;or like 4/2 not 20.5/12 no decimal values will be divided
ORG 0H          ;
MOV A, #25      ;
MOV R0, #05     ;
MOV R1, #00H    ;
LOOP: SUBB A, R0;
      INC R1    ;
      JNZ LOOP  ;
END

Multiplying 2 numbers using MUL mnemonic

;program to multiply using MUL mnemonic
ORG 0H;
MOV A, #00H ;
MOV R0,#13H
MOV R1, #00H
MOV B, #03H ;
MUL AB 
END

Multiplying 2 numbers with 16 bit answer

; program to add 2 numbers whose answer is 16 bit
ORG 0H;
MOV A, #00H ;
MOV R0,#13H
MOV R1, #00H
AGAIN: ADD A, #12H;
       JC INCREMENT ; 
       DJNZ R0,AGAIN;

INCREMENT: INC R1 ;
           SJMP AGAIN;
END

Multiplying with 8 bit answer using loop in 8051

; program to multiply two numbers using loop answer is 8 bit 
ORG 0H;
MOV A, #00H ;
MOV R0,#13H

AGAIN: ADD A, #12H;
       DJNZ R0,AGAIN;
END

Saturday, July 23, 2011

Jump Instructions


JZ LABEL ; JUMP IF A = 0
JNZ LABEL ; JUMP IF A <> 0
DJNZ Rn, LABEL ; DECREMENT AND JUMP IF REGISTER <> 0
CJNE A, DATA ; JUMP IF A <> DATA
CJNE REG, #DATA ; JUMP IF BYTE <> #DATA
JC LABEL ; JUMP IF CY = 1
JNC LABEL ; JUMP IF CY = 0
JB BIT, LABEL ; JUMP IF BIT = 1
JNB BIT, LABEL ; JUMP IF BIT = 0
JBC BIT, LABEL ; JUMP IF BIT = 1 AND CLEAR BIT
SJMP LABEL ; SHORT JUMP
LJMP LABEL ; LONG JUMP

Assembling and Running 8051 Program


4 basic steps are needed to be performed to assemble and run an 8051 program


Step 1: To write the program using any editor and save it with extension .asm or .src depending on the assembler one is using.


Step 2: The source file is fed into assembler which converts it to machine code and gives us 2 files one with extension .lst i.e. the list file and other with extension .obj i.e. the object file.


Step 3: Old assemblers required a third step to link all object files to create one absolute file with extension .abs This file is used by 8051 trainers to monitor program.


Step 4: The abs file is fed into a program called "OH" (i.e Object to hex converter) which creates a file with extension .hex that is ready to be burned in the ROM of the controller.


The List file
This is a very important file for programmers as it shows all opcodes and memory address as they will be stored in the controller. This makes error detection of labels and code quite easy.

Structure of Assembly language


An assembly language program consits of lines of assembly language instruction. An assembly language instruction consists of 


mnemonics, optionally followed by one or two operand. Obviously the operands are the one being manipulated and mnemonics are 


telling CPU how to manipulate them.


An assembly language consists of 4 fields


label: mnemonic [operands] ; comments


the Syntax above is self explanatory. So no post will be on its description.

Friday, July 22, 2011

A switch is connected to pin P1.7. WAP to continuosly check status of switch and send 'Y' or 'N' to P2


; P1.7 HAS SWITCH CONNECTED TO IT
; CONSIDER 1 AS ON 0 AS OFF
BACK: JB P1.7, LABEL ;
MOV P2, #'N' ;
SJMP -BACK ; MINUS SIGN REPRESENTS BACKWARD JUMP
LABEL: MOV P2, #'Y' ;
SJMP -BACK ;
; END OF PROGRAM 

Tuesday, July 19, 2011

Overview: An intro to 8051 microController part 2

--> One of the important registers in 8051 is the PROGRAM COUNTER. Its width is 16 bit allowing 8051 to access memory address from 0000 to FFFF a total 0f 64K of memory. Though not all 8051 have a 64K of memory.


--> Different microProcessor wakes up at different locations when they are powered up. But microControllers are one unified group of -----. When they are powered up they all woke up at same place that is at memory address 0000H.


--> So when writing code for controller our program should start from memory address 0000H.


--> STACK IN 8051 is a section of RAM used by the CPU to store information temporarily. This information could be data or address. As there are only a limited number of registers therefore CPU needs some storage.


--> The register used to access stack is STACK POINTER REGISTER. This in 8051 is only 8 bits wide. When 8051 is powered up SP has a default value of 07. This means that RAM location 08 is the first location used for STACKING by 8051.


--> STACK POINTER points to last used location of the stack. So when data is PUSH is execute the SP is incremented by one. When its POP is executed the SP is decremented by one.


--> STACK can only be used between 08H to 1FH ie 28 bytes. If we need more than that we have to use address between 30H to i think 6FH or 7FH.

Registers in 8051: An intro to 8051 microController part -1

The first part for intro of micro controller 8051.



Registers in 8051
A
B
R0
R1
R2
R3
R4
R5
R6
R7
DPTR (DATA POINTER)
PC (PROGRAM COUNTER)


Operation on registers remains the same as in 8085.
like
MOV R0, 12H ;
MOV A, R0 ;
ADD A, R1 ;


etc etc.
MVI instruction used for loading data in registers in 8085 is performed
by MOV instruction in 8051.


MOV R0, #55H ;
MOV R1, #0FFH ;


point to note:
1) a value to be loaded in register must be preceded by a pound sign(#)
otherwise it means to load from a memory location  like


MOV R0, 12H ;


means move value stored at 12H to register R0.


2) in order to load an immediate value 55H into register we need to use
pound sign(#). where pound sign preceds a value  like


MOV R0, #55H ;


means move value 55H to register.

Saturday, July 16, 2011

Friday, July 15, 2011

Tuesday, July 5, 2011

MicroController vs MicroProcessor

By microprocessor here I mean general purpose microprocessor like intels 8080,8085, 8086 80286, etc.
These microprocessors contains no RAM, no ROM and no I/O ports.


A system designer needs to add these items to microprocessor during its application. This makes the system bulkier and much more expensive. But provides the versatility such that designer can decide on amount of RAM, ROM and Ports to be added.


On the other hand microcintroller comes with a microprocessor plus a fixed amount of RAM, ROM and ports.  that cannot be changed at any point of time except during its manufacturing. These are ideal where cost and space are a critical thing.


Application like a simple TV remote do not need a computing power of a microprocessor. It just needs to read few signals and change few bits. COst is the major consideration here. Thats why micro controller is preffered over a microprocessor.