First project in Embedded C

Right now I am tinkering around with embedded programming; desktop programming is getting a little boring.

I am trying to make a clock. The part I am having trouble with is displaying the time. I need to know how a numeric display would hook up to my processor. Would it plug into a I/O port? A Pin?

I need to know because as of right now, I am assuming that the display hooks up to a port. I am planning on using a Atmel 8052 family processor with 4 I/0 Ports.

Port 0 will be used for switches that will set the time
Port 1 will be used for the Hours display
Port 2 will be used for the Minutes display
Port 3 will be used for the Seconds display (i want a seconds display just for kicks)

Therefore, to I would send the time value to the whole port:

P1 = 12;

for example.

I am using the Kiel compiler and I can post my code if it will help.

Parents
  • There are many ways to accomplish what you want.

    One problem with the way you suggest is that it uses up all of your ports.

    If you use 7-segment displays (so named because they have 7 segments which can be used to make up all 10 digits 0-9) you can multiplex them using a single port (for the segments) and a few other bits for the digit selection.

    You can use 7 bits of P1 for the segments and 3 bits of P3 to select the digit you are writing to. This is how many digital clocks actually work.

    This idea is that your eye reacts relatively slowly. So, if you multiplex the digits faster than 30-40 times a second your eye is fooled into thinking that they are all lit at the same time - you don't see the blink because of the persistence of the LEDs.

    You would typically do this in software in an interrupt.

    digit = (digit + 1) % 6;
    
    P3 = (P3 & ~0x07) | (digit & 0x07);
    P1 = value[digit];

    Then, somewhere in your program (probably every second) you would update the time value.

    value[0] = Hour/10
    value[1] = Hour%10;
    value[2] = Minute/10;
    value[3] = Minute%10;
    value[4] = Second/10;
    value[5] = Second%10;

    This, too, would probably be updated in the time-tick interrupt that incremented the second hand of the clock.

    One strategy would be to use a single interrupt that triggered 100 times a second. You could update the seconds every 100 interrupts and you could refresh the next display digit each interrupt.

    Hopefully, this helps you out.

    Jon

Reply
  • There are many ways to accomplish what you want.

    One problem with the way you suggest is that it uses up all of your ports.

    If you use 7-segment displays (so named because they have 7 segments which can be used to make up all 10 digits 0-9) you can multiplex them using a single port (for the segments) and a few other bits for the digit selection.

    You can use 7 bits of P1 for the segments and 3 bits of P3 to select the digit you are writing to. This is how many digital clocks actually work.

    This idea is that your eye reacts relatively slowly. So, if you multiplex the digits faster than 30-40 times a second your eye is fooled into thinking that they are all lit at the same time - you don't see the blink because of the persistence of the LEDs.

    You would typically do this in software in an interrupt.

    digit = (digit + 1) % 6;
    
    P3 = (P3 & ~0x07) | (digit & 0x07);
    P1 = value[digit];

    Then, somewhere in your program (probably every second) you would update the time value.

    value[0] = Hour/10
    value[1] = Hour%10;
    value[2] = Minute/10;
    value[3] = Minute%10;
    value[4] = Second/10;
    value[5] = Second%10;

    This, too, would probably be updated in the time-tick interrupt that incremented the second hand of the clock.

    One strategy would be to use a single interrupt that triggered 100 times a second. You could update the seconds every 100 interrupts and you could refresh the next display digit each interrupt.

    Hopefully, this helps you out.

    Jon

Children
More questions in this forum