📄 main.lst
字号:
C51 COMPILER V6.11 MAIN 03/29/2001 16:17:12 PAGE 1
C51 COMPILER V6.11, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN .\main.OBJ
COMPILER INVOKED BY: C:\KEIL\C51\BIN\C51.EXE .\main.c DEBUG OBJECTEXTEND
stmt level source
1 #include <Reg768.h>
2 #include <stdio.h>
3
4 #define TIMER0_COUNT 0xD906 //10000h-((6,000,000Hz / (6 * FREQ))-12)
5 static unsigned timer0_tick; // Tick timer for funct0();
6 static unsigned timer1_tick; // Tick timer for funct1();
7 static bit bzy_flag0, bzy_flag1;
8
9 /*******************************************
10 Function Prototypes
11 ********************************************/
12 void timer0_initialize (void);
13 void serial_init(void);
14 void funct0(void);
15 void funct1(void);
16
17
18 void main (void)
19 {
20 1 serial_init();
21 1 timer0_initialize ();
22 1 bzy_flag0 = bzy_flag1 = 0;
23 1
24 1 while(1) // Call functions Round Robin
25 1 {
26 2 funct0();
27 2 funct1();
28 2 }
29 1 }
30
31 void funct0(void)
32 {
33 1 if(!bzy_flag0) // If task not active make task ready
34 1 {
35 2 bzy_flag0 = 1; // Set busy flag bit
36 2 timer0_tick = 0; // Clear timer0_tick count
37 2 }
38 1
39 1 if(timer0_tick >= 100) // Suspend task for delay
40 1 {
41 2 printf("In funct0 task.\n");
42 2 bzy_flag0 = 0;
43 2 }
44 1 }
45
46 void funct1(void)
47 {
48 1 if(!bzy_flag1) // If task not active make task ready
49 1 {
50 2 bzy_flag1 = 1; // Set busy flag bit
51 2 timer1_tick = 0; // Clear timer1_tick count
52 2 }
53 1
54 1 if(timer1_tick >= 400) // Suspend task for delay
55 1 {
C51 COMPILER V6.11 MAIN 03/29/2001 16:17:12 PAGE 2
56 2 printf("In funct1 task.\n");
57 2 bzy_flag1 = 0; // Task is complete - Make not active
58 2 }
59 1 }
60
61 /******************************************************************************
62 static void timer0_isr (void);
63 This function is an interrupt service routine for TIMER 0. It should never
64 be called by a C or assembly function. It will be executed automatically
65 when TIMER 0 overflows.
66 *******************************************************************************/
67 static void timer0_isr (void) interrupt 1 using 1
68 {
69 1 /*********************************************************
70 1 Stop Timer 0, adjust the timer 0 counter so that
71 1 we get another interrupt in 10ms, and restart the
72 1 timer.
73 1 **********************************************************/
74 1
75 1 TR0 = 0; // stop timer 0
76 1 TL0 = TL0 + (TIMER0_COUNT & 0x00FF);
77 1 TH0 = TH0 + (TIMER0_COUNT >> 8);
78 1 TR0 = 1; // start timer 0
79 1
80 1 /********************************************************
81 1 Increment the timer tick. This interrupt should
82 1 occur approximately every 10ms.
83 1 *********************************************************/
84 1 timer0_tick++;
85 1 timer1_tick++;
86 1 }
87
88 /******************************************************************************
89 void timer0_initialize (void);
90 This function enables TIMER 0. TIMER 0 generates an interrupt every 100Hz.
91 ******************************************************************************/
92 void timer0_initialize (void)
93 {
94 1 EA = 0; // disable all interrupts
95 1 TR0 = 0; // stop timer 0
96 1 TMOD &= ~0x0F; // clear timer 0 mode bits
97 1 TMOD |= 0x01; // put timer 0 into 16-bit no prescale
98 1 TL0 = (TIMER0_COUNT & 0x00FF);
99 1 TH0 = (TIMER0_COUNT >> 8);
100 1 PT0 = 0; // set low priority for timer 0
101 1 ET0 = 1; // enable timer 0 interrupt
102 1 TR0 = 1; // start timer 0
103 1 EA = 1; // enable interrupts
104 1 }
105
106 /*****************************************************
107 Configure the serial port to run at 1200 Baud using
108 timer 1 as an 8 bit auto reload baud rate generator
109 *****************************************************/
110
111 void serial_init(void)
112 {
113 1
114 1 SCON = 0x50; // set UART as 8-bit mode 1
115 1 TMOD |= 0x20; // put timer 1 into 8-bit autoload mode 2
116 1 TH1 = 0xA9; // reload value for 1200 baud
117 1 TR1 = 1; // enable timer 1
C51 COMPILER V6.11 MAIN 03/29/2001 16:17:12 PAGE 3
118 1 TI = 1; // enable first transmitt
119 1 }
120
121
122
123
124
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 164 ----
CONSTANT SIZE = 34 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 4 ----
IDATA SIZE = ---- ----
BIT SIZE = 2 ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -