
Forgive me readers, but this is a replica of the replica. It all began with an interesting
article , where the author introduced us to his ATMega8 based development. Obviously, this stone is redundant for the task that was implemented on it, and the
opponent paid attention to it .
But now I have zasverbilo ... um, in the palms, and I could not help but try to insert my five kopecks. I understand that my real note is too big for a comment, but I don’t draw on a full article, but I’ll try.
')
Retelling the content of the previous series makes no sense, who cares - I gave the links. Let's go straight to the point.
The scheme on the relay, proposed by a respected author, caused me some semblance of a toothache. Perhaps because in my youth I had to deal with decadic-step and coordinate ATS, after which I hated the relay for the rest of my life. Yes, relay circuits are easy, yes, they will work even in a nuclear explosion, but ...
The first but - reliability
What do you think are the most unreliable components of electronic circuits? Perhaps I am mistaken, but in my experience these are mechanical contacts and electrolytic capacitors. Contacts burn, oxidize, capacitors dry. And here the whole circuit consists of contacts and capacitors. In addition, in this circuit, polar capacitors are connected in parallel to the windings of the relay, and as a result, when the EMF is broken, self-induction closes through what? - correctly - through a capacitor, which in this case will work with such a poor diode. And that turns out to be connected in reverse polarity. I do not think that it will benefit the so not very reliable component.
The second but the cost
How much does one relay cost? Looking for "Ali", I did not find anything decent cheaper than one American dollar. Okay, even if I do not know how to search, take the price of 50 cents. Four relays (after all, in the original scheme, four channels) - already two bucks. It turns out only one relay will cost more than the entire bundle of options on the microcontroller, including the microcontroller itself. And if in that scheme there is still more extra details ...
Third but extensibility
But tell me: what will we do with this scheme if we need to introduce additional functionality into the product? No, I do not ask to play military marches, but at least squeak a buzzer after the expiration of the time that is given to the player to answer?
Voooot ...
Okay, that was a saying. And now to the point. See the diagram. I quote: "soldering was faster than drawing."

One shareware chip, three resistors, three capacitors. Piezopischalka. And that's all. It is possible to feed this economy from three elements AA. Without any stabilizers. At rest, it consumes less microampere (power down mode) - you can refuse the switch - another hateful contact.
The AVR AT90S1200 controller is not because it’s good for something, I just have one polvedra left after one of the ancient projects, and since it’s been out of production for a long time now I’m not going to stick it anywhere. Only in some home-made. Therefore, shareware. But, as the author of the
first article correctly noted, anyone will do here.
Now about the program. Since there is no RAM in this controller (from the word in general), and the hardware stack is only three-level, there are no high-level languages. Only Assembler, only hardcore ...
Put the button on the interrupt also does not work. There is only one external interrupt, and there are six connoisseurs at the table. Well, we will poll in a loop. And to interview all at the same time, so that there is no advantage to one player. The polling cycle time at a clock frequency of 1 MHz is 6 μs, that is, we catch the difference between the presses of 6 μs. If two players press the button at the same time, then all of a sudden, you never know, two LEDs will be illuminated. All honest. Although, I think the probability of such an event will be very low. But still, if the accuracy of determining the leader in 6µs is not enough - you can connect quartz, flash the fusion and start the controller at a frequency of 12 MHz. In this case, the polling rate will increase 12 times. Your KO
Contact bounce does not affect anything, since we react to the very first level drop seen. This is followed by the processing of pressing, and what is already going on there on the button - we do not care.

I agree, different buttons with different time and bounce character can give someone an advantage in a microsecond or two, but, in my opinion, this is catching fleas.
Actually code;---------------------------------------------------------------------------- ;¦ Title : . ;¦ Version : 0.0 ;¦ ;¦ Last updated : 16.01.16 ;¦ Target : AT90S1200 1MHz ( RC-) ;+--------------------------------------------------------------------------- .include "1200def.inc" ;¦ ;+--------------------------------------------------------------------------- .def acc = r20 ; .def temp1 = r21 ; .def temp2 = r22 ; .def temp3 = r23 ; .def temp4 = r24 ; .def temp5 = r25 ; .def temp6 = r26 ; .def temp7 = r27 ; ;¦ ;+--------------------------------------------------------------------------- .equ ini_b = 0b00111111 ; PORTB .equ dir_b = 0b11111111 ; 1-out 0-in ; ¦¦¦¦¦¦¦¦ .equ led01 = 0 ;¦¦¦¦¦¦¦+-12(out) .equ led02 = 1 ;¦¦¦¦¦¦+--13(out) .equ led03 = 2 ;¦¦¦¦¦+---14(out) .equ led04 = 3 ;¦¦¦¦+----15(out) .equ led05 = 4 ;¦¦¦+-----16(out) .equ led06 = 5 ;¦¦+------17(out) (MOSI) .equ buzzer1 = 6 ;¦+-------18(out) (MISO) .equ buzzer2 = 7 ;+--------19(out) (SCK) .equ ini_d = 0b00111111 ; PORTD .equ dir_d = 0b01000000 ; 1-out 0-in ; ¦¦¦¦¦¦¦ .equ key01 = 0 ; ¦¦¦¦¦¦+--2 (in) .equ key02 = 1 ; ¦¦¦¦¦+---3 (in) .equ key03 = 2 ; ¦¦¦¦+----6 (in) (INT0) .equ key04 = 3 ; ¦¦¦+-----7 (in) .equ key05 = 4 ; ¦¦+------8 (in) .equ key06 = 5 ; ¦+-------9 (in) .equ pin11 = 6 ; +--------11(out) . ;¦ ;¦ ;+--------------------------------------------------------------------------- .include "mymacros.inc" .macro init_ports ldi acc,dir_b out DDRB,acc ; B / ldi acc,ini_b out PORTB,acc ; ldi acc,dir_d out DDRD,acc ; D / ldi acc,ini_d out PORTD,acc ; .endmacro .macro init_wd wdr ; reset watchdog timer ldi acc,0b00001111 ; watchdog , . - 2048 out WDTCR,acc .endmacro .macro init_irq ; acc ldi acc,(1<<se)+(1<<sm)+(0<<isc01)+(0<<isc00) ; ¦ ¦ ¦ ¦ ; ¦ ¦ +----------+-- : "00" - ; ¦ +--------------------- 0-idle mode 1-power down ; +----------------------------- 1-sleep out MCUCR,acc ; ldi acc,(1<<int0) ; out GIMSK,acc ; INT0 clr acc out GIMSK,acc ; INT0 .endmacro .macro comparator_off ; acc ldi acc,(1<<ACD) out ACSR,acc ; .endmacro .macro speaker_up sbi PORTB,buzzer1 cbi PORTB,buzzer2 .endmacro .macro speaker_dn sbi PORTB,buzzer2 cbi PORTB,buzzer1 .endmacro ;---------------------------------------------------------------------------- ;¦ ;¦ ;¦ ;+--------------------------------------------------------------------------- .CSEG .org 0 rjmp start ; ;---------------------------------------------------------------------------- ;¦ ;¦ ;¦ ;+--------------------------------------------------------------------------- ;¦ ;¦ ;¦ temp5,6,7 ;+--------------------------------------------------------------------------- .equ const10ms = 2500-2 .macro wait_ms ; 10 2550, ldi temp5,@0/10 rcall delay10N .endmacro .macro wait_s ; 1 255 ldi temp4,@0 lb1: ldi temp5,100 rcall delay10N dec temp4 brne PC-3 .endmacro delay10N: ; wdr ; 1 ldi temp6,low(const10ms) ; 1 ldi temp7,high(const10ms) ; 1 d10ms1: ; - 4 , 4 subi temp6,1 ; 1 sbci temp7,0 ; 1 brne d10ms1 ; 2 djnz temp5,delay10N ; ret ;¦ 2.5 ( 200) ;¦ ;¦ temp6,7 ;+--------------------------------------------------------------------------- .equ const200us = 49 .macro beep rcall snd .endmacro snd: ldi temp6,0 ; 256 snd1: speaker_up rcall delay200us speaker_dn rcall delay200us djnz temp6,snd1 ret delay200us: ; 3 () ldi temp7,const200us ; 1 del200: nop ; 1 djnz temp7,del200 ; 1+2 ret ; 4-1 ;---------------------------------------------------------------------------- ;¦ ;¦ ;¦ ;+--------------------------------------------------------------------------- start: init_ports init_irq ; sleep comparator_off waitloop: ; wdr in acc,PIND ori acc,0b11000000 ; . cpi acc,0xff breq waitloop ; out PORTB,acc ; , beep ; ; wait_s 10 ; N ; - beep wait_ms 100 ; N beep wait_ms 100 beep ldi acc,0xff out PORTB,acc ; sleep rjmp 0 ; . .exit ; -------------------------------------------------
Thanks for attention. If something is wrong - write in a personal, correct.