Searching \ for '[PIC]: Help with 7 seg counter' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/time.htm?key=count
Search entire site for: 'Help with 7 seg counter'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: Help with 7 seg counter'
2001\11\19@224331 by cdb

flavicon
face
I thought I'd try 7 seg Leds instead of LCD's and run into a problem which
must be simple as I can' t solve it.

I need a pointer? in the right direction.

I can multiplex the LEDs no problem I just can't get a simple test counter
variable to update no matter where I bung it :). Though it will display a
static value.

The code I have is as follows - all variables are global at the moment as my
simulator doesn't show local ones in an easy to see manner. The counter
(dec) gets reset to zero after the first pass to display its contents.

Any help appreciated.

Colin

void main()
{
setup();
while(1)
  {
   // dec=1657;  //test static works!
   if (IntFlag)
   {
     IntFlag=0;
     DoInt();
  }
//   dec++;  //number to count from 0 to max count for display
    //  if(dec>=MAX_DIGIT+1) {dec=0;}
  }
}

void setup()
{
#ifdef 16F628
//turn comparator off
#endif
PORTB=0;
TRISB=0;
PORTA=0;
TRISA=0;
OPTION_REG=207;
TMR0=0;
INTCON |=(1<<GIE) |(1<<T0IE);
}

void DoInt()
{
convert_digit(dec);
display();
}

const int QuickInt=1;

void Interrupt()
{
 if (INTCON& (1<<T0IF))
 {
    (INTCON&=~(1<<T0IF));
    IntFlag=1;
}
}


unsigned int dec_bcd(unsigned int digit)
{
 unsigned int const power_10[4]={1,10,100,1000};  // Mr P. Andersons
routine
 return power_10[digit];
}

void convert_digit(unsigned int number)
{
   for (digit=0; digit<MAX_DIGIT; digit++)
    {
      x=dec_bcd((MAX_DIGIT-1)- digit);
      Disp_Seg[((MAX_DIGIT-1)-digit)]= segments[dec/x];
      dec=dec% x;
    }
}

void display()
{
PORTA=0;            //blank digits
if (disp==MAX_DIGIT)
{
   disp=0;
  PORTA=disp;
}
PORTB=Disp_Seg[disp];
PORTA=1<<disp;
disp++;
}

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2001\11\21@044139 by cdb

flavicon
face
Can anyone help me with this post from yesterday. Its driving me batty.

colin

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email spam_OUTlistservTakeThisOuTspammitvma.mit.edu with SET PICList DIGEST in the body


2001\11\21@134953 by Barry Gershenfeld

picon face
Are you saying it goes to zero and stays there?

leave the increment line in but take out the line about
 //  if(dec>=MAX_DIGIT+1) {dec=0;}
and see if it works then.  If so there's something
funny about that line.  If not, look elsewhere.

Also, sometimes the processor resets continuously (watchdog or
transient) but looks like it's working...after all, it
runs properly for a short time before starting over.

Barry


>Can anyone help me with this post from yesterday. Its driving me batty.
>
>colin

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email .....listservKILLspamspam@spam@mitvma.mit.edu with SET PICList DIGEST in the body


2001\11\21@215405 by cdb

flavicon
face
Yep when the display function returns to Main dec returns to zero and stays
there. That particular line you mention is not used commented out. Its sole
purpose was to make sure that the test counter never goes past the max
number for the 4 digits ei: 9999 for a 4 digit disp. I know in the code I
posted it doesn't do that but as I said its not operational at the moment.

I'm going to experiment with pointers (shudder) see if that makes a
difference.

thanks
Colin

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email listservspamKILLspammitvma.mit.edu with SET PICList DIGEST in the body


2001\11\21@221802 by Barry Gershenfeld
picon face
I didn't look at your code closely to see where else the displayed
number would change so I was just suggesting you put the increment
back in but not the set-to-zero.   But you said "dec" wouldn't ever
get off zero.   Now that I think about it you are probably expecting
a function to change it for you, and it should, if the variable
is global.  At least maybe declare it ahead of everything else.

Pointers?  Been through the horrors.  So bring on the
confusion...

Good luck,

Barry




At 12:51 PM 11/22/01 +1000, you wrote:
{Quote hidden}

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email .....listservKILLspamspam.....mitvma.mit.edu with SET PICList DIGEST in the body


More... (looser matching)
- Last day of these posts
- In 2001 , 2002 only
- Today
- New search...