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.

use 89c51 microcontroller to design 6 or 9 digit counter

Status
Not open for further replies.

adnanmehfooz

Newbie level 4
Joined
May 13, 2010
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,323
any body plz help me to design 6 or 9 digit bcd counter that will only count up ward. i design this counter by using flip flops but nw i want to design it by using micro controller.
 

allot 6(or9 ) bcd locations in internal data ram.

when u want to count up,
increment the lsd first .
based on carry (bcd carry) ripple through all higher bcd digits .

update the dataram .
display the contents of these digits.

srizbf
13thmay2010
 

WHAT IS THE ERROR IN THIS CODE.
Code:
//C  Program://

#include <AT89X52.H>
unsigned char code dispbit[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
unsigned char code dispcode[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x00,0x40};
unsigned char dispbuf[8]={0,0,0,0,0,0,10,10};
unsigned char temp[8];
unsigned char dispcount;
unsigned char T0count;
unsigned char timecount;
bit flag;
unsigned long x;

void main(void)
{
  unsigned char i;
  TMOD=0x15;
  TH0=0;
  TL0=0;
  TH1=(65536-4000)/256;
  TL1=(65536-4000)%256;
  TR1=1;
  TR0=1;
  ET0=1;
  ET1=1;
  EA=1;
 
  while(1)
   {
     if(flag==1)
       {
         flag=0;
         x=T0count*65536+TH0*256+TL0;
         for (i=0; i<8; i++)
           {
             temp[i]=0;
           }
         i=0;
         while(x/10)
           {
             temp[i]=x%10;
             x=x/10;
             i++;
           }
         temp[i]=x;
         for (i=0; i<6; i++)
           {
             dispbuf[i]=temp[i];
           }
         timecount=0;
         T0count=0;
         TH0=0;
         TL0=0;
         TR0=1;
       }
   }
} 

void t0(void) interrupt 1 using 0
{
  T0count++;
}

void t1(void) interrupt 3 using 0
{
  TH1=(65536-4000)/256;
  TL1=(65536-4000)%256;
  timecount++;
  if(timecount==250)
    {
      TR0=0;
      timecount=0;
      flag=1;
    }
  P0=dispcode[dispbuf[dispcount]];
  P2=dispbit[dispcount];
  dispcount++;
  if(dispcount==8)
    {
      dispcount=0;
    }
}
 

hi, i thing the problem is with your timer 0 interrupt. a high to low pulse at timer0 pin(port 3.4) will increment the TL0 register by one. only if the number pulses going to cross the maximum timer value you are going to get a interrupt, otherwise only same value will be displayed in your seven segment. change the counetr algorithm.

regards
kj
 

thanks brother

but plz explain your answer.how can i change my count algo.

best regards
adnan
 

connect your counter input to any of the external interupt 0(p3.2).


#include....

int counter;
.
.
.
.

void externalcount interrupt 0
{
counter++;
}

void init()
{

;enable external interupt

}
void main()
{

init()

while(1)
{
; convert the counter variable in to decimal 4 digit or 6 digit
; and display the same in seven segment through multiplexing


}
}



regards
kj
 

dear brother kj
i am totally new in programming so i cannot understand what are u saying plz explain it. if u have a complete programme plz upload .and thank u very much for ur time
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top