fork download
  1. #include<pic.h>
  2.  
  3.  
  4. CONFIG(0x3f72);
  5.  
  6.  
  7. #define SBIT_TXEN
  8. 5
  9.  
  10. #define SBIT_SPEN
  11. 7
  12.  
  13. #define SBIT_CREN
  14. 4
  15.  
  16.  
  17. void UART_Init(int baudRate)
  18. {
  19. TRISC=0x80; // Configure Rx pin as input and Tx as output TXSTA=(1<<SBIT_TXEN); // Asynchronous mode, 8-bit data & enable transmitter
  20.  
  21.  
  22. RCSTA=(1<<SBIT_SPEN) | (1<<SBIT_CREN); // Enable Serial Port and 8-bit continuous receive
  23. SPBRG = (20000000UL/(long)(64UL*baudRate))-1; // baud rate @20Mhz Clock
  24. }
  25.  
  26. void UART_TxChar(char ch)
  27. {
  28. while(TXIF==0); // Wait till the transmitter register becomes empty TXIF=0; // Clear transmitter flag
  29. TXREG=ch; // load the char to be transmitted into transmit reg
  30. }
  31.  
  32.  
  33. char UART_RxChar()
  34. {
  35. while(RCIF==0); // Wait till the data is received RCIF=0; // Clear receiver flag
  36. return(RCREG); // Return the received data to calling function
  37. }
  38. void main()
  39. {
  40. char i,a[]={"Press Any Key in Keyboard:"}; char ch;
  41.  
  42. UART_Init(9600); //Initialize the UART module with 9600 baud rate for(i=0;a[i]!=0;i++)
  43. {
  44. UART_TxChar(a[i]); // Transmit predefined string
  45. }
  46.  
  47. while(1)
  48. {
  49. ch = UART_RxChar(); // Receive a char from serial port UART_TxChar(ch); // Transmit the received char
  50. }
  51. }
Success #stdin #stdout 0.03s 25792KB
stdin
Standard input is empty
stdout
#include<pic.h>


    CONFIG(0x3f72);


#define SBIT_TXEN
5

#define SBIT_SPEN
7

#define SBIT_CREN
4


void UART_Init(int baudRate)
{
TRISC=0x80; // Configure Rx pin as input and Tx as output TXSTA=(1<<SBIT_TXEN); // Asynchronous mode, 8-bit data & enable transmitter


RCSTA=(1<<SBIT_SPEN) | (1<<SBIT_CREN); // Enable Serial Port and 8-bit continuous receive
SPBRG = (20000000UL/(long)(64UL*baudRate))-1; // baud rate @20Mhz Clock
}

void UART_TxChar(char ch)
{
while(TXIF==0); // Wait till the transmitter register becomes empty TXIF=0; // Clear transmitter flag
TXREG=ch; // load the char to be transmitted into transmit reg
}


char UART_RxChar()
{
while(RCIF==0); // Wait till the data is received RCIF=0; // Clear receiver flag
return(RCREG); // Return the received data to calling function
}
void main()
{
char i,a[]={"Press Any Key in Keyboard:"}; char ch;

UART_Init(9600); //Initialize the UART module with 9600 baud rate for(i=0;a[i]!=0;i++)
{
UART_TxChar(a[i]); // Transmit predefined string
}

while(1)
{
ch = UART_RxChar(); // Receive a char from serial port UART_TxChar(ch); // Transmit the received char
}
}