吉林省电子大赛 运动木棒长度计量装置 程序清单Word下载.docx
《吉林省电子大赛 运动木棒长度计量装置 程序清单Word下载.docx》由会员分享,可在线阅读,更多相关《吉林省电子大赛 运动木棒长度计量装置 程序清单Word下载.docx(25页珍藏版)》请在冰豆网上搜索。
//unsignedcharstart_pic[10]={'
s'
'
t'
a'
r'
!
'
};
//unsignedintstart_count;
////////////////////////////////////回显完毕
unsignedcharconstplay_back[16]={'
p'
l'
y'
b'
c'
k'
'
o'
v'
e'
unsignedintplay_count;
//////////////////测试看结果value_a0value_a1value_b0value_b1
//unsignedcharsend_val_a0[8]="
aaaaa"
//unsignedcharsend_val_a1[8]="
bbbbb"
//unsignedcharsend_val_b0[8]="
ccccc"
unsignedcharsend_val_b1[8]="
ddddd"
////////////////////////////////////////////////////////////////////
#defineIrDA_0PIN_a1
#defineIrDA_1PIN_a2
unsignedlongcount;
//////计数值
floatrange_init=10.00;
//////两个红外间距离为5cm
floatrange_long;
/////一个木棍长度
int16Mu_long;
/////一个木棍长度乘以100range_long*100;
floatrange_total;
//////记录木棍总长度
int16Mu_total;
//////记录木棍总长度乘以100range_tatal*100;
unsignedintnum_total;
//////记录木棍数量
unsignedintMu_num;
/////显示用
floatspeed_current;
///////木棍速度
int1over_flag;
////木棍下落结束标志
unsignedlongvalue_a0;
/////首次通过时计数值
unsignedlongvalue_a1;
unsignedlongvalue_b0;
/////再次通过时计数值
unsignedlongvalue_b1;
//unsignedlongvalue_c0;
/////
//unsignedlongvalue_c1;
int1flag_0;
//初始化为0
int1flag_1;
int1fan_flag;
/////正反计数标志
int1fan_flag1;
int1fan_flag2;
/////////////////串口数据区////////////串口数据区//////////
unsignedchars_uart_data[22]="
$$XXX.XX,ZZ,YYY.YY##"
unsignedints_uart_i;
voiduart_change()
{
s_uart_data[2]=send_long[0];
s_uart_data[3]=send_long[1];
s_uart_data[4]=send_long[2];
s_uart_data[6]=send_long[4];
s_uart_data[7]=send_long[5];
s_uart_data[9]=send_num[0];
s_uart_data[10]=send_num[1];
s_uart_data[12]=send_total[0];
s_uart_data[13]=send_total[1];
s_uart_data[14]=send_total[2];
s_uart_data[16]=send_total[4];
s_uart_data[17]=send_total[5];
}
voiduart_fashe()
output_low(PIN_C1);
///////语音控制位高电平有效
output_high(PIN_C0);
////////////串口控制位高电平有效
delay_ms(1000);
for(s_uart_i=0;
s_uart_i<
20;
s_uart_i++)
{
putc(s_uart_data[s_uart_i]);
}
putc('
\n'
);
delay_ms(200);
output_low(PIN_C0);
/////////////////语音播报//////////////语音播报////////////
unsignedchars_welcome[]="
欢迎使用长度测试系统"
//
unsignedcharheadOfFrame[5];
unsignedcharecc=0;
unsignedintspeak_i=0;
voidzhuanhuan()//////转换
sound_data[8]=send_long[0];
sound_data[9]=send_long[1];
sound_data[10]=send_long[2];
sound_data[12]=send_long[4];
sound_data[13]=send_long[5];
sound_data[22]=send_num[0];
sound_data[23]=send_num[1];
sound_data[34]=send_total[0];
sound_data[35]=send_total[1];
sound_data[36]=send_total[2];
sound_data[38]=send_total[4];
sound_data[39]=send_total[5];
voidspeak(intcount,unsignedchar*string)
headOfFrame[0]=0xFD;
headOfFrame[1]=0x00;
headOfFrame[2]=count+3;
//t_length+3;
headOfFrame[3]=0x01;
headOfFrame[4]=0x00;
ecc=0;
for(speak_i=0;
speak_i<
5;
speak_i++)
ecc=ecc^(headOfFrame[speak_i]);
putc(headOfFrame[speak_i]);
for(speak_i=0;
count;
ecc=ecc^(string[speak_i]);
putc(string[speak_i]);
putc(ecc);
voidsound_speaker(intput_int_s,char*put_sound)
//output_low(PIN_A5);
//delay_ms(500);
output_high(PIN_C1);
speak(put_int_s,put_sound);
delay_ms(100);
unsignedcharkey;
int1new_key_flag;
/**************************************************************************
RB4RB5RB6RB7
RB0K0K1K2K3
RB1K4K5K6K7
RB2K8K9KAKB
RB3KCKDKEKF
*************************************************************************/
#defineK0'
1'
#defineK1'
2'
#defineK2'
3'
#defineK3'
0'
#defineK4'
4'
#defineK5'
5'
#defineK6'
6'
#defineK7'
#defineK8'
7'
#defineK9'
8'
#defineKA'
9'
#defineKB'
#defineKC'
*'
#defineKD'
#defineKE'
#'
#defineKF'
#int_RB
voidRB_key_scan(void)
unsignedchartemp,temp1,temp2,count;
count=0;
set_tris_b(0xf0);
//11110000
output_b(0);
temp1=input_b();
temp1&
=0XF0;
if(temp1!
=0XF0)
set_tris_b(0x0F);
temp2=input_b();
temp2&
=0x0F;
temp=temp1|temp2;
switch(temp)
case0x77:
key=KF;
new_key_flag=1;
break;
case0x7B:
key=KB;
case0x7D:
key=K7;
case0x7E:
key=K3;
case0xB7:
key=KE;
case0xBB:
key=KA;
case0xBD:
key=K6;
case0xBE:
key=K2;
case0xD7:
key=KD;
case0xDB:
key=K9;
case0xDD:
key=K5;
case0xDE:
key=K1;
case0xE7:
key=KC;
case0xEB:
key=K8;
case0xED:
key=K4;
case0xEE:
key=K0;
default:
new_key_flag=0;
do{temp1=input_b();
temp1&
delay_ms(300);
while(temp1!
=0xf0);
/////////////////函数声明///////////////////////////////////////
voidjuliceliang();
voidfan_juliceliang();
voidhandle_long();
voidhandle_total();
voidhandle_num();
//voidhandle_a0();
//voidhandle_a1();
//voidhandle_b0();
//voidhandle_b1();
voidlcd_xianshi();
voidhuixian();
voidhandle_b1();
////////////////////////////////////////////////////////////////
#int_timer0
voidintval()
set_timer0(0x63);
////////1ms
count++;
//#int_ad
//voidadc_handler(){
//touch_pad=read_adc(ADC_READ_ONLY);
//read_adc(ADC_START_ONLY);
//possiblycoulduse"
if(ADCON0){"
//if(((ADCON0&
0x38)>
>
3)==0){//mustbechannel1
//touch_pad/*ch1_result*/=read_adc();
//get8-bitreadingforch1
//}
//ADCON0|=0x00/*0x4*/;
//RestartA/D(setstheGObittostartconversion)
//Iftheprogramwasnotinterrupt-based,theGObit
//couldbeinterrogatedtodeterminewhentheconversion
//wascompleted.
//}
#int_rda
voidRDA_isr()
voidinit(void)
set_tris_a(0x1f);
//output_a(0);
port_b_pullups(TRUE);
/////key
setup_adc(ADC_CLOCK_INTERNAL);
//setup_adc_ports(ANALOG_RA3_REF);
////RA0_RA1_RA3_引脚为模拟输入
setup_adc_ports(RA0_ANALOG);
setup_adc(ADC_CLOCK_DIV_32);
////Fosc/32最高速度
set_adc_channel(0);
flag_0=0;
///////物体经过红外标志
flag_1=0;
fan_flag=0;
fan_flag1=0;
over_flag=0;
range_total=0.00;
range_long=0.00;
num_total=0;
save_count=0;
///////存储计数
//////定时器0初始化
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_32);
//set_timer0(0x63);
///////定时1ms
//////中断允许
//enable_interrupts(INT_TIMER0);
disable_interrupts(INT_TIMER0);
//enable_interrupts(INT_RDA);
enable_interrupts(INT_RB);
//enable_interrupts(INT_AD);
enable_interrupts(GLOBAL);
/////////调试参数
//range_long=12.348;
//range_total=34.561;
//num_total=98;
//over_flag=1;
//////////调试参数
//output_low(PIN_E2);
lcd_init();
//delay_ms
(1);
sound_speaker(20,s_welcome);
lcd_display();
delay_ms
(1);
lcd_clear();
/*for(start_count=0;
start_count<
=7;
start_count++)
lcd_data(start_pic[start_count]);
}
*/
}//init
voidmain()
init();
while
(1)
//set_tris_a(0);
//set_tris_a(0xFF);
read_adc(ADC_START_ONLY);
if((flag_0==0)&
&
(input(IrDA_0)==1))
if(fan_flag==0)
{
fan_flag=1;
fan_flag1=0;
fan_flag2=0;
count=0;
set_timer0(0x63);
enable_interrupts(INT_TIMER0);
}
value_a0=count;
///////////////
flag_0=1;
//output_high(PIN_E2);
if((flag_1==0)&
(input(IrDA_1)==1))
fan_flag1=1;
fan_flag2=1;
value_a1=count;
flag_1=1;
//output_low(PIN_E2);
if((flag_0==1)&
(input(IrDA_0)==0))
value_b0=count;
//////////////
flag_0=0;
if(fan_flag2==1)
over_flag=1;
disable_interrupts(INT_TIMER0);
}
if((flag_1==1)&
(input(IrDA_1)==0))
value_b1=count;
////////////
flag_1=0;
if(fan_flag2==0)
}
if(over_flag==1)
over_flag=0;
fan_flag=0;
/////清零反向标志
if(fan_flag1==0)
juliceliang();
////距离测量
num_total=num_total+1;
range_total=range_total+range_long;
///////记录木棍总长度
else
fan_juliceliang();
num_total=num_total-1;
range_total=range_total-range_long;
handle_long();
handle_total();
handle_num();