Pages

Wednesday, 24 August 2011

8085 Microprocessor

Properties
  1. Single + 5V Supply
  2. 4 Vectored Interrupts (One is Non Maskable)
  3. Serial In/Serial Out Port
  4. Decimal, Binary, and Double Precision Arithmetic
  5. Direct Addressing Capability to 64K bytes of memory
The Intel 8085A is a new generation, complete 8 bit parallel central processing unit
(CPU). The 8085A uses a multiplexed data bus. The address is split between the 8bit
address bus and the 8bit data bus. Figures are at the end of the document.
Pin Description
The following describes the function of each pin:
A6 - A1s (Output 3 State)
Address Bus; The most significant 8 bits of the memory address or the 8 bits of the I/0
address,3 stated during Hold and Halt modes.
AD0 - 7 (Input/Output 3state)
Multiplexed Address/Data Bus; Lower 8 bits of the memory address (or I/0 address)
appear on the bus during the first clock cycle of a machine state. It then becomes the
data bus during the second and third clock cycles. 3 stated during Hold and Halt
modes.
ALE (Output)
Address Latch Enable: It occurs during the first clock cycle of a machine state and
enables the address to get latched into the on chip latch of peripherals. The falling
edge of ALE is set to guarantee setup and hold times for the address information.
ALE can also be used to strobe the status information. ALE is never 3stated.
SO, S1 (Output)
Data Bus Status. Encoded status of the bus cycle:
S1 S0
O O HALT
0 1 WRITE
1 0 READ
1 1 FETCH
S1 can be used as an advanced R/W status.
RD (Output 3state)
READ; indicates the selected memory or 1/0 device is to be read and that the Data
Bus is available for the data transfer.
WR (Output 3state)
WRITE; indicates the data on the Data Bus is to be written into the selected memory
or 1/0 location. Data is set up at the trailing edge of WR. 3stated during Hold and Halt
modes.
READY (Input)
If Ready is high during a read or write cycle, it indicates that the memory or
peripheral is ready to send or receive data. If Ready is low, the CPU will wait for
Ready to go high before completing the read or write cycle.
HOLD (Input)
HOLD; indicates that another Master is requesting the use of the Address and Data
Buses. The CPU, upon receiving the Hold request. will relinquish the use of buses as
soon as the completion of the current machine cycle. Internal processing can continue.
The processor can regain the buses only after the Hold is removed. When the Hold is
acknowledged, the Address, Data, RD, WR, and IO/M lines are 3stated.
HLDA (Output)
HOLD ACKNOWLEDGE; indicates that the CPU has received the Hold request and
that it will relinquish the buses in the next clock cycle. HLDA goes low after the Hold
request is removed. The CPU takes the buses one half clock cycle after HLDA goes
low.
INTR (Input)
INTERRUPT REQUEST; is used as a general purpose interrupt. It is sampled only
during the next to the last clock cycle of the instruction. If it is active, the Program
Counter (PC) will be inhibited from incrementing and an INTA will be issued. During
this cycle a RESTART or CALL instruction can be inserted to jump to the interrupt
service routine. The INTR is enabled and disabled by software. It is disabled by Reset
and immediately after an interrupt is accepted.
INTA (Output)
INTERRUPT ACKNOWLEDGE; is used instead of (and has the same timing as) RD
during the Instruction cycle after an INTR is accepted. It can be used to activate the
8259 Interrupt chip or some other interrupt port.
RST 5.5
RST 6.5 - (Inputs)
RST 7.5
RESTART INTERRUPTS; These three inputs have the same timing as I NTR except
they cause an internal RESTART to be automatically inserted.
RST 7.5 ~~ Highest Priority
RST 6.5
RST 5.5 o Lowest Priority
The priority of these interrupts is ordered as shown above. These interrupts have a
higher priority than the INTR.
TRAP (Input)
Trap interrupt is a nonmaskable restart interrupt. It is recognized at the same time as
INTR. It is unaffected by any mask or Interrupt Enable. It has the highest priority of
any interrupt.
RESET IN (Input)
Reset sets the Program Counter to zero and resets the Interrupt Enable and HLDA
flipflops. None of the other flags or registers (except the instruction register) are
affected The CPU is held in the reset condition as long as Reset is applied.
RESET OUT (Output)
Indicates CPlJ is being reset. Can be used as a system RESET. The signal is
synchronized to the processor clock.
X1, X2 (Input)
Crystal or R/C network connections to set the internal clock generator X1 can also be
an external clock input instead of a crystal. The input frequency is divided by 2 to
give the internal operating frequency.
CLK (Output)
Clock Output for use as a system clock when a crystal or R/ C network is used as an
input to the CPU. The period of CLK is twice the X1, X2 input period.
IO/M (Output)
IO/M indicates whether the Read/Write is to memory or l/O Tristated during Hold and
Halt modes.
SID (Input)
Serial input data line The data on this line is loaded into accumulator bit 7 whenever a
RIM instruction is executed.
SOD (output)
Serial output data line. The output SOD is set or reset as specified by the SIM
instruction.
Vcc--+5 volt supply.
Vss--Ground Reference.

Some 8051 Programmes

Some 8051 micro controller programms
FINDING SUM OF NATURAL NUMBERS

CLR A                                                                                                                                   
MOV R1,#0
MOV R2,#20
AGAIN: INC R1
ADD A,R1
DJNZ R2,AGAIN
MOV R5,A
END


FINDING NUMBER OF ZERO’S AND ONE’S IN A NUMBER

MOV R2,#0;INITIALIZE ONE'S COUNTER=0
MOV R3,#0;INITIALIZE ZERO'S COUNTER=0
MOV R1,#08;INITIALIZE THE LOOP COUNT
MOV R0,#56;NUMBER
MOV A,R0
BACK:RRC A
JC SKIP;IF CARRY IS PRESENT GO TO SKIP
INC R3;INCREMENT ZERO'S COUNT
AJMP LOOP1
SKIP:INC R2;INCREMENT ONE'S COUNT
LOOP1:DJNZ R1,BACK
END


FINDING VARIANCE AND MEAN OF NUMMBERS
MOV R7,#6H
MOV R0,#30H
MOV @R0,#5H
INC R0
MOV @R0,#2H
INC R0
MOV @R0,#7H
INC R0
MOV @R0,#4H
INC R0
MOV @R0,#3H
INC R0
MOV @R0,#3H
MOV R0,#30H
LJMP LOOP
BACK: MOV R0,#30H
MOV R3,#00H
MOV R2,#6H
SJMP LOOP2
LOOP2: MOV A,10H
MOV B,@R0
LOOP6: SUBB A,B
JC LOOP4
MOV R4,A
MOV B,R4
MUL AB
MOV R5,A
MOV R6,B
MOV A,#0FH
CLR C
ANL A,R5
MOV R5,A
MOV A,#0F0H
ANL A,R6
ORL A,R5
ADD A,R3
MOV R3,A
INC R0
DJNZ R2,LOOP2
MOV B,#6
DIV AB
MOV 18H,A
MOV 19H,B
SJMP SKIP
LOOP4:MOV A,@R0
MOV B,10H
CLR C
AJMP LOOP6
LOOP:CLR A
LOOP1: ADD A,@R0
INC R0
DJNZ R7,LOOP1
ACALL AVG
AJMP BACK
AVG: MOV B,#6H
DIV AB
MOV 10H,A
MOV 11H,B
RET
SKIP:NOP
END

SORTING AND FINDING AVERAGE

MAX SET R3 ;SET R3 FOR STORING MAXIMUM NUMBER
MIN SET R2 ;SET R2 FOR STORING MINIMUM NUMBER
MOV R0,#30H ;INITIALIZE THE REGISTER R1
MOV @R0,#7 ;INPUT NUMBERS TO STORE FROM 30H
INC R0 ;
MOV @R0,#4 ;
INC R0 ;
MOV @R0,#1 ;
INC R0 ;
MOV @R0,#8 ;
INC R0 ;
MOV @R0,#3 ;
MOV R3,#8 ;ASIGN THE LOOP COUNT FOR OUTER LOOP (AGAIN)
AGAIN:MOV R0,#30H ;STARTING THE PROCESS OF SORTING
MOV R4,#4 ; ASIGN INNER LOOP COUNT(BACK)
BACK:MOV B,@R0 ;
MOV R5,B ;
INC R0 ;
MOV A,@R0 ;
MOV R6,A ;
CJNE A,B,LOOP ;COMPARE THE TWO NUMBERS IF IT IS NOT EQUAL JUMP TO LOOP
AJMP LOOP1 ;IF TWO NUMBERS ARE EQUAL THEN JUMP TO LOOP1
LOOP:JNC LOOP1 ;IF A IS GREATER THAN B JUMP TO LOOP1
MOV B,R5 ;IF A<B EXCHANGE PROCESS STARTS ACORDING TO BUBBLE SORT
MOV @R0,B ;
DEC R0 ;
MOV A,R6 ;
MOV @R0,A ;
INC R0 ;
DJNZ R4,BACK ;REPEAT LOOP UNTIL R4=0
DJNZ R3,AGAIN ;REPEAT LOOP UNTIL R3=0
ACALL NEXT ;CALLS SUBROUTINE NEXT
AJMP SKIP ;JUMP TO SKIP AT THE END OF PROGRAM
LOOP1:DJNZ R4,BACK
DJNZ R3,AGAIN
ACALL NEXT
AJMP SKIP
NEXT:MOV A,@R0
MOV MAX,A ;STORES THE MAXIMUM VALUE IN MAX
MOV R0,#30H
MOV A,@R0
MOV MIN,A ;STORES THE MINIMUM VALUE IN MIN
ACALL LOOP3 ;CALLS THE SUBROUTINE LOOP3 FOR FINDING AVERAGE
RET
LOOP3: MOV R5,#5
MOV R0,#30H
CLR A
LOOP4:ADD A,@R0
INC R0
DJNZ R5,LOOP4
MOV B,#5
DIV AB
MOV 40H,A;MOVES THE QUOTIENT OF AVERAGE TO 40H
MOV 41H,B ;MOVES THE REMAINDER OF AVERAGE TO 41H
RET
SKIP:NOP
END
FIBBONACI SERIES
MOV R4,#8
MOV A,R4
MOV R3,A
SUBB A,#2
MOV R5,A
MOV R1,#30H
MOV @R1,#0
CLR C
MOV A,#1
MOV B,R3
MOV R4,B
SUBB A,R4
JZ NEXT
INC R1
MOV @R1,#1
CLR C
MOV A,#2
MOV B,R3
MOV R4,B
SUBB A,R4
JZ NEXT
MOV A,@R1
AGAIN:DEC R1
MOV B,@R1
ADD A,B
INC R1
INC R1
MOV @R1,A
DJNZ R5,AGAIN
NEXT :NOP
END

FINDING BIGGER NUMBER IN ARRAY
MOV R0,#60H
MOV R5,#1
MOV R2,#10
MOV R3,#10
AGAIN:MOV A,R5
MOV @R0,A
INC R5
INC R0
DJNZ R2,AGAIN
CLR A
MOV R0,#60H
MOV B,#0
SUM: MOV A,@R0
CJNE A,B,LOOP
LOOP: JC LOOP1
MOV B,A
INC R0
DJNZ R3,SUM
SJMP NEXT
LOOP1:INC R0
DJNZ R3,SUM
SJMP NEXT
NEXT:MOV A,B
END

BINARY TO GRAY
MOV A,#52H
MOV R0,A
CLR C
RRC A
XRL A,R0
END

BINARY TO BCD
MOV A,#76H
MOV B,#100
DIV AB
MOV R0,A
MOV A,B
MOV B,#10H
DIV AB
MOV R1,A
MOV R3,B
END

PROGRAM TO CHECK WHETHER CONTENT OF A>20H OR NOT
MOV A,#89H
MOV 20H,#10H
SUBB A,20H
JZ EQUAL
JNB ACC.7,POS
CLR P2.7
SJMP NEXT
POS:CLR P1.1
CLR P1.2
EQUAL:CLR P3.2
NEXT:NOP
END

FINDING GCD AND LCM OF NUMBERS <=22
NUM1 SET R2;SETS THE R2 FOR NUMBER1
NUM2 SET R3;SETS THE R3 FOR NUMBER2
GCD SET R6;SETS THE R6 FOR STORE GCD
LCM SET R7;SETS THE R7 FOR LCM
MOV NUM1,#6;NUMBER1
MOV NUM2,#10;NUMBER2
MOV A,NUM1;
MOV B,NUM2;
MOV R4,A;TEMPORERLY STORE NUM1 IN R4
MOV R5,B;TEMPORERLY STORE NUM2 IN R5
AGAIN:MOV A,R4;MOVES R4 TO A
MOV B,R5;MOVES R5 TO B
DIV AB;DIVIDE NUMBER1 BY NUMBER2
MOV A,R5;MOVE R5 TO A
MOV R4,A;MOV A TO R4
MOV R5,B;MOV REMAINDER TO R5
MOV A,B;MOV REMAINDER TO A
JZ NEXT;IF REMAINDER IS ZERO JUMP TO NEXT
AJMP AGAIN;REPEAT LOOP
NEXT:MOV A,R4;
MOV GCD,A;MOVES THE GCD OF NUMBERS TO GCD
MOV A,NUM1;
MOV B,NUM2;
MUL AB;MULTIPLIES NUM1 AND NUM2
MOV R4,A
MOV R5,B
CLR C
MOV B,GCD
DIV AB
MOV LCM,A
END
DA A OPERATION
MOV 31H,#00H
MOV 25H,#63H
MOV 26H,#63H
MOV 27H,#63H
MOV A,25H
ADD A,26H
DA A
MOV R0,A
MOV A,#00H
ADDC A,31H
MOV 31H,A
MOV A,R0
ADD A,27H
DA A
MOV 30H,A
MOV A,#00H
ADDC A,31H
MOV 31H,A
END
BINARY TO DECIMAL AND ASCII
MOV R0,#32H
MOV R1,#60H
MOV R3,#83H
MOV R4,#3
MOV B,#10
MOV A,R3
DIV AB
MOV @R0,B
DEC R0
MOV B,#10
DIV AB
MOV @R0,B
DEC R0
MOV @R0,A
MOV R0,#30H
AGAIN:MOV A,@R0
ORL A,#30H
MOV @R1,A
INC R0
INC R1
DJNZ R4,AGAIN
END
PACKED BCD TO ASCII
MOV R0,#38H
MOV A,R0
ANL A,#0FH
ADD A,#30H
MOV R1,A; ASCII(FIRST DGT)
MOV A,R0
ANL A,#0F0H
SWAP A
ADD A,#30H
MOV R2,A ;ASCII(SECOND DGT)
END

FINDING SMALLEST NUMBER IN ARRAY OF NUMBERS 
MOV R0,#60H
MOV R5,#10
MOV R2,#8
MOV R3,#10
AGAIN:MOV A,R5
MOV @R0,A
DEC R5
INC R0
DJNZ R2,AGAIN
CLR A
MOV R0,#60H
MOV B,@R0
SUM: MOV A,@R0
CJNE A,B,LOOP
LOOP: JNC LOOP1
MOV B,A
INC R0
DJNZ R3,SUM
SJMP NEXT
LOOP1:INC R0
DJNZ R3,SUM
SJMP NEXT
NEXT:MOV A,B
MOV R7,A;SAVE SMALLEST NUMBER IN R7
END
ASCII TO DECIMAL
MOV R1,#42H
MOV A,R1
CLR C
SUBB A,#41
MOV A,R1
JC DGT
CLR C
SUBB A,#37H ;ASCII?CHAR
SJMP NEXT
DGT: CLR C
SUBB A,#30H ;ASCII?NUMBER
NEXT:
END