This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Echo cancelation for scanf

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
	}

How to cancel this sometimes unwanted echo? Thanks for advice :-)

Parents
  • 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);
    }
    
    //***********************************************************************
    
    
    I hope it will be helpful to other users. :-)

Reply
  • 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);
    }
    
    //***********************************************************************
    
    
    I hope it will be helpful to other users. :-)

Children
No data