Пример #1
0
int main(int argc, const char *argv[])
{
    int i;
    int c;
    initrand();
    int nServer = NUM_SERVERS;
    int nClient = NUM_CLIENTS;
    printf("\nBegin client-server message passing test program\n");
    printf("Implemented as Strategy 2: 1 mutex, 1 producer sem and 1 consumer sem per port\n");
    printf("Servers perform addition on two integers sent by clients and pass back the result\n");
    printf("Spawning %d servers listening on ports 0 to %d\n", nServer, nServer-1);
    printf("Spawning %d clients with receive ports %d to %d\n\n", nClient, nServer, nServer+nClient-1);
    printf("Press 'Enter' to continue:\n");
    c=getchar();

    InitQ(&RunQ);
    // Declare a set (array of ports). The ports are numbered 0 to 99.
    for(i = 0; i < NUM_PORTS; ++i)
        PortInit(&ports[i], PORT_DEPTH);
    
    // start multiple clients
    for(i = NUM_SERVERS; i < (NUM_SERVERS+NUM_CLIENTS) ; ++i)
        start_thread(client);

    // start 10 servers, listening on ports 0 to 9 (the "known" ports)
    for(i = 0; i < NUM_SERVERS; ++i)
        start_thread(server);
    

    run();
    return 0;
}
Пример #2
0
/*!
 * Init board.
 */
void BoardInit(void)
{
    /* Initialise ports. */
    PortInit();
    /* Initialise system clock. */
    SystemClkInit();
    /* Initialise SPI1. */
    Spi1Init();
    /* Initialise Timer0. */
    Timer0Init();
    /* Initialise Timer3. */
    Timer3Init();
    /* Initialise interrupts. */
    InterruptInit();
    /* Initialise the LCD. */
    LcdInit();
    /* Clear LCD. */
    LcdClearDisplay();
    /* Initialise LEDs. */
    LEDInit();
  #ifdef RTC_ENABLED
    /* RTC init. */
    RTC_Init();
  #endif //RTC_ENABLED
  #ifdef UART0_ENABLED
    /* UART0 init. */
    Uart0Init();
  #endif //UART0_ENABLED
}
Пример #3
0
int main(void) 
{
	//timer0_init(); // timer 0 initialize 
	SystemInit(); // system variables and state initialize
	timer1_init(); // timer 1 initialize
	PortInit(); // inputs and outputs initialize
	_delay_ms(500);
	start_Test();
	_delay_ms(5000);
	while(1)
	{
		if(is_high(PINB,PB0))
		{
			if(first_Pause == 0)
			{
				pause_Test();
				first_Pause++;
			}
		}
		else
		{
			first_Pause= 0;
			RI_Test_1();
		}
	}
}
Пример #4
0
/*-----------------------------------------------------------------------------
*  main
*/
int main(void) {

   uint8_t ret;
   int   sioHdl;

   /* set clock prescaler to 2 (set clock to 7.3928 MHz) */
   CLKPR = 1 << CLKPCE;
   CLKPR = 1;

   /* get module address from EEPROM */
   sMyAddr = eeprom_read_byte((const uint8_t *)MODUL_ADDRESS);
   GetClientListFromEeprom();
    
   PortInit();
   TimerInit();
   ButtonInit();
   PwmInit();
   ApplicationInit();

   SioInit();
   SioRandSeed(sMyAddr);

   /* sio for bus interface */
   sioHdl = SioOpen("USART1", eSioBaud9600, eSioDataBits8, eSioParityNo,
                    eSioStopBits1, eSioModeHalfDuplex);

   SioSetIdleFunc(sioHdl, IdleSio1);
   SioSetTransceiverPowerDownFunc(sioHdl, BusTransceiverPowerDown);
   BusTransceiverPowerDown(true);

   BusInit(sioHdl);
   spBusMsg = BusMsgBufGet();

   /* warten for full operation voltage */
   while (!POWER_GOOD);

   /* enable ints before RestorePwm() */
   ENABLE_INT;
   TimerStart();
   RestorePwm();

   /* ext int for power fail: INT0 low level sensitive */
   EICRA &= ~((1 << ISC01) | (1 << ISC00));
   EIMSK |= (1 << INT0);

   ApplicationStart();
   
   /* Hauptschleife */
   while (1) {
      Idle();
      ret = BusCheck();
      ProcessBus(ret);
      CheckButton();
      PwmCheck();
      ApplicationCheck();
      CheckEvent();
   }
   return 0;
}
Пример #5
0
void main()
{
   union {
      unsigned int32 hours;
      unsigned int8 minutes;
      unsigned int8 seconds;} upTime;
   
   
   TICK_TYPE CurrentTick,PreviousUDPTick,PreviousSATick;
   resetStatus = (RCON & 0b00111111) | !(STKPTR & 0b11000000); // Get the Reset Status
   RCON = RCON | 0b00111111; //Reset RCON Reset flags... (Reset Register)
   STKPTR = STKPTR & 0b00111111; // Clear Stack Overflow/Underflow flags
   PortInit(); 
   OutputInit();  
   restart_wdt();
   romEZHRInit();    //set up default ezhr settings
   eeROMinit();      //set up default eprom settings
   IPAddressInit();  //set up MAC and default IP addresses
   delay_ms(500); 
   ADCInit();        //set up ADC ports
   iniADCParams();    
   SerialInit();     //set up serial ports
   TickInit();       //set up tick timer
   enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);
   StackInit();   
   WritePHYReg(ERXFCON,EthernetRXfilterSetting); // Allow only uni & multi
   SetLEDConfig(E_LED_CONFIG);   // swap LED's 
   output_high(E_SW_PWR_DN);     // Power Ethernet Switch
   output_high(E_SW_RST);
   output_low(RS485_TXEN);
   output_high(RS485_RXDIS);
   output_high(RS232_F_OFF);
   output_high(RS232_F_ON);
   CurrentTick = PreviousUDPTick = get_ticks();
   UDPSampleRate = eeReadUDPRate() * TICKS_PER_MILLISECOND;
   portControlInit();
   while(TRUE)
   {
      CurrentTick = get_ticks();
      restart_wdt();
      StackTask();
      restart_wdt();
      MyTCPTask();//handles TCP connections
      restart_wdt();
      setIO();// checks voltage status and sets ports accordingly
//!      if(CurrentTick-PreviousUDPTick >= UDPSampleRate)
//!      {
//!         currentRoutine=UDPTASK;
//!         BOOL UDPDone = MyUDPTask();
//!         if(UDPDone) 
//!         {
//!            PreviousUDPTick=CurrentTick;
//!         }
//!      }
      StackApplications();
   }
}
Пример #6
0
//--------------------------------------------------------------------
int main(void)
{
	char data[16];
	int axe_value=5;
	
	SystemInit(); // system variables and state initialize
	PortInit(); // inputs and outputs initialize
	LIS302DL_init();				// initialize I2C LIS302DL XYZ accelerometer.
	//sei();						// Enable interrupts.

	Command_Display(Clear_Screen);	
	Command_Display(Go_Home);
	itoa(axe_value, data, 10);		//Convert the X value integer into string.
	UWriteString(data);					//Print X value number on LCD.
	Set_Cursor_Position(1,2);
	UWriteString(uTeslas_String);	
	_delay_ms(5000);
    while(1)
    {	
	
		//-------------------------------------------------------------------
		// Read accelerometer and print X,Y,Z axis value on LCD.	
		//-------------------------------------------------------------------
		
		axe_value = LIS302DL_read(outX); //Read X axe value.
		Command_Display(Clear_Screen);	
		Command_Display(Go_Home);
		itoa(axe_value, data, 10);		//Convert the X value integer into string.
		UWriteString(data);					//Print X value number on LCD.  
		Set_Cursor_Position(1,2);
		UWriteString(uTeslas_String);
		
		/*	
		axe_value = LIS302DL_read(outY); //Read Y axe value.
		Command_Display(Clear_Screen);	
		Command_Display(Go_Home);
		itoa(axe_value, data, 10);
		UWriteString(data);
		placeEmptyCharacters(data,4);
		
		Set_Cursor_Position(1,2);
		UWriteString(uTeslas_String);
			
		axe_value = LIS302DL_read(outZ); //Read Z axe value.
		Command_Display(Clear_Screen);	
		Command_Display(Go_Home);
		itoa(axe_value , data, 10);
		UWriteString(data);
		placeEmptyCharacters(data,4);
		
		Set_Cursor_Position(1,2);
		UWriteString(uTeslas_String);
			*/
		_delay_ms(1000);	
    }
}
Пример #7
0
/*
  MainInit routine

  This routine performs the main initialisation.
*/
void MainInit(void)
{
  PortInit();
  Timer_Init();
  IIC_Init();
  UART_Init();
  sei();    // Enable global interrupts
  WM8960_Init();
  WM8960_Init();//again
}
Пример #8
0
/*-----------------------------------------------------------------------------
*  program start
*/
int main(void) {                      

    int     sioHandle;
    uint8_t windThreshold1;
    uint8_t windThreshold2;

    MCUSR = 0;
    wdt_disable();

    /* get module address from EEPROM */
    sMyAddr = eeprom_read_byte((const uint8_t *)MODUL_ADDRESS);
    windThreshold1 = eeprom_read_byte((const uint8_t *)WIND_THRESHOLD1);
    windThreshold2 = eeprom_read_byte((const uint8_t *)WIND_THRESHOLD2);
    GetClientListFromEeprom();

    PortInit();
    TimerInit();
    SioInit();
    sioHandle = SioOpen("USART0", eSioBaud9600, eSioDataBits8, eSioParityNo, 
                        eSioStopBits1, eSioModeHalfDuplex);
    SioSetIdleFunc(sioHandle, IdleSio);
    SioSetTransceiverPowerDownFunc(sioHandle, BusTransceiverPowerDown);

    BusTransceiverPowerDown(true);
   
    BusInit(sioHandle);
    spRxBusMsg = BusMsgBufGet();

    /* enable global interrupts */
    ENABLE_INT;  

    SendStartupMsg();

    /* wait for controller startup delay for sending first state telegram */
    DELAY_S(STARTUP_DELAY);

    while (1) { 
        Idle();
        ProcessSwitch();
        ProcessBus();
      
        if (sWind >= windThreshold1) {
            sWindSwitch |= 0x01;
        } else {
            sWindSwitch &= ~0x01;    
        }
        if (sWind >= windThreshold2) {
            sWindSwitch |= 0x02;
        } else {
            sWindSwitch &= ~0x02;    
        }    
    }
    return 0;  /* never reached */
}
Пример #9
0
/*************************************************
  Function:		HarewareInit
  Description:  
  Input:		
  Output:		
  Return:		
  Others:
*************************************************/
void HarewareInit(void)
{
    SetPowerChange(1);
	EA = 0;
	PortInit();
	UartInit();
	TimerInit();
	LCDInit();
    KeyBoardInit();
    DS1302Init();
	EA = 1;
}
Пример #10
0
/*
 *==============================================================================================
 * 函数名称:TargetInit
 * 功能描述:初始化目标板,完成以下功能:
 *           1. 时钟初始化
 *           2. mmu初始化
 *           3. 串口初始化
 *           4. 串口初始化
 * 传    参:void
 * 返 回 值:void
 *==============================================================================================
 */
 void
 TargetInit( void )
 {
 	U32		i;
 	U8		key;
 	U32		mpllVal = 0;
 	
 	i		= 2;						/* 使用400MHz主频                                      */
 	switch ( i )
 	{
 		case 0:							/* 200MHz */
 			key = 12;
 			mpllVal = (92 << 12) | (4 << 4) | (1);
 			break;
 			
 		case 1:							/* 300MHz */
 			key = 14;
 			mpllVal = (67 << 12) | (1 << 4) | (1);
 			break;
 			
 		case 2:							/* 400MHz */
 			key = 14;
 			mpllVal = (92 << 12) | (1 << 4) | (1);
 			break;
 			
 		case 3:							/* 440MHz */
 			key = 14;
 			mpllVal = (102 << 12) | (1 << 4) | (1);
 			break;
 			
 		default:						/* 默认使用400MHz */
 			key = 14;
 			mpllVal = (92 << 12) | (1 << 4) | (1);
 			break;
 	}
 	
 	ChangeMPLLValue( (mpllVal >> 12) & 0xff, (mpllVal >> 4) & 0x3f, mpllVal & 3 );	/* 时钟初始化 */
 	ChangeClockDivider( key, 12 );
 	
 	MMUDisableICache( );				
 	MMUDisableDCache( );
 	MMUInit( );							/* MMU初始化                                           */
 	
 	PortInit( );						/* 端口初始化                                          */
 	
 	UartSelect( 0 );					/* 串口选择                                            */
 	UartInit( 0, 115200 );				/* 串口初始化                                          */
 }
Пример #11
0
void MasterInitialize()//called on startup, will call the port setup etc. as well as find the appropriate setting for the pot
{
	cli();//disable interrupts
	
	ADCInit();
	
	PortInit();//these init values (clock and port) are taken directly from our old code
	
	ClockInit();
	
	SerialInit();
		
	sei();//enable interrupts
	
	return;
}
Пример #12
0
/*-----------------------------------------------------------------------------
*  program start
*/
int main(void) {                      

   MCUSR = 0;
   wdt_disable();

   /* get module address from EEPROM */
   sMyAddr = eeprom_read_byte((const uint8_t *)MODUL_ADDRESS);

   PortInit();
   TimerInit();

   InitComm();

   /* enable global interrupts */
   ENABLE_INT;  

   SendStartupMsg();

   while (1) { 
      Idle();
      ProcessBus();
   }
   return 0;  /* never reached */
}
Пример #13
0
/*-----------------------------------------------------------------------------
*  program start
*/
int main(void) {                      

    int     sioHandle;
    uint8_t i;
    uint8_t u8;

    MCUSR = 0;
    wdt_disable();

    /* get module address from EEPROM */
    sMyAddr = eeprom_read_byte((const uint8_t *)MODUL_ADDRESS);
    for (i = 0; i < NUM_BUTTON_EVENT_ADDRESSES; i++) {
        sMySwitchAddr[i] = eeprom_read_byte((const uint8_t *)(BUTTON_EVENT_ADRESS_BASE + i));
    }
   
    PortInit();
    TimerInit();
    SioInit();
    SioRandSeed(MY_ADDR);
    sioHandle = SioOpen("USART0", eSioBaud9600, eSioDataBits8, eSioParityNo, 
                        eSioStopBits1, eSioModeHalfDuplex);
    SioSetIdleFunc(sioHandle, IdleSio);
    SioSetTransceiverPowerDownFunc(sioHandle, BusTransceiverPowerDown);

    BusTransceiverPowerDown(true);
   
    BusInit(sioHandle);
    spRxBusMsg = BusMsgBufGet();

    /* enable global interrupts */
    ENABLE_INT;  
    i2c_slave(SLAVE_ADRESSE);

    button_register = 0;

    init_BJ(SLAVE_ADRESSE);

    for (i = 0; i < NR_OF_LEDS; i++) {
        u8 = eeprom_read_byte((const uint8_t *)(COLOR_LED_BASE + i));
        set_LED(i, u8);
        sNewLedData[i / 2] |= (u8 & 0x0f) << ((i % 2) ? 4 : 0);
    }

    i2c_slave(SLAVE_ADRESSE);

    SendStartupMsg();
   
    while (1) { 
        Idle();
        if (send_startup == 1) {
            init_BJ(SLAVE_ADRESSE);
            for (i = 0; i < NR_OF_LEDS; i++) {
                set_LED(i, eeprom_read_byte((const uint8_t *)(COLOR_LED_BASE + i)));
            }
        }
        sInputState = button_register; 
        ProcessButton(sInputState);

        ProcessBus();

        for (i = 0; i < BUS_SW16_LED_SIZE_SET_VALUE; i++) {
            if ((sNewLedData[i] & 0x0f) != (sLedData[i] & 0x0f) ) { // linke LED
                set_LED(i * 2, sNewLedData[i] & 0x0f);
                i2c_slave(SLAVE_ADRESSE);
            }
            if ((sNewLedData[i] & 0xf0) != (sLedData[i] & 0xf0) ) { // rechte LED
                set_LED(i * 2 + 1, (sNewLedData[i] & 0xf0) >> 4);
                i2c_slave(SLAVE_ADRESSE);
            }
            sLedData[i] = sNewLedData[i];
        }
    }
Пример #14
0
int main(void)
{
	
    /* Configure Oscillator to operate the device at 30Mhz
       Fosc= Fin*M/(N1*N2), Fcy=Fosc/2
       Fosc= 7.37*(32)/(2*2)=58.96Mhz for Fosc, Fcy = 29.48Mhz */

    /* Configure PLL prescaler, PLL postscaler, PLL divisor */
    //PLLFBDbits.PLLDIV=38;   /* M = PLLFBD + 2 */ // izlazna frekvencija = 30Mhz
    //Fin=8MHz, Fcy=30MHz 
	// Configure PLL prescaler, PLL postscaler, PLL divisor
	PLLFBD = 28; 				// M=40    ---> PLLFBD + 2 = M
	CLKDIVbits.PLLPOST = 0; 	// N2=2    ---> 2x(PLLPOST + 2) = N2
	CLKDIVbits.PLLPRE = 0; 	// N1=2    ---> PLLPRE + 2 = N1

	//new oscillator selection
	__builtin_write_OSCCONH(0b011);  				//0b011 ---> XT with PLL
	//enable oscillator source switch
	__builtin_write_OSCCONL (OSCCONL | (1<<0)); 	//OSWEN 

	//wait for PLL lock -> wait to new settings become available
	while (OSCCONbits.COSC != 0b011); 
	//wait for PLL lock
	while (OSCCONbits.LOCK != 0b1); 
    
    AD1PCFGL = 0xFFFF;// all PORT Digital

   
    RPINR18bits.U1RXR = 0;		//UART1 RX na RP0- pin 4
    RPOR0bits.RP1R = 3;			//UART1 TX na RP1- pin 5
    RPINR14bits.QEA1R = 2;		//QEI1A na RP2
    RPINR14bits.QEB1R = 3;		//QEI1B na RP3

    RPINR16bits.QEA2R = 4;		//QEI2A na RP4
    RPINR16bits.QEB2R = 7;		//QEI2B na RP7
    
    CAN_init(DRIVER_IDENTIFICATOR); // inicijalizacija CAN BUS- a-> argument je adresa drajvera

    int tmp;
    char komanda, v, smer;
    int Xc, Yc, ugao;
    
    NewLine();

    PortInit();
    //UARTinit();
    TimerInit();
    QEIinit();
    PWMinit();
   // CloseMCPWM();

    resetDriver();

    setSpeed(0x80);
    setSpeedAccel(K2);	//K2 je za 1m/s /bilo je 2
    int tmpX, tmpY, tmpO;
    unsigned char rxBuffer[8];
    while(1)
    {

        __delay_ms(1000);
        setSpeed(30);
       // kretanje_pravo(-1000, 0);
        if(getStatus() == STATUS_MOVING)
            CAN_getLastMessage(rxBuffer);
        else
            CAN_read(rxBuffer);

        komanda = rxBuffer[0];

        switch(komanda)
        {
            // zadavanje pozicije
            case 'I':
                tmpX = rxBuffer[1] << 8;
                tmpX |= rxBuffer[2];

                tmpY = rxBuffer[3] << 8;
                tmpY |= rxBuffer[4];

                tmpO = rxBuffer[5] << 8;
                tmpO |= rxBuffer[6];

                setPosition(tmpX, tmpY, tmpO);

                break;

            // citanje pozicije i statusa
            case 'P':
                sendStatusAndPosition();

                break;

            //zadavanje max. brzine (default K2/2)
            case 'V':
                tmp = rxBuffer[1];
                setSpeed(tmp);

                break;

            //kretanje pravo [mm]
            case 'D':
                tmp = rxBuffer[1] << 8;
                tmp |= rxBuffer[2];
                v = rxBuffer[3];

                PWMinit();
                kretanje_pravo(tmp, v);

                break;

            //relativni ugao [stepen]
            case 'T':
                tmp = rxBuffer[1] << 8;
                tmp |= rxBuffer[2];

                PWMinit();
                okret(tmp);

                break;

            //apsolutni ugao [stepen]
            case 'A':
                tmp = rxBuffer[1] << 8;
                tmp |= rxBuffer[2];

                PWMinit();
                apsolutni_ugao(tmp);

                break;

            //idi u tacku (Xc, Yc) [mm]
            case 'G':
                tmpX = rxBuffer[1] << 8;
                tmpX |= rxBuffer[2];
                tmpY = rxBuffer[3] << 8;
                tmpY |= rxBuffer[4];
                v = rxBuffer[5];
                smer = rxBuffer[6];

                PWMinit();
                gotoXY(tmpX, tmpY, v, smer);

                break;

            //kurva
            case 'Q':
                tmpX = rxBuffer[1] << 8;
                tmpX |= rxBuffer[2];
                tmpY = rxBuffer[3] << 8;
                tmpY |= rxBuffer[4];
                tmpO = rxBuffer[5] << 8;
                tmpO |= rxBuffer[6];
                smer = rxBuffer[7];

                PWMinit();
                kurva(tmpX, tmpY, tmpO, smer);

                break;

             //ukopaj se u mestu
            case 'S':
                stop();

                break;

            //stani i ugasi PWM
            case 's':
                stop();
                CloseMCPWM();

                break;

            case 'R':
                resetDriver();

                break;

            default:
                forceStatus(STATUS_ERROR);
                break;
        }
    }

    return 0;
}
Пример #15
0
/*-----------------------------------------------------------------------------
*  program start
*/
int main(void) {                      

   int     sioHandle;
   uint8_t inputState;

   MCUSR = 0;
   wdt_disable();

   /* get module address from EEPROM */
   sMyAddr = eeprom_read_byte((const uint8_t *)MODUL_ADDRESS);

   sInputType = eeprom_read_byte((const uint8_t *)INPUT_TYPE);
   if (sInputType > INPUT_TYPE_MOTION_DETECTOR) {
      sInputType = INPUT_TYPE_DUAL_BUTTON;
   }
   PortInit();
   TimerInit();
   SioInit();
   SioRandSeed(sMyAddr);
   sioHandle = SioOpen("USART0", eSioBaud9600, eSioDataBits8, eSioParityNo, 
                       eSioStopBits1, eSioModeHalfDuplex);
   SioSetIdleFunc(sioHandle, IdleSio);
   SioSetTransceiverPowerDownFunc(sioHandle, BusTransceiverPowerDown);

   BusTransceiverPowerDown(true);
   
   BusInit(sioHandle);
   spRxBusMsg = BusMsgBufGet();

   /* enable global interrupts */
   ENABLE_INT;  

   SendStartupMsg();
   
   if ((sInputType == INPUT_TYPE_DUAL_SWITCH) ||
       (sInputType == INPUT_TYPE_MOTION_DETECTOR)) {
      /* wait for controller startup delay for sending first state telegram */
      DELAY_S(STARTUP_DELAY);
   }

   if ((sInputType == INPUT_TYPE_DUAL_SWITCH) ||
       (sInputType == INPUT_TYPE_MOTION_DETECTOR)) {
      inputState = GetInputState();
      sSwitchStateOld = ~inputState;
      ProcessSwitch(inputState);
   }

   while (1) { 
      Idle();
   
      inputState = GetInputState(); 
      if ((sInputType == INPUT_TYPE_DUAL_SWITCH) ||
          (sInputType == INPUT_TYPE_MOTION_DETECTOR)) {
         ProcessSwitch(inputState);
      } else if (sInputType == INPUT_TYPE_DUAL_BUTTON) {
         ProcessButton(inputState);
      }

      ProcessBus();
   }
   return 0;  /* never reached */
}
int main(void) 
{
	
	Simple_Clk_Init();
	Power_Clk_Init();
	PortInit();
	UartInit();
	
	write("Hello World\r\n"); // Test the serial connection on startup
	
	//char array[i]; // declare a char array
	//char array[4] = {'1','8','9','7'}; 
	//write (array);
	
	Port *ports = PORT_INSTS; // Use port registers
	
	PortGroup *portAs = &(ports->Group[0]); //introduce port groups A
	PortGroup *portBs = &(ports->Group[1]); //introduce port groups B
	
	//set a direction; SET = output, CLR = input
	portAs ->DIRCLR.reg = PORT_PA16|PORT_PA17|PORT_PA18|PORT_PA19;	 // inputs
	portAs ->DIRSET.reg = PORT_PA04|PORT_PA05|PORT_PA06|PORT_PA07;   // outputs
	
	portBs->DIRSET.reg = PORT_PB00|PORT_PB01|PORT_PB02|PORT_PB03|PORT_PB04|PORT_PB05|PORT_PB06|PORT_PB07; //outputs
	
	//setting pull up and pull down resistors
	portAs ->PINCFG[16].reg = PORT_PINCFG_INEN|PORT_PINCFG_PULLEN;
	portAs ->PINCFG[17].reg = PORT_PINCFG_INEN|PORT_PINCFG_PULLEN;
	portAs ->PINCFG[18].reg = PORT_PINCFG_INEN|PORT_PINCFG_PULLEN;
	portAs ->PINCFG[19].reg = PORT_PINCFG_INEN|PORT_PINCFG_PULLEN;

	

	while(1)
	{
		    receive();
		
			portAs -> OUTSET.reg = PORT_PA04|PORT_PA05| PORT_PA06|PORT_PA07;
			switch (v)
			{
				case 0:
				ledDisplay(array[v]);
				portAs -> OUTCLR.reg = PORT_PA07;
				if (portAs ->IN.reg & PORT_PA19)
				{
					//character 1
					array[i] = '1';
					i++;
					while (portAs ->IN.reg & PORT_PA19);		
				}
				else if (portAs ->IN.reg & PORT_PA18)
				{
					array[i] = '2';
					i++;

					while (portAs ->IN.reg & PORT_PA18);
				}
				else if (portAs ->IN.reg & PORT_PA17)
				{
					array[i] = '3';
					i++;
					while (portAs ->IN.reg & PORT_PA17);
				}
				
				break;
				
				
				case 1:
				ledDisplay(array[v]);
				portAs -> OUTCLR.reg = PORT_PA06;
				if (portAs ->IN.reg & PORT_PA19)
				{
					// character 4
					array[i] = '4';
					i++;
					while (portAs ->IN.reg & PORT_PA19);

				}
				else if (portAs ->IN.reg & PORT_PA18)
				{
					array[i] = '5';
					i++;
					while (portAs ->IN.reg & PORT_PA18);
				}
				else if (portAs ->IN.reg & PORT_PA17)
				{
					array[i] = '6';
					i++;
					while (portAs ->IN.reg & PORT_PA17);
				}
				
				break;
				
				
				case 2:
				ledDisplay(array[v]);
				portAs -> OUTCLR.reg = PORT_PA05;
				if (portAs ->IN.reg & PORT_PA19)
				{
					// Number 7
					array[i] = '7';
					i++;
					while (portAs ->IN.reg & PORT_PA19);

				}
				else if (portAs ->IN.reg & PORT_PA18)
				{
					array[i] = '8';
					i++;
					
					while (portAs ->IN.reg & PORT_PA18);
					
				}
				else if (portAs ->IN.reg & PORT_PA17)
				{
					array[i] = '9';
					i++;
					while (portAs ->IN.reg & PORT_PA17);
				}
			
				break;
				
				
				
				case 3:
				ledDisplay(array[v]);
				portAs -> OUTCLR.reg = PORT_PA04;
				if (portAs ->IN.reg & PORT_PA18)
				{
					array[i] = '0';
					i++;
					while (portAs ->IN.reg & PORT_PA18);
				}
				else if (portAs ->IN.reg & PORT_PA16)
				{
					//D
					write(array);
					i = 0;
					while (portAs ->IN.reg & PORT_PA16);
				}
				
				break;
				
			}

			v++;	
			
			if (v == 4)
			{
				v = 0;
			}			
		
			if (i == 4)
			{ i = 0;}	
	}
	
}