Révision 808
Ajouté par begresset il y a presque 4 ans
SP4C12.c | ||
---|---|---|
/***********************************************************************/
|
||
#include "sfr32c87.h"
|
||
|
||
void init_led(void){
|
||
pd1=0b11111111;
|
||
p1=0b00000000;
|
||
}
|
||
|
||
void uart0_init(void){
|
||
|
||
u0mr=0b00000101;
|
||
u0brg=0b00100000;
|
||
u0c0=0b00010001;
|
||
u0c1=0b00000101;
|
||
pd6=0b00011000;
|
||
ps0=0b00001000;
|
||
u0c0=0b00001001;
|
||
u0c1=0b00010101;
|
||
|
||
pd6_0=0;
|
||
pd6_1=0;
|
||
pd6_2=0;
|
||
pd6_3=1;
|
||
|
||
ps0_0=0;
|
||
ps0_1=0;
|
||
ps0_2=0;
|
||
ps0_3=1;
|
||
|
||
}
|
||
|
||
void uart0_tx(char c){
|
||
while (ti_u0c1!=1){
|
||
u0tb=c;
|
||
}
|
||
while (ti_u0c1!=1);
|
||
u0tb=c;
|
||
}
|
||
|
||
|
||
char uart0_rx(){
|
||
while (ri_u0c1!=0);
|
||
return u0rb;
|
||
}
|
||
|
||
char buffer[128]=0, trame[]="$GPGGA*";
|
||
//Test de uart0_rx() :
|
||
void main(void)
|
||
{
|
||
int etat=0, i=0;
|
||
|
||
uart0_init();
|
||
while (1)
|
||
{
|
||
uart0_tx ('c');
|
||
init_led();
|
||
|
||
if((trame[i])=='$'){
|
||
p1=0xff;
|
||
while((trame[i])!='*'){
|
||
buffer[i]=trame[i];
|
||
i++;
|
||
}
|
||
}
|
||
if((uart0_rx())=='*'){
|
||
p1=0x0f;
|
||
}
|
||
|
||
}
|
||
|
||
//Affiche l'alphabet en continu
|
||
/*void main(void)
|
||
{
|
||
char c='A';
|
||
int i;
|
||
uart0_init();
|
||
|
||
while(1){
|
||
i=0;
|
||
while (i<26){
|
||
uart0_tx(c+i);
|
||
i++;
|
||
}
|
||
}
|
||
}
|
||
}*/
|
||
|
Formats disponibles : Unified diff
séance c2.