aanand_44
Junior Member level 2
18f1320 uart
Hi,
I am user for C18 compiler. Now I am trying to use USART function in project. now i can transmit data controller to PC but i can't receive data from PC to Controller. Here i have attached the code. Please any one help me. Thanks in advance.
CPU: 18f1320
IDE: MPLAB7.6
compiler :C18
PIN USED:RB4=RX
RB1=TX
Anand
code:
Hi,
I am user for C18 compiler. Now I am trying to use USART function in project. now i can transmit data controller to PC but i can't receive data from PC to Controller. Here i have attached the code. Please any one help me. Thanks in advance.
CPU: 18f1320
IDE: MPLAB7.6
compiler :C18
PIN USED:RB4=RX
RB1=TX
Anand
code:
Code:
#include <p18f1320.h>
#include <delays.h>
#include <usart.h>
#include <stdlib.h>
#pragma config OSC = HS //INTIO2 // define osc type
#pragma config WDT = OFF // disable Watchdog Timer
#pragma config PWRT = OFF // disable Power-up Timer
#pragma config BOR = OFF // disable Brown-out Reset
#pragma config MCLRE = ON // disable MCLR
int onesec;
char data;
void main (void)
{
onesec = 1000;
ADCON1 = 0x00; //// disable PORTB A/D
//OSCCON = 0b01110111;
OSCCON = 0b01000100;
TRISA = 0;
TRISB=0x12;
TXREG = 0xAA;
baudUSART (BAUD_IDLE_CLK_HIGH &
BAUD_8_BIT_RATE &
BAUD_WAKEUP_ON &
BAUD_AUTO_OFF);
// Open the USART configured as 8N1, 2400 baud
OpenUSART ( USART_TX_INT_OFF &
USART_RX_INT_ON &
USART_ASYNCH_MODE &
USART_EIGHT_BIT &
USART_CONT_RX &
USART_BRGH_LOW, 129);
RCSTA = 0b10010000;
while (1){
// write to the USART
putrsUSART("\nUART READY!\n"); // This statement printed in hyperteminal
// // wait for input
/********************************************************/
/* problem is here, after printing the statement UART READY! LED is blinkin
But this can't sense keyboard inttrupt */
/**********************************************************/
while (!DataRdyUSART())
{
PORTA = 0x01; //LED ON
Delay10KTCYx(onesec); // 1 second delay
PORTA = 0; //LED OFF
Delay10KTCYx(onesec);
}
while(DataRdyUSART())
{
data = ReadUSART();
WriteUSART ( data );
}
}
}