Bài giảng Vi xử lý: Chương 3.9 - Bùi Minh Thành
lượt xem 6
download
Bài giảng "Vi xử lý - Chương 3.9: System và program developments of 8051" giới thiệu tới người đọc các nội dung: Flowcharts, pseudo code, The development environment, intel hexadecimal format, integration and verification, hardware development, designing software,... Mời các bạn cùng tham khảo nội dung chi tiết.
Bình luận(0) Đăng nhập để gửi bình luận!
Nội dung Text: Bài giảng Vi xử lý: Chương 3.9 - Bùi Minh Thành
- System & Program 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 2011/12/7 T. L. Jong, Dept. of E.E., NTHU 1
- 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 2011/12/7 T. L. Jong, Dept. of E.E., NTHU 2
- Flowcharts Decision block Off-page connector Process box Predefined process (subroutine) Input/Output block Program flow arrow Program terminator 2011/12/7 T. L. Jong, Dept. of E.E., NTHU 3
- 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 2011/12/7 T. L. Jong, Dept. of E.E., NTHU 4
- 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 2011/12/7 T. L. Jong, Dept. of E.E., NTHU 5
- 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 2011/12/7 T. L. Jong, Dept. of E.E., NTHU 6
- The Three Structures Statements [count= 0] PRINT_STRING(“Select Option:”) Loops (iteration) WHILE/DO REPEAT/UNTIL Choice IF/THEN/ELSE CASE 2011/12/7 T. L. Jong, Dept. of E.E., NTHU 7
- The WHILE/DO Statement WHILE [condition] DO [statement] (statement might not be performed at all!) Enter WHILE [c == 1] DO [statement] Condition No True? ENTER: JNC EXIT STATEMENT: (statement) Yes JMP ENTER EXIT: (continue) Statement Exit 2011/12/7 T. L. Jong, Dept. of E.E., NTHU 8
- WHILE/DO: SUM Subroutine [sum (A) = 0] WHILE [length (R7) > 0] DO BEGIN [sum = sum + @pointer (R0)] [increment pointer] [decrement length] END 8051 code (closely structured; 13 bytes) (loosely structured; 9 bytes) SUM: CLR A SUM: CLR A LOOP: CJNZ R7,#0,STAM INC R7 JMP EXIT MORE: DJNZ R7,SKIP STAM: ADD A,@R0 RET INC R0 SKIP: ADD A,@R0 DEC R7 INC R0 JMP LOOP: SJMP MORE EXIT: RET 2011/12/7 T. L. Jong, Dept. of E.E., NTHU 9
- WHILE/DO Pseudo code: WHILE [ACC != CR AND R7 != 0] DO [statement] Enter 8051 code: No ENTER: CJNE A,#0DH,SKIP ACC != ? JMP EXIT SKIP: CJNE R7,#0,STAM Yes JMP EXIT No STAM: (one or more statements) R7 != 0? . Yes . JMP ENTER Statement Exit EXIT: (continue) 2011/12/7 T. L. Jong, Dept. of E.E., NTHU 10
- The REPEAT/UNTIL Statement REPEAT [statement] UNTIL [condition] (statement performed at least once) Enter REPEAT [statement] UNTIL [c == 1] Statement ENTER: (statement) No JNC ENTER Condition EXIT: (continue) True? Yes Exit 2011/12/7 T. L. Jong, Dept. of E.E., NTHU 11
- The REPEAT/UNTIL Statement REPEAT [ACC = @pointer] [increment pointer] UNTIL [ACC == ‘Z’ or ACC == 0] Enter 8051 code: Get a char STAM: MOV A,@R0 INC R0 JZ EXIT Inc pointer CJNE A,#’Z’,STAM No EXIT: RET Char = No Char = “Z”? 0? Yes Yes Exit 2011/12/7 T. L. Jong, Dept. of E.E., NTHU 12
- The IF/THEN/ELSE Statement IF [condition] THEN [statement 1] ELSE [statement 2] Enter No condition Yes true? Statement 2 Statement 1 Exit 2011/12/7 T. L. Jong, Dept. of E.E., NTHU 13
- The IF/THEN/ELSE Statement [input character] IF [input character == graphic] THEN [echo character] ELSE [echo ‘.’] 8051 code: (closely structured; 14 bytes) Enter ENTER: ACALL INCH ACALL ISGRPH JNC STMENT2 STMENT1: ACALL OUTCH Input character JMP EXIT STMENT2: MOV A,#’.’ ACALL OUTCH No Graphic Yes EXIT: (continue) char? (loosely structured; 10 bytes) ACALL INCH Echo “.” Echo char ACALL ISGRPH JC SKIP MOV A,#’.’ SKIP: ACALL OUTCH Exit (continue) 2011/12/7 T. L. Jong, Dept. of E.E., NTHU 14
- The CASE Statement CASE [expression] OF 0: [statement 0] 1: [statement 1] 2: [statement 2] . . N: [statement 0] [default] Enter END_CASE expression No expression No expression No expression No 0? 1? 2? n? Yes Yes Yes Yes Statement 0 Statement 1 Statement 2 Statement n default Exit 2011/12/7 T. L. Jong, Dept. of E.E., NTHU 15
- The CASE Statement [input a character] CASE [character] OF ‘0’: [statement 0] ‘1’: [statement 1] ‘2’: [statement 2] Enter ‘3’: [statement 3] END_CASE Input character char No char No char No char No == “0”? == “1”? == “2”? == “3”? Yes Yes Yes Yes Action 0 Action 1 Action 2 Action 3 Exit 2011/12/7 T. L. Jong, Dept. of E.E., NTHU 16
- The CASE Statement 8051 code: (loosely structured) (closely structured) ACALL INCH ACALL INCH ANL A,#3 ;reduce to 3 bits CJNE A,#’0’,SKIP1 RL A ACT0: . MOV DPTR,#TABLE . JMP @A+DPTR JMP EXIT TABLE: AJMP ACT0 SKIP1: CJNE A,#’1’,SKIP2 AJMP ACT1 ACT1: . AJMP ACT2 . ACT3: . JMP EXIT . SKIP2: CJNE A,#’2’,SKIP3 JMP EXIT ACT2: . ACT0: . . . JMP EXIT JMP EXIT SKIP3: CJNE A,#’3’,EXIT ACT1: . ACT3: . . . JMP EXIT ACT2: . EXIT: (continue) . EXIT: (continue) 2011/12/7 T. L. Jong, Dept. of E.E., NTHU 17
- The GOTO Statement GOTO statement can always be avoided by using the structures. Sometimes GOTO statement provides an easy method of terminating a structure when errors occur. GOTO statements usually becomes unconditional jump in assembly implementation. Extreme caution is needed. Never exit a subroutine using GOTO instead of normal return for the return address will be left on the stack and eventually stack overflow will occur. 2011/12/7 T. L. Jong, Dept. of E.E., NTHU 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 statements from the structure entry points and exit points Use the commercial at sign (@) for indirect addressing 2011/12/7 T. L. Jong, Dept. of E.E., NTHU 19
- Suggested Pseudo Code Syntax Reserved words: BEGIN END REPEAT UNTIL WHILE DO IF THEN ELSE CASE OF RETURN Arithmetic operators: + addition - subtraction * multiplication / division % modulus (remainder after division) 2011/12/7 T. L. Jong, Dept. of E.E., NTHU 20
CÓ THỂ BẠN MUỐN DOWNLOAD
-
Bài giảng Vi xử lý - Chương 4: Tập lệnh và lập trình điều khiển
43 p | 245 | 35
-
Bài giảng Vi xử lý - Chương 9: Ứng dụng
17 p | 136 | 19
-
Bài giảng Vi xử lý: Chương 2 - Bùi Minh Thành
87 p | 156 | 16
-
Bài giảng Vi xử lý: Chương 5 - Bùi Minh Thành (tt)
84 p | 132 | 11
-
Bài giảng Vi xử lý: Chương 3.1 - Bùi Minh Thành
101 p | 119 | 11
-
Bài giảng Vi xử lý: Chương 5 - Bùi Minh Thành
140 p | 136 | 10
-
Bài giảng Vi xử lý: Chương 3.5 - Bùi Minh Thành
18 p | 125 | 10
-
Bài giảng Vi xử lý: Chương 3.4 - Bùi Minh Thành
75 p | 95 | 8
-
Bài giảng Vi xử lý: Chương 1 - Bùi Minh Thành
135 p | 85 | 7
-
Bài giảng Vi xử lý: Chương 3.7 - Bùi Minh Thành
26 p | 104 | 7
-
Bài giảng Vi xử lý - Chương 7: Ngắt quãng
14 p | 81 | 7
-
Bài giảng Vi xử lý- Chương 6: Giao tiếp ngoại vi
41 p | 99 | 6
-
Bài giảng Vi xử lý: Chương 3.6 - Bùi Minh Thành
39 p | 79 | 6
-
Bài giảng Vi xử lý: Chương 3.8 - Bùi Minh Thành
49 p | 87 | 6
-
Bài giảng Vi xử lý - Chương 10: Vi điều khiển H8
55 p | 110 | 5
-
Bài giảng Vi xử lý - Chương 8: Các chức năng đặc biệt
64 p | 89 | 5
-
Bài giảng Vi xử lý- Chương 5: Bộ định thi
25 p | 82 | 4
Chịu trách nhiệm nội dung:
Nguyễn Công Hà - Giám đốc Công ty TNHH TÀI LIỆU TRỰC TUYẾN VI NA
LIÊN HỆ
Địa chỉ: P402, 54A Nơ Trang Long, Phường 14, Q.Bình Thạnh, TP.HCM
Hotline: 093 303 0098
Email: support@tailieu.vn