📄 f411_vr_led.lst
字号:
C51 COMPILER V7.06 F411_VR_LED 02/18/2009 16:30:50 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE F411_VR_LED
OBJECT MODULE PLACED IN F411_VR_LED.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE F411_VR_LED.c BROWSE DEBUG OBJECTEXTEND
stmt level source
1 //-----------------------------------------------------------------------------
2 // F411_VR_LED.c
3 //-----------------------------------------------------------------------------
4 // Copyright 2006 Silicon Laboratories, Inc.
5 // http://www.silabs.com
6 //
7 // Program Description:
8 //
9 // This file contains the functions that use the PWM to brighten, dim, and
10 // flutter the LEDs.
11 //
12 // These functions work by using a pointer (LED_DCH) to an "LED byte," which
13 // is just a byte in memory associated with each LED. In F411_VR.c,
14 // one of the Timer ISRs updates the PCA PWM registers with all the LED bytes
15 // every interrupt period, so the LEDs that don't change are still updated,
16 // but visually nothing changes.
17 //
18 // When the timer interrupts, PCA0CPH1 is reloaded with the current value
19 // LED0_DC, which is changed by the functions (Dim, Brighten, and Flutter)
20 // based on the desired LED behavior. By decrementing the time the LED is
21 // on in steps (based on the ADJ variable), the LED appears to "dim" off,
22 // and by incrementing the time the LED is on in steps, the LED appears to
23 // "brighten" slowly.
24 //
25 // The LED_DCH pointer must be pointed to the correct LEDx_DC byte BEFORE
26 // each of these functions is called.
27 //
28 // LED_DCH -> LED0_DC -> PCA0CPH1, where CEX1 (output from the PCA) is tied
29 // to LED0
30 //
31 // For example, the resulting dim LED waveform might look something like
32 // this, since the LEDs are ON when CEX1 = 0:
33 //
34 // _ __ ___
35 // CEX1 _____________________________| |____________| |___________| |
36 //
37 // | 1st step | 2nd step | 3rd step | 4th step |
38 //
39 // (continued)
40 // ____ _____ ______ _______
41 // CEX1 __________| |_________| |________| |_______| |
42 //
43 // | 5th step | 6th step | 7th step | 8th step |
44 //
45 // (continued)
46 // ________ _________ __________ ___________
47 // CEX1 ______| |_____| |____| |___| |
48 //
49 // | 9th period | 10th period | 11th period | 12th period |
50 //
51 // (continued)
52 // ____________ _____________________________________________
53 // CEX1 __| |_|
54 //
55 // | 13th period | 14th period | 15th period | 16th period |
C51 COMPILER V7.06 F411_VR_LED 02/18/2009 16:30:50 PAGE 2
56 //
57 // The LED has appeared to "dim" slowly off.
58 //
59 //
60 //
61 // NOTE: The calling function must have the same register context as the LED
62 // functions, so it must either have the keyword "using 0" or all "using 0"
63 // keywords for the LED functions need to be removed.
64 //
65 // How To Use: See Readme.txt
66 //
67 // FID: 41X000008
68 // Target: C8051F411
69 // Tool chain: Keil C51 7.50 / Keil EVAL C51
70 // Silicon Laboratories IDE version 2.6
71 // Project Name: F411_VR
72 //
73 // Release 1.3
74 // -All changes by TP
75 // -02 Feb 2006
76 // -project version updated, no changes to this file
77 //
78 // Release 1.2
79 // -All changes by TP
80 // -21 Nov 2005
81 // -project version updated, no changes to this file
82 //
83 // Release 1.1
84 // -All changes by TP
85 // -16 Aug 2004
86 // -project version updated, no changes to this file
87 //
88 // Release 1.0
89 // -Initial Revision (TP)
90 // -15 AUG 2004
91 //
92
93 //-----------------------------------------------------------------------------
94 // Includes
95 //-----------------------------------------------------------------------------
96 #include <c8051f410.h> // SFR declarations
97
98 //-----------------------------------------------------------------------------
99 // Global Variables
100 //-----------------------------------------------------------------------------
101 unsigned char ADJ = 15;
102 unsigned int LED_PWM = 65535;
103 int LED_PWM_CHANGE = 0x0000;
104 unsigned char *LED_DCH;
105 unsigned char LED0_DC = 0x00;
106 unsigned char LED1_DC = 0x00;
107 // add another LEDx_DC variable here, if desired, and point to it with *LED_DCH
108 // before calling the LED functions
109
110 //-----------------------------------------------------------------------------
111 // Function PROTOTYPES
112 //-----------------------------------------------------------------------------
113 void Dim_LED (void);
114 void Brighten_LED (void);
115 void Flutter_LED (void);
116
117
C51 COMPILER V7.06 F411_VR_LED 02/18/2009 16:30:50 PAGE 3
118 //-----------------------------------------------------------------------------
119 // Dim_LED
120 //-----------------------------------------------------------------------------
121 //
122 // Return Value : None
123 // Parameters : None
124 //
125 // Dim the LED using the PCA in 8-bit PWM mode. The Timer0 ISR in
126 // F411_VR.c updates the value LED_DCH is pointing to.
127 //
128 // NOTE: This function requires that the LED_DCH pointer be "pointing" to the
129 // appropriate LED byte, as explained above.
130 //
131 void Dim_LED (void) using 0
132 {
133 1 // retrieve the previous value of the duty cycle
134 1 unsigned char duty_cycle = *LED_DCH;
135 1
136 1 ADJ = 0xF1; // set the ADJ such that the LED will
137 1 // get dimmer
138 1 LED_PWM = 65535; // reset the Timer 0 interval
139 1 LED_PWM_CHANGE = 0; // do not change the Timer 0 interval
140 1 TCON |= 0x10; // start Timer 0
141 1
142 1 // wait until the LED is fully off
143 1 while (duty_cycle != 0x00)
144 1 {
145 2 duty_cycle = *LED_DCH;
146 2 }
147 1
148 1 TCON &= ~0x10; // stop Timer 0 (no more updates to the
149 1 // PCA duty cycle)
150 1 }
151
152 //-----------------------------------------------------------------------------
153 // Brighten_LED
154 //-----------------------------------------------------------------------------
155 //
156 // Return Value : None
157 // Parameters : None
158 //
159 // Brighten the LED using the PCA in 8-bit PWM mode. The Timer0 ISR in
160 // F411_VR.c updates the value LED_DCH is pointing to.
161 //
162 // NOTE: This function requires that the LED_DCH pointer be "pointing" to the
163 // appropriate LED byte, as explained above.
164 //
165 void Brighten_LED (void) using 0
166 {
167 1 // retrieve the previous value of the duty cycle
168 1 unsigned char duty_cycle = *LED_DCH;
169 1
170 1 ADJ = 0x0F; // set the ADJ such that the LED will
171 1 // brighten
172 1 LED_PWM = 65535; // reset the Timer 0 interval
173 1 LED_PWM_CHANGE = 0; // do not change the Timer 0 interval
174 1 TCON |= 0x10; // start Timer 0
175 1
176 1 // wait until the LED is fully on
177 1 while (duty_cycle != 0xFF)
178 1 {
179 2 duty_cycle = *LED_DCH;
C51 COMPILER V7.06 F411_VR_LED 02/18/2009 16:30:50 PAGE 4
180 2 }
181 1
182 1 TCON &= ~0x10; // stop Timer 0 (no more updates to the
183 1 // PCA duty cycle)
184 1 }
185
186 //-----------------------------------------------------------------------------
187 // Flutter_LED
188 //-----------------------------------------------------------------------------
189 //
190 // Return Value : None
191 // Parameters : None
192 //
193 // Cause the LED to dim on and off. The Timer0 ISR in F411_VR.c updates
194 // the value LED_DCH is pointing to.
195 //
196 // NOTE: This function requires that the LED_DCH pointer be "pointing" to the
197 // appropriate LED byte, as explained above.
198 //
199 void Flutter_LED (void) using 0
200 {
201 1 // retrieve the previous value of the duty cycle
202 1 unsigned char duty_cycle = *LED_DCH;
203 1
204 1 // check if the LED is currently on or off
205 1 if (duty_cycle == 0xFF)
206 1 {
207 2 ADJ = 0xF1;
208 2 }
209 1 else
210 1 {
211 2 ADJ = 0x0F;
212 2 }
213 1 LED_PWM = 65535; // reset the Timer 0 interval
214 1 LED_PWM_CHANGE = -200; // change the Timer 0 interval each
215 1 // interrupt cycle so the LED has a
216 1 // "fluttering" effect
217 1 TCON |= 0x10; // start Timer 0
218 1
219 1 // Wait for a flutter cycle to finish
220 1 while (LED_PWM > 17000)
221 1 {
222 2 }
223 1
224 1 TCON &= ~0x10; // stop Timer 0 (no more updates to the
225 1 // PCA duty cycle)
226 1 }
227
228 //-----------------------------------------------------------------------------
229 // End Of File
230 //-----------------------------------------------------------------------------
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 164 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 10 ----
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILER V7.06 F411_VR_LED 02/18/2009 16:30:50 PAGE 5
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -