Dear all,
I know its wrong to ask question in forum , since i have designed code for PIC controller using MPlab. I am asking here to get answer since its in C code.
am using Mplab x Ide with v3.61 on Xc8 compiler, PIC18F24K40. I used MCC generated UART code for send and receive data.
I have Euart functions like below
#define LED_RX RC7 // Pin assigned RX LED
#define LED_TX RC6 // Pin assigned TX LED
#define LED RC2 // Pin assigned for LED
unsigned int count=0;
char data;
char data1[10];
/* Send Data Serially */
void send_string(const char *x)
{
while(*x)
{
EUSART_Write(*x++);
}
}
char receive_text()
{
unsigned char text[10]; /*character arrya to store the string*/
unsigned char i=0; /*array index variable */
/*character is received until end of the string received */
do
{
while(1==PIR3bits.RCIF);
*(text+i)=RC1REG;
i++;
}while(*(text+i));
return text; /* return the base address of received string */
}
char UART_Read()
{
while(1==PIR3bits.RCIF);
return RC1REG;
}
/* Timer Interrupt Service Routine Program*/
void Blink_Count()
{
if(PIR0bits.TMR0IF == 1)
{
PIR0bits.TMR0IF =0;
count=count+1;
if(count>=15)
{
// LED=!LED;
count=0;
}
}
}
void main(void)
{
// Initialize the device
SYSTEM_Initialize();
// If using interrupts in PIC18 High/Low Priority Mode you need to enable the Global High and Low Interrupts
// If using interrupts in PIC Mid-Range Compatibility Mode you need to enable the Global and Peripheral Interrupts
// Use the following macros to:
// Enable high priority global interrupts
//INTERRUPT_GlobalInterruptHighEnable();
// Enable low priority global interrupts.
//INTERRUPT_GlobalInterruptLowEnable();
// Disable high priority global interrupts
//INTERRUPT_GlobalInterruptHighDisable();
// Disable low priority global interrupts.
//INTERRUPT_GlobalInterruptLowDisable();
// Enable the Global Interrupts
//INTERRUPT_GlobalInterruptEnable();
// Enable the Peripheral Interrupts
//INTERRUPT_PeripheralInterruptEnable();
// Disable the Global Interrupts
//INTERRUPT_GlobalInterruptDisable();
// Disable the Peripheral Interrupts
//INTERRUPT_PeripheralInterruptDisable();
send_string("Serial CHECK CODE\r\n");
while (1)
{
data= EUSART_Read();
rxbuf[10]=data;
printf("%s\n",&rxbuf[10]);
__delay_ms(150);
}
}
And tested Serial communication. with this code i could print welcome on Serial Monitor
void main(void)
{
EUSART_Initialize();
while (1)
{
char array[20] = "Hello World";
printf("%s\n",array);
__delay_ms(150);
}
}
The problem i am facing is. When i try to send data 0103000000Ac5CD In ASCii format i receice as charcter ,but when i try to send in hex format i could not able to receive nothing. If am printing data like i used in working hello print example i got garbage value.