The Philippine Electronics and Technology Forum
February 10, 2012, 09:49:09 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Search Login Register  

Pages: [1]   Go Down
  Print  
Author Topic: Program for shot clock and score for zilog score board  (Read 1586 times)
sphinxnator_15
CR2032 Battery
**

Pogi/Ganda Points: 1
Offline Offline

Posts: 27


« on: March 29, 2008, 02:42:36 PM »

Good day to all... Mam and sir how we will fix this program...
Our project is all about wireless score board and shot clock using zilog... We have a receiver of remote control we bought from qizmo and a receiver kit using also a smaller version of zilog... we connected this receiver as input of seven segment driver which is compose of only 7447 for each segment...
This is our program for score
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include<ez8.h>

void main (void)
{
PADD=0x00;
PAAF=0x00;
PAOC=0x00;
PAHDE=0x00;
PCDD=0xFF;
PCAF=0x00;

PAOUT = 0x00;

if (PCIN == 0x01)
     {
      PAOUT+=0x01;
     }
else if (PCIN == 0x02)
     {
     PAOUT+=0x02;
     }
else if (PCIN == 0x04)
     {
     PAOUT+=0x03;
     }
else if (PCIN == 0x08)
     {
     PAOUT-=0x01;
      }
}
// The problem in our program is, as the remote is pressed it continue incrementing...
We have arrived in a conclusion that the function must add only after the button is unpressed (debouncing) but we don't how to do it....



     
Logged
The Philippine Electronics and Technology Forum
« on: March 29, 2008, 02:42:36 PM »

 Logged
Mentor Lee
Size C Battery
*****

Pogi/Ganda Points: 16
Offline Offline

Gender: Male
Posts: 193


"Call to Me and I will answer you.....


« Reply #1 on: March 29, 2008, 03:21:11 PM »

Ang dami mong if..else. bakit hindi switch statement and gamitin mo? Anyways, ilan ang buttons na kailangan mo. This code fragment is for two buttons only and the buttons are active low (ie pullup resistor keeps the pin high and the push of the button gives a low signal). I will not use structure/union to make it simple but you can actually use just a byte to represent 8 button states. I will assume the buttons are connected to pins 1 & 2 ( I don't know encore! MCU).
Code:
#define pin1   
#define pin2
/* Button Variables */

char isBtn1, isBtn2;   // these variables need to be global you just apply optimization to save RAM if required


/*************Button Routine**********************/
char buttonPress (void)
{ char retVal;
 // check btn1 is pressed
  if  (!pin1) delay_ms(10) ;  // delay for debouncing depends on the buttons/switches
  if (!pin1) isBtn1 = 1 else   // check again the state after the debounce period, if still true , save state
  isBtn1 = 0;                    // or maybe it was just noise so reset the button state
  if (!pin2) delay_ms(10)     // check the next button...pressed?  if yes, debounce
  if (!pin2) isBtn2 = 1 else        // verify if indeed pressed then save state
  isBtn2 = 0;                     // same as above
// now you have to check for the button release
  if ((pin1) && (isBtn1)) {retVal = 1;} else  // means button 1 has a valid stroke
  if ((pin2) && (isBtn2)) {retval = 2;} else  // means button 2 has  a valid stroke
   retVal = 0;                                       // no button pressed & released

  return retVal;

}

More on the code above:
You must implement the delay routine (delay_ms(x)) and if the button is still bouncing you have to add more delay time . But for the small OMRON type buttons, 5ms is ok. I have used this routines many times without problem. But remember, this requires polling the port (regular call interval) . But you may use a timer to regularly poll the pins/button state to have less overhead on the code. You must also define pin1 & pin2 properly ( i used default definition).


 
Logged

...and show you great and inscrutable things that you do not know "
--Hotline 333--
paranz
Moderator
Nuclear Reactor
*****

Pogi/Ganda Points: 167
Offline Offline

Gender: Male
Posts: 4511


1/4W resistor specialist


« Reply #2 on: March 29, 2008, 08:07:15 PM »

@sphinx

yan lang po ba ang whole code ?

kindly include all the codes as well as a more description ng hardware
Logged
RRcom
CR2032 Battery
**

Pogi/Ganda Points: 3
Offline Offline

Posts: 45



« Reply #3 on: March 30, 2008, 03:15:46 AM »

tama nga yung paglalagay ng time delay
at eto pa pwede karing maglagay ng loop code sa huli
ex. nag press ka ng button 1 at syempre na proccess na yung  program para sa button 1 pero nakadiin ka parin sa button 1 maglagay ka ng while(button_1); at mag lolock na yun hangat di mo binibitiwan ang buton di sya makakawala sa loop, at pag nabitiwan mona makakawala na sya at pwede nang ma read ang next instruction.
Logged

Made in Calamba City
Born2BeWired
Technical People
Lead Acid Battery
*****

Pogi/Ganda Points: 149
Offline Offline

Gender: Male
Posts: 798


Analog and Precision Circuits Junkie


WWW
« Reply #4 on: March 30, 2008, 08:00:05 AM »

As Uncle Ho and RRcom correctly pointed out, your program must wait for the key (just counted in) to be released before making any move to read it again (software one shot). Try this simple modification on your code for a quick check:

Code:
#include<ez8.h>

void main (void)
{
unsigned char oldPCIN;

PADD=0x00;
PAAF=0x00;
PAOC=0x00;
PAHDE=0x00;
PCDD=0xFF;
PCAF=0x00;

PAOUT = 0x00;

while(1)
    {

        if(PCIN == 0x01) PAOUT+=0x01;

        if(PCIN == 0x02) PAOUT+=0x02;

        if(PCIN == 0x04) PAOUT+=0x03;

        if(PCIN == 0x08) PAOUT-=0x01;

        oldPCIN=PCIN;        // copy current key port value

        while(PCIN==oldPCIN);        // wait until key is released or key port value changed

    }
}

Notes:

1. I did not include a keyboard debounce routine since you are using a IR decoder as your input. I assume the IR decoder circuit already took care of this. Uncle Ho routine took care of everything.

2. I still do my programming in assembly, and I am not particularly good at C.  Grin

Logged

Electronics <- Once you got a taste of it, you will never get enough.

Insanity <- Doing the same thing, expecting different results.

Arrogance is directly proportional to Ignorance.
janbobis
CR2032 Battery
**

Pogi/Ganda Points: 3
Offline Offline

Gender: Male
Posts: 32


It's hard to bring good men down


« Reply #5 on: April 14, 2008, 12:35:17 PM »

I think it would  be better to clarify your problem. medyo mlabo kc eh.. some thought na wireless ang scoring as in kpag may naka shoot eh automatic scoring.. S tingin ko ur project is a simple scoreboard done wirelessly tama ba?

The actual solution to your problem, as suggested by two members here is to use a debounce algo...

example:
Create a variable (integer or boolean)... its up to you...
kpag nag napress ung switch, magtsi-change ng state ung variable (say, from 0 to 1).
While pressed ung switch, lging nka 1 ung variable. kpag na release na, magtsi-change state ulit ung variable (say, 2 na ang value nya)

then gwa ka ng checker if 2 n ung value ng variable then that's the time to branch into something
Logged

//-------------------------------------------------//
//---- it's hard to bring good men down -----//
//-------------------------------------------------//
The Philippine Electronics and Technology Forum
   

 Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  


Related Topics
Subject Started by Replies Views Last post
HU KNOWS DA COMPLETE INFO OF WIRELESS SCORE BOARD>>>??
Cellular Telephony
arkiose99 5 1234 Last post March 05, 2009, 10:24:21 PM
by elgie
HELP: clock program
General Electronics and Technology Discussion
balingkit08 1 401 Last post September 02, 2010, 11:16:05 AM
by dimps
score board
General Digital Design
-Al- 2 594 Last post August 23, 2010, 08:59:50 PM
by ultrasonic™
shot clock program using c++ tulong!!!
COE Students
neon11 1 536 Last post March 08, 2010, 11:13:36 AM
by mini_mouse ^_^
24 second shot clock
General Digital Design
bluegirl 0 368 Last post March 04, 2010, 05:41:19 PM
by bluegirl
24 sec shot clock..
PIC Microcontrollers
transistorized 8 279 Last post December 09, 2010, 11:19:33 PM
by Kaizer03
24 shot clock counter
General Digital Design
jkent_reynes 13 512 Last post December 14, 2010, 06:30:15 PM
by zer0w1ng
Powered by MySQL Powered by PHP Powered by SMF 1.1.15 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!