我做了一个基于MSP430F5529的AD电压采集的东西,输入口是P6.6,无意间直接把稳压电源接到了接口上,现在采样显示的值非常小,实际3.5V,显示只有0.01V,求助高手,是哪里的问题,还是我单片机坏了?换了一个输入引脚还是这样,AD模块好像还可以用,具体是哪里的问题呢?
- //***************************************************************************//
- // //
- // MSP-EXP430F5529 LAB CODE //
- // //
- // lab1 - CLOCK //
- // //
- //***************************************************************************//
- /*******************************************************************************
- *
- * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of Texas Instruments Incorporated nor the names of
- * its contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- ******************************************************************************/
- #include <msp430f5529.h>
- #include <stdio.h>
- #include "HAL_PMM.h"
- #include "HAL_UCS.h"
- #include "HAL_Board.h"
- #include "HAL_Buttons.h"
- #include "HAL_Cma3000.h"
- #include "HAL_Dogs102x6.h"
- #include "stdlib.h"
- #include "lab1.h"
- /* *所有的全局变量
- *电压采样值和测频是采样到得个数
- */
- uint16_t timeoutCounter;
- uint32_t results[10];
- uint32_t sum=0,com,acom,flag=0;
- uint32_t cap,newdata,olddata,data;
- uint32_t num;
- /*设置时钟源*/
- void int_clk()
- {
- P2DIR |= BIT2; // SMCLK set out to pins
- P2SEL |= BIT2;
- P7DIR |= BIT7; // MCLK set out to pins
- P7SEL |= BIT7;
- P5SEL |= BIT2+BIT3; // Port select XT2
- P5SEL |= BIT2+BIT3; // Port select XT2
- UCSCTL6 &= ~XT2OFF; // Enable XT2
- UCSCTL3 |= SELREF_2; // FLLref = REFO
- // Since LFXT1 is not used,
- // sourcing FLL with LFXT1 can cause
- // XT1OFFG flag to set
- UCSCTL4 |= SELA_2+SELS_5 + SELM_5;
- // Loop until XT1,XT2 & DCO stabilizes - in this case loop until XT2 settles
- do
- {
- UCSCTL7 &= ~(XT2OFFG + XT1LFOFFG + DCOFFG);
- // Clear XT2,XT1,DCO fault flags
- SFRIFG1 &= ~OFIFG; // Clear fault flags
- }while (SFRIFG1&OFIFG); // Test oscillator fault flag
- UCSCTL6 &= ~XT2DRIVE0; // Decrease XT2 Drive according to
- }
- /*
- *液晶初始化
- *开发板初始化
- */
- void chushi(void)
- {
- uint8_t contrast = *((unsigned char *)contrastSetpointAddress); //读取FLASH中对比度值
- uint8_t brightness = *((unsigned char *)brightnessSetpointAddress); //读取FLASH中背光值
- // Initialize accelerometer offset from flash
- /*Cma3000_setAccel_offset(*((unsigned char *)accelXcalibrationAddress), //初始化加速度偏移量
- *((unsigned char *)accelYcalibrationAddress),
- *((unsigned char *)accelZcalibrationAddress));*/
- // Stop WDT
- WDTCTL = WDTPW + WDTHOLD; //关闭看门狗
- // Basic GPIO initialization
- Board_init(); //初始化GPIO
- // Set Vcore to accomodate for max. allowed system speed
- SetVCore(3); //设VCore为最大
- __enable_interrupt(); //使能全局中断
- // Set up LCD
- Dogs102x6_init(); //初始化LCD
- Dogs102x6_backlightInit(); //背光初始化
- // Contrast not programed in Flash Yet
- if (contrast == 0xFF) //若当前FLASH中无对比度值,则将对比度值设为11(默认)
- // Set Default Contrast
- contrast = 11;
- // Brightness not programed in Flash Yet
- if (brightness == 0xFF) //若当前FLASH中无背光值,则将背光值设为11(默认)
- // Set Default Brightness
- brightness = 11;
- Dogs102x6_setBacklight(brightness); //设置初始背光值
- Dogs102x6_setContrast(contrast); //设置初始对比度值
- Dogs102x6_clearScreen(); //清屏
- // Set up wheel
- Buttons_init(BUTTON_ALL); //初始化按键
- Buttons_interruptEnable(BUTTON_ALL); //使能所有按键中断
- buttonsPressed = 0; //键值清零
- Dogs102x6_stringDraw(1, 0, "**== Message ==** ", DOGS102x6_DRAW_NORMAL);
- Dogs102x6_stringDraw(3, 0, " Welcome to ", DOGS102x6_DRAW_NORMAL);
- Dogs102x6_stringDraw(5, 0, " SH University", DOGS102x6_DRAW_NORMAL);
- Dogs102x6_stringDraw(7, 0, " MSP-EXP430F5529 ", DOGS102x6_DRAW_NORMAL);
- while (!buttonsPressed) //等待按键被按下,或者超时退出等待
- {
- for (timeoutCounter = 0; timeoutCounter < 0x0FFF; timeoutCounter++)
- {
- if (buttonsPressed)
- break;
- __delay_cycles(2000);
- }
- break;
- }
- Dogs102x6_clearScreen();
- Dogs102x6_stringDraw(1, 0, " Battery power", DOGS102x6_DRAW_NORMAL);
- Dogs102x6_stringDraw(3, 0, " measurement", DOGS102x6_DRAW_NORMAL);
- Dogs102x6_stringDraw(6, 0, "*S1=Enter S2=Esc*", DOGS102x6_DRAW_NORMAL);
- // Board_ledOn(LED_ALL);
- // Wait for button press
- while (!buttonsPressed) //等待按键被按下,或者超时退出等待
- {
- for (timeoutCounter = 0; timeoutCounter < 0x0FFF; timeoutCounter++)
- {
- if (buttonsPressed)
- break;
- __delay_cycles(2000);
- }
- break;
- }
- Board_ledOff(LED_ALL);
- }
- /*ADC12的初始化*/
- void adc1()
- {
- P6SEL |= BIT6;
- ADC12CTL0 = ADC12ON+ADC12SHT0_8+ADC12MSC;
- ADC12CTL1 = ADC12SHP+ADC12CONSEQ_2;
- ADC12MCTL0=ADC12SREF_0+ADC12INCH_6;
- ADC12CTL0 |= ADC12ENC;
- }
- /*直流电压采样数据转换显示*/
- void display1()
- {
- if(flag==1)
- {
- char string1[20];
- string1[0]=com/1000+48;
- string1[1]=46;
- string1[2]=com/100%10+48;
- string1[3]=com/10%10+48;
- string1[4]=com%10+48;
- string1[5]=' ';
- char string2[20];
- string2[0]=com/1000+48;
- string2[1]=46;
- string2[2]=com/100%10+48;
- string2[3]=com/10%10+48;
- string2[4]=com%10+48;
- string2[5]=' ';
- Dogs102x6_stringDraw(1, 0, "*==DC voltage==*", DOGS102x6_DRAW_NORMAL);
- Dogs102x6_stringDraw(3, 0, "value1=", DOGS102x6_DRAW_NORMAL);
- Dogs102x6_stringDraw(3, 40, string1, DOGS102x6_DRAW_NORMAL);
- Dogs102x6_stringDraw(3, 70, "(V)", DOGS102x6_DRAW_NORMAL);
- Dogs102x6_stringDraw(5, 0, "value2=", DOGS102x6_DRAW_NORMAL);
- Dogs102x6_stringDraw(5, 40, string2, DOGS102x6_DRAW_NORMAL);
- Dogs102x6_stringDraw(5, 70, "(V)", DOGS102x6_DRAW_NORMAL);
- Dogs102x6_stringDraw(7, 0, " *== good job==*", DOGS102x6_DRAW_NORMAL);
- for (timeoutCounter = 0; timeoutCounter < 0x02FF; timeoutCounter++)
- {
- __delay_cycles(1000);
- }
- flag=0;
- }
- }
- /*交流电压采样数据转化显示
- *频率采样显示
- */
- /*void display2()
- {
- char str1[20],str3[20];
- cap=40000000/num;
- str1[0]=acom/1000+48;
- str1[1]=46;
- str1[2]=acom/100%10+48;
- str1[3]=acom/10%10+48;
- str1[4]=acom%10+48;
- str1[5]=' ';
- str3[0]=cap/10000000+'0';
- str3[1]=cap/1000000%10+'0';
- str3[2]=cap/100000%10+'0';
- str3[3]=cap/10000%10+'0';
- str3[4]=cap/1000%10+'0';
- str3[5]=cap/100%10+'0';
- str3[6]=cap/10%10+'0';
- str3[7]=46;
- str3[8]=cap%10+'0';
- str3[9]=' ';
- Dogs102x6_stringDraw(1, 0, "*==AC voltage==*", DOGS102x6_DRAW_NORMAL);
- Dogs102x6_stringDraw(3, 0, "value=", DOGS102x6_DRAW_NORMAL);
- Dogs102x6_stringDraw(3, 40, str1, DOGS102x6_DRAW_NORMAL);
- Dogs102x6_stringDraw(3, 75, "(V)", DOGS102x6_DRAW_NORMAL);
- Dogs102x6_stringDraw(5, 1, "F =", DOGS102x6_DRAW_NORMAL);
- Dogs102x6_stringDraw(5, 30, str3, DOGS102x6_DRAW_NORMAL);
- Dogs102x6_stringDraw(5, 90, "HZ", DOGS102x6_DRAW_NORMAL);
- Dogs102x6_stringDraw(7, 0, " *== good job==*", DOGS102x6_DRAW_NORMAL);
- }*/
- /*主函数设置*/
- void main()
- {
- int_clk();
- chushi();
- adc1();
- Dogs102x6_clearScreen();
- Board_ledOff(LED_ALL);
- ADC12CTL0 |= ADC12SC;
- _EINT();
- cap=0;
- acom=0;
- com=0;
- P1DIR |= BIT3;
- P2SEL |= BIT0; //TA1.1
- while (1)
- {
- buttonsPressed = 0;
- Dogs102x6_clearScreen();
- /* while (!(buttonsPressed & BUTTON_S1))
- {
- //ADC12IE = 0x01;
- Board_ledOn(LED4);
- TA1CCTL1=CM_1+SCS+CCIS_0+CAP+CCIE;
- TA1CTL=TASSEL_2+MC_2+TACLR+TAIE;
- display2();
- }
- buttonsPressed = 0;
- Dogs102x6_clearScreen();
- __delay_cycles(2000);
- Board_ledOff(LED_ALL);*/
- while (!(buttonsPressed & BUTTON_S2))
- {
- ADC12IE = 0x01;
- Board_ledOn(LED6);
- display1();
- }
- Dogs102x6_clearScreen();
- __delay_cycles(2000);
- Board_ledOff(LED_ALL);
- ADC12IE = 0x00;
- ADC12CTL0 &= ~ADC12SC;
- }
- }
- /*ADC12中断函数*/
- #pragma vector=ADC12_VECTOR
- __interrupt void ADC12ISR (void)
- {
- static unsigned int m,count = 0;
- float factor=0.80566;
- results[count]=ADC12MEM0;
- count++;
- for(m=0;m<10;m++)
- {
- sum+=results[m];
- }
- sum/=10;
- sum=sum*factor;
- com=sum;
- if (count == 10)
- {
- count = 0;
- flag=1;
- ADC12IE = 0x00;
- }
- }
- /*TA1的中断函数*/
- #pragma vector=TIMER1_A1_VECTOR
- __interrupt void TIMER1_A1_ISR(void)
- {
- switch(__even_in_range(TA1IV,14))
- {
- case 0: break; // No interrupt
- case 2:
- if(TA1CCTL1&CM0)
- {
- newdata=TA1R;
- if(newdata<olddata)
- {
- data=65536+newdata-olddata;
- }
- else
- {
- data=newdata-olddata;
- }
- olddata=newdata;
- num=data;
- }
- P1OUT ^= BIT3;
- break; // CCR1 not used
- case 4: break; // CCR2 not used
- case 6: break; // reserved
- case 8: break; // reserved
- case 10: break; // reserved
- case 12: break; // reserved
- case 14: break; // overflow
- default: break;
- }
- }
复制代码
此帖出自
小平头技术问答
我也是我也,应该是头文件没写的关系,拜托楼主给一下头文件可以吗?万分感谢拜托拜托
一周热门 更多>