void Soft_Usart_SendByte(INT8U ucData)
{
INT8U tmpI;
Usart_Tx_Port = 1;
Usart_Tx_Port = 0;
for(tmpI=0; tmpI<8; tmpI++)
{
Soft_DelayMs(1);
Usart_Tx_Port = ((ucData>>tmpI)&0x01)?1:0;
}
Soft_DelayMs(1);
Usart_Tx_Port = 1;
Soft_DelayMs(2);
}
void Soft_DelayMs(INT16U ucTimeOut)
{
TMR2IF = 0;
do
{
if(TMR2IF == 1)
{
TMR2IF = 0;
ucTimeOut--;
}
}while(ucTimeOut);
}
void Init_Timer2(void)
{
T2CON = 0b00000110; //T2ON=1, 1:16
PR2 = BIT_TIME
TMR2 = 0x00;
TMR2IP = 0;
TMR2IF = 0;
}
#define BIT_TIME (INT8U)(XTAL / BAUD)
#ifndef XTAL
#define XTAL (8000000UL/4/16)
#endif
#ifndef BAUD
#define BAUD (9600UL)
#endif
#define Usart_Tx_Port PORTDbits.RD0
#define Usart_Tx_DDR TRISDbits.TRISD0
#define Usart_Rx_Port PORTDbits.RD1
#define Usart_Rx_DDR TRISDbits.TRISD1
|