找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 630|回复: 2
打印 上一主题 下一主题
收起左侧

一个单片机秒表程序,哪里出错了?error C141: syntax error near 'SCL'

[复制链接]
跳转到指定楼层
楼主
ID:999123 发表于 2022-1-11 15:44 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
一个51单片机秒表程序,编译提示:SCL附近语法错误,      在第87行。     才接触单片机不久,小白一个,怎么也找不到,敬请高手指点指点。

AA.C(87): error C141: syntax error near 'SCL'
AA.C(114): error C141: syntax error near 'write_byte'
Target not created

请高手看看哪里出错了?
单片机源程序如下:
  1. #include"reg52.h"
  2.   #define uchar unsigned char
  3.   #define uint unsigned int
  4.   bit write=0;

  5.   sbit SDA=P2^0;
  6.   sbit SCL=P2^1;
  7.   uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f};

  8. uchar sec, tcnt;
  9.          

  10.   void delay()
  11.   {;;}
  12.   void delay1ms(uint z)
  13.   {  uint x, y;
  14.      for(x=z;x>0;x--)
  15.              for(y=110;y>0;y--);
  16.   }
  17.   void start()         //开始信号
  18.   {
  19.      SDA=1;
  20.          delay();
  21.      SCL=1;
  22.          delay();
  23.          SDA=0;
  24.          delay();
  25.    }
  26.    void stop()  //停止
  27.    {
  28.      SDA=0;
  29.          delay();
  30.          SCL=1;
  31.          delay();
  32.          SDA=1;
  33.          delay();
  34.         }
  35.   void  respons() //应答
  36.     {
  37.           char i;
  38.           SCL=1;
  39.           delay();
  40.           while((SDA==1)&&(i<250))i++;
  41.           SCL=0;
  42.           delay();
  43.         }
  44.    void  init()
  45.     {
  46.           SDA=1;
  47.           delay();
  48.           SCL=1;
  49.           delay();
  50.         }
  51.    void  write_byte(uchar date)                 //写
  52.      {
  53.                
  54.            uchar i,temp;
  55.            temp=date;
  56.            for(i=0;i<8;i++)
  57.            {
  58.              temp=temp<<1;
  59.                  SCL=0;
  60.                  delay();
  61.                  sda=CY;
  62.                  delay();
  63.                  SCL=1;
  64.                  delay();
  65.                  }

  66.                   SCL=0;
  67.                   delay();
  68.                   SDA=1;
  69.                   delay();
  70.             }
  71.            uchar read_byte()                           //读
  72.         {
  73.           uchar i,k;
  74.           SCL=0;
  75.           delay();
  76.           SDA=1;
  77.           delay();
  78.           for(i=0;i<8;i++)
  79.          {
  80.            SCL=1;
  81.            delay();
  82.                    k=(k<<1)|sda            
  83.           SCL=0;                          //     这里报;scl附近语法错误。
  84.            delay();
  85.           }
  86.           return k;

  87.           }

  88.                   void  write_add(uchar address,uchar date)                          
  89.           {
  90.             start();
  91.                 write_byte(0xa0);
  92.                 respons();
  93.                 write_byte(address);
  94.                 respons();
  95.                 write_byte(date);
  96.                 respons();
  97.                 stop();
  98.            }
  99.            uchar read_add(uchar address)
  100.           {
  101.              uchar date;
  102.                  start();
  103.                  write_byte(0xa0);
  104.                  respons();
  105.                  write_byte(address);
  106.                  respons;
  107.                  start()
  108.                  write_byte(0xa1);
  109.              respons;
  110.                  date=rede_byte();
  111.                  stop();
  112.                  return date;
  113.                 }
  114.         void display(uchar bai_c, uchar sh_c)//显示
  115.           {         
  116.              P0=table[bai_c];   //显示第一位
  117.                  P1=0xff;
  118.                  delay1ms(5);
  119.                  P0=table[sh_c];
  120.                  P1=0xfe;
  121.                  delay1ms(5);
  122.                 }      

  123.         void main()
  124.         {
  125.            init();
  126.            sec=read_add(2);          //读出保存的数据赋予sec
  127.            if(sec>100)                  //防止首次读取出错
  128.               sec=0;
  129.                 TMOD=0x01;                 //定时器工作方式1
  130.                 ET0=1;                        //存疑
  131.                 EA=1;
  132.                 TH0=(65536-5000)/256;           //赋值
  133.                 TL0=(65536-5000)%256 ;
  134.                 TR0=1;                                                  //开始计时
  135.                 while(1)
  136.            {
  137.                 display(sec/10,sec%10);
  138.                 if(wtite==1)                           //判断计时器是否计时一秒
  139.                 {
  140.                 write=0;                                                //清0
  141.                   write_add(2,sec);                   //再24C16写数据
  142.                 }
  143.                 }
  144.                
  145.                  }
  146.                
  147.                  void t0()interrupt 1        //定时中断程序
  148.                   {
  149.                     TH0=(65536-50000)/256;          //赋值
  150.                         TL0=(65536-50000)%256;
  151.                           tcnt++;                                  //每过50ms,tcnt加1
  152.                           if(tcnt=20)                                //计满20时
  153.             {
  154.                           tcnt=0;                                        //重新再计
  155.                           sec++;
  156.                           write=1;                                  //一秒写一次24C16
  157.                           if(sec==100)                                 //定时100秒,再从0开始
  158.                           sec=0;
  159.                         }
  160.                         }
复制代码


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:878061 发表于 2022-1-11 21:06 | 只看该作者
错误太多了,86行113行少分号,112行和115行少括号,其它自己再找找
回复

使用道具 举报

板凳
ID:999123 发表于 2022-1-12 13:21 | 只看该作者
谢谢指导,又找到几个语法错误后,终于运行了.
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表