We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Well, scanf now works fine. I can read signed int, hex and float. :-) But every received sign is echoed by scanf.
while(1) { printf("Enter your personal secret Hex-key!\n"); if (scanf("%X",&A)) break; scanf("%*"); //Clearing scanf input stream }
"But every received sign is echoed by scanf" No it isn't - it's echoed by getchar: http://www.keil.com/support/man/docs/c51/c51_getchar.htm As suggested in your previous post, you should really read the stuff into your own buffer, and then use sscanf on that! http://www.keil.com/forum/docs/thread7600.asp
Hello, Did you see ungetchar()/getchar()? I hope to help you this. Best Regards...
"Did you see ungetchar()/getchar()? I hope to help you this." It's getchar that's causing the "problem"!
Now i have this solution, works pretty well.
//*********************************************************************** //* putchar & _getkey for the ADuC7026 //* 24.04.2006 : Echo cancellation //*********************************************************************** #include <aduc7026.h> #define CR 0x0D #pragma thumb static int Echo_flag; //*********************************************************************** int putchar(int ch) /* Write character to Serial Port */ { if (!Echo_flag) { if (ch == '\n') //additional CR { while(!(COMSTA0 & 0x020)){} COMTX = CR; } while(!(COMSTA0 & 0x020)){} COMTX = ch; } Echo_flag = 0; //Echo on for next call of putchar return (ch); } //*********************************************************************** int _getkey (void) { while(!(COMSTA0 & 0x01)){} //waits until a sign appears in COMRX Echo_flag = 1; //Echo off for next call of putchar return (COMRX); } //***********************************************************************