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

How to scan strings from keyboard much clever?

I want to scan string from keyboard and display on LCd ,but when scanning the next string ,the buffer for saving pre_string will be changed to the value in scanning buffer,and the display also will be changed.

so i want a solution for scanning string from keyboard .can you give me some flowchart or code for example.

best regards,
nantiangumo

  • "but when scanning the next string ,the buffer for saving pre_string will be changed"

    So don't change it, then!

    Have a buffer to receive data from the keyboard, and a separate buffer for data to display; you "scanning" stuff should only ever read from the input buffer.

  • My program structure as following:

    static unsigned char idata sKeyBuf[15]= {0};
    static unsigned char idata sScanBuf[10] = {0};
    static unsigned char idata cForm = 0,cPrePos = 0;
    unsigned char *ptr;
    
    void main()
    {
    	...
    	sprintf(sKeyBuf,"%s","12345678");
    
    	while(1)
    	{
    		...
    		cForm = StateMachine(key); //Scanning the functional key for switiching LCD PAGE
    		ptr = ScanKeyboard(Key); //getting the string from keyboard
    		ptr = DispFamat(ptr,cForm); //format string for displaying
    		if ((cForm / 10) == 2) //getting in one LCD page
    		{
    
    			if (cPrePos != cForm % 10)
    			{
    
    				switch(cPrePos)
    				{
    					case 0:PrintFunc(obv,Pos0,sKeybuf); //  disp  full string obverse at position0 only when disp position be changed ;
    					case 1:PrintFunc(obv,Pos1,sKeybuf);
    					...
    					default:break;
    				}
    				sprintf(sKeybuf,"%s\0",ptr);//if disp position changed ,the previous string be saved in sKeyBuf;
    				cPrePos = cForm % 10; // if disp position changed ,cPrePos changed.
    			}
    
    			switch(cForm%10)  //positioning where to display
    			{
    				case 0:PrintFunc(rev,Pos0,ptr); // disp  string  reverse at position0 every byte input ;
    				case 1:PrintFunc(rev,Pos1,ptr);
    				...
    				default:break;
    			}
    			...
    
    		}
    		...
    	}
    }
    

    when display reverse ,the string can disp rightly,just when disp obverse ,the string in sKeyBuf be changed as ptr pointting to. tell me what is the mistake if you found after reading ?
    Thanks all!

  • I'm sorry, but I don't understand your question. Could you try to explain the problem more clearly?

    One thought: do you really intend your switch case statements to fall through?