一个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
请高手看看哪里出错了?
单片机源程序如下:
- #include"reg52.h"
- #define uchar unsigned char
- #define uint unsigned int
- bit write=0;
- sbit SDA=P2^0;
- sbit SCL=P2^1;
- uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f};
- uchar sec, tcnt;
-
- void delay()
- {;;}
- void delay1ms(uint z)
- { uint x, y;
- for(x=z;x>0;x--)
- for(y=110;y>0;y--);
- }
- void start() //开始信号
- {
- SDA=1;
- delay();
- SCL=1;
- delay();
- SDA=0;
- delay();
- }
- void stop() //停止
- {
- SDA=0;
- delay();
- SCL=1;
- delay();
- SDA=1;
- delay();
- }
- void respons() //应答
- {
- char i;
- SCL=1;
- delay();
- while((SDA==1)&&(i<250))i++;
- SCL=0;
- delay();
- }
- void init()
- {
- SDA=1;
- delay();
- SCL=1;
- delay();
- }
- void write_byte(uchar date) //写
- {
-
- uchar i,temp;
- temp=date;
- for(i=0;i<8;i++)
- {
- temp=temp<<1;
- SCL=0;
- delay();
- sda=CY;
- delay();
- SCL=1;
- delay();
- }
- SCL=0;
- delay();
- SDA=1;
- delay();
- }
- uchar read_byte() //读
- {
- uchar i,k;
- SCL=0;
- delay();
- SDA=1;
- delay();
- for(i=0;i<8;i++)
- {
- SCL=1;
- delay();
- k=(k<<1)|sda
- SCL=0; // 这里报;scl附近语法错误。
- delay();
- }
- return k;
- }
- void write_add(uchar address,uchar date)
- {
- start();
- write_byte(0xa0);
- respons();
- write_byte(address);
- respons();
- write_byte(date);
- respons();
- stop();
- }
- uchar read_add(uchar address)
- {
- uchar date;
- start();
- write_byte(0xa0);
- respons();
- write_byte(address);
- respons;
- start()
- write_byte(0xa1);
- respons;
- date=rede_byte();
- stop();
- return date;
- }
- void display(uchar bai_c, uchar sh_c)//显示
- {
- P0=table[bai_c]; //显示第一位
- P1=0xff;
- delay1ms(5);
- P0=table[sh_c];
- P1=0xfe;
- delay1ms(5);
- }
- void main()
- {
- init();
- sec=read_add(2); //读出保存的数据赋予sec
- if(sec>100) //防止首次读取出错
- sec=0;
- TMOD=0x01; //定时器工作方式1
- ET0=1; //存疑
- EA=1;
- TH0=(65536-5000)/256; //赋值
- TL0=(65536-5000)%256 ;
- TR0=1; //开始计时
- while(1)
- {
- display(sec/10,sec%10);
- if(wtite==1) //判断计时器是否计时一秒
- {
- write=0; //清0
- write_add(2,sec); //再24C16写数据
- }
- }
-
- }
-
- void t0()interrupt 1 //定时中断程序
- {
- TH0=(65536-50000)/256; //赋值
- TL0=(65536-50000)%256;
- tcnt++; //每过50ms,tcnt加1
- if(tcnt=20) //计满20时
- {
- tcnt=0; //重新再计
- sec++;
- write=1; //一秒写一次24C16
- if(sec==100) //定时100秒,再从0开始
- sec=0;
- }
- }
复制代码
|