Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * test.c
- *
- * Created: 17.05.2018 16:37:10
- * Author : santn
- */
- #include <avr/io.h>
- void init() {
- DDRA &= ~(1 << 0);
- DDRB = 0xFF;
- }
- uint8_t readShift() {
- return (PINA & 0x01);
- }
- uint8_t shift(uint8_t x) {
- uint8_t sh[8];
- for(int i = 0; i < 8; i++) {
- sh[i] = (x & (1 << i)) >> i;
- }
- uint8_t u = sh[0] ^ sh[2];
- uint8_t v = sh[3] ^ u;
- uint8_t w = sh[5] ^ v;
- return (w << 7) | (sh[7] << 6) | (sh[6] << 5) | (sh[5] << 4) | (sh[4] << 3) | (sh[3] << 2) | (sh[2] << 1) | sh[1];
- }
- int main(void) {
- init();
- volatile uint8_t noise = 1;
- while (1) {
- if(readShift() == 1) {
- noise = shift(noise);
- PORTB = noise;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement