int main(void) { // Hardware Init delay_init(); //ÑÓʱº¯Êý³õʼ»¯ pwr_init(); #ifdef YANMING3 charger_init(); if (check_standby_flag() == SUCCESS && check_charging() != CHARGING) { Key_GPIO_Config(); exti_key_init(); #ifdef DEBUG_POWER_OFF_WAKE_UP Screen_Init(); OLED_Clear(); OLED_Display_On(); draw_about_mesage(); #endif check_standby_wakeup_button_press(); // If we boot up from standby by pressing 5 times, the system will reboot again without // this code block. } #endif // OLED Init Screen_Init(); OLED_Clear(); // low_switch_power_init(); TIMx_Int_DeInit(); EXTIX_DeInit(); // Key Key_GPIO_Config(); // PID related code ADC1_Configuration(); PWM_Configuration(); VoltagePID_Init(); TIMx_Int_Init(); rtc_init(); // Our Init system_init(); #ifndef YANMING3 //iwdg_init(); #endif while(1) { #ifndef YANMING3 //iwdg_feed(); #endif task_schedule(); } }
void osd_test(void) { u8 t; OLED_Init(); //3?¨º??¡¥OLED OLED_Clear() ; t=' '; OLED_ShowCHinese(0,0,0);//?D 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);//?? while(1) { OLED_Clear(); OLED_ShowCHinese(0,0,0);//?D 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(6,3,"0.96' OLED TEST",16); OLED_ShowString(6,4,"0.96' OLED TEST",16); OLED_ShowString(0,5,"0.96' OLED TEST",16); OLED_ShowString(0,6,"0.96' OLED TEST",16); OLED_ShowString(1,7,"0.96' OLED TEST",16); OLED_ShowString(6,3,"0.96' OLED TEST",16); //OLED_ShowString(8,2,"ZHONGJINGYUAN"); // OLED_ShowString(20,4,"2014/05/01"); OLED_ShowString(0,6,"ASCII:",16); OLED_ShowString(63,6,"CODE:",16); OLED_ShowChar(48,6,t,16);//??¨º?ASCII¡Á?¡¤? t++; if(t>'~')t=' '; OLED_ShowNum(103,6,t,3,16);//??¨º?ASCII¡Á?¡¤?¦Ì????¦Ì rt_thread_delay(1000*3); OLED_DrawBMP(0,0,128,8,BMP1); //¨ª?????¨º?(¨ª?????¨º?¨¦¡Â¨®?¡ê?¨¦¨²3¨¦¦Ì?¡Á?¡À¨ª??¡ä¨®¡ê??¨¢??¨®????¨¤????¡ê?FLASH????8K¨°???¨¦¡Â¨®?) rt_thread_delay(1000*3); OLED_DrawBMP(0,0,128,8,BMP1); rt_thread_delay(1000*3); } }
void OLED_Init(void) { OLED_IO_Init(); GPIO_SetBits(OLED_Pin,OLED_SCL); GPIO_ResetBits(OLED_Pin,OLED_RST);//复位 delay_ms(50); GPIO_SetBits(OLED_Pin,OLED_RST);//复位结束 //从上电到下面开始初始化要有足够的时间,即等待RC复位完毕 OLED_Write_Command(0xAE|0x00); // Display Off (0x00/0x01) OLED_Write_Command(0xD5);OLED_Write_Command(0x80); // Set Clock as 100 Frames/Sec OLED_Write_Command(0xA8);OLED_Write_Command(0x3F); // 1/64 Duty (0x0F~0x3F) OLED_Write_Command(0xD3);OLED_Write_Command(0x00); // Shift Mapping RAM Counter (0x00~0x3F) OLED_Write_Command(0x40|0x00); // Set Mapping RAM Display Start Line (0x00~0x3F) OLED_Write_Command(0x8D);OLED_Write_Command(0x10|0x04); // Enable Embedded DC/DC Converter (0x00/0x04) OLED_Write_Command(0x20);OLED_Write_Command(0x02); // Set Page Addressing Mode (0x00/0x01/0x02) OLED_Write_Command(0xA0|0x01); // Set SEG/Column Mapping 0x00左右反置 0x01正常 OLED_Write_Command(0xC0|0x08); // Set COM/Row Scan Direction 0x00上下反置 0x08正常 OLED_Write_Command(0xDA);OLED_Write_Command(0x02|0x10); // Set Sequential Configuration (0x00/0x10) OLED_Write_Command(0x81);OLED_Write_Command(0xCF); // Set SEG Output Current OLED_Write_Command(0xD9);OLED_Write_Command(0xF1); // Set Pre-Charge as 15 Clocks & Discharge as 1 Clock OLED_Write_Command(0xDB);OLED_Write_Command(0x40); // Set VCOM Deselect Level OLED_Write_Command(0xA4|0x00); // Disable Entire Display On (0x00/0x01) OLED_Write_Command(0xA6|0x00); // Disable Inverse Display On (0x00/0x01) OLED_Write_Command(0xAE|0x01); // Display On (0x00/0x01) OLED_Clear(); // 初始清屏 OLED_Set_Pos(0,0); }
int main() { Xint16 audio_data[128]; int i; u8 *oled_equalizer_buf=(u8 *)malloc(128*sizeof(u8)); Xil_Out32(OLED_BASE_ADDR,0xff); OLED_Init(); //oled init IicConfig(XPAR_XIICPS_0_DEVICE_ID); AudioPllConfig(); //enable core clock for ADAU1761 AudioConfigure(); xil_printf("ADAU1761 configured\n\r"); /* * perform continuous read and writes from the codec that result in a loopback * from Line in to Line out */ while(1) { get_audio(audio_data); for(i=0;i<128;i++) { oled_equalizer_buf[i]=audio_data[i]>>18; } OLED_Clear(); OLED_Equalizer_128(oled_equalizer_buf); } return 0; }
/******************************************************************************* * @fn userAppInit * * @brief user Application init * * @param void * * @return none */ void userAppInit(void) { OLED_Init(); // 电池状态读初始化I2C SMB_Init(); // 串口初始化 bspUartInit(); // 按键初始化要等系统稳定后,防止外部中断引起系统死机 KEY_Init(); //电池状态检测初始化 chargeDetection_Init(); //OLED_ShowString(40,32, "WiCore"); OLED_Clear(); // Create one-shot clocks for internal periodic events. Util_constructClock(&periodicClock_10ms, userApp_clockHandler, 10, 0, false, USER_10MS_EVT); #ifndef INCLUDE_CLKSTOP systemState.powerOffFlag = 1; Util_startClock(&periodicClock_10ms); #else Util_stopClock(&periodicClock_10ms); #endif }
int main(void) { delay_init(); NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); uart_init(115200); //串口初始化为115200 Uart2_Init(115200); OLED_Init(); LED_Init(); OLED_Clear(); KEY_Init();//IO初始化 TIM3_Int_Init(499,7199);//10Khz的计数频率,计数到500为50ms NET_Init(); ConnectToDevice(); delay_ms(300); LED2 = 0; delay_ms(100); LED2 = 1; EEPROM_Init(); // ReadLedStatusFromFlash(); StartToUploadFlag = 1; while(1) { MainMenuIntoSubMenu(); SwitchDetect(); } }
void sys_driver_init() { //open screen gpio_setup(SCREES_DC, GPIO_OUTPUT); gpio_write(SCREES_DC, 0); //screen reset gpio_setup(SCREES_RES, GPIO_OUTPUT); gpio_write(SCREES_RES, 1); //rgb led uint8_t led_pin[] = {28, 29, 30}; light_setup(led_pin, 0); //init screen SSD1306_Init_Struct init_struct; init_struct.SCL = 9; init_struct.SDA = 8; ssd1306_config(&init_struct); OLED_Init(); OLED_Clear(); gfx_init_screen((uint8_t *)&screen, 128, 32, 1); gfx_clear(); OLED_Refresh_all(); //hall task gpio_change_point = NULL; gpio_watch(HALL, GPIO_FALLING); //button gpio_setup(BUTTON, GPIO_INPUT_PULLUP); }
void menu_Run() { switch(menu_Mode) { case show_time_1: OLED_Clear(0,0,127,7); OLED_ShowString(16,0,":"); OLED_ShowString(40,0,":"); menu_Showtime(); menu_Mode = show_time; break; case show_time : menu_Showtime(); break; case show_sen_1: OLED_Clear(0,0,127,7); OLED_ShowString(16+24,0,"cm"); OLED_ShowString(0,0,"H:"); OLED_ShowString(0,2,"P:"); OLED_ShowString(0,4,"R:"); OLED_ShowString(0,6,"Y:"); menu_Showsen(); menu_Mode = show_sen; break; case show_sen : menu_Showsen(); break; case set_sen_1: OLED_ShowString(0,0,"S_Height:"); OLED_ShowString(0,2,"P_offset:"); OLED_ShowString(0,4,"R_offset:"); OLED_ShowString(0,6,"Y_offset:"); OLED_ShowNum(72,0,Expect.hight,3,18,0); OLED_ShowFloat(72,2,sen.angle_test_offset.pitch - 10.00f,2); OLED_ShowFloat(72,4,sen.angle_test_offset.roll - 10.00f,2); OLED_ShowFloat(72,6,sen.angle_test_offset.yaw - 10.00f,2); OLED_ShowChar(120,0,'S'); menu_Mode = set_sen; break; case set_sen: menu_Setsen(); menu_Mode = show_time_1; break; default: break; } }
void Get_ZeroGauss_OffsetXY( int16_t* pMField_X_Raw_Offset, int16_t* pMField_Y_Raw_Offset ) { #define NUM_CALIB_CIRCLES 1 // Calibration performed by taking 8 measurements 45deg apart, // repeated NUM_CALIB_CIRCLES times uint8_t i; uint8_t MField_X_LowByte, MField_X_HighByte; uint8_t MField_Y_LowByte, MField_Y_HighByte; int16_t MField_X_Raw, MField_Y_Raw; int32_t MField_X_Acc = 0, MField_Y_Acc = 0; uint16_t ColorSequence[8] = {RED, WHITE, GREEN, BLUE, CYAN, ORANGE, LIGHT_BLUE, YELLOW } ; // Display Instructions : OLED_PrintString("CALIBRATION\n\n"); OLED_PrintString("Lay La BlueFrog flat\n"); OLED_PrintString("Then rotate it 45 deg.\n at each change of color:"); Delay_ms(5000); // Go --- 8 equally spaced magnetic field measurements, repeatable n times per #define for (i=0; i < 8*NUM_CALIB_CIRCLES; i++) { OLED_Fill( X_FULL_SCREEN/2 -20, Y_FULL_SCREEN/2-20, 40, 40, ColorSequence[i] ); Delay_ms(2500); Stm32_Led_ON(); // SINGLE SHOT conversion : CTRL_REG3 @0x22 : I2C2_WriteSingleReg(LIS3MDL_CHIPID, 0x22, 0x01); // 0b00000001 while ( (I2C2_ReadSingleReg(LIS3MDL_CHIPID, 0x27)& 0x08) != 0x08); // read status reg until it flags new XYZ data available // Accumulate Results MField_X_LowByte = I2C2_ReadSingleReg(LIS3MDL_CHIPID, 0x28); MField_X_HighByte = I2C2_ReadSingleReg(LIS3MDL_CHIPID, 0x29); MField_X_Raw = (int16_t)( (MField_X_HighByte <<8 ) | MField_X_LowByte ); MField_X_Acc += (int32_t)(MField_X_Raw); MField_Y_LowByte = I2C2_ReadSingleReg(LIS3MDL_CHIPID, 0x2A); MField_Y_HighByte = I2C2_ReadSingleReg(LIS3MDL_CHIPID, 0x2B); MField_Y_Raw = (int16_t)( (MField_Y_HighByte <<8 ) | MField_Y_LowByte ); MField_Y_Acc += (int32_t)(MField_Y_Raw); Stm32_Led_OFF(); } *pMField_X_Raw_Offset = (int16_t)(MField_X_Acc / i); *pMField_Y_Raw_Offset = (int16_t)(MField_Y_Acc / i); GUI_DispStringAt("", 10, 90); OLED_PrintString("THANKS,\nCALIBRATION DONE !"); Delay_ms(2000); OLED_Clear(); }
/*====================================================================================================*/ void KDWM_SSD1331_Config( void ) { SSD1331_Config(); delay_ms(100); SSD1331_Init(); OLED_Clear(BLACK); // OLED_TestColoBar(); }
/* * 液晶初始化 */ void OLED_Init(void) { OLED_Pin_Init(OLED_PORT, OLED_SCL); //GPIO_Init(OLED_PORT, OLED_SCL, OUT, 1); OLED_Pin_Init(OLED_PORT, OLED_SDA); //GPIO_Init(OLED_PORT, OLED_SDA, OUT, 1); OLED_Pin_Init(OLED_PORT, OLED_RST); //GPIO_Init(OLED_PORT, OLED_RST, OUT, 1); OLED_Pin_Init(OLED_PORT, OLED_DC); //GPIO_Init(OLED_PORT, OLED_DC, OUT, 1); //配置OLED端口引脚为GPIO输出 OLED_D0_OH; OLED_RST_OL; OLED_Delay_ms(50); OLED_RST_OH; /* 从上电到下面开始初始化要有足够的时间,即等待RC复位完毕 */ OLED_WrCmd(0xAE | 0x00); // Display Off (0x00) OLED_WrCmd(0xD5); OLED_WrCmd(0x80); // Set Clock as 100 Frames/Sec OLED_WrCmd(0xA8); OLED_WrCmd(0x3F); // 1/64 Duty (0x0F~0x3F) OLED_WrCmd(0xD3); OLED_WrCmd(0x00); // Shift Mapping RAM Counter (0x00~0x3F) OLED_WrCmd(0x40 | 0x00); // Set Mapping RAM Display Start Line (0x00~0x3F) OLED_WrCmd(0x8D); OLED_WrCmd(0x10 | 0x04); // Enable Embedded DC/DC Converter (0x00/0x04) OLED_WrCmd(0x20); OLED_WrCmd(0x02); // Set Page Addressing Mode (0x00/0x01/0x02) OLED_WrCmd(0xA0 | 0x01); // Set SEG/Column Mapping 0x00左右反置 0x01正常 OLED_WrCmd(0xC0 | 0x08); // Set COM/x Scan Direction 0x00上下反置 0x08正常 OLED_WrCmd(0xDA); OLED_WrCmd(0x02 | 0x10); // Set Sequential Configuration (0x00/0x10) OLED_WrCmd(0x81); OLED_WrCmd(0xCF); // Set SEG Output Current OLED_WrCmd(0xD9); OLED_WrCmd(0xF1); // Set Pre-Charge as 15 Clocks & Discharge as 1 Clock OLED_WrCmd(0xDB); OLED_WrCmd(0x40); // Set VCOM Deselect Level OLED_WrCmd(0xA4 | 0x00); // Disable Entire Display On (0x00/0x01) OLED_WrCmd(0xA6 | 0x00); // Disable Inverse Display On (0x00/0x01) OLED_WrCmd(0xAE | 0x01); // Display On (0x01) OLED_Clear(); //初始清屏 OLED_Set_XY(0,0); }
/** * @brief This function handles Hard Fault exception. * @param None * @retval None */ void HardFault_Handler(void) { /* Go to infinite loop when Hard Fault exception occurs */ Moto_PwmUpdate(0,0,0,0); OLED_Clear(0,0,127,7); OLED_ShowString(0,0,"HardFault_Handler"); while (1) { } }
void osd_init(void) { OLED_Init(); //3?¨º??¡¥OLED OLED_Clear() ; osd_line_1to4_all_disp(); }
void OLED_Init(void) { Init_IC(); OLED_Clear(); // All_Screen(); // OLED_ShowNum(0, 0, 2567890134, 10, 16); // update_battery(30); OLED_Refresh_Gram(); // oled_display(image2); }
void EXTI3_IRQHandler(void) { if(EXTI_GetITStatus(EXTI_Line3)!=RESET) { OLED_Clear(); OLED_ShowString(0,0,"shutdown"); printf("/r/nshutdown"); } Board_Down(); EXTI_ClearITPendingBit(EXTI_Line3); }
//! Initialize the OLED display. //! \param ulFrequency specifies the SSI Clock Frequency to be used. //OLED初始化 void OLED_Init(unsigned long ulFrequency) { unsigned long ulIdx; // // Enable the SSI0 and GPIO port blocks as they are needed by this driver. // SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIO_OLEDDC); // // Configure the SSI0CLK and SSIOTX pins for SSI operation. // GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_5); GPIOPadConfigSet(GPIO_PORTA_BASE, GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_5, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD_WPU); // // Configure the GPIO port pin used as a D/Cn signal for OLED device, // and the port pin used to enable power to the OLED panel. // GPIOPinTypeGPIOOutput(GPIO_OLEDDC_BASE, GPIO_OLEDDC_PIN | GPIO_OLEDEN_PIN); GPIOPadConfigSet(GPIO_OLEDDC_BASE, GPIO_OLEDDC_PIN | GPIO_OLEDEN_PIN, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD); GPIOPinWrite(GPIO_OLEDDC_BASE, GPIO_OLEDDC_PIN | GPIO_OLEDEN_PIN, GPIO_OLEDDC_PIN | GPIO_OLEDEN_PIN); HWREGBITW(&g_ulSSIFlags, FLAG_DC_HIGH) = 1; // // Configure and enable the SSI0 port for master mode. // OLED_Enable(ulFrequency); // // Clear the frame buffer. // OLED_Clear(); // // Initialize the SSD1329 controller. Loop through the initialization // sequence array, sending each command "string" to the controller. // for(ulIdx = 0; ulIdx < sizeof(OLED_INIT_CMD); ulIdx += OLED_INIT_CMD[ulIdx] + 1) { // // Send this command. // RITWriteCommand(OLED_INIT_CMD + ulIdx + 1, OLED_INIT_CMD[ulIdx] - 1); } }
//显示字符串 //x,y:起点坐标 //*p:字符串起始地址 //用16字体 void OLED_ShowString(u8 x,u8 y,const u8 *p) { #define MAX_CHAR_POSX 122 #define MAX_CHAR_POSY 58 while(*p!='\0') { if(x>MAX_CHAR_POSX){x=0;y+=16;} if(y>MAX_CHAR_POSY){y=x=0;OLED_Clear();} OLED_ShowChar(x,y,*p,16,1); x+=8; p++; } }
////////////////////////////////////////////////////////////////////// //初始化SSD1306 void OLED_Init(void) { spi_base_address = spi_master_init(SPI0, SPI_MODE0, 0); if (spi_base_address == 0) { return ; } nrf_gpio_cfg_output(OLED_RST); // OLED Reset pin nrf_gpio_cfg_output(OLED_RS); // DC control pin OLED_RST_Set(); OLED_RST_Clr(); // delay_ms(100); nrf_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); //设置内存地址模式 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(0xFF,OLED_CMD); //1~255;默认0X7F (亮度设置,越大越亮) OLED_WR_Byte(OLED_Contrast,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(); }
//退出 void Menu_Quit(void) { if(Key_2 == 0) { DelayMs(100); if(Key_2 == 0) { OLED_Clear(); CCD_Flag = 0; PIT_Stop(PIT1); FTM_PWM_ChangeDuty(FTM0_CH3_PA6,0); } } }
/** * @brief Show small dialogue * @param string: Passage time: Time of the dialoue that lasts occupyThread:Will ShowSmallDialogue() occupies thread until time is up */ void ShowSmallDialogue(const char string[], u16 time, bool occupyThread) { u8 startAddr, endAddr; u8 stringLength; stringLength = GetStringGraphicalLength(string); startAddr = 63 - stringLength * 4; endAddr = startAddr + stringLength * 8; xSemaphoreTake(OLEDRelatedMutex, portMAX_DELAY); OLED_Clear(); OLED_DrawRect(startAddr - 4, 20, endAddr + 4, 44, DRAW); OLED_ShowAnyString(startAddr, 24, string, NotOnSelect, 16); OLED_Refresh_Gram(); if (occupyThread) { vTaskDelay(time / portTICK_RATE_MS); } xSemaphoreGive(OLEDRelatedMutex); if (occupyThread) { xSemaphoreTake(OLEDRelatedMutex, portMAX_DELAY); OLED_Clear(); xSemaphoreGive(OLEDRelatedMutex); } }
//------------------------------------------------------------------------------------------------------------------------ // OLED_Init: Initialisiert das Display und schaltet es ein //------------------------------------------------------------------------------------------------------------------------ void OLED_Init() { const BYTE bInitSeq[] = { 0xFD, // Command Un Lock 0x12, 0xAE, // Display off 0xD5, // Set Display Clock Divide Ratio / Oscillator Frequency 0xA0, 0xA8, // Set Multiplex-Ratio 0x3F, 0xD3, // Set Display Offset 0x00, 0x40, // Set Display Start-Line // 0xA1, // Set Segment Remap ( Text wie in Spirometer ) 0xA0, // Set Segment Remap ( Text wie in EIS ) // 0xC8, // Set COM Output Scan Direction (Remapped) ( Text wie in Spirometer ) 0xC0, // Set COM Output Scan Direction (Normal) ( Text wie in EIS ) 0xDA, // Set COM-Pins Hardware Configuration 0x12, // Set COL Output Scan Direction (Remapped) ( Text wie in Spirometer ) 0x81, // Set Current Control 0xE3, 0xD9, // Set Pre-Charge Period 0x19, 0xDB, // Set VCOMH Deselect Level 0x34, 0xA4, // Set Entire Display on 0xA6 // Set Normal Display (not inverse) // 0x20 // Set Horizontal Addressing Mode (geht nicht da sonst Set_Position nicht funktioniert }; OLED_RESET_LOW; __delay_cycles(MCLK_FREQ * 0.00001f); // 10µs low OLED_RESET_HIGH; __delay_cycles(MCLK_FREQ * 0.00001f); // 10µs high bevor es weiter geht for (BYTE i=0; i<sizeof(bInitSeq); i++) OLED_WR_CMD( bInitSeq[i] ); OLED_Clear(); OLED_On(30); __delay_cycles(MCLK_FREQ * 0.1); // 0,1sec = 100ms warten (Recommended Delay) }
//初始化SSD1306 void OLED_Init(void) { //#if (FB_OLED && FB_SPI_OLED) // spi_init(QN_SPI1, SPI_BITRATE(1000000), SPI_8BIT, SPI_MASTER_MOD); //#endif oled_io_config(); OLED_RST_Set(); delay(100000); OLED_RST_Clr(); delay(100000); 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); }
void oled_update_step_count(void) { static bool flag = false; OLED_Clear(); if(flag) { OLED_ShowImg(0, 0, PEDO_IMAGE_1, 1); flag = false; } else { OLED_ShowImg(0, 0, PEDO_IMAGE_2, 1); flag = true; } OLED_ShowNum(7, 0, get_the_step_count(), 6, 32); OLED_Refresh_Gram(); }
void NMI_Handler(void)//?????? { OLED_Clear(); FTM_PWM_ChangeDuty(FTM0_CH3_PA6,0); FTM_PWM_ChangeDuty(FTM0_CH4_PA7,0); // FTM_PWM_ChangeDuty(FTM1_CH0_PA8,0); // FTM_PWM_ChangeDuty(FTM1_CH1_PA9,0); OLED_Write_String(0,0,(uint8_t *)"The Chip"); OLED_Write_String(0,2,(uint8_t *)"have big"); OLED_Write_String(0,4,(uint8_t *)"error"); #if(CHIP_DEBUG==ON) wait(); #endif while(1); }
void HardFault_Handler(void)//????????? { OLED_Clear(); FTM_PWM_ChangeDuty(FTM0_CH3_PA6,0); FTM_PWM_ChangeDuty(FTM0_CH4_PA7,0); // FTM_PWM_ChangeDuty(FTM1_CH0_PA8,0); // FTM_PWM_ChangeDuty(FTM1_CH1_PA9,0); OLED_Write_String(0,0,(uint8_t *)"The memory"); OLED_Write_String(0,2,(uint8_t *)"or Stacks"); OLED_Write_String(0,4,(uint8_t *)"overflows"); #if(CHIP_DEBUG==ON) wait(); #endif while(1); }
void oled_test(void) { //Reset_IC(); Init_IC(); Clear_Screen(); All_Screen(); OLED_Clear(); OLED_ShowNum(0, 0, 2567890134, 10, 12); OLED_ShowString(0, 12, "abcdefghijk"); while(1) { OLED_Refresh_Gram(); nrf_delay_ms(1500); Clear_Screen(); } }
//初始化SSD1306 void OLED_Init(void) { Clr_OLED_VDD; usleep(300); // 300us Clr_OLED_RES; usleep(30000); // 30ms Set_OLED_RES; usleep(30000); // 30ms Clr_OLED_VBAT; write_cmd(0xAE); //关闭显示 write_cmd(0xD5); //设置时钟分频因子,震荡频率 write_cmd(0x80); //[3:0],分频因子;[7:4],震荡频率 write_cmd(0xA8); //设置驱动路数 write_cmd(0X3F); //默认0X3F(1/64) write_cmd(0xD3); //设置显示偏移 write_cmd(0X00); //默认为0 write_cmd(0x40); //设置显示开始行 [5:0],行数. write_cmd(0x8D); //电荷泵设置 write_cmd(0x14); //bit2,开启/关闭 write_cmd(0x20); //设置内存地址模式 write_cmd(0x02); //[1:0],00,列地址模式;01,行地址模式;10,页地址模式;默认10; write_cmd(0xA1); //段重定义设置,bit0:0,0->0;1,0->127; write_cmd(0xC0); //设置COM扫描方向;bit3:0,普通模式;1,重定义模式 COM[N-1]->COM0;N:驱动路数 write_cmd(0xDA); //设置COM硬件引脚配置 write_cmd(0x12); //[5:4]配置 write_cmd(0x81); //对比度设置 write_cmd(0xEF); //1~255;默认0X7F (亮度设置,越大越亮) write_cmd(0xD9); //设置预充电周期 write_cmd(0xf1); //[3:0],PHASE 1;[7:4],PHASE 2; write_cmd(0xDB); //设置VCOMH 电压倍率 write_cmd(0x30); //[6:4] 000,0.65*vcc;001,0.77*vcc;011,0.83*vcc; write_cmd(0xA4); //全局显示开启;bit0:1,开启;0,关闭;(白屏/黑屏) write_cmd(0xA6); //设置显示方式;bit0:1,反相显示;0,正常显示 write_cmd(0xAF); //开启显示 OLED_Clear(); }
///////////////////////////////////////////////////////////////////// //显示字符串 //x,y:起点坐标 //*p:字符串起始地址 //用16字体 void OLED_ShowString(uint8_t x,uint8_t y, uint8_t *p) { #define MAX_CHAR_POSX 122 //#define MAX_CHAR_POSY 58 #define MAX_CHAR_POSY 64 while(*p!='\0') { if(x>MAX_CHAR_POSX) { x=0;y+=16; } if(y>MAX_CHAR_POSY) { y=x=0;OLED_Clear(); } OLED_ShowChar(x,y,*p,16,1); x+=8; p++; } }
void OLED_Init(PmodOLED *InstancePtr, u32 GPIO_Address, u32 SPI_Address, bool orientation, bool invert) { /* Init the PIC32 peripherals used to talk to the display. */ OLED_HostInit(InstancePtr, GPIO_Address, SPI_Address); /* Init the memory variables used to control access to the ** display. */ OLED_DvrInit(InstancePtr); /* Init the OLED display hardware. */ OLED_DevInit(InstancePtr, orientation, invert); /* Clear the display. */ OLED_Clear(InstancePtr); }
/****************************************************** Function: void OLED_Init(void) Description: 驱动端口初始化、SSD1306初始化。 Calls: void OLED_Init(void); //驱动端口初始化 void OLED_WCMD(u8 cmd); //向SSD1306写命令 ******************************************************/ void OLED_SetInit(void) { OLED_Init(); //端口初始化 OLED_WCMD(0xAE); //关闭显示 OLED_WCMD(0xD5); //设置时钟分频因子,震荡频率 OLED_WCMD(0x50); //[3:0],分频因子;[7:4],震荡频率 OLED_WCMD(0xA8); //设置驱动路数 OLED_WCMD(0x3F); //默认0X3F(1/64) OLED_WCMD(0xD3); //设置显示偏移 OLED_WCMD(0x00); //默认为0 OLED_WCMD(0x40); //设置显示开始行 [5:0],行数. OLED_WCMD(0x8D); //电荷泵设置 OLED_WCMD(0x14); //bit2,开启/关闭 OLED_WCMD(0x20); //设置内存寻址模式 OLED_WCMD(0x02); //[1:0],00,列地址模式;01,行地址模式;10,页地址模式;默认10; OLED_WCMD(0xA1); //段重定义设置,bit0: 0,column 0->SEG 0; 1,column 0->SEG 127; OLED_WCMD(0xC8); //设置COM扫描方向;bit3:0,普通模式;1,重定义模式 COM[N-1]->COM0;N:驱动路数 OLED_WCMD(0xDA); //设置COM硬件引脚配置 [5:4]配置 配置COM(SSD1306)与ROW(液晶)的连接关系 OLED_WCMD(0x12); //[5:4]配置 配置COM(SSD1306)与ROW(液晶)的连接关系 OLED_WCMD(0x81); //对比度设置 OLED_WCMD(0xEF); //1~255;默认0X7F (亮度设置,越大越亮) OLED_WCMD(0xD9); //设置预充电周期 OLED_WCMD(0xF1); //[3:0],PHASE 1;[7:4],PHASE 2; OLED_WCMD(0xDB); //设置VCOMH 电压倍率 OLED_WCMD(0x30); //[6:4] 000,0.65*vcc;001,0.77*vcc;011,0.83*vcc; OLED_WCMD(0xA4); //全局显示开启;bit0:1,开启;0,关闭;(白屏/黑屏) OLED_WCMD(0xA6); //设置显示方式;bit0:1,反相显示;0,正常显示 OLED_WCMD(0xAF); //开启显示 OLED_Clear(); //清屏 }