get stuck when trying to use keypad (help me)

hi hello there, am newbie here and got stuck with my program. Actually i use Nuvoton NUC140VE3CN in this case not the arduino, i just wanted ask about the program working even both of them use a same programming language.

So i trying to controlling some component like buzzer and led, before u can controll them u should be logged in with password. The problem is, when i has logged in the next program wont working.

heres the code:

char TEXT0[16]		="Controlling Component";
char TEXT1[16]		="KeyCode :      ";
char TEXT2[16]		="               ";
char passcode[7]	        ="123456";
char keycode[7]		="000000";

#define  BLUE  1
#define  GREEN 2
#define  RED   3

void init_RGBLED(void)
{
	// initialize GPIO pins
	DrvGPIO_Open(E_GPA, 12, E_IO_OUTPUT); // GPA12 pin set to output mode
	DrvGPIO_Open(E_GPA, 13, E_IO_OUTPUT); // GPA13 pin set to output mode
	DrvGPIO_Open(E_GPA, 14, E_IO_OUTPUT); // GPA14 pin set to output mode

	// set GPIO pins output Hi to disable LEDs
	DrvGPIO_SetBit(E_GPA, 12); // GPA12 pin output Hi to turn off Blue  LED
	DrvGPIO_SetBit(E_GPA, 13); // GPA13 pin output Hi to turn off Green LED
	DrvGPIO_SetBit(E_GPA, 14); // GPA14 pin output Hi to turn off Red   LED
}

void RGBLED(uint8_t LEDcolor)
{
	switch(LEDcolor) {
		case BLUE:  DrvGPIO_ClrBit(E_GPA,12); // Blue LED on
		            DrvGPIO_SetBit(E_GPA,13);
		            DrvGPIO_SetBit(E_GPA,14);
		            break;
		case GREEN: DrvGPIO_SetBit(E_GPA,12);
		            DrvGPIO_ClrBit(E_GPA,13); // Green LED on
		            DrvGPIO_SetBit(E_GPA,14);
		            break;
		case RED:   DrvGPIO_SetBit(E_GPA,12);
		            DrvGPIO_SetBit(E_GPA,13);
		            DrvGPIO_ClrBit(E_GPA,14); // Red   LED on
		            break;
		default:    DrvGPIO_SetBit(E_GPA,12);
		            DrvGPIO_SetBit(E_GPA,13);
		            DrvGPIO_SetBit(E_GPA,14);
                break;
  }
	DrvSYS_Delay(100000 * LEDcolor);
	DrvGPIO_SetBit(E_GPA,12);
	DrvGPIO_SetBit(E_GPA,13);
	DrvGPIO_SetBit(E_GPA,14);
}

// Function: input the number of buzz
void Buzz(int number)
{
	int i;
	for (i=0; i<number; i++) {
	  DrvGPIO_ClrBit(E_GPB,11); // GPB11 = 0 to turn on Buzzer
	  DrvSYS_Delay(100000);	 // Delay
	  DrvGPIO_SetBit(E_GPB,11); // GPB11 = 1 to turn off Buzzer
	  DrvSYS_Delay(100000);	 // Delay
	}
}


int main(void)
{
	uint8_t i=0;
	uint8_t number=0;
	uint8_t number1=0;

	init_RGBLED();                               // initial RGB LEDs

	UNLOCKREG();                                 // Unlock the protected registers
	DrvSYS_SetOscCtrl(E_SYS_XTL12M, 1);          // Enable 12MHz oscillator
	DrvSYS_Delay(5000);                          // delay for stable clock
	DrvSYS_SelectHCLKSource(0);	                 // HCLK clock source. 0: external 12MHz;
	LOCKREG();                                   // Lock the protected registers

	DrvGPIO_Open(E_GPA, 4, E_IO_INPUT); 	//set GPA0 to input mode
	DrvGPIO_Open(E_GPB, 11, E_IO_OUTPUT); 	//initial GPIO pin GPB11 for controlling Buzzer

	DrvGPIO_Open(E_GPB, 15, E_IO_INPUT);

	Initial_pannel();
	clr_all_pannal();


	OpenKeyPad();
	print_lcd(0, TEXT0);
	print_lcd(1, TEXT1);

	i=0;

	while(1)
	{
		number=Scankey();
		if (number!=0) {
		DrvSYS_Delay(1000000);
		keycode[i] = 0x30+number;
		sprintf(TEXT1+9+i,"%d",number);
		print_lcd(1,TEXT1);
		i++;
		//RGBLED(BLUE);

			if(i==6){

				if(strcmp(keycode,passcode)==0) {
					RGBLED(GREEN);
					sprintf(TEXT2,"PassCode:True");
					print_lcd(2,TEXT2);
					DrvSYS_Delay(250000);
					clr_all_pannal();

					print_lcd(0, "== Press Button ==");
					DrvSYS_Delay(250000);
					print_lcd(1,"1. Turn On Buzzer");
					DrvSYS_Delay(250000);
					print_lcd(2,"2. Green LED");
					DrvSYS_Delay(250000);
					print_lcd(3,"3. Blue LED");

					number1 =Scankey();
					if (number1 !=0) {
						if(number1==1) { Buzz(1);
							} else if(number1==2) { RGBLED(GREEN);
							} else if(number1==3) { RGBLED(BLUE);
						}
					}


				} else {
					RGBLED(RED);
					Buzz(1);
					printf(TEXT2,"PassCode: Wrong");
					print_lcd(2,TEXT2);
				}
			}

		}

	}
}

Seems to be that once you enter a password, you want to enter a while loop. Now, after you enter a password, Scankey() is called. If there is no key being pressed, the infinite loop repeats, and you need to enter a password again.

Quit trying to do everything in main(). Learn to write functions.

PaulS:
Seems to be that once you enter a password, you want to enter a while loop. Now, after you enter a password, Scankey() is called. If there is no key being pressed, the infinite loop repeats, and you need to enter a password again.

Quit trying to do everything in main(). Learn to write functions.

hello Pauls, i dont get what u mean. So what should in this case? Quit trying to do everything in main(). Learn to write functions?