刚开始用,打算把开发板例程的LAB2和ADC12例程的单次采样比较相结合,但是遇到错误,对于解决这个问题没什么想法,来求教各位
先想问几个问题
1。新建工程添加头文件时一定要通过“选择“properties”,在出现的属性对话框中选择“Build”“MSP430 Complier”“include options””这样的步骤么?
2。新手通过更改现成的可编译成功的例程学习这样有帮助么?还是应该自己练习?
3。我在网上找到的大部分代码都只是部分核心代码,但是只要想加入自带led显示就会出现问题,请问这样有什么好的解决办法么?
----------------------------------------------------------------------------------------------------------------------------------------------------------------
错误如下
Description Resource Path Location Type
#10010 errors encountered during linking; "LAB2.out" not built LAB2 C/C++ Problem
#10056 symbol "ADC12_ISR" redefined: first defined in "./lab2.obj"; LAB2 C/C++ Problem
<a href="file:/D:/Program%20Files/ti/ccsv5/tools/compiler/dmed/HTML/10099.html">#10099-D</a> program will not fit into lnk_msp430f5529.cmd /LAB2 line 180 C/C++ Problem
ADC12部分代码
//******************************************************************************
// MSP430F552x Demo - ADC12, Sample A0, Set P1.0 if A0 > 0.5*AVcc
//
// Description: A single sample is made on A0 with reference to AVcc.
// Software sets ADC12SC to start sample and conversion - ADC12SC
// automatically cleared at EOC. ADC12 internal oscillator times sample (16x)
// and conversion. In Mainloop MSP430 waits in LPM0 to save power until ADC12
// conversion complete, ADC12_ISR will force exit from LPM0 in Mainloop on
// reti. If A0 > 0.5*AVcc, P1.0 set, else reset.
//
// MSP430F552x
// -----------------
// /|\| |
// | | |
// --|RST |
// | |
// Vin -->|P6.0/CB0/A0 P1.0|--> LED
//
// Bhargavi Nisarga
// Texas Instruments Inc.
// April 2009
// Built with CCSv4 and IAR Embedded Workbench Version: 4.21
//******************************************************************************
#include <msp430f5529.h>
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
ADC12CTL0 = ADC12SHT02 + ADC12ON; // Sampling time, ADC12 on
ADC12CTL1 = ADC12SHP; // Use sampling timer
ADC12IE = 0x01; // Enable interrupt
ADC12CTL0 |= ADC12ENC;
P6SEL |= 0x01; // P6.0 ADC option select
P1DIR |= 0x01; // P1.0 output
while (1)
{
ADC12CTL0 |= ADC12SC; // Start sampling/conversion
__bis_SR_register(LPM0_bits + GIE); // LPM0, ADC12_ISR will force exit
__no_operation(); // For debugger
}
}
#pragma vector = ADC12_VECTOR
__interrupt void ADC12_ISR(void)
{
switch(__even_in_range(ADC12IV,34))
{
case 0: break; // Vector 0: No interrupt
case 2: break; // Vector 2: ADC overflow
case 4: break; // Vector 4: ADC timing overflow
case 6: // Vector 6: ADC12IFG0
if (ADC12MEM0 >= 0x7ff) // ADC12MEM = A0 > 0.5AVcc?
P1OUT |= BIT0; // P1.0 = 1
else
P1OUT &= ~BIT0; // P1.0 = 0
__bic_SR_register_on_exit(LPM0_bits); // Exit active CPU
case 8: break; // Vector 8: ADC12IFG1
case 10: break; // Vector 10: ADC12IFG2
case 12: break; // Vector 12: ADC12IFG3
case 14: break; // Vector 14: ADC12IFG4
case 16: break; // Vector 16: ADC12IFG5
case 18: break; // Vector 18: ADC12IFG6
case 20: break; // Vector 20: ADC12IFG7
case 22: break; // Vector 22: ADC12IFG8
case 24: break; // Vector 24: ADC12IFG9
case 26: break; // Vector 26: ADC12IFG10
case 28: break; // Vector 28: ADC12IFG11
case 30: break; // Vector 30: ADC12IFG12
case 32: break; // Vector 32: ADC12IFG13
case 34: break; // Vector 34: ADC12IFG14
default: break;
}
}
自改程序部分:
主程序
#include <stdint.h>
#include "msp430.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 "HAL_Menu.h"
#include "HAL_Wheel.h"
#include "LPM.h"
#include "PMM.h"
#include "lab2.h"
uint16_t timeoutCounter;
void main(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为最大
// Use 32.768kHz XTAL as reference
LFXT_Start(XT1DRIVE_0); //利用LFXT1(32.768kHZ)作为时钟参考
// Set system clock to max (25MHz)
Init_FLL_Settle(25000, 762); //利用FLL(锁频环)将系统时钟设为最大25MHZ
SFRIFG1 = 0; //清中断标志
SFRIE1 |= OFIE; //使能晶振失效中断
// Globally enable interrupts
__enable_interrupt(); //使能全局中断
// Setup real time clock
//SetupRTC(); //设置实时时钟
// 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
Wheel_init(); //初始化齿轮电位计
Buttons_init(BUTTON_ALL); //初始化按键
Buttons_interruptEnable(BUTTON_ALL); //使能所有按键中断
buttonsPressed = 0; //键值清零
// Display TI **
// Wait for button press
// buttonsPressed = 0;
//显示文字说明:
Dogs102x6_stringDraw(3, 0, " Welcome to ", DOGS102x6_DRAW_NORMAL);
Dogs102x6_stringDraw(4, 0, " MSP-EXP430F5529 ", DOGS102x6_DRAW_NORMAL);
Dogs102x6_stringDraw(6, 0, "Wait for a moment", DOGS102x6_DRAW_INVERT);
Dogs102x6_stringDraw(7, 0, "or press S1 | S2 ", DOGS102x6_DRAW_INVERT);
// Wait for button press
while (!buttonsPressed) //等待按键被按下,或者超时退出等待
{
for (timeoutCounter = 0; timeoutCounter < 0xFFFF; timeoutCounter++)
{
if (buttonsPressed)
break;
__delay_cycles(2000);
}
//Timeout break
break;
}
// 主循环
while (1)
{
lab2(); //试验二程序
}
}
lab2
#include <stdint.h>
#include "msp430.h"
#include "HAL_PMM.h"
#include "HAL_UCS.h"
#include "HAL_Board.h"
#include "HAL_Buttons.h"
#include "HAL_Dogs102x6.h"
#include "HAL_Menu.h"
#include "HAL_Wheel.h"
#include "Clock.h"
#include "LPM.h"
#include "Random.h"
#include "PMM.h"
#include "Demo_Cube.h"
#include "CTS_Layer.h"
#include "stdlib.h"
#include "lab2.h"
static const char *const capMenuText[] = {
"==LAB2:Cap App===",
"1. CapLED ",
"2. CapDemo ",
"3. Simon",
};
char *itoa(int, char *, int);
// Forward Declared Function
void CapLED(void);
void CapDemo(void);
void simon(void);
void lab2(void)
{
uint8_t selection = 0;
buttonsPressed = 0;
Dogs102x6_clearScreen();
Dogs102x6_stringDraw(7, 0, "*S1=Enter S2=Esc*", DOGS102x6_DRAW_NORMAL);
selection = Menu_active((char **)capMenuText, 1);
if (buttonsPressed & BUTTON_S2);
else
switch (selection)
{
case 1: CapLED(); break; //触摸滑块演示实验程序
//触摸按键柱形图演示实验程序
//Simon游戏实验程序
default: break;
}
}
void CapLED(void)
{
Board_ledOff(LED_ALL); //关闭所有LED
Dogs102x6_clearScreen();
buttonsPressed = 0;
Dogs102x6_stringDraw(1, 0, " Slide Finger on ", DOGS102x6_DRAW_NORMAL);
Dogs102x6_stringDraw(2, 0, " Touch Pads ", DOGS102x6_DRAW_NORMAL);
while (!(buttonsPressed & BUTTON_S2)) //S2按键按下退出程序
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
ADC12CTL0 = ADC12SHT02 + ADC12ON; // Sampling time, ADC12 on
ADC12CTL1 = ADC12SHP; // Use sampling timer
ADC12IE = 0x01; // Enable interrupt
ADC12CTL0 |= ADC12ENC;
P6SEL |= 0x01; // P6.0 ADC option select
P1DIR |= 0x01; // P1.0 output
while (1)
{
ADC12CTL0 |= ADC12SC; // Start sampling/conversion
__bis_SR_register(LPM0_bits + GIE); // LPM0, ADC12_ISR will force exit
__no_operation(); // For debugger
}
}
Board_ledOff(LED_ALL);
Dogs102x6_clearScreen();
buttonsPressed = 0;
}
#pragma vector = ADC12_VECTOR
__interrupt void ADC12_ISR(void)
{
switch(__even_in_range(ADC12IV,34))
{
case 0: break; // Vector 0: No interrupt
case 2: break; // Vector 2: ADC overflow
case 4: break; // Vector 4: ADC timing overflow
case 6: // Vector 6: ADC12IFG0
if (ADC12MEM0 >= 0x7ff) // ADC12MEM = A0 > 0.5AVcc?
P1OUT |= BIT0; // P1.0 = 1
else
P1OUT &= ~BIT0; // P1.0 = 0
__bic_SR_register_on_exit(LPM0_bits); // Exit active CPU
case 8: break; // Vector 8: ADC12IFG1
case 10: break; // Vector 10: ADC12IFG2
case 12: break; // Vector 12: ADC12IFG3
case 14: break; // Vector 14: ADC12IFG4
case 16: break; // Vector 16: ADC12IFG5
case 18: break; // Vector 18: ADC12IFG6
case 20: break; // Vector 20: ADC12IFG7
case 22: break; // Vector 22: ADC12IFG8
case 24: break; // Vector 24: ADC12IFG9
case 26: break; // Vector 26: ADC12IFG10
case 28: break; // Vector 28: ADC12IFG11
case 30: break; // Vector 30: ADC12IFG12
case 32: break; // Vector 32: ADC12IFG13
case 34: break; // Vector 34: ADC12IFG14
default: break;
}
}
谢谢各位了先
|