📄 pwm.lst
字号:
ARM COMPILER V0.12, PWM 08/10/04 14:12:24 PAGE 1
ARM COMPILER V0.12, COMPILATION OF MODULE PWM
OBJECT MODULE PLACED IN .\Flash\PWM.obj
COMPILER INVOKED BY: C:\Keil\ARM\BIN\CA.exe PWM.c THUMB OPTIMIZE(7,SPEED) BROWSE DEBUG PRINT(.\FLASH\PWM.LST) TABS(4) OB
-JECT(.\Flash\PWM.obj)
stmt level source
1 /******************************************************************************/
2 /* This file is part of the uVision/ARM development tools */
3 /* Copyright KEIL ELEKTRONIK GmbH 2002-2004 */
4 /******************************************************************************/
5 /* */
6 /* PWM.C: LED Flasher */
7 /* */
8 /******************************************************************************/
9
10 #include <LPC21xx.H> /* LPC21xx definitions */
11
12 void PWM0_isr(void) __irq
13 {
14 1 PWMIR |= 0x00000001; /* Clear match0 interrupt */
15 1 VICVectAddr = 0x00000000;
16 1 }
17
18
19 void poll_ADC (void) { /* Get ADC Value and set PWM */
20 1 unsigned int cnt;
21 1 unsigned int val;
22 1 static unsigned int oldval;
23 1
24 1 ADCR |= 0x01000000; /* Start A/D Conversion */
25 1 do {
26 2 val = ADDR; /* Read A/D Data Register */
27 2 } while ((val & 0x80000000) == 0); /* Wait for end of A/D Conversion */
28 1 ADCR &= ~0x01000000; /* Stop A/D Conversion */
29 1 val = (val >> 6) & 0x03FF; /* Extract AIN0 Value */
30 1
31 1 if ((val != oldval)) {
32 2 PWMMR2 = val;
33 2 PWMLER = 0x4; /* Enable Shadow latch */
34 2 oldval = val;
35 2 }
36 1 }
37
38
39 void init_PWM (void) {
40 1
41 1 VICVectAddr8 = (unsigned)PWM0_isr; /* Set the PWM ISR vector address */
42 1 VICVectCntl8 = 0x00000028; /* Set channel */
43 1 VICIntEnable = 0x00000100; /* Enable the interrupt */
44 1
45 1 PINSEL0 |= 0x00028008; /* Enable P0.7 and P0.1 as PWM output */
46 1 PWMPR = 0x00000000; /* Load prescaler */
47 1
48 1 PWMPCR = 0x00000C0C; /* PWM channel 2 & 3 double edge control, output enabled */
49 1 PWMMCR = 0x00000003; /* On match with timer reset the counter */
50 1 PWMMR0 = 0x400; /* set cycle rate to sixteen ticks */
51 1 PWMMR1 = 0; /* set rising edge of PWM2 to 100 ticks */
52 1 PWMMR2 = 0x200; /* set falling edge of PWM2 to 200 ticks */
53 1 PWMMR3 = 0x400; /* set rising edge of PWM3 to 100 ticks */
54 1 PWMLER = 0xF; /* enable shadow latch for match 1 - 3 */
55 1 PWMEMR = 0x00210A8E; /* Match 1 and Match 2 outputs set high */
56 1 PWMTCR = 0x00000002; /* Reset counter and prescaler */
57 1 PWMTCR = 0x00000009; /* enable counter and PWM, release counter from reset */
58 1 }
ARM COMPILER V0.12, PWM 08/10/04 14:12:24 PAGE 2
59
60
61 int main (void) {
62 1 unsigned int n;
63 1 int rx_char;
64 1
65 1 IODIR1 = 0x00FF0000; /* P1.16..23 defined as Outputs */
66 1 ADCR = 0x01200401; /* Setup A/D: 10-bit AIN0 @ 3MHz */
67 1 init_PWM();
68 1
69 1 while (1) { /* Loop forever */
70 2 poll_ADC();
71 2 }
72 1 }
ARM COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -