Files
8051_TimerDelay_1/Listings/TimerDelay_1.lst
2018-05-14 01:36:01 +08:00

163 lines
5.0 KiB
Plaintext
Executable File
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

C51 COMPILER V9.54 TIMERDELAY_1 05/05/2018 23:36:54 PAGE 1
C51 COMPILER V9.54, COMPILATION OF MODULE TIMERDELAY_1
OBJECT MODULE PLACED IN .\Objects\TimerDelay_1.obj
COMPILER INVOKED BY: C:\Keil_v5\C51\BIN\C51.EXE TimerDelay_1.c OPTIMIZE(8,SPEED) BROWSE DEBUG OBJECTEXTEND PRINT(.\Listi
-ngs\TimerDelay_1.lst) TABS(2) OBJECT(.\Objects\TimerDelay_1.obj)
line level source
1 //同一顆七節碼顯示 0 - 9每個號碼停留 1.5 秒
2
3 #include <reg51.h>
4
5 // 宣告 D 型正反器街接腳
6 sbit P2_6 = P2^6;
7 sbit P2_7 = P2^7;
8
9 // 宣告延時函式
10 void delay_1ms();
11 void delay_1500ms();
12
13 // 宣告七段顯示器函式
14 void Slect_Seg(unsigned char number);
15 void Display_Seg(unsigned char display);
16
17 //宣告數字的表示
18 char code NUM[10] = {
19 0x3F, // 0
20 0x06, // 1
21 0x5B, // 2
22 0x4F, // 3
23 0x66, // 4
24 0x6D, // 5
25 0x7D, // 6
26 0x07, // 7
27 0x7F, // 8
28 0x6F // 9
29 };
30
31 // 主程式
32 int main(){
33 1 // 設定哪顆亮
34 1 Slect_Seg(~0x01); // 0xfe 就是 11111110
35 1
36 1
37 1 // 不讓程式結束的無窮迴圈
38 1 while(1) {
39 2 // 選數字從 0 - 9
40 2 int i;
41 2 for(i = 0; i < 10; i++) {
42 3 Display_Seg(NUM[i]);
43 3 delay_1500ms(); // 延時 1.5 秒
44 3 }
45 2 }
46 1
47 1 }
48
49 void Slect_Seg(unsigned char number) {
50 1
51 1 // 關閉 D 型正反器(預防措施)
52 1 P2_7 = 0;
53 1
54 1 // 指定哪顆亮
C51 COMPILER V9.54 TIMERDELAY_1 05/05/2018 23:36:54 PAGE 2
55 1 P0 = number;
56 1
57 1 // 開啟控制哪顆亮的 D 型正反器
58 1 P2_7 = 1;
59 1
60 1 // 延時(吃哪顆亮)
61 1 delay_1ms();
62 1
63 1 // 關閉 D 型正反器(讓吃進去的那顆固定亮)
64 1 P2_7 = 0;
65 1 }
66
67 void Display_Seg(unsigned char display) {
68 1
69 1 // 關閉 D 型正反器(預防措施)
70 1 P2_6 = 0;
71 1
72 1 // 指定號碼
73 1 P0 = display;
74 1
75 1 // 開啟控制哪顆亮的 D 型正反器
76 1 P2_6 = 1;
77 1
78 1 // 延時(吃號碼)
79 1 delay_1ms();
80 1
81 1 // 關閉 D 型正反器(讓吃進去的號碼固定住)
82 1 P2_6 = 0;
83 1 }
84
85
86
87 // 延遲 1ms
88 void delay_1ms(void) {
89 1 //設定為 mode1
90 1 TMOD = 0x10;
91 1
92 1 //設定初始值
93 1 TF1 = 0;
94 1 TR1 = 0;
95 1 TL1 = (65536 - 9) % 256;
96 1 TH1 = (65536 - 9) / 256;
97 1
98 1 //開啟計時器
99 1 TR1 = 1;
100 1
101 1 //當 TF1 沒有溢位
102 1 while(TF1 == 0);
103 1
104 1 //關閉計時器
105 1 TR1 = 0;
106 1
107 1 //將 TF1 歸零
108 1 TF1 = 0;
109 1 }
110
111 // 延遲 1500ms
112 void delay_1500ms(void) {
113 1 //設定為 mode1
114 1 TMOD = 0x10;
115 1
116 1 //設定初始值
C51 COMPILER V9.54 TIMERDELAY_1 05/05/2018 23:36:54 PAGE 3
117 1 TF1 = 0;
118 1 TR1 = 0;
119 1 TL1 = (65536 - 13824) % 256;
120 1 TH1 = (65536 - 13824) / 256;
121 1
122 1 //開啟計時器
123 1 TR1 = 1;
124 1
125 1 //當 TF1 沒有溢位
126 1 while(TF1 == 0);
127 1
128 1 //關閉計時器
129 1 TR1 = 0;
130 1
131 1 //將 TF1 歸零
132 1 TF1 = 0;
133 1
134 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 122 ----
CONSTANT SIZE = 10 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- 2
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)