Files
8051_Interrupt_1/Listings/Interrupt_1.lst
2018-05-13 17:25:41 +08:00

102 lines
3.2 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.

C51 COMPILER V9.54 INTERRUPT_1 05/13/2018 16:58:21 PAGE 1
C51 COMPILER V9.54, COMPILATION OF MODULE INTERRUPT_1
OBJECT MODULE PLACED IN .\Objects\Interrupt_1.obj
COMPILER INVOKED BY: C:\Keil_v5\C51\BIN\C51.EXE Interrupt_1.c OPTIMIZE(8,SPEED) BROWSE DEBUG OBJECTEXTEND PRINT(.\Listin
-gs\Interrupt_1.lst) TABS(2) OBJECT(.\Objects\Interrupt_1.obj)
line level source
1 // Timer 0 take as interrupt
2 // Timer 1 take as delay
3
4 #include <reg51.h>
5
6 // 宣告延時函式
7 void delay10ms(void);
8
9 unsigned int timer0_counter = 150;
10
11 void main(void){
12 1
13 1 //開啟 Timer0 和 Timer1
14 1 TMOD = 0x11;
15 1
16 1 //interrupt control
17 1 TL0 = (65536 - 9216) % 256;
18 1 TH0 = (65536 - 9216) / 256;
19 1 TF0 = 0;
20 1 TR0 = 1; //開啟計時器 timer0
21 1 ET0 = 1; //開啟 TF0 的中斷模組開關
22 1 EA = 1; //開啟中斷模組總開關
23 1
24 1 delay10ms();
25 1
26 1 while(1){
27 2 // do LED move up to down per 1.5 sec
28 2 // using Timer 1 Mode 1 to generate 10ms delay
29 2 }
30 1 }
31
32
33 void delay10ms(void){
34 1 //設定初始值
35 1 TF1 = 0;
36 1 TR1 = 0;
37 1 TL1 = (65536-9216) % 256;
38 1 TH1 = (65536-9216) / 256;
39 1
40 1 //開啟計時器 timer1
41 1 TR1 = 1;
42 1
43 1 //當 TF1 沒有溢位
44 1 while(TF1 == 0);
45 1
46 1 //關閉計時器
47 1 TR1 = 0;
48 1
49 1 //將 TF1 歸零
50 1 TF1 = 0;
51 1 }
52
53
54 // timer0 在計時到的時候(TF0 = 1)會呼叫的中斷副函式
C51 COMPILER V9.54 INTERRUPT_1 05/13/2018 16:58:21 PAGE 2
55 void my_timer0(void) interrupt 1 {
56 1
57 1 //設定初始值
58 1 TL0 = (65536 - 9216) % 256;
59 1 TH0 = (65536 - 9216) / 256;
60 1 TF0 = 0;
61 1
62 1 // timer0_counter 一直遞減
63 1 timer0_counter--;
64 1
65 1
66 1 //當 timer0_counter 為 0 時,實作七段顯示器
67 1 if (timer0_counter == 0){
68 2 // 實作七段顯示器
69 2
70 2
71 2 //將 timer0_counter 的值設回 150
72 2 timer0_counter = 150;
73 2
74 2 }
75 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 74 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 2 ----
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)