刚学单片机,第一次弄,想根据书里的例程做个简单的温度报警器。在链接的时候出了问题,主程序如下:
#include <stdint.h>
#include "msp430f5529.h"
#include "HAL_Board.h"
#include "HAL_Buttons.h"
#include "HAL_Dogs102x6.h"
#include "HAL_Menu.h"
#include "HAL_Wheel.h"
#include "show.h"
uint16_t timeoutCounter;
void main(void)
{
uint8_t contrast = *((unsigned char *)contrastSetpointAddress); //读取FLASH中对比度值
uint8_t brightness = *((unsigned char *)brightnessSetpointAddress); //读取FLASH中背光值
// Stop WDT
WDTCTL = WDTPW + WDTHOLD; //关闭看门狗
// Basic GPIO initialization
Board_init(); //初始化GPIO
// 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; //键值清零
Dogs102x6_clearScreen();
buttonsPressed = 0;
//显示文字说明:
Dogs102x6_stringDraw(1, 0, " Welcome to ", DOGS102x6_DRAW_NORMAL);
Dogs102x6_stringDraw(3, 0, " Temperature ", DOGS102x6_DRAW_NORMAL);
Dogs102x6_stringDraw(4, 0, " Alarm ", 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)
{
show() ;
}
}
子程序:
#include <stdint.h>
#include "msp430f5529.h"
#include "HAL_Board.h"
#include "HAL_Buttons.h"
#include "HAL_Dogs102x6.h"
#include "HAL_Menu.h"
#include "HAL_Wheel.h"
#include "stdlib.h"
#include "show.h"
/*long temp;
int TEMP = 0;
volatile unsigned int a;
volatile unsigned int b;
volatile unsigned int c;
volatile unsigned int *f;
unsigned char mun_char_table[]={"0123456789abcdef"};*/
static const char *const capMenuText[] = {
"temperature alarm",
"1. SetValue ",
"2. monitor ",
"3. restart",
};
char *itoa(int, char *, int);
// Forward Declared Function
void SetValue(void);
void restart(void);
void monitor(void);
/***************************************************************************//**
* @brief The menu of lab2.
* @param none
* @return none
******************************************************************************/
void show(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, 3);
if (buttonsPressed & BUTTON_S2);
else
switch (selection)
{
case 1: SetValue(); break; //设置温度报警上限模块
case 2: monitor(); break; //温度监测模块
case 3: restart(); break; //重启模块
default: break;
}
}
void monitor(void)
{
/*WDTCTL = WDTPW + WDTHOLD; // Stop WDT
Dogs102x6_init();
Dogs102x6_backlightInit();
Dogs102x6_setBacklight(50);
Dogs102x6_setContrast(10);
Dogs102x6_clearScreen();
REFCTL0 &= ~REFMSTR; // Reset REFMSTR to hand over control to
// ADC12_A ref control registers
ADC12CTL0 = ADC12SHT0_8 + ADC12REFON + ADC12ON;
// Internal ref = 1.5V
ADC12CTL1 = ADC12SHP; // enable sample timer
ADC12MCTL0 = ADC12SREF_1 + ADC12INCH_10; // ADC i/p ch A10 = temp sense i/p
ADC12IE = 0x001; // ADC_IFG upon conv result-ADCMEMO
__delay_cycles(75); // 75us delay to allow Ref to settle
ADC12CTL0 |= ADC12ENC;
while(1)
{
ADC12CTL0 |= ADC12SC; // Sampling and conversion start
__bis_SR_register(LPM4_bits + GIE); // LPM0 with interrupts enabled
__no_operation();
TEMP=((temp - 1855) * 667) / 4096;
a=TEMP/10+48;
f=&a;
Dogs102x6_charDraw(1,30,*f,0);//显示十位
b=(int)(TEMP)%10+48;
f=&b;
Dogs102x6_charDraw(1,36,*f,0);//显示个位
__no_operation(); // SET BREAKPOINT HERE
}
}
#pragma vector=ADC12_VECTOR
__interrupt void ADC12ISR (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
temp = ADC12MEM0; // Move results, IFG is cleared
__bic_SR_register_on_exit(LPM4_bits); // Exit active CPU
break;
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;
}
}*/
}
void SetValue(void)
{
char i,l;
Dogs102x6_clearScreen();
buttonsPressed = 0;
Dogs102x6_stringDraw(2, 0, "set value:", DOGS102x6_DRAW_NORMAL);
while(1)
{
i=(int)Wheel_getPosition();
// Dogs102x6_charDraw(7,20,*M+48,0);
Dogs102x6_charDraw(4,40,i+48,0);
if(buttonsPressed & BUTTON_S1)
break;
}
while(1)
{
l=(int)Wheel_getPosition();
// Dogs102x6_charDraw(7,20,*M+48,0);
Dogs102x6_charDraw(4,60,l+48,0);
if(buttonsPressed & BUTTON_S1)
break;
}
}
void restart(void)
{
}
运行到monitor()是就会显示上述这个问题。
请前辈们指教
希望留下QQ号,有单片机上的疑难我会去请教的
此帖出自
小平头技术问答
一周热门 更多>