root/branch/sacco/sp4c12/SP4c1/SP4c1/uart0.c @ 861
| 739 | gasacco | /***********************************************************************/
|
|
/* */
|
|||
| 755 | gasacco | /* FILE :uart0.c */
|
|
| 739 | gasacco | /* 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. */
|
|||
/***********************************************************************/
|
|||
| 755 | gasacco | #include "sfr32c87.h"
|
|
| 739 | gasacco | ||
| 755 | gasacco | ||
| 739 | gasacco | void uart0_init(void)
|
|
{
|
|||
| 755 | gasacco | u0mr = 0x05;
|
|
//Param?trage des modes sp?ciaux
|
|||
u0smr = 0x00;
|
|||
u0smr2 = 0x00;
|
|||
u0smr3 = 0x00;
|
|||
u0smr4 = 0x00;
|
|||
u0c0 = 0x11;
|
|||
//Param?trage des bauds
|
|||
u0brg = 32;
|
|||
u0c1 = 0x00;
|
|||
pd6_0 =1;
|
|||
pd6_1 =0;
|
|||
pd6_2 =0;
|
|||
pd6_3 =1;
|
|||
ps0_0 =1;
|
|||
ps0_1 =0;
|
|||
ps0_2 =0;
|
|||
ps0_3 =1;
|
|||
u0c1 = 0x05;
|
|||
}
|
|||
| 739 | gasacco | ||
| 755 | gasacco | void uart0_tx (char c)
|
|
{
|
|||
while ( ti_u0c1 !=1);
|
|||
u0tb = c;
|
|||
}
|
|||
| 739 | gasacco | ||
| 755 | gasacco | char uart0_rx()
|
|
{
|
|||
while (ri_u0c1 !=1);
|
|||
return u0rb;
|
|||
| 739 | gasacco | ||
}
|
|||
| 755 | gasacco | char alphabet(void)
|
|
{
|
|||
int c = 65;
|
|||
uart0_init();
|
|||
while(1)
|
|||
{
|
|||
uart0_tx((char) c);
|
|||
c = (int)c +1;
|
|||
if (c==91)
|
|||
{
|
|||
c = (int) 65;
|
|||
}
|
|||
}
|
|||
}
|
|||
| 858 | gasacco | ||
int hex2int( char*c)
|
|||
{
|
|||
}
|
|||
short recTrame (char *Buffer)
|
|||
{
|
|||
int i=0;
|
|||
char CS =0;
|
|||
char a;
|
|||
char CS_reel[1];
|
|||
| 755 | gasacco | ||
| 858 | gasacco | while (uart0_rx() !='$');
|
|
while (a = uart0_rx() != '*')
|
|||
{
|
|||
Buffer[i] = a;
|
|||
CS = Buffer[i] + CS;
|
|||
i++;
|
|||
}
|
|||
CS_reel[0] = uart0_rx();
|
|||
CS_reel[1] = uart0_rx();
|
|||
if (CS_reel[0] + CS_reel[1] == CS)
|
|||
{
|
|||
uart0_tx('Y');
|
|||
}
|
|||
return i;
|
|||
}
|
|||
| 755 | gasacco | ||
| 858 | gasacco | ||
| 755 | gasacco | void main(void)
|
|
{
|
|||
| 858 | gasacco | char nb1;
|
|
char nb2;
|
|||
char trame[100];
|
|||
uart0_init();
|
|||
while (1)
|
|||
| 755 | gasacco | {
|
|
| 858 | gasacco | nb1 = (char) (recTrame(trame))/10;
|
|
nb2 = (char) (recTrame(trame))%10;
|
|||
| 755 | gasacco | ||
| 858 | gasacco | uart0_tx(nb1+48);
|
|
uart0_tx(nb2+48);
|
|||
| 755 | gasacco | }
|
|
}
|
|||