F28035_ADC(2)

云书歌谣 分享 2019-03-29 下载文档

58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. 74. 75. 76. 77. 78. 79. 80. 81. 82. 83. 84. 85. 86. 87. 88. 89. 90. 91. 92. 93. 94. 95. 96. 97. 98. 99. 100. 101. void main(void) {

// Step 1. Initialize System Control:

// PLL, WatchDog, enable Peripheral Clocks

// This example function is found in the DSP2802x_SysCtrl.c file. InitSysCtrl();

// Step 2. Initalize GPIO:

// This example function is found in the DSP2802x_Gpio.c file and // illustrates how to set the GPIO to it's default state. // InitGpio(); // Skipped for this example

// Step 3. Clear all interrupts and initialize PIE vector table: // Disable CPU interrupts DINT;

// Initialize PIE control registers to their default state. // The default state is all PIE interrupts disabled and flags // are cleared.

// This function is found in the DSP2802x_PieCtrl.c file. InitPieCtrl();

// Disable CPU interrupts and clear all CPU interrupt flags: IER = 0x0000; IFR = 0x0000;

// Initialize the PIE vector table with pointers to the shell Interrupt // Service Routines (ISR).

// This will populate the entire table, even if the interrupt

// is not used in this example. This is useful for debug purposes. // The shell ISR routines are found in DSP2802x_DefaultIsr.c. // This function is found in DSP2802x_PieVect.c. InitPieVectTable();

// Step 4. Initialize all the Device Peripherals:

// This function is found in DSP2802x_InitPeripherals.c // InitPeripherals(); // Not required for this example

// Step 5. User specific code:

InitAdc();

102. 103. 104. 105. 106. 107. 108. 109. 110. 111. 112. 113. 114. 115. 116. 117. 118. 119. 120. 121. 122. 123. 124. 125. 126. 127. 128. 129. 130. 131. 132. 133. 134. 135. 136. 137. 138. 139. 140. 141. 142. 143. 144. 145.

EALLOW;

AdcRegs.ADCSAMPLEMODE.bit.SIMULEN0 = 1; //同时采样 AdcRegs.ADCSOC0CTL.bit.CHSEL = 4; //soc通道选择 AdcRegs.ADCSOC1CTL.bit.CHSEL = 12;

AdcRegs.ADCSOC0CTL.bit.ACQPS = 6; //采样时间 AdcRegs.ADCSOC1CTL.bit.ACQPS = 6;

AdcRegs.ADCSOC0CTL.bit.TRIGSEL = 1; //soc触发选择,TIM0

AdcRegs.ADCCTL1.bit.INTPULSEPOS = 1; //结果存入寄存器才产生中断

PieVectTable.ADCINT1 = &ADC_convered;

AdcRegs.INTSEL1N2.bit.INT1SEL = 1; //中断线1选择soc1 AdcRegs.INTSEL1N2.bit.INT1CONT = 0;

AdcRegs.INTSEL1N2.bit.INT1E = 1; //中断使能

PieCtrlRegs.PIEIER1.bit.INTx1 = 1; //使能int1.1 EDIS;

/****************设置定时器,用以触发ADC*****************/ CpuTimer0Regs.TPR.bit.TDDR = 59;

CpuTimer0Regs.TPRH.bit.TDDRH = 0; //对输入时钟60分频,60M/60=1M CpuTimer0Regs.PRD.all = 500000;//定时0.5s CpuTimer0Regs.TCR.bit.TRB = 1; //reload CpuTimer0Regs.TCR.bit.TIE = 1; //使能中断 CpuTimer0Regs.TCR.bit.TSS = 0; //开始计数

EALLOW;

PieVectTable.TINT0 = &tim0_isr;

PieCtrlRegs.PIECTRL.bit.ENPIE = 1; //使能PIE PieCtrlRegs.PIEIER1.bit.INTx7 = 1; //使能int1.7 IER |= 0x0001;//使能GROUP1 EINT; EDIS;

LEDs_init(); while(1) { }; }

interrupt void ADC_convered(void) {

146. LED_toggle(LED2);

147. ADCINA4_Voltage_sum += AdcResult.ADCRESULT0; 148. ADCINB4_Voltage_sum += AdcResult.ADCRESULT1; 149. AdcRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; 150. PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; 151. convered_count++;

152. /*********转换16次,取平均值*********/ 153. if(convered_count > 15) 154. {

155. ADCINA4_Voltage = ADCINA4_Voltage_sum >> 4;//相当于除以16 156. ADCINB4_Voltage = ADCINB4_Voltage_sum >> 4; 157. ADCINA4_Voltage_sum = 0; 158. ADCINB4_Voltage_sum = 0; 159. convered_count = 0; 160. } 161. } 162.

163. interrupt void tim0_isr(void) 164. {

165. LED_toggle(LED0);

166. PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; 167. }

168. //=========================================================================== 169. // No more.

170. //=========================================================================== 程序运行结果:


F28035_ADC(2).doc 将本文的Word文档下载到电脑

下一篇:最新2018年高考时文精选作文素材10篇之2018年2月14日

相关推荐
相关阅读
本类排行
× 游客快捷下载通道(下载后可以自由复制和排版)

下载本文档需要支付 7 元

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:xxxxxx QQ:xxxxxx