my boxing timer


Closed Thread
Results 1 to 8 of 8

Thread: my boxing timer

  1. #1
    Join Date
    Dec 2006
    Posts
    18

    Default my boxing timer

    This has been my first attempt at programing a micrcontroller or programming from that matter.I box so i made a boxing timer which times either a 3min round or a 2min round with a 1min rest. Buzzer to end and start round and two leds green and red to indicate round or rest. I though id post the code as im sure u experience ppl could show me a far easier way of acheiveing the same result with less code.
    'boxing timer attempt 1
    TRISB=0 'PORTB=OUTPUT
    TRISA=3 'PORTA12=INPUT

    B0 VAR BYTE 'SECONDS VARIABLE5
    start
    Low PORTB.1
    Low PORTB.2
    Pause 3000
    IF PORTA.1=0 Then loop1
    IF PORTA.1=1 Then loop2
    GoTo start '9


    lOOP1:
    For b0=0 TO 240
    IF PORTA.1=1 Then start

    IF B0=0 Then 'RING BELL 3SEC 16
    High PORTB.0
    EndIF
    IF B0=3 Then
    Low PORTB.0 'BELL END HEHE
    EndIF '20
    IF B0<170 Then 'TURN GREEN LIGHT ON18
    High PORTB.1
    EndIF
    IF B0>170 Then 'TURN GREEN LIGHT OF
    Low PORTB.1
    EndIF
    IF b0=169 Then
    High PORTB.0
    EndIF
    IF b0=170 Then
    FreqOut PORTB.1,10000,8
    EndIF
    IF B0>170 Then 'TURN RED LIGHT ON21
    High PORTB.2
    EndIF
    IF B0<170 Then 'TURN RED LIGHT OF
    Low PORTB.2
    EndIF

    IF B0=170 Then 'RING BELL END ROUNDHigh PORTB.0
    High PORTB.0
    EndIF
    IF B0=173 Then 'STOP BELL
    Low PORTB.0
    EndIF
    IF b0=220 Then
    FreqOut PORTB.2,10000,4
    EndIF
    IF b0=220 Then
    High PORTB.0 '40
    EndIF
    IF B0=223 Then
    Low PORTB.0
    EndIF
    IF b0=223 Then
    b0=0
    EndIF
    Pause 1000
    Next b0
    GoTo start


    lOOP2:
    For b0=0 TO 180
    IF PORTA.1=0 Then start

    IF B0=0 Then 'RING BELL 3SEC 16
    High PORTB.0
    EndIF
    IF B0=3 Then
    Low PORTB.0 'BELL END HEHE
    EndIF '60
    IF B0<110 Then 'TURN GREEN LIGHT ON18
    High PORTB.1
    EndIF
    IF B0>110 Then 'TURN GREEN LIGHT OF
    Low PORTB.1
    EndIF
    IF b0=109 Then
    High PORTB.0
    EndIF
    IF b0=110 Then
    Low PORTB.0
    FreqOut PORTB.1,10000,8
    EndIF
    IF B0>110 Then 'TURN RED LIGHT ON21
    High PORTB.2
    EndIF
    IF B0<110 Then 'TURN RED LIGHT OF
    Low PORTB.2
    EndIF
    IF B0=110 Then 'RING BELL END ROUND
    High PORTB.0
    EndIF
    IF B0=113 Then 'STOP BELL
    Low PORTB.0
    EndIF
    IF b0=160Then
    FreqOut PORTB.2,10000,4
    EndIF
    IF b0=160 Then
    High PORTB.0 '80
    EndIF
    IF B0=163 Then
    Low PORTB.0
    EndIF
    IF b0=163 Then
    b0=0
    EndIF
    Pause 1000
    Next b0
    GoTo start '90

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    made a boxing timer, times either a 3min round or a 2min round with a 1min rest. Buzzer to end and start round, two leds green and red to indicate round or rest. I though id post the code as im sure u experience ppl could show me a far easier way of acheiveing the same result with less code.
    'boxing timer attempt 1
    TRISB=0:trisa=3 'PORTB=OUTPUT, PORTA12=INPUT
    B0 VAR BYTE 'SECONDS VARIABLE5

    start:
    Low PORTB.1 : Low PORTB.2 : Pause 3000
    IF PORTA.1=0 Then loop1
    IF PORTA.1=1 Then loop2
    GoTo start '9

    lOOP1:
    For b0=0 TO 240 : IF PORTA.1=1 Then start
    select case b0
    case 0
    high portb.0
    case 3
    Low PORTB.0 'BELL END HEHE
    case is < 170
    High PORTB.1 : low portb.2
    case is > 170
    Low PORTB.1 : high portb.2
    case 169
    high portb.0
    case 170
    FreqOut PORTB.1,10000,8 : High PORTB.0
    case 173
    Low PORTB.0
    case 220
    FreqOut PORTB.2,10000,4 : High PORTB.0
    case 223
    Low PORTB.0 : b0=0
    end select
    Pause 1000 : goto bigfinish

    lOOP2:
    For b0=0 TO 180 : IF PORTA.1=0 Then start
    select case b0
    case 0
    high portb.0
    case 3
    low portb.0
    case is < 110
    high portb.1 : low portb.2
    case is > 110
    high lower portb.1 : high portb.2
    case 109
    high portb.0
    case 110
    Low PORTB.0 : FreqOut PORTB.1,10000,8: high PORTB.0
    case 113
    Low PORTB.0
    case 160
    FreqOut PORTB.2,10000,4:High PORTB.0 '80
    case 163
    Low PORTB.0:b0=0
    end select
    Pause 1000
    bigfinish:
    Next b0
    GoTo start


    There's a thousand different ways to do this. Whatever works for you...

  3. #3
    Join Date
    Dec 2006
    Posts
    18


    Did you find this post helpful? Yes | No

    Default

    Thanks for you rely skimask. You have saved me from a lot of "if endifs" on my next timer.

  4. #4
    Join Date
    Dec 2006
    Posts
    18


    Did you find this post helpful? Yes | No

    Default 16f628a problem

    My boxing timer has been working fine on a 16f84a. I have changed to a 16f628a and have had a headache ever since. Managed to sort most of the problems out. However both my green and red leds go on at the same time if my round switch is low. works fine when my round switch is high. so i cant switch between rounds. i have looked at the data manual and have found no reason for the porta bits to affect each other like this.
    Does any one have any ideas????

  5. #5
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by hoops2006 View Post
    My boxing timer has been working fine on a 16f84a. I have changed to a 16f628a and have had a headache ever since. Managed to sort most of the problems out. However both my green and red leds go on at the same time if my round switch is low. works fine when my round switch is high. so i cant switch between rounds. i have looked at the data manual and have found no reason for the porta bits to affect each other like this.
    Does any one have any ideas????
    ANSEL, CMCON, any of those applicable?

  6. #6
    Join Date
    Dec 2006
    Posts
    18


    Did you find this post helpful? Yes | No

    Default

    To try and fault find i have stuck leds on my outputs porta 0 1 2. And wrote a program to light them one at a time with a 1sec delay. Even this doesnt work. One of the leds doesnt light one stays on at half brightness and the other led does what it should. Can anyone see why this program isnt working.


    @ DEVICE pic16F628A, INTRC_OSC_NOCLKOUT
    ' System Clock Options
    @ DEVICE pic16F628A, WDT_ON
    ' Watchdog Timer
    @ DEVICE pic16F628A, PWRT_ON
    ' Power-On Timer
    @ DEVICE pic16F628A, MCLR_OFF
    ' Master Clear Options (Internal)
    @ DEVICE pic16F628A, BOD_ON
    ' Brown-Out Detect
    @ DEVICE pic16F628A, LVP_OFF
    ' Low-Voltage Programming
    @ DEVICE pic16F628A, CPD_ON
    ' Data Memory Code Protect
    @ DEVICE pic16F628A, PROTECT_ON
    ' Program Code Protection

    cmcon = 7

    DEFINE OSC 4

    TRISB= 00000000 'PORTB=OUTPUT
    TRISA= 00000000 'PORTA=output




    main:
    PORTA.0 = 1
    Pause 1000
    PORTA.0 = 0
    PORTA.1 = 1
    Pause 1000
    PORTA.1 = 0
    PORTA.2 = 1
    Pause 1000
    PORTA.2 = 0
    GoTo main
    End

  7. #7
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by hoops2006 View Post
    To try and fault find i have stuck leds on my outputs porta 0 1 2. And wrote a program to light them one at a time with a 1sec delay. Even this doesnt work. One of the leds doesnt light one stays on at half brightness and the other led does what it should. Can anyone see why this program isnt working.

    @ DEVICE pic16F628A, INTRC_OSC_NOCLKOUT
    @ DEVICE pic16F628A, WDT_ON
    @ DEVICE pic16F628A, PWRT_ON
    @ DEVICE pic16F628A, MCLR_OFF
    @ DEVICE pic16F628A, BOD_ON
    @ DEVICE pic16F628A, LVP_OFF
    @ DEVICE pic16F628A, CPD_ON
    @ DEVICE pic16F628A, PROTECT_ON
    DEFINE OSC 4
    cmcon=7:TRISB=0:TRISA= 0
    main:
    PORTA.0 = 1 : Pause 1000 : PORTA.0 = 0 : PORTA.1 = 1 : Pause 1000
    PORTA.1 = 0 : PORTA.2 = 1 : Pause 1000 : PORTA.2 = 0 : GoTo main
    End
    Got a pullup on MCLR? (i know you've got mclr_off)
    Try an external oscillator and switch your clock modes.
    Turn off your watchdog timer.
    Just ideas...

  8. #8
    Join Date
    Dec 2006
    Posts
    18


    Did you find this post helpful? Yes | No

    Default time display

    Finally got my boxing timer completed. Now i want to have a seven segemt display counting down the round and rest time. I have seen the schematics for multiplexing the displays, so no problems there. But as a complete proggraming novice with only one little project under my belt i havent a clue how to code it. Could any of you experience people give me a few pointers. Would be greatly appreciated.

Similar Threads

  1. Elapsed Timer Demo
    By Darrel Taylor in forum Code Examples
    Replies: 111
    Last Post: - 29th October 2012, 17:39
  2. High Resolution Timer & Speed Calculator
    By WOZZY-2010 in forum Code Examples
    Replies: 4
    Last Post: - 7th February 2010, 16:45
  3. Timer + rc5
    By naga in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 19th November 2009, 07:56
  4. Timer interrupt frequency
    By Samoele in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 17th January 2009, 23:49
  5. timer interupt help 16f73
    By EDWARD in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 3rd July 2005, 08:41

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts