| 
 | 
推荐
 
 
 楼主 |
发表于 2016-8-22 14:14:59
|
只看该作者
 
 
 
【STM 32】之智能药盒
 本帖最后由 郭庆帅 于 2016-9-25 14:43 编辑  
 
这是焊接后的照片  上面有步进电机驱动模块和语音模块、一键下载模块 、显示模块主控模块 、传感器模块、 电源模块 
 
这是焊接的背面后面有我wifi模块和一些按键和时钟模块和保存数据模块 
 
 
下面是全部焊好的正面图 
 
 
这是后面的最终图 (调试好的)因为算错了电流 还有就是有散热 最终是这样的 
 
到此电路部分完成。。。。。。。。。。。。。。。。。。。。。 
下面开始 单片机程序!!!!!!!!!!!!!! 
1.首先获取时间 
- uint8_t getTime[9]={0xFF,0xFF,0x00,0x05,0x17,0x78,0x00,0x00,0x94};
 
  复制代码 
2 写入时间(给本地时钟写入时间) 
- PCF8563_set(0x10,0x07,XIEDate,XIEHour,XIEMin,XIEsecond,0x05);//
 
 -                                 PCF8563_read(time);
 
  复制代码 
 
3存储药品个数和吃药时间 
-  Tmp[1]= CENCHU_A;Tmp[2]=CENCHU_B;Tmp[3]=CENCHU_C;Tmp[4]=CENCHU_D;
 
 -                             Tmp[5]= ZAOSHI;Tmp[6]=ZAOFEN;Tmp[7]=ZHONGSHI;Tmp[8]=ZHONGFEN;
 
 -                              Tmp[9]= WANSHI;Tmp[10]=WANFEN;Tmp[11]=CENCHU_C;Tmp[12]=CENCHU_D;
 
 -                                IIC_WriteBuf(0,Tmp,16);
 
 -                                 IIC_ReadBuf(0,Tmp,16);
 
  复制代码 
4 温湿度传感器 
5语音程序 
-     if(wtadd==0)
 
 -                 {
 
 -          if((GPIO_ReadInputDataBit(GPIO_WT588BY_PORT,GPIO_Pin_1)))
 
 -        {
 
 -         Send_oneline( 0 ); 
 
 -                                  ++wtadd;
 
 -           }
 
 -            }        
 
  复制代码 6 光耦传感器(这个地方用的中断) 
- #include "Hal_GUANGOU.h"
 
  
- #include "Hal_Step_otor.h"
 
 - #include "stdio.h"
 
 - #include "delay.h"
 
 - extern  int a ;
 
  
- void Delay1(__IO u32 nCount)         //¼òµ¥µÄÑÓʱº¯Êý
 
 - {
 
 -         while(--nCount);
 
 - } 
 
  
- void STEP_GPIO_GInit(void)//¹âñî
 
 -         {
 
 -       GPIO_InitTypeDef GPIO_InitStructure;
 
 -             RCC_APB2PeriphClockCmd( GPIO_G1_CLK | GPIO_G2_CLK, ENABLE);//??LED
 
 -     
 
 -       GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_IPU;//IPU                                        //???????????
 
 -       GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;                                        //?????
 
 -         
 
 -       GPIO_InitStructure.GPIO_Pin = GPIO_G1_PIN;        //¹âñî                                                //??LED1
 
 -       GPIO_Init(GPIO_G1_PORT, &GPIO_InitStructure);                                                //???LED1
 
  
-       GPIO_InitStructure.GPIO_Pin = GPIO_G2_PIN;        //¹âñî                                                //??LED2
 
 -       GPIO_Init(GPIO_G2_PORT, &GPIO_InitStructure);        
 
 -                 
 
 -                     
 
 -                   
 
 -                 
 
 - }
 
 - void STEP_GPIO_HUOER(void)//»ô¶û
 
 -         {
 
 -       GPIO_InitTypeDef GPIO_InitStructure;
 
 -             RCC_APB2PeriphClockCmd( GPIO_Y1_CLK | GPIO_Y2_CLK, ENABLE);//??LED
 
 -     
 
 -       GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_IPD;//IPU                                        //???????????
 
 -       GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;                                        //?????
 
 -         
 
 -             GPIO_InitStructure.GPIO_Pin = GPIO_Y1_PIN;        //»ô¶û                                                //??LED1
 
 -       GPIO_Init(GPIO_Y1_PORT, &GPIO_InitStructure);                                                //???LED1
 
  
-       GPIO_InitStructure.GPIO_Pin = GPIO_Y2_PIN;                //»ô¶û                                        //??LED2
 
 -       GPIO_Init(GPIO_Y2_PORT, &GPIO_InitStructure);
 
 -         
 
 -                   GPIO_InitStructure.GPIO_Pin = GPIO_BEIYONG3_PIN;        //±¸ÓÃÊäÈë
 
 -       GPIO_Init(GPIO_BEIYONG3_PORT, &GPIO_InitStructure);                                                //???LED1
 
  
-       GPIO_InitStructure.GPIO_Pin = GPIO_BEIYONG4_PIN;                //±¸ÓÃÊäÈë
 
 -       GPIO_Init(GPIO_BEIYONG4_PORT, &GPIO_InitStructure);
 
 - }
 
 - void EXTIX_Init(void)
 
 - {
 
 -  
 
 -            EXTI_InitTypeDef EXTI_InitStructure;
 
 -            NVIC_InitTypeDef NVIC_InitStructure;
 
 -           void STEP_GPIO_GInit();//¹âñî
 
  
-     RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);        //ʹÄܸ´Óù¦ÄÜʱÖÓ
 
 -     NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);        //ÉèÖÃNVICÖжϷÖ×é2:2λÇÀÕ¼ÓÅÏȼ¶£¬2λÏìÓ¦ÓÅÏȼ¶
 
 -     
 
 - //    GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource1);
 
 - //        
 
 - //    EXTI_InitStructure.EXTI_Line=EXTI_Line1;
 
 - //          EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; //ÖжÏģʽ
 
 - //          EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;//ϽµÑØ
 
 - //          EXTI_InitStructure.EXTI_LineCmd=ENABLE; 
 
 - //          EXTI_Init(&EXTI_InitStructure);                //¸ù¾ÝEXTI_InitStructÖÐÖ¸¶¨µÄ²ÎÊý³õʼ»¯ÍâÉèEXTI¼Ä´æÆ÷
 
 - //        
 
 - //    
 
 - //        
 
 - //          NVIC_InitStructure.NVIC_IRQChannel = EXTI1_IRQn;                        //ʹÄܰ´¼ü ËùÔÚµÄÍⲿÖжÏͨµÀ
 
 - //          NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x02;        //ÇÀÕ¼ÓÅÏȼ¶2£¬ 
 
 - //          NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x00;                                        //×ÓÓÅÏȼ¶0×î¸ß¼¶
 
 - //          NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;                                                                //ʹÄÜÍⲿÖжÏͨµÀ
 
 - //          NVIC_Init(&NVIC_InitStructure); 
 
 -  
 
 -         
 
 -     RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);        //ʹÄܸ´Óù¦ÄÜʱÖÓ
 
 -     NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);        //ÉèÖÃNVICÖжϷÖ×é2:2λÇÀÕ¼ÓÅÏȼ¶£¬2λÏìÓ¦ÓÅÏȼ¶
 
 -     //GPIOA.0          ÖжÏÏßÒÔ¼°Öжϳõʼ»¯ÅäÖà ÉÏÉýÑØ´¥·¢ PA0  WK_UP
 
 -     GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource0); 
 
 -     EXTI_InitStructure.EXTI_Line=EXTI_Line0;
 
 -           EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; //ÖжÏģʽ EXTI_Trigger_Rising  ÉÏÉý
 
 -           EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;//ÉÏÉýÑØ
 
 -           EXTI_InitStructure.EXTI_LineCmd=ENABLE; 
 
 -           EXTI_Init(&EXTI_InitStructure);                //¸ù¾ÝEXTI_InitStructÖÐÖ¸¶¨µÄ²ÎÊý³õʼ»¯ÍâÉèEXTI¼Ä´æÆ÷
 
  
-           NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;                        //ʹÄܰ´¼ü ËùÔÚµÄÍⲿÖжÏͨµÀ
 
 -           NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x01;        //ÇÀÕ¼ÓÅÏȼ¶2£¬ 
 
 -           NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x00;                                        //×ÓÓÅÏȼ¶0×î¸ß¼¶
 
 -           NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;                                                                //ʹÄÜÍⲿÖжÏͨµÀ
 
 -           NVIC_Init(&NVIC_InitStructure);         
 
 -         
 
 -         
 
 - }
 
 - void EXTI0_IRQHandler(void)  //0,1,2,3,4,9_5,15_10
 
 - { 
 
 -               printf("½øÈëÖжÏ");
 
 -                      a=a+1;
 
 -         printf(" %d",a);
 
 -               Delay1(300000);
 
 -                 
 
 -         EXTI_ClearITPendingBit(EXTI_Line0); //Çå³ýLINE4ÉϵÄÖжϱê־λ  
 
 - }
 
  复制代码 
7 霍尔传感器(和语音提醒) 
- bool IR_Handle(void)
 
 - {
 
 -         printf("½øÈë»ô¶û¼ì²â");
 
 -     if(GPIO_ReadInputDataBit(Infrared_GPIO_PORT, Infrared_GPIO_PIN))
 
 -     {
 
 -                         if(b%2==0)
 
 -                                 {
 
 -                                         if(q==1)
 
 -                                         {                
 
 -                                                 if((GPIO_ReadInputDataBit(GPIO_WT588BY_PORT,GPIO_Pin_1)))
 
 -               {
 
 -                                                                 printf("ÓïÒôÌáÐѹéλ");
 
 -         Send_oneline(4);
 
 -                                                                 q=0;
 
 -                 }
 
 -                                                         }
 
 -                                                 
 
 -                                         printf("Ò©ºÐÔÚÔλÖÃ");
 
 -                            return 0;
 
 -                                 }
 
 -                         else
 
 -                         {
 
 -                                 
 
 -     printf("Ö´ÐÐÖÐÒ©ºÐÒÔÄóö");                                
 
 -                 if((GPIO_ReadInputDataBit(GPIO_WT588BY_PORT,GPIO_Pin_1)))
 
 -        {
 
 -         Send_oneline(2);
 
 -        }
 
 -                     return 1;
 
 -                         }
 
  
-     }
 
 -     else
 
 -     {
 
 -                         printf("yyyyyy%d",h);
 
 -                         if(h ==1 )
 
 -                         {
 
 -                                 printf("hahahhahahhh");
 
 -                         
 
 -                                 if((GPIO_ReadInputDataBit(GPIO_WT588BY_PORT,GPIO_Pin_1)))
 
 -        {
 
 -         Send_oneline(3);
 
 -                                  b=0;
 
 -                                          h=0;
 
 -                                  q=1;
 
 -                          }
 
 -                          
 
 -                  }
 
  
-         return 0;
 
 -                  }
 
 -                         
 
 -     }
 
  复制代码 
8 步进电机程序 
- #define GPIO_A1_CLK    RCC_APB2Periph_GPIOA//B¸Ä³ÉA
 
 - #define GPIO_A1_PORT   GPIOA
 
 - #define GPIO_A1_PIN    GPIO_Pin_12
 
  
- #define GPIO_B1_CLK    RCC_APB2Periph_GPIOA
 
 - #define GPIO_B1_PORT   GPIOA
 
 - #define GPIO_B1_PIN    GPIO_Pin_11
 
  
- #define GPIO_C1_CLK    RCC_APB2Periph_GPIOB
 
 - #define GPIO_C1_PORT   GPIOB
 
 - #define GPIO_C1_PIN    GPIO_Pin_15
 
  
- #define GPIO_D1_CLK    RCC_APB2Periph_GPIOB
 
 - #define GPIO_D1_PORT   GPIOB
 
 - #define GPIO_D1_PIN    GPIO_Pin_14
 
  
- #define GPIO_A2_CLK    RCC_APB2Periph_GPIOB
 
 - #define GPIO_A2_PORT   GPIOB
 
 - #define GPIO_A2_PIN    GPIO_Pin_10
 
  
- #define GPIO_B2_CLK    RCC_APB2Periph_GPIOB
 
 - #define GPIO_B2_PORT   GPIOB
 
 - #define GPIO_B2_PIN    GPIO_Pin_11
 
  
- #define GPIO_C2_CLK    RCC_APB2Periph_GPIOB
 
 - #define GPIO_C2_PORT   GPIOB
 
 - #define GPIO_C2_PIN    GPIO_Pin_12
 
  
- #define GPIO_D2_CLK    RCC_APB2Periph_GPIOB
 
 - #define GPIO_D2_PORT   GPIOB
 
 - #define GPIO_D2_PIN    GPIO_Pin_13
 
  复制代码 步进电机原理程序 
- #define Coil_A1 {GPIO_SetBits(GPIO_A1_PORT,GPIO_A1_PIN);\
 
 -                                                                 GPIO_ResetBits(GPIO_B1_PORT,GPIO_B1_PIN);\
 
 -                                                                 GPIO_ResetBits(GPIO_C1_PORT,GPIO_C1_PIN);\
 
 -                                                                 GPIO_ResetBits(GPIO_D1_PORT,GPIO_D1_PIN);\
 
 -                                                         }//AÏàͨµç£¬ÆäËûÏà¶Ïµç
 
 - #define Coil_B1 {GPIO_ResetBits(GPIO_A1_PORT,GPIO_A1_PIN);\
 
 -                                                                 GPIO_SetBits(GPIO_B1_PORT,GPIO_B1_PIN);\
 
 -                                                                 GPIO_ResetBits(GPIO_C1_PORT,GPIO_C1_PIN);\
 
 -                                                                 GPIO_ResetBits(GPIO_D1_PORT,GPIO_D1_PIN);\
 
 -                                                                 }//BÏàͨµç£¬ÆäËûÏà¶Ïµç
 
 - #define Coil_C1 {GPIO_ResetBits(GPIO_A1_PORT,GPIO_A1_PIN);\
 
 -                                                                 GPIO_ResetBits(GPIO_B1_PORT,GPIO_B1_PIN);\
 
 -                                                                 GPIO_SetBits(GPIO_C1_PORT,GPIO_C1_PIN);\
 
 -                                                                 GPIO_ResetBits(GPIO_D1_PORT,GPIO_D1_PIN);\
 
 -                                                                 }//CÏàͨµç£¬ÆäËûÏà¶Ïµç
 
 - #define Coil_D1 {GPIO_ResetBits(GPIO_A1_PORT,GPIO_A1_PIN);\
 
 -                                                                 GPIO_ResetBits(GPIO_B1_PORT,GPIO_B1_PIN);\
 
 -                                                                 GPIO_ResetBits(GPIO_C1_PORT,GPIO_C1_PIN);\
 
 -                                                                 GPIO_SetBits(GPIO_D1_PORT,GPIO_D1_PIN);\
 
 -                                                                 }//DÏàͨµç£¬ÆäËûÏà¶Ïµç
 
 - #define Coil_AB1 {GPIO_SetBits(GPIO_A1_PORT,GPIO_A1_PIN);\
 
 -                                                                 GPIO_SetBits(GPIO_B1_PORT,GPIO_B1_PIN);\
 
 -                                                                 GPIO_ResetBits(GPIO_C1_PORT,GPIO_C1_PIN);\
 
 -                                                                 GPIO_ResetBits(GPIO_D1_PORT,GPIO_D1_PIN);\
 
 -                                                                 }//ABÏàͨµç£¬ÆäËûÏà¶Ïµç
 
 - #define Coil_BC1 {GPIO_ResetBits(GPIO_A1_PORT,GPIO_A1_PIN);\
 
 -                                                                 GPIO_SetBits(GPIO_B1_PORT,GPIO_B1_PIN);\
 
 -                                                                 GPIO_SetBits(GPIO_C1_PORT,GPIO_C1_PIN);\
 
 -                                                                 GPIO_ResetBits(GPIO_D1_PORT,GPIO_D1_PIN);\
 
 -                                                                 }//BCÏàͨµç£¬ÆäËûÏà¶Ïµç
 
 -                                                         
 
 - #define Coil_CD1 {GPIO_ResetBits(GPIO_A1_PORT,GPIO_A1_PIN);\
 
 -                                                                 GPIO_ResetBits(GPIO_B1_PORT,GPIO_B1_PIN);\
 
 -                                                                 GPIO_SetBits(GPIO_C1_PORT,GPIO_C1_PIN);\
 
 -                                                                 GPIO_SetBits(GPIO_D1_PORT,GPIO_D1_PIN);\
 
 -                                                                 }//CDÏàͨµç£¬ÆäËûÏà¶Ïµç
 
 - #define Coil_DA1 {GPIO_SetBits(GPIO_A1_PORT,GPIO_A1_PIN);\
 
 -                       GPIO_ResetBits(GPIO_B1_PORT,GPIO_B1_PIN);\
 
 -                                                                 GPIO_ResetBits(GPIO_C1_PORT,GPIO_C1_PIN);\
 
 -                                                                 GPIO_SetBits(GPIO_D1_PORT,GPIO_D1_PIN);\
 
 - }
 
 -                                                                 //DÏàͨµç£¬ÆäËûÏà¶Ïµç
 
 - #define Coil_OFF {GPIO_ResetBits(GPIO_A1_PORT,GPIO_A1_PIN);\
 
 -                                                                         GPIO_ResetBits(GPIO_B1_PORT,GPIO_B1_PIN);\
 
 -                                                                         GPIO_ResetBits(GPIO_C1_PORT,GPIO_C1_PIN);\
 
 -                                                                          GPIO_ResetBits(GPIO_D1_PORT,GPIO_D1_PIN);\
 
 -                                                                         }//È«²¿¶Ïµç
 
  
- #define Coil_A2 {GPIO_SetBits(GPIO_A2_PORT,GPIO_A2_PIN);\
 
 -                                                                 GPIO_ResetBits(GPIO_B2_PORT,GPIO_B2_PIN);\
 
 -                                                                 GPIO_ResetBits(GPIO_C2_PORT,GPIO_C2_PIN);\
 
 -                                                                 GPIO_ResetBits(GPIO_D2_PORT,GPIO_D2_PIN);\
 
 -                                                         }//AÏàͨµç£¬ÆäËûÏà¶Ïµç
 
 - #define Coil_B2 {GPIO_ResetBits(GPIO_A2_PORT,GPIO_A2_PIN);\
 
 -                                                                 GPIO_SetBits(GPIO_B2_PORT,GPIO_B2_PIN);\
 
 -                                                                 GPIO_ResetBits(GPIO_C2_PORT,GPIO_C2_PIN);\
 
 -                                                                 GPIO_ResetBits(GPIO_D2_PORT,GPIO_D2_PIN);\
 
 -                                                                 }//BÏàͨµç£¬ÆäËûÏà¶Ïµç
 
 - #define Coil_C2 {GPIO_ResetBits(GPIO_A2_PORT,GPIO_A2_PIN);\
 
 -                                                                 GPIO_ResetBits(GPIO_B2_PORT,GPIO_B2_PIN);\
 
 -                                                                 GPIO_SetBits(GPIO_C2_PORT,GPIO_C2_PIN);\
 
 -                                                                 GPIO_ResetBits(GPIO_D2_PORT,GPIO_D2_PIN);\
 
 -                                                                 }//CÏàͨµç£¬ÆäËûÏà¶Ïµç
 
 - #define Coil_D2 {GPIO_ResetBits(GPIO_A2_PORT,GPIO_A2_PIN);\
 
 -                                                                 GPIO_ResetBits(GPIO_B2_PORT,GPIO_B2_PIN);\
 
 -                                                                 GPIO_ResetBits(GPIO_C2_PORT,GPIO_C2_PIN);\
 
 -                                                                 GPIO_SetBits(GPIO_D2_PORT,GPIO_D2_PIN);\
 
 -                                                                 }//DÏàͨµç£¬ÆäËûÏà¶Ïµç
 
 - #define Coil_AB2 {GPIO_SetBits(GPIO_A2_PORT,GPIO_A2_PIN);\
 
 -                                                                 GPIO_SetBits(GPIO_B2_PORT,GPIO_B2_PIN);\
 
 -                                                                 GPIO_ResetBits(GPIO_C2_PORT,GPIO_C2_PIN);\
 
 -                                                                 GPIO_ResetBits(GPIO_D2_PORT,GPIO_D2_PIN);\
 
 -                                                                 }//ABÏàͨµç£¬ÆäËûÏà¶Ïµç
 
 - #define Coil_BC2 {GPIO_ResetBits(GPIO_A2_PORT,GPIO_A2_PIN);\
 
 -                                                                 GPIO_SetBits(GPIO_B2_PORT,GPIO_B2_PIN);\
 
 -                                                                 GPIO_SetBits(GPIO_C2_PORT,GPIO_C2_PIN);\
 
 -                                                                 GPIO_ResetBits(GPIO_D2_PORT,GPIO_D2_PIN);\
 
 -                                                                 }//BCÏàͨµç£¬ÆäËûÏà¶Ïµç
 
 -                                                         
 
 - #define Coil_CD2 {GPIO_ResetBits(GPIO_A2_PORT,GPIO_A2_PIN);\
 
 -                                                                 GPIO_ResetBits(GPIO_B2_PORT,GPIO_B2_PIN);\
 
 -                                                                 GPIO_SetBits(GPIO_C2_PORT,GPIO_C2_PIN);\
 
 -                                                                 GPIO_SetBits(GPIO_D2_PORT,GPIO_D2_PIN);\
 
 -                                                                 }//CDÏàͨµç£¬ÆäËûÏà¶Ïµç
 
 - #define Coil_DA2 {GPIO_SetBits(GPIO_A2_PORT,GPIO_A2_PIN);\
 
 -                       GPIO_ResetBits(GPIO_B2_PORT,GPIO_B2_PIN);\
 
 -                                                                 GPIO_ResetBits(GPIO_C2_PORT,GPIO_C2_PIN);\
 
 -                                                                 GPIO_SetBits(GPIO_D2_PORT,GPIO_D2_PIN);\
 
 - }
 
 -                                                                 //DÏàͨµç£¬ÆäËûÏà¶Ïµç
 
 - #define Coil_OFF2 {GPIO_ResetBits(GPIO_A2_PORT,GPIO_A2_PIN);\
 
 -                                                                         GPIO_ResetBits(GPIO_B2_PORT,GPIO_B2_PIN);\
 
 -                                                                         GPIO_ResetBits(GPIO_C2_PORT,GPIO_C2_PIN);\
 
 -                                                                          GPIO_ResetBits(GPIO_D2_PORT,GPIO_D2_PIN);\
 
 -                                                                         }//È«²¿¶Ïµç
 
  复制代码 到此stm32程序完毕 (代码比较多 ,仔细看哦) 
 
 
下面是机械部分这是智能药盒侧视图(整体图 震贴) 
 
 
下面从零到一组装 
 
 
 
下面的可是上了铣床铣出来的 
 
 
 
 
 
把这两个组装起来 
 
 
 
加上同步轮 
 
 
下面是电机部分 
 
 
下面是电机组装 
 
 
图2 
 
 
整体框架 
 
 
 
外观美化 
 
 
最终完成 
 
 
 
             健康卫士APP一、控制页面
- <font size="1">//控制页面
 
 - protected void onCreate(Bundle savedInstanceState) {
 
 -                 super.onCreate(savedInstanceState);
 
 -                 setContentView(R.layout.gokit_control);
 
 -                 tabHost = (TabHost) findViewById(android.R.id.tabhost);
 
 -                 tabHost.setup();
 
 -                 tabHost.addTab(tabHost.newTabSpec("one_drug").setIndicator("第一种药").setContent(R.id.one_drug));
 
 -                 tabHost.addTab(tabHost.newTabSpec("two_drug").setIndicator("第二种药").setContent(R.id.two_drug));
 
 -                 tabHost.addTab(tabHost.newTabSpec("three_drug").setIndicator("第三种药").setContent(R.id.three_drug));
 
 -                 tabHost.addTab(tabHost.newTabSpec("four_drug").setIndicator("第四种药").setContent(R.id.four_drug));
 
 -                 
 
 -                 initViews();   //初始化控件
 
 -                 initEvents();  //初始化**
 
 -                 
 
 -                 deviceStatu = new HashMap<String, Object>();
 
 -                 controlDevice = (ControlDevice) getIntent().getSerializableExtra("device");
 
 -                 WApplication.mControlDevice=controlDevice;
 
 -                 xpgWifiDevice = BaseActivity.findDeviceByMac(controlDevice.getMac(), controlDevice.getDid());
 
 -                 if (xpgWifiDevice != null) {
 
 -                         xpgWifiDevice.setListener(deviceListener);
 
 -                 }
 
 -                 actionBar.setTitle(controlDevice.getName());
 
 -         }
 
  
-         final protected static char[] hexArray = "0123456789ABCDEF".toCharArray();
 
  
-         public static String bytesToHex(byte[] bytes) {
 
 -                 char[] hexChars = new char[bytes.length * 3];
 
 -                 for (int j = 0; j < bytes.length; j++) {
 
 -                         int v = bytes[j] & 0xFF;
 
 -                         hexChars[j * 3] = hexArray[v >>> 4];
 
 -                         hexChars[j * 3 + 1] = hexArray[v & 0x0F];
 
 -                         hexChars[j * 3 + 2] = ' ';
 
 -                 }
 
 -                 return new String(hexChars);
 
 -         }
 
  
 
 
-         /**
 
 -          * 初始化控件.
 
 -          */
 
 -         private void initViews() {
 
 -                 mybutton = (Button) findViewById(R.id.mybutton);
 
 -                 
 
 -                 editTextA = (EditText) findViewById(R.id.editTextA);
 
 -                 editTextB = (EditText) findViewById(R.id.editTextB);
 
 -                 editTextC = (EditText) findViewById(R.id.editTextC);
 
 -                 editTextD = (EditText) findViewById(R.id.editTextD);
 
 -                 editTextE = (EditText) findViewById(R.id.editTextE);
 
 -                 editTextF = (EditText) findViewById(R.id.editTextF);
 
 -                 editTextG = (EditText) findViewById(R.id.editTextG);
 
 -                 editTextH = (EditText) findViewById(R.id.editTextH);
 
 -                 
 
 -                 vibrator = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
 
 -                 swInfrared = (Switch) findViewById(R.id.sw_infrared1);
 
 -         
 
 -                 
 
 -                 Map<String, String> map = FileActivity.ShowData3();
 
 -                 if(map != null)
 
 -                 {
 
 -                         editTextA.setText(map.get("Aname"));
 
 -                         editTextB.setText(map.get("Age"));
 
 -                         editTextC.setText(map.get("Bname"));
 
 -                         editTextD.setText(map.get("Bge"));
 
 -                         editTextE.setText(map.get("Cname"));
 
 -                         editTextF.setText(map.get("Cge"));
 
 -                         editTextG.setText(map.get("Dname"));
 
 -                         editTextH.setText(map.get("Dge"));
 
 -                 }
 
  
-         }
 
  
-         /**
 
 -          * 初始化**.
 
 -          */
 
 -         private void initEvents() {
 
 -                 /**打开预约时间页面*/
 
 -                 mybutton.setOnClickListener(new OnClickListener() {
 
 -                         @Override
 
 -                         public void onClick(View v) {
 
 -                                 // TODO Auto-generated method stub
 
 -                                 String unt1 = editTextB.getText().toString().trim();
 
 -                                 String unt2 = editTextD.getText().toString().trim();
 
 -                                 String unt3 = editTextF.getText().toString().trim();
 
 -                                 String unt4 = editTextH.getText().toString().trim();
 
 -                                 Intent intent = new Intent();
 
 -                                 
 
 -                                 //储存药品名字合个数
 
 -                                 if(TextUtils.isEmpty(editTextC.getText().toString()) && TextUtils.isEmpty(editTextE.getText().toString()) && TextUtils.isEmpty(editTextG.getText().toString()))
 
 -                                 {
 
 -                                         FileActivity.DataLog3(editTextA.getText().toString(),Integer.parseInt(editTextB.getText().toString()), "", 0, "",0,"",0);
 
 -                                 }
 
 -                                 else if(editTextE.getText().toString() == null && editTextG.getText().toString() == null)
 
 -                                 {
 
 -                                         FileActivity.DataLog3(editTextA.getText().toString(),Integer.parseInt(editTextB.getText().toString()),editTextC.getText().toString(),Integer.parseInt(editTextD.getText().toString()) , "",0,"",0);
 
 -                                 }
 
 -                                 else if(editTextG.getText().toString() == null)
 
 -                                 {
 
 -                                         FileActivity.DataLog3(editTextA.getText().toString(),Integer.parseInt(editTextB.getText().toString()),editTextC.getText().toString(),Integer.parseInt(editTextD.getText().toString()) , editTextE.getText().toString(),Integer.parseInt(editTextF.getText().toString()),"",0);
 
 -                                 }
 
 -                                 else
 
 -                                 {
 
 -                                         FileActivity.DataLog3(editTextA.getText().toString(),Integer.parseInt(editTextB.getText().toString()), editTextC.getText().toString(),Integer.parseInt(editTextD.getText().toString()), editTextE.getText().toString(),Integer.parseInt(editTextF.getText().toString()), editTextG.getText().toString(),Integer.parseInt(editTextH.getText().toString()));
 
 -                                 }
 
 -                                 
 
 -                                 if(TextUtils.isEmpty(unt1))
 
 -                                 {
 
 -                                         intent.putExtra("one1","0");
 
 -                                 }
 
 -                                 else
 
 -                                 {
 
 -                                         intent.putExtra("one1",unt1);
 
 -                                 }
 
 -                                 if(TextUtils.isEmpty(unt2))
 
 -                                 {
 
 -                                         intent.putExtra("one2","0");
 
 -                                 }
 
 -                                 else
 
 -                                 {
 
 -                                         intent.putExtra("one2",unt2);
 
 -                                 }
 
 -                                 if(TextUtils.isEmpty(unt3))
 
 -                                 {
 
 -                                         intent.putExtra("one3","0");
 
 -                                 }
 
 -                                 else
 
 -                                 {
 
 -                                         intent.putExtra("one3",unt3);
 
 -                                 }
 
 -                                 if(TextUtils.isEmpty(unt4))
 
 -                                 {
 
 -                                         intent.putExtra("one4","0");
 
 -                                 }
 
 -                                 else
 
 -                                 {
 
 -                                         intent.putExtra("one4",unt4);
 
 -                                 }
 
 -                                 intent.setClass(GokitControlActivity1.this, Time_Activity.class);
 
 -                                 startActivity(intent);
 
 -                         }
 
 -                 });
 
 -                 swInfrared.setOnCheckedChangeListener(new OnCheckedChangeListener() {
 
  
-                         @Override
 
 -                         public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
 
 -                                 try {
 
 -                                         if(isChecked == true)
 
 -                                         {
 
 -                                                 vibrator.vibrate(new long[]{1000,3000,1000,3000},0);  //手机震动提示
 
 -                                                 
 
 -                                                 new AlertDialog.Builder(GokitControlActivity1.this).setTitle("警告")//设置对话框标题  
 
 -                                              .setMessage("为了您的健康!\n请按时吃药!")//设置显示的内容
 
 -                                             .setNegativeButton("确定",new DialogInterface.OnClickListener() {//添加返回按钮  
 
 -                                                     
 
 -                                                  @Override  
 
 -                                                  public void onClick(DialogInterface dialog, int which) {//响应事件  
 
 -                                           
 
 -                                                      // TODO Auto-generated method stub  
 
 -                                                         SimpleDateFormat formatter = new SimpleDateFormat ("yyyy-MM-dd HH:mm");
 
 -                                         Date curDate = new Date(System.currentTimeMillis());//获取当前时间
 
 -                                         String str = formatter.format(curDate);
 
 -                                         if(editTextA.getText().toString() != null)
 
 -                                         {
 
 -                                                                  FileActivity.DataLog2(editTextA.getText().toString(),Integer.parseInt(editTextB.getText().toString()),str);
 
  
-                                         }
 
 -                                         if(editTextC.getText().toString() != null)
 
 -                                         {
 
 -                                                 FileActivity.DataLog2(editTextC.getText().toString(),Integer.parseInt(editTextD.getText().toString()),str);
 
 -                                         }
 
 -                                         if(editTextE.getText().toString() != null)
 
 -                                         {
 
 -                                                 FileActivity.DataLog2(editTextE.getText().toString(),Integer.parseInt(editTextF.getText().toString()),str);
 
 -                                         }
 
 -                                         if(editTextG.getText().toString() != null)
 
 -                                         {
 
 -                                                 FileActivity.DataLog2(editTextG.getText().toString(),Integer.parseInt(editTextH.getText().toString()),str);
 
 -                                         }
 
 -                                                          vibrator.cancel();
 
 -                                                      Log.i("123"," 请保存数据!"); 
 
 -                                           
 
 -                                                  }  
 
 -                                           
 
 -                                              }).show();//在按键响应事件中显示此对话框 
 
 -                                         }
 
 -                                         else
 
 -                                         {
 
 -                                                  vibrator.cancel();
 
 -                                         }
 
 -                                         Log.v("123", ""+isChecked);
 
 -                                         
 
 -                                         sendJson(KEY_INFRARED, isChecked);
 
 -                                 } catch (JSONException e) {
 
 -                                         e.printStackTrace();
 
 -                                 }
 
 -                         }
 
 -                 });
 
 -         }
 
  复制代码 
 
二、预约时间- <blockquote>class Button12 implements OnClickListener
 
  复制代码 
三、温湿度查看
- /**
 
 - *温湿度查看
 
 - */
 
 - case R.id.action_device_status:
 
 -                         new Ale.Builder(GokitControlActivity1.this).setTitle("温湿度查看")//设置对话框标题  
 
 -                           
 
 -                      .setMessage("环境湿度   "+ s +"\n" + "环境温度  " + w)//设置显示的内容
 
 -                     .setNegativeButton("确定",new DialogInterface.OnClickListener() {//添加返回按钮  
 
 -                          @Override  
 
 -                   
 
 -                          public void onClick(DialogInterface dialog, int which) {//响应事件  
 
 -                   
 
 -                              // TODO Auto-generated method stub  
 
 -                   
 
 -                              Log.i("alertdialog"," 请保存数据!"); 
 
 -                   
 
 -                          }  
 
 -                   
 
 -                      }).show();//在按键响应事件中显示此对话框                          
 
 -                         break;
 
  复制代码
四、储存数据与读取数据 
五、服药日志记录 - /*<span style="font-size: 14px; line-height: 1.5;">*服药日志</span>
 
  复制代码 
   
 
 
 
资料和视频在9楼!!!!!!!!!!!如果你觉的好可以打赏,我们还会出更好的作品!!!!!!!! 
 
 
 
 
 
 |   
 
 
 
 |