|
程序如下,但是进不了中断,有谁知道可以告诉我么?万万分感谢~~~
char buffer[255];
int flag = 0,cont = 0;
char data[3]= {'0','0','\0'};
uint8_t data1 = 0;
uint16_t intialWheelValue = 0;
uint16_t wheelValue = 0;
FRESULT WriteFile(char* fileName, char* text, WORD size);
void TimerB_Init(void);
void DataAcq()
{
char data[3]= {'0','0','\0'};
uint8_t data1 = 0;
uint16_t intialWheelValue = 0;
uint16_t wheelValue = 0;
TimerB_Init();
Dogs102x6_init();
Dogs102x6_clearScreen();
Buttons_interruptEnable(BUTTON_ALL); //按键中断使能
buttonsPressed = 0;
intialWheelValue = Wheel_getValue(); // 得到初始齿轮电位计采样值
__enable_interrupt(); //使能全局中断
while(!(buttonsPressed & BUTTON_S2)){
Dogs102x6_stringDraw(3, 45, &data[0], DOGS102x6_DRAW_INVERT); //显示数
wheelValue = Wheel_getValue();
data1 = wheelValue/68; //得到当前齿轮电位计采样值
if (intialWheelValue != wheelValue){ //若当前齿轮电位计采样值与初始齿轮电位计采样值不同,进行小时重置
if (data1 < 10){
data[0] = '0';
data[1] = '0' + data1;
}
else if (data1 < 20){
data[0] = '1';
data[1] = '0' + (data1 - 10);
}
else if (data1 < 30){
data[0] = '2';
data[1] = '0' + (data1 - 20);
}
else if (data1 < 40){
data[0] = '3';
data[1] = '0' + (data1 - 30);
}
else if (data1 < 50){
data[0] = '4';
data[1] = '0' + (data1 - 40);
}
else if (data1 < 60){
data[0] = '5';
data[1] = '0' + (data1 - 50);
}
else {
data[0] = '6';
data[1] = '0';
}
}
}
}
FRESULT WriteFile(char* fileName, char* text, WORD size)
{
// Result code
FRESULT rc;
// File system object
FATFS fatfs;
// File object
FIL fil;
UINT bw;
// Register volume work area (never fails)
f_mount(0, &fatfs);
// Open file
rc = f_open(&fil, fileName, FA_READ | FA_WRITE | FA_OPEN_ALWAYS);
if (rc)
{
die(rc);
}
//指针指到文本最后
rc = f_lseek(&fil, f_size(&fil));
if(rc)
{
die(rc);
}
// Write to file
rc = f_write(&fil, text, size, &bw);
if (rc)
{
die(rc);
}
// Close the file
rc = f_close(&fil);
if (rc)
{
die(rc);
}
return rc;
}
/*定时器初始化*/
void TimerB_Init(void)
{
TB0CCR0 = 32768;
TB0CTL = TBSSEL_0+TBCLR+MC_1; //
TB0CCTL0 = CCIE;
}
#pragma vector = TIMERB0_VECTOR
__interrupt void Timer_B0(void)
{
cont = cont+1;
if(cont == 1)
{
cont = 0;
flag = 1;
buffer[0] = '[';
buffer[1] = data[0];
buffer[2] = data[1];
buffer[3] = ']';
WriteFile("1.txt",buffer,4); //写入数据
}
}
|
阿莫论坛20周年了!感谢大家的支持与爱护!!
该献的血还是要献的。你不献他不献。难道让我去献? --- 出自坛友:lovejp1981
|