Zdravím,
potřeboval bych pomoci s úkolem, nechci ho vypracovat, ale chci poradit jak na to.
Princip: Komponenty dle obrázku. Náhodně se rozsvítí jedna LED a úkolem hráče je stisknout příslušný přepínač dříve než LED zhasne. Na displeji 3x7 se zobrazuje skóre, pokud to hráč stihne zmáčknout včas = 1 bod, pokud neudělá nic = 0 bodů, pokud stiskne špatně = -1 bod.
Děkuji za případné rady.
Fórum › Assembler
Intel 8051 - Hra s mouchou

nahodis timer, rosvitis nahodne jednu ledku (treba po 500ms nebo i rychleji)
nahodis druhej timer (po cca 1ms) a testujes stisky tlacitek (mozna i celej port), zaroven je to dost rychle na obnovovani 7seg na tretim a casti 4. portu
v hlavnim programu pak jen kempis (a nebo tam muzes presunout to obnovovani displaye)
(nejnarocnejsi je asi udelat v assembleru ten generator nahody .. ale taky by to slo nejak zprasit - rotacni buffer par xoru, nandu, ... )
Zdravím, pokud pomůže, tak tady máš možný algoritmus (jak by se to asi řešilo v C - AVRGCC
int static bod = 0;
int diody[9] = { 0, 1, 2, 4, 8, 16, 32, 64, 128};
// PORTA... 7-seg (zobrazí výsledek)
// PORTB... tlačítka pro hru
// PORTC... diody pro hru (svítí v log. 0)
// čtení tlačítek pro HRU (bity 0-7)
// + ošetřené zákmity
unsigned char ctiTLAC_HRA() {
unsigned char a,b;
do {
a = (~PINB)&0b11111111;
_delay_ms(10);
b = (~PINB)&0b11111111;
}
while (a != b);
switch (a) {
case 0b00000001:
return '1';
case 0b00000010:
return '2';
case 0b00000100:
return '3';
case 0b00001000:
return '4';
case 0b00010000:
return '5';
case 0b00100000:
return '6';
case 0b01000000:
return '7';
case 0b10000000:
return '8';
default:
return '0';
}
}
unsigned char ctiDIODY_HRA() {
unsigned char a;
a = PINC;
switch (a) {
case 0b11111110:
return '1';
case 0b11111101:
return '2';
case 0b11111011:
return '3';
case 0b11110111:
return '4';
case 0b11101111:
return '5';
case 0b11011111:
return '6';
case 0b10111111:
return '7';
case 0b01111111:
return '8';
default:
return '0';
}
}
void vyhodnoceni() {
// algoritmus
/* 1. spustíš TIMER1 s příslušným nastavením
2. nahodíš náhodnou LED: PORTC = diody[rand()%8];
3. _delay_ms(1); spustíš TIMER2 s příslušným nastavením
4. if ((ctiDIODY_HRA() == ctiTLAC_HRA()) {
bod++;
}
else {
bod--;
}
5. PORTA = bod;
*/
}
int main() {
// výstup
DDRA = 255;
DDRC = 255;
while (1) {
vyhodnoceni();
}
return 0;
}

Přidej příspěvek
Toto téma je starší jak čtvrt roku – přidej svůj příspěvek jen tehdy, máš-li k tématu opravdu co říct!
Ano, opravdu chci reagovat → zobrazí formulář pro přidání příspěvku
×Vložení zdrojáku
×Vložení obrázku
×Vložení videa
Aktuálně jsou podporována videa ze serverů YouTube, Vimeo a Dailymotion.
×






























































Uživatelé prohlížející si toto vlákno
Uživatelé on-line: 0 registrovaných, 363 hostů
Podobná vlákna
Assembler > Intel 8051 — založil R_T
Programování intel 8051 — založil Klarushiik
Intel ISPC a C++ — založil lacika_dnb
CPU Intel Core2Duo — založil remmidemmi
Import csv - intel — založil Jan Cerny