Hi,
But how can i program using C at the PC site to send data to pic and on the PIC, how i manage those data from PC?
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 char read_data; void main() { adcon1=0x06; adcon0=0x0f; cmcon=0x07; ccp1con=0; ccp2con=0; TRISC=0x80; TRISB=0x02; UART1_Init(9600); Delay_ms(100); UART1_Write_Text("s"); while(1) { if (UART1_Data_Ready()==1) { UART1_Write_Text("A"); read_data= UART1_Read(); UART1_Write(read_data+1); } } }
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 //Without ISR char uart_rcv[32], uart_rd; void main() { TRISC = 0x80; TRISB = 0x02; ADCON0 = 0x0F; ADCON1 = 0x06; CMCON = 0x07; UART1_Init(9600); Delay_ms(100); UART1_Write_Text("UART Test..."); while(1) { if (UART1_Data_Ready()) { uart_rd = UART1_Read(); //Receive single character UART1_Write(uart_rd); //Echo back received character UART1_Write(0x0D); UART1_Write(0x0A); UART1_Read_Text(uart_rcv, "\r\n", 32); //Receive string strcat(uart_rcv, "\r\n"); UART1_Write_Text(uart_rcv); //Echo back received string } } } //using ISR char uart_rcv[32], uart_rd, i = 0; void Interrupt() { if(RCIF_bit){ uart_rcv[i++] = RCREG; uart_rcv[i] = '\0'; RCIF_bit = 0; } } void main() { TRISC = 0x80; TRISB = 0x02; ADCON0 = 0x0F; ADCON1 = 0x06; CMCON = 0x07; UART1_Init(9600); Delay_ms(100); RCIE_bit = 1; UART1_Write_Text("UART Test..."); while(1) { if(uart_rcv[0]){ UART1_Write_Text(uart_rcv); UART1_Write(0x0D); UART1_Write(0x0A); } } }
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 typedef unsigned char u8int_t; u8int_t uart_rcv[32], uart_rd, i = 0; void Interrupt() { if(RCIF_bit){ uart_rcv[i++] = RCREG; uart_rcv[i] = '\0'; RCIF_bit = 0; } } void main() { TRISC = 0x80; TRISB = 0x02; ADCON0 = 0x0F; ADCON1 = 0x06; CMCON = 0x07; INTCON = 0xC0; UART1_Init(9600); Delay_ms(100); RCIE_bit = 1; UART1_Write_Text("UART Test..."); UART1_Write(0x0D); UART1_Write(0x0A); while(1) { if((uart_rcv[i - 2] == 'X') && (uart_rcv[i - 1] == 'X')){ UART1_Write(0x0D); UART1_Write(0x0A); UART1_Write_Text(uart_rcv); uart_rcv[i - 2] = '\0'; uart_rcv[i - 1] = '\0'; } } }
FERR: Framing Error bit
1 = Framing error (can be updated by reading RCREG register and receive next valid byte)
0 = No framing error
bit 1 OERR
Overrun Error bit
1 = Overrun error (can be cleared by clearing bit CREN)
0 = No overrun error
......
c1 =Read1USART(); // le lire => RAZ RCIF
if(RCSTA1bits.FERR==1 )
{
RCSTA1bits.SPEN = 0 ;
RCSTA1bits.SPEN= 1 ;
c1=0;
}
if (RCSTA1bits.OERR==1) // voir parag 16.1.26 p273
{
RCSTA1bits.CREN = 0 ;
RCSTA1bits.CREN = 1 ;
c1=0;
}
.....
Dear All,
I'm Facing a Problem with UART Communication between PIC and PC.I mentioned my System Spec,
1,PIC16F877A
2.4mHz
3.Mikro C for PIC
Here I Placed my Code.Kindly help to complete this.I Tried this with Proteus, It was working,While testing with the Actual Hardware Its sending data from PIC to PC.But Its Not Recieving my data (PC to PIC). Thanks in Advance.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 char read_data; void main() { adcon1=0x06; adcon0=0x0f; cmcon=0x07; ccp1con=0; ccp2con=0; TRISC=0x80; TRISB=0x02; UART1_Init(9600); Delay_ms(100); UART1_Write_Text("s"); while(1) { if (UART1_Data_Ready()==1) { UART1_Write_Text("A"); read_data= UART1_Read(); UART1_Write(read_data+1); } } }
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?