Example #1
0
void LCD_PowerUp() {

    //Turn on the back light
    LCD_BL = 1;

    //Pause 60ms
    Wait_ms(60);

    //8-Bit, 2 Line, 5x7 Dots
    LCD_FunctionSet(1, 1, 1);

    //Display ON, Cursor OFF, Blink OFF
    LCD_DisplayOnOff(1, 0, 0);

    //Clear the Display
    LCD_ClearDisplay();

    //Pause 60ms
    Wait_ms(60);

    //8-Bit, 2 Line, 5x7 Dots
    LCD_FunctionSet(1, 1, 1);

    //Display ON, Cursor OFF, Blink OFF
    LCD_DisplayOnOff(1, 0, 0);

    //Clear the Display
    LCD_ClearDisplay();

}
Example #2
0
unsigned char ISD_Out(unsigned char DATA)
{
    unsigned char RESULT;
    unsigned char i;
    RA2=1;
    RESULT=0;
    for(i=0;i<8; i++)
    {
        if(DATA&1)
         {
            RA3=1;
         }
       else
         {
            RA3=0;
         }
        RA2=0;
        Wait_ms(1);
        RA2=1;
        Wait_ms(1);
  
        RESULT=RESULT>>1;
        if(RA4)
        {
          RESULT=RESULT+0X80;
        }
        DATA=DATA>>1;
    }
 return(RESULT);
}
Example #3
0
void Note3_4th(unsigned char NOTE)
{
	PR2 = NOTE;
	TMR2ON = 1;
	Wait_ms(2700);
	TMR2ON = 0;
	Wait_ms(300);
}
Example #4
0
void Note1_4th(unsigned char NOTE)
{
	PR2 = NOTE;
	TMR2ON = 1;
	Wait_ms(900);
	TMR2ON = 0;
	Wait_ms(100);
}
Example #5
0
void Note3_8th(unsigned char NOTE)
{
	PR2 = NOTE;
	TMR2ON = 1;
	Wait_ms(1350);
	TMR2ON = 0;
	Wait_ms(150);
}
Example #6
0
void Note5_8th(unsigned char NOTE)
{
	PR2 = NOTE;
	TMR2ON = 1;
	Wait_ms(2250);
	TMR2ON = 0;
	Wait_ms(250);
}
Example #7
0
void WholeNote(unsigned char NOTE)
{
	PR2 = NOTE;
	TMR2ON = 1;
	Wait_ms(3600);
	TMR2ON = 0;
	Wait_ms(400);
}
Example #8
0
void HalfNote(unsigned char NOTE)
{
	PR2 = NOTE;
	TMR2ON = 1;
	Wait_ms(1800);
	TMR2ON = 0;
	Wait_ms(200);
}
Example #9
0
void Note3_32nd(unsigned char NOTE)
{
	PR2 = NOTE;
	TMR2ON = 1;
	Wait_ms(112);
	TMR2ON = 0;
	Wait_ms(12);
}
Example #10
0
void Note1_16th(unsigned char NOTE)
{
	PR2 = NOTE;
	TMR2ON = 1;
	Wait_ms(225);
	TMR2ON = 0;
	Wait_ms(25);
}
Example #11
0
void Note1_8th(unsigned char NOTE)
{
	PR2 = NOTE;
	TMR2ON = 1;
	Wait_ms(450);
	TMR2ON = 0;
	Wait_ms(50);
}
Example #12
0
void M_Write_0(unsigned long int Address, unsigned int Data)
{
    RC6 = 1;
    Wait_ms(5);
    RC6 = 0; 
    M_Write_Enable();  
    RC6 = 1;
    Wait_ms(5);  
    RC6 = 0; 
    M_Write_Address(Address); 
    M_Write_Data(Data>>8);
    M_Write_Data(Data);
    RC6 = 1;
    }
Example #13
0
void LCD_Inst(unsigned char c)
{
    RB2 = 0;        // send an instruction
	PORTB = (PORTB & 0x0F) |  (c & 0xF0);
	LCD_Strobe();
	PORTB = (PORTB & 0x0F) |  ((c<<4) & 0xF0);
	LCD_Strobe();
	Wait_ms(100);
}
void* Reap_CPU_V1(void* param)
{
	Reap_CPU_param* state = (Reap_CPU_param*)param;

	Work tempwork;
	tempwork.time = 13371337;

	uint8_t tempdata[512];
	memset(tempdata, 0, 512);

	uint8_t finalhash[32];
	uint8_t hash_results[1] = {};

	uint32_t current_server_id;

	while(!shutdown_now)
	{
		if (current_work.old)
		{
			Wait_ms(20);
			continue;
		}
		if (tempwork.time != current_work.time)
		{
			pthread_mutex_lock(&current_work_mutex);
			tempwork = current_work;
			pthread_mutex_unlock(&current_work_mutex);
			memcpy(tempdata, &tempwork.data[0], 128);
			*(uint32_t*)&tempdata[100] = state->thread_id;
			current_server_id = tempwork.server_id;
		}

		*(uint64_t*)&tempdata[76] = tempwork.ntime_at_getwork + (ticker()-tempwork.time)/1000;

		for(uint32_t h=0; h<CPU_BATCH_SIZE; ++h)
		{
			BlockHash_1_mine_V1(tempdata, finalhash, hash_results);
			if (hash_results[0])
			{
				BlockHash_1(tempdata, finalhash);
				if (finalhash[30] != 0 || finalhash[31] != 0)
					cpu_shares_hwinvalid++;
				else
					cpu_shares_hwvalid++;
				if (CPU_Hash_Below_Target(finalhash, &tempwork.target_share[0]))
					CPU_Got_share(state,tempdata,tempwork.target_share,current_server_id);
			}
			++*(uint32_t*)&tempdata[108];
		}
		state->hashes += CPU_BATCH_SIZE;
	}
	pthread_exit(NULL);
	return NULL;
}
Example #15
0
void Set_Play(unsigned char m, unsigned char n )
{
 TMR3ON = 0;
 TMR3IE = 0;

 RA0=1;
 RA2=1;
 RA3=0;

 RA0=0;

 ISD_Out(0x01);
 ISD_Out(0x00);
 
 RA0=1;
 RA2=1;
 RA3=0;
 
 RA0=0;
 ISD_Out(0x04);
 ISD_Out(0x00);

 RA0=1; 
 RA2=1;
 RA3=0;
 
 RA0=0; 
 ISD_Out(0x80);
 ISD_Out(0x00);

 ISD_Out(m);
 ISD_Out(0x00);

 ISD_Out(n);
 ISD_Out(0x00);
 ISD_Out(0x00);
 Wait_ms(100);

 RA0=1;
 RA2=1;
 RA3=0;
 
 RA0=0; 
 ISD_Out(0x07);
 ISD_Out(0x00);
 RA0=1; 

 TMR3ON = 1;
 TMR3IE = 1;

}
void* Reap_CPU_XPM_hp7(void* param)
{

	Reap_CPU_param* state = (Reap_CPU_param*)param;

	Work tempwork;
	tempwork.time = 13371337;

	//uchar tempdata[80];
	//memset(tempdata, 0, 80);

	uchar finalhash[32];
	uchar temphash[32];
	uchar hash_results[1] = {};

	uint current_server_id;
	
	uint starttime = ticker();
	uint currenttime = starttime;
	
	uint foundprimes=0;

	while(!shutdown_now)
	{
		if (current_work.old)
		{
			Wait_ms(20);
			continue;
		}
		if (tempwork.time != current_work.time)
		{
			pthread_mutex_lock(&current_work_mutex);
			tempwork = current_work;
			pthread_mutex_unlock(&current_work_mutex);

			*(uint*)&tempwork.data[76] = state->thread_id<<28;
			current_server_id = tempwork.server_id;
		}

		bool result = MinePrime_hp(state,tempwork);
		if (result) 
		{
			pthread_mutex_lock(&current_work_mutex);
			current_work.old = true;
			pthread_mutex_unlock(&current_work_mutex);
		}
		++*(uint*)&tempwork.data[76];
	}
	pthread_exit(NULL);
	return NULL;
}
Example #17
0
void main(void)
{
    //variables
    unsigned char i;

    //inputs and outputs
    TRISA = 0;
    TRISB = 0;
    TRISC = 0;
    TRISD = 0;
    TRISE = 0;
    ADCON1 = 0x0F;
    
    LCD_Init();

    LCD_Move(0,0);  for (i=0; i<20; i++) LCD_Write(MSG0[i]);
    Wait_ms(3000);
    LCD_Inst(1);

    // set up Timer0 for PS = 1
    T0CS = 0;
    T0CON = 0x88;
    TMR0ON = 1;
    TMR0IE = 1;
    TMR0IP = 1;
    PEIE = 1;
    
    // set up Timer1 for 1ms
    TMR1CS = 0;
    T1CON = 0x81;
    TMR1ON = 1;
    TMR1IE = 1;
    TMR1IP = 1;
    PEIE = 1;

    // set up Timer3 for 1ms
    TMR3CS = 0;
    T3CON = 0x81;
    TMR3ON = 1;
    TMR3IE = 1;
    TMR3IP = 1;
    PEIE = 1;

    //Turn on all interrupts
    GIE = 1;

    while(1){
        LCD_Move(1,0); LCD_Out(Timer0, 3);
    }
}
Example #18
0
void IR_Program(unsigned long int Address)
{
	TMR3IE = 0;
	TMR3ON = 0;
	IR_program_mode();
    RC6 = 1;
    Wait_ms(100);
    RC6 = 0;
    M_Write_Enable();
    RC6 = 1;
    RC6 = 0;
    for(i=0;i<120;i++){M_Write_0((Address+2*i),   IR_program[i]);}
	TMR3IE = 1;
	TMR3ON = 1;
}
Example #19
0
void Set_Play(unsigned char m, unsigned char n )
{


 RA0=1;
 RA2=1;
 RA3=0;

 RA0=0;

 ISD_Out(0x01);
 ISD_Out(0x00);
 
 RA0=1;
 RA2=1;
 RA3=0;
 
 RA0=0;
 ISD_Out(0x04);
 ISD_Out(0x00);

 RA0=1; 
 RA2=1;
 RA3=0;
 
 RA0=0; 
 ISD_Out(0x80);
 ISD_Out(0x00);

 ISD_Out(m);
 ISD_Out(0x00);

 ISD_Out(m);
 ISD_Out(0x00);
 ISD_Out(0x00);
 Wait_ms(100);

 RA0=1;
 RA2=1;
 RA3=0;
 
 RA0=0; 
 ISD_Out(0x07);
 ISD_Out(0x00);



}
void ShowConfiguration(void)
{
	char str [100];

	  Usart1Send((char *) "Configuration:\r\n");
#ifdef CONFIGURATION_IN_SST
	  LoadFilesIndex();

	  sprintf(str, "B1T: %d, B1R: %d\r\n", param_struct.b1t, param_struct.b1r);
	  Usart1Send(str);
	  Wait_ms(100);

	  sprintf(str, "B2T: %d, B2R: %d\r\n", param_struct.b2t, param_struct.b2r);
	  Usart1Send(str);
	  Wait_ms(100);

	  sprintf(str, "B3T: %d, B3R: %d\r\n", param_struct.b3t, param_struct.b3r);
	  Usart1Send(str);
	  Wait_ms(100);

	  sprintf(str, "B4T: %d, B4R: %d\r\n", param_struct.b4t, param_struct.b4r);
	  Usart1Send(str);
	  Wait_ms(100);
#endif

#ifdef CONFIGURATION_IN_FLASH
	  sprintf(str, "B1T: %d, B1R: %d\r\n", b1t, b1r);
	  Usart1Send(str);
	  Wait_ms(100);

	  sprintf(str, "B2T: %d, B2R: %d\r\n", b2t, b2r);
	  Usart1Send(str);
	  Wait_ms(100);

	  sprintf(str, "B3T: %d, B3R: %d\r\n", b3t, b3r);
	  Usart1Send(str);
	  Wait_ms(100);

	  sprintf(str, "B4T: %d, B4R: %d\r\n", b4t, b4r);
	  Usart1Send(str);
	  Wait_ms(100);
#endif
}
Example #21
0
void main(void) {
    signed char ret = 0;
    signed char lastMenu = 0;
    char pnum = 0;

    SetupIO();
    MOTOR_FORWARD = 0;
    MOTOR_REVERSE = 0;

    Move_shifted_position.ul = 0;
    Move_position[0].ul = 0;
    Move_position[1].ul = 0;
    //PID_SetPoint = 0;
    char idx;
    for (idx = 0; idx < 16; idx++) RotaryDetentIntervals[idx] = 0xFF;

    LoadSettings();
    //FactoryDefault();

    SetupHardware();

    LCD_PowerUp();
    LCD_ClearDisplay();

    LCD_PrintString("CINEFLUX ORBIT\0");
    LCD_SetPosition(1, 0);
    LCD_PrintString(VER);
    Wait_ms(2000);

    const char *COMMAND_0 = "ORBIT MODE\0";
    const char *COMMAND_1 = "WAYPOINT MODE\0";
    const char *COMMAND_3 = "RUN PRESET\0";
    const char *COMMAND_2 = "REALTIME MODE\0";
    const char *COMMAND_4 = "BATTERY VOLTAGE\0";
    const char *COMMAND_5 = "GO TO SLEEP\0";
    const char *COMMAND_6 = "EXTERNAL CTRL MODE\0";
    const char*CommandMenu[7];
    CommandMenu[0] = COMMAND_0;
    CommandMenu[1] = COMMAND_1;
    CommandMenu[2] = COMMAND_2;
    CommandMenu[3] = COMMAND_3;
    CommandMenu[4] = COMMAND_4;
    CommandMenu[5] = COMMAND_5;
    CommandMenu[6] = COMMAND_6;

    bFollowMode = 1;
    LCD_ClearDisplay();
    LCD_PrintString("MOVE TO ZERO DEGREES\0");
    LCD_SetPosition(1, 0);
    LCD_PrintString("THEN CLICK...\0");
    GetClick();
    bClear_MotorPosition = 1;
    while (bClear_MotorPosition) Idle();
    Wait_ms(10);
    bFollowMode = 0;
    LCD_ClearDisplay();

    while (1) {
        UI_Location = UI_LOC_MAINMENU;
        ret = DisplayMenu(CommandMenu, 6, lastMenu);
labelProcessCommand:
        switch (ret) {
            case 0:
            case USER_INPUT_MACRO_ORBITMODE:
                lastMenu = 0;
                ret = CreateOrbitProgram();
                if (ret == -2) RealtimeMode();
                if (ret == -1) RealtimeMode();
                if (ret<-2) goto labelProcessCommand;
                break;
            case 1:
            case USER_INPUT_MACRO_WAYMODE:
                lastMenu = 1;
                ret = CreateWaypointProgram();
                if (ret<-2) goto labelProcessCommand;
                if (ret < 0) {
                    ret = RealtimeMode();
                    if (ret<-2) goto labelProcessCommand;
                }
                break;
            case 3:
                lastMenu = 3;
                ret = GetPresetNumber();
                if (ret == -1) break;
                if (ret == -2) break;
                if (ret<-2) goto labelProcessCommand;
                pnum = ret;
                ret = RunPreset(pnum);
                if (ret<-2) goto labelProcessCommand;
                break;
            case 2:
            case USER_INPUT_MACRO_REALMODE:
                lastMenu = 0;
                ret = RealtimeMode();
                if (ret<-2) goto labelProcessCommand;
                break;
            case 4:
                lastMenu = 0;
                ret = ShowVoltage();
                if (ret<-2) goto labelProcessCommand;
                break;
            case 5:
            case USER_INPUT_MACRO_SLEEP:
                lastMenu = 0;
                GoToSleep();
                break;
            case 6:
            case USER_INPUT_MACRO_EXTMODE:
                lastMenu = 0;
                ret = ExtMode();
                if (ret<-2) goto labelProcessCommand;
                break;
            case USER_INPUT_MACRO_RUNPRESET0:
                ret = RunPreset(1);
                if (ret<-2) goto labelProcessCommand;
                break;
            case USER_INPUT_MACRO_RUNPRESET1:
                ret = RunPreset(2);
                if (ret<-2) goto labelProcessCommand;
                break;
            case USER_INPUT_MACRO_RUNPRESET2:
                ret = RunPreset(3);
                if (ret<-2) goto labelProcessCommand;
                break;
            case USER_INPUT_MACRO_RUNPRESET3:
                ret = RunPreset(4);
                if (ret<-2) goto labelProcessCommand;
                break;
            case USER_INPUT_MACRO_RUNPRESET4:
                ret = RunPreset(5);
                if (ret<-2) goto labelProcessCommand;
                break;

        }
    }
}
Example #22
0
void __ISR(_CHANGE_NOTICE_VECTOR, ipl2) ChangeNotice_Handler(void)
{
        if(InTheMiddleOfSomething)
            return;
	BYTE bVal;
	bVal = PORTReadBits(IOPORT_B, BIT_0 | BIT_3);
        Led2;

        
        /******************A front wall is detected******************/
        // 
        if(!FrontSensor && LeftSensor)
        {
            InTheMiddleOfSomething = fTrue;
            Led1;
            Led2Clr;

            //Reverse the motor
            SetRightSpeed(dtcMtrStopped);
            RightReverse; //SetRightDir(prtMtrRightDirClr); //Reverse
            SetRightSpeed(dtcMtrMedium);
            //mCNClearIntFlag();

            //Wait until the turn is executed
            Wait_ms(TURN90);

            //Continue going straight
            SetRightSpeed(dtcMtrStopped);
            RightForward; //SetRightDir(prtMtrRightDirSet); //Forward
            SetRightSpeed(dtcMtrMedium);
            
            Led1Clr;
            InTheMiddleOfSomething = fFalse;
            mCNClearIntFlag();
            return;
        }

        if(LeftSensor)
        {
            InTheMiddleOfSomething = fTrue;
            Led4;
            Led2Clr;
            
            //Run for a few moments to get around the corner
            Wait_ms(TURN90/2);

            //Stop it until the turn is completed
            SetLeftSpeed(dtcMtrStopped);
            Wait_ms(TURN90);

            //Continue going straight and wait to mare sure it can detect the new wall
            SetLeftSpeed(dtcMtrMedium);
            Wait_ms(TURN90/4);

            Led4Clr;
            InTheMiddleOfSomething = fFalse;
        }
        
        /*
	if(LeftSensor && FrontSensor)
	{
            SetLeftSpeed(dtcMtrStopped);
            SetRightSpeed(dtcMtrStopped);
	}
	else
        {
            if(LeftSensor)	//Far left sensor -> hard left
            {
                SetLeftSpeed(dtcMtrMedium);
            }
            if(FrontSensor)	//Far right sensor -> hard right
            {
                SetRightSpeed(dtcMtrMedium);
            }
        }

	*/
	mCNClearIntFlag();
}
Example #23
0
//-----------------------------------------------------------------------------
// Command_Decode
//-----------------------------------------------------------------------------
//
// Return Value : Error code
// Parameters   : Pointer to input string
//
// Parses the command string and calls the appropriate functions.
//
//-----------------------------------------------------------------------------
uint8_t CommandDecode(char * instr)
{
	char * cp;						// character pointer
	const DEVICE_FAMILY *dfptr;		// pointer to current device family
	const DERIVATIVE_ENTRY *deptr;	// pointer to current derivative
	uint8_t command_number = 99;	// number of command encoded in 'instr'
	uint8_t result = INVALID_COMMAND;

	printf("Command: %s\n", instr);
	command_number = 0xFF;
	if (instr[0] >= '0' && instr[0] <= '9')
	{
		// if first char is a digit, then interpret it as a command number
		command_number = atoi (instr);
	}

	{
		// interpret command as a string and find command number
		// or find command by command_number
		const COMMAND *ctptr = Commands;
		while (ctptr->name != NULL)
		{
			if (command_number != 0xFF)
			{
				if (ctptr->number == command_number)
					break;
			}
			else if (strncmp (instr, ctptr->name, ctptr->name_size) == 0)
			{	// we've found the command, so record its number and exit
				command_number = ctptr->number;
				break;
			}
			ctptr++;
		}
		if (ctptr->name != NULL)
		{
			if (ctptr->need_discover && !FamilyFound)
			{
				result = DEVICE_UNDISCOVERED;
				command_number = 0xFE;	// Unknown command
			}
		}
		else
			command_number = 0xFF;	// Unknown command
	}

	// Now we have a command number, so act on it.
	switch (command_number)
	{
		case 0:	// Device Autodetect
		{
			uint8_t deviceId = 0xFF;		// initialize device and derivative
			uint8_t revisionId = 0xFF;
			uint8_t derivativeId = 0xFF;	// id's to invalid selections

			printf("Device Autodetect\n");
			Start_Stopwatch();
			if (NO_ERROR == (result = C2_Halt ())
			&&	NO_ERROR == (result = C2_Discover (&deviceId, &revisionId, &derivativeId))
				)
			{
				CommandsList = KnownFamilies[FamilyNumber].InitStrings;
			}
			Stop_Stopwatch();
			printf("Device ID     : %02X\n", deviceId);
			printf("Revision ID   : %02X\n", revisionId);
			printf("Derivative ID : %02X\n", derivativeId);
			break;
		}
		case 1:	// Print Menu
		{
			printf("? stub\n");
			Start_Stopwatch();
			Display_Menu();
			Stop_Stopwatch();
			result = NO_ERROR;
			break;
		}
		case 2:	// Wait ms
		{
			uint16_t wait_time;
			cp = GetNextWord(instr);
			if (NO_ERROR == (result = CheckEmpty(cp)))
			{
				wait_time = atoi (cp);
				printf("Waiting %d ms\n", wait_time);
				Start_Stopwatch();
				Wait_ms (wait_time);
				Stop_Stopwatch();
				printf("Stopwatch_ms is %u\n", Stopwatch_ms);
				result = NO_ERROR;
			}
			break;
		}
		case 3:	// Wait us
		{
			uint16_t wait_time;
			cp = GetNextWord(instr);
			if (NO_ERROR == (result = CheckEmpty(cp)))
			{
				wait_time = atoi (cp);

				printf("Waiting %d us\n", wait_time);
				Start_Stopwatch();
				Wait_us (wait_time);
				Stop_Stopwatch();
				printf("Stopwatch_us is %u\n", Stopwatch_us);

				result = NO_ERROR;
			}
			break;
		}
		case 4:	// Start Stopwatch
		{
			printf("Start Stopwatch\n");
			result = Start_Stopwatch();
			break;
		}
		case 5:	// Stop Stopwatch
		{
			printf("Stop Stopwatch\n");
			result = Stop_Stopwatch();
			printf("Stopwatch_ms is %u\n", Stopwatch_ms);
			printf("Stopwatch_us is %u\n", Stopwatch_us);
			break;
		}
		case 6:	// Set Timeout ms
		{
			uint16_t wait_time;
			printf("Set Timeout ms:\n");
			cp = GetNextWord(instr);
			if (NO_ERROR == (result = CheckEmpty(cp)))
			{
				wait_time = atoi (cp);

				printf("Timing out for %d ms\n", wait_time);
				Start_Stopwatch();
				SetTimeout_ms (wait_time);
				SetTimeout_us (1);
				while (!IsDoneTimeout_ms())
					;
				Stop_Stopwatch();
				printf("Stopwatch_ms is %u\n", Stopwatch_ms);
				result = NO_ERROR;
			}
			break;
		}
		case 7:	// Set Timeout us
		{
			uint16_t wait_time;
			printf("Set Timeout us\n");
			cp = GetNextWord(instr);
			if (NO_ERROR == (result = CheckEmpty(cp)))
			{
				wait_time = atoi(cp);

				printf("Timing out for %d us\n", wait_time);
				Start_Stopwatch();
				SetTimeout_us(wait_time);
				while (!IsDoneTimeout_us())
					;
				Stop_Stopwatch();
				printf("Stopwatch_us is %u\n", Stopwatch_us);

				result = NO_ERROR;
			}
			break;
		}
		case 8:		// Pin init
		{
			printf("Pin Init\n");
			result = Pin_Init();
			break;
		}
		case 9:		// C2 Reset
		{
			printf("C2 Reset\n");
			result = C2_Reset();
			break;
		}
		case 10:	// C2 Write Address
		{
			uint16_t addr;
			cp = GetNextWord(instr);
			if (NO_ERROR == (result = CheckEmpty(cp)))
			{
				addr = atox (cp);

				printf("C2 Write Address: %02X\n", addr);
				Start_Stopwatch();
				result = C2_WriteAR(addr);
				Stop_Stopwatch();
			}
			break;
		}
		case 11:	// C2 Read Address
		{
			Start_Stopwatch();
			result = C2_ReadAR();
			Stop_Stopwatch();
			printf("C2 Read Address: %02X\n", (uint16_t) C2_AR);
			break;
		}
		case 12:	// C2 Write Data
		{
			uint8_t data;
			cp = GetNextWord(instr);
			if (NO_ERROR == (result = CheckEmpty(cp)))
			{
				data = atox (cp);

				printf("C2 Write Data: %02X\n", (uint16_t) data);
				Start_Stopwatch ();
				result = C2_WriteDR (data, C2_WRITE_DR_TIMEOUT_US);
				Stop_Stopwatch ();
			}
			break;
		}
		case 13:	// C2 Read Data
		{
			Start_Stopwatch ();
			result = C2_ReadDR (C2_READ_DR_TIMEOUT_US);
			Stop_Stopwatch ();
			printf("C2 Read Data: %02X\n", (uint16_t) C2_DR);
			break;
		}
		case 14:	// C2 Reset and Halt
		{
			printf("C2 Reset and Halt\n");
			result = C2_Halt ();
			break;
		}
		case 15:	// C2 Get Device ID
		{
			uint8_t devId;

			printf("C2 Get Device ID\n");
			Start_Stopwatch ();
			result = C2_GetDevID (&devId);
			Stop_Stopwatch ();
			printf("Device ID is %u, 0x%04X\n", devId, devId);
			break;
		}
		case 16:	// C2 Get Revision ID
		{
			uint8_t revid;
			printf("C2 Get Revision ID\n");
			Start_Stopwatch ();
			result = C2_GetRevID (&revid);
			Stop_Stopwatch ();
			printf("Revision ID is %u, 0x%04X\n", revid, revid);
			break;
		}
		case 17:	// C2 Read SFR
		{
			uint8_t sfr_value, sfr_address;
			cp = GetNextWord(instr);
			if (NO_ERROR == (result = CheckEmpty(cp)))
			{
				sfr_address = atox (cp);

				Start_Stopwatch ();
				result = C2_ReadSFR (sfr_address, &sfr_value);
				Stop_Stopwatch ();
				printf("C2 Read SFR(%02X) %02X\n", (uint16_t) sfr_address, (uint16_t) sfr_value);
			}
			break;
		}
		case 18:	// C2 Write SFR
		{
			uint8_t sfr_address, sfr_value;

			cp = GetNextWord(instr);
			if (NO_ERROR == (result = CheckEmpty(cp)))
			{
				sfr_address = atox (cp);
				cp = GetNextWord(cp);
				if (NO_ERROR == (result = CheckEmpty(cp)))
				{
					sfr_value = atox (cp);

					printf("C2 Write %02X to SFR(%02X)\n", (uint16_t) sfr_value, (uint16_t) sfr_address);
					Start_Stopwatch ();
					result = C2_WriteSFR (sfr_address, sfr_value);
					Stop_Stopwatch ();
				}
			}
			break;
		}
		case 19:	// C2 Read Direct
		{
			uint8_t sfr_value, sfr_address;
			cp = GetNextWord(instr);
			if (NO_ERROR == (result = CheckEmpty(cp)))
			{
				sfr_address = atox (cp);

				Start_Stopwatch ();
				result = C2_ReadDirect (sfr_address, &sfr_value, C2_DIRECT);
				Stop_Stopwatch ();
				printf("C2 Read Direct(%02X) %02X\n", (uint16_t) sfr_address, (uint16_t) sfr_value);
			}
			break;
		}
		case 20:	// C2 Write Direct <address> <value>
		{
			uint8_t sfr_address, sfr_value;

			cp = GetNextWord(instr);
			if (NO_ERROR == (result = CheckEmpty(cp)))
			{
				sfr_address = atox (cp);
				cp = GetNextWord(cp);
				if (NO_ERROR == (result = CheckEmpty(cp)))
				{
					sfr_value = atox (cp);

					printf("C2 Write %02x to Direct(%02X)\n", (uint16_t) sfr_value, (uint16_t) sfr_address);
					Start_Stopwatch ();
					result = C2_WriteDirect (sfr_address, sfr_value, C2_DIRECT);
					Stop_Stopwatch ();
				}
			}
			break;
		}
		case 21:	// C2 Read Indirect
		{
			uint8_t sfr_value, sfr_address;
			
			cp = GetNextWord(instr);
			if (NO_ERROR == (result = CheckEmpty(cp)))
			{
				sfr_address = atox (cp);

				Start_Stopwatch ();
				result = C2_ReadDirect (sfr_address, &sfr_value, C2_INDIRECT);
				Stop_Stopwatch ();
				printf("C2 Read Indirect(%02X) %02X\n", (uint16_t) sfr_address, (uint16_t) sfr_value);
			}
			break;
		}
		case 22:	// C2 Write Indirect
		{
			uint8_t sfr_address;
			uint8_t sfr_value;

			cp = GetNextWord(instr);
			if (NO_ERROR == (result = CheckEmpty(cp)))
			{
				sfr_address = atox (cp);
				cp = GetNextWord(cp);
				if (NO_ERROR == (result = CheckEmpty(cp)))
				{
					sfr_value = atox (cp);

					printf("C2 Write %02x to Indirect(%02X)\n", (uint16_t) sfr_value, (uint16_t) sfr_address);
					Start_Stopwatch ();
					result = C2_WriteDirect (sfr_address, sfr_value, C2_INDIRECT);
					Stop_Stopwatch ();
				}
			}
			break;
		}
		case 23:	// C2 Discover
		{
			uint8_t j, deviceId, revisionId, derivativeId;

			printf("C2 Discover\n");
			Start_Stopwatch ();
			result = C2_Discover (&deviceId, &revisionId, &derivativeId);
			Stop_Stopwatch ();

			if (result != NO_ERROR)
				break;

			dfptr = &(KnownFamilies[FamilyNumber]);
			deptr = &(KnownFamilies[FamilyNumber].DerivativeList[DerivativeNumber]);

			printf("Family Information:\n");
			printf("Device ID: 0x%04X\n", dfptr->DEVICE_ID);
			printf("Family string: %s\n", dfptr->FAMILY_STRING);
			printf("Mem Type: %u\n", (uint16_t) dfptr->MEM_TYPE);
			printf("Page Size: %u\n", dfptr->PAGE_SIZE);
			printf("Has SFLE: %u\n", (uint16_t) dfptr->HAS_SFLE);
			printf("Security Type: %u\n", (uint16_t) dfptr->SECURITY_TYPE);
			printf("FPDAT address: 0x%02X\n", (uint16_t) dfptr->FPDAT);
			printf("Device ID: 0x%04X\n", dfptr->DEVICE_ID);
			printf("Init strings:\n");
			for (j = 0; ; j++)
			{
				if (dfptr->InitStrings[j] == NULL)
					break;
				printf("%s\n", dfptr->InitStrings[j]);
			}
			printf("\n");
			printf("Derivative Information\n");
			printf("----------------------\n");
			printf("Derivative ID        : %02X\n", deptr->DERIVATIVE_ID);
			printf("Derivative String    : %s\n", deptr->DERIVATIVE_STRING);
			printf("Features String      : %s\n", deptr->FEATURES_STRING);
			printf("Package String       : %s \n", deptr->PACKAGE_STRING);
			printf("Code Start Address   : %05X\n", deptr->CODE_START);
			printf("Code Size            : %05X\n", deptr->CODE_SIZE);
			printf("Write Lock Byte Addr : %05X\n", deptr->WRITELOCKBYTEADDR);
			printf("Read Lock Byte Addr  : %05X\n", deptr->READLOCKBYTEADDR);
			printf("Code 2 Start Address : %05X\n", deptr->CODE2_START);
			printf("Code 2 Size          : %05X\n", deptr->CODE2_SIZE);
			printf("\n");

			break;
		}
		case 24:	// Run Init String
		{
			result = NO_ERROR;
			printf("Execute Device Init String:\n");
			if (FamilyFound == true)
				CommandsList = KnownFamilies[FamilyNumber].InitStrings;
			else
				printf("Device not connected.\n");
			break;
		}
		case 25:	// C2 Flash Read <start addr> <length>
		{
			uint32_t addr;
			uint16_t length;

			printf("C2 Flash Read\n");
			cp = GetNextWord(instr);
			if (NO_ERROR == (result = CheckEmpty(cp)))
			{
				addr = atolx (cp);
				cp = GetNextWord(cp);
				if (NO_ERROR == (result = CheckEmpty(cp)))
				{
					length = atoi (cp);
					if (length > sizeof (BinDest))
						length = sizeof (BinDest);

					printf(
						"Reading %u bytes starting at address 0x%05lX\n",
						length,
						(unsigned long)addr
					);
					Start_Stopwatch ();
					result = C2_FLASH_Read (BinDest, addr, length);
					Stop_Stopwatch ();

					BIN2HEXSTR (HexDest, BinDest, length);
					printf("Memory contents are %s\n", HexDest);
				}
			}
			break;
		}
		case 26:	// C2 OTP Read <start addr> <length>
		{
			uint32_t addr;
			uint16_t length;

			printf("C2 OTP Read\n");
			cp = GetNextWord(instr);
			if (NO_ERROR == (result = CheckEmpty(cp)))
			{
				addr = atolx (cp);
				cp = GetNextWord(cp);
				if (NO_ERROR == (result = CheckEmpty(cp)))
				{
					length = atoi (cp);

					if (length > sizeof (BinDest))
						length = sizeof (BinDest);

					printf("Reading %u bytes starting at address 0x%05lX\n",
						length,
						(unsigned long)addr
					);
					Start_Stopwatch ();
					result = C2_OTP_Read (BinDest, addr, length);
					Stop_Stopwatch ();

					BIN2HEXSTR (HexDest, BinDest, length);
					printf("Memory contents are %s\n", HexDest);
				}
			}
			break;
		}
		case 27:	// C2 Flash Write <start addr> <hex string>
		{
			uint32_t addr;
			uint8_t length;

			printf("C2 Flash Write\n");
			cp = GetNextWord(instr);
			if (NO_ERROR == (result = CheckEmpty(cp)))
			{
				addr = atolx (cp);
				cp = GetNextWord(cp);
				if (NO_ERROR == (result = CheckEmpty(cp)))
				{
					// warning! 'dest' could be overtaken by a long string
					if (NO_ERROR == (result = HEXSTR2BIN (BinDest, cp, &length, sizeof(BinDest))))
					{
						printf("Writing %u bytes starting at address 0x%05X\n", length, addr);
						// printf("Writing the following string: %s\n", cp);
						Start_Stopwatch ();
						result = C2_FLASH_Write (addr, BinDest, length);
						Stop_Stopwatch ();
					}
				}
			}
			break;
		}
		case 28:	// C2 OTP Write <start addr> <hex string>
		{
			uint32_t addr;
			uint8_t length;

			printf("C2 OTP Write\n");
			cp = GetNextWord(instr);
			if (NO_ERROR == (result = CheckEmpty(cp)))
			{
				addr = atolx (cp);
				cp = GetNextWord(cp);
				if (NO_ERROR == (result = CheckEmpty(cp)))
				{

					if (NO_ERROR != (result = HEXSTR2BIN (BinDest, cp, &length, sizeof(BinDest))))
					{
						printf("Hex string too long");
						break;
					}

					printf(
						"Writing %u bytes starting at address 0x%05lX\n",
						(uint16_t) length,
						(unsigned long)addr
					);
					printf("Writing the following string: %s\n", cp);
					Start_Stopwatch ();
					result = C2_OTP_Write (addr, BinDest, length);
					Stop_Stopwatch ();
				}
			}
			break;
		}
		case 29:	// C2 Page Erase <address in page to erase>
		{
			uint32_t addr;

			printf("C2 Flash Page Erase\n");
			cp = GetNextWord(instr);
			if (NO_ERROR == (result = CheckEmpty(cp)))
			{
				addr = atolx (cp);

				printf("Erasing page containing address 0x%05X\n", addr);
				Start_Stopwatch ();
				result = C2_FLASH_PageErase (addr);
				Stop_Stopwatch ();
			}
			break;
		}
		case 30:	// C2 Device Erase
		{
			printf("C2 Flash Device Erase\n");

			printf("Erasing device...\n");
			Start_Stopwatch ();
			result = C2_FLASH_DeviceErase ();
			Stop_Stopwatch ();

			break;
		}
		case 31:	// C2 Flash Blank Check
		{
			uint32_t addr;
			uint32_t length;

			printf("C2 Flash Blank Check\n");

			addr = KnownFamilies[FamilyNumber].DerivativeList[DerivativeNumber].CODE_START;
			length = KnownFamilies[FamilyNumber].DerivativeList[DerivativeNumber].CODE_SIZE;

			printf("Checking starting at address 0x%05X for 0x%05X bytes: ", addr, length);
			Start_Stopwatch ();
			result = C2_FLASH_BlankCheck (addr, length);
			Stop_Stopwatch ();

			printf((result == DEVICE_IS_BLANK) ? "OK\n" : "Fail\n");
			break;
		}
		case 32:	// C2 OTP Blank Check
		{
			uint32_t addr;
			uint32_t length;

			printf("C2 OTP Blank Check\n");

			addr = KnownFamilies[FamilyNumber].DerivativeList[DerivativeNumber].CODE_START;
			length = KnownFamilies[FamilyNumber].DerivativeList[DerivativeNumber].CODE_SIZE;

			printf("Checking starting at address 0x%05X for 0x%05X bytes: ", addr, length);

			Start_Stopwatch ();
			result = C2_OTP_BlankCheck (addr, length);
			Stop_Stopwatch ();

			printf((result == NO_ERROR) ? "OK\n" : "Fail\n");
			break;
		}
		case 33:	// C2 Get Lock Byte value
		{
			printf("C2 Get Lock Byte\n");
			break;
		}
		case 34:	// Write Target to HEX
		{
			printf("Write Target to HEX:\n");
			Start_Stopwatch ();
			result = OP_Write_TARGET2HEX();
			Stop_Stopwatch ();

			break;
		}
		case 36:	// Write HEX to Target
		{
			HEX_RECORD hex;

			printf("Write HEX to Target:\n");

			cp = GetNextWord(instr);
			if (NO_ERROR == (result = CheckEmpty(cp)))
			{
				hex.Buf = BinDest;
				result = HEX_Decode(&hex, cp, sizeof(BinDest));
				if (result == NO_ERROR && hex.RECLEN != 0)
				{
					printf("Writing %u bytes starting at address 0x%05X\n", hex.RECLEN, hex.OFFSET.U16);
					Start_Stopwatch ();
					result = C2_FLASH_Write (hex.OFFSET.U16, hex.Buf, hex.RECLEN);
					Stop_Stopwatch ();
				}
				else if (result == EOF_HEX_RECORD)
					result = NO_ERROR;
			}
			break;
		}
		case 35:	// Read SFRs and directs
		{
			uint8_t row;
			uint8_t col;
			uint8_t value;

			Start_Stopwatch ();
			for (row = 0xF8; row != 0x00; row = row - 8)
			{
				for (col = 0; col != 0x08; col++)
				{
					if (NO_ERROR != (result = C2_ReadDirect ((row+col), &value, C2_DIRECT)))
						break;

					if (col == 0)
						printf("\n0X%02X: %02X", (uint16_t) (row), (uint16_t) value);
					else
						printf(" %02X", (uint16_t) value);
				}
			}
			printf("\n\n");
			Stop_Stopwatch ();
			break;
		}
		case 0xFE:
			break;
		default:
		{
			result = INVALID_COMMAND;
		}
	}
	printf("Result: %02X %s\n", result, GetErrorName(result));
	return result;
}
void ShowFileSystem(void)
{
	char str [100];

	  Usart1Send((char *) "File System:\r\n");
	  Wait_ms(100);
	  //LoadFilesIndex();

	  sprintf(str, "num0: %08x %08x %d\r\n", files.posi0, files.lenght0, files.lenght0);
	  Usart1Send(str);
	  Wait_ms(100);

	  sprintf(str, "num1: %08x %08x %d\r\n", files.posi1, files.lenght1, files.lenght1);
	  Usart1Send(str);
	  Wait_ms(100);

	  sprintf(str, "num2: %08x %08x %d\r\n", files.posi2, files.lenght2, files.lenght2);
	  Usart1Send(str);
	  Wait_ms(100);

	  sprintf(str, "num3: %08x %08x %d\r\n", files.posi3, files.lenght3, files.lenght3);
	  Usart1Send(str);
	  Wait_ms(100);

	  sprintf(str, "num4: %08x %08x %d\r\n", files.posi4, files.lenght4, files.lenght4);
	  Usart1Send(str);
	  Wait_ms(100);

	  sprintf(str, "num5: %08x %08x %d\r\n", files.posi5, files.lenght5, files.lenght5);
	  Usart1Send(str);
	  Wait_ms(100);

	  sprintf(str, "num6: %08x %08x %d\r\n", files.posi6, files.lenght6, files.lenght6);
	  Usart1Send(str);
	  Wait_ms(100);

	  sprintf(str, "num7: %08x %08x %d\r\n", files.posi7, files.lenght7, files.lenght7);
	  Usart1Send(str);
	  Wait_ms(100);

	  sprintf(str, "num8: %08x %08x %d\r\n", files.posi8, files.lenght8, files.lenght8);
	  Usart1Send(str);
	  Wait_ms(100);

	  sprintf(str, "num9: %08x %08x %d\r\n", files.posi9, files.lenght9, files.lenght9);
	  Usart1Send(str);
	  Wait_ms(100);
}
Example #25
0
void* Reap_CPU_XPM_mtrlt(void* param)
{

	Reap_CPU_param* state = (Reap_CPU_param*)param;

	Work tempwork;
	tempwork.time = 13371337;

	//uchar tempdata[80];
	//memset(tempdata, 0, 80);

	uchar finalhash[32];
	uchar temphash[32];
	uchar hash_results[1] = {};

	uint current_server_id;
	
	uint starttime = ticker();
	uint currenttime = starttime;
	
	uint foundprimes=0;

	while(!shutdown_now)
	{
		if (current_work.old)
		{
			Wait_ms(20);
			continue;
		}
		if (tempwork.time != current_work.time)
		{
			pthread_mutex_lock(&current_work_mutex);
			tempwork = current_work;
			pthread_mutex_unlock(&current_work_mutex);
			//memcpy(tempdata, &tempwork.data[0], 80);

			*(uint*)&tempwork.data[76] = state->thread_id<<28;
			current_server_id = tempwork.server_id;

		}


		uint trues=0;
		
		for(uint h=0; h<CPU_BATCH_SIZE; ++h)
		{
			bool result = MinePrime(state,tempwork);
			if (result) 
			{
				foundprimes++;
			}
			
			++*(uint*)&tempwork.data[76];
		}
		//cout << "Every " << double(CPU_BATCH_SIZE)/double(trues) << "th num is true" << endl;

		state->hashes += CPU_BATCH_SIZE;
	}
	pthread_exit(NULL);
	return NULL;
}
void Wait_seconds(unsigned int time) {
    unsigned int msWait = time * 1000;
    Wait_ms(msWait);
}
signed char RunOrbitProgram() {
    signed char retCode=0;
    UI_Location=UI_LOC_ORBITRUN;    
    signed char ret;
    double EndPos;
    double CurrentPos;
    double TimeRemaining;
    double DistanceRemaining;

    LCD_ClearDisplay();
    LCD_PrintString("MOVING TO START\0");
    MoveToAngle(CurrentOrbitProgram.Origin_deg, 90);
    while (bMove_InProgress) {
        Idle();
        ret = GetInput_nonblocking();
        if (ret == USER_INPUT_CANCEL) {
            retCode=-2;
            goto labelFinished;
        }
        if (ret<0){
            retCode=ret;
            goto labelFinished;
        }
    }


    double Distance = CurrentOrbitProgram.CycleCount_rev * 360;
    if (CurrentOrbitProgram.EndMode == 2) Distance = 7776000;
    if (!CurrentOrbitProgram.IsClockWise) Distance = -Distance;

    bLock_Motor_Position = 1;
    CurrentPos = Motor_Position;
    bLock_Motor_Position = 0;
    CurrentPos *= Config.Degrees_Per_Count;

    EndPos = CurrentPos + Distance;


    LCD_ClearDisplay();
    LCD_PrintString("RUNNING: T-HH:MM:SS\0");

    if (CurrentOrbitProgram.EndMode == 2) {
        LCD_ClearDisplay();
        LCD_PrintString("ORBIT RUNNING\0");
        LCD_SetPosition(1, 0);
        LCD_PrintString("INFINITE RUNTIME\0");
    }

    double SpdConvert = 1 / CurrentOrbitProgram.Speed_deg_sec;
    ret = GetInput_nonblocking();

    Move(Distance, CurrentOrbitProgram.Speed_deg_sec);
    while (bMove_InProgress) {

        bLock_Motor_Position = 1;
        CurrentPos = Motor_Position;
        bLock_Motor_Position = 0;
        CurrentPos *= Config.Degrees_Per_Count;

        DistanceRemaining = EndPos - CurrentPos;
        if (DistanceRemaining < 0) DistanceRemaining = -DistanceRemaining;
        TimeRemaining = DistanceRemaining*SpdConvert;
        DistanceRemaining *= 0.002778;

        if (!(CurrentOrbitProgram.EndMode == 2)) {
            LCD_SetPosition(0, 11);
            PrintTime(TimeRemaining, 0b1110, 0);
            LCD_SetPosition(1, 0);
            LCD_PrintFloat(DistanceRemaining, 5, 2, 0);
            LCD_PrintString(" REV REMAIN\0");
        }

        ret = GetInput_nonblocking();
        if (ret == USER_INPUT_CANCEL) {
            retCode=-2;
            goto labelFinished;
        }
        if (ret<0){
            retCode=ret;
            goto labelFinished;
        }

        Idle();
    }

labelFinished:
    bMove_InProgress = 0;
    bFollowMode = 1;
    LCD_ClearDisplay();
    LCD_PrintString("STOPPING...\0");
    Idle();
    bMove_InProgress = 0;
    bFollowMode = 1;
    Wait_ms(500);
    bFollowMode = 0;
    return retCode;
}
Example #28
0
void main(void) {
    signed char ret = 0;
    signed char lastMenu = 0;
    char pnum = 0;

    SetupIO();
    MOTOR_FORWARD = 0;
    MOTOR_REVERSE = 0;

    Move_shifted_position.ul = 0;
    Move_position[0].ul = 0;
    Move_position[1].ul = 0;
    //PID_SetPoint = 0;
    char idx;
    for (idx = 0; idx < 16; idx++) RotaryDetentIntervals[idx] = 0xFF;

    //LoadSettings();
    FactoryDefault();

    SetupHardware();

    LCD_PowerUp();
    LCD_ClearDisplay();

    LCD_PrintString("CINEFLUX ORBIT\0");
    LCD_SetPosition(1,0);    
    LCD_PrintString(VER);
    Wait_ms(2000);

    const char *COMMAND_0 = "ORBIT MODE\0";
    const char *COMMAND_1 = "WAYPOINT MODE\0";
    const char *COMMAND_3 = "RUN PRESET\0";
    const char *COMMAND_2 = "REALTIME MODE\0";
    const char *COMMAND_4 = "BATTERY VOLTAGE\0";
    const char *COMMAND_5 = "GO TO SLEEP\0";
    const char *COMMAND_6 = "EXTERNAL CTRL MODE\0";
    const char*CommandMenu[7];
    CommandMenu[0] = COMMAND_0;
    CommandMenu[1] = COMMAND_1;
    CommandMenu[2] = COMMAND_2;
    CommandMenu[3] = COMMAND_3;
    CommandMenu[4] = COMMAND_4;
    CommandMenu[5] = COMMAND_5;
    CommandMenu[6] = COMMAND_6;

    bFollowMode = 1;
    LCD_ClearDisplay();
    LCD_PrintString("MOVE TO ZERO DEGREES\0");
    LCD_SetPosition(1, 0);
    LCD_PrintString("THEN CLICK...\0");
    GetClick();
    bClear_MotorPosition = 1;
    while (bClear_MotorPosition) Idle();
    Wait_ms(10);
    bFollowMode = 0;
    LCD_ClearDisplay();

    while (1) {
        ret = DisplayMenu(CommandMenu, 6, lastMenu);
        switch (ret) {
            case 0:
                lastMenu = 0;
                if (!CreateOrbitProgram() == 0)
                    RealtimeMode();
                break;
            case 1:
                lastMenu = 1;
                if (!CreateWaypointProgram() == 0)
                    RealtimeMode();
                break;
            case 3:
                lastMenu = 2;
                ret = GetPresetNumber();
                if (ret == -1) break;
                if (ret == -2) break;
                pnum = ret;
                switch (GetPresetType(pnum)) {
                    case 1:
                        LoadPreset(pnum, (unsigned char *) &CurrentPath);
                        if (!RunWaypointProgram() == 0)
                            RealtimeMode();
                        break;
                    case 2:
                        LoadPreset(pnum, (unsigned char *) &CurrentOrbitProgram);
                        if (!RunOrbitProgram() == 0)
                            RealtimeMode();
                        break;
                }
                break;
            case 2:
                lastMenu = 2;
                RealtimeMode();
                break;
            case 4:
                lastMenu = 0;
                ShowVoltage();
                break;
            case 5:
                lastMenu = 0;
                GoToSleep();
                break;
            case 6:
                lastMenu = 0;
                ExtMode();
                break;
        }
    }
}