/* SE1.C rs232 */ /* PC <--> 8051 RS232 COM1 <9600 N 8 1> */ #define op outportb #define ip inportb #include #include /*-----------------------------*/ main() { unsigned char c; init_232(); clrscr(); puts("---------------------------------------"); puts("SE1.EXE PC RS232 COM1 <9600 N 8 1> "); puts("---------------------------------------"); while(1) { /* check any valid data in */ c=ip(0x3fd); if( (c & 0x01)== 0x01) { c=ip(0x3f8); printf("%c",c); } /* check user key in */ if( kbhit() ) { c=getch(); switch(c) { case ' ': clrscr(); puts("--------------------------------------"); puts("SE1.EXE PC RS232 COM1 <9600 N 8 1>"); puts("--------------------------------------"); break; case 27 : exit(0); break; default : printf("%c", c); tx(c); break; } } } } /*---------------------------------------------*/ init_232() { op(0x3fb, 0x80); op(0x3f8, 0x0c); op(0x3f9, 0 ); op(0x3fb, 0x03); op(0x3fc, 0x02); op(0x3f9, 0 ); } /*----------------------------------------------*/ /* in 3fd bit1=1 have data in from 3f8 */ char rx() { char in; while(1) { if(kbhit()) { getch(); break; } in=ip(0x3fd); if( (in & 0x01)== 0x01) { in=ip(0x3f8); return(in); } } } /*---------------------------------------*/ /* in 3fd bit5=1 7654 op to 3f8 */ tx(char c) { char in; while(1) { in=ip(0x3fd); if( (in & 0x20)== 0x20 ) { op(0x3f8, c); break; } } } /*-------------------------------------------*/