错误提示:error 213:syntax error before'{'(at column 24)(213)
有没大'佬'帮忙解决一下
相关代码:
#include
#include "ny8_constant.h"
#define UPDATE_REG(x) __asm__("MOVR _" #x ",F")
#define u8 unsigned char
#define uchar unsigned char
#define u16 unsigned int
#define u32 unsigned long int
#define uint8_t unsigned char
#define uint16_t unsigned int
#define uint32_t unsigned long int
// void F_KeySacnPro(void)
typedef union
{
unsigned char byte;
struct
{
u8 bit0 : 1;
u8 bit1 : 1;
u8 bit2 : 1;
u8 bit3 : 1;
u8 bit4 : 1;
u8 bit5 : 1;
u8 bit6 : 1;
u8 bit7 : 1;
} bits;
}Flag;
volatile Flag Flag1;
#define KEY_ONOFF PORTBbits.PB3;
// #define u8 unsigned char;
#define TimerSum ;
u8 R_KeyCount;
#define B_KeyFlag Flag1.bits.bit4;
#define B_LongKeyFlag Flag1.bits.bit7;
#define B_Power Flag1.bits.bit5;
unsigned char i = 0;
unsigned int t = 0;
/*void Delay_50us(unsigned int time)
{
while(time--);
}*/
void main()// PB2 & PB0 output high
{
BODCON = 0; // set PB0 open-drain output mode
BPLCON = (unsigned char)~C_PB3_PLB; // Enable PB1 Pull-Low Resistor,others disable
IOSTB = C_PB3_Input; // Set PB4 & PB1 to input mode,others set to output mode
PORTB = 0;
t = 0x01;
void F_KeySacnPro(void){
if( !KEY_ONOFF )
{
R_KeyCount++;
if( R_KeyCount >= 5 )
{
if( !B_KeyFlag )
{
B_KeyFlag = 1; //按键按下一次有效
// while(1)
{
for(i = 0; i < 10; i++)
{
//亮其中一个,且按照P2.0到P2.7的顺序点亮
if( t == 0x01 )
{
PORTB = 0x01;
}
else if( t == 0x02 )
{
PORTB = 0x02;
}
else if( t == 0x04 )
{
PORTB = 0x04;
}
else if( t == 0x08 )
{
PORTB = 0x10;
}
else if( t == 0x10 )
{
PORTB = 0x20;
}
else if( t == 0x20 )
{
PORTB = 0x10;
}
else if( t == 0x40 )
{
PORTB = 0x04;
}
else if( t == 0x80 )
{
PORTB = 0x02;
}
t <<= 1;
Delay_50us(20000); //粗略延时500ms
}
t = 0x01;
}
/* if( !B_Power )
{
B_Power = 1;
if( R_WorkMode == 0 )
{
R_WorkMode = 1;
}
}
*/
}
else if( R_KeyCount >= 100 )
{
if( !B_LongKeyFlag )
{
B_LongKeyFlag = 1; // 长按按键一次有效
if( B_Power )
{
B_Power = 0;
}
}
}
}
}
else
{
if( !B_OnceKeyFlag && B_KeyFlag && !B_LongKeyFlag )
{ // 要执行 短按松开有效 如果出现长按 就无效
R_WorkMode++;
if( R_WorkMode >= 7 )
{
R_WorkMode = 0;
B_Power = 0;
}
}
R_KeyCount = 0;
B_KeyFlag = 0;
B_LongKeyFlag = 0;
}
}
}
在你的代码中,main()函数中缺少一对大括号,导致编译器无法识别你的函数定义。你需要在 t = 0x01; 的下一行加上一个左大括号 {,将其作为 F_KeySacnPro() 函数的开始,并将函数的结尾加上一个右大括号 }。
正确的 main() 函数和 F_KeySacnPro() 函数应该是这样的:
void F_KeySacnPro(void){
if( !KEY_ONOFF )
{
R_KeyCount++;
if( R_KeyCount >= 5 )
{
if( !B_KeyFlag )
{
B_KeyFlag = 1; //按键按下一次有效
// while(1)
{
for(i = 0; i < 10; i++)
{
//亮其中一个,且按照P2.0到P2.7的顺序点亮
if( t == 0x01 )
{
PORTB = 0x01;
}
else if( t == 0x02 )
{
PORTB = 0x02;
}
else if( t == 0x04 )
{
PORTB = 0x04;
}
else if( t == 0x08 )
{
PORTB = 0x10;
}
else if( t == 0x10 )
{
PORTB = 0x20;
}
else if( t == 0x20 )
{
PORTB = 0x10;
}
else if( t == 0x40 )
{
PORTB = 0x04;
}
else if( t == 0x80 )
{
PORTB = 0x02;
}
t <<= 1;
Delay_50us(20000); //粗略延时500ms
}
t = 0x01;
}
/*if( !B_Power )
{
B_Power = 1;
if( R_WorkMode == 0 )
{
R_WorkMode = 1;
}
}*/
}
else if( R_KeyCount >= 100 )
{
if( !B_LongKeyFlag )
{
B_LongKeyFlag = 1; // 长按按键一次有效
if( B_Power )
{
B_Power = 0;
}
}
}
}
}
else
{
if( !B_OnceKeyFlag && B_KeyFlag && !B_LongKeyFlag )
{ // 要执行 短按松开有效 如果出现长按 就无效
R_WorkMode++;
if( R_WorkMode >= 7 )
{
R_WorkMode = 0;
B_Power = 0;
}
}
R_KeyCount = 0;
B_KeyFlag = 0;
B_LongKeyFlag = 0;
}
}
void main()
{
BODCON = 0; // set PB0 open-drain output mode
BPLCON = (unsigned char)~C_PB3_PLB; // Enable PB1 Pull-Low Resistor,others disable
IOSTB = C_PB3_Input; // Set PB4 & PB1 to input mode,others set to output mode
PORTB = 0;
t = 0x01;
while(1)
{
F_KeySacnPro();
}
}
有用望采纳。
60行多写了个花括号