#include "oled2.h" #include "app.h" /*******************************************Ä£ÄâI2C***********************************************************/ static void i2c_Delay(void) { uint8_t i; /*¡¡ ÏÂÃæµÄʱ¼äÊÇͨ¹ýÂß¼­·ÖÎöÒDzâÊԵõ½µÄ¡£ ¹¤×÷Ìõ¼þ£ºCPUÖ÷Ƶ72MHz £¬MDK±àÒë»·¾³£¬1¼¶ÓÅ»¯ Ñ­»·´ÎÊýΪ10ʱ£¬SCLƵÂÊ = 205KHz Ñ­»·´ÎÊýΪ7ʱ£¬SCLƵÂÊ = 347KHz£¬ SCL¸ßµçƽʱ¼ä1.5us£¬SCLµÍµçƽʱ¼ä2.87us Ñ­»·´ÎÊýΪ5ʱ£¬SCLƵÂÊ = 421KHz£¬ SCL¸ßµçƽʱ¼ä1.25us£¬SCLµÍµçƽʱ¼ä2.375us */ for (i = 0; i < 10; i++) ; } void i2c_Start(void) { /* µ±SCL¸ßµçƽʱ£¬SDA³öÏÖÒ»¸öÏÂÌøÑØ±íʾI2C×ÜÏ߯ô¶¯ÐźŠ*/ BSP_I2C_SDA_1(); BSP_I2C_SCL_1(); i2c_Delay(); BSP_I2C_SDA_0(); i2c_Delay(); BSP_I2C_SCL_0(); i2c_Delay(); } void i2c_Stop(void) { /* µ±SCL¸ßµçƽʱ£¬SDA³öÏÖÒ»¸öÉÏÌøÑØ±íʾI2C×ÜÏßÍ£Ö¹ÐźŠ*/ BSP_I2C_SDA_0(); BSP_I2C_SCL_1(); i2c_Delay(); BSP_I2C_SDA_1(); } void i2c_SendByte(uint8_t _ucByte) { uint8_t i; /* ÏÈ·¢ËÍ×ֽڵĸßλbit7 */ for (i = 0; i < 8; i++) { if (_ucByte & 0x80) { BSP_I2C_SDA_1(); } else { BSP_I2C_SDA_0(); } i2c_Delay(); BSP_I2C_SCL_1(); i2c_Delay(); BSP_I2C_SCL_0(); if (i == 7) { BSP_I2C_SDA_1(); // ÊÍ·Å×ÜÏß } _ucByte <<= 1; /* ×óÒÆÒ»¸öbit */ i2c_Delay(); } } uint8_t i2c_ReadByte(void) { uint8_t i; uint8_t value; /* ¶Áµ½µÚ1¸öbitΪÊý¾ÝµÄbit7 */ value = 0; for (i = 0; i < 8; i++) { value <<= 1; BSP_I2C_SCL_1(); i2c_Delay(); if (BSP_I2C_SDA_READ()) { value++; } BSP_I2C_SCL_0(); i2c_Delay(); } return value; } uint8_t i2c_WaitAck(void) { uint8_t re; BSP_I2C_SDA_1(); /* CPUÊÍ·ÅSDA×ÜÏß */ i2c_Delay(); BSP_I2C_SCL_1(); /* CPUÇý¶¯SCL = 1, ´ËʱÆ÷¼þ»á·µ»ØACKÓ¦´ð */ i2c_Delay(); if (BSP_I2C_SDA_READ()) /* CPU¶ÁÈ¡SDA¿ÚÏß״̬ */ { re = 1; } else { re = 0; } BSP_I2C_SCL_0(); i2c_Delay(); return re; } void i2c_Ack(void) { BSP_I2C_SDA_0(); /* CPUÇý¶¯SDA = 0 */ i2c_Delay(); BSP_I2C_SCL_1(); /* CPU²úÉú1¸öʱÖÓ */ i2c_Delay(); BSP_I2C_SCL_0(); i2c_Delay(); BSP_I2C_SDA_1(); /* CPUÊÍ·ÅSDA×ÜÏß */ } void i2c_NAck(void) { BSP_I2C_SDA_1(); /* CPUÇý¶¯SDA = 1 */ i2c_Delay(); BSP_I2C_SCL_1(); /* CPU²úÉú1¸öʱÖÓ */ i2c_Delay(); BSP_I2C_SCL_0(); i2c_Delay(); } void i2c_CfgGpio(void) { GPIO_InitTypeDef GPIO_InitStruct = {0}; I2Cx_SCL_GPIO_CLK_ENABLE(); I2Cx_SDA_GPIO_CLK_ENABLE(); /**I2C2 GPIO Configuration PB10 ------> I2C2_SCL PB9 ------> I2C2_SDA */ GPIO_InitStruct.Pin = BSP_I2C_SCL_PIN | BSP_I2C_SDA_PIN; ; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; HAL_GPIO_Init(BSP_GPIO_PORT_I2C, &GPIO_InitStruct); /* ¸øÒ»¸öÍ£Ö¹ÐźÅ, ¸´Î»I2C×ÜÏßÉϵÄËùÓÐÉ豸µ½´ý»úģʽ */ i2c_Stop(); } /*******************************************Ä£ÄâI2C***********************************************************/ //static uint8_t sendBuffer[2] = {0}; //void OLED2_Send(uint8_t *data, uint8_t len)//·¢ËÍÊý¾Ý 8bit * len //{ // //HAL_I2C_Master_Transmit(&hi2c1, SSD1306_I2C_ADDR| 0x00, data, len,10);//1000 //} //void SSD1306_WriteCmd(uint8_t cmd)//·¢ËÍÃüÁî [0x00;cmd] //{ // sendBuffer[0] = 0x00; // sendBuffer[1] = cmd; // OLED2_Send(sendBuffer, 2); // delay_us(50); //} void SSD1306_WriteCmd(uint8_t cmd) { // sendBuffer[0] = 0x00; // sendBuffer[1] = cmd; // HAL_I2C_Master_Transmit(&hi2c1,SSD1306_I2C_ADDR,sendBuffer, 2,20); i2c_Start(); i2c_SendByte(SSD1306_I2C_ADDR | 0x00); i2c_Ack(); i2c_SendByte(0x00); //cmd i2c_Ack(); i2c_SendByte(cmd); i2c_Ack(); i2c_Stop(); } void SSD1306_WriteData(uint8_t data) { // sendBuffer[0] = 0x40; // sendBuffer[1] = data; // OLED2_Send(sendBuffer, 2); i2c_Start(); i2c_SendByte(SSD1306_I2C_ADDR | 0x00); i2c_Ack(); i2c_SendByte(0x40); //data i2c_Ack(); i2c_SendByte(data); i2c_Ack(); i2c_Stop(); } //SSD1306??? void OLED2_Init(void) { delay_us(500000); //SSD1306????,????????? SSD1306_WriteCmd(0xAE);//--display off SSD1306_WriteCmd(0x00);//--set low column address SSD1306_WriteCmd(0x10);//--set high column address SSD1306_WriteCmd(0x40);//--set start line address SSD1306_WriteCmd(0xB0);//--set page address SSD1306_WriteCmd(0x81);// contract control SSD1306_WriteCmd(0xFF);//--128 // SSD1306_WriteCmd(0xA1);//set segment re-map 0 to 127 SSD1306_WriteCmd(0xA0);//×óÓÒ·­×ª SSD1306_WriteCmd(0xA6);//set normal display SSD1306_WriteCmd(0xA8);//set multiplex ratio(1 to 64) SSD1306_WriteCmd(0x3F);//--1/32 duty // SSD1306_WriteCmd(0xC8);//Com scan direction SSD1306_WriteCmd(0xC0);//ÉÏÏ·­×ª SSD1306_WriteCmd(0xD3);//set display offset SSD1306_WriteCmd(0x00);//no offset SSD1306_WriteCmd(0xD5);//set display clock divide ratio/oscillator frequency SSD1306_WriteCmd(0x80);// SSD1306_WriteCmd(0xD8);//set area color mode off SSD1306_WriteCmd(0x05);// SSD1306_WriteCmd(0xD9);//Set Pre-Charge Period SSD1306_WriteCmd(0xF1);// SSD1306_WriteCmd(0xDA);//set com pin hardware configuartion SSD1306_WriteCmd(0x12);// SSD1306_WriteCmd(0xDB);//set Vcomh SSD1306_WriteCmd(0x30);//0x20,0.77xVcc SSD1306_WriteCmd(0x8D);//set charge pump enable SSD1306_WriteCmd(0x14);// SSD1306_WriteCmd(0xAF);//--turn on oled panel OLED_Clear(); } //????:???????? void OLED_SetPos(uint8_t x, uint8_t y) { //??3??????????????? SSD1306_WriteCmd(0xb0+y); //????? 0xb0~0xb7 SSD1306_WriteCmd(((x&0xf0)>>4)|0x10); //??????? SSD1306_WriteCmd((x&0x0f)); //??????? } //??OLED?? void OLED_DisplayOn(void) { SSD1306_WriteCmd(0X8D); //SET DCDC?? SSD1306_WriteCmd(0X14); //DCDC ON SSD1306_WriteCmd(0XAF); //DISPLAY ON } //??OLED?? void OLED_DisplayOff(void) { SSD1306_WriteCmd(0X8D); //SET DCDC?? SSD1306_WriteCmd(0X10); //DCDC OFF SSD1306_WriteCmd(0XAE); //DISPLAY OFF } //????,???,????????!?????? //int clr_i = 0; //uint8_t clr_n = 0; void OLED_Clear(void) { // clr_i *= (clr_i<8); int i; uint8_t n; for(i=0;i<8;i++) { SSD1306_WriteCmd (0xb0+i); //?????(0~7) SSD1306_WriteCmd (0x00); //??????—???? SSD1306_WriteCmd (0x10); //??????—???? for(n = 0;n < 128;n++) SSD1306_WriteData(0); } //???? // clr_i++; } //???????????,?????? //x:0~127,y:0~7 //Char_Size:???? 16/12 //uint8_t sc_i = 0; void OLED_ShowChar(uint8_t x,uint8_t y,uint8_t chr,uint8_t Char_Size,uint8_t color) { uint8_t c=0,i=0; // uint8_t c = 0; c=chr-' ';//??????? if(x>MAX_COLUMN-1) { x=0; y=y+2; } if(Char_Size ==16) { if(color == 0) { OLED_SetPos(x,y); for(i=0;i<8;i++) { SSD1306_WriteData(F8X16[c*16+i]);//?????? } OLED_SetPos(x,y+1); for(i=0;i<8;i++) { SSD1306_WriteData(F8X16[c*16+i+8]);//?????? } } if(color == 1) { OLED_SetPos(x,y); for(i=0;i<8;i++) { SSD1306_WriteData(~F8X16[c*16+i]);//?????? } OLED_SetPos(x,y+1); for(i=0;i<8;i++) { SSD1306_WriteData(~F8X16[c*16+i+8]);//?????? } } } else { OLED_SetPos(x,y); for(i=0;i<6;i++) { SSD1306_WriteData(F6x8[c][i]); } // sc_i *= (sc_i<6); // OLED_SetPos(x,y); // SSD1306_WriteData(F6x8[c][sc_i]); // sc_i++; } } //??????? void OLED_ShowString(uint8_t x,uint8_t y,char *str,uint8_t Char_Size,uint8_t color) { unsigned char j=0; while (str[j]!='\0') { OLED_ShowChar(x,y,str[j],Char_Size,color); x+=8; if(x>120) { x=0; y+=2; } j++;//????????page,??0-7 } } //???? //?????16*16???,??????4??? //index:????????? void OLED_ShowCN(uint8_t x,uint8_t y,uint8_t index,uint8_t color) { uint8_t t; if(color == 0) { OLED_SetPos(x,y); for(t=0;t<16;t++) { SSD1306_WriteData(Hzk[index][t]); } OLED_SetPos(x,y+1); for(t=0;t<16;t++) { SSD1306_WriteData(Hzk[index][t+16]); } } if(color == 1) { OLED_SetPos(x,y); for(t=0;t<16;t++) { SSD1306_WriteData(~Hzk[index][t]); } OLED_SetPos(x,y+1); for(t=0;t<16;t++) { SSD1306_WriteData(~Hzk[index][t+16]); } } } char str_print2[16] = {0},str_print3[16] = {0}; float Xads_temp2[2] = {0},T_temp2[2] = {0},OC1_temp[2] = {0},OC2_temp[2] = {0}; char disp_step2 = 0; void OLED_DisplayTest(void) { switch(disp_step2) { case 0 :// ³õʼ»¯ { OLED2_Init(); disp_step2++; } break; case 1 :// ÏÔʾ²»¶¯ { disp_step2++; OLED_ShowString(0,0,(char *)("Pos"),16,0); //(x,y,char,size,color), color{0Õý³££¬1·´ÏÔ},x{0-128},y{} sprintf(str_print2, "%.2f",X_ads1220 ); // µç×è³ß OLED_ShowString(0,2,str_print2,16,0); OLED_ShowString(0,4,(char *)("Temp"),16,0); sprintf(str_print2, "%.2f",TEMP_M1820 ); //ÎÂ¶È OLED_ShowString(40,6," ",16,0); OLED_ShowString(48,2,(char *)("mv"),16,0); } break; case 2 :// ÏÔʾ¶¯µÄ²¿·Ö { //λÖà Xads_temp2[0] = X_ads1220; if(Xads_temp2[1] - Xads_temp2[0] > 0.001 ) { OLED_ShowString(40,2," ",16,0); sprintf(str_print2, "%.2f",Xads_temp2[0]*100 ); // µç×è³ß OLED_ShowString(0,2,str_print2,16,0); Xads_temp2[1] = Xads_temp2[0]; } //ÎÂ¶È T_temp2[0] = TEMP_M1820; if(T_temp2[1] != T_temp2[0]) { sprintf(str_print2, "%.2f",T_temp2[1] ); //ÎÂ¶È OLED_ShowString(40,6," ",16,0); OLED_ShowString(0,6,str_print2,16,0); T_temp2[1] = T_temp2[0]; } } break; default :// { disp_step2 = 0; } break; } } char oled_p = 0,oled_s[2] = {0},oled_en = 0,oled_s_motorok[2] = {0},oled_s_magnetok[2] = {0}; char para_flag = 0,motor_flag1 = 0,motor_flag2 = 0,magnet_flag = 0; unsigned int step_temp[2] = {1,1},smp_intr_temp[2] = {0},smp_dpth_temp[2] = {0}; char run_mode_temp[2] = {0}; int direc_temp[2] = {1,1}; void OLED_MenuTest(void) { switch(oled_p) { case 0: //³õʼ»¯ { OLED2_Init(); oled_p++; } break; case 1: //ÏÔʾ²»¶¯µÄÄÚÈÝ { OLED_Clear(); OLED_ShowString(0,0," ",16,1); OLED_ShowString(80,0," ",16,1); OLED_ShowCN(48,0,0,1); OLED_ShowCN(64,0,1,1); OLED_ShowString(0,2,"Parameter ",16,0); OLED_ShowString(0,4,"Motor Control",16,0); OLED_ShowString(0,6,"Magnet Sample",16,0); if(oled_s[0] == 0) OLED_ShowChar(112,2,'<',16,0); if(oled_s[0] == 1) OLED_ShowChar(112,4,'<',16,0); if(oled_s[0] == 2) OLED_ShowChar(112,6,'<',16,0); oled_p++; } break; case 2: //²Ëµ¥Ñ¡Ôñ { if(oled_s[0] == 0) //µ±Ç°Ñ¡ÔñµÚ0ÐÐ { if(oled_s[0] != oled_s[1]) //ÊÇ·ñ·¢Éú±ä»¯ { OLED_ShowChar(112,2,'<',16,0); if(oled_s[1] == 1) OLED_ShowChar(112,4,' ',16,0); //Ë¢ÐÂ֮ǰËùÔÚÐÐ1 if(oled_s[1] == 2) OLED_ShowChar(112,6,' ',16,0); //Ë¢ÐÂ֮ǰËùÔÚÐÐ2 oled_s[1] = oled_s[0]; } } if(oled_s[0] == 1) { if(oled_s[0] != oled_s[1]) //ÊÇ·ñ·¢Éú±ä»¯ { OLED_ShowChar(112,4,'<',16,0); if(oled_s[1] == 0) OLED_ShowChar(112,2,' ',16,0); if(oled_s[1] == 2) OLED_ShowChar(112,6,' ',16,0); oled_s[1] = oled_s[0]; } } if(oled_s[0] == 2) { if(oled_s[0] != oled_s[1]) //ÊÇ·ñ·¢Éú±ä»¯ { OLED_ShowChar(112,6,'<',16,0); if(oled_s[1] == 0) OLED_ShowChar(112,2,' ',16,0); if(oled_s[1] == 1) OLED_ShowChar(112,4,' ',16,0); oled_s[1] = oled_s[0]; } } if( (oled_s[0] == 0) && (oled_en == 1) ) //½øÈë²ÎÊý¹Û²â { oled_en = 0; oled_p = 3; } if( (oled_s[0] == 1) && (oled_en == 1) ) //½øÈëµç»ú¿ØÖÆ { oled_en = 0; oled_p = 4; } if( (oled_s[0] == 2) && (oled_en == 1) ) //½øÈë´ÅÐÔ´«¸ÐÆ÷²ÉÑùÉèÖà { oled_en = 0; oled_p = 8; } } break; case 3: //²ÎÊýÏÔʾ£¬·¢Éú±ä»¯Ê±Ë¢Ð { if(para_flag == 0) //Ö»ÏÔʾһ´Î { para_flag = 1; OLED_Clear(); OLED_ShowString(0,0,(char *)("Pos"),16,0); //(x,y,char,size,color), color{0Õý³££¬1·´ÏÔ},x{0-128},y{} sprintf(str_print2, "%.2f",X_ads1220 ); OLED_ShowString(0,2,str_print2,16,0); OLED_ShowString(88,0,(char *)("OC1"),16,0); OLED_ShowString(0,4,(char *)("Temp"),16,0); sprintf(str_print3, "%.2f",TEMP_M1820 ); OLED_ShowString(0,6,str_print3,16,0); OLED_ShowString(88,4,(char *)("OC2"),16,0); OLED_ShowString(64,2,(char *)("mv"),16,0); if(ocin1 == 1) { OLED_ShowString(88,2," OK ",16,0); }else { OLED_ShowString(88,2,"ERR",16,0); } if(ocin2 == 1) { OLED_ShowString(88,6," OK ",16,0); }else { OLED_ShowString(88,6,"ERR",16,0); } }else //±ä»¯Ê±Ë¢Ð { //λÖà Xads_temp2[0] = X_ads1220; if( (Xads_temp2[1] - Xads_temp2[0] > 0.5) || (Xads_temp2[0] - Xads_temp2[1] > 0.5)) { sprintf(str_print2, "%.2f",Xads_temp2[0] ); // µç×è³ß OLED_ShowString(0,2,str_print2,16,0); Xads_temp2[1] = Xads_temp2[0]; } //ÎÂ¶È T_temp2[0] = TEMP_M1820; if(T_temp2[1] != T_temp2[0]) { OLED_ShowString(40,6," ",16,0); sprintf(str_print3, "%.2f",T_temp2[1] ); //ÎÂ¶È OLED_ShowString(0,6,str_print3,16,0); T_temp2[1] = T_temp2[0]; } //λÖÿª¹Ø1 OC1_temp[0] = ocin1; if( OC1_temp[1] != OC1_temp[0] ) { if(OC1_temp[0] == 1) { OLED_ShowString(88,2," OK ",16,0); }else { OLED_ShowString(88,2,"ERR",16,0); } OC1_temp[1] = OC1_temp[0]; } //λÖÿª¹Ø2 OC2_temp[0] = ocin2; if( OC2_temp[1] != OC2_temp[0] ) { if(OC2_temp[0] == 1) { OLED_ShowString(88,6," OK ",16,0); }else { OLED_ShowString(88,6,"ERR",16,0); } OC2_temp[1] = OC2_temp[0]; } } if(oled_en == 1) //OK¼ü°´Ïº󷵻ز˵¥ { oled_en = 0; oled_p = 1; para_flag = 0; } } break; case 4: //µç»ú¿ØÖÆ£¬É趨Ô˶¯Ä£Ê½ { if(motor_flag1 == 0) { motor_flag1 = 1; OLED_Clear(); // OLED_ShowString(0,0,"Motor Control",16,0); OLED_ShowString(0,0,"Run Mode:",16,0); if(Run_Mode == 0) OLED_ShowString(80,0,"STEP",16,1); if(Run_Mode == 1) OLED_ShowString(80,0,"LOOP",16,1); OLED_ShowString(0,2,"Run Step:",16,0); sprintf(str_print2, "%d",Run_mm ); OLED_ShowString(80,2,str_print2,16,0); OLED_ShowString(100,2,"mm",16,0); OLED_ShowString(0,4,"Run Dire:",16,0); OLED_ShowString(80,4,"POS",16,0); OLED_ShowString(0,6,"Cancel",16,0); OLED_ShowString(80,6,"OK",16,0); }else { if(run_mode_temp[0] != run_mode_temp[1]) //Ô˶¯Ä£Ê½±ä»¯Ê±Ë¢Ð { if(run_mode_temp[0] == 0) OLED_ShowString(80,0,"STEP",16,1); if(run_mode_temp[0] == 1) OLED_ShowString(80,0,"LOOP",16,1); run_mode_temp[1] = run_mode_temp[0]; } } if( oled_en == 1 ) //Ô˶¯Ä£Ê½È·ÈϺóÈ¡Ïû·´ÏÔ { oled_en = 0; motor_flag1 = 0; if(run_mode_temp[0] == 0) OLED_ShowString(80,0,"STEP",16,0); if(run_mode_temp[0] == 1) OLED_ShowString(80,0,"LOOP",16,0); oled_p = 5; } } break; case 5: //µç»ú¿ØÖÆ£¬É趨Ô˶¯²½³¤ { if(run_mode_temp[0] == 0) { if(motor_flag1 == 0) { motor_flag1 = 1; sprintf(str_print2, "%d",Run_mm ); OLED_ShowString(80,2,str_print2,16,1); }else { if(step_temp[0] != step_temp[1]) //²½³¤±ä¶¯Ê±Ë¢Ð { OLED_ShowString(80,2," ",16,0); sprintf(str_print2, "%d",step_temp[0] ); OLED_ShowString(80,2,str_print2,16,1); } step_temp[1] = step_temp[0]; } if(oled_en == 1) //²½³¤È·¶¨ºóÈ¡Ïû·´ÏÔ { oled_en = 0; motor_flag1 = 0; OLED_ShowString(80,2,str_print2,16,0); oled_p = 6; } } if(run_mode_temp[0] == 1) { step_temp[0] = 1; OLED_ShowString(80,2," ",16,0); sprintf(str_print2, "%d",step_temp[0] ); OLED_ShowString(80,2,str_print2,16,0); oled_p = 6; } } break; case 6: { if(motor_flag1 == 0) { motor_flag1 = 1; OLED_ShowString(80,4,"POS",16,1); }else { if(direc_temp[0] !=direc_temp[1] ) { if(direc_temp[0] == 1) { OLED_ShowString(80,4,"POS",16,1); } if(direc_temp[0] == 2) { OLED_ShowString(80,4,"REV",16,1); } direc_temp[1] = direc_temp[0]; } } if(oled_en == 1) { oled_en = 0; motor_flag1 = 0; if(direc_temp[0] == 1) { OLED_ShowString(80,4,"POS",16,0); } if(direc_temp[0] == 2) { OLED_ShowString(80,4,"REV",16,0); } oled_p = 7; } } break; case 7: //ÉèÖÃÄÚÈÝÈ·ÈÏ£¬OKºóдÈë²¢ÔËÐУ¬CancelÈ¡Ïû²¢·µ»Ø²Ëµ¥ { if(motor_flag1 == 0) { motor_flag1 = 1; oled_s_motorok[0] = 0; oled_s_motorok[1] = 0; OLED_ShowString(0,6,"Cancel",16,1); }else { if(oled_s_motorok[0] != oled_s_motorok[1]) { if(oled_s_motorok[0] == 0) { OLED_ShowString(0,6,"Cancel",16,1); OLED_ShowString(80,6,"OK",16,0); } if(oled_s_motorok[0] == 1) { OLED_ShowString(0,6,"Cancel",16,0); OLED_ShowString(80,6,"OK",16,1); } oled_s_motorok[1] = oled_s_motorok[0]; } } if((oled_en == 1) && (oled_s_motorok[0] == 0)) //È¡Ïûºó³õʼ»¯ÔÝ´æÊý¾Ý { oled_en = 0; motor_flag1 = 0; Motor_Run = 0; run_mode_temp[0] = 0; run_mode_temp[1] = 0; step_temp[0] = 1; step_temp[1] = 1; direc_temp[0] = 1; direc_temp[1] = 1; oled_p = 1; } if((oled_en == 1) && (oled_s_motorok[0] == 1)) //È·ÈϺó½«ÔÝ´æÊý¾ÝдÈë¶ÔÓ¦²ÎÊý { oled_en = 0; motor_flag1 = 0; Motor_Run = 1; Run_Mode = run_mode_temp[0]; Run_mm = step_temp[0]; motor_direc = direc_temp[0]; oled_p = 8; } } break; case 8: //ÔËÐÐ״̬ÏÔʾ£¬ÔËÐÐÖÐÏÔʾRunning...£¬µ±Ç°ÈÎÎñ½áÊøºóÏÔʾCompleted£¡ { if(motor_flag2 == 0) { motor_flag2 = 1; OLED_Clear(); OLED_ShowString(0,0,"Running...",16,0); OLED_ShowString(0,2,"Pos:",16,0); OLED_ShowString(106,2,"mv",16,0); OLED_ShowString(0,4,"OC1:",16,0); OLED_ShowString(64,4,"OC2:",16,0); if(ocin1 == 1) { OLED_ShowString(8,6," OK ",16,0); }else { OLED_ShowString(8,6,"ERROR",16,0); } if(ocin2 == 1) { OLED_ShowString(72,6," OK ",16,0); }else { OLED_ShowString(72,6,"ERROR",16,0); } }else { //λÖà Xads_temp2[0] = X_ads1220; if( (Xads_temp2[1] - Xads_temp2[0] > 0.5) || (Xads_temp2[0] - Xads_temp2[1] > 0.5)) { sprintf(str_print2, "%.2f",Xads_temp2[0] ); // µç×è³ß OLED_ShowString(40,2,str_print2,16,0); Xads_temp2[1] = Xads_temp2[0]; } //λÖÿª¹Ø1 OC1_temp[0] = ocin1; if( OC1_temp[1] != OC1_temp[0] ) { if(OC1_temp[0] == 1) { OLED_ShowString(8,6," OK ",16,0); }else { OLED_ShowString(8,6,"ERROR",16,0); } OC1_temp[1] = OC1_temp[0]; } //λÖÿª¹Ø2 OC2_temp[0] = ocin2; if( OC2_temp[1] != OC2_temp[0] ) { if(OC2_temp[0] == 1) { OLED_ShowString(72,6," OK ",16,0); }else { OLED_ShowString(72,6,"ERROR",16,0); } OC2_temp[1] = OC2_temp[0]; } if(Motor_Run == 0) { OLED_ShowString(0,0,"Completed !",16,0); } } if(oled_en == 1) //°´ÏÂOKºó·µ»ØÖ÷²Ëµ¥ { oled_en = 0; Runmotor_step = 0; Motor_Run = 0; oled_p = 1; motor_flag2 = 0; } } break; case 9: //´Å¸ÐÓ¦´«¸ÐÄ£¿é²ÉÑùÉèÖã¬ÉèÖòÉÑù¼ä¸ôms { if(magnet_flag == 0) { magnet_flag = 1; OLED_Clear(); OLED_ShowString(0,0,"Sample Set",16,0); OLED_ShowString(0,2,"Interval:",16,0); OLED_ShowString(100,2,"ms",16,0); OLED_ShowString(0,4,"Deepth:",16,0); smp_intr_temp[0] = magnet_tx[3]; smp_intr_temp[1] = magnet_tx[3]; smp_dpth_temp[0] = magnet_tx[5]; smp_dpth_temp[1] = magnet_tx[5]; sprintf(str_print2, "%d",smp_intr_temp[0] ); OLED_ShowString(80,2,str_print2,16,1); sprintf(str_print2, "%d",smp_dpth_temp[0] ); OLED_ShowString(80,4,str_print2,16,0); OLED_ShowString(0,6,"Cancel",16,0); OLED_ShowString(80,6,"OK",16,0); }else { if(smp_intr_temp[0] != smp_intr_temp[1]) { OLED_ShowString(88,2," ",16,0); sprintf(str_print2, "%d",smp_intr_temp[0] ); OLED_ShowString(80,2,str_print2,16,1); //·´ÏÔ smp_intr_temp[1] = smp_intr_temp[0]; } } if(oled_en == 1) { oled_en = 0; magnet_flag = 0; OLED_ShowString(80,2," ",16,0); sprintf(str_print2, "%d",smp_intr_temp[0] ); OLED_ShowString(80,2,str_print2,16,0); //È¡Ïû·´ÏÔ oled_p = 10; } } break; case 10: //´Å¸ÐÓ¦´«¸ÐÄ£¿é²ÉÑùÉèÖã¬ÉèÖòÉÑùÉî¶È { if(magnet_flag == 0) { magnet_flag = 1; sprintf(str_print2, "%d",smp_dpth_temp[0] ); OLED_ShowString(80,4,str_print2,16,1); }else { if(smp_dpth_temp[0] != smp_dpth_temp[1]) { OLED_ShowString(88,4," ",16,0); sprintf(str_print2, "%d",smp_dpth_temp[0] ); OLED_ShowString(80,4,str_print2,16,1); //·´ÏÔ smp_dpth_temp[1] = smp_dpth_temp[0]; } } if(oled_en == 1) { oled_en = 0; magnet_flag = 0; OLED_ShowString(80,4," ",16,0); sprintf(str_print2, "%d",smp_dpth_temp[0] ); OLED_ShowString(80,4,str_print2,16,0); //È¡Ïû·´ÏÔ oled_p = 11; } } break; case 11: //´Å¸ÐÓ¦´«¸ÐÄ£¿éÉèÖÃÈ·ÈÏ { if(magnet_flag == 0) { magnet_flag = 1; oled_s_magnetok[0] = 0; oled_s_magnetok[1] = 0; OLED_ShowString(0,6,"Cancel",16,1); }else { if(oled_s_magnetok[0] != oled_s_magnetok[1]) { if(oled_s_magnetok[0] == 0) { OLED_ShowString(0,6,"Cancel",16,1); OLED_ShowString(80,6,"OK",16,0); } if(oled_s_magnetok[0] == 1) { OLED_ShowString(0,6,"Cancel",16,0); OLED_ShowString(80,6,"OK",16,1); } oled_s_magnetok[1] = oled_s_magnetok[0]; } } if(oled_en == 1) { if(oled_s_magnetok[0] == 0) { oled_en = 0; magnet_flag = 0; smp_intr_temp[0] = magnet_tx[3]; smp_intr_temp[1] = magnet_tx[3]; smp_dpth_temp[0] = magnet_tx[5]; smp_dpth_temp[1] = magnet_tx[5]; oled_p = 1; } if(oled_s_magnetok[0] == 1) { oled_en = 0; magnet_flag = 0; magnet_tx[3] = smp_intr_temp[0]; magnet_tx[5] = smp_dpth_temp[0]; oled_p = 1; } } } break; default: { } } }