Example #1
0
int AUD_Init(void)
{
    GPIO_InitTypeDef GPIO_InitStructure;

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD|RCC_APB2Periph_AFIO,ENABLE);

    GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_Out_OD;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

    GPIO_InitStructure.GPIO_Pin   = AUD_DAT;
    GPIO_Init(GPIOD, &GPIO_InitStructure);

    GPIO_InitStructure.GPIO_Pin   = AUD_RST;
    GPIO_Init(GPIOD, &GPIO_InitStructure);

    GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_IPU;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

    GPIO_InitStructure.GPIO_Pin   = AUD_BUSY;
    GPIO_Init(GPIOD, &GPIO_InitStructure);

	DAT_L();
	RST_L();
	Delay_Ms(1); 
//	rt_thread_delay(1);
	RST_H();
//	rt_thread_delay(1);
	Delay_Ms(1);
	RST_L();

	return 0;
}
int MPU9250_AK8963_SPIx_Writes(u8 akm_addr, u8 reg_addr, u8 len, u8* data)
{
	u32 timeout = 0;
	uint8_t status = 0;
	u8 tmp = 0;
	u8 index = 0;

	tmp = akm_addr;
	MPU9250_SPIx_Writes(MPU9250_SPIx_ADDR, MPU9250_I2C_SLV4_ADDR, 1, &tmp);
	Delay_Ms(1);

	while(index < len){
		tmp = reg_addr + index;
		MPU9250_SPIx_Writes(MPU9250_SPIx_ADDR, MPU9250_I2C_SLV4_REG, 1, &tmp);
		Delay_Ms(1);
		MPU9250_SPIx_Writes(MPU9250_SPIx_ADDR, MPU9250_I2C_SLV4_DO, 1, data + index);
		Delay_Ms(1);
		tmp = MPU9250_I2C_SLV4_EN;
		MPU9250_SPIx_Writes(MPU9250_SPIx_ADDR, MPU9250_I2C_SLV4_CTRL, 1, &tmp);
		Delay_Ms(1);

		do {
			if (timeout++ > 50)
				return -2;
			MPU9250_SPIx_Reads(MPU9250_SPIx_ADDR, MPU9250_I2C_MST_STATUS, 1, &status);
			Delay_Ms(1);
		} while ((status & MPU9250_I2C_SLV4_DONE) == 0);
		if (status & MPU9250_I2C_SLV4_NACK)
			return -3;
		index++;
	}
	return 0;
}
/**
    Stores a given int by splitting it into low and high order bits
    and puts them into banks next to each other
    
    @param eepromadrs - the starting address in EEPROM to store the split int
    @param val - the int to be stored
*/
void storeAn3(char eepromadrs, int val)
{
    EEPROM_Write(eepromadrs, val & 0xFF);
    Delay_Ms(5);
    EEPROM_Write(eepromadrs + 1, (val >> 8) & 0xFF);
    Delay_Ms(5);
}
Example #4
0
unsigned short le_carac()
{
   if (COD_PORTB() == INT_0){ Delay_Ms(50);
   while (COD_PORTB() == INT_0); return('1'); }
   if (COD_PORTB() == INT_1){ Delay_Ms(50);
   while (COD_PORTB() == INT_1); return('2'); }
   if (COD_PORTB() == INT_2){ Delay_Ms(50);
   while (COD_PORTB() == INT_2); return('3'); }
   if (COD_PORTC() == INT_TMR_2){ Delay_Ms(50);
   while (COD_PORTC() == INT_TMR_2); return('4'); }

   return(255);
}
Example #5
0
void testTimerCNT(void)
{
	//float us_in=0.00;
    while(1){
        //Start_CNT();
        Delay_Ms(3);
		//us_in = getCNT_Us();
        //printf("%Us:%f\r\n",us_in);
        //Start_CNT();
        Delay_Ms(3);
        //Stop_CNT();
        //printf("Ms:%f\r\n",getCNT_Ms());
    }
}
/**************************************************************************************************
* MAIN PROGRAM
**************************************************************************************************/
void main()
{
/*SDA_pin_out = 1;
  // Start the test example
  while(1)                           // Endless loop
  {
    //Read_SHT11(&temperature, &rel_humidity);
    Transmit_results();
    Delay_ms(800);                   // delay 800ms
  }*/
  
  Init_MCU();                            // Initialize the MCU
  while(1) {
    if (User_Button == 0)  {  // If PORTD.B0 is pressed :
      UART6_Write_Text("EchoTest\r");    // send text string
      Delay_ms(250);                     // wait for 250ms
    }

    if(Received){                        // If data is received via UART :
      LED_RED = 1;
      Delay_Ms(1000);
      LED_RED = 0;
      Received = 0;                      // clear received data flag
      Delay_ms(250);                     // wait for 250ms
    }
  }
}
/**
 * @brief 实现键盘的相关功能
 * 检测键盘是否被按下并对L与H进行加减
 * 
 */
void key()
{
    Key_value = P3; //4个独立按键占P3^0~P3^3
    Key_value = Key_value & 0x0f;
    if (Key_value != 0x0f) //如果有按键被按下
    {
        Delay_Ms(10);
        if (Key_value != 0x0f)
        {
            switch (Key_value)
            {
            case 0x0e:
                H++;
                break;

            case 0x0d:
                H--;
                break;

            case 0x0b:
                L++;
                break;

            case 0x07:
                L--;
                break;
            }
        }
    }
}
Example #8
0
int main()
{

	unsigned int i, j = 0;

   volatile unsigned int *pLcdDestReg = (volatile unsigned int*)(LCD_DEST_REG_ADDR);
   volatile unsigned int *pLcdWidthReg = (volatile unsigned int*)(LCD_WIDTH_REG_ADDR);
   volatile unsigned int *pLcdHeightReg = (volatile unsigned int*)(LCD_HEIGHT_REG_ADDR);
   volatile unsigned int *pLcdCmdReg = (volatile unsigned int*)(LCD_CMD_REG_ADDR);

   volatile unsigned int *pCam = (volatile unsigned int*)(OV7670_0_BASE | 0x80000000);
   volatile unsigned char pid[2] = {0,0};

  *pLcdCmdReg = 0; // make sure that the DMA is stopped before calling the LCD init functions
  *pCam = 0;
  LCD_Init();
  LCD_Clear(0X00ff);
  //init_lcd_frame();



   printf("%x\n", lcd_frame);

   *pCam = 1; // turns the camera ON. Camera turns on with the next new frame
   Delay_Ms(2000); // add delay to be sure that frames are already in the memory

   *pLcdDestReg = LT24_CONTROLLER_0_BASE + 4;
   *pLcdWidthReg = 240; // LCD width
   *pLcdHeightReg = 320; // LCD height
   *pLcdCmdReg = 0x1f00000; // by default camera throws images starting from here
   *pLcdCmdReg |= 0x80000000; // this commands turns the LCD ON



}
Example #9
0
/*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
** 函数名称: main
** 功能描述: 主函数入口
** 参数描述:这个程序演示了串口收发程序 ,接收是采用中断方式
				你可以输入键盘上的任意值 电脑超级终端将以十进制输出你输入的数值
				比如:1对应十进制是49;2对应于50;a对应于97;这个你懂!!!
** 作   者: xt
** 日   期: 2011年6月20日
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
int main(void)
{
    SystemInit();					//系统时钟配置
    Init_NVIC();					//中断向量表注册函数
    Init_LED();						//各个外设引脚配置

    Init_Usart();					//串口引脚配置			//Usart
    Usart_Configuration(115200);	//串口配置 设置波特率为115200    //Usart

    lcd12864_WaitBusy();	       //lcd12864
    lcd12864_WriteCmd();	       //lcd12864
    lcd12864_WriteData();	       //lcd12864
    lcd12864_InitDis();		       //lcd12864
//	lcd12864_locate16(1,1);	       //lcd12864
//	lcd12864_DisStr("abcdefg");	   //lcd12864

    ADC1_GPIO_Config();	           //温度ADC1
    ADC1_MODE_Config();			   //温度ADC1


//	printf(menu);					//输出字符串
//	printf("贝一特助你开启STM32大门,让你轻松入门!!\n\r");
//	printf("请输入键盘上的任意字符,串口将以十进制输出你输入的字符\n\r");
    while(1)
    {
        LED1=~LED1;
        Delay_Ms(200);				 //LED1闪烁,系统正在运行
        ADC_ConvertedValue_Temper_LocalValue=ADC_ConvertedValue;
        Delay_Ms(200);
        inter_temper=(1.43-ADC_ConvertedValue_Temper_LocalValue*3.3/4096)/0.0043+25;
        printf("当前温度=%d\tADC1的采集值=%3d",inter_temper,ADC_ConvertedValue_Temper_LocalValue);
        lcd12864_WriteCmd(0x80);
        lcd12864_DisStr("当前温度=");
        lcd12864_WriteCmd(0x87);
        lcd12864_DisStr("度");
        a=(unsigned char)inter_temper/10;
        b=(unsigned char)inter_temper%10;
        c=a+0x30;
        lcd12864_WriteCmd(0x85);
        lcd12864_WriteData(c);
        c=b+0x30;
        lcd12864_WriteCmd(0x86);
        lcd12864_WriteData(c);

    }
}
/**
    Retrieves two values from EEPROM from the selected EEPROM location
    and adds them together to get the original int back from the store
    function
    
    @param eepromadrs - teh starting address in EEPROM to retrieve the values from
    @return - value in eepromadrs + eepromadrs+1 left shifted 8 (low + high order bits)
*/
int getAn3(char eepromadrs)
{
    int val1;
    int val2;

    val1 = EEPROM_read(eepromadrs);
    Delay_Ms(5);
    val2 = EEPROM_read(eepromadrs + 1);
    return ((val1 & 0xFF) + ((val2 << 8) & 0xFF00));
}
Example #11
0
void DAControlLED()
{
    uchar i = 0; //i取值0~255,代表D/转换的数字量。
    I2C_Init();  //I2C总线初始化
    while (1)
    {
        I2C_DAC_WriteData(i);
        i++;
        Delay_Ms(20);
    }
}
Example #12
0
/****************************************************************************//**
 * @brief        Main LED Blinking Program
 *               Blink the LED Which is Selected
 * @param[in]	 LED Which We Want to Blink
 * @return		 LED will Get Blink
 *******************************************************************************/
void main (void)
{
	Sys_Init();												// Initialize the System

	/* Loop Forever */
	while(1)
	{
		GPIO_toggleOutputOnPin(GPIO_PORT_P5,GPIO_PIN1);		// Toggle the Output Pin Selected

		Delay_Ms(1000);										// Provides Delay in ms
	}
}
/**************************************************************************************************
* Transmit result to Receiver
**************************************************************************************************/
void Transmit_results(){
  char i;
  UART6_Write_Text("Test Data\r\n");
  Delay_Ms(2000);
/*sprintf(Temp_str, "T: %3.1f degC", temperature);
  sprintf(Humi_str, "RH: %3.1f pct", rel_humidity);*/

/*for (i = 0; i < 16; i++){
    Old_Temp_str[i] = Temp_str[i];
    Old_Humi_str[i] = Humi_str[i];
  }*/
}
Example #14
0
void testUSART(void)
{
    u8 temp,recvNum;
    while(1){
        recvNum=uxQueueMessagesWaiting(xRxedChars);
        printf("Hello world!,rec=%d\r\n",recvNum);
        Delay_Ms(500);

        if(recvNum>0)
        {
            while(recvNum--){
                xSerialGetChar((signed char*)&temp,0);
                xSerialPutChar(temp , 5/portTICK_RATE_MS);
            }
            //xSerialPutChar('\r' , 5/portTICK_RATE_MS);
            //xSerialPutChar('\n' , 5/portTICK_RATE_MS);
        }

        Delay_Ms(300);

    }
}
/**
 * @brief 主函数
 * 
 */
void DS18B20Example0()
{
    float i;
    char temp[8];

    DS18B20_SendChangeCmd();

    LCD1602_Init();

    LCD1602_Write_Com(0x80 + 0 + 3); //写位置指针
    LCD1602_Write_Dat('H');          //写入显示值
    LCD1602_Write_Com(0x80 + 0 + 8);
    LCD1602_Write_Dat('L');

    LCD1602_Write_String(0, 1, "TEMP:");
    Delay_Ms(1000);

    H = 40;
    L = 10;
    while (1)
    {
        i = DS18B20_GetTmpValue(); //获取温度值float类型
        DS18B20_SendChangeCmd();
        DS18B20_temperToStr(i, temp);               //将温度值转化为string
        LCD1602_Write_String(7, 1, temp);           //写温度
        LCD1602_Write_String(5, 0, uchartostr(H));  //写H
        LCD1602_Write_String(10, 0, uchartostr(L)); //写L
        if (i >= H || i <= L)
        {
            beep = 0;
        }
        else
        {
            beep = 1;
        }
        key();
        Delay_Ms(200);
    }
}
Example #16
0
void CH375_Test(void)
{
	UINT8 err = 0;
	UINT32 i = 0;

	CH375_PortInit();


	err = CH375LibInit();

	gErr = err;


	while(1)
	{
	  	while(CH375DiskStatus != DISK_CONNECT) 
			xQueryInterrupt();
		OSTimeDlyHMSM(0, 0, 0, 200);
#if 1		
		for(i = 0; i < 5; i++)
		{
			Delay_Ms(100);
			if(CH375DiskReady() == ERR_SUCCESS)
			{
				break;
			}			
		}
#endif
		mStrcpy((char*)mCmdParam.Open.mPathName, "/TEST.TXT");
		err = CH375FileOpen();
		if(err != ERR_SUCCESS)
			break;

		mCmdParam.ByteLocate.mByteOffset = 0xffffffff;
		err = CH375ByteLocate();
	   	if(err != ERR_SUCCESS)
			break;

		i = mStrcpy(mCmdParam.ByteWrite.mByteBuffer, "This is a test");
		mCmdParam.ByteWrite.mByteCount = i;
		err = CH375ByteWrite();
	   	if(err != ERR_SUCCESS)
			break;

		err = CH375FileClose();
	   	if(err != ERR_SUCCESS)
			break;
		break;
	}
	while(1);
}
Example #17
0
void DispInit(void)
{	
	LcdInit();
	LCD_OFF();
	GUI_Init();	
  GUI_SetBkColor(GUI_BLACK);
  GUI_Clear();
	GUI_SetDrawMode(GUI_DRAWMODE_NORMAL);
	GUI_DrawBitmap(&bm_yanghe_logo,0,0);
	LCD_ON();
	Delay_Ms(2000);
	GUI_SetFont(&GUI_NOW_FONT);
	Display_Welcome();
}
int MPU9250_AK8963_SPIx_Read(u8 akm_addr, u8 reg_addr, u8* data) {
	u8 status = 0;
	u32 timeout = 0;

	MPU9250_SPIx_Writes(MPU9250_SPIx_ADDR, MPU9250_I2C_SLV4_REG, 1, &reg_addr);
	Delay_Ms(1);
	reg_addr = akm_addr | MPU9250_I2C_READ;
	MPU9250_SPIx_Writes(MPU9250_SPIx_ADDR, MPU9250_I2C_SLV4_ADDR, 1, &reg_addr);
	Delay_Ms(1);
	reg_addr = MPU9250_I2C_SLV4_EN;
	MPU9250_SPIx_Writes(MPU9250_SPIx_ADDR, MPU9250_I2C_SLV4_CTRL, 1, &reg_addr);
	Delay_Ms(1);

	do {
		if (timeout++ > 50){
			return -2;
		}
		MPU9250_SPIx_Reads(MPU9250_SPIx_ADDR, MPU9250_I2C_MST_STATUS, 1, &status);
		Delay_Ms(1);
	} while ((status & MPU9250_I2C_SLV4_DONE) == 0);
	MPU9250_SPIx_Reads(MPU9250_SPIx_ADDR, MPU9250_I2C_SLV4_DI, 1, data);
	return 0;
}
Example #19
0
int AUD_Play(uint32_t index)
{
	if( index > MAX_AUD_NUM	)
		return -1;

	RST_H();
	//rt_thread_delay(1);
	Delay_Ms(1);
	RST_L();
	//rt_thread_delay(1);
	Delay_Ms(1);
	do
	{
		DAT_H();
		//rt_thread_delay(1); 
   Delay_Ms(1);		
		DAT_L();
		//rt_thread_delay(1); 
		Delay_Ms(1);
	}while(index--);

	return 0;
}
Example #20
0
static void  LCD_Config (void)
{
    SPI_InitTypeDef   SPI_init;
    GPIO_InitTypeDef  gpio_init;
    
    gpio_init.GPIO_Pin   = LCD_PWR_Pin;
    gpio_init.GPIO_Speed = GPIO_Speed_50MHz;
    gpio_init.GPIO_Mode  = GPIO_Mode_Out_PP;
    GPIO_Init(LCD_PWR_Port, &gpio_init);    
    
    gpio_init.GPIO_Pin   = LCD_RST_Pin | LCD_DC_Pin | LCD_CS_Pin;
    gpio_init.GPIO_Speed = GPIO_Speed_50MHz;
    gpio_init.GPIO_Mode  = GPIO_Mode_Out_PP;
    GPIO_Init(GPIOB, &gpio_init);
    
    // for SPI interface
    gpio_init.GPIO_Pin   = LCD_SCK_Pin | LCD_MOSI_Pin;
    gpio_init.GPIO_Speed = GPIO_Speed_50MHz;
    gpio_init.GPIO_Mode  = GPIO_Mode_AF_PP;
    GPIO_Init(GPIOB, &gpio_init);
    
    // enable OLED PWREN vcc = 16v
    GPIO_ResetBits(LCD_PWR_Port, LCD_PWR_Pin);

		GPIO_ResetBits(LCD_CS_Port, LCD_CS_Pin);   
    GPIO_ResetBits(LCD_RST_Port, LCD_RST_Pin);
    Delay_Ms(10);
    GPIO_SetBits(LCD_RST_Port, LCD_RST_Pin); 
    GPIO_SetBits(LCD_CS_Port, LCD_CS_Pin);

    SPI_init.SPI_Direction = SPI_Direction_1Line_Tx;
    SPI_init.SPI_Mode = SPI_Mode_Master;
    SPI_init.SPI_DataSize = SPI_DataSize_8b;
    SPI_init.SPI_CPOL = SPI_CPOL_High;
    SPI_init.SPI_CPHA = SPI_CPHA_2Edge;
    SPI_init.SPI_NSS = SPI_NSS_Soft;
    SPI_init.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;
    SPI_init.SPI_FirstBit = SPI_FirstBit_MSB;
    SPI_init.SPI_CRCPolynomial = 7;


    SPI_I2S_DeInit(SPI2); 
    SPI_Cmd(SPI2, DISABLE); 
    SPI_Init(SPI2, &SPI_init); 
    SPI_Cmd(SPI2, ENABLE);
    SPI_CalculateCRC(SPI2, DISABLE);
}
Example #21
0
void testPinSellected(void)
{
    //功能选择
    if(read_KEY_4==Bit_SET)
    {
        //====================================
        //查询IO,确认是否需要清除EEPROM-------------------IO_1-->Clear All
        if(read_KEY_1==Bit_SET)
        {
            //printf("I'll clear EEPROM U12\r\n");
            //printf("%d:%d\r\n",i,ReadeOneInt_24Cxx(dev,(i&0xFFFC) )  );
            //clearALL_INT_24Cxx(U12);
            //check_clear_24Cxx(U12);
            //printf("Check Clear EEPROM Done\r\n");

        }

        //====================================
        //查询IO,确认是否需要读取EEPROM---------------------IO_2-->Read All
        if(read_KEY_2==Bit_SET)
        {
            //printf("I'll Read EEPROM U12\r\n");
            readALL_INT_24Cxx(U12);
            //printf("Check Clear EEPROM Done\r\n");
        }
        //====================================
        //查询IO,确认是否需要写全EEPROM---------------------IO_3-->Fill All
        if(read_KEY_3==Bit_SET)
        {
            copyrALL_INT_24Cxx(U9,U12);
            //printf("I'llfillALL_TMP102_24Cxx(U12)\r\n");
            fillALL_TMP102_24Cxx(U12);
            //printf("Check Clear EEPROM Done\r\n");
        }


    }

    while(read_KEY_4==Bit_SET)
    {
        ChangeLED();
        Delay_Ms(300);

    }
}
Example #22
0
/*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
** 函数名称: main
** 功能描述: 主函数入口
** 参数描述:这个程序演示了串口收发程序 ,接收是采用中断方式
				你可以输入键盘上的任意值 电脑超级终端将以十进制输出你输入的数值 
				比如:1对应十进制是49;2对应于50;a对应于97;这个你懂!!!
** 作   者: XT
** 日   期: 2011年6月20日
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
int main(void)
{
	SystemInit();					//系统时钟配置
	Init_NVIC();					//中断向量表注册函数
	Init_LED();						//各个外设引脚配置
	Init_Usart();					//串口引脚配置
	Usart_Configuration(115200);	//串口配置 设置波特率为115200

	lcd12864_WaitBusy();
	lcd12864_WriteCmd();
	lcd12864_WriteData();
	lcd12864_InitDis();
	lcd12864_DisStr("套");

//	printf("哈哈\n\r");
//	printf("请输入键盘上的任意字符,串口将以十进制输出你输入的字符\n\r");		   
	while(1)													
	{  
		LED1=~LED1;	   				
		Delay_Ms(200);				 //LED1闪烁,系统正在运行
	}
}
Example #23
0
/**
 * @brief 扫描矩阵键盘,返回扫描码
 * 扫描码约定:
 * “0”为有效
 * 高四位从低→高表示按键1~4列
 * 低四位从低→高表示第1~4行
 * 所有按键未按下则返回0xff
 * @return uchar
 */
uchar KeyScan(void)          //键盘扫描函数,使用行列反转扫描法
{                            //采用矩阵按键。P30~P33行线,P34~P37列线
    uchar cord_h, cord_l;    //行列值中间变量
    KeyPort = 0x0f;          //列线输出全为0
    cord_h = KeyPort & 0x0f; //读入行线值
    if (cord_h != 0x0f)      //先检测有无按键按下
    {
        Delay_Ms(10); //去抖
        if ((KeyPort & 0x0f) != 0x0f)
        {
            cord_h = KeyPort & 0x0f; //读入行线值
            KeyPort = cord_h | 0xf0; //输出当前行线值
            cord_l = KeyPort & 0xf0; //读入列线值

            while ((KeyPort & 0xf0) != 0xf0)
                ; //等待松开并输出

            return (cord_h + cord_l); //键盘最后组合码值
        }
    }
    return (0xff); //返回该值
}
/**
    Displays a graph based off reading from AN3 every 50ms
    for 64 points. When plotting is finished min, max and mean values
    are displayed.
*/
void runGraph()
{
    int an3;
    int min;
    int max;
    unsigned int mean;
    char i;
    
    for(i = 0; i < 64; i++)
    {
        an3 = ADC_Read(3);
        
        if(i==0)min = an3;
        if(an3 > max)max = an3;
        if(an3 < min)min = an3;
        mean += an3;

        Glcd_V_Line(32,(32-(an3/32)),63+i,1);
        Delay_Ms(50);
    }
    intOut(26, 0, min);
    intOut(26, 10, max);
    intOut(26, 20, mean = (mean/64));
}
Example #25
0
/*主函数*/
void main()
{
	INT8U Temp_Key; //存放按键处理值
	BOOL I2C_OK;	//I2C读写是否成功(1成功,0失败)

	LCD1602_Init();  //LCD1602初始化
	IR_TX_RX_Init(); //IR发送、接收初始化
	I2C_Init();		 //I2C初始化
	Delay_Ms(50);

	LCD1602_Write_String(0, 0, "Welcome to use!");
	LCD1602_Write_String(0, 1, "IR Remote Module"); //欢迎文字
	Delay_Ms(5000);									//5秒延时

	LCD1602_Clear(); //LCD1602清屏
	LCD1602_Write_String(0, 0, "Switch Mode!");
	LCD1602_Write_String(0, 1, "Default CopyMode"); //功能选择提示文字

	while (1)
	{
		if (IR_RX_Finish) //IR是否接收完成
		{
			IR_RX_Finish = 0;
			LCD1602_Clear();

			/*LCD1602以16进制显示IR接收到的用户名与键值码*/
			LCD1602_Write_String(0, 1, INT8UtostrHEX(IR_RX_CODE[0]));
			LCD1602_Write_String(3, 1, INT8UtostrHEX(IR_RX_CODE[1]));
			LCD1602_Write_String(7, 1, INT8UtostrHEX(IR_RX_CODE[2]));
			LCD1602_Write_String(10, 1, INT8UtostrHEX(IR_RX_CODE[3]));
		}
		Temp_Key = KeyPro(); //提取按键处理值
		if (KeyPro_OK)		 //按键处理是否成功
		{
			KeyPro_OK = 0;
			if (TorR_Mod) //选择为发送模式
			{
				if (Temp_Key != 0xfd) //非选择模式按键按下(S3,发送模式)
				{
					do
					{
						I2C_OK = I2C_ReadData(Temp_Key);
					} while (!I2C_OK); //等待I2C读取发送码成功

					Transmit_TR_CODE(); //发送红外编码
					LCD1602_Clear();

					LCD1602_Write_String(0, 1, INT8UtostrHEX(Temp_Key)); //显示学习按键值
					LCD1602_Write_String(5, 1, INT8UtostrHEX(I2C_OK));   //显示成功读取IR_TX_CODE

					/*LCD1602以16进制显示从I2C取出的IR_TX_CODE*/
					LCD1602_Write_String(0, 0, INT8UtostrHEX(IR_TX_CODE[0]));
					LCD1602_Write_String(3, 0, INT8UtostrHEX(IR_TX_CODE[1]));
					LCD1602_Write_String(7, 0, INT8UtostrHEX(IR_TX_CODE[2]));
					LCD1602_Write_String(10, 0, INT8UtostrHEX(IR_TX_CODE[3]));
				}
				else //选择模式按键按下(S3)
				{
					LCD1602_Clear();
					LCD1602_Write_String(0, 0, "IR Transmit Mode");
					LCD1602_Write_String(3, 1, "Please Key!");
				}
			}
			else //学习模式
			{
				if (Temp_Key != 0xfe) //非选择模式按键按下(S2,学习模式)
				{
					LCD1602_Clear();
					LCD1602_Write_String(14, 1, INT8UtostrHEX(Temp_Key)); //显示按键值
					do
					{
						I2C_OK = I2C_WriteData(Temp_Key);
					} while (!I2C_OK);									//等待将接收红外码存入I2C成功

					LCD1602_Write_String(14, 0, INT8UtostrHEX(I2C_OK)); //显示存入成功
					Delay_Ms(100);
					/*从I2C读取刚存入的IR学习码*/
					I2C_ReadData(Temp_Key);
					LCD1602_Write_String(0, 0, INT8UtostrHEX(IR_TX_CODE[0]));
					LCD1602_Write_String(3, 0, INT8UtostrHEX(IR_TX_CODE[1]));
					LCD1602_Write_String(7, 0, INT8UtostrHEX(IR_TX_CODE[2]));
					LCD1602_Write_String(10, 0, INT8UtostrHEX(IR_TX_CODE[3]));
				}
				else //选择模式按键按下(S2,学习模式)
				{
					LCD1602_Clear();
					LCD1602_Write_String(0, 0, "IRcode Copy Mode");
					LCD1602_Write_String(0, 1, "Please In IRcode");
				}
			}
		}
	}
}
Example #26
0
void delay( uint32_t ms )
{
	Delay_Ms(ms);
}
Example #27
0
void LCD_Init(void)
{
	LCD_Bus_Init();

	Set_Cs;
	Set_Rs;
	Set_nWr;
	Set_nRd;
	Clr_Rst;
	Delay_Ms(10);
	Set_Rst;
	Delay_Ms(10);
	Lcd_Light_ON;

	//driving ability
	LCD_WriteReg(0xEA, 0x0000);
	LCD_WriteReg(0xEB, 0x0020);
	LCD_WriteReg(0xEC, 0x000C);
	LCD_WriteReg(0xED, 0x00C4);
	LCD_WriteReg(0xE8, 0x0040);
	LCD_WriteReg(0xE9, 0x0038);
	LCD_WriteReg(0xF1, 0x0001);
	LCD_WriteReg(0xF2, 0x0010);
	LCD_WriteReg(0x27, 0x00A3);

	//power voltage
	LCD_WriteReg(0x1B, 0x001B);
	LCD_WriteReg(0x1A, 0x0001);
	LCD_WriteReg(0x24, 0x002F);
	LCD_WriteReg(0x25, 0x0057);

	//VCOM offset
	LCD_WriteReg(0x23, 0x008D); //for flicker adjust

	//power on
	LCD_WriteReg(0x18, 0x0036);
	LCD_WriteReg(0x19, 0x0001); //start osc
	LCD_WriteReg(0x01, 0x0000); //wakeup
	LCD_WriteReg(0x1F, 0x0088);
	Delay_Ms(5);
	LCD_WriteReg(0x1F, 0x0080);
	Delay_Ms(5);
	LCD_WriteReg(0x1F, 0x0090);
	Delay_Ms(5);
	LCD_WriteReg(0x1F, 0x00D0);
	Delay_Ms(5);

	//color selection
	LCD_WriteReg(0x17, 0x0005); //0x0005=65k, 0x0006=262k

	//panel characteristic
	LCD_WriteReg(0x36, 0x0000);

	//display on
	LCD_WriteReg(0x28, 0x0038);
	Delay_Ms(40);
	LCD_WriteReg(0x28, 0x003C);

	//display options
	LCD_WriteReg(0x16, 0x00A8); //MY=1 MX=0 MV=1 ML=0 BGR=1

	LCD_Area(0, 0, (LCD_WIDTH-1), (LCD_HEIGHT-1));
}
Example #28
0
/**********************************************************************
**函数原型:     void 	InitNic()            
**说    明:对芯片的工作寄存器进行设置,各个寄存器的用法可参考文档和
**				 络芯片的数据手册
************************************************************************/
void etherdev_init(void)
{	unsigned char temp;
	ETH_RST_PIN=0;             //reset
	Delay_Ms(60);
	ETH_RST_PIN=1;
	Delay_Ms(50);
	ETH_RST_PIN=0; 
	Delay_Ms(100);

	//use reset port to reset the ic
	temp=Reg18;
	Reg18=temp;

	if(Reg04 & 0x80)	   //ISR.RST
	{
		xlog("nic reset fail\r\n");
		for(;;)
		{
			P1_7 = 0;
			P1_6 = 0;
			Delay_Ms(200);
			P1_7 = 1;
			P1_6 = 1;
			Delay_Ms(200);
		}
	}
	else
	{
		xlog("nic reset ok\r\n");
	}


	Reg00=0x21;   //使芯片处于停止模式,这时进行寄存器设置
	Delay_Ms(100); //延时10毫秒,确保芯片进入停止模式
	

	if((Reg0a != 0x50) || (Reg0b != 0x70))
	{
		xlog("nic id error\r\n");
		for(;;)
		{
			P1_7 = 1;
			P1_6 = 0;
			Delay_Ms(200);
			P1_7 = 0;
			P1_6 = 1;
			Delay_Ms(200);
		}
	}
	else
	{
		xlog("nic id correct\r\n");
	}


	page(0);
	Reg0a=0x00;   //清rbcr0
	Reg0b=0x00;   //清rbcr1
	Reg0c= 0xe0;  //RCR,监视模式,不接收数据包
	Reg0d= 0xe2;  //TCR,loop back模式
	
	Reg01=0x4c;

//	Reg02=0x80;
	Reg02=0x60;
	Reg03=0x4c;
	Reg04=0x40;  //TPSR,发送起始页寄存器
	Reg07=0xff;  //清除所有中断标志位,中断状态寄存器
	Reg0f=0x00;  //中断屏蔽寄存器清0,禁止中断
	
	Reg0e=0xc8;  // 数据配置寄存器,8位dma方式
	page(1);
	Reg07=0x4d;
	Reg08=0x00;
	Reg09=0x00;
	Reg0a=0x00;
	Reg0b=0x00;
	Reg0c=0x00;
	Reg0d=0x00;
	Reg0e=0x00;
	Reg0f=0x00;
	Reg00=0x22;  //这时让芯片开始工作   
	Set_Mac();  //将芯片物理地址写入到MAR寄存器
  
	page(0);
	//Reg0c=0xcc;  //将芯片设置成正常模式,跟外部网络连接
	Reg0c=0xc4;	   //接收广播,不接收多播
	Reg0d=0xe0;
	
	Reg00=0x22;  //启动芯片开始工作
	Reg07=0xff;  //清除所有中断标志位
    
	TR0  = 0;          
	// Set timer/ counter 0 as mode 1 16 bit timer.      
	TMOD &= 0xF0;
	TMOD |= 0x01;
	// Preload for 24Hz periodic interrupt.    
	TH0 = ETH_T0_RELOAD >> 8; 
	TL0 = ETH_T0_RELOAD;
	// Restart timer/ counter 0 running.
	TR0 = 1;
	// Enable timer/ counter 0 overflow interrupt.            
	ET0 = 1;
	// Enable global interrupt.
//	EA = 1;
}
//#include "head.h"
int main() {

	unsigned int i, j = 0;

	volatile unsigned int *pLcdDestReg =
			(volatile unsigned int*) (LCD_DEST_REG_ADDR);
	volatile unsigned int *pLcdWidthReg =
			(volatile unsigned int*) (LCD_WIDTH_REG_ADDR);
	volatile unsigned int *pLcdHeightReg =
			(volatile unsigned int*) (LCD_HEIGHT_REG_ADDR);
	volatile unsigned int *pLcdCmdReg =
			(volatile unsigned int*) (LCD_CMD_REG_ADDR);

	volatile unsigned int *pCam = (volatile unsigned int*) (OV7670_0_BASE
			| 0x80000000);
	volatile unsigned char pid[2] = { 0, 0 };

	*pLcdCmdReg = 0; // make sure that the DMA is stopped before calling the LCD init functions
	*pCam = 0;
	LCD_Init();
	LCD_Clear(0X00ff);
	//init_lcd_frame();

	printf("%x\n", lcd_frame);

	*pCam = 1; // turns the camera ON. Camera turns on with the next new frame
	Delay_Ms(2000); // add delay to be sure that frames are already in the memory

	*pLcdDestReg = LT24_CONTROLLER_0_BASE + 4;
	*pLcdWidthReg = 240; // LCD width
	*pLcdHeightReg = 320; // LCD height

	volatile unsigned char *pCamAddress = (volatile unsigned char*) (0x1f00000
			| 0x80000000); // by default camera throws images starting from here

	//*pLcdCmdReg = 0x1f00000;

	//printf ("%x\n",*pLcdCmdReg) ;

	//volatile unsigned char *image=(volatile unsigned char *)pCamAddress;


	int iter =0;
	while (1) {
		int count = 0;
		for (i = 0; i < 320; i++) {
			for (j = 0; j < 240; j++) {

			if (pCamAddress[640 * j + i] < 128) {
			//	if(i < 160){
					//LCD_WR_DATA(0Xffff);
			     	LCD_WR_DATA(0X0000);
					//printf("here");

				} else {
					LCD_WR_DATA(0Xffff);



				}

				count++;
			}

		}

		//Delay_Ms(2000);
		//sprintf("iter : %d", iter++);
	}

	//printf("count : %d", count);

}
Example #30
0
void StartLidarDemo(void)
{

	u32 i;
	u32 j;
	static u8 gridnum;
	lidarScale = 25;
	gridnum = 3;

	while(1)
	{
		fps_time = 0;

		//switch lidarScale
		if(Touch_pressed)
		{
			switch(lidarScale)//8916 874 07 98
			{
				case 13:
				{
					lidarScale = 25;
					gridnum = 3;
					break;
				}
				case 25:
				{
					lidarScale = 50;
					gridnum = 6;
					break;
				}
				case 50:
				{
					lidarScale = 13;
					gridnum = 1;
					break;
				}
			}
			LCD_Clear(BLACK);
			Delay_Ms(200);
		}
		//draw onscreen info
		LCD_DrawCircle(120,160,3,YELLOW);

		LCD_DisplayStringLine(2," # AN DIHN LIDAR DEMO");

		//lidar motor spinning rate in 1/10 of Hz
		sprintf(stringBuf," # SPIN %.2u", lidarSpeed);
		LCD_DisplayStringLine(220,stringBuf);



		//draw grid circles

		for(j=1;j<=gridnum;j++)
		{
			LCD_DrawCircle(120,160,j*1000/lidarScale,RGB(0x33,0x33,0x33));
		}

		//draw point cloud
		for(i=0;i<360;i++)
		{
			if((lidarBuf[i].dist != lidarBufOld[i].dist))
			{
				PutPixel(120-(lidarBufOld[i].x / lidarScale),160+(lidarBufOld[i].y / lidarScale),BLACK);
				//if(!lidarBuf[i].error)
				{

					if(!lidarBuf[i].warning)
					{
						PutPixel(120-(lidarBuf[i].x / lidarScale),160+(lidarBuf[i].y / lidarScale),GREEN);
					}
					else
					{
						PutPixel(120-(lidarBuf[i].x / lidarScale),160+(lidarBuf[i].y / lidarScale),YELLOW);
					}

					lidarBufOld[i].dist = lidarBuf[i].dist;
					lidarBufOld[i].x = lidarBuf[i].x;
					lidarBufOld[i].y = lidarBuf[i].y;
				}
			}
		}

		SearchWalls();
	//	DrawWalls();

		//display refresh rate, in frames per second
		if (fps_update > 20000)
		{
			sprintf(stringBuf, " # FPS %.3u", 100000/fps_time);
			LCD_DisplayStringLine(207, stringBuf);
			fps_update = 0;
		}
		//LCD_Clear(BLACK);
	}
}