daily pastebin goal
43%
SHARE
TWEET

Untitled

a guest Jan 20th, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <avr/io.h>
  2. #include <util/delay.h>
  3.  
  4. #define SegOne   0x01
  5. #define SegTwo   0x02
  6. #define SegThree 0x04
  7. #define SegFour  0x08  
  8.  
  9.  
  10.  
  11. int main() {
  12.     char seg_code[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
  13.     int cnt, num, temp,i;
  14.  
  15.     /* Configure the ports as output */
  16.     DDRB = 0xff; // Data lines
  17.     DDRD = 0xff; // Control signal PORTD0-PORTD3
  18.  
  19.     while (1)
  20.     {
  21.         for (cnt = 0x00; cnt <= 9999; cnt++) // loop to display 0-9999
  22.         {
  23.             for (i = 0; i < 100; i++)
  24.             {
  25.                 num = cnt;
  26.                 temp = num / 1000;
  27.                 num = num % 1000;
  28.                 PORTD = SegOne;
  29.                 PORTB = seg_code[temp];              
  30.                 _delay_ms(1);
  31.  
  32.                 temp = num / 100;
  33.                 num = num % 100;
  34.                 PORTD = SegTwo;
  35.                 PORTB = seg_code[temp];
  36.                 _delay_ms(1);
  37.  
  38.                 temp = num / 10;
  39.                 PORTD = SegThree;
  40.                 PORTB = seg_code[temp];
  41.                 _delay_ms(1);
  42.  
  43.                 temp = num % 10;
  44.                 PORTD = SegFour;
  45.                 PORTB = seg_code[temp];
  46.                 _delay_ms(1);                              
  47.             }
  48.         }
  49.     }
  50. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top