/* FLASH.C - LED Flasher for Phytecs Rapid Development Kits */ #include #include /* include 8051 header file */ sfr CKCON = 0x8E; // clock control register 80c320 void V24OutB0 (char); char V24InB (void); void V24OutW(int val); #define WORD unsigned int void V24Init (void); sbit lichtschranke1 = P1^1; sbit lichtschranke2 = P1^2; /* sbit test = P1^3; char rennfreigabe,rennenaktiv1,rennenaktiv2; int counter1,counter2; int ls1counter,ls2counter; // Für Genauigkeit beim Fahren in die Lichtschranke void timerstart0(WORD wert) { TH0=wert >> 8; TL0=wert & 0xff; TMOD=((TMOD & 0xf1) | 0x01); ET0=1; TR0=1; } void timerstart1(WORD wert) { TH1=wert >> 8; TL1=wert & 0xff; TMOD=(( TMOD & 0x1f) | 0x10); ET1=1; TR1=1; } void zeitsenden (int counter,char nr){ char hi, lo; hi = (char)counter>>8; lo = (char)counter; V24OutB0(nr); V24OutB0(hi); V24OutB0(lo); } void timerintfkt () interrupt 3 { timerstart1(15535); // timerregister neu laden /*if (test) test=0; else test=1; */ if (ls1counter>0) ls1counter--; if (ls2counter>0) ls2counter--; if (rennfreigabe == 1) { if (rennenaktiv1 == 1) { counter1 ++; } if (rennenaktiv2 == 1) { counter2 ++; } if (ls1counter==0 && lichtschranke1 == 0) { // fahrer in LS if (rennenaktiv1 == 0){ rennenaktiv1 = 1; ls1counter=300; } else { rennenaktiv1 = 0; ls1counter=300; printf("1,%u\n",counter1); } } if (ls2counter==0 && lichtschranke2 == 0) { if (rennenaktiv2 == 0){ rennenaktiv2 = 1; ls2counter=300; } else { rennenaktiv2 = 0; ls2counter=300; printf("2,%u\n",counter2); } } } } void rennenstart () { rennfreigabe = 1; counter1 = 0; counter2 = 0; ls1counter = 0; ls2counter = 0; rennenaktiv1 = 0; rennenaktiv2 = 0; } void rennenstop () { rennfreigabe = 0; V24OutW (counter1); V24OutW (counter2); printf("Rennen gestoppt\n"); printf("%u\n%u\n",counter1,counter2); } /* void T1Run(unsigned int wert){ // starte timer 1 TH1=wert >> 8; TL1=wert & 0xff; // mode1, 16 bit timer TMOD=((TMOD & 0x1f) | 0x10); // xxxx 0001 ET1=1; // enable timer0_interr. TR1=1; // turn control on } void Timer1(void) interrupt 3 { // interruptservice timer1 T1Run(15535); // 50000inc/5MHz if (test) test=0; else test=1; } */ void main () { char command; //Variable für Befehle von PC lichtschranke1=lichtschranke2=1; timerstart1(15535); //ist für Hundert Hz CKCON=0xFF; // timerbetriebsmodus setzen V24Init(); //Initialisierung der Schnittstelle EA=1; // enable all interrupts printf("Hallo"); while(1) { command = V24InB (); switch (command){ //f = Kommando Freigabe,oder Reset case 'f': rennenstart(); printf("Rennen gestartet\n"); break; case 's': rennenstop(); //s = Stop break; } } } -------------------------------------------------------------------------------------------------------------------- .../*char V24InB(void){ char ic; while (!RI) // Wait here for received character ; ic = SBUF0; RI=0; // Get ready for next character if (ic != CNTLQ && ic != CNTLS) return (ic); // return new character return(0); } void V24OutB0(char b){ SBUF0=b; // Copy char to SBUF while (!TI) // Wait here until TI bit set ; TI=0; // Get ready for next character } void V24OutW(int val){ SBUF0=val; // Copy hi order byte to SBUF while (!TI) // Wait here until TI bit set ; TI=0; // Get ready for next character SBUF0=val>>8; // Copy low byte to SBUF while (!TI) // Wait here until TI bit set ; TI=0; // Get ready for next character } /* void V24OutB1(char b){ SBUF1=b; // Copy char to SBUF1 while (!TI1) // Wait here until TI bit set ; TI1=0; // Get ready for next character } */ /* void V24OutS(char no,char *s){ if (!no) while (*s) { V24OutB0(*s); s++; } else while (*s) { V24OutB1(*s); s++; } } */...