第一范文网 - 专业文章范例文档资料分享平台

F28035_ADC(2)

来源:用户分享 时间:2019-03-29 本文由云书歌谣 分享 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

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. //=========================================================================== 程序运行结果:

搜索“diyifanwen.net”或“第一范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,第一范文网,提供最新综合文库F28035_ADC(2)全文阅读和word下载服务。

F28035_ADC(2).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/wenku/88869.html(转载请注明文章来源)
热门推荐
Copyright © 2018-2022 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top