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.

The scheme of counting button clicks with the output of the number of clicks on the seven-segment indicator (up to 99 clicks)

Status
Not open for further replies.

microlab_rcr

Newbie
Joined
Apr 28, 2021
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
35
Hello, i have a problem with this task, i dont understand how to display numbers on a seven-segment indicator after 10. I understand that you need to quickly switch the state of the common anode of each indicator, but I can't imagine how to write it in the program, maybe you will give some advice. I attached the code mikroC and scheme from Proteus.
 

Attachments

  • counter.rar
    35.4 KB · Views: 112

Here's the c code from archive:
C:
/* The scheme of counting button clicks with the output of the number of clicks on the seven-segment indicator (up to 99 clicks) */

int count = 0; //counter
int razr;
bit oldstate; //button state
char seg[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; //7seg digits

void setup() // setip i/o
{
 TRISB = 0;
 TRISD.RD0 = 0;
 TRISD.RD1 = 0;
 TRISD.RD2 = 1;
 PORTD.RD0 = 0;
 PORTD.RD1 = 0;
 PORTB = 0;
}


void setMode(int c) //*
{
 if (c < 10)
 {
  delay_ms(20);
  PORTD.RD1 = 1;
  PORTB = seg[c%10];
 }
 if (c >= 10)
 {
  PORTD.RD0 = 1;
  PORTB = seg[(c/10)%10];
 }
}

void main()
{
 setup();
 while(1)
 {
  if (Button (&PORTD, 2, 5, 1))//Debouncing
  {
   oldstate = 1; //flag button state
  }
  if (oldstate && Button (&PORTD, 2, 5, 0))
  {
   count++;
   oldstate = 0;
  }
  if (count == 100)
  {
   count = 0;
  }
  setMode(count);
 }
}

Please don't presume that EDAboard users are working with Proteus, better post a schematic print.
 

Here's the c code from archive:
C:
/* The scheme of counting button clicks with the output of the number of clicks on the seven-segment indicator (up to 99 clicks) */

int count = 0; //counter
int razr;
bit oldstate; //button state
char seg[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; //7seg digits

void setup() // setip i/o
{
 TRISB = 0;
 TRISD.RD0 = 0;
 TRISD.RD1 = 0;
 TRISD.RD2 = 1;
 PORTD.RD0 = 0;
 PORTD.RD1 = 0;
 PORTB = 0;
}


void setMode(int c) //*
{
 if (c < 10)
 {
  delay_ms(20);
  PORTD.RD1 = 1;
  PORTB = seg[c%10];
 }
 if (c >= 10)
 {
  PORTD.RD0 = 1;
  PORTB = seg[(c/10)%10];
 }
}

void main()
{
 setup();
 while(1)
 {
  if (Button (&PORTD, 2, 5, 1))//Debouncing
  {
   oldstate = 1; //flag button state
  }
  if (oldstate && Button (&PORTD, 2, 5, 0))
  {
   count++;
   oldstate = 0;
  }
  if (count == 100)
  {
   count = 0;
  }
  setMode(count);
 }
}

Please don't presume that EDAboard users are working with Proteus, better post a schematic print.
Oh sorry, thanks for advice)
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top