uwezi

labb_03_code_03.c

Nov 13th, 2019
158
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. ATmega8, 48, 88, 168, 328
  3.  
  4. /Reset PC6|1   28|PC5
  5.  seg_A PD0|2   27|PC4
  6.  seg_B PD1|3   26|PC3
  7.  seg_C PD2|4   25|PC2
  8.  seg_D PD3|5   24|PC1
  9.  seg_E PD4|6   23|PC0
  10.        Vcc|7   22|Gnd
  11.        Gnd|8   21|Aref
  12.        PB6|9   20|AVcc
  13.        PB7|10  19|PB5 SCK   Anode_1
  14.  seg_F PD5|11  18|PB4 MISO  Anode_2
  15.  seg_G PD6|12  17|PB3 MOSI  Anode_3
  16.  dot   PD7|13  16|PB2       Anode_4
  17.        PB0|14  15|PB1
  18. */
  19.  
  20. #define F_CPU 1000000UL  // 1 MHz standard clock
  21.  
  22. #include <avr/io.h>     // defines all macros and symbols
  23. #include <util/delay.h> // defines time delay functions
  24.  
  25. uint8_t framebuffer[4] = {0b00111111,0b00000110,0b01011011,0b01001111};
  26.  
  27. int main (void)
  28. {
  29.   uint8_t i;
  30.  
  31.   DDRD = 0b11111111;     //  all pins of PORT D as output
  32.   DDRB = 0b00111100;     // some pins of PORT B as output
  33.  
  34.   while (1)              // infinite main loop
  35.   {
  36.     for (i=0; i<4; i++)
  37.     {
  38.       PORTB &=  0b11000011;        // all digits off
  39.       PORTB |= (0b00000100 << i);  // activate digit #i
  40.       PORTD  = ~framebuffer[i];    // output bit pattern
  41.       _delay_ms(500);              // wait 500 ms
  42.     }
  43.   }
  44. }
RAW Paste Data