[an error occurred while processing this directive]
|
в ISR по приему организовать что-то типа
....
if (SBUF==0x0D)flag_CR=TRUE;
.....
#include
#include
#include
#include <89c51rd2.H>
#include
#include
#include
#include#define MAX_CMD 4
#define uchar unsigned charuchar xdata temp;
unsigned char ascii_bcd(char *s){
unsigned char out;
out=((s[0]-0x30)<<4)+(s[1]-0x30);
return out;
}void bcd_ascii(unsigned char bcd,char* s1){
s1[0]=(bcd>>4)+0x30;
s1[1]=(bcd&0x0F)+0x30;
s1[2]=0x00;
}
void gettime(char xdata*arg){
uchar *T,t;
char *s;
T=malloc(5);
s=malloc(3);
if(T!=NULL){
T[0]=4;
uc_I2C2Data(I2C_PCF8583, TM_HSEC , T);
t=(uchar)T[3];
bcd_ascii(t,s);
printf("Time is:%s",s);
t=T[2];
bcd_ascii(t,s);
printf(":%s",s);
t=T[1];
bcd_ascii(t,s);
printf(":%s \r\n",s);
free(s);
free(T);
}
}void settime(char xdata*arg){
uchar xdata *ucTime1;
ucTime1=malloc(5);
if(ucTime1!=NULL){ucTime1[0]=4;
ucTime1[1]=0x00;
ucTime1[2]=ascii_bcd(arg+6);
ucTime1[3]=ascii_bcd(arg+3);
ucTime1[4]=ascii_bcd(arg);
uc_Data2I2C(I2C_PCF8583, TM_HSEC , ucTime1);
printf("Settime OK:%s\r\n",arg);
free(ucTime1);
}
else printf("Out of space! \r\n");
}
void run(char xdata*arg){
uchar xdata *ucTime1;
ucTime1=calloc(2,sizeof(uchar));
if(ucTime1!=NULL){ucTime1[0]=2;
ucTime1[1]=0x08;
uc_Data2I2C(I2C_PCF8583, CTRL , ucTime1);
free(ucTime1);
}
else printf("Out of space! \r\n");
printf("Run OK \r\n");
}
void stop(char xdata*arg){
uchar xdata *ucTime1;
ucTime1=calloc(2,sizeof(uchar));
if(ucTime1!=NULL){ucTime1[0]=2;
ucTime1[1]=0x88;
uc_Data2I2C(I2C_PCF8583, CTRL , ucTime1);
free(ucTime1);
}
else printf("Out of space! \r\n");
printf("Stop OK \r\n");
}
void storetime(char xdata* arg){
}const struct Arr_cmd{
char* str;
unsigned char len;
void (*func)(char xdata*);
} Arr_cmd[MAX_CMD]={ "Gettime", 7, gettime,
"Settime", 7, settime,
"Run", 3, run,
"Stop", 4, stop};char xdata str2[16];
uchar xdata ucResTime[10]={0x04};
void main(void) {
uchar ucError;
uchar xdata *ucTime;
unsigned char y,l,t;
char i;
serial_init();
init_mempool (0x01FF,511);
ucTime=malloc(10);
if(ucTime==NULL)printf("Error malloc!");ucError = uc_I2C_Dev(I2C_PCF8583);
// Device was found
if (ucError == OK){
//1. read time with AM/PM flag
ucError = uc_I2C2Data(I2C_PCF8583, TM_SEC , ucResTime);
//2. write text into RAM
//ucError = uc_Data2I2C(I2C_PCF8583, 0x10 , aucInfo);
}
printf("Hello \r\n");
ucTime[0]='1';
ucTime[1]='1';
ucTime[2]=':';
ucTime[3]='2';
ucTime[4]='2';
ucTime[5]=':';
ucTime[6]='3';
ucTime[7]='4';
settime(ucTime);
while(1){
if(flag_CR==TRUE){
flag_CR=FALSE;
scanf("%s",&str2);
t=0;
for(y=0;y<=(MAX_CMD-1);y++){
i = strncmp (Arr_cmd[y].str,str2,Arr_cmd[y].len);
if(i==0){
l=Arr_cmd[y].len;
Arr_cmd[y].func(&str2[l]);
t=1;
break;
};
}
if (t==0)printf ("Bad command \r\n");
}
}
}
E-mail: info@telesys.ru