本帖最后由 fasm 于 2015-12-20 16:05 编辑
#include <reg52.h>
#define uchar unsigned char
signed char Up_Flag,Uc_Flag;
uchar code Adr_Str1[]=":ADR01;";
uchar code Up_Str1[]=":VOL10.00;";
uchar code Up_Str2[]=":VOL13.50;";
uchar code Up_Str3[]=":VOL16.00;";
uchar code Out_Str[]=":OUT1;";
uchar code Adr_Str2[]=":ADR02;";
uchar code Uc1_Str1[]=":VOL02.00;";
uchar code Uc1_Str2[]=":VOL03.00;";
uchar code Uc1_Str3[]=":VOL04.00;";
uchar code Uc1_Str4[]=":VOL05.00;";
uchar code Uc1_Str5[]=":VOL06.00;";
uchar code Uc1_Str6[]=":VOL07.00;";
uchar code Uc1_Str7[]=":VOL08.00;";
uchar code Uc2_Str1[]=":VOL02.70;";
uchar code Uc2_Str2[]=":VOL04.05;";
uchar code Uc2_Str3[]=":VOL05.40;";
uchar code Uc2_Str4[]=":VOL06.75;";
uchar code Uc2_Str5[]=":VOL08.10;";
uchar code Uc2_Str6[]=":VOL09.45;";
uchar code Uc2_Str7[]=":VOL10.80;";
uchar code Uc3_Str1[]=":VOL03.20;";
uchar code Uc3_Str2[]=":VOL04.80;";
uchar code Uc3_Str3[]=":VOL06.40;";
uchar code Uc3_Str4[]=":VOL08.00;";
uchar code Uc3_Str5[]=":VOL09.60;";
uchar code Uc3_Str6[]=":VOL11.20;";
uchar code Uc3_Str7[]=":VOL12.80;";
sbit UpFirst=P1^4;
sbit UpPrior=P1^5;
sbit UpNext=P1^6;
sbit UpLast=P1^7;
sbit UcFirst=P3^2;
sbit UcPrior=P3^3;
sbit UcNext=P3^4;
sbit UcLast=P3^5;
extern void delay(uchar i);
void Uc_Up_Init();
void SerialPort_Init();
void System_Init();
void Uc_Send();
void Up_Send();
void Uc_Up_Init(void)
{
UpFirst=1;
UpPrior=1;
UpNext=1;
UpLast=1;
UcFirst=1;
UcPrior=1;
UcNext=1;
UcLast=1;
}
void SerialPort_Init(void)
{
TMOD=0x20;
TH1=0xfd;
TL1=0xfd;
SCON=0x40;
PCON=0;
TR1=1;
}
void System_Init(void)
{
uchar *VOL_Init[6]={Adr_Str1,Up_Str2,Out_Str,Adr_Str2,Uc2_Str1,Out_Str};
uchar i=6;
uchar **p;
p=VOL_Init;
while(i)
{
while(**p!='\0')
{
SBUF=**p;
while(!TI)
{
;
}
TI=0;
(*p)++;
}
delay(25);
p++;
i--;
}
Up_Flag=2;
Uc_Flag=1;
}
void Uc_Send(void)
{
signed char i=Uc_Flag;
uchar j=3;
uchar **p;
if(Up_Flag==1)
{
uchar *Uc_Str[7]={Uc1_Str1,Uc1_Str2,Uc1_Str3,Uc1_Str4,Uc1_Str5,Uc1_Str6,Uc1_Str7};
}
else if(Up_Flag==2)
{
uchar *Uc_Str[7]={Uc2_Str1,Uc2_Str2,Uc2_Str3,Uc2_Str4,Uc2_Str5,Uc2_Str6,Uc2_Str7};
}
else if(Up_Flag==3)
{
uchar *Uc_Str[7]={Uc3_Str1,Uc3_Str2,Uc3_Str3,Uc3_Str4,Uc3_Str5,Uc3_Str6,Uc3_Str7};
}
uchar *VOL_Uc[3]={Adr_Str2,Uc_Str[i-1],Out_Str};
p=VOL_Uc;
while(j)
{
while(**p!='\0')
{
SBUF=**p;
while(!TI)
{
;
}
TI=0;
(*p)++;
}
delay(25);
p++;
j--;
}
}
void Up_Send(void)
{
signed char i=Up_Flag;
uchar j=3;
uchar **p;
uchar *Up_Str[3]={Up_Str1,Up_Str2,Up_Str3};
uchar *VOL_Up[3]={Adr_Str1,Up_Str[i-1],Out_Str};
p=VOL_Up;
while(j)
{
while(**p!='\0')
{
SBUF=**p;
while(!TI)
{
;
}
TI=0;
(*p)++;
}
delay(25);
p++;
j--;
}
Uc_Send();
}
void main(void)
{
Uc_Up_Init();
SerialPort_Init();
System_Init();
while(1)
{
if(UcNext==0)
{
delay(10);
if(UcNext==0)
{
Uc_Flag++;
if(Uc_Flag>=7)
Uc_Flag=7;
Uc_Send();
}
}
else if(UcPrior==0)
{
delay(10);
if(UcPrior==0)
{
Uc_Flag--;
if(Uc_Flag<=1)
Uc_Flag=1;
Uc_Send();
}
}
else if(UcLast==0)
{
delay(10);
if(UcLast==0)
{
Uc_Flag=7;
Uc_Send();
}
}
else if(UcFirst==0)
{
delay(10);
if(UcFirst==0)
{
Uc_Flag=1;
Uc_Send();
}
}
else if(UpNext==0)
{
delay(10);
if(UpNext==0)
{
Up_Flag++;
if(Uc_Flag>=3)
Up_Flag=3;
Up_Send();
}
}
else if(UpPrior==0)
{
delay(10);
if(UpPrior==0)
{
Up_Flag--;
if(Up_Flag<=1)
Up_Flag=1;
Up_Send();
}
}
else if(UpLast==0)
{
delay(10);
if(UpLast==0)
{
Up_Flag=3;
Up_Send();
}
}
else if(UpFirst==0)
{
delay(10);
if(UpFirst==0)
{
Up_Flag=1;
Up_Send();
}
}
}
}
keil C U3报错如下
compiling Test1.c...
TEST1.C(112): error C141: syntax error near 'unsigned'
TEST1.C(112): error C202: 'VOL_Uc': undefined identifier
TEST1.C(112): error C141: syntax error near '{'
TEST1.C(112): error C141: syntax error near '}'
Test1.c - 4 Error(s), 0 Warning(s).
找不出来错误啊!还是不可以这样做?
Test1.rar
(10.79 KB)
|