Files
8051_Segment_1/Listings/Segment_1.lst
2018-05-06 01:49:17 +08:00

116 lines
3.7 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_1 05/05/2018 22:08:09 PAGE 1
C51 COMPILER V9.54, COMPILATION OF MODULE SEGMENT_1
OBJECT MODULE PLACED IN .\Objects\Segment_1.obj
COMPILER INVOKED BY: C:\Keil_v5\C51\BIN\C51.EXE Segment_1.c OPTIMIZE(8,SPEED) BROWSE DEBUG OBJECTEXTEND PRINT(.\Listings
-\Segment_1.lst) TABS(2) OBJECT(.\Objects\Segment_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(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 // 主程式
31 int main(){
32 1 // 設定哪顆亮
33 1 Slect_Seg(~0x01); // 0xfe 就是 11111110
34 1
35 1
36 1 // 不讓程式結束的無窮迴圈
37 1 while(1) {
38 2 // 選數字從 0 - 9
39 2 int i;
40 2 for(i = 0; i < 10; i++) {
41 3 Display_Seg(NUM[i]);
42 3 delay(1500); // 延時 1.5 秒
43 3 }
44 2 }
45 1
46 1 }
47
48 void Slect_Seg(unsigned char number) {
49 1
50 1 // 關閉 D 型正反器(預防措施)
51 1 P2_7 = 0;
52 1
53 1 // 指定哪顆亮
54 1 P0 = number;
C51 COMPILER V9.54 SEGMENT_1 05/05/2018 22:08:09 PAGE 2
55 1
56 1 // 開啟控制哪顆亮的 D 型正反器
57 1 P2_7 = 1;
58 1
59 1 // 延時(吃哪顆亮)
60 1 delay(1);
61 1
62 1 // 關閉 D 型正反器(讓吃進去的那顆固定亮)
63 1 P2_7 = 0;
64 1 }
65
66 void Display_Seg(unsigned char display) {
67 1
68 1 // 關閉 D 型正反器(預防措施)
69 1 P2_6 = 0;
70 1
71 1 // 指定號碼
72 1 P0 = display;
73 1
74 1 // 開啟控制哪顆亮的 D 型正反器
75 1 P2_6 = 1;
76 1
77 1 // 延時(吃號碼)
78 1 delay(1);
79 1
80 1 // 關閉 D 型正反器(讓吃進去的號碼固定住)
81 1 P2_6 = 0;
82 1 }
83
84 // 延遲
85 void delay(int time) {
86 1 unsigned int i, j;
87 1 for (i = 0; i < time; i++)
88 1 for (j = 0; j < 120; j++);
89 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 120 ----
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)