Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

24 second shotclock timer for basketball using C compiler

Status
Not open for further replies.

clarence501

Junior Member level 3
Joined
Jan 24, 2011
Messages
26
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Philippines
Activity points
1,463
Hey Guys, I really need your professional help right now. I'm making this 24 second shotclock timer for my project.
I have been able to make the source code for setting the 24 shot clock, using interrupt. But I'm stuck on how to do the timing. What I want to do is to set the shot clock either from 0-24 value and then when i switch RB4 == 1 and press the interrupt RB0 again, it will start counting on the current set value. I don't know how to do that yet. Can you guys give me some professional Help? This is the ISIS circuit model :**broken link removed**

Here is my source code:

Code:
#include <pic.h>
int num = 0;

void initialize(void);
void timing(void);
void do_outputs(void);

void main(void)
{
	initialize();
	while(1)
	{
		do_outputs();
		timing();
	}

}
void initialize(void)
{
	PORTC = 0x40;
	PORTD = 0x40;
	TRISC = 0x00;
	TRISD = 0x00;
	INTEDG = 0;
	GIE = 1;
	INTE = 1;
}

void timing(void)
{

}

void do_outputs(void)
{
	GIE = 0;
	if (INTF)
	{
		INTF = 0;
			if((RB2==1) && (RB4==0))
				{num++;}
			if((RB2==0) && (RB4==0))
				{num--;}
			{
					if(num==-1)
					{
					num=24;
					PORTC = 0x10;
					PORTD = 0x40;
					}
					if(num==0)
					{
					PORTC = 0x40;
					PORTD = 0x40;
					}
					if(num==1)
					{
					PORTC = 0x79;
					PORTD = 0x40;
					}
					if(num==2)
					{
					PORTC = 0x24;
					PORTD = 0x40;
					}
					if(num==3)
					{
					PORTC = 0x30;
					PORTD = 0x40;
					}
					if(num==4)
					{
					PORTC = 0x19;
					PORTD = 0x40;
					}
					if(num==5)
					{
					PORTC = 0x12;
					PORTD = 0x40;
					}
					if(num==6)
					{
					PORTC = 0x02;
					PORTD = 0x40;
					}
					if(num==7)
					{
					PORTC = 0x78;
					PORTD = 0x40;
					}
					if(num==8)
					{
					PORTC = 0x00;
					PORTD = 0x40;
					}
					if(num==9)
					{
					PORTC = 0x10;
					PORTD = 0x40;
					}
					if(num==10)
					{
					PORTC = 0x40;
					PORTD = 0x79;
					}
					if(num==11)
					{
					PORTC = 0x79;
					PORTD = 0x79;
					}
					if(num==12)
					{
					PORTC = 0x24;
					PORTD = 0x79;
					}
					if(num==13)
					{
					PORTC = 0x30;
					PORTD = 0x79;
					}
					if(num==14)
					{
					PORTC = 0x19;
					PORTD = 0x79;
					}
					if(num==15)
					{
					PORTC = 0x12;
					PORTD = 0x79;
					}
					if(num==16)
					{
					PORTC = 0x02;
					PORTD = 0x79;
					}
					if(num==17)
					{
					PORTC = 0x78;
					PORTD = 0x79;
					}
					if(num==18)
					{
					PORTC = 0x00;
					PORTD = 0x79;
					}
					if(num==19)
					{
					PORTC = 0x10;
					PORTD = 0x79;
					}
					if(num==20)
					{
					PORTC = 0x40;
					PORTD = 0x24;
					}
					if(num==21)
					{
					PORTC = 0x79;
					PORTD = 0x24;
					}
					if(num==22)
					{
					PORTC = 0x24;
					PORTD = 0x24;
					}
					if(num==23)
					{
					PORTC = 0x30;
					PORTD = 0x24;
					}
					if(num==24)
					{
					PORTC = 0x19;
					PORTD = 0x24;
					}
					if(num==25)
					{
					PORTC = 0x40;
					PORTD = 0x40;
					num = 0;
					}
				}
				GIE =1;
		}
}
 
Last edited by a moderator:

You can use two buttons. One to set timer value and another to start timer after set. Write a 500 ms Interrupt code. For every two interrupts time is 1 sec. Decrement the counter which holds set time on every two interrupts. If this counter is 24 then on every 2 interrupts decrement this counter and when its value becomes 0, 24 sec has elapsed. It will be a countdown timer.

Try attached simulation.

96286d1379454346-shotclock.png
 

Attachments

  • shotClock.rar
    14.2 KB · Views: 94
  • shotClock.png
    shotClock.png
    35 KB · Views: 275
Last edited:

Hi Jayanth, I'm not quite sure I understood what you meant on this statement: "Write a 500 ms Interrupt code. For every two interrupts time is 1 sec. Decrement the counter which holds set time on every two interrupts[/I]". Are you using the interrupts on pins RB0, RB1, and RB2? What I know as of now is you can use interrupt on RB0. Also, what are the outputs in pins RB3 and RB4? I have tried the circuit, it's working except it malfunctions when clear is triggered. Thank you for sharing your idea by the way. But still, I wand to understand how that worked.
 

Wait I will post the code. I didn't use interrupts for the buttons. I used interrupt for time and display.

Write a 500 ms Interrupt code. For every two interrupts time is 1 sec. Decrement the counter which holds set time on every two interrupts.

That is for generating delay. If Timer is configured to generate 500 ms interrupt then 2 such interrupts make 1 sec and 48 such interrupts for 24 sec.

it's working except it malfunctions when clear is triggered.

Where is clear? You mean Reset? What happens exactly?
 

Okay, what code are you using? Is it still C? I only understand C language. Can you help me implementing the codes for timing after setting? Yup, the reset. When I click the reset button, the program no longer works, and i have to stop simulation and start again for it to start working again.
 

Here is the mikroC PRO PIC code. See if you can find any problem. Use cof file and debug in Proteus and see what is causing the problem. Test it in real hardware. Maybe it is Proteus problem and not code.



Edit: Fixed version attached.
 

Attachments

  • shotClock.rar
    74.2 KB · Views: 80
  • shotClock fixed.rar
    89.2 KB · Views: 153
Last edited:

I see, you are using MikroC. I'm using MPLAB IDE by the way. Is there a way to convert the codes from MikroC to MPLAB? Okay I'll try the hardware. I will be using Pic Kit 3 by the way.
 

I'm using the universal tool suite for C. You have ideas on how to convert that?
 

Never heard about Universal Tool suite. Provide the link for the Compiler.

Edit: Do you mean Hi-Tech Universal Toolsuite?

Try attached code.
 

Attachments

  • Hi-Tech PICC Code.rar
    15.7 KB · Views: 115
Last edited:

I have downloaded the file Jayanth. I will study the codes and do my best to understand them. I will get back to you when I have questions. Thank you for sharing.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top