Пример #1
0
/**
 * Function to stop a SPI transaction on the given device.
 * This is used to set the SlaveSelect to idle after a transaction occurred thus releasing the bus.
 * \param pointer - SPIContext pointer
 * \return none
 */
void SPIStop(SPIContext * obj)
{
	
	vTaskSuspendAll();
	#ifndef SPI2_FLASH
		#ifdef SPI_DBG
		uartwrite(1,"[SPI_DBG] SPI stop, checking SS\n");
		#endif
		if(obj->ss_pin != SPI_OPT_NO_SS)
		{
			
			#ifdef SPI_DBG
			uartwrite(1,"[SPI_DBG] Pulling SS up\n");
			#endif
			if(SPI2STATbits.SPITBF)
				Delay10us(obj->delay);
			IOPut(obj->ss_pin,on);
		}
	
	#else
		if(SPI2STATbits.SPITBF)
			Delay10us(obj->delay);
		LATDbits.LATD6=1;
	#endif
	xTaskResumeAll();
}
Пример #2
0
//-----------------------------------------------------------------------------
// Envoi des données au LCD
// aData: les données à transmettre au LCD
//-----------------------------------------------------------------------------
static void mLcd_SendLcdData(UINT8 aData)
{
  // E inactif
  Delay10us(1);
  mLCD_E=1;
  mLCD_RW=0;
  mLCD_RS=1;
  
  // écriture des données
  //iDio_SetPortB(aData);
    mLCD_D0= aData & 0x01;
    mLCD_D1= (aData & 0x02)>>1;
    mLCD_D2= (aData & 0x04)>>2;
    mLCD_D3= (aData & 0x08)>>3;
    mLCD_D4= (aData & 0x10)>>4;
    mLCD_D5= (aData & 0x20)>>5;
    mLCD_D6= (aData & 0x40)>>6;
    mLCD_D7= (aData & 0x80)>>7;
    Delay10us(1);

  // Bit E (start data read/write) à 1
  // le bits E doit être à 1 pendant au moins 230nsec
  //iDio_SetPortK(kMaskIo0,kIoOn);
  mLCD_E=0;
  Delay10us(1);

  // Bit E (start data read/write) à 0
  // les data sont latchés à ce moment là
  //iDio_SetPortK(kMaskIo0,kIoOff);
  mLCD_E=1;
  mLCD_RW=0;
  mLCD_RS=0;

}
Пример #3
0
//-----------------------------------------------------------------------------  
//	Ouverture de l'interface (init du display)
//-----------------------------------------------------------------------------
void mLcd_Open(void)
{
	unsigned long i = 0 ;

    //power supply of LCD
    mLCD_VDD=1;
    mLCD_V0=1;

    DelayMs(40);

	// Selection du mode 2 lignes + display on
    mLcd_SendLcdCmd(0x3C);
    Delay10us(4);

    
    // attendre ~39us
    
    // Selection du mode pas curseur + display on
    mLcd_SendLcdCmd(0x0C);
    Delay10us(4);

    
    // attendre ~39us

    //Display clear
    mLcd_SendLcdCmd(0x01);
    DelayMs(2);
    
    // attendre ~1.53ms
    mLcd_SendLcdCmd(0x06);
    Delay10us(4);

}
Пример #4
0
static void writeToDisplayPort( UINT8 value  )
{
	UINT8 shift = 0x01;

	DIGIT_PORT_1 = ~(0XFF);		//switch off display
	DIGIT_PORT_2 = ~(0XFF);
	DIGIT_PORT_3 = ~(0XFF);		
	DIGIT_PORT_4 = ~(0XFF);		

	Delay10us(1);

	DATA_PORT = value;


	if(digitDisplay.digitIndex < 8)
	{
		shift <<= digitDisplay.digitIndex;
	
		DIGIT_PORT_1 = shift;
		DIGIT_PORT_2 = shift;
		DIGIT_PORT_3 = shift;
		DIGIT_PORT_4 = shift;
	}

	Delay10us(1);

}
Пример #5
0
/*******************************************************************************
* PUBLIC FUNCTION: Disp_GLCDCommand
*
* PARAMETERS:
* ~ command byte
*
* RETURN:
* ~ void
*
* DESCRIPTIONS:
* Send command byte to the GLCD controller.
* Please refer to the datasheet for the list of commands.
*******************************************************************************/
void Disp_GLCDCommand(unsigned char command)
{
	RS = 0;
    //Delay10us(2);

    E = 1;
	Delay10us(2);
	// Move higher nibble first
	DB4 = (command & (1 << 4)) >> 4;
    DB5 = (command & (1 << 5)) >> 5;
    DB6 = (command & (1 << 6)) >> 6;
    DB7 = (command & (1 << 7)) >> 7;
	Delay10us(2);
	E = 0;

	E = 1;
	Delay10us(2); 
	// Then move the lower nibble
    DB4 = (command & (1 << 0)) >> 0;
    DB5 = (command & (1 << 1)) >> 1;
    DB6 = (command & (1 << 2)) >> 2;
    DB7 = (command & (1 << 3)) >> 3;
	Delay10us(2); 
    E = 0;

	Delay10us(2);					// Please increase this delay if the screen is not showing things correctly.
	
}
Пример #6
0
void KT_I2C_Start(void) {
	SDA_1;
	Delay10us();
	SCL_1;
	Delay10us();
	SDA_0;
	Delay10us();
	SCL_0;
	Delay10us();
}
Пример #7
0
void KT_I2C_Stop(void) {
	SCL_0;
	Delay10us();
	SDA_0;
	Delay10us();
	SCL_1;
	Delay10us();
	SDA_1;
	Delay10us();
}
Пример #8
0
void display_row (unsigned char p_byRow)
{
	unsigned char i,j;
	unsigned char k;
	if(p_byRow == 1)			// if row  is same as saying if row is non zero, in our case its row = 1
	{
	// Set the address to the second line
	lcd_cmd(0xC0);
	Delay10us(5);

	// Output second line
		for(i = 0; i < 16u; i++)
		{
		// Erase the rest of the line if a null char is 
		// encountered (good for printing strings directly)
		if(LCDText[i] == 0u)
		{
			for(j=i; j < 16u; j++)
			{
				LCDText[j] = ' ';
			}
		}
		
		lcd_dat(LCDText[i]);
		Delay10us(5);
		}
	
	}

	else
	{
		lcd_cmd(0x80);
		DelayMs(2);

		// Output first line
		for(i = 0; i < 16u; i++)
		{
		// Erase the rest of the line if a null char is 
		// encountered (good for printing strings directly)
		if(LCDText[i] == 0u)
		{
			for(j=i; j < 16u; j++)
			{
				LCDText[j] = ' ';
			}
		}
		lcd_dat(LCDText[i]);
		Delay10us(5);
		
		}
	}
}
Пример #9
0
uint8_t KT_I2C_Write(uint8_t u8Data) {
	uint8_t i, ret;
	for(i=0; i<8; ++i) {
		if(u8Data&0x80) {
			SDA_1;
		} else {
			SDA_0;
		}
		Delay10us();
		SCL_1;
		Delay10us();
		Delay10us();
		SCL_0;
		Delay10us();
		u8Data<<=1;
	}
	//kiem tra ack
	SDA_1;
	Delay10us();
	SCL_1;
	Delay10us();
	if(SDA_VAL) {
		ret=1;
	} else {
		ret=0;
	}
	Delay10us();
	SCL_0;
	Delay10us();
	return ret;
}
Пример #10
0
uint8_t KT_I2C_Read(uint8_t u8Ack) {
	uint8_t i, ret;
	for(i=0; i<8; ++i) {
		ret<<=1;
		Delay10us();
		SCL_1;
		Delay10us();
		if(SDA_VAL) {
			ret|=0x01;
		}
		Delay10us();
		SCL_0;
		Delay10us();
	}
	//kiem tra ack
	if(u8Ack) {
		SDA_1;
	} else {
		SDA_0;
	}
	Delay10us();
	SCL_1;
	Delay10us();
	Delay10us();
	SCL_0;
	Delay10us();
	return ret;
}
Пример #11
0
void ConsoleInit(void)
{
#if defined(ENABLE_CONSOLE)
		unsigned long i = 0;
		
		// Don't attempt anything if not connected
		if (!USB_BUS_SENSE) return;

		USBInitializeSystem();
		USBDeviceAttach();

		// This will only work in an interrupt driven USB system - exits on button press, only exits after enumeration is usb is detected
		while (USBDeviceState < CONFIGURED_STATE)
		{
			#ifndef USB_INTERRUPT
			USBDeviceTasks(); 	// Interrupt or polling method.  If using polling, must call
			#endif
			USBProcessIO();
			Delay10us(1);
			
			// Timed-out starting connection (perhaps a charger or disconnected?)
			if (i++ >= 1000000ul) 
			{ 
				// The USB connection has failed -- if we're not using the PLL when the radio is on, turn it off now
				USBDeviceDetach();
				return;
			}
		}
		

 		// Gives host time to assign CDC port
 		i = 0;
		while (USBDeviceState >= CONFIGURED_STATE && i++ < 600000ul)
		{
			MRF_LED = 1;
			#ifndef USB_INTERRUPT
			USBDeviceTasks(); 	// Interrupt or polling method.  If using polling, must call
			#endif
			USBProcessIO();
			Delay10us(10);
			if (usb_haschar())
			{
				break;
			}	
		}
		MRF_LED = 0;
#endif
	return;
}
Пример #12
0
/*
*------------------------------------------------------------------------------
* void PutrsUART(const rom char *data)
*
* Summary	: Send the rom character string through UART
*
* Input		: const rom char *data - pointer to the null terminated string rom.
*
* Output	: None
*------------------------------------------------------------------------------
*/
void PutrsUART(const rom char *data)
{
	TX_EN = 1;	//enable the tx control for rs485 communication
	Delay10us(1);
  do
  {
	// Wait till the last bit trasmision
    while(BusyUSART());
	// Transmit a byte
    putcUSART(*data++);
  } while( *data != '\0');

	TX_EN = 0;	//disable the tx control for rs485 communication
	Delay10us(1);
}
Пример #13
0
void KT_I2C_Init(void) {
	GPIO_InitPara GPIO_InitStructure;
	
	RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_GPIOB,ENABLE);

    GPIO_InitStructure.GPIO_Pin   = GPIO_PIN_6 | GPIO_PIN_7;
    GPIO_InitStructure.GPIO_Speed = GPIO_SPEED_50MHZ;
    GPIO_InitStructure.GPIO_Mode  = GPIO_MODE_OUT_OD;

    GPIO_Init(GPIOB,&GPIO_InitStructure);
	
	SDA_1;
	SCL_1;
	Delay10us();
	Delay10us();
}
Пример #14
0
/**
 * Delays for the given time.
 * @param ms    Time to delay = given time x 1ms
 */
void DelayMs(unsigned char ms)
{
    while (ms--)
    {
        Delay10us(99);
    }
}
Пример #15
0
void KT_I2C_Init(void) {
	//GPIO_InitTypeDef GPIO_InitStructure;
	
	//RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);

    //GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_6 | GPIO_Pin_7;
    //GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    //GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_Out_OD;

    //GPIO_Init(GPIOB,&GPIO_InitStructure);
	GPIO_Init(GPIOD, GPIO_PIN_4, GPIO_MODE_OUT_OD_LOW_FAST);
	GPIO_Init(GPIOD, GPIO_PIN_5, GPIO_MODE_OUT_OD_LOW_FAST);
	SDA_1;
	SCL_1;
	Delay10us();
	Delay10us();
}
Пример #16
0
/******************************************************************************
 * Function:        void LCDUpdate(void)
 *
 * PreCondition:    LCDInit() must have been called once
 *
 * Input:           LCDText[]
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        Copies the contents of the local LCDText[] array into the 
 *					LCD's internal display buffer.  Null terminators in 
 *					LCDText[] terminate the current line, so strings may be 
 *					printed directly to LCDText[].
 *
 * Note:            None
 *****************************************************************************/
void LCDUpdate(void)
{
	BYTE i, j;

	// Go home
	LCDWrite(0, 0x02);
	DelayMs(2);

	// Output first line
	for(i = 0; i < 16u; i++)
	{
		// Erase the rest of the line if a null char is 
		// encountered (good for printing strings directly)
		if(LCDText[0][i] == 0u)
		{
			for(j=i; j < 16u; j++)
			{
				LCDText[0][j] = ' ';
			}
		}
		LCDWrite(1, LCDText[0][i]);
		Delay10us(5);
	}
	
	// Set the address to the second line
	LCDWrite(0, 0xC0);
	Delay10us(5);
    
	// Output second line
//	for(i = 16; i < 32u; i++)
    for(i = 0; i < 16u; i++)
	{
		// Erase the rest of the line if a null char is 
		// encountered (good for printing strings directly)
		if(LCDText[1][i] == 0u)
		{
			//for(j=i; j < 32u; j++)
            for(j=i; j < 16u; j++)
			{
				LCDText[1][j] = ' ';
			}
		}
		LCDWrite(1, LCDText[1][i]);
		Delay10us(5);
	}
}
Пример #17
0
/****************************************************************************
  Function:
    void DelayMs( UINT16 ms )
  Description:
    This routine performs a software delay in intervals of 1 millisecond.
  Precondition:
    None
  Parameters:
    UINT16 ms - number of one millisecond delays to perform at once.
  Returns:
    None
  Remarks:
    None
  ***************************************************************************/
void DelayMs( UINT16 ms )
{
	volatile UINT8 i;
	while (ms--)
    {
    	i = 4;
        while (i--){Delay10us( 25 );}
    }
}
Пример #18
0
// *-------------------------------------------*
UINT16 ADC_Conversion(void){
	
    AD1CON1bits.SAMP=1;			// Inicia adquisicion
    Delay10us(5);
    AD1CON1bits.SAMP=0;			// Inicia conversion
    Nop();
    while(AD1CON1bits.DONE==0);	// Esperamos conversion
    return(ADC1BUF0);
}
Пример #19
0
void DelayMs(WORD ms){
    unsigned char i;
    while(ms--){
        i=4;
        while(i--){
            Delay10us(25);
        }
    }
}
Пример #20
0
void DelayPreServo(void)
{
    unsigned char i;
    i=4;
    while(i--)
    {
        Delay10us(18);
    }
}
// Purpose:    Write a BYTE of data
// Inputs:     The BYTE of data to write
void s1d13700_SendByte(BYTE data)
{
   	S1D13700_TRIS_DATA &= 0xFFFFFF00;
   	
    //S1D13700_WR = 0;
    S1D13700_A0 = 0;
    S1D13700_CS = 0;
	Delay10us();
    S1D13700_E = 1;
	Delay10us();
    
    S1D13700_WR_DATA = data;
	Delay10us();
    S1D13700_E = 0;
    Delay10us();
    //S1D13700_WR = 1;
    S1D13700_CS = 1;
    S1D13700_E = 1;   
}
// Purpose:    Send an 8 bit command
// Inputs:     The command to send
void s1d13700_SendCMD(BYTE cmd)
{
	S1D13700_TRIS_DATA &= 0xFFFFFF00;
	
    //S1D13700_WR = 0;
    S1D13700_A0 = 1;
    S1D13700_CS = 0;
    Delay10us();
    S1D13700_E = 1;
    Delay10us();

    S1D13700_WR_DATA = cmd;
    Delay10us();
    S1D13700_E = 0;
    Delay10us();
    //S1D13700_WR = 1;
    S1D13700_CS = 1;
    S1D13700_E = 1;
}
Пример #23
0
void DelayMs(uint16_t ms)
{
    unsigned char i;
    while (ms--) {
        i = 4;
        while (i--) {
            Delay10us(25);
        }
    }
}
Пример #24
0
/************************************************************************
* Function: void GfxTconWriteCommand(BYTE index, WORD value)                                           
*                                                                       
* Overview: This writes a word to SPI by calling the write byte 
*           routine.
*                                                                       
* Input: index - The index (or address) of the register to be written.
*        value - The value that will be written to the register.
*                                                                       
* Output: none                                 
*                                                                       
************************************************************************/
void GfxTconWriteCommand(WORD index, WORD value)
{
    GfxTconSetIO(BB_CS, 0);

    // Index
    GfxTconSetIO(BB_DC, 0);
    GfxTconWriteByte(((WORD_VAL) index).v[1]);
    GfxTconWriteByte(((WORD_VAL) index).v[0]);

    GfxTconSetIO(BB_CS, 1);
    Delay10us(1);
    GfxTconSetIO(BB_CS, 0);

    // Data
    GfxTconSetIO(BB_DC, 1);
    GfxTconWriteByte(((WORD_VAL) value).v[1]);
    GfxTconWriteByte(((WORD_VAL) value).v[0]);
    GfxTconSetIO(BB_CS, 1);
    Delay10us(1);
}
Пример #25
0
/****************************************************************************
  Function:
    void DelayMs( unsigned short int ms )

  Description:
    This routine performs a software delay in intervals of 1 millisecond.

  Precondition:
    None

  Parameters:
    UINT16 ms - number of one millisecond delays to perform at once.

  Returns:
    None

  Remarks:
    None
  ***************************************************************************/
void DelayMs( unsigned short int ms )
{
    volatile unsigned char i;

    while (ms--)
    {
        i = 4;
        while (i--)
        {
            Delay10us( 25 );
        }
    }
}
Пример #26
0
/*
*------------------------------------------------------------------------------
* void WriteDataToDisplay(UINT8 digit, UINT8 data)
*
* Summary	: Write one byte data on the bus
*
* Input		: UINT8 digit - digit number to write the data
*			  UINT8 dataByte - data byte for the digit
*
* Output	: None
*------------------------------------------------------------------------------
*/
void WriteDataToDisplay(UINT8 digit, UINT8 data)
{
	if( digit >=64 )
	{
		digit+=128;
	}
	DISPLAY_CONTROL = DISPLAY_DISABLE;	//disable the display
	DIGIT_PORT = digit;					//set the address
	DATA_PORT = data;					// write data
	DISPLAY_CONTROL = DISPLAY_ENABLE;	//enable the display
	Delay10us(10);						//delay for the data to stabilize
	DISPLAY_CONTROL = DISPLAY_DISABLE;	//disable it again

}
Пример #27
0
//-----------------------------------------------------------------------------
//	Ecriture sur le LCD complet
// aChar: Pointeur sur la chaîne de charactère à afficher 32 caractères
//-----------------------------------------------------------------------------
void mLcd_WriteEntireDisplay(UINT8* aChar)
{

	UINT16 i;
	
	// Attente du busy flag=0
	while(TRUE==mLcd_ReadLcdBusy());
	
	// Efface la mémoire
	mLcd_SendLcdCmd(kReturnHome); 
    DelayMs(2);
	
	// Envoi des 32 caractères à l'affichage
	for (i=0;i<kMaxLcdCarac;i++) 
		{
	  	// Attente du busy=0
			while(TRUE==mLcd_ReadLcdBusy());
			
			// Envoi du caractère au LCD
			mLcd_SendLcdData(*aChar);
            Delay10us(5);
			
			// Si fin de 1ère ligne on passe à la 2e
			if((kNbOfChar-1)==i)
				{
					// Attente du busy flag=0
					while(TRUE==mLcd_ReadLcdBusy());
	
					// 2e ligne
					mLcd_SendLcdCmd(kLineJump);
                    Delay10us(5);
				}
			
			// Caractère suivant
			aChar++;
	  }
}
Пример #28
0
double distance()	
{

 double distemp=0;
 

   TRIG = 1;
   Delay10us();
	Delay10us();
   TRIG = 0;
   while(ECHO==0);
   TR1 = 1; //开定时器
   
  while(ECHO==1);
    TR1=0;
	

	distemp= ((TH1*256+TL1)*1.08) *  340.0 /2 /10000; 
//	printf("TL0 IS %bd",TL1);
//	printf("TH0 IS %bd",TH1);
	TH1 = 0;
	TL1 = 0;
	return distemp;
}
Пример #29
0
/*
*------------------------------------------------------------------------------
* void DDR_loadDigit(UINT8 digit, UINT8 data)
*
* Summary	: Write one byte data on the bus
*
* Input		: UINT8 digit - digit number to write the data
*			  UINT8 dataByte - data byte for the digit
*
* Output	: None
*------------------------------------------------------------------------------
*/
void DDR_loadDigit(UINT8 digit, UINT8 data)
{
    /*
    	if( digit >=64 )
    	{
    		digit+=128;
    	}
    */
    DISABLE_TMR1_INTERRUPT();
    DISPLAY_CONTROL = DISPLAY_DISABLE;	//disable the display
    DIGIT_PORT = digit;					//set the address
    DATA_PORT = (~LED_MAP[data]) | 0X80;  // write data
    DISPLAY_CONTROL = DISPLAY_ENABLE;	//enable the display
    Delay10us(50);						//delay for the data to stabilize
    DISPLAY_CONTROL = DISPLAY_DISABLE;	//disable it again
    ENABLE_TMR1_INTERRUPT();
}
Пример #30
0
/**
 * Reset the NIC
 */
void NICReset(void)
{
    #if (DEBUG_MAC >= LOG_INFO)
    debugPutMsg(5); //@mxd:5:Reset MAC
    #endif

    TRISD = 0xff;   //Input
    WRITE_NIC_ADDR(0);

    NIC_IOW_IO = 1;
    NIC_IOR_IO = 1;
    NIC_RESET_IO = 1;
    NIC_CTRL_TRIS = 0x00;

    // Reset pulse must be at least 800 ns.
    Delay10us(1);
    DelayMs(5);

    NIC_RESET_IO = 0;
}