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.

Ready Steady GO!, a game for the Junebug in Swordfish BASIC

Status
Not open for further replies.

blueroomelectronics

Well-Known Member
It's a reaction time, the program is crude but runs fine. You'll need JUNEBUG.BAS (download from my site) and it uses the PICkit2 UART tool to display your results.

When LED 1 lights press button #1.
Your time was 0.835040 Seconds.
When LED 1 lights press button #1.
Your time was 0.166864 Seconds.
When LED 1 lights press button #1.
Too Slow, press RESET to try again.
When LED 1 lights press button #1.
Too Soon! You have to wait till LED #1 is lit.

Code:
{
*****************************************************************************
*  Name    : ReadySteadyGO.BAS                                              *
*  Author  : William Richardson                                             *
*  Notice  : Copyright (c) 2008 blueroomelectronics                         *
*          : All Rights Reserved                                            *
*  Date    : 3/3/2008                                                       *
*  Version : 0.9beta                                                        *
*  Notes   : LEDs 3,2,1 countdown, press button #1 as soon as LED 1 is lit 
*          : DIP Switch #4 must be on to see results using PICkit2 UART Tool                                                                   *
*****************************************************************************
}
Device = 18F1320
Clock = 8               // 8MHz clock

Include "junebug.bas"
Include "convert.bas"
Include "usart.bas"

Dim Qualify, Temp As Byte
Dim Time As string    ' total time in us

Interrupt ButtonPress()
    T0CON.7 = 0     ' stop the timer
    If Qualify = 0
        Then
        Write("Too Soon! You have to wait till LED #1 is lit.",13,10)
        LED(6)    
        Else
        temp = Tmr0l    ' loads TMR0H
        Time = dectostr(((tmr0H*256)+Temp)*16,6)
        Write("Your time was 0.",Time," Seconds.",13,10)
        LED(4)
    EndIf
    INTCON.4 = 0        '
    While true
    Wend
End Interrupt
OSCCON = $72            // 8 MHz clock
SetBaudrate(br9600)   
INTCON2.7 = 0       ' weak pullups on
INTCON.1 = 0        ' INT0IF
INTCON.4 = 1        ' INT0IE
INTCON2.6 =0        ' INTEDG0 falling edge trigger
ADCON1  = %11110101
    Write("When LED 1 lights press button #1.",13,10)    
    Qualify = 0
    T0CON = $04         ' 1/32 prescaler on timer 0, 16 bit mode
    TMR0L = 0           ' clear the timer
    TMR0H = 0
LED(3)                  ' Ready               
    DelayMS(1000)
    INTCON.1 = 0        ' clear the interrupt flag           
    Enable(ButtonPress)
LED(2)                  ' Steady
    DelayMS(500)
    Qualify = 1         ' don't disqualify yourself by pressing too early   
    T0CON.7 = 1         ' start the timer 
LED(1)                  ' GO
    DelayMS(1000)       ' 1 second timeout
    INTCON.4 = 0        ' too slow disable interrupt
LED(5)
    Write("Too Slow, press RESET to try again.",13,10)
While true
Wend
End
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top