Esempio n. 1
0
void test_I2C_CLK_speed(void)
{
	while(1){
	SCL_H;
	Delay_Us(50);
	SCL_L;
	Delay_Us(50);
	}
}
Esempio n. 2
0
void Init_LCD( void )             // initialize LCD display
{
        // turn off all analog functions on the pins used
    AD1PCFGH = 0xFF00;   //turns off channels AN24-31
    AD1PCFGL = 0x8000; //turns off channel AN15 for ADC1
    AD2PCFGL = 0x8000; //turns off channel AN15 for ADC2

	// 15mS delay after Vdd reaches nnVdc before proceeding with LCD initialization
	// not always required and is based on system Vdd rise rate
	Delay(Delay_15mS_Cnt);                  // 15ms delay

	/* set initial states for the data and control pins */
	LATE &= 0xFF00;
    RW = 0;                       // R/W state set low
	RS = 0;                       // RS state set low
	E = 0;                        // E state set low

	/* set data and control pins to outputs */
	TRISE &= 0xFF00;
 	RW_TRIS = 0;                  // RW pin set as output
	RS_TRIS = 0;                  // RS pin set as output
	E_TRIS = 0;                   // E pin set as output

	/* 1st LCD initialization sequence */
	DATA &= 0xFF00;
    DATA |= 0x0038;
    E = 1;
    Nop();
    Nop();
    Nop();
    E = 0;                        // toggle E signal
   	Delay(Delay_5mS_Cnt);         // 5ms delay

	/* 2nd LCD initialization sequence */
	DATA &= 0xFF00;
    DATA |= 0x0038;
    E = 1;
    Nop();
    Nop();
    Nop();
    E = 0;                        // toggle E signal
    Delay_Us( Delay200uS_count ); // 200uS delay

	/* 3rd LCD initialization sequence */
	DATA &= 0xFF00;
    DATA |= 0x0038;
    E = 1;
    Nop();
    Nop();
    Nop();
    E = 0;                        // toggle E signal
    Delay_Us( Delay200uS_count ); // 200uS delay

    lcd_cmd( 0x38 );              // function set
    lcd_cmd( 0x0C );              // Display on/off control, cursor blink off (0x0C)
    lcd_cmd( 0x06 );			  // entry mode set (0x06)
}
Esempio n. 3
0
void xWriteCH375Data( UINT8 mData )
{
    Delay_Us(2);
    CH375_WriteData(mData);
    CH375_Set_A0(0);
    CH375_Set_CS(0);
    CH375_Set_WR(0);
    Delay_Us(5);
    CH375_Set_WR(1);
    Delay_Us(0);
    CH375_Set_CS(1);
    Delay_Us(2);	
}
Esempio n. 4
0
//=============================================================
// 语法格式:	void nRF2401_Initial(void)
// 实现功能:	nRF 初始化
// 参数:		无
// 返回值:		无
//=============================================================
void nRF2401_Initial(void)
{
	*P_SystemClock = 0x98;						// 设置系统时钟为49MHz
	*P_IOB_Attrib |= (CS+DATA+PWR+CLK1+CE+DR1);
	*P_IOB_Dir |= (CS+DATA+PWR+CLK1+CE);
	*P_IOB_Dir&=~DR1;
	*P_IOB_Buffer &=~(CS+DATA+CLK1+CE+DR1);		// 初始化IO端口

	nRF2401_ON();
	Delay_Us(3000);
	nRF2401_WriteCommand();						// 向nRF2401A写命令字
	Delay_Us(300);
}
Esempio n. 5
0
void xWriteCH375Cmd( UINT8 mCmd )
{
    Delay_Us(2);
    CH375_WriteData(mCmd);
    CH375_Set_A0(1);
    CH375_Set_CS(0);
    CH375_Set_WR(0);
    Delay_Us(5);
    CH375_Set_WR(1);
    Delay_Us(0);
    CH375_Set_CS(1);
    Delay_Us(2);
}
Esempio n. 6
0
/*
// initializes the lcd
*/
void lcd_init(LCD_CONFIG* lcd) 
{
	int i;
	/*
	// 15mS delay after Vdd reaches nnVdc
	//
	//if (lcd->VddRiseDelay)
	//	sleep(lcd->VddRiseDelay);
	*/
	Delay(Delay_5mS_Cnt);
	/*
	// set initial states for the data and
	// control pins
	*/
	*lcd->DataLine = 0x00;			/* assert data lines */
	BP_CLR( lcd->RWLine );			/* assert the R/W line */
	BP_CLR( lcd->RSLine );			/* assert the RS line */
	BP_CLR( lcd->ELine );			/* assert the E line */
	/*
	// send initialization sequence
	*/
	SEND_DATA(0x38);
	Delay(Delay_5mS_Cnt);
	SEND_DATA(0x38);
	Delay_Us(Delay200uS_count);
	SEND_DATA(0x38);
	Delay_Us(Delay200uS_count);
	/*
	// send initialization commands
	*/
    lcd_cmd( lcd, 0x38 );          	/* function set */
    lcd_cmd( lcd, 0x0C );          	/* Display on/off control, cursor blink off (0x0C) */
    lcd_cmd( lcd, 0x06 );		  	/* entry mode set (0x06) */
    lcd_cmd( lcd, 0x01 );			/* clear the LCD */
    lcd->line_no = 0;
    lcd->line_pos = 0;
    lcd->write_pos = 0;
    lcd->last_update_s = 0;
    lcd->last_update_ms = 0;
    /*
    // clear lcd buffers
    */    
    for (i = 0; i < LCD_LINE_LENGTH; i++)
    {
	    lcd->lines[0][i] = 0x20;
	    lcd->lines[1][i] = 0x20;
    }
}
void lcd_data( char data )        // subroutine for lcd data
{
//	TRISD &= 0xFF00;              // ensure RD0 - RD7 are outputs
	RW = 0;       				 // ensure RW is 0
    RS = 1;                       // assert register select to 1
	DATA &= 0xFF00;               // prepare RD0 - RD7
    DATA |= data;                 // data byte to lcd
    E = 1;
 	Nop();
    Nop();
    Nop();
    E = 0;                       // toggle E signal
    RS = 0;                      // negate register select to 0
    Delay_Us( Delay200uS_count ); // 200uS delay
    Delay_Us( Delay200uS_count ); // 200uS delay
}
Esempio n. 8
0
//=============================================================
// 语法格式:	void nRF2401_ReceiveWord(unsigned int *RxData)
// 实现功能:	从nRF2401A读出一个字的数据
// 参数:		unsigned int *RxData:读出的数据
// 返回值:		无
//=============================================================
void nRF2401_ReceiveWord(unsigned int *RxData)
{
	unsigned int i = 0,j = 0;
	unsigned int dat = 0;

	*P_IOB_Dir &= ~DATA;			// 输入
	while(*P_IOB_Data&DR1)
	{
		dat <<= 1;
		*P_IOB_Buffer &= ~CLK1;
		if(*P_IOB_Data&DATA)
			dat |= 0x01;
		i++;
		*P_IOB_Buffer |= CLK1;
		Delay_Us(1);
		if(i>15)
		{
			i = 0;
			RxData[j] = dat;
			dat = 0;
			j++;
		}
		*P_IOB_Buffer &= ~CLK1;
	}
	*P_IOB_Dir |= DATA;			// 输出
}
Esempio n. 9
0
//=============================================================
// 语法格式:	void nRF2401_SendWord(unsigned int TxData)
// 实现功能:	将目标地址+字数据写入nRF2401A
// 参数:		unsigned int TxData: 待发送字数据
// 返回值:		无
//=============================================================
void nRF2401_SendWord(unsigned int TxData)
{
	unsigned int i;
	
//	*P_IOB_Dir |= DATA;
	*P_IOB_Buffer |= CE;
	Delay_Us(10);					//
	for(i=0; i<AddrByteCnt; i++)
	{
		nRF2401_WriteByte(AddrBuffer[i]);
	}
	nRF2401_WriteWord(TxData);
	*P_IOB_Buffer &= ~CE;
	*P_IOB_Buffer &= ~DATA;
	Delay_Us(200);
}
Esempio n. 10
0
UINT8 xReadCH375Data( void )
{
    UINT8 data;
    
    Delay_Us(2);
    CH375_WriteData(0xff);
    CH375_Set_A0(0);
    CH375_Set_CS(0);
    CH375_Set_RD(0);
    Delay_Us(0);
    data = CH375_ReadData();	
    CH375_Set_RD(1);
    CH375_Set_CS(1);
    Delay_Us(2);
    return data;
}
Esempio n. 11
0
//=============================================================
// 语法格式:	void nRF2401_WriteWord(unsigned int uiData)
// 实现功能:	向nRF2401A写入一个字数据
// 参数:		unsigned int uiData: 待写入数据
// 返回值:		无
//=============================================================
void nRF2401_WriteWord(unsigned int uiData)
{
	unsigned int i;
	for(i=0; i<16; i++)
	{
		*P_IOB_Buffer &= ~CLK1;
		if(uiData&0x8000)
			*P_IOB_Buffer |= DATA;
		else
			*P_IOB_Buffer &= ~DATA;
			Delay_Us(1);
			*P_IOB_Buffer |= CLK1;
			Delay_Us(1);
			*P_IOB_Buffer &=~CLK1;
			uiData = uiData<<1;
	}
}
Esempio n. 12
0
//=============================================================
// 语法格式:	void nRF2401_SendBuffer_Word(unsigned int *TxData,unsigned int DataWord)
// 实现功能:	向nRF2401A发送一个数组的数据(字方式)
// 参数:		unsigned int *TxData: 待发送数组
//				unsigned int DataWord:数组的长度					
// 返回值:		无
//=============================================================
void nRF2401_SendBuffer_Word(unsigned int *TxData,unsigned int DataWord)
{
	unsigned int i;
	
//	*P_IOB_Dir |= DATA;
	*P_IOB_Buffer |= CE;
	Delay_Us(10);					//
	for(i=0; i<AddrByteCnt; i++)
	{
		nRF2401_WriteByte(AddrBuffer[i]);
	}
	for(i=0; i<DataWord; i++)
	{
		nRF2401_WriteWord(TxData[i]);
	}
	*P_IOB_Buffer &= ~CE;
	*P_IOB_Buffer &= ~DATA;
	Delay_Us(200);
}
Esempio n. 13
0
/*
// sends a command to the lcd
*/
void lcd_cmd(LCD_CONFIG* lcd, unsigned char cmd) 
{
    /*
    // make sure that the R/W and RS lines
    // are asserted
    */
    BP_CLR( lcd->RWLine );
    BP_CLR( lcd->RSLine );
	/*
	// send the command to the LCD
	*/    
    SEND_DATA( cmd );
    /*
    // microchip sample uses 5ms but
    // 400 us works for me
    */
	Delay_Us( Delay200uS_count );
	Delay_Us( Delay200uS_count );
}
Esempio n. 14
0
/*******************************************************************************
* Function Name  : VN_Delay(unsigned long delay_uS)
* Description    : Delay the processor for deltaT time in microseconds.  The user
*                  needs to place the hardware specific code here necessary to
*                  delay the processor for the time span given by delay_uS
*                  measured in micro seconds. This function doesn't need to be
*                  ultra precise. The only requirement on this function is that
*                  the processor is delayed a time NO LESS THAN 90% of the time
*                  given by the variable delay_uS in microseconds. The minimum
*                  timespan that is used by the VectorNav library code is 50uS so
*                  the function call shouldn't affect the timing accuracy much.
*                  If you decide to modify this library or wish to have more
*                  precision on this delay function then you can comment out this
*                  function and replace it with an optimized macro instead. Many
*                  compilers have their own delay routines or macros so make sure
*                  you check your compiler documentation before attempting to
*                  write your own.
* Input          : delay_uS -> Time to delay the processor in microseconds
* Output         : None
* Return         : None
*******************************************************************************/
void VN_Delay(unsigned long delay_uS) {

    /* User code to delay the processor goes here. Below is example code that
       works for a 32-bit ARM7 Cortex processor clocked at 72 MHz.  For any
       other processor you will need to replace this with code that works
       for your processor.  Many compilers will have their own delay routines
       so make sure you check your compiler documentation before attempting to
       write your own. */
    Delay_Us(delay_uS);

}
Esempio n. 15
0
//=============================================================
// 语法格式:	void nRF2401_WriteCommand(void)
// 实现功能:	nRF 写命令字
// 参数:		无
// 返回值:		无
//=============================================================
void nRF2401_WriteCommand(void)
{
	unsigned int i;
	*P_IOB_Buffer &= ~CE;
	*P_IOB_Buffer |= CS;
	Delay_Us(5);
	for(i=0; i<15; i++)
	{
		nRF2401_WriteByte(InitData[i]);
	}
	*P_IOB_Buffer &= ~CS;
	*P_IOB_Buffer |= CE;
}
Esempio n. 16
0
/*******************************************************************************
 *
 *                      Main Function
 *
 *******************************************************************************/
int main() {
    // setting up everything
    initialize();
    int LcdCounter = 0;
    int LcdFlag = 0, LcdLine = 1;
    /*************** Main Loop ***********************************/
    while (1) {

        // Next press of RD6 = the printing of one char
        if ((_RD6 == 0) && (LcdFlag == 1))
        {
            if (LcdCounter < (sizeof(LcdData1)-1))
            {
                puts_lcd(&LcdData1[LcdCounter], 1);
                LcdCounter++;
            }
            if (LcdCounter >= (sizeof(LcdData1)- 1))
            {
                if ((LcdCounter == (sizeof(LcdData1) - 1 )) && (LcdLine = 1))
                {
                    line_2();
                    LcdLine = 2;
                }

                else if (LcdCounter <= ((sizeof(LcdData1) + sizeof(LcdData2)) -2))
                {
                    puts_lcd(&LcdData2[(LcdCounter - sizeof(LcdData1))], 1);
                    LcdCounter++;
                }
            }
            Delay_Us(1000);                                  // Debouncing
        }
        // First press of RD6 = clear the screen
        if ((_RD6 == 0) && (LcdFlag == 0))
        {
            home_clr();
            home_it();
            LcdFlag = 1;
            Delay_Us(1000);                                 // Debouncing
        }

        // If RD7 was pressed
        if ((_RD7 == 0))
        {
            if ((LcdCounter == sizeof(LcdData1)) && (LcdLine == 2))
            {
                lcd_cmd(0x8F);
                puts_lcd(&LcdSpace, 1);
                lcd_cmd(0x8F);
                LcdCounter--;
//                LcdLine = 1;
            }
            else
            {
                cursor_left();
                puts_lcd(&LcdSpace, 1);
                cursor_left();
                LcdCounter--;
            }


            Delay_Us(1000);                                 // Debouncing
        }

    } // End of the infinite While loop

    return 1;
}
Esempio n. 17
0
void xDelay100uS( void )
{
	Delay_Us(100);
}
Esempio n. 18
0
void xDelayAfterWrite( void )			/* д²Ù×÷ºóÑÓʱ */
{
	Delay_Us(200);
}