----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()); 
 
        delay(1000); 
 
} 
BOOL fWaitToTx(void)  
{  
    BYTE bTxStatus;  
        while ( !(bTxStatus = TX8_bReadTxStatus() & TX8_TX_COMPLETE));  
        return (TRUE);   
}  
 
void delay(unsigned int x)  
{  
    unsigned i;  
        for(i = 0; i < x; i++);  
} 
 |