----TX部分----
//
// Custom.c
//
// Custom functions for insertion into PSoC Express projects, including fixed functions
//
#include <m8c.h>
#include "PSoCAPI.h"
#include "custom.h"
#define START 0xa5
#define X 0x41
#define Y 0x52
#define STOP 0x5a
const BYTE data[] ={ START, X, Y, STOP};
extern SYSTEM_VARS_STRUC SystemVars;
void delay(unsigned int x);
BOOL fWaitToTx(void);
BYTE A;
BYTE B;
//
// CustomInit() is run after driver and channel instantiation functions, but before the main loop
//
void CustomInit( void )
{
}
//
// CustomPostInputUpdate() is run after input drivers have updated SystemVars, but before transfer
// functions are evaluated.
//
void CustomPostInputUpdate( void )
{
}
//
// CustomPreOutputUpdate() is run after transfer functions have been evaluated, but before the output
// driver are updated with values from SystemVars.
//
void CustomPreOutputUpdate( void )
{
unsigned char i;
Counter8_Start();
TX8_Start(0);
M8C_EnableGInt;
A = PRT1DR;
B = PRT1DR;
//START
TX8_SendData(START);
if (fWaitToTx());
//X
if (SystemVars.ReadWriteVars.pse_XAxis < 0)
A = (-SystemVars.ReadWriteVars.pse_XAxis >> 3) | 0x80;
else
A = (SystemVars.ReadWriteVars.pse_XAxis >> 3) & 0x7f;
TX8_SendData(A);
if (fWaitToTx());
delay(100);
//Y
if (SystemVars.ReadWriteVars.pse_YAxis < 0)
B = (-SystemVars.ReadWriteVars.pse_YAxis >> 3) | 0x80;
else
B = (SystemVars.ReadWriteVars.pse_YAxis >> 3) & 0x7f;
TX8_SendData(B);
if (fWaitToTx());
//STOP
TX8_SendData(STOP);
if (fWaitToTx());
----RX部分----
//----------------------------------------------------------------------------
// C main line
//----------------------------------------------------------------------------
#include <m8c.h> // part specific constants and macros
#include "PSoCAPI.h" // PSoC API definitions for all User Modules
#include "RX8.h"
while (1)
{
if (fWaitToRx())
{
if(bRxData)
{
if (j == 0)
{
DigBuf1_Start();
DigBuf2_Stop();
DigBuf4_Start();
DigBuf3_Stop();
for (i = 7; i <= 120; i++)
{
PWM8_WritePulseWidth(i);
PWM81_WritePulseWidth(i);
delay(2500);
}
for (i = 120; i >= 7; i--)
{
PWM8_WritePulseWidth(i);
PWM81_WritePulseWidth(i);
delay(2500);
}
}
else
{
DigBuf1_Stop();
DigBuf2_Start();
DigBuf4_Stop();
DigBuf3_Start();
for (i = 7; i <= 120; i++)
{
PWM8_WritePulseWidth(i);
PWM81_WritePulseWidth(i);
delay(2500);
}
for (i = 120; i >= 7; i--)
{
PWM8_WritePulseWidth(i);
PWM81_WritePulseWidth(i);
delay(2500);
}
}
j = 1 - j;
}
}