#if...#endif的用法总结
参考:https://www.cnblogs.com/lihuidashen/p/3485401.html
在写到 pwm音阶程序的时候,在代码中有#if...#endif的用法问题,相关音阶的代码如下:
1 /*******************************************************/
2 /* pwm音阶程序 */
3 /*******************************************************/
4
5
6 #include <hidef.h> /* common defines and macros */
7 #include "derivative.h" /* derivative-specific definitions */
8
9 #define LEDCPU PORTK_PK4
10 #define LEDCPU_dir DDRK_DDRK4 //
11 #define BUS_CLOCK 32000000
12 #define OSC_CLOCK 16000000
13
14
15 unsigned int sounghigh[10]={
16 4048,3816,3402,3030,2866,2551,2273,2024,1912,1704
17 };
18
19 unsigned int soundtone[8]={
20 1,2,3,4,5,6,7,8
21 };
22
23 unsigned int soundlong[8]={
24 1,1,1,1,1,1,1,1
25 };
26
27 unsigned int t;
28
29
30 /*******************************************************/
31 /* 初始化锁相环 */
32 /*******************************************************/
33 void INIT_PLL(void) {
34 CLKSEL &= 0x7f;
35 PLLCTL &= 0x8f;
36 CRGINT &= 0xdf;
37
38 #if(BUS_CLOCK == 40000000)
39 SYNR = 0x44;
40 #elif(BUS_CLOCK == 32000000)
41 SYNR = 0x43;
42 #elif(BUS_CLOCK == 24000000)
43 SYNR = 0x42;
44 #endif
45
46 REFDV = 0X81;
47 PLLCTL |= 0X70;
48 asm NOP;
49 asm NOP;
50 while(!(CRGFLG&0x08));
51 CLKSEL |= 0x80;
52 }
53
54
55 /*******************************************************/
56 /* 初始化PWM */
57 /*******************************************************/
58 void init_pwm(void) {
59 PWMCTL_CON01 = 1;
60 PWMPOL_PPOL1 = 1;
61 PWMPRCLK = 0X55;
62 PWMCLK = 0X00;
63 PWMPER01 = 3816;
64 PWME_PWME1 = 1;
65 }
66
67 /*******************************************************/
68 /* 延时函数 */
69 /*******************************************************/
70 void delay(void) {
71 unsigned int i,j;
72 for(i=0;i<10;i++)
73 for(j=0;j<50000;j++);
74 }
75
76 /*******************************************************/
77 /* 延时函数 */
78 /*******************************************************/
79 void delay2(unsigned