/Designs/STOPWATCH02A/SW/main.c
1,6 → 1,5
#include "main.h"
 
unsigned int position;
unsigned int32 section[4];
unsigned int32 time; // pocitadlo preteceni casovace
 
22,11 → 21,20
 
#include <lcd.c>
 
#define BUTTON1 PIN_D0
#define BUTTON2 PIN_D1
#define BUTTON3 PIN_D2
#define BUTTON1 PIN_D0
#define BUTTON2 PIN_D1
#define BUTTON3 PIN_D2
#define BUTTON4 PIN_D3
 
#define START1 PIN_B0
#define STOP1 PIN_B1
#define START2 PIN_B2
#define STOP2 PIN_B3
#define START3 PIN_B4
#define STOP3 PIN_B5
#define START4 PIN_B6
#define STOP4 PIN_B7
 
#define BEEPER PIN_C0
 
unsigned int32 run;
53,7 → 61,7
lcd_gotoxy(5,2);
Output_toggle(PIN_A0);
delay_ms(100);
printf(lcd_putc,"%d %d %d %d",bit_test(input_b(),0), bit_test(input_b(),1), bit_test(input_b(),2), bit_test(input_b(),3));
printf(lcd_putc,"%x",input_b());
}
}
void send_measuring()
63,10 → 71,6
 
void main()
{
unsigned int8 last, input;
unsigned int16 timer;
int exception;
 
setup_adc_ports(NO_ANALOGS|VSS_VDD);
port_b_pullups(TRUE);
setup_adc(ADC_OFF);
95,7 → 99,7
lcd_gotoxy(1,2);
printf(lcd_putc,"TEST");
 
while(!usb_cdc_connected()) if(!input(BUTTON1)) test_mode();
while(!usb_cdc_connected()) if(!input(BUTTON1)) test_mode(); // pockej nez se pripoji seriovy port PC
lcd_gotoxy(1,1);
printf(lcd_putc,"\f PC connected...");
106,41 → 110,16
{
run++;
printf(lcd_putc,"\f\nSTART");
section[0]=0;
section[1]=0;
section[2]=0;
section[3]=0;
last!=input_b();
while(input(BUTTON1)); // ceka na zmacknuti startovaciho tlacitka
printf(lcd_putc,"\f\n STOP"); //
 
while(input(BUTTON1));
printf(lcd_putc,"\f\n STOP");
while((!input(START1)) && (input(BUTTON2))); // cekame na tlacitko stop nebo na preruseni paprsku
time = 0;
set_timer0(0);
position = 0;
exception = 0;
 
while((position < 4) && (input(BUTTON2))) // cekame na tlacitko stop nebo na preruseni vsech paprsku
{
if(last!=(input=input_b())) // pri preruseni nektereho z paprsku zjistime ktery to byl
{
timer=get_timer0();
if(bit_test(last ^ input, position))section[position] = (time << 16) + timer; // kontroluje, jestli jsou paprsky preruseny ve spravnem poradi.
else exception=INORDER;
time=0;
set_timer0(0);
position++;
}
last=input_b();
}
if (exception == INORDER)
{
printf(lcd_putc,"\fInorder! Send?");
lcd_gotoxy(1,2);
printf(lcd_putc,"YES NO");
While(input(BUTTON1) && input(BUTTON4));
if(!input(BUTTON1)) send_measuring();
if(!input(BUTTON4)) continue;
}
else send_measuring();
while((input(STOP1)) && (input(BUTTON2)))
section[0] = (time << 16) + get_timer0();
send_measuring();
}
}