PDA

View Full Version : my boxing timer



hoops2006
- 5th January 2007, 13:31
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

skimask
- 5th January 2007, 19:09
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...

hoops2006
- 5th January 2007, 21:26
Thanks for you rely skimask. You have saved me from a lot of "if endifs" on my next timer.

hoops2006
- 24th March 2007, 19:13
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????

skimask
- 25th March 2007, 04:20
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?

hoops2006
- 31st March 2007, 19:06
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

skimask
- 31st March 2007, 20:07
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...

hoops2006
- 29th September 2007, 19:07
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.