📄 com.c
字号:
/* THIS SAMPLE CODE IS PROVIDED AS IS AND IS SUBJECT TO ALTERATIONS. FUJITSU */
/* MICROELECTRONICS ACCEPTS NO RESPONSIBILITY OR LIABILITY FOR ANY ERRORS OR */
/* ELIGIBILITY FOR ANY PURPOSES. */
/* (C) Fujitsu Microelectronics Europe GmbH */
/************************************************************************/
/* FFMC-16LX Softune V01 */
/* Fujitsu Mikroelektronik/Germany */
/* */
/* Project UART540 Member list: */
/* - start.asm */
/* - mb90540.asm */
/* - main.c */
/* - com.c */
/* */
/* Even the program has been carefully checked and is believed to work */
/* properly no warranty is given by Fujitsu. */
/* */
/* History */
/* */
/* Date Rev. Author Description */
/*14.01.00 1.00 MEN communication functions */
/************************************************************************/
/******************************* Includes ***************************************/
#include "mb90540.h"
/******************************* Gloabals ***************************************/
extern unsigned char tbuf,rbuf,temp;
extern unsigned char *p_string;
extern char length;
/******************************* Strings ****************************************/
unsigned char message[] = " No answer from slave 1, check connection ";
unsigned char message2[] = " No answer from slave 2, check connection ";
/******************************* Prototyps **************************************/
void send(unsigned char);
char wait(unsigned char);
void receive_adr(void);
void receive_data(void);
void echo_ch(void);
/*============================== PROCEDURES ====================================*/
void send(unsigned char data)
{
switch(data){
case '1': tbuf = '1'; /* sending address to slave1 */
break;
case '2': tbuf = '2'; /* sending address to slave2 */
break;
case 'd': URD0_D8 = 0; /* set data bit */
tbuf = 'd'; /* send data */
break;
default : tbuf = 0; /* send nothing */
}
}
void receive_adr(void)
{
switch(rbuf) /* select the address of the slave */
{
case '1': URD0_D8 = 0;
tbuf = 'a'; /* detect slave1 */
break;
case '2': URD0_D8 = 0;
tbuf = 'b'; /* detect slave2 */
break;
default : tbuf = 0;
}
}
void receive_data(void)
{
if(rbuf == 'd')
{
tbuf = 'r'; /* send acknowlegde to the master */
}
}
char wait(unsigned char value) /* wait for response */
{
unsigned int i;
char status = 0;
for(i = 0;i < 65000; i++) /* wait loop */
{
if(rbuf == 'a' || rbuf == 'r' || rbuf == 'b') /* when receiving the correct sign */
{
i = 0;
tbuf = rbuf; /* echo received character */
rbuf = 0; /* clear receive buffer */
while(tbuf != 0); /* waiting until buffer is empty */
break; /* leave the timeout generator */
}
}
if(i >= 64000) /* time is over */
{
if(value == '1')
{
p_string = message; /* send error message */
length = strlen(p_string); /* get string lenght */
}
else
{
p_string = message2; /* send error message */
length = strlen(p_string); /* get string lenght */
}
status = -1;
}
return(status); /* return status */
}
void echo_ch(void)
{
tbuf = rbuf; /* master echos received data */
while(tbuf != 0); /* wait until buffer is empty */
}
/*============================== END OF PROCEDURES ======================================*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -