The 8051  microcontroller
Upcoming SlideShare
Loading in...5
×
 

The 8051 microcontroller

on

  • 268 views

8051 assembly language programming.

8051 assembly language programming.

Statistics

Views

Total Views
268
Views on SlideShare
268
Embed Views
0

Actions

Likes
0
Downloads
14
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    The 8051  microcontroller The 8051 microcontroller Presentation Transcript

    • 8051 ASSEMBLY LANGUAGE PROGRAMMING BY AVINASH KUMAR MISHRA
    • INTRODUCTION TO PROGRAMMING: CPU CAN ONLY WORK IN BINARY,IT CAN DO SO AT VERY FAST SPEED.FOR HUMAN IT IS QUITE TEDIOUS AND SLOW TO DEAL WITH 0’S & 1’S IN ORDER TO PROGRAM THE COMPUTER .A PROGRAM THAT CONSISTS OF 0s AND 1s IS CALLED MACHINE LANGUAGE. ASSEMBLY LANGUAGE WERE DEVELOPED THAT PROVIDED MNEUMONICS FOR THE MACHINE CODE INSTRUCTION ,PLUS OTHER FEATURES
    • THAT MADE PROGRAMMING FASTER AND . LESS PRONE TO ERROR. ASSEMBLY LANGUAGE PROGRAMS MUST BE TRANSLATED INTO MACHINE CODE BY A PROGRAM CALLED ASSEMBLER. TO PROGRAM IN ASSEMBLY LANGUAGE , THE PROGRAMMER MUST KNOW ALL THE REGISTERS OF THE CPU AND THE SIZE OF EACH ,AS WELL AS OTHER DETAILS.
    • STRUCTURE OF ASSEMBLY LANGUAGE AN ASSEMBLY LANGUAGE CONSISTS OF FOUR FIELDS. “ [LABEL:] MNEUMONICS [OPERAND] [;COMMENT] ” HERE BRACKETS INDICATE THAT A FIELD IS OPTIONAL .
    • EXAMPLE ORG OOH ;START AT LOCATION 0 MOV R5,#25H ;LOAD 25H INTO R5 MOV R6,#20H ; LOAD 20H INTO R6 MOV A ,#00H ; LOAD 00H INTO A ADD A ,R5 ; ADD CONTENTS OF R5 TO A ADD A ,R6 ; ADD CONTENTS OF R6 TO A ADD A ,#12H ; NOW A=A+ 12H HERE: SJMP HERE ; STAY IN THIS LOOP END
    • STEPS TO CREATE A PROGRAM : EDITOR PROGRAM ASSEMBLER PROGRAM LINKER PROGRAM OH PROGRAM
    • PROGRAM COUNTER: IT IS SPECIAL FUNCTION REGISTER WHICH GENERALLY TELL OUR CONTROLLER OR PROCESSOR ABOUT NEXT EXECUTING PROCESS.
    • STACK POINTER: IT IS THE SPECIAL FUNCTION REGISTER WHICH IS USED TO STORE THE EXECUTED PROGRAM INSIDE YOUR STACK MEMORY. IT GENERALLY WORK ON THE PHENOMENA LIFO( LAST IN FIRST OUT).
    • ASSEMBLER DIRECTIVES:  ORG(ORIGIN):USED TO INDICATE THE BEGINNING OF THE ADDERESS .  EQU(EQUATE): USED TO DEFINE A CONSTANT WITHOUT COPYING A MEMORY LOCATION.  END: IT INDICATES TO THE ASSEMBLER THE END OF SOURCE(ASM ) FILE.
    • PROGRAM STATUS WORD(PSW):
    • DEFINITION OF PSW REGISTER: THE PROGRAM STATUS WORD (PSW) REGISTER IS AN 8 - BIT REGISTER. IT IS ALSO REFFERED TO AS FLAG REGISTER.ALTHOUGH PSW REGISTER IS 8-BITS WIDE, OLY 6-BITS ARE USED BY 8051 . THE OTHER TWO ARE USER DEFINABLE FLAGS. FOUR OF FLAGS ARE CALLED CONDITIONAL FLAGS ,MEANS THAT THEY INDICATE SOME CONDITION
    • CONTINUE THAT RESULT AFTER A INSTRUCTION IS EXECUTED . THESE FOUR ARE CY (CARRY) ,AC(AUXILIARY CARRY) , P ( PARITY) AND OV(OVERFLOW) .RS0 AND RS1 ARE USED TO CHANGE BANK REGISTORS . THE PSW .1 AND PSW.5 ARE GENERAL PURPOSE STATUS FLAG BITS AND CAN BE USED BY PROGRAMMER FOR ANY PURPOSE.
    • 8051 REGISTER BANKS & STACK: THERE ARE 32 BYTES OF RAM ARE SET ASIDE FOR THE REGISTER BANKS AND STACK. THERE ARE 128 BYTES OF RAM ARE USED IN 8051 . THE 128 BYTES ARE ASSIGNED ADDRESSES 00 TO 7FH. FROM THESE 32 BYTES ARE USED FOR STACK AND REGISTER BANK .
    • THERE ARE 4 REGISTER BANKS. THESE ARE [1] BANK(0) : ADDRESS FROM 00H TO 07H. [2] BANK(1) : ADDRESS FROM 08H TO 0FH. [3] BANK(1) : ADDRESS FROM 10H TO 17 H. [4] BANK(1) : ADDRESS FROM 18H TO 1FH. FROM 20H TO 2FH ARE ASSIGNED FOR BITADDERESSABLE RAM AND FROM 30H TO 7F H ARE FOR SCRATCH PAD RAM.
    • RAM ALLOCATION
    • 8051 REGISTER BANKS & THEIR RAM ADDERESSES
    • STACK IN THE 8051: STACK SI THE SECTION OF RAM USED BY CPU TO STORE INFORMATION TEMPORA – RILY . THIS INFORMATION COULD BE DATA OR ADDERESS . THE CPU NEEDS THIS AREA FOR STORAGE SINCE THERE ARE ONLY A LIMITED NUMBER OF REGISTERS.
    • PUSHING ONTO STACK: WE PUSH DATA ONTO STACK,THE STACK POINTER (SP) IS INCREMENTED BY ONE. • EXAMPLE: MOV R6,#25H MOV R1,#12H MOV R4,#0F3H PUSH 6 PUSH 1 PUSH 4
    • SOLUTION: AFTER PUSH6 0B 0A 09 08 25 AFTER PUSH1 0B 0A 09 12 08 25 START SP=07 SP=08 SP=09 0B 0A 09 08 AFTER PUSH 4 0B 0A F3 09 12 08 25 SP=0A
    • POPPING FROM STACK:
    • PROGRAMMING 8051 TIMERS: • THE 8051 HAS TWO TIMERS : TIMER0 TIMER1. • TIMER0 AND TIMER1 ARE 16-BITS WIDE. • THE 8051 HAS 8-BIT ARCHITECTURE , EACH IS ACCESSED BY TWO SEPARATE REGISTERS OF LOW BYTE AND HIGH BYTE.
    • • TIMER0 REGISTERS: THE 16-BIT REGISTER OF TIMER0 IS ACCESSED AS LOW BYTE AND HIGH BYTE i.e TL0 & TH0. • TIMER1 REGISTERS: THE 16-BIT REGISTER OF TIMER0 IS ACCESSED AS LOW BYTE AND HIGH BYTE i.e TL1 & TH1. • TMOD (TIMER MODE) REGISTER: BOTH TIMERS 0 &1 USE SAME REGISTER TMOD.
    • FIGURE OF TIMER0 AND TIMER1
    • TMOD REGISTER
    • STEPS TO PROGRAM FOR MODE1 a) LOAD TMOD b) LOAD TH & TL c) START TIMER (SBIT TR) d) SET TI MER FLAG H:JNB TF,H e) CLR TR f) CLR TF g) RET
    • STEPS TO PROGRAM FOR MODE2 a) LOAD TMOD REGISTER b) LOAD TIMER TYPE c) SET TIMER/START TI MER d) SET FLAG e) CLR FLAG f) RET
    • COUNTERS TIMER / COUNTERS ARE USED TO GENERATE TIME DELAYS . THESE TIMERS CAN BE USED AS COUNTERS COUNTING EVENTS HAPPENING OUTSIDE THE 8051 . WHEN THE TIMER / COUNTER IS USED AS A TIMER, THE 8051’S CRYSTAL IS USED AS THE SOURCE OF FREQUENCY.
    • . END
    • . THANK YOU