Exemplo n.º 1
0
//*****************************************************************************
//		GLOBAL DATA VARIABLES
//*****************************************************************************
int main(void)
{
	//
		// Enable lazy stacking for interrupt handlers.  This allows floating-point
		// instructions to be used within interrupt handlers, but at the expense of
		// extra stack usage.
		//
		FPULazyStackingEnable();

		//
		// Set the clocking to run directly from the crystal.
		//
		SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN| SYSCTL_XTAL_16MHZ);

		//
		// Set up and enable the SysTick timer.  It will be used as a reference
		// for delay loops in the interrupt handlers.  The SysTick timer period
		// will be set up for one second.
		//
		SysTickPeriodSet(SysCtlClockGet());
		SysTickEnable();

		GPIO_Initialize();

	while(1)
	{
		LED_ChangeColor(LED_BLUE);
		DelayMS(1);
		LED_ChangeColor(LED_RED);
		DelayMS(1);
	}

}
Exemplo n.º 2
0
/////*PROGRAMME PRINCIPAL*/////
void main (void)
{
    /* Initialisations. */
    ADCON1 = 0x0F ;
    ADCON0 = 0b00000000;
    WDTCON = 0 ;

    /* Configurations. */
    TRISA   = 0b11101111 ;
    TRISB   = 0xFF ;
    TRISC   = 0xFF ;

    /* Signal de démarrage du programme. */
    led = 0;
    for(i=0;i<20;i++)
    {
        led=led^1;
        DelayMS(50);
    }
    led = 0;

    INTCONbits.GIE = 1; /* Autorise interruptions. */

    DelayMS(1000);


    /* Boucle principale. */
     while(1)
    {

    }
}
void read_xyz(void)
{
	// sign extend byte to 16 bits - need to cast to signed since function
	// returns uint8_t which is unsigned
	acc_X = (int8_t) i2c_read_byte(MMA_ADDR, REG_XHI);
	DelayMS(100);
	acc_Y = (int8_t) i2c_read_byte(MMA_ADDR, REG_YHI);
	DelayMS(100);
	acc_Z = (int8_t) i2c_read_byte(MMA_ADDR, REG_ZHI);

}
Exemplo n.º 4
0
//触摸屏校准代码
//得到四个校准参数
void touch_adjust(void)
{
	u16 tempVal[4][2]={0};
	u16 adjPointX[4]={20,340,20,340};
	u16 adjPointY[4]={20,20,220,220};
	u8 i;
						 
	LCD_Clear(White);//清屏 
	LCD_SetBackColor(White);
	LCD_SetTextColor(Black);
	LCD_DisplayString(24,110,"点击屏幕上红点进行校准"); 
	DelayMS(1000);
	
	LCD_Clear(White);//清屏 
	LCD_SetTextColor(Red);
	penPoint.keyState=Up;
	
AG:	i=0;
	do
	{		
		LCD_DrawCircle(adjPointX[i],adjPointY[i],1);
		LCD_DrawCircle(adjPointX[i],adjPointY[i],2);
		LCD_DrawCircle(adjPointX[i],adjPointY[i],3);
		LCD_DrawCircle(adjPointX[i],adjPointY[i],4);

		if(penPoint.keyState==Down)
		{
			if(GetTouchValue())
			{
				tempVal[i][0]=penPoint.x;
				tempVal[i][1]=penPoint.y;
				LCD_Clear(White);//清屏
				DelayMS(100);	
				i++;
			}
		}
		penPoint.keyState=Up;		
	}while(i<4);

	if(IsOk(tempVal)==0)goto AG;

	penConfig.xfac=(float)(340-20)/(tempVal[1][0]-tempVal[0][0]);
	penConfig.yfac=(float)(220-20)/(tempVal[3][1]-tempVal[0][1]);
	penConfig.xoff=20-penConfig.xfac*tempVal[0][0];
	penConfig.yoff=20-penConfig.yfac*tempVal[0][1];
	
	LCD_Clear(White);//清屏
	LCD_DisplayString(24,110,"屏幕校准成功");
	save_adjdata();
	DelayMS(1000);
	LCD_Clear(White);//清屏	 	     
}
Exemplo n.º 5
0
void Flash()
{

  for (int i = 0; i < 5; i++)
  {
    // red light
    P3OUT = BIT3;
    DelayMS(100);
    // green light
    P3OUT = BIT2;
    DelayMS(100);
  }
}
Exemplo n.º 6
0
void initADXL345(int busSelect, int accelAddress)
{
    int BW_RATE = 0x0B;
    int DATA_FORM = 0x0A;
    int PWR_CTRL = 0x08;

    MasterI2CWrite(busSelect, accelAddress, 0x2C, &BW_RATE, 1);       //Sets the BW_Rate
    DelayMS(10);
    MasterI2CWrite(busSelect, accelAddress, 0x31, &DATA_FORM, 1);     //Sets the data format
    DelayMS(10);
//    MasterI2CWrite(busSelect, ADXL345_ADD, 0x2D, 0x00, 1);           //0x2D is the power control register
//    DelayMS(10);
    MasterI2CWrite(busSelect, accelAddress, 0x2D, &PWR_CTRL, 1);      //Sets the power and sets to measurement mode
    DelayMS(10);
}
Exemplo n.º 7
0
bool GetDDC_Access(uint8_t* SysCtrlRegVal)
{
        uint8_t sysCtrl, TPI_ControlImage, DDCReqTimeout = T_DDC_ACCESS;

	sysCtrl = I2C_ReadByte(TPI_SLAVE_ADDR, 0x1A);
        *SysCtrlRegVal = sysCtrl;

        sysCtrl |= BIT_2;
        I2C_WriteByte(TPI_SLAVE_ADDR, 0x1A, sysCtrl);


        while (DDCReqTimeout--) {
                TPI_ControlImage = I2C_ReadByte(TPI_SLAVE_ADDR, 0x1A);

                if (TPI_ControlImage & BIT_1) {
                        sysCtrl |= BIT_1;
                        I2C_WriteByte(TPI_SLAVE_ADDR, 0x1A, sysCtrl);
                        return true;
                }
                I2C_WriteByte(TPI_SLAVE_ADDR, 0x1A, sysCtrl);
                DelayMS(200);
        }
        I2C_WriteByte(TPI_SLAVE_ADDR, 0x1A, sysCtrl);
        return false;
}
Exemplo n.º 8
0
void CML_Power_Contr(void)
{

	//u8 A_Ch_Power_Level_TX[16];
	//u8 D_Ch_Power_Level_TX[16];
    //2.1V  高   8290
	//1.54V 中	 81DF
	//1.05V 低	 8147
	//0.8V  极低 80F4

/*
    if(Tx_Status)
	{
		if (TX_Power = 0x01)
        	CBUS_SendTwoByte(0xA8,0x81,0x47); //A8[11:10] = 00 DAC1;A8[9:0] 
		else if (TX_Power = 0x02)
        	CBUS_SendTwoByte(0xA8,0x81,0xDF); //A8[11:10] = 00 DAC1;A8[9:0] 
		else if (TX_Power = 0x03)
        	CBUS_SendTwoByte(0xA8,0x82,0x90); //A8[11:10] = 00 DAC1;A8[9:0] 
		else
        	CBUS_SendTwoByte(0xA8,0x80,0xF4); //A8[11:10] = 00 DAC1;A8[9:0] 	
	}
	else
*/
        CBUS_Send16U(AUXDAX_DATA_CTL,0x8001); //dac1 0dbm 输出功率最小
    DelayMS(1);
}
Exemplo n.º 9
0
int UART_Read(uint8_t *buf, int size, int timeout)
{
    /* retry every 1ms */
    int retry = timeout / 1; 
    
    for (;;)
    {
        if (LX_FIFOCount(fifo) == 0)
        {
            /* return cause timeout */
            if (retry-- <= 0)
            {
                break;
            }

            DelayMS(1);
            continue;
        }

        break;
    }

    if (LX_FIFOCount(fifo) == 0)
    {
        return 0;
    }

    int readLen = LX_FIFORead(fifo, (uint8_t *)buf, size);

    return readLen;
}
Exemplo n.º 10
0
void Disp_Reset() {
	DelayMS(15);
	DISP_OUT;

	PORTG = (PORTG & ~7);
	DISP_DATA_OUT(0x03);  // 8 bit interface
	DISP_EN_HIGH;
	DISP_DATA_OUT(0x03);  // 8 bit interface
	DISP_EN_LOW;

	DelayMS(5);

	DISP_EN_HIGH;
	DISP_DATA_OUT(0x03);  // 8 bit interface
	DISP_EN_LOW;

	DelayMS(5);

	DISP_EN_HIGH;
	DISP_DATA_OUT(0x03);   // 8 bit interface
	DISP_EN_LOW;

	DelayMS(5);

	DISP_DATA_OUT(0x02);
	DISP_EN_HIGH;
	DISP_DATA_OUT(0x02);   // set to 4 bit interface
	DISP_EN_LOW;

	DelayMS(20);

	Disp_WriteIR(0x28);    // 4 bit interface, 2 lines, 5x8
	DelayMS(1);

	Disp_WriteIR(0x08);    // display off
	DelayMS(1);

	Disp_WriteIR(0x01);    // display clear
	DelayMS(20);

	Disp_WriteIR(0x0c);
	DelayMS(1);			// display on

	Disp_WriteIR(0x06);    // Entry mode set, increment, no shift
	DelayMS(1);

}
Exemplo n.º 11
0
static bool StartTPI(void)
{

	WriteByteTPI(TPI_ENABLE, 0x00);
	DelayMS(100);
    	bInTpiMode = true;	
	return true;
}
Exemplo n.º 12
0
static void WriteInitialRegisterValues(void)
{
	I2C_WriteByte(TPI_SLAVE_ADDR, 0x08, 0x37);

	I2C_WriteByte(TPI_SLAVE_ADDR, 0xA0, 0xD0);
	I2C_WriteByte(TPI_SLAVE_ADDR, 0xA1, 0xFC);

	I2C_WriteByte(TPI_SLAVE_ADDR, 0xA3, 0xC0);
	I2C_WriteByte(TPI_SLAVE_ADDR, 0xA6, 0x0C);
	I2C_WriteByte(TPI_SLAVE_ADDR, 0x2B, 0x01);

	ReadModifyWriteTPI(0x90, BIT_3 | BIT_2, BIT_2);
	I2C_WriteByte(TPI_SLAVE_ADDR, 0x91, 0xA5);
	I2C_WriteByte(TPI_SLAVE_ADDR, 0x94, 0x75);


	I2C_WriteByte(CBUS_SLAVE_ADDR, 0x31, I2C_ReadByte(CBUS_SLAVE_ADDR, 0x31) | 0x0c);

	I2C_WriteByte(TPI_SLAVE_ADDR, 0xA5, 0xA0);
	TPI_DEBUG_PRINT(("1x Mode\n"));
	I2C_WriteByte(TPI_SLAVE_ADDR, 0x95, 0x31);
	I2C_WriteByte(TPI_SLAVE_ADDR, 0x96, 0x20);

	ReadModifyWriteTPI(0x97,  BIT_1, 0);

	ReadModifyWriteTPI(0x95, BIT_6, BIT_6);
	WriteByteTPI(0x92, 0x86);
	WriteByteTPI(0x93, 0xCC);
	if (txPowerState != TX_POWER_STATE_D3) {
		ReadModifyWriteTPI(0x79, BIT_5 | BIT_4, BIT_4);
	}

	DelayMS(25);
	ReadModifyWriteTPI(0x95, BIT_6, 0x00);
	ReadModifyWriteTPI(0x78, BIT_5, 0);

	I2C_WriteByte(TPI_SLAVE_ADDR, 0x90, 0x27);

	I2C_WriteByte(TPI_SLAVE_ADDR, 0x05, 0x08);
	DelayMS(2);
	I2C_WriteByte(TPI_SLAVE_ADDR, 0x05, 0x00);

	InitCBusRegs();

	I2C_WriteByte(TPI_SLAVE_ADDR, 0x05, ASR_VALUE);
	}
Exemplo n.º 13
0
uint8_t WM8904_Init(Twid *pTwid, uint32_t device,  uint32_t PCK)
{
    uint8_t count, size;
    uint16_t data = 0;

    // Reset (write Reg@0x0 to reset)
    WM8904_Write(pTwid, device, 0, 0xFFFF);

    for(data=0; data<1000; data++);
    //wait ready
    while(data!=0x8904)
        data=WM8904_Read(pTwid, device, 0);

    if (PMC_MCKR_CSS_SLOW_CLK == PCK) {
        {
            size = sizeof(wm8904_access_slow)/4+1;
            for(count=0; count<size; count++) {
                WM8904_Write(pTwid, device, wm8904_access_slow[count].address, wm8904_access_slow[count].value);
                if(((wm8904_access_slow[count].address==0x05)&&(wm8904_access_slow[count].value==0x0047))
                        ||((wm8904_access_slow[count].address==0x74)&&(wm8904_access_slow[count].value==0x0005))
                        ||((wm8904_access_slow[count].address==0x12)&&(wm8904_access_slow[count].value==0x000F))) {
                    DelayMS(5);
                }
                if (((wm8904_access_slow[count].address==0x44)&&(wm8904_access_slow[count].value==0x00F0))
                        ||((wm8904_access_slow[count].address==0x3A)&&(wm8904_access_slow[count].value==0x00B9))) {
                    DelayMS(100);
                }
            }
        }
    } else if (PMC_MCKR_CSS_MAIN_CLK == PCK) {
        for(count=0; count<255; count++) {
            if(wm8904_access_main[count].address<255) {
                WM8904_Write(pTwid, device, wm8904_access_main[count].address, wm8904_access_main[count].value);
            } else {
                break;
            }
        }
    } else {
        printf("W: PCK not supported! \n\r");
        while(1);
    }


    return 0;
}
Exemplo n.º 14
0
void initLCD(void){
	GPIO_DeInit(LCD_PORT);
	GPIO_Init(LCD_PORT, GPIO_PIN_ALL, GPIO_MODE_OUT_PP_LOW_FAST);

	GPIO_WriteLow(LCD_PORT,LCD_E); //clear enable
	GPIO_WriteLow(LCD_PORT,LCD_RS); //going to write command
   
	DelayMS(30); //delay for LCD to initialise.
	LCD_NYB(0x03,0); //Required for initialisation
	DelayMS(5); //required delay
	LCD_NYB(0x03,0); //Required for initialisation
	DelayMS(1); //required delay
	LCD_DATA(0x02,0); //set to 4 bit interface, 1 line and 5*7 font
	LCD_DATA(0x28,0); //set to 4 bit interface, 2 line and 5*10 font
	LCD_DATA(0x0c,0); //set to 4 bit interface, 2 line and 5*7 font
	LCD_DATA(0x01,0); //clear display
	LCD_DATA(0x06,0); //move cursor right after write
}
Exemplo n.º 15
0
void RebootMachine(void)
{
	//system("reboot");
	//dsl 2011.9.14, Now the memory not enough for zem510, zem560 and zem515 coreboard when support TTS, Webserver, 3200FPs
	TTime t;
	GetTime(&t);
	ExSetPowerOnTime(t.tm_hour, t.tm_min);
	DelayMS(10);
	ExPowerRestart();	
}
Exemplo n.º 16
0
//TODO: See if I can get rid of some of these variables.
//TODO: Does the big buffer need to be 32 bits?
uint8_t SHT25_ReadRH(int16_t *RHValue)
{
	uint32_t BigBuffer;
	uint16_t SmallBuffer;
	uint8_t DataToSend;
	uint8_t DataToReceive[3];
	uint8_t stat;
	uint8_t i;

	DataToSend = SHT25_READ_RH_NOHOLD;

	//Start RH conversion
	stat = I2CSoft_RW(SHT25_I2C_ADDR, &DataToSend, NULL, 1, 0);
	
	//Wait for response
	DelayMS(30);
	for(i=0; i<20; i++)
	{
		stat = I2CSoft_RW(SHT25_I2C_ADDR, NULL, DataToReceive, 0, 3);
		if(stat == SOFT_I2C_STAT_OK)
		{
			break;
		}
		DelayMS(10);
	}
	
	if(i >= 20)
	{
		//Device did not respond
		return SHT25_RETURN_STATUS_TIMEOUT;
	}

	SmallBuffer = (DataToReceive[0] << 8) | (DataToReceive[1]);
	
	if(SHT25_VerifyCRC(SmallBuffer, DataToReceive[2]) == 1)
	{
		BigBuffer = ((12500l)*((uint32_t)(SmallBuffer)) - 39321600l)/(65536l);
		
		*RHValue = ((int16_t)BigBuffer);
		return SHT25_RETURN_STATUS_OK;
	}
	return SHT25_RETURN_STATUS_CRC_ERROR;
}
Exemplo n.º 17
0
//TODO: See if I can get rid of some of these variables.
//TODO: Will this ever be negative?
//TODO: Does the big buffer need to be 32 bits?
uint8_t SHT25_ReadTemp(int16_t *TempValue)
{
	int32_t BigBuffer;
	uint16_t SmallBuffer;
	uint8_t DataToSend;
	uint8_t DataToReceive[3];
	uint8_t stat;
	uint8_t i;

	DataToSend = SHT25_READ_TEMP_NOHOLD;

	//Start temperature conversion
	stat = I2CSoft_RW(SHT25_I2C_ADDR, &DataToSend, NULL, 1, 0);
	
	//Wait for response
	DelayMS(75);
	for(i=0; i<20; i++)
	{
		stat = I2CSoft_RW(SHT25_I2C_ADDR, NULL, DataToReceive, 0, 3);
		if(stat == SOFT_I2C_STAT_OK)
		{
			break;
		}
		DelayMS(10);
	}
	
	if(i >= 20)
	{
		//Device did not respond
		return SHT25_RETURN_STATUS_TIMEOUT;
	}

	SmallBuffer = (DataToReceive[0] << 8) | (DataToReceive[1]);
	
	if(SHT25_VerifyCRC(SmallBuffer, DataToReceive[2]) == 1)
	{
		BigBuffer = (17572l*(int32_t)(SmallBuffer) - 307036160l)/(65536l);
		*TempValue = (int16_t)BigBuffer;
		return SHT25_RETURN_STATUS_OK;
	}
	return SHT25_RETURN_STATUS_CRC_ERROR;
}
Exemplo n.º 18
0
// This is the emulator's version of WriteLights.  The output window is updated
// here.  TODO: Reparameterize -> PIXELS_PER_ARM should come from (gData->size / 2).
void UpdateEmuOutput(galaxyData_t *gData, outputMapping_e map) {

  // Vars
  int i;

  // A word on mapping...  Layouts below are described as left to right.
  // pixelMap is generated as 20 .. 0, 21 .. 41
  // gData is 0 .. 41 in FULL, and 0 .. 20, 20 .. 0 in MIRROR.
  if (map == MAP_MIRROR) {
    // Mirrored output.
    for (i = 0; i < PIXELS_PER_ARM ; i++) {
      // Pixmap 0 .. 20.  gData 20 .. 0
      boxRGBA(sdlRenderer, pixelMap[i].x - PIX_SIZE, pixelMap[i].y - PIX_SIZE,
                           pixelMap[i].x + PIX_SIZE, pixelMap[i].y + PIX_SIZE,
                           gData->pixels[PIXELS_PER_ARM - i - 1]->r,
                           gData->pixels[PIXELS_PER_ARM - i - 1]->g,
                           gData->pixels[PIXELS_PER_ARM - i - 1]->b, 255);

      // Pixmap 21 .. 41.  gData 20 .. 0
      boxRGBA(sdlRenderer, pixelMap[i + PIXELS_PER_ARM].x - PIX_SIZE,
                           pixelMap[i + PIXELS_PER_ARM].y - PIX_SIZE,
                           pixelMap[i + PIXELS_PER_ARM].x + PIX_SIZE,
                           pixelMap[i + PIXELS_PER_ARM].y + PIX_SIZE,
                           gData->pixels[PIXELS_PER_ARM - i - 1]->r,
                           gData->pixels[PIXELS_PER_ARM - i - 1]->g,
                           gData->pixels[PIXELS_PER_ARM - i - 1]->b, 255);
    }
  } else {
    // Full output.
    for (i = 0; i < PIXELS_PER_ARM ; i++) {
      // Pixmap 0 .. 20.  gData 20 .. 0
      boxRGBA(sdlRenderer, pixelMap[i].x - PIX_SIZE, pixelMap[i].y - PIX_SIZE,
                           pixelMap[i].x + PIX_SIZE, pixelMap[i].y + PIX_SIZE,
                           gData->pixels[PIXELS_PER_ARM - i - 1]->r,
                           gData->pixels[PIXELS_PER_ARM - i - 1]->g,
                           gData->pixels[PIXELS_PER_ARM - i - 1]->b, 255);

      // Pixmap 21 .. 41.  gData 21 .. 41
      boxRGBA(sdlRenderer, pixelMap[i + PIXELS_PER_ARM].x - PIX_SIZE,
                           pixelMap[i + PIXELS_PER_ARM].y - PIX_SIZE,
                           pixelMap[i + PIXELS_PER_ARM].x + PIX_SIZE,
                           pixelMap[i + PIXELS_PER_ARM].y + PIX_SIZE,
                           gData->pixels[PIXELS_PER_ARM + i]->r,
                           gData->pixels[PIXELS_PER_ARM + i]->g,
                           gData->pixels[PIXELS_PER_ARM + i]->b, 255);
    }
  }

  // Render the scene to the window.
  SDL_RenderPresent(sdlRenderer);

  // Set the timer to emulate the serial transmission time.
  DelayMS((int) PACKET_TIME);
}
Exemplo n.º 19
0
void uvPre(){
	uchar command[2];
	
	I2C_rst();
	I2C_initial();
	DelayMS(100);	// wait from init to standby
	
	// prepare UV Meter/Send hardware key
	command[0] = 0x17;
	writeToRegister(HW_KEY, command, 1);
	readFromRegister(HW_KEY, command, 1);
}
Exemplo n.º 20
0
void WM8960Test(void)
{
  Uint8 i;
  while(1)
  {
    for(i = 1; i < 2; i++)
    {
      WM8960_WriteData(i,WM8960_ROUT1,0x159);// R3
      DelayMS(500);
    }
  }
}
Exemplo n.º 21
0
void CheckTxFifoStable(void)
{
	uint8_t bTemp;

	bTemp = ReadIndexedRegister(0x01, 0x3E);
	if ((bTemp & (BIT_7 | BIT_6)) != 0x00) {
		TPI_DEBUG_PRINT(("FIFO Overrun / Underrun\n"));
		WriteIndexedRegister(0x01, 0x05, BIT_4 | ASR_VALUE);
		DelayMS(1);
		WriteIndexedRegister(0x01, 0x05, ASR_VALUE);
	}
}
Exemplo n.º 22
0
void LCD_Init(void){
    //Setai pini pt LCD
    LCD_PORT->MODER = 0x5055;     //Setaea pinilo pentu output PD0:PD3(DB4:DB7),PD6(E),PD7(RS)
    LCD_PORT->OTYPER = 0x00;      //Setae de tip PUSH-PULL pentu toti
    LCD_PORT->OSPEEDR = 0xA0AA;   //50 MHz Fecventa potului pentu LCD
    LCD_PORT->PUPDR = 0x00;       //PULL-UP/PULL-DOWN Dezactivate

    BitClr(LCD_E);                //clear enable - pin PD6
    BitClr(LCD_RS);               //going to write command - pin PD7

    DelayMS(30);                //delay for LCD to initialise.
    LCD_NYB(0x30,0);              //Required for initialisation
    DelayMS(5);                 //required delay
    LCD_NYB(0x30,0);              //Required for initialisation
    DelayMS(1);                 //required delay
    LCD_DATA(0x02,0);           //set to 4 bit interface, 1 line and 5*7 font
    LCD_DATA(0x28,0);           //set to 4 bit interface, 2 line and 5*10 font
    LCD_DATA(0x0c,0);           //set to 4 bit interface, 2 line and 5*7 font
    LCD_DATA(0x01,0);           //clear display
    LCD_DATA(0x06,0);           //move cursor right after write

}
Exemplo n.º 23
0
void System_Reset(void)
{
	if(s8_Input_Select == eInput_Usb1 && System.bPowerOn&&System.ColdStartTime==0)
	{
		System.bColdStart=1;
		SET_Special_Setup();
		System.bColdStart=0;
		
		DelayMS(10);
		
		System.ColdStartTime=(2000/10);
	}
}
Exemplo n.º 24
0
uint8_t SHT25_Reset(void)
{
	uint8_t DataToSend;
	uint8_t stat;

	DataToSend = SHT25_RESET;
	stat = I2CSoft_RW(SHT25_I2C_ADDR, &DataToSend, NULL, 1, 0);
	
	//Sensor takes <15ms to reinitalize
	DelayMS(15);
	
	return stat;
}
Exemplo n.º 25
0
/****************************************************************************
* 名    称: KeyScan()
* 功    能: 读取按键状态
* 入口参数: 无
* 出口参数: 0为抬起   1为按键按下
****************************************************************************/
uchar KeyScan(void)
{
    if (KEY1 == 0)
    {
        DelayMS(10);
        if (KEY1 == 0)
        {
            while(!KEY1); //松手检测
            return 1;     //有按键按下
        }
    }
    
    return 0;             //无按键按下
}
Exemplo n.º 26
0
//Jump to DFU bootloader
static int _F2_Handler (void)
{
	printf_P(PSTR("Jumping to bootloader. A manual reset will be required\nPress 'y' to continue..."));
	
	if(WaitForAnyKey() == 'y')
	{
		printf_P(PSTR("Jump\n"));
		DelayMS(100);
		Jump_To_Bootloader();
	}
	
	printf_P(PSTR("Canceled\n"));
	return 0;
}
Exemplo n.º 27
0
int main(void)
{
    Motor left, right;
    ConfigMotors(&left, &right);

    PORTD = 0b10101010;
    while(1)
    {
        Motor_Move(&left, FORWARD_MOTOR);
        Motor_Move(&right, BACK_MOTOR);
        DelayMS(50);
    }
    return 0;
}
//initializes mma8451 sensor
//i2c has to already be enabled
int init_mma()
{
	  //check for device
		if(i2c_read_byte(MMA_ADDR, REG_WHOAMI) == WHOAMI)	{
  		DelayMS(10);
			
			//set active mode, 14 bit samples and 100 Hz ODR (0x19)
			i2c_write_byte(MMA_ADDR, REG_CTRL1, 0x01);
			
			return 1;
		}
		//else error
		return 0;
}
Exemplo n.º 29
0
void tpi_clear_pending_event(void)
{
	int retry = 100;

	while (retry--) {
		WriteByteTPI(0x3c, 1);
		WriteByteTPI(0x3d, 1);
		if (ReadByteTPI(0x3d) & 0x01)
			DelayMS(1);
		else
			break;
	}
	if (retry < 19) TPI_DEBUG_PRINT(("%s: retry=%d\n", __func__, 19 - retry));
}
Exemplo n.º 30
0
/*
  SetInput routine

  This routine sets the input for a bay.
 */
void SetInput(enum TInput Source, enum TBay SIBay)
{
  enum TInput NewSource;
  enum TInput OldSource;


  OldSource = BaySource[SIBay];

  UART_TxStr("SetInput ");
  UART_TxNum(Source, 1);
  UART_TxStr(" for bay ");
  UART_TxNum(SIBay, 1);

  // Override any input request to a missing source

  if (InputPresent[Source]) {
    NewSource = Source;
  } else {
    UART_TxStr(" overriding as ");
    if (InputPresent[MP3In])
      NewSource = MP3In;
    else
      NewSource = LCDIn;
    UART_TxNum(NewSource, 1);
  }
  UART_TxNewLine();

  // Ignore requests for same source or empty bay

  if ((OldSource == NewSource) || (BayProduct[SIBay] == UnknownProduct)) {
    return;
  }

  // Handle format changes

  if ((OldSource > RightTablet) || (InputFormat[OldSource] != InputFormat[NewSource])) {
    ExchangeBoardMsg(BCAOutput + SIBay, BCTAudioFormat, InputFormat[NewSource], 0, BCTAck);
    BCMessageReceive(RxBuf);      // Finished with it so get ready for next msg
  }

  // Change the actual stream

  BaySource[SIBay] = NewSource;
  Input = NewSource;

  SetMux(NewSource, SIBay);

  DelayMS(100);  // Give the audio board a chance to sync to new stream
}