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.

MikroC Pro increment and decrement two 7 segment display

Status
Not open for further replies.

IcyWolfBrain

Newbie level 4
Newbie level 4
Joined
Dec 1, 2021
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
52
Hello guys, i need help with MikroC Pro programming code and the task is following -
Using two 7-segment indicators and a PIC16F628A microcontroller, implement a number generator (range: 00 ÷ 99).
Initial state: 00. Control is realized by two buttons. If one button is pressed, the generator automatically performs increment generation (increment , +1),
if the other button is pressed, automatic decrementing of the number takes place.

In attached files is screenshoot of shematics PIC16F628A microcontroller connection structure, but i dont know it is connected right?
Please can someone tell if its right?
Can someone help me out with programming code?
 

Attachments

  • Screenshot 2021-12-14 121622.png
    Screenshot 2021-12-14 121622.png
    45.4 KB · Views: 322

Not familiar with MikroC but basically yes 7 segments connected to one port,
preferably, and digit selects to the other.

The digit selects are "normally" buffered thru a bipolar switch, NPN for example,
because they take the sum of all segment on currents.

A common cathode display like this -

iu


Base R's for NPN ~ 1K. In this case the segments are also buffered. It all depends on
how much current you want to drive thru segment. Some small displays have low
segment current needs, others current too large for a processor pin to supply.

You also have to take into consideration some processors have a total current limit
for all pjns in a port, in addition to a current / pin. So that also influences weather or
not you need external segment driver.

What are the LED display current requirements per segment ?

Also keep in mind in code the counter has to perform binary >> BCD >> 7 segment conversion,
either HW and or in code.

An example - https://www.electronicshub.org/2-digit-up-down-counter/


Regards, Dana.
 
Last edited:

Not familiar with MikroC but basically yes 7 segments connected to one port,
preferably, and digit selects to the other.

The digit selects are "normally" buffered thru a bipolar switch, NPN for example,
because they take the sum of all segment on currents.

A common cathode display like this -

iu


Base R's for NPN ~ 1K. In this case the segments are also buffered. It all depends on
how much current you want to drive thru segment. Some small displays have low
segment current needs, others current too large for a processor pin to supply.

You also have to take into consideration some processors have a total current limit
for all pjns in a port, in addition to a current / pin. So that also influences weather or
not you need external segment driver.

What are the LED display current requirements per segment ?

Also keep in mind in code the counter has to perform binary >> BCD >> 7 segment conversion,
either HW and or in code.

An example - https://www.electronicshub.org/2-digit-up-down-counter/


Regards, Dana.
Hello, thanks I looked at the example, but there's another microcontroller, but I need PIC16F628A micrcontroller. And there is increment by pressing the button +1, but I need to press the button, and its auto-increment till 99, then pressing decrement to button its auto decrements. There is no need led display current requirements per segment in MikroC Pro
 

Is this a school problem you are working on ? Do you program in C or ASM ?

Regards, Dana.
 

Forum loves to help, so post your basic code for comment.

If you are new to C many folks are visual learners, so flow chart of
how stuff should work helps a lot. Allows one to see incomplete
decisions, incomplete or mis-located loops,.....

Regards, Dana.
 

Forum loves to help, so post your basic code for comment.

If you are new to C many folks are visual learners, so flow chart of
how stuff should work helps a lot. Allows one to see incomplete
decisions, incomplete or mis-located loops,.....

Regards, Dana.
So time ago a user Dan1138 on this forum already helped with PIC16F28, but there task was pushing button 7 segment incremented by 1 and pressing other button it decrement by +1 (didnt have auto function). In attachment i will Proteus schematic

Codes was:
-------
Code:
unsigned char state, prev_state;
unsigned char i;

void main(){

 portd = 0;
 trisd = 0b00000000;
 i = 0;
 prev_state = 0;

while(1){

  state = 0;

  if(portb.b0 == 0) state = state + 1;
  if(portb.b7 == 0) state = state + 2;

  if(prev_state!=state){

    switch(state){
           case 0: /* no buttons pressed */
            break;

           case 1: /* increment button pressed */
            if(i < 9) i++;
            else i = 0;
            break;

           case 2: /* decrement button pressed */
            if(i > 0) i--;
            else i = 9;
            break;

           case 3: /* both buttons pressed */
            break;
    }

    prev_state=state;

    switch(i){          /* .gfedcba */
           case 0: portd=0b00111111; break;
           case 1: portd=0b00000110; break;
           case 2: portd=0b01011011; break;
           case 3: portd=0b01111001; break;
           case 4: portd=0b01100110; break;
           case 5: portd=0b01101101; break;
           case 6: portd=0b01111101; break;
           case 7: portd=0b00000111; break;
           case 8: portd=0b01111111; break;
           case 9: portd=0b01101111; break;
    }
  }
}
}
 

Attachments

  • Screenshot 2021-12-01 132628.png
    Screenshot 2021-12-01 132628.png
    47.5 KB · Views: 232
Last edited by a moderator:

I don't see you bounce in and out the button before counting it as a press/release
to act on.

Not a C expert but "if else" typing should be more like this

if(num<10)
{
printf("The value is less than 10");
}
else
{
printf("The value is greater than 10");
}

I dont see any code to handle digit selection....

Flow chart........


Regards, Dana.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top