Exemple #1
0
void LCDInit()
{
#ifdef P_S
LCD_PS=P_S;
#endif
LCD_CS=0;
ShortDelay(10);
LCD_CS=1;
ShortDelay(10);

     SendCMD(LCD12864_CMD_NORMAL);//功能设置,基本指令集
	 LongDelay(DELAY4MS);
#ifdef __USE_PARALLEL_MODE__ 
LongDelay(DELAY4MS);
#endif
	 SendCMD(LCD12864_CMD_DISP(1,0,0));//0000,1100  整体显示,游标off,游标位置off
     SendCMD(LCD12864_CMD_RSTDDRAM);//0000,0010 DDRAM地址归位
     LongDelay(DELAY4MS);
#ifdef __USE_PARALLEL_MODE__ 
LongDelay(DELAY4MS);
#endif
	 SendCMD(LCD12864_CMD_CLEAR);//0000,0001 清DDRAM
     LongDelay(DELAY4MS);
	 SendCMD(LCD12864_CMD_SETCUR(1,0));//点设定,显示字符/光标从左到右移位,DDRAM地址AC加1//   
#ifdef __USE_PARALLEL_MODE__ 
LongDelay(DELAY4MS);
LongDelay(DELAY4MS);
#endif
}
Exemple #2
0
void SendCMD(uchar cmd)//写指令
{
    LCD_CS=0;
	LCD_RW=0;
    LCD_RS=0;
    ShortDelay(DELAY8US);
	LCD_CS=1;
    LCDData=cmd;
    ShortDelay(DELAY8US);
    LCD_CS=0;   
}
Exemple #3
0
void SendData(uchar dat)//写数据
{
    LCD_CS=0;
	LCD_RW=0;
	LCD_RS=1;
	ShortDelay(DELAY8US);
	LCD_CS=1;
	LCDData=dat;
    ShortDelay(DELAY8US);
    LCD_CS=0; 

}	
Exemple #4
0
uchar SPI_Read() //读SPI时序
{
uchar dat;
uchar t = 8;
LCD_DATA = 1; //读取数据之前DIO 引脚要置1 以切换到输入状态
do
{
LCD_CLK = 1;
ShortDelay(2);
dat <<= 1;
if (LCD_DATA) dat++;
LCD_CLK = 0;
ShortDelay(2);
} while ( --t != 0 );
return dat;
}
Exemple #5
0
//��BF�Լ�AC��ֵ������Read_BF_AC()
uint Read_BF_AC()
{
	uint temp;
	InitP0(1);
	SetRS(0);
	SetRW(1);
	//ShortDelay(1);
	SetE(0);
	//ShortDelay(1);
	SetE(1);
	ShortDelay(1);
	temp = PinData;
	ShortDelay(10);
	SetE(0);
	//ShortDelay(1);
	SetRW(0);
	SetRS(1);
	return(temp);
	}
Exemple #6
0
/*
 * main.c
 */
int main(void) {

	WDTCTL = WDTPW|WDTHOLD;                 // stop the watchdog timer

	initMotors();
	
	while(1)
	{
		TurnLeft();
		ShortDelay();
		StopBot();
		Delay();
		TurnRight();
		ShortDelay();
		StopBot();
		Delay();
		MoveForward();
		Delay();
		StopBot();
		Delay();
		MoveBack();
		Delay();
		StopBot();
		Delay();
		TurnRight();
		Delay();
		StopBot();
		Delay();
		TurnLeft();
		Delay();
		StopBot();
		Delay();
		Delay();
		Delay();

	}

}
Exemple #7
0
void ResetI2C(void){
    int i=0;
    int j=0;
    I2CEnable(I2C1, FALSE);
    TRISBSET = 0x0200;
    if(PORTDbits.RD9==0){
        sprintf(NU32_RS232OutBuffer,"Bus is low...\r\n");
        WriteString(UART2,NU32_RS232OutBuffer);
      }
    TRISDCLR = 0x0400;
    while(PORTDbits.RD9==0){
        LATDbits.LATD10=!LATDbits.LATD10;
        sprintf(NU32_RS232OutBuffer,"Pulsing SCK...\r\n");
        WriteString(UART2,NU32_RS232OutBuffer);
        ShortDelay(400000);
     }
    sprintf(NU32_RS232OutBuffer,"SDA high...\r\n");
    WriteString(UART2,NU32_RS232OutBuffer);
    TRISDSET = 0x0400;
    ShortDelay(10000);
    I2CEnable(I2C1, TRUE);
    ShortDelay(50000);
    I2Cstopevent();
}
Exemple #8
0
//д���ݵ�RAM������WriteData()
void WriteData(uint data1)
{
	InitP0(0);
	SetRS(1);
	SetRW(0);
	//ShortDelay(1);
	SetE(0);
	PinData = data1;
	//ShortDelay(1);
	SetE(1);
	ShortDelay(10);
	SetE(0);
	//ShortDelay(1);
	SetRW(1);
	SetRS(0);
	}
Exemple #9
0
//дָ�����WriteInstruc()
void WriteInstruc(uint Instruc)
{
	while(StatusCheck());
	InitP0(0);
	SetRS(0);
	SetRW(0);
	//ShortDelay(1);
	SetE(0);
	PinData = Instruc;
	//ShortDelay(1);
	SetE(1);
	ShortDelay(10);
	SetE(0);
	//ShortDelay(1);
	SetRW(1);
	SetRS(1);
	}
Exemple #10
0
void InitializeIMU(void){

    I2Cinitialize();  //Turn on and initialize I2C module 1
    ShortDelay(5000);
    I2Cwrite((0x68 << 1)|I2C_WRITE, 0x6B, 0x00); //Initialize MPU6050
    ShortDelay(5000);
    I2Cwrite((0x68 << 1)|I2C_WRITE, 0x19, 0x01); //Set Sample Rate Divider
    ShortDelay(5000);
    I2Cwrite((0x68 << 1)|I2C_WRITE, 0x1A, 0x01); //Set DLPF
    ShortDelay(5000);
    I2Cwrite((0x68 << 1)|I2C_WRITE, 0x1B, 0x10); //Change Gyro sensitivity
    ShortDelay(5000);
    I2Cwrite((0x68 << 1)|I2C_WRITE, 0x6A, 0x00); //Disable Aux I2C
    ShortDelay(5000);
    I2Cwrite((0x68 << 1)|I2C_WRITE, 0x37, 0x02); //Aux I2C Bypass
    //WriteString(UART2,"Initialized MPU6050\r\n");
    ShortDelay(10000);
    I2Cwrite((0x1E << 1)|I2C_WRITE, 0x02, 0x00); //Initialize H
    ShortDelay(50000);
}
Exemple #11
0
int main(int argc, char** argv) {

    uchar status = 0;
    
    mPORTAClearBits(BIT_6);           //Clear bits to ensure the LED is off.
    //mPORTASetPinsDigitalOut(BIT_6);   //Set port as output
  
    // lets set the digital IO bits for the ethernet module
    mPORTASetPinsDigitalOut(BIT_7|BIT_6);
    mPORTGSetPinsDigitalOut(BIT_8 | BIT_9 | BIT_14 | BIT_0);
    mPORTBSetPinsDigitalOut(0x0000FFFF);
    mPORTESetPinsDigitalOut(0x000000FF);
    
    // set the control bits high
    mPORTASetBits(BIT_7);
    mPORTGSetBits(BIT_8 | BIT_9 | BIT_14);
    mPORTGClearBits(BIT_0);
    //mPORTGClearBits(BIT_0);
    //mPORTGClearBits(0x0000FFFF);
    //mPORTEClearBits(0x0000FFFF);
    //mPORTAClearBits(0x0000FFFF);
    //mPORTBClearBits(0x0000FFFF);
    
    //while(1){}

    // lets init the W5100
    struct W5100Context_t context;
    context.Mode = MR_RST;
    context.InterruptMask = 0xFF;
    context.RetryTimeValue = 0x0FA0; // 400 ms
    context.RetryCount = 1;
    
    context.GateAdd[0] = 10;
    context.GateAdd[1] = 1;
    context.GateAdd[2] = 1;
    context.GateAdd[3] = 3;
    
    context.SHardAdd[0] = 0;
    context.SHardAdd[1] = 1;
    context.SHardAdd[2] = 2;
    context.SHardAdd[3] = 3;
    context.SHardAdd[4] = 4;
    context.SHardAdd[5] = 5;
    
    context.Subnet[0] = 255;
    context.Subnet[1] = 255;
    context.Subnet[2] = 255;
    context.Subnet[3] = 0;
    
    context.SourceIP[0] = 10;
    context.SourceIP[1] = 1;
    context.SourceIP[2] = 1;
    context.SourceIP[3] = 2;
    
    context.sockets[0].Mem = MEM_2K;
    context.sockets[1].Mem = MEM_2K;
    context.sockets[2].Mem = MEM_2K;
    context.sockets[3].Mem = MEM_2K;
    
    ShortDelay_ms(100);
    
    W5100Init( &context );
  
    W5100ReadData(SHAR0, &status, 1);
    W5100ReadData(SHAR1, &status, 1);
    W5100ReadData(SHAR2, &status, 1);
    W5100ReadData(SHAR3, &status, 1);
    W5100ReadData(SHAR4, &status, 1);
    W5100ReadData(SHAR5, &status, 1);
    
    EstablishServer(&context);
    
    // lets try a random write
    //W5100WriteData(0x001A, 0x07, 1);
    //mPORTEWrite(0x07);
    
    
  
    
     while(1)
     {
     
        status = W5100PollStatus(&context, 0);
        if( status == SOCK_ESTABLISH)
            mPORTGSetBits(BIT_0);
        else
            mPORTGClearBits(BIT_0);
        
        if( status == SOCK_CLOSE_WAIT)
            EstablishServer(&context);
        
        
         //PORTAbits.RA2 = ~PORTAbits.RA2;
        mPORTAToggleBits(BIT_6);
        ShortDelay(US_TO_CT_TICKS*1000000);
        //delay_millis(1000);
   
     }
     
    return (EXIT_SUCCESS);
}