How can I use two or more RS-232 ports on one PIC®?
The #USE RS232 (and I2C for that matter) is in effect for GETC, PUTC, PRINTF and KBHIT functions encountered until another #USE RS232 is found.The #USE RS232 is not an executable line. It works much like a #DEFINE.
The following is an example program to read from one RS-232 port (A) and echo the data to both the first RS-232 port (A) and a second RS-232 port (B).
#USE RS232(BAUD=9600, XMIT=PIN_B0, RCV=PIN_B1)
void put_to_a( char c ) {
put(c);
}
char get_from_a( ) {
return(getc()); }
#USE RS232(BAUD=9600, XMIT=PIN_B2,RCV=PIN_B3)
void put_to_b( char b ) {
putc(c);
}
main() {
char c;
put_to_a("Online\n\r");
put_to_b("Online\n\r");
while(TRUE) {
c=get_from_a();
put_to_b(c);
put_to_a(c);
}
}
The following will do the same thing but is more readable and is the recommended method:
#USE RS232(BAUD=9600, XMIT=PIN_B0, RCV=PIN_B1, STREAM=COM_A)
#USE RS232(BAUD=9600, XMIT=PIN_B2, RCV=PIN_B3, STREAM=COM_B)
main() {
char c;
fprintf(COM_A,"Online\n\r");
fprintf(COM_B,"Online\n\r");
while(TRUE) {
c = fgetc(COM_A);
fputc(c, COM_A);
fputc(c, COM_B);
}
}
Hola!!
Alguna vez he programado en Asembler, pero realmente prefiero hacerlo en C. Y ademas me parece que el mejor compilador es es PICC compiler CCS. mi pregunta es, como en ese compilador puedo configurar usar 2 puertos o conexiones RS232 seriales semi simultaneamente?. Es decir, el sistema espere un caracter por alguno de los dos puertos y cuando llegue por alguno de los 2 identifique el caracter y por cual puerto llegó. Por ejemplo tengo dos dispositivos iguales cuya salida es serial. alguno de los dos, en algun momento intentan comunicarse con el PIC (Claro a travez de un max232, quien, afortunadamente, trae espacio para dos canales independientes), y el pic debe decir: aja! el dispositivo 1 se acaba de comunicar! y envia el caracter 'F', y asi...
Saludos a todos y Gracias
HOLA A TODOS, DESPUES DE HACER MI CONSULTA RECIEN VI ESTA INFORMACION, SOLO HAY UN DETALLE, NO MANEJO EL C, SI ALGUIEN HA PASADO ESTA INFORMACION AL PROTON ME SERIA DE MUCHA UTILIDAD, SORRY POR LAS MOLESTIAS, NECESITO MANEJAR 2 ENTRADAS SERIALES QLLEGEUN AL PIC, COMO SABER Q DATO CORRESPONDE A EMISOR DE LA SEÑAL?
GRACIAS
SALUDOS