root/branch/graffin/sp4c12/sp4C12/sp4C12.c
719 | magraffin | /***********************************************************************/
|
|
/* */
|
|||
/* FILE :sp4C12.c */
|
|||
/* DATE :Wed, Jun 02, 2021 */
|
|||
/* DESCRIPTION :main program file. */
|
|||
/* CPU GROUP :87B */
|
|||
/* */
|
|||
/* This file is generated by Renesas Project Generator (Ver.4.18). */
|
|||
/* NOTE:THIS IS A TYPICAL EXAMPLE. */
|
|||
/***********************************************************************/
|
|||
881 | magraffin | #include "sfr32c87.h"
|
|
#include "uart0.h"
|
|||
char tram[80];
|
|||
char c,c1,c2,t1,t2,check=0,t3,t4,carac_tram=0;
|
|||
int i=0,debut=0,fin_tram,validation=0;
|
|||
void main(void)
|
|||
{
|
|||
uart0_init();
|
|||
/*
|
|||
while (1)
|
|||
{
|
|||
for (i=0;i<26;i++)
|
|||
{
|
|||
uart0_tx(65+i);
|
|||
}
|
|||
}
|
|||
*/
|
|||
while (1)
|
|||
{
|
|||
carac_tram=rectram(tram);
|
|||
}
|
|||
}
|
|||
void uart0_init(void)
|
|||
{
|
|||
u0mr=0x05;
|
|||
u0smr=0x00;
|
|||
u0smr2=0x00;
|
|||
u0smr3=0x00;
|
|||
u0smr4=0x00;
|
|||
u0c0=0x11;
|
|||
u0brg=0x20;
|
|||
u0c1=0x00;
|
|||
pd6_0=0;
|
|||
pd6_1=0;
|
|||
pd6_2=0;
|
|||
pd6_3=1;
|
|||
ps0_0=0;
|
|||
ps0_1=0;
|
|||
ps0_2=0;
|
|||
ps0_3=1;
|
|||
u0c1=0x05;
|
|||
}
|
|||
void uart0_tx(char c)
|
|||
{
|
|||
while (ti_u0c1!=1);
|
|||
u0tb=c;
|
|||
}
|
|||
char uart0_rx(void)
|
|||
{
|
|||
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;
|
|||
validation=0;
|
|||
do{
|
|||
c=uart0_rx();
|
|||
if (c=='\n' || c=='\r'){
|
|||
fin_tram=1;
|
|||
}
|
|||
if (c=='*'){
|
|||
/*p1_1=1;
|
|||
while (i!=10000){i++;}
|
|||
p1_1=0;*/
|
|||
//*(buffer+i)
|
|||
c1=uart0_rx();
|
|||
c2=uart0_rx();
|
|||
debut=0;
|
|||
i+=3;
|
|||
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++;
|
|||
*(buffer+i)=c;
|
|||
check=check^c;
|
|||
}
|
|||
if (c=='$'){
|
|||
/*p1_0=1;
|
|||
while (i!=10000){i++;}
|
|||
p1_0=0;*/
|
|||
i=0;
|
|||
debut=1;
|
|||
*buffer=c;
|
|||
}
|
|||
}
|
|||
while (fin_tram==0);
|
|||
return i+1;
|
|||
}
|
|||
void irectrame(char *buffer,char c){
|
|||
if (c=='$'){
|
|||
debut=1;
|
|||
*buffer=c
|
|||
}
|
|||
if (debut==1){
|
|||
*(buffer+i)=c;
|
|||
check=check^c;
|
|||
}
|
|||
if (c==
|
|||