Example #1
0
/*
*@功能:在指定位置显示一个字符,包括部分字符
*@输入:x:0~127,y:0~7,size:选择字体 16/12 
*/
void OLED_ShowChar(uint8_t x,uint8_t y,uint8_t chr)
{      	
		uint8_t c=0,i=0;	
		c=chr-' ';//得到偏移后的值			
		if(x>Max_Column-1)
		{
			x=0;
			y=y+2;
		}
		if(SIZE ==16)
		{
			OLED_Set_Pos(x,y);	
			for(i=0;i<8;i++)
				OLED_WR_Byte(F8X16[c*16+i],OLED_DATA);
			OLED_Set_Pos(x,y+1);
			for(i=0;i<8;i++)
				OLED_WR_Byte(F8X16[c*16+i+8],OLED_DATA);
		}
		else 
		{	
			OLED_Set_Pos(x,y+1);
			for(i=0;i<6;i++)
				OLED_WR_Byte(F6x8[c][i],OLED_DATA);	
		}
}
Example #2
0
/**
  * @brief  Invert a pixel

	@param  x(from 0 to 127): X position

			y(from 0 to 63) : Y position

	  @retval None
  */
void OLED_InvertPoint(u8 x, u8 y)
{
	unsigned char  pos, bx, temp = 0;
#if OLED_REFRESH_OPTIMIZE_EN
	if (UpdateOLEDJustNow == true)
		LCD_Set_Pos(x, y);
#else
	LCD_Set_Pos(x, y);
#endif
	if (x > 127 || y > 63)return;//Out of range
	pos = 7 - y / 8;
	bx = y % 8;
	temp = 1 << (7 - bx);
	if ((OLED_GRAM[x][pos] & temp) > 0)
	{
		OLED_GRAM[x][pos] &= ~temp;
	}
	else OLED_GRAM[x][pos] |= temp;
#if OLED_REFRESH_OPTIMIZE_EN	
	if (UpdateOLEDJustNow == true)
		OLED_WR_Byte(OLED_GRAM[x][pos], OLED_DATA);
	else
	{
		GRAM_Changing = true;
		GRAM_Changed = true;
	}
#else
	OLED_WR_Byte(OLED_GRAM[x][pos], OLED_DATA);
#endif
}
Example #3
0
//开启OLED显示
void OLED_Display_On(void)
{
    OLED_WR_Byte(0X8D,OLED_CMD);  //SET DCDC命令
    OLED_WR_Byte(0X81,OLED_CMD);  //DCDC ON
    OLED_WR_Byte(0xAD,OLED_CMD);//set charge pump enable
    OLED_WR_Byte(0x8A,OLED_CMD);//
    OLED_WR_Byte(0XAF,OLED_CMD);  //DISPLAY ON
}
Example #4
0
/**
  * @brief  Set position

	@param  x(from 0 to 127): X position

			y(from 0 to 63) : Y position

	  @retval None
  */
static void LCD_Set_Pos(unsigned char  x, unsigned char  y)
{
#if OLED_MODEL
	x = x + 2;
#endif
	OLED_WR_Byte(0xb0 + (7 - y / 8), OLED_CMD);
	OLED_WR_Byte(((x & 0xf0) >> 4) | 0x10, OLED_CMD);
	OLED_WR_Byte((x & 0x0f), OLED_CMD);
}
Example #5
0
//清屏函数,清完屏,整个屏幕是黑色的!和没点亮一样!!!	  
void OLED_Clear(void)  
{  
	u8 i,n;		    
	for(i=0;i<8;i++)  
	{  
		OLED_WR_Byte (0xb0+i,OLED_CMD);    //设置页地址(0~7)
		OLED_WR_Byte (0x00,OLED_CMD);      //设置显示位置—列低地址
		OLED_WR_Byte (0x10,OLED_CMD);      //设置显示位置—列高地址   
		for(n=0;n<128;n++)OLED_WR_Byte(0,OLED_DATA); 
	} //更新显示
}
Example #6
0
//更新显存到LCD		 
void OLED_Refresh_Gram(void)
{
	u8 i,n;		    
	for(i=0;i<8;i++)  
	{  
		OLED_WR_Byte (0xb0+i,OLED_CMD);    //设置页地址(0~7)
		OLED_WR_Byte (0x00,OLED_CMD);      //设置显示位置—列低地址
		OLED_WR_Byte (0x10,OLED_CMD);      //设置显示位置—列高地址   
		for(n=0;n<128;n++)OLED_WR_Byte(OLED_GRAM[n][i],OLED_DATA); 
	}   
}
Example #7
0
void OLED_On(void)
{
    u8 i,n;
    for(i=0; i<8; i++)
    {
        OLED_WR_Byte (0xb0+i,OLED_CMD);    //设置页地址(0~7)
        OLED_WR_Byte (0x00,OLED_CMD);      //设置显示位置—列低地址
        OLED_WR_Byte (0x10,OLED_CMD);      //设置显示位置—列高地址
        for(n=0; n<Max_Column; n++)OLED_WR_Byte(1,OLED_DATA);
    } //更新显示
}
Example #8
0
File: oled.c Project: tymbys/Watch
//Єь–¬ѕ‘іжµљLCD		 
void OLED_Refresh_Gram(void)
{
	u8 i,n;		    
	for(i=0;i<8;i++)  
	{  
		OLED_WR_Byte (0xb0+i,OLED_CMD);    //…и÷√“≥µЎ÷Ј£®0~7£©			// CMD_SET_PAGE
		OLED_WR_Byte (0x00,OLED_CMD);      //…и÷√ѕ‘ Њќї÷√°™Ѕ–µЌµЎ÷Ј		//CMD_SET_COLUMN_LOWER
		OLED_WR_Byte (0x10,OLED_CMD);      //…и÷√ѕ‘ Њќї÷√°™Ѕ–ЄяµЎ÷Ј  	//CMD_SET_COLUMN_UPPER
		for(n=0;n<128;n++)OLED_WR_Byte(OLED_GRAM[n][i],OLED_DATA); 
	}   
}
Example #9
0
/*
*@功能:清屏函数,清完屏,整个屏幕是黑色的!和没点亮一样!!!	  
*/
void OLED_Clear(void)  
{  
	uint8_t i,n;		    
	for(i=0;i<8;i++)  
	{  
		OLED_WR_Byte (0xb0+i,OLED_CMD);    //设置页地址(0~7)
		OLED_WR_Byte (0x02,OLED_CMD);      //设置显示位置—列低地址,从第2列开始
		OLED_WR_Byte (0x10,OLED_CMD);      //设置显示位置—列高地址   
		for(n=0;n<133;n++)
			OLED_WR_Byte(0,OLED_DATA); 
	} //更新显示
}
Example #10
0
void OLED_ShowChar(u8 x,u8 y,u8 chr)
{      	
	unsigned char c=0,i=0;	
		c=chr-' ';//得到偏移后的值			
		if(x>Max_Column-1){x=0;y=y+2;}
	
		OLED_Set_Pos(x,y);	
		for(i=0;i<8;i++)
		OLED_WR_Byte(F8X16[c*16+i],OLED_DATA);
		OLED_Set_Pos(x,y+1);
		for(i=0;i<8;i++)
		OLED_WR_Byte(F8X16[c*16+i+8],OLED_DATA);
		
}
Example #11
0
//清屏函数,清完屏,整个屏幕是黑色的!和没点亮一样!!!
void OLED_Clear(void)
{
    u8 i,n;
    for(i=0; i<16; i++)
    {
        OLED_WR_Byte (0xb0+i,OLED_CMD);    //设置页地址(0~7)
        OLED_WR_Byte (0x00,OLED_CMD);      //设置显示位置—列低地址
        OLED_WR_Byte (0x10,OLED_CMD);      //设置显示位置—列高地址
        OLED_Set_Pos(pos_x_offset, i);
        for(n=0+pos_x_offset; n<Max_Column+pos_x_offset; n++)
            OLED_WR_Byte(0,OLED_DATA);
    } //更新显示

}
Example #12
0
/**
  * @brief  Upload GRAM to OLED immediately

	  @retval None
  */
void OLED_Refresh_Gram(void)
{
	unsigned char  i, n;
	for (i = 0; i < 8; i++)
	{
		OLED_WR_Byte(0xb0 + i, OLED_CMD);
#if OLED_MODEL
		OLED_WR_Byte(0x02, OLED_CMD);
#else
		OLED_WR_Byte(0x00, OLED_CMD);
#endif
		OLED_WR_Byte(0x10, OLED_CMD);
		for (n = 0; n < 128; n++)OLED_WR_Byte(OLED_GRAM[n][i], OLED_DATA);
	}
}
Example #13
0
void OLED_Clear_line(u8 x,u8 y,u8 sizef)  
{  
	u8 i,n;		
	rt_mutex_take(oled_disp_mut,RT_WAITING_FOREVER);

	i = y;
	
 
	OLED_WR_Byte (0xb0+i,OLED_CMD);    //¨¦¨¨??¨°3¦Ì??¡¤¡ê¡§0~7¡ê?
	OLED_WR_Byte (0x00,OLED_CMD);      //¨¦¨¨????¨º??????a¨¢D¦Ì¨ª¦Ì??¡¤
	OLED_WR_Byte (0x10,OLED_CMD);      //¨¦¨¨????¨º??????a¨¢D??¦Ì??¡¤   
	for(n=0;n<128;n++)OLED_WR_Byte(0,OLED_DATA); 

	rt_mutex_release(oled_disp_mut);
	
}
Example #14
0
/*
*@功能:显示汉字
*/
void OLED_ShowChinese(uint8_t x,uint8_t y,uint8_t no)
{      			    
		uint8_t t,adder=0;
		OLED_Set_Pos(x,y);	
    for(t=0;t<16;t++)
		{
				OLED_WR_Byte(Hzk[2*no][t],OLED_DATA);
				adder+=1;
    }	
		OLED_Set_Pos(x,y+1);	
    for(t=0;t<16;t++)
		{	
				OLED_WR_Byte(Hzk[2*no+1][t],OLED_DATA);
				adder+=1;
		}					
}
Example #15
0
//显示汉字
void OLED_ShowCHinese(u8 x,u8 y,u8 no)
{      			    
	u8 t,adder=0;
	OLED_Set_Pos(x,y);	
    for(t=0;t<16;t++)
	{
		OLED_WR_Byte(Hzk[2*no][t],OLED_DATA);
		adder+=1;
    }	
	OLED_Set_Pos(x,y+1);	
    for(t=0;t<16;t++)
	{	
		OLED_WR_Byte(Hzk[2*no+1][t],OLED_DATA);
		adder+=1;
    }					
}
Example #16
0
/*
*@功能:唤醒初始化
*/
void WKUP_Init(void)
{	
	uint8_t cw;
	cw=Check_WKUP();
	
	OLED_WR_Byte(0xAE,OLED_CMD); //关闭显示
	//程序刚下进去时由于没有长按取消键,所以检测结果为0,直接进入停机模式
	//if(Check_WKUP()) 
	if(!cw) 		
		Sys_Standby();    //不是开机,进入停机模式  
	
}
Example #17
0
void OLED_ShowChar_Bold(u16 x,u8 y,u8 chr,u8 Char_Size)
{

    unsigned char c=0,i=0,j=0;
    x += pos_x_offset;
    c = chr-'0';//得到偏移后的值
    if(Char_Size == 32) {
        for (j=0;j<Char_Size/8;j++) {
            OLED_Set_Pos(x,y+j);
            for(i=0; i<16; i++)
                OLED_WR_Byte(BoldF16x32[c][i+j*16],OLED_DATA);
        }
    }
}
Example #18
0
/* What we input are (0,0,Max_Column,8,BMP1) */
void OLED_DrawBMP(unsigned char x0, unsigned char y0,unsigned char x1, unsigned char y1, const unsigned char BMP[])
{
    unsigned int j=0;
    unsigned char x,y;
    x0 += pos_x_offset;
    x1 += pos_x_offset;
    for(y=y0; y<y1; y++)
    {
        OLED_Set_Pos(x0,y);
        for(x=x0; x<x1; x++)
        {
            OLED_WR_Byte(BMP[j++],OLED_DATA);
        }
    }
}
Example #19
0
/***********功能描述:显示显示BMP图片128×64起始点坐标(x,y),x的范围0~127,y为页的范围0~7*****************/
void OLED_DrawBMP(unsigned char x0, unsigned char y0,unsigned char x1, unsigned char y1,unsigned char BMP[])
{ 	
  unsigned int j=0;
  unsigned char x,y;
  
  if(y1%8==0) y=y1/8;      
  else y=y1/8+1;
  for(y=y0;y<y1;y++)
  {
    OLED_Set_Pos(x0,y);
    for(x=x0;x<x1;x++)
    {      
      OLED_WR_Byte(BMP[j++],OLED_DATA);	    	
    }
  }
} 
Example #20
0
/*
*@功能:系统进入停机模式
*/
void Sys_Enter_Standby(void)
{			 
	
	//相比Sys_Standby(),在进入停机模式之前,可以做些减小功耗的措施
	//这里做一些可以在停机模式减小功耗的措施
	
	OLED_WR_Byte(0xAE,OLED_CMD); //关闭显示
	//RCC_APB2PeriphResetCmd(0X01FC,DISABLE);		//复位所有IO口
	
	
	
	
	
	Sys_Standby();
	
}
Example #21
0
/*
*@功能:显示显示BMP图片128×64起始点坐标(x,y),x的范围0~127,y为页的范围0~7
*/
void OLED_DrawBMP(uint8_t x0, uint8_t y0,uint8_t x1, uint8_t y1,uint8_t BMP[])
{ 	
		uint32_t j=0;
		uint8_t x,y;
		
		//把行地址转化为页地址
		if(y1%8==0)
			y=y1/8;      
		else
			y=y1/8+1;
		
		for(y=y0;y<y1;y++)
		{
			OLED_Set_Pos(x0,y);
			for(x=x0;x<x1;x++)
			{      
				OLED_WR_Byte(BMP[j++],OLED_DATA);	    	
			}
		}
} 
Example #22
0
void OLED_ShowChar_Mode(u8 x,u8 y,u8 chr,u8 Char_Size, u8 mode)
{
    unsigned char c=0,i=0;
    x += pos_x_offset;
    if(Char_Size == 8) {
        c=chr-'A';//得到偏移后的值
        OLED_Set_Pos(x,y);
        for(i=0; i<6; i++)
            if (mode == 1)
                OLED_WR_Byte(F6x8[c][i],OLED_DATA);
            else if (mode == 0)
                OLED_WR_Byte(~F6x8[c][i],OLED_DATA);
    } else if(Char_Size ==16) {
        c=chr-' ';//得到偏移后的值
        OLED_Set_Pos(x,y);
        for(i=0; i<8; i++)
            if (mode == 1)
                OLED_WR_Byte(F8X16[c*16+i], OLED_DATA);
            else if (mode == 0)
                OLED_WR_Byte(~F8X16[c*16+i], OLED_DATA);
        OLED_Set_Pos(x,y+1);
        for(i=0; i<8; i++)
            if (mode == 1)
                OLED_WR_Byte(F8X16[c*16+i+8], OLED_DATA);
            else if (mode == 0)
                OLED_WR_Byte(~F8X16[c*16+i+8], OLED_DATA);
    }
    /*
    else if (Char_Size == 24) {
        OLED_Set_Pos(x,y);
        for(i=0; i<6; i++)
            if (mode == 1)
                OLED_WR_Byte(F6x8[c][i],OLED_DATA);
            else if (mode == 0)
                OLED_WR_Byte(~F6x8[c][i],OLED_DATA);
    }
    */
}
Example #23
0
/*
*@功能 主函数入口
*@参数	空
*@返回	空
*/
int main(void)
{
	

	
	
	
	
  /*测试变量部分*/	
	/*******************************************/
	uint8_t t=' ';
	uint8_t usb_code[6]={0x55,0x7A,0xBB,0x01,0x00,0x01};//下位机反复的向上位机发送此命令,用以建立初始化连接
  uint8_t p[6]={0x30,0x31,0x32,0x33,0x34,0x35};
	uint8_t hanzi[11];
	uint8_t *phz;
	uint32_t flash_data;
	uint8_t flash_temp[4];
	uint8_t status;
  uint32_t addr;
	uint8_t nChar;
// 	uint8_t char_buf[50];
// 	uint8_t count;

	uint32_t batt_test=0;
	/*********************************************/
	
	//设置中断向量表的位置在 0x5000,即内部flash的前20K
	NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x5000);		


	
	
	SystemTick_Init();
	NVIC_Configuration();
		

	//按键初始化
	Init_Sw_Key_Io();
 	Exit_Line_Init();	



	EXTILine_Mask(EXTI_Line5);
	EXTILine_Mask(EXTI_Line8);	
	EXTILine_Mask(EXTI_Line15);	

	//长按开机,如果长按不够3m则继续保持关机状态,如果长按3m,则退出停机模式,开机
	WKUP_Init();		
	
	EXTILine_Unmask(EXTI_Line5);
	EXTILine_Unmask(EXTI_Line8);
	EXTILine_Unmask(EXTI_Line15);
	
	
	
  //如果没有进入停机模式,则开启显示
	OLED_WR_Byte(0xAF,OLED_CMD); //开启显示
	
	
  longpress=0;
	stop_flag=0;
	
	SPI_FLASH_Init();
	//正常运行后,显示logo
	OLED_Init();
	SPI_FLASH_Init();	
	
	
	OLED_Clear();	
	OLED_DrawBMP(32,2,48,4,hui);
	OLED_ShowUnite(48,2,"合科技");		
	//delay_ms(800);	




	
	USB_BIT_Init();
	
	//为降低功耗的控制位
	/****************************************/
	bluetooth_control_Init();

	max232_control_Init();

	oled_control_Init();
	OLED_ON;
	
	buzzer_control_Init();
	BUZZER_OFF;

	coil_control_Init();	
	COIL_NO_ACTUATE;
	/****************************************/
	
	





	Init_Timer();
	
	//实时时钟初始化
	RTC_init();
	
	//初始化并启动看门狗
	//iwdg_init();
	
	//串口1 USB初始化及配置
	Uart1_Init();
	USART1_Configuration();
	
	//串口2 RFID初始化及配置
	Uart2_Init();
	USART2_Configuration();	
	
	//串口3 bluetooth初始化及配置
	Uart3_Init();
	USART3_Configuration();	
	bluetooth_Configuration();	//蓝牙的EN和BRST配置
	CLR_BT_EN;	//开启蓝牙
	

	
	
	ADC_GPIO_Configuration();
	ADC_Configuration();
	

	
	//flash区域指针初始化
	//SPI_FLASH_WriteWord(INIT_FLAG,1);   //此次下载清flash
 	SPI_FLASH_WriteWord(INIT_FLAG,0);		  //此次下载不清flash
	
	if(SPI_FLASH_ReadWord(INIT_FLAG) ==0x01)		//当初始化标志等于1,就初始化POINT和ROW
	{
	  mykey_init();		//初始化钥匙操作的头指针 ---如何设定在什么情况下重新设置
	}	
	


	

	
// 	 OLED_ClearArea(0,4,128,6);	
// 	 OLED_ShowUnite(24,4,"初始化蓝牙");		
// 	 mac_query_result=bluetooth_mac();
	
	
	
	
	
	/*延时函数测试*/
	/**********************************************/
// 	GPIO_Configuration();
// 	while(1)
// 	{
// 		GPIO_SetBits(GPIOB,GPIO_Pin_0);
// 		delay_ms(1000);
// 		GPIO_ResetBits(GPIOB,GPIO_Pin_0);
// 		delay_ms(3000);	
// 	}
	/**********************************************/

	
	/*OLED测试*/
	/**********************************************/
//   while(1)
//   {
// 		OLED_Clear();
// 		OLED_ShowChinese(0,0,0);  //中
// 		OLED_ShowChinese(18,0,1); //景
// 		OLED_ShowChinese(36,0,2); //园
// 		OLED_ShowChinese(54,0,3); //电
// 		OLED_ShowChinese(72,0,4); //子
// 		OLED_ShowChinese(90,0,5); //科
// 		OLED_ShowChinese(108,0,6);//技
// 		OLED_ShowString(0,3,"1.3' OLED TEST");
// 		//OLED_ShowString(8,2,"ZHONGJINGYUAN");  
// 	  //OLED_ShowString(20,4,"2014/05/01");  
// 		OLED_ShowString(0,6,"ASCII:");  
// 		OLED_ShowString(63,6,"CODE:");  
// 		OLED_ShowChar(48,6,t);//显示ASCII字符	   
// 		t++;
// 		if(t>'~')
// 			t=' ';
// 		OLED_ShowNum(103,6,t,3,16);//显示ASCII字符的码值 	
// 			
//     delay_ms(8000);
//     //OLED_Clear();
// 		
// 		OLED_DrawBMP(0,0,128,8,BMP1);  //图片显示(图片显示慎用,生成的字表较大,会占用较多空间,FLASH空间8K以下慎用)
// 		delay_ms(800);
// 		
//     //OLED_Display_On();
//     //delay_ms(800);		
// 		
// 		OLED_DrawBMP(0,0,128,8,BMP2);
// 		delay_ms(800);	
// 		
//    //OLED_Display_Off();	
//    //delay_ms(800);				
//   }
	/**********************************************/
	
	
	
	
	/*OLED+字库测试*/
	/**********************************************/	
// 	phz="字库";
// 	hanzi[0]=*phz;
// 	hanzi[1]=*(phz+1);
// 	hanzi[2]=*(phz+2);
// 	hanzi[3]=*(phz+3);
// 	hanzi[4]=*(phz+4);	
// 	
// 	
// 	OLED_ShowChinese(0,0,"汉");
// 	OLED_ShowChinese(16,0,"字");
// 	
// 	OLED_ShowUnite(0,2,"你很不错");
// 	OLED_ShowUnite(0,4,"ABCDEF");		
// 	OLED_ShowUnite(0,6,"123456");		
	
	
	/**********************************************/	
	
/*
		STM32F103C8串口有3个
		串口1通过USB接充电器,与上位机PC通信
		串口2通过串口读RFID的数据
		串口3通过蓝牙与PDA通信
*/	
	
	
 	/*串口1 USB测试*/
	/**********************************************/
	
// 	while(1)
// 	{
// 		UART1nSendChar(1,"12345",5);
// 		delay_ms(1000);
// 	}
	//UART1nSendChar(1,usb_code,6);	
	
	//USB_Cheak_init();
	
	//Test_Usb_Data();


// 	UART1SendwordHex(1, 0x123456);

//   UART1nSendChar(1,"汉字",5);	

// 	while(1);
	
	/**********************************************/
	
	
	
	
 	/*串口2 RFID测试*/
	/**********************************************/
// 	while(1)
// 	{
// 			OLED_ShowUnite(32,2,"RFID");
// 			delay_ms(1000);	
// 			UART1nSendChar(1,"12345",5);
// 			//OLED_Clear();	    //清屏
// 			nChar =Read_RfidData(2,Rfid_Buff,0xff);
// 			m_UB2;
// 			if(nChar ==5) 
// 			{
// 				if(Rfid_Buff[0]==0&&Rfid_Buff[1]==0&&Rfid_Buff[2]==0&&Rfid_Buff[3]==0)
// 					;
// 				else		//至少有一个不为零
// 				{
// 					UART1nSendChar(1,Rfid_Buff,5);
// 					OLED_ShowNumHex(32,4,Rfid_Buff[0],2,16);
// 					OLED_ShowNumHex(48,4,Rfid_Buff[1],2,16);
// 					OLED_ShowNumHex(64,4,Rfid_Buff[2],2,16);
// 					OLED_ShowNumHex(80,4,Rfid_Buff[3],2,16);
// 					delay_ms(1000);						
// 					break;
// 				}
// 			}
// 	}
// 	while(1);		
	
	
	
	
	
	/**********************************************/	
	
	
	
	
 	/*串口3 bluetooth测试*/
	/**********************************************/
// 	CLR_BT_EN;
// 	CLR_BT_BRTS;
// 	
// 	while(1)
// 	{
// 		UART3nSendChar(3,"012345",6);
// 		delay_ms(1000);
// 	}
// 		while(1)
// 		{
// 			UART3nSendChar(3,"TTM:MAC-?",9);

// 			count=UART3GetCount(3);
// 			UART3nReadChar(3,char_buf,count);
// 			
// 			
// 			
// 			
// 			UART1nSendChar(1,char_buf,count);

// 			delay_ms(1000);
// 		}

	/**********************************************/	
	
	
	/*flash测试*/
	/**********************************************/	
	
	
//   SPI_FLASH_WriteWord(AUTHOR_ROW,0x456789);
// 	
// 	SPI_FLASH_BufferRead(flash_temp,AUTHOR_ROW,4);	
// 	
// 	flash_data=SPI_FLASH_ReadWord(AUTHOR_ROW);

// 	UART1nSendChar(1,flash_temp,4);	
//   
// 	OLED_ShowNum(0,6,flash_data,8,16);	
// 	
// 	//SPI_FLASH_WriteEnable();
//   status=SPI_FLASH_ReadStatusReg();
// 	OLED_ShowNum(112,6,status,1,16);	
	
//  SPI_FLASH_BulkErase();
	
// 	SPI_FLASH_BufferWrite("98765",0x100002,6);
// 	SPI_FLASH_BufferRead(p,0x100002,6);
	
	
// 	SPI_FLASH_Write("98765",0x1f0005,6);
// 	SPI_FLASH_Read(p,0x1f0005,6);	
// 	while(1)
// 	{
// 		UART1nSendChar(1,p,6);	
// 		delay_ms(1000);
// 	}
	
	/**********************************************/	
	


	//菜单测试
	/**********************************************/	
	
  //Main_Lcd_Show();   //主界面显示	
	//Main_Lcd_Show2();	
	
// 	mode=1;
// 	
// 	OLED_ShowChar(0,0,'A');
// 	
// 	OLED_ShowChinese(0,2,"我");
// 	
// 	OLED_ShowUnite(0,4,"你很不错");
// 	
// 	while(1);
// 	
// 	mode=0;
// 	delay_ms(1000);

	//ShowMenu(HsMenu);
	
	
// 	Choose_MenuOp1();

//  Choose_MenuOp4(); 

// 	Choose_MenuOp4_1();
//  Choose_MenuOp4_2();
// 	Choose_MenuOp4_22();
// 	Choose_MenuOp4_3();
// 	Choose_MenuOp4_4();

// 	Choose_MenuOp5();

// 	Choose_MenuOp5_1();
// 	Choose_MenuOp5_3();
// 	Choose_MenuOp5_4();	

// 		while(1)
// 		{
// 			Main_Oled_Time();	
// 			Main_Oled_Power();
// 			delay_ms(1000);
// 		}	

	

// 		while(1);
	/**********************************************/		
	
	
	
	
	
	//蜂鸣器测试
  /**********************************************/	
// 	while(1)
// 	{
// 		BUZZER_OFF;
// 		delay_ms(1000);
// 		
// 		BUZZER_ON;
// 		delay_ms(1500);	
// 	}
	
	/**********************************************/		
	
	
	
	
	
	//协议测试
	/**********************************************/	
	//OLED_Clear();
// 	OLED_ShowUnite(32,2,"通信中..");
// 	OLED_ShowUnite(0,4,"你很不错");
// 	delay_ms(1000);
// 	addr=0xFFFF;
// 	OLED_ShowNumHex(0,6,addr,8,16);
	
	//USB_Cheak_init();
  //USB_transmit();

//  		bluetooth_uart_switch=1;
// 		Test_Usb_Data();
//  		while(1);


	


//   SPI_FLASH_WriteWord(AUTHOR_POINT,AUTHOR_START);		

//   addr= SPI_FLASH_ReadWord(AUTHOR_POINT);   

//   OLED_ShowNum(0,0,addr,8,16);
	/**********************************************/	
	
	
	
	
	//ADC测试
	/**********************************************/		
	
// 	while(1)
// 	{
// 		OLED_Clear();
// 		batt_test=ADC_GetConversionValue(ADC1);
// 		OLED_ShowNum(24,2,batt_test,8,16);
// 		delay_ms(1000);
// 	}
// 	
	
	
	/**********************************************/		
	
	
	
	//定时器2测试
	/**********************************************/
	
	
// 	GPIO_Configuration();
// 	GPIO_ResetBits(GPIOB,GPIO_Pin_6);
// 	delay_ms(10);
// 	GPIO_SetBits(GPIOB,GPIO_Pin_6);
//   g_WaitTimeOut = 0;
//   SetTimer(TIMER_TIMEOUT,1,Do_TimeOut,THREE_MIN);
// 	while(g_WaitTimeOut == 0)
// 	{
// 		GPIO_ResetBits(GPIOB,GPIO_Pin_6);

// 	}	
//   KillTimer(TIMER_TIMEOUT);	
// 	GPIO_SetBits(GPIOB,GPIO_Pin_6);
	
//   g_WaitTimeOut = 0;
//   SetTimer(TIMER_TIMEOUT,10,Do_TimeOut,THREE_MIN);
// 	while(g_WaitTimeOut == 0)
// 	{
// 			nChar =Read_RfidData(2,Rfid_Buff,0xff);
// 			if(nChar ==5)
// 			{
// 					OLED_ShowUnite(32,80,Rfid_Buff);
// 					++rfidrow;
// 					delay_ms(1000);		
// 					for(i=0;i<4;i++)
// 					{
// 							for(k =0;k<40;k++)
// 								msDelay(500);
// 							WritEDAta(CAIMA_START+8*rfidrow+4+i,Rfid_Buff[i]);
// 					}				
// 					break;
// 			}

// 	}	
//   KillTimer(TIMER_TIMEOUT);		
	/**********************************************/	
	
	
	
	
	
	
	
// 	OLED_ClearArea(0,4,128,6);
// 	OLED_ShowUnite(24,4,"初始化完成");		
// 	delay_ms(100);
	
	
	//bluetooth_uart_switch=0;
// 	for(int iter=0;iter<3;iter++)
// 		Power_Cheak();	

  //主循环测试
	g_State=ST_IDLE;
	while(1)																					 
	{   
		switch (g_State)				//g_State是一个全局函数
		{
			
			 case ST_IDLE:    			//#define  ST_IDLE          0XFF
			 ST_Idle();		    			//空闲时做状态检测,可改变g_State
			 break;			
			
			 case ST_USB: 					//#define  ST_USB	          0XFD         
			 USB_transmit();				//USB传输
			 break;
			 	 
// 			 case ST_KEY:
// 			 Key_Trismit();  				//读钥匙的RFID,判断是否已经连接上
// 			 break;
			 
			 case ST_LCDMENU:   		//#define  ST_LCDMENU      0XFA			多选择菜单操作
			 Choose_MenuOp1();
			 break;
			 
			 default:break;

			}
	 }		
}
Example #24
0
//关闭OLED显示     
void OLED_Display_Off(void)
{
	OLED_WR_Byte(0X8D,OLED_CMD);  //SET DCDC命令
	OLED_WR_Byte(0X10,OLED_CMD);  //DCDC OFF
	OLED_WR_Byte(0XAE,OLED_CMD);  //DISPLAY OFF
}		   			 
Example #25
0
//开启OLED显示    
void OLED_Display_On(void)
{
	OLED_WR_Byte(0X8D,OLED_CMD);  //SET DCDC命令
	OLED_WR_Byte(0X14,OLED_CMD);  //DCDC ON
	OLED_WR_Byte(0XAF,OLED_CMD);  //DISPLAY ON
}
Example #26
0
void OLED_Set_Pos(unsigned char x, unsigned char y) 
{ 
	OLED_WR_Byte(0xb0+y,OLED_CMD);
	OLED_WR_Byte(((x&0xf0)>>4)|0x10,OLED_CMD);
	OLED_WR_Byte((x&0x0f)|0x01,OLED_CMD); 
}   	  
Example #27
0
//初始化SSD1306					    
void OLED_Init(void)
{ 
  	OLED_RST_Set();
	delay_ms(100);
	OLED_RST_Clr();
	delay_ms(100);
	OLED_RST_Set(); 

	OLED_WR_Byte(0xAE,OLED_CMD);//--turn off oled panel
	OLED_WR_Byte(0x00,OLED_CMD);//---set low column address
	OLED_WR_Byte(0x10,OLED_CMD);//---set high column address
	OLED_WR_Byte(0x40,OLED_CMD);//--set start line address  Set Mapping RAM Display Start Line (0x00~0x3F)
	OLED_WR_Byte(0x81,OLED_CMD);//--set contrast control register
	OLED_WR_Byte(0xCF,OLED_CMD); // Set SEG Output Current Brightness
	OLED_WR_Byte(0xA1,OLED_CMD);//--Set SEG/Column Mapping     0xa0左右反置 0xa1正常
	OLED_WR_Byte(0xC8,OLED_CMD);//Set COM/Row Scan Direction   0xc0上下反置 0xc8正常
	OLED_WR_Byte(0xA6,OLED_CMD);//--set normal display
	OLED_WR_Byte(0xA8,OLED_CMD);//--set multiplex ratio(1 to 64)
	OLED_WR_Byte(0x3f,OLED_CMD);//--1/64 duty
	OLED_WR_Byte(0xD3,OLED_CMD);//-set display offset	Shift Mapping RAM Counter (0x00~0x3F)
	OLED_WR_Byte(0x00,OLED_CMD);//-not offset
	OLED_WR_Byte(0xd5,OLED_CMD);//--set display clock divide ratio/oscillator frequency
	OLED_WR_Byte(0x80,OLED_CMD);//--set divide ratio, Set Clock as 100 Frames/Sec
	OLED_WR_Byte(0xD9,OLED_CMD);//--set pre-charge period
	OLED_WR_Byte(0xF1,OLED_CMD);//Set Pre-Charge as 15 Clocks & Discharge as 1 Clock
	OLED_WR_Byte(0xDA,OLED_CMD);//--set com pins hardware configuration
	OLED_WR_Byte(0x12,OLED_CMD);
	OLED_WR_Byte(0xDB,OLED_CMD);//--set vcomh
	OLED_WR_Byte(0x40,OLED_CMD);//Set VCOM Deselect Level
	OLED_WR_Byte(0x20,OLED_CMD);//-Set Page Addressing Mode (0x00/0x01/0x02)
	OLED_WR_Byte(0x02,OLED_CMD);//
	OLED_WR_Byte(0x8D,OLED_CMD);//--set Charge Pump enable/disable
	OLED_WR_Byte(0x14,OLED_CMD);//--set(0x10) disable
	OLED_WR_Byte(0xA4,OLED_CMD);// Disable Entire Display On (0xa4/0xa5)
	OLED_WR_Byte(0xA6,OLED_CMD);// Disable Inverse Display On (0xa6/a7) 
	OLED_WR_Byte(0xAF,OLED_CMD);//--turn on oled panel
	
	OLED_WR_Byte(0xAF,OLED_CMD); /*display ON*/ 
	OLED_Clear();
	OLED_Set_Pos(0,0); 	
}  
Example #28
0
//初始化SSD1306					    
void OLED_Init(void)
{ 	 				 	 					    
	GPIO_InitTypeDef  GPIO_InitStructure;
  	  
	RCC_APB2PeriphClockCmd(	RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC, ENABLE );
		  
#if OLED_MODE==1					 
 	GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable , ENABLE);	//JTAG-DP 失能 + SW-DP使能 

	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; 		 //推挽输出
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_Init(GPIOB, &GPIO_InitStructure);						    	 
	GPIO_Write(GPIOB,0XFFFF);

	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; 		 //推挽输出
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_Init(GPIOC, &GPIO_InitStructure);
	GPIO_SetBits(GPIOC, GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9);//如果每一位决定一个GPIO_Pin,则可以通过或的形式来初始化多个IO

#else
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; 		 //推挽输出
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_Init(GPIOB, &GPIO_InitStructure);
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD ; 		 //推挽输出	
	GPIO_Init(GPIOB, &GPIO_InitStructure);				    	 
	GPIO_Write(GPIOB,0X03);

	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8|GPIO_Pin_9;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; 		 //推挽输出
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_Init(GPIOC, &GPIO_InitStructure);
	GPIO_SetBits(GPIOC, GPIO_Pin_8|GPIO_Pin_9);
//	GPIO_SetBits(GPIOC, GPIO_Pin_9);
#endif
 
					  
	OLED_WR_Byte(0xAE,OLED_CMD); //关闭显示
	OLED_WR_Byte(0xD5,OLED_CMD); //设置时钟分频因子,震荡频率
	OLED_WR_Byte(80,OLED_CMD);   //[3:0],分频因子;[7:4],震荡频率
	OLED_WR_Byte(0xA8,OLED_CMD); //设置驱动路数
	OLED_WR_Byte(0X3F,OLED_CMD); //默认0X3F(1/64) 
	OLED_WR_Byte(0xD3,OLED_CMD); //设置显示偏移
	OLED_WR_Byte(0X00,OLED_CMD); //默认为0

	OLED_WR_Byte(0x40,OLED_CMD); //设置显示开始行 [5:0],行数.
													    
	OLED_WR_Byte(0x8D,OLED_CMD); //电荷泵设置
	OLED_WR_Byte(0x14,OLED_CMD); //bit2,开启/关闭
	OLED_WR_Byte(0x20,OLED_CMD); //设置内存地址模式
	OLED_WR_Byte(0x02,OLED_CMD); //[1:0],00,列地址模式;01,行地址模式;10,页地址模式;默认10;
	OLED_WR_Byte(0xA1,OLED_CMD); //段重定义设置,bit0:0,0->0;1,0->127;
	OLED_WR_Byte(0xC0,OLED_CMD); //设置COM扫描方向;bit3:0,普通模式;1,重定义模式 COM[N-1]->COM0;N:驱动路数
	OLED_WR_Byte(0xDA,OLED_CMD); //设置COM硬件引脚配置
	OLED_WR_Byte(0x12,OLED_CMD); //[5:4]配置
		 
	OLED_WR_Byte(0x81,OLED_CMD); //对比度设置
	OLED_WR_Byte(0xEF,OLED_CMD); //1~255;默认0X7F (亮度设置,越大越亮)
	OLED_WR_Byte(0xD9,OLED_CMD); //设置预充电周期
	OLED_WR_Byte(0xf1,OLED_CMD); //[3:0],PHASE 1;[7:4],PHASE 2;
	OLED_WR_Byte(0xDB,OLED_CMD); //设置VCOMH 电压倍率
	OLED_WR_Byte(0x30,OLED_CMD); //[6:4] 000,0.65*vcc;001,0.77*vcc;011,0.83*vcc;

	OLED_WR_Byte(0xA4,OLED_CMD); //全局显示开启;bit0:1,开启;0,关闭;(白屏/黑屏)
	OLED_WR_Byte(0xA6,OLED_CMD); //设置显示方式;bit0:1,反相显示;0,正常显示	    						   
	OLED_WR_Byte(0xAF,OLED_CMD); //开启显示	 
	OLED_Clear();
}  
Example #29
0
File: oled.c Project: tymbys/Watch
//contrast 0.. ff
void OLED_SetContrast(unsigned char contrast)
{
	OLED_WR_Byte(0x81,OLED_CMD); //∂‘±»∂»…и÷√
	OLED_WR_Byte(contrast,OLED_CMD);
}
Example #30
0
File: oled.c Project: tymbys/Watch
//≥х ЉїѓSSD1306					    
void OLED_Init(void)
{ 	
 
 	GPIO_InitTypeDef  GPIO_InitStructure;
 	

 	//RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOD|RCC_APB2Periph_GPIOG|RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB, ENABLE);

 	RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);



	//GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3|GPIO_Pin_6;	 //PD3,PD6Ќ∆Ќм д≥ц
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7|GPIO_Pin_6|GPIO_Pin_5|GPIO_Pin_4|GPIO_Pin_3;

 	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; //GPIO_Mode_Out_PP; 		 //Ќ∆Ќм д≥ц
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;//GPIO_Speed_50MHz;//Ћў∂»50MHz
 	//GPIO_Init(GPIOD, &GPIO_InitStructure);	  //≥х ЉїѓGPIOD3,6
 	GPIO_Init(GPIOA, &GPIO_InitStructure);
 	//GPIO_SetBits(GPIOD,GPIO_Pin_3|GPIO_Pin_6);	//PD3,PD6  д≥цЄя
 	GPIO_SetBits(GPIOA,GPIO_Pin_7|GPIO_Pin_6|GPIO_Pin_5|GPIO_Pin_4|GPIO_Pin_3);
/*
 #if OLED_MODE==1
 
 	GPIO_InitStructure.GPIO_Pin =0xFF; //PC0~7 OUTЌ∆Ќм д≥ц
 	GPIO_Init(GPIOC, &GPIO_InitStructure);
 	GPIO_SetBits(GPIOC,0xFF); //PC0~7 д≥цЄя

 	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15;				 //PG13,14,15 OUTЌ∆Ќм д≥ц
 	GPIO_Init(GPIOG, &GPIO_InitStructure);
 	GPIO_SetBits(GPIOG,GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15);						 //PG13,14,15 OUT   д≥цЄя

 #else*/
/*
 	//GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1;				 //PC0,1 OUTЌ∆Ќм д≥ц
 	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7|GPIO_Pin_6;
 	//GPIO_Init(GPIOC, &GPIO_InitStructure);
 	GPIO_Init(GPIOB, &GPIO_InitStructure);
 	//GPIO_SetBits(GPIOC,GPIO_Pin_0|GPIO_Pin_1);						 //PC0,1 OUT   д≥цЄя
 	GPIO_SetBits(GPIOB,GPIO_Pin_7|GPIO_Pin_6);

	//GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;				 //PG15 OUTЌ∆Ќм д≥ц	  RST
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
 	//GPIO_Init(GPIOG, &GPIO_InitStructure);
 	GPIO_Init(GPIOB, &GPIO_InitStructure);
 	//GPIO_SetBits(GPIOG,GPIO_Pin_15);						 //PG15 OUT   д≥цЄя
 	GPIO_SetBits(GPIOB,GPIO_Pin_5);
*/

 //#endif
  							  
	OLED_RST_Clr();
	delay_ms(100);
	OLED_RST_Set(); 
					  
	OLED_WR_Byte(0xAE,OLED_CMD); //єЎ±’ѕ‘ Њ
	OLED_WR_Byte(0xD5,OLED_CMD); //…и÷√ ±÷”Ј÷∆µ“т„”,’рµі∆µ¬ 
	OLED_WR_Byte(80,OLED_CMD);   //[3:0],Ј÷∆µ“т„”;[7:4],’рµі∆µ¬ 
	OLED_WR_Byte(0xA8,OLED_CMD); //…и÷√«э∂ѓ¬Ј э
	OLED_WR_Byte(0X3F,OLED_CMD); //ƒђ»ѕ0X3F(1/64) 
	OLED_WR_Byte(0xD3,OLED_CMD); //…и÷√ѕ‘ Њ∆Ђ“∆
	OLED_WR_Byte(0X00,OLED_CMD); //ƒђ»ѕќ™0

	OLED_WR_Byte(0x40,OLED_CMD); //…и÷√ѕ‘ Њњ™ Љ–– [5:0],–– э.
													    
	OLED_WR_Byte(0x8D,OLED_CMD); //µзЇ…±√…и÷√
	OLED_WR_Byte(0x14,OLED_CMD); //bit2£ђњ™∆ф/єЎ±’


	OLED_WR_Byte(0x20,OLED_CMD); //Set Memory Addressing Mode
	///
	//   Default => 0x02
		//     0x00 => Horizontal Addressing Mode
		//     0x01 => Vertical Addressing Mode
		//     0x02 => Page Addressing Mode
	//OLED_WR_Byte(0x02,OLED_CMD); //[1:0],00£ђЅ–µЎ÷Јƒ£ љ;01£ђ––µЎ÷Јƒ£ љ;10,“≥µЎ÷Јƒ£ љ;ƒђ»ѕ10;
	OLED_WR_Byte(0x02,OLED_CMD);
	///


	//OLED_WR_Byte(0xA1,OLED_CMD); //∂ќ÷Ў∂®“е…и÷√,bit0:0,0->0;1,0->127;
	//OLED_WR_Byte(0xC0,OLED_CMD); //…и÷√COM…®√иЈљѕт;bit3:0,∆’Ќ®ƒ£ љ;1,÷Ў∂®“еƒ£ љ COM[N-1]->COM0;N:«э∂ѓ¬Ј э
	//OLED_WR_Byte(0xDA,OLED_CMD); //Set COM Pins Hardware Configuration
	//OLED_WR_Byte(0x12,OLED_CMD); //[5:4]≈д÷√

	///---------------
	OLED_WR_Byte(0xA0,OLED_CMD); //отзеркалить 0xA0/0xA1 лево-право
	OLED_WR_Byte(0xC8,OLED_CMD); //Set COM Output Scan Direction отзеркалить ветх-низ C0h/C8h
	OLED_WR_Byte(0xDA,OLED_CMD); //Set COM Pins Hardware Configuration
	OLED_WR_Byte(0x18,OLED_CMD); //[5:4] отзеркалить ветх-низ
	//-----------------
		 
	OLED_WR_Byte(0x81,OLED_CMD); //∂‘±»∂»…и÷√
	OLED_WR_Byte(0xEF,OLED_CMD); //1~255;ƒђ»ѕ0X7F (ЅЅ∂»…и÷√,‘љіу‘љЅЅ)
	OLED_WR_Byte(0xD9,OLED_CMD); //…и÷√‘§≥дµз÷№∆Џ
	OLED_WR_Byte(0xf1,OLED_CMD); //[3:0],PHASE 1;[7:4],PHASE 2;
	OLED_WR_Byte(0xDB,OLED_CMD); //…и÷√VCOMH µз—є±∂¬ 
	OLED_WR_Byte(0x30,OLED_CMD); //[6:4] 000,0.65*vcc;001,0.77*vcc;011,0.83*vcc;

	OLED_WR_Byte(0xA4,OLED_CMD); //включить дисплей

	OLED_WR_Byte(0xA6,OLED_CMD); //нормальное отображение
	//OLED_WR_Byte(0xA7,OLED_CMD); //инвертированое отображение

	//OLED_WR_Byte(0xC8,OLED_CMD);

	OLED_WR_Byte(0xAF,OLED_CMD); //њ™∆фѕ‘ Њ	 
	OLED_Clear();
}