## How to display the sequence (10,15,20,25,30....60) on dual dice seven segment display

9 posts / 0 new
Author
Message

Hi

How to display the sequence (10,15,20,25,30....60) on dual dice seven segment display.Their are 2 Keys when Key1 Pressed  for first time 10 should display when key1 pressed for second time  15 to be displayed when key2 pressed(decreament)  it should come from  current value (15-10)5decreament/increament interval is 5.Kindly guide me

Kindly guide me

You need to do your own schoolwork.

Think about a solution.

Describe your solution clearly (in English).

Ask a specific question.

Yes,   all your classmates will be able to see any messages.    They might even learn something from you.

David.

Its not school work...i am not school student..I am asking the Logic ,counting 00 to 99 like that sequence i have done but it seems to be difficult for this sequence (10,15,20,25,30,35....60).If possible kindly guide me

Last Edited: Tue. Apr 14, 2015 - 02:17 PM

Go on.   Perhaps you might benefit from a school class!

Try it with money.   e.g. 5 cent coins.

Do you have 5 Rupee notes?

David.

What is difficult?

You just need to count in steps of five instead of counting in steps of one - surely?

Top Tips:

1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...

".i am not school student..I am asking the Logic ,counting 00 to 99 like that sequence i have done "

Well, if you are not a student, may be you can get accustomed to bad practices.

A first step might be to show what you have done : if something is ugly, it will be corrected and might be used as a ground to evolve from  towards a step +-5 counter.

Hi

this is the code i am trying to generate (10,15,20,25....60)

Output  :when key pressed i am seeing all the values at a time  like for first key press only 10 should display,for second keypress 15 should display  but here as soon i press key 10 15 ,20 upto 60 it is showing.kindly guide me to solve this

/*
* sevenseg00.c
*/

#ifndef F_CPU
#define F_CPU 1000000UL
#endif

#include <avr/io.h>
#include <util/delay.h>

int main(void)

{
unsigned int digits[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
unsigned int i,unit,ten;
DDRD=0XFF;
DDRC=0XFF;

DDRB|=(0<<DDB0);

/* turn on internal pull-up resistor for the switch */

PORTB|=(1<<PB0);

DDRB|=(0<<DDB1);

/* turn on internal pull-up resistor for the switch */

PORTB|=(1<<PB1);

int j=-1;

char flag1=0,flag2=0;  //flags for 2 switches

while(1)

{

if(bit_is_clear(PINB,0)&&flag1==0&&j!=9)   //check switch1 is pressed

{
++j;    //increase value of i to -1 to 0 for 1st time

for(i=10;i<=60;i+=5)

{

for(j=i;j<=i;j++)
{

ten=i/10;
unit=i%10;

//    _delay_ms(1000);
PORTD=digits[unit];

//unit=0;

PORTC=0X01;
_delay_ms(200);
PORTD=digits[ten];

//ten=0;

PORTC=0X02;
_delay_ms(210);

flag1=1;           //Flag for switch1 is 1 after key press
}
}  //end of for

}

if(bit_is_set(PINB,0))                //Released condition for switch1
{
flag1=0;    //In release condition switch1 flag is zero
}

if (bit_is_clear(PINB,1)&&flag2==0&&j>0)   //check switch2 is pressed

{

--j;

PORTD=digits[unit];
PORTC=0X01;
_delay_ms(200);
PORTD=digits[ten];
PORTC=0X02;
_delay_ms(210);
flag2=1;
}

if(bit_is_set(PINB,1))            //Released condition for switch2
{
if(i<0&&flag2==1)
{

j=-1;   //after0 if still key pressed detects to not to consider
}
flag2=0;    //when switch not pressed

}  //end of release condition of switch2

}   //end of while

}  //end of main

You can test the switch voltage to see if it is hi or lo by reading the PIN. To find the edge of the switch voltage, you need to see if the switch is hi this pass and not last pass. So you have to save the switch state in a var

<

#define SWIN() (PINB & 0x01)==0

unsigned char swin; //switch state this pass

unsigned char swinl //switch state last pass;

.

.

.

swin = SWIN(); //read switch state into a variable

if(swin && ! swinl){ //switch just went in

dosomething();

}

swinl=swin; //remember state for next pass

>

Imagecraft compiler user

*        for(j=i;j<=i;j++) is very strange (not harmful)

*#ifndef F_CPU
#define F_CPU 1000000UL
#endif
is already done in avrlibc ...

why do you use _delay_ms(200) and 210? (an eye cannot see the difference)

PORTD=digits[unit];
PORTC=0X01;
_delay_ms(200);
PORTD=digits[ten];
PORTC=0X02;
_delay_ms(210);

might be put into a function (some compielrs can inline it, if you want very fast code : the length of your delayss makes it unlikely) . advantages would be double : flash would be shorter, if not inlined and things would become easier to read (suppose you want to reuse this code after 6 months)

++j;    //increase value of i to -1 to 0 for 1st time comments and code are unconsistent

Edited : none of these cosmetical changes/hints will solve your problem, but I bet Bob Gardner did it...

Last Edited: Wed. Apr 15, 2015 - 05:12 PM