Projet

Général

Profil

« Précédent | Suivant » 

Révision 799

Ajouté par magraffin il y a presque 4 ans

la fonction rectram est finie, le checksum fonctionne ainsi que le stokage de la trame

Voir les différences:

uart0.c
#include "sfr32c87.h"
#include "uart0.h"
char c;
char tram[80];
char c,c1,c2,t1,t2,check=0,t3,t4;
int i=0,debut=0,fin_tram=0,validation=0;
void main(void)
{
int i=0;
uart0_init();
pd1_0=1;
pd1_1=1;
/*
while (1)
{
......
*/
while (1)
{
c=uart0_rx();
fin_tram=rectram();
}
}
void uart0_init(void)
......
char uart0_rx(void)
{
while (ri_u0c1!=0);
while (!ri_u0c1);
return u0rb;
}
}
int decode_int(char ch)
{
char res;
if (ch>=0x30 && ch<=0x39){
res=ch-48;
}
if (ch>=0x41 && ch<=0x46){
res=ch-55;
}
return (res);
}
int rectram(char * Buffer){
fin_tram=0;
c=uart0_rx();
if (c=='\n' || c=='\r'){
return 1;
}
if (c=='*'){
/*p1_1=1;
while (i!=10000){i++;}
p1_1=0;*/
c1=uart0_rx();
c2=uart0_rx();
debut=0;
i=0;
t1=(check&0xf0)>>4;//decode_int(c1);decode_int(c1);
t2=check&0x0f;//decode_int(c2);decode_int(c2);
t3=decode_int(c1);
t4=decode_int(c2);
if (t1==t3 && t2==t4 ){
validation=1;}
}
if (debut==1){
i++;
tram[i]=c;
*(Buffer+i)=c;
check=check^c;
}
if (c=='$'){
/*p1_0=1;
while (i!=10000){i++;}
p1_0=0;*/
debut=1;
fin_tram=0;
tram[0]=c;
}
}

Formats disponibles : Unified diff