Вот в этом бесконечном цикле обрабатываются все события.
Вам тут нужно разобраться.
К сожалению - с кодировкой что то не то
Код:
while(1){
////volatile uint16_t adc_data;
////volatile uint16_t batt_voltage;
////adc_data=ReadADC(ADC_CHANNEL);
//adc_data=(adc_data/4)*7.5;
//USART_SendStr("Hello!\n\r");
if (simples_in_queue==0) display_voltage_update();
//if(update_suond_buffer_now)
// {
// sound_buffer_update();
// }
//batt_voltage = (adc_data/4)*7.5;
//batt_voltage = batt_voltage/10;
if (chit_detected)
{
lcd_clrscr();
lcd_puts("Îøèáêà äàò÷èêîâ,");
lcd_gotoxy(0, 1);
lcd_puts("Ïðîâåðü ïîâÿçêó!");
while (chit_detected)
{
beep(1000, 3, 128);
beep(500, 3, 128); //Âîñïðîèçâîäèì çâóê (÷àñòîòà, äëèòåëüíîñòü, ãðîìêîñòü)
};
keyboard_event=no_key_pressing;
reload_key_event=no_key_pressing;
joystick_event = no_pressing;
display_status();
}
switch(keyboard_event)
{
case no_key_pressing: break;
case key_pressing:
{
if (bullets > 0)
{
bullets--;//óìåíüøàåì íà 1 êîëè÷åñòâî ïàòðîíîâ
//last_simple = 0;//âîñïðîèçâîäèì çâóê âûñòðåëà
if (simples_in_queue>1) //åñëè çâóê âûñòðëà âîñïðîèçâîäèòñÿ
{
simples_in_queue=1;//çàêðîåì eeprom
while (eeprom_is_open);//äîæäåìñÿ, ïîêà eerom çàêðîåòñÿ
}
simples_in_queue = eeprom_read_word(&sound_1_size);
send_ir_package(); //Ïðîèçâîäèì "âûñòðåë"
// display_bullets_update();
}
else
{
if (simples_in_queue==0) //åñëè çâóê âûñòðëà íå âîñïðîèçâîäèòñÿ
{
play_sound_5();
}
}
keyboard_event=no_key_pressing;
}
break;
default:keyboard_event=no_key_pressing;
}
switch(reload_key_event)
{
case no_key_pressing: break;
case key_pressing:
{
if ((clips > 0)&&(simples_in_queue==0))//åñëè îáîéìû íå êîí÷èëñü è íå âîñïðîèçâîäèòüñÿ çâóê âûñòðåëà
{
playclipinsound();
clips--;//óìåíüøàåì íà 1 êîëè÷åñòâî ïàòðîíîâ
bullets = eeprom_read_byte(&eeprom_bullets_in_clip);
display_clips_update();
display_bullets_update();
for (int i=0; i< eeprom_read_byte(&eeprom_reload_duration); i++){
timer2 = 0;
while (timer2 < 8000);
}
//while (timer1 < 10000);
playclipoutsound();
BULLETS_OUT_LED_OFF;
// last_simple = 0;//âîñïðîèçâîäèì çâóê âûñòðåëà
// send_ir_package(); //Ïðîèçâîäèì "âûñòðåë"
}
reload_key_event=no_key_pressing;
}
break;
default:reload_key_event=no_key_pressing;
}
{
switch(rx_event)//âûÿñíèì, êàêîå èìåííî ñîáûòèå ïðîèçîøëî
{
case RX_COMPLETE: //ïîëó÷åí ïàêåò
{
// cli();
/*********************************************************
WOUND_LED_ON; //âêëþ÷àåì âñïîìîãàòåëüíûé ñâåòîäèîä
timer1=0;
while(timer1 < 35000);
WOUND_LED_OFF; //âûêëþ÷àåì âñïîìîãàòåëüíûé ñâåòîäèîä
************************************************************/
rx_event = NOT_EVENT;
if(!get_buffer_bit(0)) //åñëè ýòîò áèò ðàâåí 0, òî ýòî ïàêåò ñ äàííûìè (âûñòðåë)
{
// uint8_t player_id;
rx_packet = get_packet_value();
// volatile int gg;
// gg++;
if ((rx_packet.team_id != team_id())||(eeprom_read_byte(&friendly_fire_enable)&&(rx_packet.player_id != eeprom_read_byte(&eeprom_player_id))))//"ïóëÿ" ïðèëåòåëà îò èãðîêà äðóãîé, íå íàøåé, êîìàíäû
{
WOUND_LED_ON; //âêëþ÷àåì âñïîìîãàòåëüíûé ñâåòîäèîä
lcd_bl_on();
display_hit_data();
playhitsound();
WOUND_LED_OFF;
if (life_in_percent > rx_packet.damage)
{
life_in_percent = life_in_percent-rx_packet.damage;
life = (life_in_percent*10)/125;
if ((life==0)&&(life_in_percent>0)) life=1;
}
else
{
life = 0;
life_in_percent=0;
WOUND_LED_ON;
display_life(life);//îòîáðàçèì óðîâåíü æèçíè íà äèîäàõ
display_life_update();//îòîáðàçèì óðîâåíü æèçíè íà ÆÊÈ
volatile uint8_t keypress_cntr; //ñ÷åò÷èê öèêëîâ, â òå÷åíèè êîòîðûõ êóðîê áûë íàæàò
keypress_cntr = 0;
if ((eeprom_read_byte(&eeprom_tm_serial_num.device_code)!=0)&&(eeprom_read_byte(&eeprom_tm_serial_num.device_code)!=0xFF))
/*åñëè ÒÌ êëþ÷ óæå çàíåñ¸í â ïàìÿòü*/
{
joystick_event=no_pressing;
keyboard_event=no_key_pressing;
tm_event=no_tm_event;
uint8_t tm_valide;
tm_valide=0;
lcd_bl_off();
while (!tm_valide)
{//[while]
lcd_clrscr();
lcd_home();
lcd_puts("Äëÿ àêòèâàöèè");
lcd_gotoxy(0, 1);
lcd_puts("ïðèëîæèòå êëþ÷");
while (tm_event == no_tm_event)
{
WOUND_LED_INVERT;
timer2 = 0;
while (timer2 < 1000);
};
switch(tm_event)
{//[switch]
case no_tm_event:
{
}
break;
case tm_crc_error:
{
lcd_clrscr();
lcd_home();
lcd_puts("Îøèáêà CRC");
timer2 = 0;
while (timer2 < 6000){};
tm_event=no_tm_event;
}
break;
case tm_crc_ok:
{
if (tm_verification())
{ tm_valide=1;
lcd_clrscr();
lcd_home();
lcd_puts("֏!");
timer2 = 0;
while (timer2 < 6000){};
tm_event=no_tm_event;
break;
}
lcd_clrscr();
lcd_home();
lcd_puts("Íå òîò êëþ÷");
timer2 = 0;
while (timer2 < 6000){};
/*
lcd_clrscr();
lcd_home();
lcd_puts("Äëÿ àêòèâàöèè");
lcd_gotoxy(0, 1);
lcd_puts("ïðèëîæè êëþ÷");
*/
tm_event=no_tm_event;
}
break;
}//[/switch]
}//[while]
}//end if
else
{
lcd_bl_off();
display_status();
while(keypress_cntr < 20)
{
WOUND_LED_INVERT;
timer2 = 0;
while (timer2 < 1000);
switch (FIRE_KEY_IN&FIRE_KEY_PIN) //ïðîâåðÿåì, íàæàò ëè êóðîê
{
case 0: keypress_cntr++ ; break;
case FIRE_KEY_PIN: keypress_cntr = 0; break;
default: keypress_cntr = 0;
}
}
}
WOUND_LED_OFF;
init_var();//"îæèâàåì" - íà÷èíàåì íîâóþ èãðó
joystick_event=no_pressing;
keyboard_event=no_key_pressing;
tm_event=no_tm_event;
// display_status();
}
display_life(life);//îòîáðàçèì óðîâåíü æèçíè íà äèîäàõ
// display_life_update();//îòîáðàçèì óðîâåíü æèçíè íà ÆÊÈ
lcd_bl_off();
display_status();
}
// rx_player_id = rx_buffer[0];
// rx_damage = get_damage_from_rx_paket();
}
// sei();
break;
}
case RX_ERROR: //îøèáêà ïðèåìà
{
// cli();
BULLETS_OUT_LED_ON;
timer2=0;
while(timer2 < 4000);
BULLETS_OUT_LED_OFF;
rx_event = NOT_EVENT;
// sei();
break;
}
case NOT_EVENT: //îøèáêà ïðèåìà
{
// cli();
// rx_event = NOT_EVENT;
// sei();
break;
}
}
}
// timer1=0; //Ñäåëàåì ïàóçó
// while(timer1 < 65000); //Ïîäîæäåì, ïîêà íå ïðîèçîéäåò 65000 ïðåðûâàíèé òàéìåðà (÷óòü ìåíüøå ñåêóíäû)
switch(joystick_event)
{
case key_up_pressing:
{
// lcd_clrscr();
// lcd_gotoxy(0, 0);
// if ((result+10)<=max_value) result=result+10;
// lcd_gotoxy(0, 1);
// lcd_puts(int_to_str(result,3));
/*
uint16_t adc_data;
uint16_t batt_voltage;
adc_data=ReadADC(ADC_CHANNEL);
adc_data=(adc_data/4)*7.5;
display_voltage_update(adc_data);
*/
switch(display_batt_mode)
{
case icon: display_batt_mode=digit;
break;
case digit: display_batt_mode=icon;
}
joystick_event = no_pressing;
}
break;
case key_right_pressing:
{
//lcd_clrscr();
//lcd_home();
// if ((result)<max_value) result++;
// lcd_gotoxy(0, 1);
// lcd_puts(int_to_str(pgm_read_byte(arr_adress+result),3));
//lcd_puts("Íàæàòà êíîïêà \n");
//lcd_puts("Âïðàâî");
joystick_event = no_pressing;
}
break;
case key_down_pressing:
{
// lcd_clrscr();
// lcd_gotoxy(0, 0);
// if((result-9)>0) result=result-10;
// lcd_gotoxy(0, 1);
// lcd_puts(int_to_str(result,3));
joystick_event = no_pressing;
}
break;
case key_left_pressing:
{
//lcd_clrscr();
//lcd_gotoxy(0, 0);
// if ((result)>0) result--;
//lcd_puts("Íàæàòà êíîïêà \n");
//lcd_puts("Âëåâî");
// lcd_gotoxy(0, 1);
// lcd_puts(int_to_str(pgm_read_byte(arr_adress+result),3));
joystick_event = no_pressing;
}
break;
case key_central_pressing:
{
joystick_event = no_pressing;
}
break;
default: joystick_event = no_pressing;
}
if (display_bullets_update_now>0)
{
display_bullets_update();
display_bullets_update_now--;
}
};
return 0;
}