caishifu 发表于 2023-12-28 15:38:27

编译一个STC8串口例程,出现好多错误

//========================================================================
// 函数: void timer0_ISR (void) interrupt TIMER0_VECTOR
// 描述:timer0中断函数.
// 参数: none.
// 返回: none.
// 版本: V1.0, 2016-5-12
//========================================================================
void timer0_ISR (void) interrupt TIMER0_VECTOR
{
    if(RX1_TimeOut != 0)
    {
      if(--RX1_TimeOut==0)    //超时
      {
            if(RX1_cnt != 0)    //接收有数据
            {
                B_RX1_OK = 1;    //标志已收到数据块
            }
      }
    }
}


compiling MODBUS.c...
MODBUS.C(304): error C141: syntax error near 'TIMER0_VECTOR', expected 'const'
MODBUS.C(305): error C132: 'TIMER0_VECTOR': not in formal parameter list
MODBUS.C(305): error C141: syntax error near '{'
MODBUS.C(308): error C132: 'RX1_TimeOut': not in formal parameter list
MODBUS.C(312): error C244: 'B_RX1_OK': can't initialize, bad type or class
MODBUS.C(312): error C132: 'B_RX1_OK': not in formal parameter list
MODBUS.C(313): error C141: syntax error near '}'
MODBUS.c - 7 Error(s), 0 Warning(s).





乘风飞扬 发表于 2023-12-28 18:40:37

提示TIMER0_VECTOR 没定义,如果跟头文件名称不同的话,用头文件里面定义的名称。
或者直接改成中断向量号,定时器0中断向量号为“1”。

caishifu 发表于 2023-12-28 18:51:19

改成这样了
void timer0_ISR (void)interrupt 1
{
    if(RX1_TimeOut != 0)
    {
      if(--RX1_TimeOut==0)    //超时
      {
            if(RX1_cnt != 0)    //接收有数据
            {
                B_RX1_OK = 1;    //标志已收到数据块
            }
      }
    }
}

caishifu 发表于 2023-12-28 18:53:55

//========================================================================
void    UART1_config(u32 brt, u8 timer, u8 io)    // brt: 通信波特率,timer=2: 波特率使用定时器2, 其它值: 使用Timer1做波特率. io=0: 串口1切换到P3.0 P3.1,=1: 切换到P3.6 P3.7, =2: 切换到P1.6 P1.7,=3: 切换到P4.3 P4.4.
{
    brt = 65536UL - (MAIN_Fosc / 4) / brt;
    if(timer == 2)    //波特率使用定时器2
    {
      AUXR |= 0x01;      //S1 BRT Use Timer2;
      SetTimer2Baudraye((u16)brt);
    }

    else      //波特率使用定时器1
    {
      TR1 = 0;
      AUXR &= ~0x01;      //S1 BRT Use Timer1;
      AUXR |=(1<<6);    //Timer1 set as 1T mode
      TMOD &= ~(1<<6);    //Timer1 set As Timer
      TMOD &= ~0x30;      //Timer1_16bitAutoReload;
      TH1 = (u8)(brt >> 8);
      TL1 = (u8)brt;
      ET1 = 0;            // 禁止Timer1中断
      INTCLKO&= ~0x02;    // Timer1不输出高速时钟
      TR1= 1;            // 运行Timer1
    }

         if(io == 1)    {S1_USE_P36P37();    P3n_standard(0xc0);}    //切换到 P3.6 P3.7
    else if(io == 2)    {S1_USE_P16P17();    P1n_standard(0xc0);}    //切换到 P1.6 P1.7
    else if(io == 3)    {S1_USE_P43P44();    P4n_standard(0x18);}    //切换到 P4.3 P4.4
    else                {S1_USE_P30P31();    P3n_standard(0x03);}    //切换到 P3.0 P3.1

    SCON = (SCON & 0x3f) | (1<<6);    // 8位数据, 1位起始位, 1位停止位, 无校验
//    PS= 1;    //高优先级中断
    ES= 1;    //允许中断
    REN = 1;    //允许接收
}


现在出现这些错误了
MODBUS.C(374): warning C206: 'S1_USE_P36P37': missing function-prototype
MODBUS.C(374): warning C206: 'P3n_standard': missing function-prototype
MODBUS.C(374): error C267: 'P3n_standard': requires ANSI-style prototype


angmall 发表于 2023-12-28 23:02:04

按提示加上这些定义后正常了,哎,头文件不统一造成
#define                TIMER0_VECTOR      1
#define                S1_USE_P36P37()                                        P_SW1=(P_SW1 & ~0xc0) | 0x40      //UART1 使用P3.6 P3.7口
#define                S1_USE_P16P17()                                        P_SW1=(P_SW1 & ~0xc0) | 0x80      //UART1 使用P1.6 P1.7口
#define                S1_USE_P43P44()                                        P_SW1=(P_SW1 & ~0xc0) | 0xc0      //UART1 使用P4.3 P4.4口
#define         P1n_standard(bitn)                        P1M1 &= ~(bitn),      P1M0 &= ~(bitn)
#define   P3n_standard(bitn)                        P3M1 &= ~(bitn),      P3M0 &= ~(bitn)
#define         P4n_standard(bitn)                        P4M1 &= ~(bitn),      P4M0 &= ~(bitn)
#define                S1_USE_P30P31()                                        P_SW1 &= ~0xc0

caishifu 发表于 2023-12-29 05:45:38

谢谢金牌会员两个BBS回复我

21cnsound 发表于 2024-1-25 17:28:03

基本功不扎实,还需要努力

peterwangjp 发表于 2024-1-28 21:03:11

一般我遇到提示问题 先去查百度,基本都会有答案
除了语法错误 是要好好检查的
页: [1]
查看完整版本: 编译一个STC8串口例程,出现好多错误