break; } }
//加键执行函数
void Key_Add_Action(void) {
switch( WK_MODE ) {
case 3:voltage_q++;
if(voltage_q>9)voltage_q=0;
Voltage_Max= voltage_q*1000+voltage_b*100+voltage_s*10+voltage_g; break;
case 4:voltage_b++;
if(voltage_b>9)voltage_b=0;
Voltage_Max= voltage_q*1000+voltage_b*100+voltage_s*10+voltage_g; break;
case 5:voltage_s++;
if(voltage_s>9)voltage_s=0;
Voltage_Max= voltage_q*1000+voltage_b*100+voltage_s*10+voltage_g; break;
case 6:voltage_g++;
if(voltage_g>9)voltage_g=0;
Voltage_Max= voltage_q*1000+voltage_b*100+voltage_s*10+voltage_g; break;
case 7:current_q++;
if(current_q>9)current_q=0;
Current_Max= current_q*1000+current_b*100+current_s*10+current_g; break;
case 8:current_b++;
if(current_b>9)current_b=0;
Current_Max= current_q*1000+current_b*100+current_s*10+current_g; break;
case 9:current_s++;
if(current_s>9)current_s=0;
Current_Max= current_q*1000+current_b*100+current_s*10+current_g; break;
case 10:current_g++;
if(current_g>9)current_g=0;
Current_Max= current_q*1000+current_b*100+current_s*10+current_g; break; default:
break; } }
//减键执行函数
void Key_Dec_Action(void) {
switch(WK_MODE) {
case 3:voltage_q--;
if( voltage_q<0 )voltage_q = 9;
Voltage_Max= voltage_q*1000+voltage_b*100+voltage_s*10+voltage_g; break;
case 4:voltage_b--;
if( voltage_b<0 )voltage_b = 9;
Voltage_Max= voltage_q*1000+voltage_b*100+voltage_s*10+voltage_g; break;
case 5:voltage_s--;
if( voltage_s<0 )voltage_s = 9;
Voltage_Max= voltage_q*1000+voltage_b*100+voltage_s*10+voltage_g; break;
case 6:voltage_g--;
if( voltage_g<0 )voltage_g = 9;
Voltage_Max=voltage_q*1000+voltage_b*100+voltage_s*10+voltage_g; break;
case 7:current_q--;
if( current_q<0 )current_q = 9;
Current_Max= current_q*1000+current_b*100+current_s*10+current_g; break;
case 8:current_b--;
if( current_b<0 )current_b = 9;
Current_Max= current_q*1000+current_b*100+current_s*10+current_g; break;
case 9:current_s--;
if( current_s<0 )current_s = 9;
Current_Max= current_q*1000+current_b*100+current_s*10+current_g; break;
case 10:current_g--;
if( current_g<0 )current_g = 9;
Current_Max= current_q*1000+current_b*100+current_s*10+current_g; break; default:
break;
} }
//按键扫描
void KEYSCAN(void)
{
if( Key_Scan_F )//10ms到按键检测使能 { Key_Scan_F = 0;//按键使能标志位清零 Key_Num = P3&0X7C;//读键值
/************************系统设定键******************************/ if( ( !Key_Set )&&( Key_Num == Key_Backup) )//如果设定键按下 {
if( !Key_Dis_F )//按键操作示响应 {
KEY_JSQ++; //按键闭合计数器加1
if( KEY_JSQ >= AN_CJ_DL )//判定系统设定键长击 {
KEY_JSQ = 0;//闭合计数器清零 Key_Cj_Action();//执行散转函数 Key_Dis_F = 1;//按键禁止响应 } } }
else //松开或键值变化 {
if( ( !Key_Dis_F )&&( KEY_JSQ>=AN_XD_DL )&&( KEY_JSQ <= AN_CJ_DL ) )//系统设定键短击 {
KEY_JSQ = 0;
Key_Dj_Action(); Key_Dis_F = 1; }
Key_Backup = Key_Num; //重新记录键值 Key_Dis_F = 0; }
if( ( ( !Key_Right )||( !Key_Left ) )&&( Key_Num == Key_Backup ) )//左移键或右移键按下,支持短击 {
KEY_JSQ++;
if( ( KEY_JSQ >= AN_XD_DL )&&( !Key_Right ) )//右移键按下 {
KEY_JSQ = 0;
Flag_Right = 1;//右移键按下标志位 }
if( ( KEY_JSQ>=AN_XD_DL )&&( !Key_Left ) )//左移键按下 {
KEY_JSQ = 0;
Flag_Left = 1;//左移键按下标志位
} }
else//松开,短击松开后执行函数 {
if( Flag_Right ) {
Flag_Right = 0; Key_Right_Action(); }
if( Flag_Left ) {
Flag_Left = 0; Key_Left_Action(); }
Key_Backup = Key_Num; //重新记录键值 }
/***************************加键按下***************************/ if( ( !Key_Add )&&( Key_Num == Key_Backup ) ) {
if( ( !( K_ADD_DELAY-- ) )&&( !Key_Add ) ) {
Key_Add_Action();
K_ADD_DELAY = AN_LA_DL; } } else {
Key_Backup = Key_Num; K_ADD_DELAY = AN_XD_DL; }
/**************************减键按下*****************************/ if( ( !Key_Dec )&&( Key_Num == Key_Backup ) ) {
if( ( !( K_DEC_DELAY-- ))&&( !Key_Dec) ) {
Key_Dec_Action();
K_DEC_DELAY = AN_LA_DL; } } else {
Key_Backup = Key_Num; K_DEC_DELAY = AN_XD_DL; }
} }
//A/D模块函数 #include\#include\#include\
unsigned char ch=6; //通道选择
unsigned int MCU_ADC0,MCU_ADC1;//通道0电压值,通道1电压值 //ADC初始化函数 void Adc_Init(void) { P1ASF = 0XC0;//MCU_ADC0(P1.6),MCU_ADC1(P1.7) ADC_RES = 0;//AD转换结果寄存器清零
ADC_CONTR=ADC_POWER|ADC_SPEEDLL|ADC_START|ch; _nop_();//延时 _nop_(); _nop_(); _nop_(); }
//ADC中断服务函数
void Adc_Isr(void) interrupt 5 {
ADC_CONTR &=!ADC_FLAG;//当A/D转换完成后,由软件清零 if(ch==6)//ADC通道0 {
MCU_ADC0=ADC_RES; }
if(ch==7)//ADC通道1 {
MCU_ADC1=ADC_RES; } switch(ch)//ADC通道0和ADC通道1轮番读电压 {
case 6:
ch=7; break; case 7:
ch=6; break; default:
break; } }
//PWMD/A调节模块
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库智能电池充电器的设计-毕业设计 - 图文(8)在线全文阅读。
相关推荐: