Révision 842
Ajouté par lefraisse il y a presque 4 ans
SP4c12.c | ||
---|---|---|
/* NOTE:THIS IS A TYPICAL EXAMPLE. */
|
||
/***********************************************************************/
|
||
#include "sfr32c87.h"
|
||
#include <math.h>
|
||
|
||
void uart0_init(void);
|
||
void uart0_tx(char c);
|
||
char uart0_rx(void);
|
||
char uart0_rx();
|
||
void alphabet(void);
|
||
int rectrame(char* buffer);
|
||
int hex2int(char*c);
|
||
|
||
void main(void)
|
||
{
|
||
char c = 'A'; //Utilis? pour la fonction alphabet
|
||
int i=0,j;
|
||
char table[10][80];
|
||
char buffer[80];
|
||
uart0_init();
|
||
|
||
while(1){
|
||
uart0_tx('o');
|
||
//uart0_rx();
|
||
rectrame(buffer);
|
||
//alphabet(); test alphabet
|
||
|
||
/* arriv?e d'un caract?re sur le port s?rie
|
||
uart0_tx(c);
|
||
uart0_rx();
|
||
uart0_tx(c+1);
|
||
*/
|
||
|
||
/*while (i<10){
|
||
[buffer, j] = rectrame(buffer);
|
||
if (j==63){
|
||
for (i;i<j;i++){
|
||
uart0_tx(buffer[i]);
|
||
}
|
||
i++;
|
||
}
|
||
}
|
||
i=0;*/
|
||
}
|
||
}
|
||
|
||
... | ... | |
}
|
||
|
||
void uart0_tx(char c){
|
||
//Bits TE et RE ? 1 (condition pour la transmission et la r?ception)
|
||
te_u0c1=1;
|
||
crd_u0c0=1;
|
||
crs_u0c0=0;
|
||
te_u0c1=1;
|
||
crd_u0c0=1;
|
||
crs_u0c0=0;
|
||
while (ti_u0c1=0); //attente
|
||
u0tb=c;
|
||
te_u0c1=0;
|
||
}
|
||
|
||
//void uart0_rx((void){
|
||
//while (u0c1_ri=0){
|
||
// return u0rb;
|
||
//}
|
||
//}
|
||
char uart0_rx(){
|
||
while (ri_u0c1=0); //attente
|
||
return u0rb;
|
||
}
|
||
|
||
void alphabet(void){
|
||
char ch='A';
|
||
int i;
|
||
for (i=0;i<26;i++){
|
||
uart0_tx(ch);
|
||
ch+=1;
|
||
}
|
||
}
|
||
|
||
int rectrame(char *buffer){
|
||
int i=0,cheksum=0;
|
||
|
||
while (uart0_rx()!='$'); //attente d'une trame
|
||
while (uart0_rx()!='*'){
|
||
buffer[i]=uart0_rx();
|
||
i++;
|
||
}
|
||
}
|
||
|
||
int hex2int(char *c){
|
||
int i;
|
||
int d;
|
||
for (i=0;i<2;i++){
|
||
//Pour des chiffres, la valeur hexad?cimal correspond ? la valeur d?cimal
|
||
if ( (c[i]>'0') && (c[i]<'9')){
|
||
d += (c[i] - '0')*pow(2,-4*(i-1));
|
||
}
|
||
//La valeur d?cimale de A est 10 et au max on aura la lettre F en hexa
|
||
else if ((c[i]>'A')&&(c[i]<'F')){
|
||
d += (c[i]-55)*pow(2,-4*(i-1));
|
||
}
|
||
}
|
||
return d;
|
||
}
|
Formats disponibles : Unified diff
Affichage alphabet, affichage de la lettre suivante, réalisation hextoint, finir rectrame