求助!!C51新手求助各位大侠!!

panda901130 2013-01-06 01:43:49
引用
#include <reg52.h>
#include <stdio.h>
#include "ds1302.h"
#include "1602.h"
#include "i2c.h"
#include "delay.h"



#define AddWr 0x90;
#define AddRd 0x91;
#define LS 0xB0;
#define KeyPort P2;
void Init_Timer0();

sbit LS_1S=P3^0;
sbit LS_2S=P3^1;
sbit LS_3O=P3^2;
sbit LS_3C=P3^3;






bit ReadTimeFlag;
bit Autoblinds;
bit SetFlag;


sbit A1=P1^2;
sbit B1=P1^3;
sbit C1=P1^4;
sbit D1=P1^5;

sbit DC1OUT = P1^6;
sbit DC2OUT = P1^7;

#define Coil_A1 {A1=1;B1=0;C1=0;D1=0;};
#define Coil_B1 {A1=0;B1=1;C1=0;D1=0;};
#define Coil_C1 {A1=0;B1=0;C1=1;D1=0;};
#define Coil_D1 {A1=0;B1=0;C1=0;D1=1;};
#define Coil_AB1 {A1=1;B1=1;C1=0;D1=0;};
#define Coil_BC1 {A1=0;B1=1;C1=1;D1=0;};
#define Coil_CD1 {A1=0;B1=0;C1=1;D1=1;};
#define Coil_DA1 {A1=1;B1=0;C1=0;D1=1;};
#define Coil_OFF {A1=0;B1=0;C1=0;D1=0;};



extern bit ack;
unsigned char ReadADC(unsigned char Chl);
unsigned char temp1[16];
unsigned char time_buf2[16];


/*------------------------------------------------
main function
------------------------------------------------*/
main()
{

unsigned char Speed1;
unsigned int i;
unsigned char KeyScan(void);
unsigned char num;
unsigned char num1;
unsigned char PWN_ON;
LS_1S=1;
LS_2S=1;
LS_3O=1;
LS_3C=1;

LCD_Init();
DelayMs(20);
LCD_Clear();
Init_Timer0();
Ds1302_Init();

Ds1302_Read_Time();
if((time_buf1[2]+time_buf1[7])==0)
Ds1302_Write_Time();

while (1) //main cycle
{
if(ReadTimeFlag==1)
{
ReadTimeFlag=0;
Ds1302_Read_Time();
sprintf(temp1,"TIME %02d:%02d:%02d",(int)time_buf1[4],(int)time_buf1[5],(int)time_buf1[6]);
LCD_Write_String(0,0,temp1);
};


if (LS_1S==0)
goto SolarCheck;
else
PWN_ON=1;
DC1OUT=1;

if (LS_2S==0)
goto rev;

if(Autoblinds==1)
{
num=255-ReadADC(0);
if (num>80)
goto BlindC;
else if (num<70)
goto BlindO;
};


num1=KeyScan();
switch(num1)
{
case 1:Autoblinds=0;goto BlindC;
case 2:Autoblinds=0;goto BlindO;
case 3:time_buf1[4]++;if(time_buf1[4]==24)time_buf1[4]=0;
Ds1302_Write_Time();break;
case 4:time_buf1[4]--;if(time_buf1[4]==255)time_buf1[4]=23;
Ds1302_Write_Time();break;
case 5:time_buf1[5]++;if(time_buf1[5]==60)time_buf1[5]=0;
Ds1302_Write_Time();break;
case 6:time_buf1[5]--;if(time_buf1[5]==255)time_buf1[5]=59;
Ds1302_Write_Time();break;
case 7:Autoblinds=1;
default:break;

;

DelayMs(100);
}

if(LS_1S==0)
DC2OUT=0;

return;
}


BlindC:
{i=64*4;
Speed1=8;


if (LS_3C==0)
return;
else

while(i)
{
Coil_A1
DelayMs(Speed1);
Coil_B1
DelayMs(Speed1);
Coil_C1
DelayMs(Speed1);
Coil_D1
DelayMs(Speed1);
return;};}

BlindO:
{i=64*4;

Speed1=8;

if (LS_3O==0)
return;
else
while(i)
{

Coil_D1
DelayMs(Speed1);
Coil_C1
DelayMs(Speed1);
Coil_B1
DelayMs(Speed1);
Coil_A1
DelayMs(Speed1);
return;};}

SolarCheck: {if(time_buf1[4]==7&&time_buf1[5]==12)
DC1OUT=1;
return;}

rev: {DC1OUT=0;
PWN_ON=4;
DC2OUT=1;
return;
}
}



void DelayUs2x(unsigned char t)
{
while(--t);
}

void DelayMs(unsigned char t)
{

while(t--)
{

DelayUs2x(245);
DelayUs2x(245);
}
}

unsigned char KeyScan(void)
{
unsigned char keyvalue;
if(KeyPort!=0xff)
{
DelayMs(10);
if(KeyPort!=0xff)
{keyvalue=KeyPort;
while(KeyPort!=0xff)
switch(keyvalue)
{
case 0xfe:return 1;break;
case 0xfd:return 2;break;
case 0xfb:return 3;break;
case 0xf7:return 4;break;
case 0xef:return 5;break;
case 0xdf:return 6;break;
case 0xbf:return 7;break;
case 0x7f:return 8;break;
default:return 0;break;
}
}
}
return 0;
}

void Init_Timer0(void)
{
TMOD |= 0x01;

EA=1;
ET0=1;
TR0=1;


}

void Timer0_isr(void) interrupt 1
{
static unsigned int num;
TH0=(65536-2000)/256;
TL0=(65536-2000)%256;

num++;
if(num==50)
{
num=0;
ReadTimeFlag=1;
}
}

void UART_SER (void) interrupt 4
{
unsigned char Temp;
unsigned char i;
if(RI)
{
RI=0;
Temp=SBUF;
time_buf2[i]=Temp&0x0F;
i++;
if(i==16)
{
i=0;
SetFlag=1;
}
SBUF=Temp;
}
if(TI)
TI=0;
}

unsigned char ReadADC (unsigned char Chl)
{
unsigned char Val;
Start_I2c();
SendByte(AddWr);
if(ack==0)return(0);
SendByte(0x40|Chl);
if(ack==0)return(0);
Start_I2c();
SendByte(AddWr+1);
if(ack==0)return(0);
Val=RcvByte();
NoAck_I2c();
Stop_I2c();
return(Val);
}



以上是小弟写的C51,可是一直出现错误 error C141

引用
New folder\main.c(212): error C141: syntax error near ';'
New folder\main.c(212): error C141: syntax error near '!='
New folder\main.c(212): error C141: syntax error near ')'
New folder\main.c(215): error C141: syntax error near ';'
New folder\main.c(215): error C141: syntax error near '!='
New folder\main.c(215): error C141: syntax error near ')'
New folder\main.c(217): error C141: syntax error near ';'
New folder\main.c(217): error C141: syntax error near '!='
New folder\main.c(217): error C141: syntax error near ')'
New folder\main.c(285): error C141: syntax error near ';'
New folder\main.c(285): error C141: syntax error near ')'
New folder\main.c(290): error C141: syntax error near ';'
New folder\main.c(290): error C141: syntax error near ')'


想来想去一直无解。。。恳求各位大侠拔刀相助。。。
...全文
792 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
panda901130 2013-01-14
  • 打赏
  • 举报
回复
谢谢各位大侠拔刀相助,小弟感激不尽,问题都解决~~
lr2131 2013-01-09
  • 打赏
  • 举报
回复
带#开始的都是预编译指令,预编译指令都不能在语句后面加分号的,而且一般顶头一行书写完,不行的话加"\"连接多行。 #define PI 3.1415 // 不能加分号 typedef可不是预编译指令,所以它后面是要加";"的 typdef unsigned char uint8;//要加分号
lr2131 2013-01-09
  • 打赏
  • 举报
回复
引用 6 楼 wangfan027 的回复:
#define AddWr 0x90; #define AddRd 0x91; #define LS 0xB0; #define KeyPort P2; 你们都没说到点子上,楼主你把分号去掉
dceacho 2013-01-07
  • 打赏
  • 举报
回复
#define AddWr 0x90; #define AddRd 0x91; #define LS 0xB0; #define KeyPort P2; 你们都没说到点子上,楼主你把分号去掉
xqkyjy 2013-01-06
  • 打赏
  • 举报
回复
不是可以定位到错误附近吗,在那里再看看,改一改,也许就可以了
palleexu 2013-01-06
  • 打赏
  • 举报
回复
或者是中英文字符的问题,你仔细看看
panda901130 2013-01-06
  • 打赏
  • 举报
回复
引用 2 楼 zhy_yzf 的回复:
或者你可以重新写一次看看能不能解决,是语法问题。
好的,我再试试看~谢谢你的帮忙哦~
zhy_yzf 2013-01-06
  • 打赏
  • 举报
回复
或者你可以重新写一次看看能不能解决,是语法问题。
zhy_yzf 2013-01-06
  • 打赏
  • 举报
回复
{keyvalue=KeyPort; while(KeyPort!=0xff) switch(keyvalue) 上面那个while少了个分号

27,509

社区成员

发帖
与我相关
我的任务
社区描述
硬件/嵌入开发 单片机/工控
社区管理员
  • 单片机/工控社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧