Guest User

Würfelprogramm

a guest
Oct 11th, 2015
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * RandomDice.cpp
  3.  *
  4.  * Created: 07.10.2015 18:43:43
  5.  * Author : Kim-Yannick
  6.  */
  7.  
  8. #define F_CPU 10000000UL
  9.  
  10. #include <avr/io.h>
  11. #include <util/delay.h>
  12. #include <stdlib.h>
  13.  
  14. char codes[] = {0b01111110, 0b01001000, 0b00111101, 0b01101101, 0b01001011, 0b01100111, 0b01110111};
  15.  
  16. int main(void)
  17. {
  18.     DDRD = 0xFF;
  19.     DDRC = 0x00;
  20.    
  21.     PORTD = 1 << 7;
  22.     PORTC = 1;
  23.    
  24.     int seed = 0;
  25.    
  26.     while (PINC&1) {
  27.         seed += 1;
  28.         _delay_ms(5);
  29.     }
  30.    
  31.     srand(seed);
  32.    
  33.     while (1) {            
  34.         unsigned int number = rand();    
  35.        
  36.         PORTD |= 1 << 7;
  37.        
  38.         while (!PINC&1) {
  39.             number = rand();
  40.             _delay_ms(10);
  41.         }
  42.        
  43.         PORTD = codes[number%6+1];
  44.        
  45.         while (PINC&1)
  46.             _delay_ms(10);
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment