Projet

Général

Profil

« Précédent | Suivant » 

Révision 920

Ajouté par anclaud il y a environ 4 ans

Fonctions irectrame avec et sans interruptions : pas fonctionnel (a tester)

Voir les différences:

branch/CLAUD/sp4c12/SP41c/SP41c/uart0.h
void uart0_tx(char c);
char uart0_rx(void);
void alphabet(void);
int rectrame (char * Buffer);
int rectrame (char * buffer);
int hex_int(char *c);
void irectrame_1 (char * buffer);
void uart0_inter_init(void);
void irectrame_2 (char * buffer);
branch/CLAUD/sp4c12/SP41c/SP41c/uart0.c
#include "sfr32c87.h"
#include "uart0.h"
#pragma INTERRUPT 18 irectrame_2; // D?finition interruption 18
void uart0_init()
{
/*
......
iopol_u0mr = 0
*/
u0mr = 0x05;
/*
clk0_u0c0 = 1
clk1_u0c0 = 0
......
uform_u0c0 = 0
*/
u0c0 = 0x11;
/*
te_u0c1 = 1
ti_u0c1 = 0
......
uiere_u0c1 = 0
*/
u0c1 = 0x05;
u0brg = 0x20; // m = 32
// Config port 6 pd6 = 0x08
pd6_1 = 0;
pd6_2 = 0;
ps0_2 = 0;
ps0_3 = 1;
ps0_3 = 1;
}
void uart0_inter_init(void) //Configurer uart0 et interruption
{
u0mr = 0x05;
u0c0 = 0x11;
u0smr = 0x00;
u0smr2 = 0x00;
u0smr3 = 0x00;
u0smr4 = 0x00;
u0brg = 32;
u0c1 = 0x10;
pd6_0 = 0;
pd6_1 = 0;
pd6_2 = 0;
pd6_3 = 1;
psl0 &= ~(1<<3);
ps0_3 = 1;
s0tic = 0x01;
s0ric = 0x01;
//asm("FSET I");
te_u0c1 = 1;
re_u0c1 = 1;
}
void uart0_tx(char c)
{
while(!ti_u0c1);
......
}
char uart0_rx()
{
{
while(!ri_u0c1);
return u0rb;
}
......
{
uart0_tx(i);
}
}
int rectrame (char * buffer)
......
char char_recu;
char checksum = 0;
char checksum_fin_trame[2]; // Les 2 derniers caract?res de la trame
while(uart0_rx() != '$');
buffer[0] = '$';
while((char_recu = uart0_rx()) != '*')
{
buffer[i]= char_recu;
......
checksum = checksum ^ char_recu; // OU exclusif
}
buffer[i] = '*';
checksum_fin_trame[0] = uart0_rx();
checksum_fin_trame[1] = uart0_rx();
if (checksum == hex2int(checksum_fin_trame)){
if (checksum == hex2int(checksum_fin_trame))
{
trame_ok = 1;
}
else
......
{
c[i] = c[i]-48;
}
/* si le caractere est superieur a 10, soit A en hex -> retranche le nombre 55 */
if(c[i]>='A')
{
......
return( c[1]+16*c[0] );
}
void irectrame_1 (char * buffer)
{
int i;
char char_recu;
char checksum;
char checksum_fin_trame[2];
char checksum_trame_conv;
int nb_caract;
int etat;
int trame_ok;
while(1)
{
while(!ri_u0c1);
char_recu = u0rb;
/* Etat :
- 0 : Synchronisation
- 1 : Reception
- 2 : Checksum
- 3 : Validation
*/
switch(etat)
{
case 0 : // Synchronisation
if (char_recu == '$'){
i = 0;
checksum = 0;
etat = 1;
}
break;
case 1 : // Reception
if (char_recu != '*'){
buffer[i++] = char_recu;
checksum = checksum ^ char_recu;
}
else
{
nb_caract = 0;
checksum_trame_conv = 0;
etat = 2;
}
break;
case 2 : // Checksum
checksum_fin_trame[nb_caract] = char_recu;
nb_caract += 1;
if (nb_caract == 2){
checksum_trame_conv = hex2int(checksum_fin_trame);
etat = 3;
}
break;
case 3 : // Validation
if (checksum_trame_conv == checksum){
trame_ok = 1;
etat = 0;
}
else{
trame_ok = 0;
etat = 0;
}
break;
}
}
}
void irectrame_2 (char * buffer)
{
int i;
char char_recu;
char checksum;
char checksum_fin_trame[2];
char checksum_trame_conv;
int nb_caract;
int etat;
int trame_ok;
while(1)
{
while(!ri_u0c1);
char_recu = u0rb;
/* Etat :
- 0 : Synchronisation
- 1 : Reception
- 2 : Checksum
- 3 : Validation
*/
switch(etat)
{
case 0 : // Synchronisation
if (char_recu == '$'){
i = 0;
checksum = 0;
etat = 1;
}
break;
case 1 : // Reception
if (char_recu != '*'){
buffer[i++] = char_recu;
checksum = checksum ^ char_recu;
}
else
{
nb_caract = 0;
checksum_trame_conv = 0;
etat = 2;
}
break;
case 2 : // Checksum
checksum_fin_trame[nb_caract] = char_recu;
nb_caract += 1;
if (nb_caract == 2){
checksum_trame_conv = hex2int(checksum_fin_trame);
etat = 3;
}
break;
case 3 : // Validation
if (checksum_trame_conv == checksum){
trame_ok = 1;
etat = 0;
}
else{
trame_ok = 0;
etat = 0;
}
break;
}
}
}
void main(void)
{
char c;
int i, nb_caractere;
uart0_init();
//c = '3';
//c = uart0_rx();
//uart0_tx(c);
while(1)
{
char trame[128];
nb_caractere = rectrame(trame);
irectrame_1(trame);
for (i=0 ; i <= nb_caractere ; i++)
{
uart0_tx(trame[i]);
}
//alphabet();
}
// test hex2int (valid? sous codeblocks)
/*
char carac[2];
char caractere[2];
printf("saisir caractere :");
scanf("%c", &carac[0]);
scanf("%c", &carac[1]);
printf("%d", hex2int(carac));
scanf("%c", &caractere[0]);
scanf("%c", &caractere[1]);
printf("%d", hex2int(caractere));
*/
}
}

Formats disponibles : Unified diff