Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

(SOLVED)Code beat me again, 7 segment this time

Status
Not open for further replies.

fezder

Well-Known Member
So, i managed to do this many years ago, BUT, now that i started doing again (nope, didn't take copy of that previously working code....)
this for some reason won't work at least the way it should
Basic 2-digit timer, but the trouble currently is that other digit won't go on, even though i'm quite sure i told it to do so. However, when i drive them as separatery, i mean as 1 digit, they work as intened. What bothers me is that they won't work as multiplexing/synchronously, if you get my meaning. those codes all over the internet didn't help either, didn't find that thing that causes this, there is blanking supposedly between digits. But, hopefully you guys could shep some light....port manipulation might be overkill, but i recently started doing codes with it, shoudln't be issue....
and, i use 4543 bcd-7 segment driver, if that makes any difference
C:
int const t =100;
int count;


void setup()
{
  //Serial.begin(9600);       //debugging
  DDRD = DDRD | B11111100;    //Data direction register D, 0=input, 1=output: pins 4-7 output
  DDRB = B00000011;           // 8, 9 outputs
}

void loop()
{
PORTD = B00000000;                 //display 0
PORTB = B00000001;                 //turn on digit 1
picknumber(count / 1 % 10);      
delayMicroseconds(10);           
PORTD = B00000000;                  //display 0
PORTB = B00000010;                  //turn on digit 2
picknumber(count / 10 % 10);
delayMicroseconds(10);
  delay(t);                         //increment delay 0.1s, resolution is 0.1s
count++;                           //increment
//Serial.println(count);            //debugging
}



void picknumber( int count)
{
  switch (count)
  {
  //case 0: zero(); break;
  case 1:PORTD=B00010000; break;            //1
  case 2:PORTD=B01000000; break;            //2
  case 3:PORTD=B01010000; break;            //3
  case 4:PORTD=B10000000; break;            //4
  case 5:PORTD=B10010000; break;            //5
  case 6:PORTD=B11000000; break;            //6
  case 7:PORTD=B11010000; break;            //7
  case 8:PORTD=B00100000; break;            //8
  case 9:PORTD=B00110000; break;            //9
  default: B00000000; break;                //0
  }
}
 
Last edited:
Oops, that was the cause, i confused micros and millis....doh! sorry and thanks!
 
wohoo, all 4 digits work, and it's better than previous version! thanks a lot!
 
here we go
 
my previous version is at blog section, if you want to compare....now i took code and schematics to safe place hehe
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top