Files
8051_Segment_2/Listings/Segment_2.lst
2018-05-06 01:52:40 +08:00

122 lines
3.8 KiB
Plaintext
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 SEGMENT_2 05/05/2018 22:03:39 PAGE 1
C51 COMPILER V9.54, COMPILATION OF MODULE SEGMENT_2
OBJECT MODULE PLACED IN .\Objects\Segment_2.obj
COMPILER INVOKED BY: C:\Keil_v5\C51\BIN\C51.EXE Segment_2.c OPTIMIZE(8,SPEED) BROWSE DEBUG OBJECTEXTEND PRINT(.\Listings
-\Segment_2.lst) TABS(2) OBJECT(.\Objects\Segment_2.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(int);
11
12 // 宣告七段顯示器函式
13 void Slect_Seg(unsigned char number);
14 void Display_Seg(unsigned char display);
15
16 //宣告數字的表示
17 char code NUM[10] = {
18 0x3F, // 0
19 0x06, // 1
20 0x5B, // 2
21 0x4F, // 3
22 0x66, // 4
23 0x6D, // 5
24 0x7D, // 6
25 0x07, // 7
26 0x7F, // 8
27 0x6F // 9
28 };
29
30 char code POS[6] = {
31 ~0x01, // 0xfe 就是 11111110
32 ~0x02, // 0000 0010
33 ~0x04, // 0000 0100
34 ~0x08, // 0000 1000
35 ~0x10, // 0001 0000
36 ~0x20 // 0010 0000
37 };
38
39
40 // 主程式
41 int main(){
42 1
43 1 int i, j = 0;
44 1 // 不讓程式結束的無窮迴圈
45 1 while(1) {
46 2 Slect_Seg(POS[i]); // 設定哪顆亮
47 2 Display_Seg(NUM[j]); // 選數字
48 2 delay(1500); // 延時 1.5 秒
49 2 i = (i + 1) % 6;
50 2 j = (j + 1) % 10;
51 2 }
52 1 }
53
54 void Slect_Seg(unsigned char number) {
C51 COMPILER V9.54 SEGMENT_2 05/05/2018 22:03:39 PAGE 2
55 1
56 1 // 關閉 D 型正反器(預防措施)
57 1 P2_7 = 0;
58 1
59 1 // 指定哪顆亮
60 1 P0 = number;
61 1
62 1 // 開啟控制哪顆亮的 D 型正反器
63 1 P2_7 = 1;
64 1
65 1 // 延時(吃哪顆亮)
66 1 delay(1);
67 1
68 1 // 關閉 D 型正反器(讓吃進去的那顆固定亮)
69 1 P2_7 = 0;
70 1 }
71
72 void Display_Seg(unsigned char display) {
73 1
74 1 // 關閉 D 型正反器(預防措施)
75 1 P2_6 = 0;
76 1
77 1 // 指定號碼
78 1 P0 = display;
79 1
80 1 // 開啟控制哪顆亮的 D 型正反器
81 1 P2_6 = 1;
82 1
83 1 // 延時(吃號碼)
84 1 delay(1);
85 1
86 1 // 關閉 D 型正反器(讓吃進去的號碼固定住)
87 1 P2_6 = 0;
88 1 }
89
90 // 延遲
91 void delay(int time) {
92 1 unsigned int i, j;
93 1 for (i = 0; i < time; i++)
94 1 for (j = 0; j < 120; j++);
95 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 154 ----
CONSTANT SIZE = 16 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- 4
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)