PWM.C代码:输出一个20ms为周期的PWM波,定时器产生PWM波形计算方法:84000000/(8399+1)*(199+1)=0.02。
void TIM3_PWM_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
GPIO_PinAFConfig(GPIOC,GPIO_PinSource6,GPIO_AF_TIM3);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOC,&GPIO_InitStructure);
TIM_TimeBaseStructure.TIM_Prescaler=8399;
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_Period=199;
TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1;
TIM_TimeBaseInit(TIM3,&TIM_TimeBaseStructure);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
TIM_OC1Init(TIM3, &TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Enable);
TIM_ARRPreloadConfig(TIM3,ENABLE);
TIM_Cmd(TIM3, ENABLE);
}
USART3.C代码:进行串口的初始化,并使能相应的接收中断函数,来达到可接收函数解锁的目的。
void usart3_init(u32 bound)
{
NVIC_InitTypeDef NVIC_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
USART_DeInit(USART3); //复位串口3
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB,ENABLE); //使能GPIOB时钟
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE);//使能USART3时钟
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_10; //GPIOB11和GPIOB10初始化
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//复用功能
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //速度50MHz
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //推挽复用输出
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //上拉
GPIO_Init(GPIOB,&GPIO_InitStructure); //初始化GPIOB11,和GPIOB10
GPIO_PinAFConfig(GPIOB,GPIO_PinSource11,GPIO_AF_USART3); //GPIOB11复用为USART3
GPIO_PinAFConfig(GPIOB,GPIO_PinSource10,GPIO_AF_USART3); //GPIOB10复用为USART3
USART_InitStructure.USART_BaudRate = bound;//波特率一般设置为9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;//字长为8位数据格式
USART_InitStructure.USART_StopBits = USART_StopBits_1;//一个停止位
USART_InitStructure.USART_Parity = USART_Parity_No;//无奇偶校验位
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//无硬件数据流控制
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //收发模式
USART_Init(USART3, &USART_InitStructure); //初始化串口3
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);//开启中断
USART_Cmd(USART3, ENABLE); //使能串口
NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=2 ;//抢占优先级2
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //子优先级3
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能
NVIC_Init(&NVIC_InitStructure); //根据指定的参数初始化VIC寄存器
TIM7_Int_Init(100-1,8400-1); //10ms中断一次
TIM_Cmd(TIM7, DISABLE); //关闭定时器7
USART3_RX_STA=0; //清零
}
void USART3_IRQHandler(void)
{
u8 res;
if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET)//接收到数据
{
res =USART_ReceiveData(USART3);
if((USART3_RX_STA&(1<<15))==0)//接收完的一批数据,还没有被处理,则不再接收其他数据
{
if(USART3_RX_STA
{
TIM_SetCounter(TIM7,0);//计数器清空
if(USART3_RX_STA==0)
TIM_Cmd(TIM7, ENABLE); //使能定时器7
USART3_RX_BUF[USART3_RX_STA++]=res; //记录接收到的值
}else
{
USART3_RX_STA|=1<<15; //强制标记接收完成
}
}
}
}
TIMER.C代码:USART3的定时器设置。
void TIM7_Int_Init(u16 arr,u16 psc)
{
NVIC_InitTypeDef NVIC_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM7, ENABLE);//TIM7时钟使能
//定时器TIM7初始化
TIM_TimeBaseStructure.TIM_Period = arr; //设置在下一个更新事件装入活动的自动重装载寄存器周期的值
TIM_TimeBaseStructure.TIM_Prescaler =psc; //设置用来作为TIMx时钟频率除数的预分频值
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; //设置时钟分割:TDTS = Tck_tim
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //TIM向上计数模式
TIM_TimeBaseInit(TIM7, &TIM_TimeBaseStructure); //根据指定的参数初始化TIMx的时间基数单位
TIM_ITConfig(TIM7,TIM_IT_Update,ENABLE ); //使能指定的TIM7中断,允许更新中断
TIM_Cmd(TIM7,ENABLE);//使能定时器7
NVIC_InitStructure.NVIC_IRQChannel = TIM7_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0 ;//抢占优先级0
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; //子优先级1
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能
NVIC_Init(&NVIC_InitStructure); //根据指定的参数初始化VIC寄存器
}
void TIM7_IRQHandler(void)
{
if (TIM_GetITStatus(TIM7, TIM_IT_Update) != RESET)//是更新中断
{
USART3_RX_STA|=1<<15; //标记接收完成
TIM_ClearITPendingBit(TIM7, TIM_IT_Update ); //清除TIM7更新中断标志
TIM_Cmd(TIM7, DISABLE); //关闭TIM7
}
}
GUI.C代码:通过调用OLED中的驱动函数设计出了一下OLED画面。
void GUI_OLED_LOCK(void)//锁屏面板初始化
{
OLED_Clear();
OLED_ShowChinese(48,0,13,16);
OLED_ShowChinese(64,0,36,16);
OLED_ShowChinese(0,16,0,16);
OLED_ShowChinese(16,16,1,16);
OLED_ShowString(32,16,":",16);//密码开始打印位置为x=40,y=16
OLED_Refresh();
OLED_ShowPicture(48,4,80,8,BMP1);
}
void GUI_OLED_UNLOCHING(void)//进行开锁中
{
u8 i;
double t=0.0;
char buf[8];
OLED_Clear();
OLED_ShowChinese(32,0,2,16);
OLED_ShowChinese(48,0,7,16);
OLED_ShowChinese(64,0,19,16);
OLED_ShowChinese(80,0,13,16);
OLED_ShowChinese(0,16,29,16);
OLED_ShowChinese(16,16,30,16);
OLED_Refresh();
for(i=0;i<80;i++)
{
t=t+1.25;
sprintf((char *)buf,"%3.0f%%",t);
OLED_DrawLine(i+32,16,i+32,32);
OLED_ShowString(88,48,(uint8_t *)buf,16);
OLED_Refresh();
OLED_ShowPicture(48,4,80,8,BMP1);
delay_ms(50);
}
}
void GUI_OLED_UNLOCK_OK(void)//开锁成功
{
u8 i;
double t=0.0;
char buf[8];
OLED_Clear();
OLED_ShowChinese(32,0,19,16);
OLED_ShowChinese(48,0,13,16);
OLED_ShowChinese(64,0,10,16);
OLED_ShowChinese(80,0,11,16);
OLED_ShowChinese(0,16,31,16);
OLED_ShowChinese(16,16,32,16);
OLED_Refresh();
for(i=0;i<80;i++)
{
t=t+1.25;
sprintf((char *)buf,"%3.0f%%",t);
OLED_DrawLine(i+32,16,i+32,32);
OLED_ShowString(88,48,(uint8_t *)buf,16);
OLED_Refresh();
OLED_ShowPicture(43,4,85,8,BMP2);
delay_ms(50);
}
}
void GUI_OLED_UNLOCK_NO(void)//开锁失败
{
u8 i;
double t=0.0;
char buf[8];
OLED_Clear();
OLED_ShowChinese(32,0,19,16);
OLED_ShowChinese(48,0,13,16);
OLED_ShowChinese(64,0,8,16);
OLED_ShowChinese(80,0,9,16);
OLED_ShowChinese(0,16,25,16);
OLED_ShowChinese(16,16,33,16);
OLED_Refresh();
for(i=0;i<80;i++)
{
t=t+1.25;
sprintf((char *)buf,"%3.0f%%",t);
OLED_DrawLine(i+32,16,i+32,32);
OLED_ShowString(88,48,(uint8_t *)buf,16);
OLED_Refresh();
OLED_ShowPicture(48,4,80,8,BMP1);
delay_ms(50);
}
}
void GUI_OLED_UNLOCK(void)//开锁成功返回操控界面
{
OLED_Clear();
OLED_ShowChinese(32,0,14,16);
OLED_ShowChinese(48,0,15,16);
OLED_ShowChinese(64,0,16,16);
OLED_ShowChinese(80,0,17,16);
OLED_ShowChinese(0,16,37,16);
OLED_ShowChinese(16,16,38,16);
OLED_ShowChinese(32,16,39,16);
OLED_ShowChinese(48,16,40,16);
OLED_ShowString(64,16,":",16);
OLED_ShowString(0,32,"*:",16);
OLED_ShowChinese(16,32,34,16);
OLED_ShowChinese(32,32,35,16);
OLED_ShowChinese(48,32,0,16);
OLED_ShowChinese(64,32,1,16);
OLED_ShowString(0,48,"#:",16);
OLED_ShowChinese(16,48,13,16);
OLED_ShowChinese(32,48,36,16);
OLED_Refresh();
}
void GUI_PSSKEY(void)//按键说明界面
{
OLED_Clear();
OLED_ShowNum(8,0,1,1,16);
OLED_ShowNum(40,0,2,1,16);
OLED_ShowNum(72,0,3,1,16);
OLED_ShowChinese(96,0,41,16);
OLED_ShowChinese(112,0,42,16);
OLED_ShowNum(8,16,4,1,16);
OLED_ShowNum(40,16,5,1,16);
OLED_ShowNum(72,16,6,1,16);
OLED_ShowChinese(96,16,43,16);
OLED_ShowChinese(112,16,42,16);
OLED_ShowNum(8,32,7,1,16);
OLED_ShowNum(40,32,8,1,16);
OLED_ShowNum(72,32,9,1,16);
OLED_ShowChinese(96,32,13,16);
OLED_ShowChinese(112,32,36,16);
OLED_ShowString(8,48,"*",16);
OLED_ShowNum(40,48,0,1,16);
OLED_ShowString(72,48,"//m.obk20.com/bbs/m/#",16);
OLED_ShowChinese(96,48,3,16);
OLED_ShowChinese(112,48,44,16);
OLED_Refresh();
}
void GUI_PCHANGE(void)//密码修改界面
{
OLED_Clear();
OLED_ShowChinese(32,0,45,16);
OLED_ShowChinese(48,0,35,16);
OLED_ShowChinese(64,0,0,16);
OLED_ShowChinese(80,0,1,16);
OLED_ShowChinese(0,16,37,16);
OLED_ShowChinese(16,16,38,16);
OLED_ShowChinese(32,16,39,16);
OLED_ShowChinese(48,16,40,16);
OLED_ShowString(64,16,":",16);
OLED_ShowChinese(0,32,26,16);
OLED_ShowChinese(16,32,0,16);
OLED_ShowChinese(32,32,1,16);
OLED_ShowString(48,32,":",16);
OLED_ShowChinese(96,48,3,16);
OLED_ShowChinese(112,48,44,16);
OLED_Refresh();
}
MAIN.C代码:(修改密码系统部分)
思路:进入一次while函数进行一个死循环,只有当按键按下时才进行下面的操作。在下面的操作当中,合理的运用if和else if设置一个按键优先级顺序,按照这样的优先级顺序来进行按键操作。运用goto函数来进行每次按键回反的操作。
while((key4_val3=key_init_44())==RESET);
if(key4_val3==13)//按下*即S13键进行修改密码
{
GUI_PCHANGE();
for(i=0;i<7;i++)
{
delay_ms(200);
while((key4_val4=key_init_44())==RESET);
if(key4_val4==13)//返回系统主界面
{
goto loop2;
}
else if(key4_val4==4)//删除
{
i=-1;
for(j=0;j<6;j++)
{
keysd[j]=j+1;
}
key4_val4=0;
GUI_PCHANGE();
}
else if(key4_val4==8)//清除
{
if(i>0)
{
i--;
keysd
=i+1;
OLED_ShowString((56+i*8),32," ",16);
OLED_Refresh();
i--;
}
key4_val4=0;
}
else if(key4_val4==16)//确认
{
if(i==6)
{
for(i=0;i<6;i++)
{
keysd=keysa;
}
OLED_ShowChinese(0,48,10,16);
OLED_ShowChinese(16,48,11,16);
OLED_Refresh();
goto loop2;
}
key4_val4=0;
}
else if((key4_val4!=15)&&(key4_val4!=12))//数字输入
{
u8 temp;
if(i<6)
{
switch(key4_val4)
{
case 1:temp=1;
break;
case 2:temp=2;
break;
case 3:temp=3;
break;
case 5:temp=4;
break;
case 6:temp=5;
break;
case 7:temp=6;
break;
case 9:temp=7;
break;
case 10:temp=8;
break;
case 11:temp=9;
break;
case 14:temp=0;
break;
default:temp=10;
break;
}
keysa=temp;
OLED_ShowString((56+i*8),32,"*",16);
OLED_Refresh();
}
else
{
i--;
}
}
else
{
i--;
}
key4_val4=0;
}
}
else if(key4_val3==15)//按下#即S15键进行系统锁定
{
key4_val3=0;
key4_val2=0;
TIM_SetCompare1(TIM3,180);
delay_ms(2000);
TIM_SetCompare1(TIM3,100);
goto loop1;
}
PWM.C代码:输出一个20ms为周期的PWM波,定时器产生PWM波形计算方法:84000000/(8399+1)*(199+1)=0.02。
void TIM3_PWM_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
GPIO_PinAFConfig(GPIOC,GPIO_PinSource6,GPIO_AF_TIM3);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOC,&GPIO_InitStructure);
TIM_TimeBaseStructure.TIM_Prescaler=8399;
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_Period=199;
TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1;
TIM_TimeBaseInit(TIM3,&TIM_TimeBaseStructure);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
TIM_OC1Init(TIM3, &TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Enable);
TIM_ARRPreloadConfig(TIM3,ENABLE);
TIM_Cmd(TIM3, ENABLE);
}
USART3.C代码:进行串口的初始化,并使能相应的接收中断函数,来达到可接收函数解锁的目的。
void usart3_init(u32 bound)
{
NVIC_InitTypeDef NVIC_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
USART_DeInit(USART3); //复位串口3
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB,ENABLE); //使能GPIOB时钟
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE);//使能USART3时钟
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_10; //GPIOB11和GPIOB10初始化
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//复用功能
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //速度50MHz
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //推挽复用输出
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //上拉
GPIO_Init(GPIOB,&GPIO_InitStructure); //初始化GPIOB11,和GPIOB10
GPIO_PinAFConfig(GPIOB,GPIO_PinSource11,GPIO_AF_USART3); //GPIOB11复用为USART3
GPIO_PinAFConfig(GPIOB,GPIO_PinSource10,GPIO_AF_USART3); //GPIOB10复用为USART3
USART_InitStructure.USART_BaudRate = bound;//波特率一般设置为9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;//字长为8位数据格式
USART_InitStructure.USART_StopBits = USART_StopBits_1;//一个停止位
USART_InitStructure.USART_Parity = USART_Parity_No;//无奇偶校验位
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//无硬件数据流控制
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //收发模式
USART_Init(USART3, &USART_InitStructure); //初始化串口3
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);//开启中断
USART_Cmd(USART3, ENABLE); //使能串口
NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=2 ;//抢占优先级2
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //子优先级3
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能
NVIC_Init(&NVIC_InitStructure); //根据指定的参数初始化VIC寄存器
TIM7_Int_Init(100-1,8400-1); //10ms中断一次
TIM_Cmd(TIM7, DISABLE); //关闭定时器7
USART3_RX_STA=0; //清零
}
void USART3_IRQHandler(void)
{
u8 res;
if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET)//接收到数据
{
res =USART_ReceiveData(USART3);
if((USART3_RX_STA&(1<<15))==0)//接收完的一批数据,还没有被处理,则不再接收其他数据
{
if(USART3_RX_STA
{
TIM_SetCounter(TIM7,0);//计数器清空
if(USART3_RX_STA==0)
TIM_Cmd(TIM7, ENABLE); //使能定时器7
USART3_RX_BUF[USART3_RX_STA++]=res; //记录接收到的值
}else
{
USART3_RX_STA|=1<<15; //强制标记接收完成
}
}
}
}
TIMER.C代码:USART3的定时器设置。
void TIM7_Int_Init(u16 arr,u16 psc)
{
NVIC_InitTypeDef NVIC_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM7, ENABLE);//TIM7时钟使能
//定时器TIM7初始化
TIM_TimeBaseStructure.TIM_Period = arr; //设置在下一个更新事件装入活动的自动重装载寄存器周期的值
TIM_TimeBaseStructure.TIM_Prescaler =psc; //设置用来作为TIMx时钟频率除数的预分频值
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; //设置时钟分割:TDTS = Tck_tim
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //TIM向上计数模式
TIM_TimeBaseInit(TIM7, &TIM_TimeBaseStructure); //根据指定的参数初始化TIMx的时间基数单位
TIM_ITConfig(TIM7,TIM_IT_Update,ENABLE ); //使能指定的TIM7中断,允许更新中断
TIM_Cmd(TIM7,ENABLE);//使能定时器7
NVIC_InitStructure.NVIC_IRQChannel = TIM7_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0 ;//抢占优先级0
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; //子优先级1
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能
NVIC_Init(&NVIC_InitStructure); //根据指定的参数初始化VIC寄存器
}
void TIM7_IRQHandler(void)
{
if (TIM_GetITStatus(TIM7, TIM_IT_Update) != RESET)//是更新中断
{
USART3_RX_STA|=1<<15; //标记接收完成
TIM_ClearITPendingBit(TIM7, TIM_IT_Update ); //清除TIM7更新中断标志
TIM_Cmd(TIM7, DISABLE); //关闭TIM7
}
}
GUI.C代码:通过调用OLED中的驱动函数设计出了一下OLED画面。
void GUI_OLED_LOCK(void)//锁屏面板初始化
{
OLED_Clear();
OLED_ShowChinese(48,0,13,16);
OLED_ShowChinese(64,0,36,16);
OLED_ShowChinese(0,16,0,16);
OLED_ShowChinese(16,16,1,16);
OLED_ShowString(32,16,":",16);//密码开始打印位置为x=40,y=16
OLED_Refresh();
OLED_ShowPicture(48,4,80,8,BMP1);
}
void GUI_OLED_UNLOCHING(void)//进行开锁中
{
u8 i;
double t=0.0;
char buf[8];
OLED_Clear();
OLED_ShowChinese(32,0,2,16);
OLED_ShowChinese(48,0,7,16);
OLED_ShowChinese(64,0,19,16);
OLED_ShowChinese(80,0,13,16);
OLED_ShowChinese(0,16,29,16);
OLED_ShowChinese(16,16,30,16);
OLED_Refresh();
for(i=0;i<80;i++)
{
t=t+1.25;
sprintf((char *)buf,"%3.0f%%",t);
OLED_DrawLine(i+32,16,i+32,32);
OLED_ShowString(88,48,(uint8_t *)buf,16);
OLED_Refresh();
OLED_ShowPicture(48,4,80,8,BMP1);
delay_ms(50);
}
}
void GUI_OLED_UNLOCK_OK(void)//开锁成功
{
u8 i;
double t=0.0;
char buf[8];
OLED_Clear();
OLED_ShowChinese(32,0,19,16);
OLED_ShowChinese(48,0,13,16);
OLED_ShowChinese(64,0,10,16);
OLED_ShowChinese(80,0,11,16);
OLED_ShowChinese(0,16,31,16);
OLED_ShowChinese(16,16,32,16);
OLED_Refresh();
for(i=0;i<80;i++)
{
t=t+1.25;
sprintf((char *)buf,"%3.0f%%",t);
OLED_DrawLine(i+32,16,i+32,32);
OLED_ShowString(88,48,(uint8_t *)buf,16);
OLED_Refresh();
OLED_ShowPicture(43,4,85,8,BMP2);
delay_ms(50);
}
}
void GUI_OLED_UNLOCK_NO(void)//开锁失败
{
u8 i;
double t=0.0;
char buf[8];
OLED_Clear();
OLED_ShowChinese(32,0,19,16);
OLED_ShowChinese(48,0,13,16);
OLED_ShowChinese(64,0,8,16);
OLED_ShowChinese(80,0,9,16);
OLED_ShowChinese(0,16,25,16);
OLED_ShowChinese(16,16,33,16);
OLED_Refresh();
for(i=0;i<80;i++)
{
t=t+1.25;
sprintf((char *)buf,"%3.0f%%",t);
OLED_DrawLine(i+32,16,i+32,32);
OLED_ShowString(88,48,(uint8_t *)buf,16);
OLED_Refresh();
OLED_ShowPicture(48,4,80,8,BMP1);
delay_ms(50);
}
}
void GUI_OLED_UNLOCK(void)//开锁成功返回操控界面
{
OLED_Clear();
OLED_ShowChinese(32,0,14,16);
OLED_ShowChinese(48,0,15,16);
OLED_ShowChinese(64,0,16,16);
OLED_ShowChinese(80,0,17,16);
OLED_ShowChinese(0,16,37,16);
OLED_ShowChinese(16,16,38,16);
OLED_ShowChinese(32,16,39,16);
OLED_ShowChinese(48,16,40,16);
OLED_ShowString(64,16,":",16);
OLED_ShowString(0,32,"*:",16);
OLED_ShowChinese(16,32,34,16);
OLED_ShowChinese(32,32,35,16);
OLED_ShowChinese(48,32,0,16);
OLED_ShowChinese(64,32,1,16);
OLED_ShowString(0,48,"#:",16);
OLED_ShowChinese(16,48,13,16);
OLED_ShowChinese(32,48,36,16);
OLED_Refresh();
}
void GUI_PSSKEY(void)//按键说明界面
{
OLED_Clear();
OLED_ShowNum(8,0,1,1,16);
OLED_ShowNum(40,0,2,1,16);
OLED_ShowNum(72,0,3,1,16);
OLED_ShowChinese(96,0,41,16);
OLED_ShowChinese(112,0,42,16);
OLED_ShowNum(8,16,4,1,16);
OLED_ShowNum(40,16,5,1,16);
OLED_ShowNum(72,16,6,1,16);
OLED_ShowChinese(96,16,43,16);
OLED_ShowChinese(112,16,42,16);
OLED_ShowNum(8,32,7,1,16);
OLED_ShowNum(40,32,8,1,16);
OLED_ShowNum(72,32,9,1,16);
OLED_ShowChinese(96,32,13,16);
OLED_ShowChinese(112,32,36,16);
OLED_ShowString(8,48,"*",16);
OLED_ShowNum(40,48,0,1,16);
OLED_ShowString(72,48,"//m.obk20.com/bbs/m/#",16);
OLED_ShowChinese(96,48,3,16);
OLED_ShowChinese(112,48,44,16);
OLED_Refresh();
}
void GUI_PCHANGE(void)//密码修改界面
{
OLED_Clear();
OLED_ShowChinese(32,0,45,16);
OLED_ShowChinese(48,0,35,16);
OLED_ShowChinese(64,0,0,16);
OLED_ShowChinese(80,0,1,16);
OLED_ShowChinese(0,16,37,16);
OLED_ShowChinese(16,16,38,16);
OLED_ShowChinese(32,16,39,16);
OLED_ShowChinese(48,16,40,16);
OLED_ShowString(64,16,":",16);
OLED_ShowChinese(0,32,26,16);
OLED_ShowChinese(16,32,0,16);
OLED_ShowChinese(32,32,1,16);
OLED_ShowString(48,32,":",16);
OLED_ShowChinese(96,48,3,16);
OLED_ShowChinese(112,48,44,16);
OLED_Refresh();
}
MAIN.C代码:(修改密码系统部分)
思路:进入一次while函数进行一个死循环,只有当按键按下时才进行下面的操作。在下面的操作当中,合理的运用if和else if设置一个按键优先级顺序,按照这样的优先级顺序来进行按键操作。运用goto函数来进行每次按键回反的操作。
while((key4_val3=key_init_44())==RESET);
if(key4_val3==13)//按下*即S13键进行修改密码
{
GUI_PCHANGE();
for(i=0;i<7;i++)
{
delay_ms(200);
while((key4_val4=key_init_44())==RESET);
if(key4_val4==13)//返回系统主界面
{
goto loop2;
}
else if(key4_val4==4)//删除
{
i=-1;
for(j=0;j<6;j++)
{
keysd[j]=j+1;
}
key4_val4=0;
GUI_PCHANGE();
}
else if(key4_val4==8)//清除
{
if(i>0)
{
i--;
keysd=i+1;
OLED_ShowString((56+i*8),32," ",16);
OLED_Refresh();
i--;
}
key4_val4=0;
}
else if(key4_val4==16)//确认
{
if(i==6)
{
for(i=0;i<6;i++)
{
keysd=keysa;
}
OLED_ShowChinese(0,48,10,16);
OLED_ShowChinese(16,48,11,16);
OLED_Refresh();
goto loop2;
}
key4_val4=0;
}
else if((key4_val4!=15)&&(key4_val4!=12))//数字输入
{
u8 temp;
if(i<6)
{
switch(key4_val4)
{
case 1:temp=1;
break;
case 2:temp=2;
break;
case 3:temp=3;
break;
case 5:temp=4;
break;
case 6:temp=5;
break;
case 7:temp=6;
break;
case 9:temp=7;
break;
case 10:temp=8;
break;
case 11:temp=9;
break;
case 14:temp=0;
break;
default:temp=10;
break;
}
keysa=temp;
OLED_ShowString((56+i*8),32,"*",16);
OLED_Refresh();
}
else
{
i--;
}
}
else
{
i--;
}
key4_val4=0;
}
}
else if(key4_val3==15)//按下#即S15键进行系统锁定
{
key4_val3=0;
key4_val2=0;
TIM_SetCompare1(TIM3,180);
delay_ms(2000);
TIM_SetCompare1(TIM3,100);
goto loop1;
}
1
举报