avr-chat
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-chat] ATmega88 + triple 7 Segment Display (CC)


From: Student1
Subject: Re: [avr-chat] ATmega88 + triple 7 Segment Display (CC)
Date: Wed, 2 Apr 2008 16:19:36 -0700 (PDT)

[code]#include <avr/io.h>

int displaynumber (int number){
        switch (number) {
                case 0:
                        return 0x3F;
                        break;
                case 1:
                        return 0x06;
                        break;
                case 2:
                        return 0x5B;
                        break;
                case 3:
                        return 0x4F;
                        break;
                case 4:
                        return 0x66;
                        break;
                case 5:
                        return 0x6D;
                        break;                  
                case 6:
                        return 0x7D;
                        break;
                case 7:
                        return 0x07;
                        break;
                case 8:
                        return 0x7F;
                        break;
        }
}


int main(){

  // Set up regular i/o ports:
  DDRB  = 0xFF;   // Port B: output
  PORTB = 0x00;   //              with NO all pull-up resistors activated

  DDRC  = 0xFF;   // Port C: output
  PORTC = 0x00;   //              with NO all pull-up resistors activated

//DDRC  = 0xF0;   // Port C: output/input
//PORTC = 0x01;   //              with one pull-up resistor activated

  DDRD  = 0xFF;   // Port D: output
  PORTD = 0x00;   //              with NO all pull-up resistors activated


int counterones = 0;
int countertens = 0;
int counterhundreds = 0;
int timercounter = 0;
int i = 0;
        while(1) {
                PORTD = displaynumber (counterhundreds);
                PORTB = 0x06;
                PORTD = displaynumber (countertens);
                PORTB = 0x0A;
                PORTD = displaynumber (counterones);
                PORTB = 0x0C;

                if (counterones == 9) {
                        counterones = 0;
                        countertens = countertens + 1;
                }
                else
                        counterones = counterones + 1;

                if (countertens == 6) {
                        countertens = 0;
                        counterhundreds = counterhundreds + 1;
                }
                else
                        countertens = countertens + 1;
        
                if (counterhundreds == 9) {
                        counterhundreds = 0;
                }
        }
        return 0;
}

[/code]

Hi guys, so I have the 7 segment display hooked to PORTD output. And have
each of the Digit Display pins hooked up PORTB which will send a 0 to pull
it down and display the bit.

The problem is my Atmega88 chip runs at 1mHz, so 1,000,000 processes per
second cycle. How can I write a delay function such that it will display
digit ones for 20 microseconds, then display digit two tens for 20
microseconds, then digit hundreds for 20 microseconds. Rince and repeat. All
while then having to increment the ones/tens/hundreds respectively.

ie for loop

while(1) {
  for (1 seconds)
    display # on digit 1 for 20us, then turn off
    display # on digit 2 for 20us, then turn off
    display # on digit 3 for 20us, then turn off
  end

increment counter++
}

Help is appreciated.

Thanks
-- 
View this message in context: 
http://www.nabble.com/ATmega88-%2B-triple-7-Segment-Display-%28CC%29-tp15708386p16453399.html
Sent from the AVR - General mailing list archive at Nabble.com.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]