Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Soccer Five - Electronic Director

Status
Not open for further replies.

Monkey

New Member
Hi all,
I want to share this old project that I did when I needed to replace the same discret circuit that was designed by a friend.

Background
I used to play Soccer Five with some friends, the rules are that each team is composed by five players, the match takes one hour, we play in a tennis court, we change the goalkeeper every 6 minutes so that we all can get fun...

The Electronic Director
The device whistles every 6 minutes, so that we change the goalkeepers.

The Circuit
This circuit design is trivial, I won't comment it.
It requires only 4 resistors, 3 caps, a LED, a NPN, a 4MHz quartz and a PIC16F84.

Code:
;
; soccerfive.asm -- a tool to play minisoccer
;
; ----- Reason for the project: minisoccer games last one hour,
;    every 6 minutes a break allows to replace the goalkeeper.
;    The minisoccer tool plays the kickoff as a long sound, 
;    then it playes two short sounds every 6 minutes and finally
;    it plays two short sounds and a long sound when the hour is off.
;

;
; baseed on example source code for picasm by Timo Rossi
;


;                                                                 +---O BUZZER O----o VDD 5 Volt
;  VDD 5 Volt     470 ohm                        1Kohm          | |
;    o------|>|--/\/\/\/\-----------------+  +-/\/\/\/\------+--|/  2N2222
;           LED          ________________ |  |      1Kohm    |  |\
;                       -| RA2      RA1 |-+  | gnd-/\/\/\/\--+    V
;                       -| RA3      RA0 |----+                    gnd
;   VDD 5 Volt          -| RA4          |---------------------+                              
;    o--/\/\/\/\--+------|              |--------------+-|<>|-+  4 MHz cristal               
;        1Kohm    |  gnd-|              |-o VDD 5 Volt |      |       
;                 |     -| RB0      Rb7 |-             |      |        
;                ---    -| RB1      RB6 |-            ---    ---             
;          10uF  ---    -| RB2      RB5 |-      22 pF ---    --- 22pF            
;                 |     -| RB3      RB4 |-             |      |           
;                gnd     ----------------             gnd    gnd             
;

;
; define PIC device type
;
    device    pic16f84

;
; define config fuses
;     *** Note that PWRT has inverted meaning in case of PIC16F84:
;        PWRT=on means NO PWRT
;

    config    CP=off,WDT=off,PWRT=on,OSC=xt

;
; include PIC register definitions, and some macros
;
    include "picreg.h"
    include "picmac.h"

;
; bit definitions for two outputs connected to port A bits 0 and 1
; a beeper is connected as bit 0 (pin 17) and a LED as bit 1 (pin 18)
; bit masks can be computed from bit numbers with the left shift operator.
;
; The LED     has the following way: 0 = LED  OFF, 1 = LED  ON
; The BEEPER     has the following way: 0 = BEEP OFF, 1 = BEEP ON
;
    
A_BEEPER    equ    0    ; bit 0
A_LED        equ    1    ; bit 1

; 
; Definitions for program constants
;
MINUTES        equ    6
TURNS        equ    10
IN_LOOPS    equ    183    ; timer for 60 secs.

;
; define some register file variables
;

    org    0x0c    ; This is the RAM base

delay_cnt1    ds    1
delay_cnt2    ds    1
delay_cnt3    ds    1
minutes_cnt    ds    1
turns_cnt    ds    1

;
; code start
;
    org    0

    movlw    0xff
    movwf    PORTA    ;initialize port A so that LEDs are off

    bsf    STATUS,RP0            ;register page 1
    movlw    ~((1<<A_BEEPER)|(1<<A_LED))    ;LED and BEEPER as outputs,
    movwf    TRISA                ;other PORTA pins as inputs
    bcf    STATUS,RP0            ;register page 0

    movlw    ((1<<A_BEEPER)|(1<<A_LED))    ; reset, three flashes of the LED and a long beep
    movwf    PORTA        ; send outputs to the port

    clrw            ; maximum delay (256 counts)
    call delay

    movlw    (1<<A_BEEPER)    ; LED OFF, BEEP ON
    movwf    PORTA

    clrw
    call delay

    movlw    ((1<<A_BEEPER)|(1<<A_LED))    ; LED ON, BEEP ON
    movwf    PORTA

    clrw
    call delay

    movlw    (1<<A_BEEPER)    ; LED OFF, BEEP ON
    movwf    PORTA

    clrw
    call delay

    movlw    ((1<<A_BEEPER)|(1<<A_LED))    ; LED ON, BEEP ON
    movwf    PORTA

    clrw
    call delay

;    clrw            ; LED OFF, BEEP OFF
    movwf    PORTA


; main loop runs 10 times
    movlw    TURNS
    movwf    turns_cnt

main_loop
    movlw    MINUTES        ; 6 minutes
    movwf    minutes_cnt

min_loop
    movlw    IN_LOOPS    ; loops for 60 secs.
    movwf    delay_cnt3    

    clrw
cnt3_loop
;    clrw
    call delay

    decfsz    delay_cnt3,F    ; decrease loop counter, has one minute expired?
    goto    cnt3_loop    ; no, wait again

; 
; One minute is expired, let's check if it's time to replace the goalkeeper
;
    decfsz    minutes_cnt,F    ; decrease minute counter, is time elapsed?
    goto    min_loop    ; no, wait another minute

end_min
    movlw    ((1<<A_BEEPER)|(1<<A_LED))    ; two flashes of the LED and a two beeps
    movwf    PORTA        ; send outputs to the port

    clrw            ; maximum delay (256 counts)
    call delay

;    clrw            ; LED OFF, BEEP OFF
    movwf    PORTA

;    clrw
    call delay

    movlw    ((1<<A_BEEPER)|(1<<A_LED))    ; LED ON, BEEP ON
    movwf    PORTA

    clrw
    call delay

;    clrw            ; LED OFF, BEEP OFF
    movwf    PORTA

;    clrw
    call delay

; 
; Minutes are expired, it's time to check about turns
;
    decfsz    turns_cnt,F    ; decrease turn counter, is turns=0?
    goto    main_loop

end_loop
    movlw    ((1<<A_BEEPER)|(1<<A_LED))    ; LED ON, BEEP ON
    movwf    PORTA

    clrw
    call delay

;    clrw
    call delay

;    clrw
    call delay

;    clrw            ; LED OFF, BEEP OFF
    movwf    PORTA
    
stop    goto    stop


;
; delay subroutine
; input: delay count in W
;
; inner loop duration approx:
; 5*256+3 = 1283 cycles ->
; 1.28ms with 4MHz crystal (1MHz instruction time)
;
delay    movwf    delay_cnt1
    clrf    delay_cnt2
delay_a    nop
    nop
    incfsz    delay_cnt2,F
    goto    delay_a
    decfsz    delay_cnt1,F
    goto    delay_a
    return

    end

hex file, to be loaded with a PIC programmer
Code:
:10000000FF3085008316FC308500831203308500A5
:1000100000013D200130850000013D2003308500B6
:1000200000013D200130850000013D2003308500A6
:1000300000013D2085000A30900006308F00B73067
:100040008E0000013D208E0B22288F0B1F280330CD
:10005000850000013D2085003D2003308500000122
:100060003D2085003D20900B1D28033085000001B8
:100070003D203D203D2085003C288C008D01000066
:0C00800000008D0F3F288C0B3F2808006B
:02400E00F93F78
:00000001FF
 
Be better with the source code!

Code:
; Generated by WinPicProg 1.95e, (c) Nigel Goodwin Apr 2005.

            LIST      P=16F84, F=INHX8M
            include "P16F84.inc"
            __CONFIG 0x3FF9

; Variable definitions

            ORG     0x0000

            MOVLW   0xFF
            MOVWF   PORTA
            BSF     STATUS    , RP0
            MOVLW   0xFC
            MOVWF   TRISA
            BCF     STATUS    , RP0
            MOVLW   0x03
            MOVWF   PORTA
            CLRW
            CALL    Label_0001
            MOVLW   0x01
            MOVWF   PORTA
            CLRW
            CALL    Label_0001
            MOVLW   0x03
            MOVWF   PORTA
            CLRW
            CALL    Label_0001
            MOVLW   0x01
            MOVWF   PORTA
            CLRW
            CALL    Label_0001
            MOVLW   0x03
            MOVWF   PORTA
            CLRW
            CALL    Label_0001
            MOVWF   PORTA
            MOVLW   0x0A
            MOVWF   0x10
Label_0004  MOVLW   0x06
            MOVWF   0x0F
Label_0003  MOVLW   0xB7
            MOVWF   0x0E
            CLRW
Label_0002  CALL    Label_0001
            DECFSZ  0x0E      , f
            GOTO    Label_0002
            DECFSZ  0x0F      , f
            GOTO    Label_0003
            MOVLW   0x03
            MOVWF   PORTA
            CLRW
            CALL    Label_0001
            MOVWF   PORTA
            CALL    Label_0001
            MOVLW   0x03
            MOVWF   PORTA
            CLRW
            CALL    Label_0001
            MOVWF   PORTA
            CALL    Label_0001
            DECFSZ  0x10      , f
            GOTO    Label_0004
            MOVLW   0x03
            MOVWF   PORTA
            CLRW
            CALL    Label_0001
            CALL    Label_0001
            CALL    Label_0001
            MOVWF   PORTA
Label_0005  GOTO    Label_0005
Label_0001  MOVWF   0x0C
            CLRF    0x0D
Label_0006  NOP
            NOP
            INCFSZ  0x0D      , f
            GOTO    Label_0006
            DECFSZ  0x0C      , f
            GOTO    Label_0006
            RETURN
 
 

            END
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top