Advertisement
Guest User

Untitled

a guest
May 26th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. /*
  2. * test.c
  3. *
  4. * Created: 17.05.2018 16:37:10
  5. * Author : santn
  6. */
  7.  
  8. #include <avr/io.h>
  9.  
  10. void init() {
  11. DDRA &= ~(1 << 0);
  12. DDRB = 0xFF;
  13. }
  14.  
  15. uint8_t readShift() {
  16. return (PINA & 0x01);
  17. }
  18.  
  19. uint8_t shift(uint8_t x) {
  20. uint8_t sh[8];
  21. for(int i = 0; i < 8; i++) {
  22. sh[i] = (x & (1 << i)) >> i;
  23. }
  24.  
  25. uint8_t u = sh[0] ^ sh[2];
  26. uint8_t v = sh[3] ^ u;
  27. uint8_t w = sh[5] ^ v;
  28.  
  29. return (w << 7) | (sh[7] << 6) | (sh[6] << 5) | (sh[5] << 4) | (sh[4] << 3) | (sh[3] << 2) | (sh[2] << 1) | sh[1];
  30. }
  31.  
  32.  
  33. int main(void) {
  34. init();
  35. volatile uint8_t noise = 1;
  36. while (1) {
  37. if(readShift() == 1) {
  38. noise = shift(noise);
  39. PORTB = noise;
  40. }
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement