一個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;
- }
- }
復制代碼
|