Professional Documents
Culture Documents
PIC10F202 SoftwareUART
PIC10F202 SoftwareUART
// email: winnipux2014@gmail.com
/*
Baud � 1bit width in us
1200 � 1/1200=833.33us
2400 � 1/2400=416.66us
4800 � 1/4800=208.33us
9600 � 1/19600=104.16us
19200 � 1/19200=52.08us
38400 � 1/38400=26.04us
57600 � 1/57600=17.36us
115200 � 1/115200=8,68us
230400 � 1/230400=4.34us
250000 � 1/250000=4us
*/
#include <xc.h>
#ifndef _XTAL_FREQ
#define _XTAL_FREQ 4000000
#endif
//Function Declarations
void InitSoftUART(void);
unsigned char UART_Receive(void);
void UART_Transmit(const char);
void main()
{
unsigned char ch = 0;
CLRWDT();
TRISGPIO = 0b11111010;
GPIO = 0;
while(1)
{
// ch = UART_Receive(); // Receive a character from UART
ch=0xAA;
UART_Transmit(ch); // Echo back that character
ch=0xBB;
UART_Transmit(ch);
ch=0x0D;
UART_Transmit(ch);
}
}
UART_RX_DIR = 1; // Input
UART_TX_DIR = 0; // Output
}
__delay_us(OneBitDelay);
__delay_us(OneBitDelay/2); // Take sample value in the mid of bit duration
__delay_us(OneBitDelay);
}
*/
// __delay_us(OneBitDelay);
__delay_us(104.16);//9600
}