Programa Comunicacion Rs232 - Turboc
#include
#include
#include
#include
union REGS rent, rsal;
void ini_rs232()
{
rent.h.ah=0x00; /* Inicialización */
rent.x.dx=0x00; /* COM1 */
rent.h.al=0x83; /* 1200bps, sin par, 1 bit stop, 8 bit datos */
int86(0x14,&rent,&rsal);
}
void escribe(char c)
{
rent.h.ah=0x01; /* Función escribir */
rent.x.dx=0x00; /* COM1 */
rent.h.al=c; /* Escribe caracter c*/
int86(0x14,&rent,&rsal);
}
int test_rs()
{
rent.h.ah=0x03; /* Lee status de línea */
rent.x.dx=0x00; /* COM1 */
int86(0x14,&rent,&rsal);
return(rsal.h.ah & 0x01); /* Retorna bits menossignificativo */
}
char leer_rs()
{
rent.h.ah=0x02; /* Función Leer dato */
rent.x.dx=0x00; /* COM1 */
int86(0x14,&rent,&rsal);
return(rsal.h.al); /* Retorna el dato en AL */
}
voidmain()
{
/*Primero se define el tipo de variable si es entero, entero sin signo o caracter */
unsigned int suma,suma2,s;
int st,i,j,k,l,n,largo,largo2,m;
charc,c1,codL,codH,codL2,codH2,ca[50],cad1[5],cad2[5],cad3[5],buf0[5],buf1[5],buf2[5],buf3[39],buf4[3],msg[50];
/*Luego se inicializan las variables (poniendo un cero) */
i=0;
j=0;
ca[0]=0;
buf0[0]=0;
buf1[0]=0;buf2[0]=0;
buf3[0]=0;
buf4[0]=0;
suma=0;
suma2=0;
clrscr();
ini_rs232(); /* Inicialización RS-232 */
while(1)
{
st = test_rs(); /* Lee estado de la línea */if(st)
{
c1 = leer_rs(); /* Lee dato */
ca[i]=c1;
putchar(c1);
i++;
if(c1==0xd)
{
ca[i]=0;
/*se guardan cadenas para comparar los datos de envio*/
strcpy(cad1,"hola");
strcpy(cad2,"1234");
strcpy(cad3,"chao");
/*strlen mide el largo de la cadena recivida */
largo = strlen(ca);
/*con esto separticiona la cadena enviada */
strncpy(&buf0[0],&ca[0],4); /*lo primeros 4 bits, son la direccion de origen */
strncpy(&buf1[0],&ca[4],4); /*estos son la direccion de destino */...
Regístrate para leer el documento completo.