人口老龄化是当今世界人口发展的趋势,这种人口年龄结构的变化正在广泛而深刻地影响着人类社会生活的各个方面。相关调查显示目前老年人产品逐渐增多,但还不能满足中国社会的需求,随着年龄的增长,老年人体能下降且容易生病,时常需要持续吃药,所以老年人智能药盒也受到广泛的关注。在现实生活中,老年人常常会出现记忆丧失或者遗忘的时候,难免会出现漏服的现象,而当今社会老年人的子女往往会因为工作等原因无法及时提醒老年人按时服药。为解决老年人按时服药困难的问题,设计一款提醒使用者按时服药的辅助用药类产品,能够有效地解决部分老年人的用药问题,同时方便使用者存储药物。
设计的基本条件:
本设计以单片机为主控芯片,采用红外传感器、按键模块、蜂鸣器模块、显示模块、GSM模块等构成较为完善的硬件模块,达成设计的基本条件。
设计依据:
(1)基于单片机的智能药盒设计是个实际项目,通过查阅相关的资料并认真研究与分析,制定科学的设计内容和技术路线,为设计确定了科学依据。 (2)对设计中使用的红外传感器、蜂鸣器模块、显示模块、GSM模块等等模块和单片机芯片有一定的了解,能够熟练地使用设计中用到的元器件,并对所用知识进行系统的学习,有深入的了解,为设计的完成提供了技术支撑。
主要内容如下:
(1)通过按键设置时钟的时间以及每个药物位置的服药次数; (2)到达指定的服药时间,蜂鸣器发出警报; (3)测量体温,并通过红外检测药物是否被拿起; (4)通过GSM模块发送信息提醒监护人; (5)通过显示屏显示当天该吃药物的位置、次数以及时间。
本设计欲达到的目的:
设计出一款智能药盒,使之能够通过按键设置时间以及每个药物位置的服药次数,在到达指定时间时会发出警报提醒服药,通过传感器检测体温,并通过红外检测药物是否被拿起,若十分钟内药物未被拿起则通过GSM模块发送信息提醒监护人,相关参数通过显示屏显示。
演示视频
部分核心代码
#include"lcd.h"
#include"ds1302.h"
#include"DS18B20.h"
#define yh 0x80
#define er 0x80+0x40
uchar code tab0[]={"Medicine Select"};
uchar code tab1[]={"Choose : "};
uchar code tab2[]={" Times Select "};
uchar code tab3[]={" times/day"};
uchar code tab4[]={"Clock Setting / "};
uchar code tab5[]={" End Day "};
uchar code tab6[]={" : :00 "};
uchar code tab7[]={" - "};
uchar code tab8[]={"Alarm Clock Work"};
uchar code tab9[]={"Today's medicine"};
uchar code tab10[]={" None "};
uchar code tab11[]={"Medicine / "};
uchar idata clock[6][4][4];
uchar idata clock_flag[6];
uchar idata beep_flag[6][4];
uchar nian,yue,ri,week,shi,fen,miao;
uchar temp,temp1,CLOCK_FUN,MEDICINE_FUN,FLAG_CLOCK,FLAG_MEDICINE,FLAG_auxiliary;
uchar box_flag;
uchar times_flag;
uchar yao=1;
uchar times[6]={1,1,1,1,1,1};
uchar idata chiyao_flag[6][4];
sbit KEY1=P2^5;
sbit KEY2=P2^4;
sbit KEY3=P2^3;
sbit KEY4=P2^2;
sbit KEY5=P2^1;
sbit KEY6=P2^0;
sbit KEY7=P3^6;
sbit KEY8=P3^7;
sbit OUT1=P1^5;
sbit OUT2=P1^6;
sbit OUT3=P1^7;
sbit OUT4=P3^4;
sbit OUT5=P3^3;
sbit OUT6=P3^2;
sbit BEEP=P3^5;
bit Display_Flag = 0;
bit Display_Flag1 = 0;
void write_sfm(uchar add,uchar dat)
{
uchar gw,sw;
gw=dat%10;
sw=dat/10;
LcdWriteCom(er+add);
LcdWriteData(0x30+sw);
LcdWriteData(0x30+gw);
}
void write_nyr(uchar add,uchar dat)
{
uchar gw,sw;
gw=dat%10;
sw=dat/10;
LcdWriteCom(yh+add);
LcdWriteData(0x30+sw);
LcdWriteData(0x30+gw);
}
void Uart1Init(void)
{
SCON = 0x50;
AUXR |= 0x40;
AUXR &= 0xFE;
TMOD &= 0x0F;
TL1 = 0xC7;
TH1 = 0xFE;
ET1 = 0;
TR1 = 1;
}
void Uart1Send(unsigned char dat)
{
SBUF=dat;
while(!TI);
TI=0;
}
void Timer0Init(void)
{
AUXR &= 0x7F;
TMOD &= 0xF0;
TMOD |= 0x01;
TL0 = 0xB0;
TH0 = 0x3C;
TF0 = 0;
ET0 = 1;
TR0 = 1;
EA = 1;
}
uchar BCD_Decimal(uchar bcd)
{
uchar Decimal;
Decimal=bcd>>4;
return(Decimal=Decimal*10+(bcd&=0x0F));
}
void clock_set(void)
{
if((KEY1==0)&&(FLAG_MEDICINE==0)&&(FLAG_auxiliary==0))
{
Delaynms(20);
if((KEY1==0)&&(FLAG_MEDICINE==0)&&(FLAG_auxiliary==0))
{
FLAG_CLOCK=1;
CLOCK_FUN++;
switch(CLOCK_FUN)
{
case 1: TR0=0;
LcdWriteCom(er+0x07);
LcdWriteCom(0x0f);
temp=(miao)/10*16+(miao)%10;
Ds1302Write(0x8e,0x00);
Ds1302Write(0x80,0x80|temp);
Ds1302Write(0x8e,0x80);
break;
case 2: LcdWriteCom(er+0x04);
break;
case 3: LcdWriteCom(er+0x01);
break;
case 4: LcdWriteCom(yh+0x09);
break;
case 5: LcdWriteCom(yh+0x06);
break;
case 6: LcdWriteCom(yh+0x03);
break;
case 7: LcdWriteCom(0x0c);
CLOCK_FUN=0;
FLAG_CLOCK=0;
temp=(miao)/10*16+(miao)%10;
Ds1302Write(0x8e,0x00);
Ds1302Write(0x80,0x00|temp);
Ds1302Write(0x8e,0x80);
TR0=1;
break;
}
while(KEY1==0);
}
}
if((KEY2==0)&&(FLAG_MEDICINE==0)&&(FLAG_auxiliary==0))
{
Delaynms(20);
if((KEY2==0)&&(FLAG_MEDICINE==0)&&(FLAG_auxiliary==0))
{
if(FLAG_CLOCK==1)
{
CLOCK_FUN--;
if(CLOCK_FUN==0)
{
CLOCK_FUN=1;
}
}
switch(CLOCK_FUN)
{
case 1: TR0=0;
LcdWriteCom(er+0x07);
LcdWriteCom(0x0f);
temp=(miao)/10*16+(miao)%10;
Ds1302Write(0x8e,0x00);
Ds1302Write(0x80,0x80|temp);
Ds1302Write(0x8e,0x80);
break;
case 2: LcdWriteCom(er+0x04);
break;
case 3: LcdWriteCom(er+0x01);
break;
case 4: LcdWriteCom(yh+0x09);
break;
case 5: LcdWriteCom(yh+0x06);
break;
case 6: LcdWriteCom(yh+0x03);
break;
}
while(KEY2==0);
}
}
}
void medicine_set()
{
if((KEY6==0)&&(FLAG_CLOCK==0)&&(FLAG_auxiliary==0))
{
Delaynms(20);
if((KEY6==0)&&(FLAG_CLOCK==0)&&(FLAG_auxiliary==0))
{
uchar num;
FLAG_MEDICINE=1;
MEDICINE_FUN++;
switch(MEDICINE_FUN)
{
case 1: TR0=0;
LcdWriteCom(yh);
for(num=0;num<16;num++)
LcdWriteData(tab0[num]);
LcdWriteCom(er);
for(num=0;num<16;num++)
LcdWriteData(tab1[num]);
LcdWriteCom(er+0x0c);
LcdWriteData(yao+'0');
LcdWriteCom(er+0x0c);
LcdWriteCom(0x0f);
break;
case 2: LcdWriteCom(yh);
for(num=0;num<16;num++)
LcdWriteData(tab2[num]);
LcdWriteCom(er);
for(num=0;num<16;num++)
LcdWriteData(tab3[num]);
LcdWriteCom(er+0x03);
LcdWriteData(times[yao-1]+'0');
LcdWriteCom(er+0x03);
LcdWriteCom(0x0f);
break;
case 3: LcdWriteCom(yh);
for(num=0;num<16;num++)
LcdWriteData(tab4[num]);
LcdWriteCom(er);
for(num=0;num<16;num++)
LcdWriteData(tab6[num]);
LcdWriteCom(yh+13);
LcdWriteData(1+'0');
LcdWriteCom(yh+15);
LcdWriteData(times[yao-1]+'0');
write_sfm(4,clock[yao-1][0][1]);
write_sfm(7,clock[yao-1][0][0]);
LcdWriteCom(er+0x08);
break;
case 4: LcdWriteCom(yh);
for(num=0;num<16;num++)
LcdWriteData(tab4[num]);
LcdWriteCom(er);
for(num=0;num<16;num++)
LcdWriteData(tab6[num]);
LcdWriteCom(yh+13);
LcdWriteData(1+'0');
LcdWriteCom(yh+15);
LcdWriteData(times[yao-1]+'0');
write_sfm(4,clock[yao-1][0][1]);
write_sfm(7,clock[yao-1][0][0]);
LcdWriteCom(er+0x05);
break;
case 5: if(times[yao-1]>=2)
{
LcdWriteCom(yh);
for(num=0;num<16;num++)
LcdWriteData(tab4[num]);
LcdWriteCom(er);
for(num=0;num<16;num++)
LcdWriteData(tab6[num]);
LcdWriteCom(yh+13);
LcdWriteData(2+'0');
LcdWriteCom(yh+15);
LcdWriteData(times[yao-1]+'0');
write_sfm(4,clock[yao-1][1][1]);
write_sfm(7,clock[yao-1][1][0]);
LcdWriteCom(er+0x08);
}else MEDICINE_FUN=10;
break;
case 6: LcdWriteCom(yh);
for(num=0;num<16;num++)
LcdWriteData(tab4[num]);
LcdWriteCom(er);
for(num=0;num<16;num++)
LcdWriteData(tab6[num]);
LcdWriteCom(yh+13);
LcdWriteData(2+'0');
LcdWriteCom(yh+15);
LcdWriteData(times[yao-1]+'0');
write_sfm(4,clock[yao-1][1][1]);
write_sfm(7,clock[yao-1][1][0]);
LcdWriteCom(er+0x05);
break;
case 7: if(times[yao-1]>=3)
{
LcdWriteCom(yh);
for(num=0;num<16;num++)
LcdWriteData(tab4[num]);
LcdWriteCom(er);
for(num=0;num<16;num++)
LcdWriteData(tab6[num]);
LcdWriteCom(yh+13);
LcdWriteData(3+'0');
LcdWriteCom(yh+15);
LcdWriteData(times[yao-1]+'0');
write_sfm(4,clock[yao-1][2][1]);
write_sfm(7,clock[yao-1][2][0]);
LcdWriteCom(er+0x08);
}else MEDICINE_FUN=10;
break;
case 8: LcdWriteCom(yh);
for(num=0;num<16;num++)
LcdWriteData(tab4[num]);
LcdWriteCom(er);
for(num=0;num<16;num++)
LcdWriteData(tab6[num]);
LcdWriteCom(yh+13);
LcdWriteData(3+'0');
LcdWriteCom(yh+15);
LcdWriteData(times[yao-1]+'0');
write_sfm(4,clock[yao-1][2][1]);
write_sfm(7,clock[yao-1][2][0]);
LcdWriteCom(er+0x05);
break;
case 9: if(times[yao-1]>=4)
{
LcdWriteCom(yh);
for(num=0;num<16;num++)
LcdWriteData(tab4[num]);
LcdWriteCom(er);
for(num=0;num<16;num++)
LcdWriteData(tab6[num]);
LcdWriteCom(yh+13);
LcdWriteData(4+'0');
LcdWriteCom(yh+15);
LcdWriteData(times[yao-1]+'0');
write_sfm(4,clock[yao-1][3][1]);
write_sfm(7,clock[yao-1][3][0]);
LcdWriteCom(er+0x08);
}else MEDICINE_FUN=10;
break;
case 10: LcdWriteCom(yh);
for(num=0;num<16;num++)
LcdWriteData(tab4[num]);
LcdWriteCom(er);
for(num=0;num<16;num++)
LcdWriteData(tab6[num]);
LcdWriteCom(yh+13);
LcdWriteData(4+'0');
LcdWriteCom(yh+15);
LcdWriteData(times[yao-1]+'0');
write_sfm(4,clock[yao-1][3][1]);
write_sfm(7,clock[yao-1][3][0]);
LcdWriteCom(er+0x05);
break;
case 11: LcdWriteCom(yh);
for(num=0;num<16;num++)
LcdWriteData(tab5[num]);
LcdWriteCom(er);
for(num=0;num<16;num++)
LcdWriteData(tab7[num]);
write_sfm(5,clock[yao-1][0][3]);
write_sfm(8,clock[yao-1][0][2]);
LcdWriteCom(er+0x09);
break;
case 12: LcdWriteCom(yh);
for(num=0;num<16;num++)
LcdWriteData(tab5[num]);
LcdWriteCom(er);
for(num=0;num<16;num++)
LcdWriteData(tab7[num]);
write_sfm(5,clock[yao-1][0][3]);
write_sfm(8,clock[yao-1][0][2]);
LcdWriteCom(er+0x06);
break;
case 13: LcdWriteCom(yh);
for(num=0;num<16;num++)
LcdWriteData(tab8[num]);
LcdWriteCom(er);
for(num=0;num<16;num++)
LcdWriteData(' ');
if(clock_flag[yao-1]==1)
{
LcdWriteCom(er+0x06);
LcdWriteData('O');
LcdWriteData('N');
LcdWriteData(' ');
}else
{
LcdWriteCom(er+0x06);
LcdWriteData('O');
LcdWriteData('F');
LcdWriteData('F');
}
LcdWriteCom(0x0C);
break;
case 14:LcdWriteCom(yh);
for(num=0;num<16;num++)
LcdWriteData(' ');
LcdWriteCom(er);
for(num=0;num<16;num++)
LcdWriteData(' ');
TR0=1;
FLAG_MEDICINE=0;
MEDICINE_FUN=0;
break;
}
}
while(KEY6==0);
}
if((KEY5==0)&&(FLAG_CLOCK==0)&&(FLAG_auxiliary==0))
{
Delaynms(20);
if((KEY5==0)&&(FLAG_CLOCK==0)&&(FLAG_auxiliary==0))
{
uchar num;
if(FLAG_MEDICINE==1)
{
if(MEDICINE_FUN==1)
{
LcdWriteCom(yh);
for(num=0;num<16;num++)
LcdWriteData(' ');
LcdWriteCom(er);
for(num=0;num<16;num++)
LcdWriteData(' ');
LcdWriteCom(0x0c);
TR0=1;
FLAG_MEDICINE=0;
MEDICINE_FUN=0;
}
else
{
MEDICINE_FUN=1;
TR0=0;
LcdWriteCom(yh);
for(num=0;num<16;num++)
LcdWriteData(tab0[num]);
LcdWriteCom(er);
for(num=0;num<16;num++)
LcdWriteData(tab1[num]);
LcdWriteCom(er+0x0c);
LcdWriteData(yao+'0');
LcdWriteCom(er+0x0c);
LcdWriteCom(0x0f);
}
}
}
while(KEY5==0);
}
}
void main(void)
{
BEEP=0;
IO_init();
Uart1Init();
LcdInit();
Ds1302Init();
Delaynms(10);
Ds1302ReadTime();
LcdDisplay();
Timer0Init();
clock[0][0][2]=clock[0][0][3]=1;
clock[1][0][2]=clock[1][0][3]=1;
clock[2][0][2]=clock[2][0][3]=1;
clock[3][0][2]=clock[3][0][3]=1;
clock[4][0][2]=clock[4][0][3]=1;
clock[5][0][2]=clock[5][0][3]=1;
while(1)
{
clock_set();
medicine_set();
digital_change();
auxiliary();
clock_scan();
temp11=Ds18b20ReadTemp();
GetTemp();
if((KEY8==0)&&(Key8Press==0))
{
Delaynms(20);
if((KEY8==0)&&(Key8Press==0))
{
Display_Flag=~Display_Flag;
}
while(KEY8==0);
}
}
}
#include<STC15F2K60S2.h>
#include<intrins.h>
unsigned char temp;
sbit Pow = P3^6;
void Delay100ms()
{
unsigned char i, j, k;
_nop_();
_nop_();
i = 5;
j = 144;
k = 71;
do
{
do
{
while (--k);
} while (--j);
} while (--i);
}
void Delay(unsigned int a)
{
unsigned int b;
for(b=a;b>0;b--)
Delay100ms();
}
void IO_init(void)
{
P0M0=0x00;
P0M1=0x00;
P1M0=0x00;
P1M1=0x00;
P2M0=0x00;
P2M1=0x00;
P3M0=0x00;
P3M1=0x00;
P4M0=0x00;
P4M1=0x00;
P5M0=0x00;
P5M1=0x00;
P6M0=0x00;
P6M1=0x00;
P7M0=0x00;
P7M1=0x00;
}
void Uart1Init(void)
{
SCON = 0x50;
AUXR |= 0x01;
AUXR |= 0x04;
T2L = 0xC7;
T2H = 0xFE;
AUXR |= 0x10;
ES=1;
EA=1;
}
void Uart1Send(unsigned char dat)
{
SBUF=dat;
while(!TI);
TI=0;
}
void Uart1Sends(unsigned char *str)
{
while(*str!='\0')
{
SBUF=*str;
while(!TI);
TI=0;
str++;
}
}
void Messages(unsigned char th)
{
if(th>0&&th<7)
{
P_SW1 |= 0x40;
ES=0;
Uart1Sends("AT+CSCS=\"GSM\"\r\n");
Delay(1);
Uart1Sends("AT+CMGF=1\r\n");
Delay(1);
Uart1Sends("AT+CSCA?\r\n");
Delay(1);
Uart1Sends("AT+CSMP=17,167,0,0\r\n");
Delay(1);
Uart1Sends("AT+CMGS=\"18888888888\"\r\n");
Delay(1);
Uart1Sends("The patient did not take medicine");
switch(th)
{
case 0X01: Uart1Sends(" 1 on time!");break;
case 0X02: Uart1Sends(" 2 on time!");break;
case 0X03: Uart1Sends(" 3 on time!");break;
case 0X04: Uart1Sends(" 4 on time!");break;
case 0X05: Uart1Sends(" 5 on time!");break;
case 0X06: Uart1Sends(" 6 on time!");break;
}
Uart1Send(0x1a);
P_SW1 &= 0xbf;
temp=0;
ES=1;
}
}
void main(void)
{
IO_init();
Uart1Init();
temp=0;
Pow=1;Delay(1);
Pow=0;Delay(45);
Pow=1;
while(1)
{
Messages(temp);
}
}
void Uart1 (void) interrupt 4
{
if(RI==1)
{
RI=0;
temp=SBUF;
}
}
|