1. Trang chủ
  2. » Công Nghệ Thông Tin

System & Program Developments of 8051 pptx

48 212 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 48
Dung lượng 461,5 KB

Nội dung

08/09/14 T. L. Jong, Dept. of E.E. , NTHU 1 System & Program System & Program Developments of 8051 Developments of 8051  Program Structure and Design  Introduction  Advantages and Disadvantages of Structured Programming  The Three Structures: statements, loops, choice  Pseudo Code Syntax  Assembly Language Programming  Tools & Techniques for Program Development  The Development Cycle  Integration and Verification  Command and Environments 08/09/14 T. L. Jong, Dept. of E.E. , NTHU 2 Introduction  Structured Programming:  Organizing and coding programs that reduces complexity, improves clarity, and facilitates debugging and modifying  All programs may be written using only three structures: statements, loops, and choice—too good to be true.  Introduce Structure programming to assembly language programming  Flowcharts  Pseudo code  Assembly language 08/09/14 T. L. Jong, Dept. of E.E. , NTHU 3 Flowcharts Decision block Process box Input/Output block Program terminator Off-page connector Predefined process (subroutine) Program flow arrow 08/09/14 T. L. Jong, Dept. of E.E. , NTHU 4 Pseudo Code  Strict adherence to structure in combination with informal language  [get a character from the keyboard]  IF [condition is true] THEN [do statement 1] ELSE BEGIN [do statement 2] [do statement 3] END 08/09/14 T. L. Jong, Dept. of E.E. , NTHU 5 Advantages & Disadvantages of Structured Programming  Advantages:  Simple to trace, debug  Finite number of structures  Structures as building block  The set of structure is complete  Structures are self-documenting, easy to read  Structures are easy to describe in flowcharts, syntax diagrams, pseudo code,  Increased program productivity 08/09/14 T. L. Jong, Dept. of E.E. , NTHU 6 Advantages & Disadvantages of Structured Programming  Disadvantages:  Only a few high-level languages (Pascal, C, PL/M) accept the structures directly; others require extra translation stage  Structured program may execute slower and require more memory  Some problems (a minority) are more difficult to solve using only the three structures  Nested structures can be difficult to follow 08/09/14 T. L. Jong, Dept. of E.E. , NTHU 7 The Three Structures  Statements  [count = 0]  PRINT_STRING(“Select Option:”)  Loops (iteration)  WHILE/DO  REPEAT/UNTIL  Choice  IF/THEN/ELSE  CASE 08/09/14 T. L. Jong, Dept. of E.E. , NTHU 8 The WHILE/DO Statement  WHILE [condition] DO [statement] (statement might not be performed at all!) Enter Condition True? Statement Exit No Yes WHILE [c == 1] DO [statement] ENTER: JNC EXIT STATEMENT: (statement) JMP ENTER EXIT: (continue) 08/09/14 T. L. Jong, Dept. of E.E. , NTHU 9 WHILE/DO: SUM Subroutine [sum (A) = 0] WHILE [length (R7) > 0] DO BEGIN [sum = sum + @pointer (R0)] [increment pointer] [decrement length] END [sum (A) = 0] WHILE [length (R7) > 0] DO BEGIN [sum = sum + @pointer (R0)] [increment pointer] [decrement length] END 8051 code (closely structured; 13 bytes) SUM: CLR A LOOP: CJNZR7,#0,STAM JMP EXIT STAM: ADD A,@R0 INC R0 DEC R7 JMP LOOP: EXIT: RET (loosely structured; 9 bytes) SUM: CLR A INC R7 MORE: DJNZ R7,SKIP RET SKIP: ADD A,@R0 INC R0 SJMP MORE 08/09/14 T. L. Jong, Dept. of E.E. , NTHU 10 WHILE/DO Pseudo code: WHILE [ACC != CR AND R7 != 0] DO [statement] 8051 code: ENTER: CJNE A,#0DH,SKIP JMP EXIT SKIP: CJNE R7,#0,STAM JMP EXIT STAM: (one or more statements) . . JMP ENTER EXIT: (continue) Enter ACC != <CR>? R7 != 0? Statement Exit No No Yes Yes [...]... value >= second && true if both values are true || true if either value is true Bitwise Logical operators: & logical AND | logical OR ^ logical XOR ~ logical NOT (one’s complement) >> logical shift right & ^ | Precedence... addressing: @ 08/09/14 T L Jong, Dept of E.E 22 Suggested Pseudo Code Syntax Operator Precedence: () ~ @ * / + > < -= >= *= /= etc T L Jong, Dept of E.E 23 Suggested Pseudo Code Syntax Structures: Statement: [do something] Statement block: BEGIN [statement] [statement] END WHILE/DO: WHILE [condition] DO [statement] 08/09/14 T L Jong, Dept of E.E 24 Suggested Pseudo Code... 08/09/14 CASE /OF: CASE [expression] OF 1: [statement 1] 2: [statement 2] 3: [statement 3] n: [statement n] [default] END T L Jong, Dept of E.E 25 Assembly Language Programming Labels Use labels that are descriptive of the destination they represent Comments Use comments wherever possible Comment conditional jump instructions using a question similar to the flowchart Comment Blocks At the beginning of each... printer ;no, done and return T L Jong, Dept of E.E 31 Assembly Language Programming Saving Registers on the Stack Especially for nested subroutine calls, and building complex programs using subroutine building blocks Avoid changing the working registers when returns The Use of Equates Defining constants with equates makes programs easier o read and maintain The Use of Subroutines Divide and Conquer – subdivide... OUT CHARACTER CLR ACC.7 ;STRIP OFF PARITY BIT AND RET ;RETURN ; *************************************************************************************** * ;USES OUTCHR ; OUTSTR: MOV T L Jong, Dept of E.E A,@DPTR ;GET CHARACTER 08/09/14 35 JZ EXIT ;IF 0, DONE AND EXIT Assembly Language Programming Program Organization Equates  Initialization instructions  Main body of program  Subroutines  Data constant... occur 08/09/14 T L Jong, Dept of E.E 18 Pseudo Code Syntax Tips of using pseudo code:  Use descriptive language for statements  Avoid machine dependency in statements  Enclose conditions & statements in brackets: []  Begin all subroutines with their names followed by a set of parameters: ()  End all subroutine with RETURN ()  Use lower text except reserved words & subroutine names  Indent all... simple operations are programmed as subroutines and used as building blocks of the large complex program 08/09/14 T L Jong, Dept of E.E 32 OUTSTR SUBROUTINE EXAMPLE OUTCHR OUTSTR Enter Add odd parity To character Get a char From string Char != 0? Enter TX buffer empty? No Yes No Clear flag Yes OUTCHR Inc pointer 08/09/14 Exit Write character To transmitter Clear parity bit T L Jong, Dept of E.E Exit 33 OUTSTR... Comment Blocks At the beginning of each subroutine: name of the sub, operations, entry conditions, exit conditions, name of other subroutines used, name of registers affected, etc 08/09/14 T L Jong, Dept of E.E 26 INLINE SUBROUTINE EXAMPLE ;*************************************************************************************** ; ;INLINE INPUT LINE OF CHARACTERS ; LINE MUST END WITH ; MAXIMUM LENGTH... Jong, Dept of E.E 14 The CASE Statement Enter CASE [expression] OF 0: [statement 0] 1: [statement 1] 2: [statement 2] N: [statement 0] [default] END_CASE expression No expression No expression No 0? 1? 2? Yes Statement 0 Exit 08/09/14 Yes Statement 1 expression n? Yes Statement 2 No Yes Statement n T L Jong, Dept of E.E default 15 The CASE Statement [input a character] CASE [character] OF ‘0’: [statement... STORED AT END OF LINE ;USES INCHAR, OUTCHR ; ; *************************************************************************************** * INLINE: PUSH 00H ;SAVE R0 ON STACK PUSH 07H ;SAVE R7 ON STACK PUSH ACC ;SAVE ACCUMULATOR MOV R0,#60H ;SET UP BUFFER AT 60H MOV R7,#31 ;MAX LENGTH OF LINE STMENT: ACALL INCHAR ;INPUT A CHARACTER ACALL OUTCHR ;ECHO TO CONSOLE 08/09/14 27 MOV T L Jong, Dept of E.E BUFFER . Dept. of E.E. , NTHU 1 System & Program System & Program Developments of 8051 Developments of 8051  Program Structure and Design  Introduction  Advantages and Disadvantages of Structured. Dept. of E.E. , NTHU 5 Advantages & Disadvantages of Structured Programming  Advantages:  Simple to trace, debug  Finite number of structures  Structures as building block  The set of. syntax diagrams, pseudo code,  Increased program productivity 08/09/14 T. L. Jong, Dept. of E.E. , NTHU 6 Advantages & Disadvantages of Structured Programming  Disadvantages:  Only a few

Ngày đăng: 09/08/2014, 06:21