Exemple #1
0
 void LCD_i_write(BYTE v)
 {
     LCDWritePortA(0);
     DelayMs(1);
     LCDWritePortB(v);
     Nop();
     Nop();
     Nop();
     Nop();
     LCDWritePortA(0x40);
     Nop();
     Nop();
     Nop();
     Nop();
     Nop();
     Nop();
     LCDWritePortA(0x00);
     return;
 }
void wait(unsigned int count)
{
    /* count of 1 is approx 10.5us */
    volatile unsigned int x;
    
    for(x = 0; x < count; x++)
    {
        Nop();
    }    
}    
Exemple #3
0
void LCD_i_write(uint8_t v)
{
    LCDWritePortA(0);
    DELAY_ms(1);
    LCDWritePortB(v);
    Nop();
    Nop();
    Nop();
    Nop();
    LCDWritePortA(0x40);
    Nop();
    Nop();
    Nop();
    Nop();
    Nop();
    Nop();
    LCDWritePortA(0x00);
    return;
}
Exemple #4
0
void LCD_d_write(uint8_t v)
{
    DELAY_ms(1);
    LCDWritePortA(0x80);
    LCDWritePortB(v);
    Nop();
    Nop();
    Nop();
    Nop();
    LCDWritePortA(0xC0);
    Nop();
    Nop();
    Nop();
    Nop();
    Nop();
    Nop();
    LCDWritePortA(0);

} 
Exemple #5
0
/*********************************************************************
* Function:        RestartI2C()
* Overview:		Generates a restart condition and optionally returns status
********************************************************************/
unsigned int RestartI2C(void)
{
	//This function generates an I2C Restart condition and returns status 
	//of the Restart.

	I2C1CONbits.RSEN = 1;		//Generate Restart		
	Nop();
	while (I2C1CONbits.RSEN);	//Wait for restart	
	//return(I2C1STATbits.S);	//Optional - return status
}
Exemple #6
0
/*********************************************************************
* Function:        StopI2C()
* Overview:		Generates a bus stop condition
********************************************************************/
unsigned int StopI2C(void)
{
	//This function generates an I2C stop condition and returns status 
	//of the Stop.

	I2C1CONbits.PEN = 1;		//Generate Stop Condition
	Nop();
	while (I2C1CONbits.PEN);	//Wait for Stop
	//return(I2C1STATbits.P);	//Optional - return status
}
Exemple #7
0
 void LCD_d_write(BYTE v)
 {
     DelayMs(1);
     LCDWritePortA(0x80);
     LCDWritePortB(v);
     Nop();
     Nop();
     Nop();
     Nop();
     LCDWritePortA(0xC0);
     Nop();
     Nop();
     Nop();
     Nop();
     Nop();
     Nop();
     LCDWritePortA(0);
     
 } 
Exemple #8
0
unsigned int StartI2C(void)
{
	//This function generates an I2C start condition and returns status 
	//of the Start.

	I2C1CONbits.SEN = 1;		//Generate Start Condition
	Nop();
	while (I2C1CONbits.SEN);	//Wait for Start Condition
	//return(I2C1STATbits.S);	//Optionally return status
}
Exemple #9
0
void fpga_0clear(void)
{
//	while(BUSY!=0){}
	SLC=memory0set;
	SLT=0;
    SLT=1;
	Nop();
	SLT=0;

}
Exemple #10
0
void i2c_Start(char addr, char rw){
    I2C2CONbits.ACKDT = 0;
    int i=0;
    for(i=0;i<1000;i++)
        Nop();
    I2C2CONbits.SEN = 1;
    while(I2C2CONbits.SEN){};
    i2c_Write(addr | rw);

}
Exemple #11
0
void adxl345_get_xyz(PACC_XYZ adxl345) {
    ACC_CS = 0;
    SD_CS = 1;
    Nop();
    Nop();
    Nop();

    SPI_INTERRUPT_FLAG = 0;
    SPIBUF = 0xF2; // do a multiread of all 6 bytes (0b11[0x32: DATAX0])
    while (!SPI_INTERRUPT_FLAG);

    SPI_INTERRUPT_FLAG = 0;
    SPIBUF = 0x00;
    while (!SPI_INTERRUPT_FLAG);

    SPI_INTERRUPT_FLAG = 0;
    SPIBUF = 0x00;
    while (!SPI_INTERRUPT_FLAG);
    adxl345->x = SPIBUF;
    adxl345->x ^= 0x80;

    SPI_INTERRUPT_FLAG = 0;
    SPIBUF = 0x00;
    while (!SPI_INTERRUPT_FLAG);

    SPI_INTERRUPT_FLAG = 0;
    SPIBUF = 0x00;
    while (!SPI_INTERRUPT_FLAG);
    adxl345->y = SPIBUF;
    adxl345->y ^= 0x80;

    SPI_INTERRUPT_FLAG = 0;
    SPIBUF = 0x00;
    while (!SPI_INTERRUPT_FLAG);

    SPI_INTERRUPT_FLAG = 0;
    SPIBUF = 0x00;
    while (!SPI_INTERRUPT_FLAG);
    adxl345->z = SPIBUF;
    adxl345->z ^= 0x80;

    ACC_CS = 1;
}
Exemple #12
0
void K9F1208_Wdata(unsigned char data)//写数据
{
	K9F_Odata;//输出
	K9F_CLE=0;
	K9F_ALE=0;
	K9F_WE=0;
	K9F_O_data=data;
	Nop();
	K9F_WE=1;
}	
/********************************************************************
* Function: 	void GetCommand()
*
* Precondition: UART Setup
*
* Input: 		None.
*
* Output:		None.
*
* Side Effects:	None.
*
* Overview: 	Polls the UART to recieve a complete AN851 command.
*			 	Fills buffer[1024] with recieved data.
*
* Note:		 	None.
********************************************************************/
void GetCommand()
{
	BYTE RXByte;
	BYTE checksum;
	WORD dataCount;

	while(1){

		#ifndef USE_AUTOBAUD
        GetChar(&RXByte);                                                           //Get first STX
        if(RXByte == STX){
        #else
        AutoBaud();                                                                 //Get first STX and calculate baud rate
		RXByte = UxRXREG;                                                           //Dummy read
        #endif

		T2CONbits.TON = 0;                                                          //Disable timer - data received

		GetChar(&RXByte);                                                           //Read second byte
		if(RXByte == STX){                                                          //2 STX, beginning of data

			checksum = 0;                                                           //Reset checksum
			dataCount = 0;                                                          //Reset datacount

			while(dataCount <= MAX_PACKET_SIZE+1){                                  //Maximum num bytes to receive
				GetChar(&RXByte);
				switch(RXByte){
					case STX:                                                       //Start over if STX
						checksum = 0;
						dataCount = 0;
						break;

					case ETX:                                                       //End of packet if ETX
						checksum = ~checksum +1;                                    //Test checksum
						Nop();
						if(checksum == 0) return;                                   //Return if OK
						dataCount = 0xFFFF;                                         //Otherwise restart
						break;

					case DLE:                                                       //If DLE, treat next as data
						GetChar(&RXByte);
					default:                                                        //Get data, put in buffer
						checksum += RXByte;
						buffer[dataCount++] = RXByte;
						break;

				}                                                                   //End switch(RXByte)
			}                                                                       //End while(byteCount <= 1024)
		}                                                                           //End if(RXByte == STX)

        #ifndef USE_AUTOBAUD
        }                                                                           //End if(RXByte == STX)
        #endif
	}                                                                               //End while(1)
}                                                                                   //End GetCommand()
Exemple #14
0
/*****************************************************************************
  Function:
	static void GetTickCopy(void)

  Summary:
	Reads the tick value.

  Description:
	This function performs an interrupt-safe and synchronized read of the 
	48-bit Tick value.

  Precondition:
	None

  Parameters:
	None

  Returns:
  	None
  ***************************************************************************/
static void GetTickCopy(void)
{
	// Perform an Interrupt safe and synchronized read of the 48-bit 
	// tick value
#if defined(__18CXX) || defined (__SDCC__)
	do
	{
           INTCONbits.TMR0IE = 1;		// Enable interrupt
           Nop();
	   INTCONbits.TMR0IE = 0;		// Disable interrupt
	   vTickReading[0] = TMR0L;
	   vTickReading[1] = TMR0H;
	   *((DWORD*)&vTickReading[2]) = dwInternalTicks;
	} while(INTCONbits.TMR0IF);
	INTCONbits.TMR0IE = 1;			// Enable interrupt
#else
	do
	{
		DWORD dwTempTicks;
		
		IEC0bits.T1IE = 1;			// Enable interrupt
		Nop();
		IEC0bits.T1IE = 0;			// Disable interrupt
		
		// Get low 2 bytes
		((WORD*)vTickReading)[0] = TMR1;
		
		// Correct corner case where interrupt increments byte[4+] but 
		// TMR1 hasn't rolled over to 0x0000 yet
		dwTempTicks = dwInternalTicks;
		if(((WORD*)vTickReading)[0] == 0xFFFFu)
			dwTempTicks--;
		
		// Get high 4 bytes
		vTickReading[2] = ((BYTE*)&dwTempTicks)[0];
		vTickReading[3] = ((BYTE*)&dwTempTicks)[1];
		vTickReading[4] = ((BYTE*)&dwTempTicks)[2];
		vTickReading[5] = ((BYTE*)&dwTempTicks)[3];
	} while(IFS0bits.T1IF);
	IEC0bits.T1IE = 1;				// Enable interrupt
#endif
}
Exemple #15
0
Uint8 r_cv_read(){
    R_CV_Tris = 1;
    Nop();
    if(R_CV_Read){
        delayus(100);
        if(R_CV_Read){
            return true;
        }
    }
    return false;
}
void spi_sck_pulse(void)
{
	RPOR4bits.RP8R=0;// remove SPI CLK from pin
	SPICLK=0; // SCK low
	_delay_ms(0.10);
	SPICLK=1; // SCK high
	_delay_ms(0.10);
	SPICLK=0; // SCK low
	RPOR4bits.RP8R=SCK1OUT_IO; 	//reassign SPI CLK
	Nop();
}
Exemple #17
0
void osd_spi_write(char addr, char byte)
{
    OSD_CS = 1 ;				// Make sure we start with active-low CS high
    OSD_SCK = 0 ;				// and CK low

    OSD_CS = 0 ;				// Set active-low CS low to start the SPI cycle
    spi_write_raw_byte(addr) ;	// Send the Address
    spi_write_raw_byte(byte) ;	// Send the data

    OSD_CS = 1 ;				// Set active-low CS high to end the SPI cycle

    Nop();
    Nop();
    Nop();
    Nop();	// Kill some time with CS high to make a more solid pulse

    OSD_MOSI = 0 ;

    return ;
}
Exemple #18
0
// *------------------------------------------------------*
void vSST25ResetWriteProtection(void){
	
    SST25_CS=0;
    vSPIPut(SST25_CMD_EWSR);
    SST25_CS=1;
	Nop();
    SST25_CS=0;
    vSPIPut(SST25_CMD_WRSR);
    vSPIPut(0x00);
    SST25_CS=1;
}
Exemple #19
0
void DelayCount(void)
{
    unsigned short Delay;
    Delay = 0x8000;

    while (Delay>0)
    {
        Delay--;
        Nop();
    }
}
Exemple #20
0
Uint8 l_cl_read(){
    L_CL_Tris = 1;
    Nop();
    if(L_CL_Read==0){
        delayus(100);
        if(L_CL_Read==0){
            return true;
        }
    }
    return false;
}
void calcForces(tactileFrame_t* sensor, FORCEUNION* forces){

    Nop();
    int i,j;
    float A[3*ROWS*COLS];

    for (i = 0; i < ROWS*COLS; i++) {
        A[i*3] = (float) sensor->frame[i];
        A[i*3+1] = A[i*3]*A[i*3];
        A[i*3+2] = A[i*3+1]*A[i*3];
    }
    
    for (j = 0; j < 6; j++) {
        forces->F[j] = 0;
        for (i = 0; i < 3*ROWS*COLS; i++) {
            forces->F[j] += A[i]*N[j][i];
        }
    }
    Nop();
}
Exemple #22
0
Uint8 r_cl_hold_read(){
    R_CL_Hold_Tris = 1;
    Nop();
    if(R_CL_Hold_Read){
        delayus(100);
        if(R_CL_Hold_Read){
            return true;
        }
    }
    return false;
}
Exemple #23
0
Uint8 l_op_read(){
    L_OP_Tris = 1;
    Nop();
    if(L_OP_Read==0){
        delayus(100);
        if(L_OP_Read==0){
            return true;
        }
    }
    return false;
}
Exemple #24
0
Uint8 in_local(){
    Local_Tris = 1;
    Nop();
    if(Local_Read==0){
        delayus(100);
        if(Local_Read==0){
            return true;
        }
    }
    return false;
}
Exemple #25
0
Uint8 in_remote(){
    Remote_Tris = 1;
    Nop();
    if(Remote_Read==0){
        delayus(100);
        if(Remote_Read==0){
            return true;
        }
    }
    return false;
}
Exemple #26
0
Uint8 in_stop(){
    XN_STOP_Tris = 1;
    Nop();
    if(XN_STOP_Read){
        delayus(100);
        if(XN_STOP_Read){
            return true;
        }
    }
    return false;
}
Exemple #27
0
Uint8 phase_c_read(){
    Phase_C_Tris = 1;
    Nop();
    if(Phase_C_Read==0){
        delayus(100);
        if(Phase_C_Read==0){
            return false;
        }
    }
    return true;
}
Exemple #28
0
Uint8 r_esd_read(){
    R_ESD_Tris = 1;
    Nop();
    if(R_ESD_Read){
        delayus(100);
        if(R_ESD_Read){
            return true;
        }
    }
    return false;
}
Exemple #29
0
Uint8 r_op_read(){
    R_OP_Tris = 1;
    Nop();
    if(R_OP_Read){
        delayus(100);
        if(R_OP_Read){
            return true;
        }
    }
    return false;
}
Exemple #30
0
Uint8 r_st_read(){
    R_ST_Tris = 1;
    Nop();
    if(R_ST_Read){
        delayus(100);
        if(R_ST_Read){
            return true;
        }
    }
    return false;
}