| ??? 02/15/00 14:11 Read: times |
#1506 - dual serial port and printf, scanf |
The following code is giving me fits. I am using a dallas 80c320. printf and scanf work ok. The problem is getting more than one character from the scanf function. Printf works ok. The loops will compile but there must be some error that I do not see.
#include <c:c51incds80c320.h> #include <stdio.h> unsigned char i; unsigned char port0; unsigned char a; unsigned char j; unsigned char buf1[8]; unsigned char buf2[8]; unsigned long n; unsigned char cmd; unsigned int d; #define XON 0x11 #define XOFF 0x13 char putchar (char c) { if(port0){ if (c == 'n') { if (RI) { if (SBUF == XOFF) { do { RI = 0; while (!RI); } while (SBUF != XON); RI = 0; } } while (!TI); TI = 0; SBUF = 0x0d; /* output CR */ } if (RI) { if (SBUF == XOFF) { do { RI = 0; while (!RI); } while (SBUF != XON); RI = 0; } } while (!TI); TI = 0; return (SBUF = c); } else{ if (c == 'n') { if (RI_1) { if (SBUF1 == XOFF) { do { RI_1 = 0; while (!RI_1); } while (SBUF1 != XON); RI_1 = 0; } } while (!TI_1); TI_1 = 0; SBUF1 = 0x0d; /* output CR */ } if (RI_1) { if (SBUF1 == XOFF) { do { RI_1 = 0; while (!RI_1); } while (SBUF1 != XON); RI_1 = 0; } } while (!TI_1); TI_1 = 0; return (SBUF1 = c); } } char _getkey () { if(port0){ char c; while (!RI); c = SBUF; RI = 0; return (c); } else{ char c; while (!RI_1); c = SBUF1; RI_1 = 0; return (c); } } void main (void) { // setup for timer one TMOD = 0x20; TH1 = 0xf7; // setup for serial port zero SCON = 0x50; PCON = 0x80; // setup for serial port one SCON1 = 0x50; WDCON = 0x80; // enable timer 1 TR1 = 1; TI = 1; TI_1 = 1; EA = 1; while (1) { scanf("%c", &cmd); if(cmd == 'c'){ for(n=0;n>=7;n++){ buf1[n]=0; } } if(cmd == 'a' ){ for(n=0;n>=7;n++){ port0 = 1; scanf("%c", &buf1[n]); } } if(cmd == 'g' ){ for(n=0;n>7;n++){ port0 = 1; printf(&buf1[n]); } } } } |



