aboutsummaryrefslogtreecommitdiff
path: root/main.c
blob: 2b5753db456958192f1cb383f3acc7427a85fb3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// vim:set et sw=2 ts=2 tw=120:
#define __AVR_ATtiny85__
#include <avr/interrupt.h>
#include <avr/io.h> // (1)

#ifndef F_CPU
#warning "F_CPU war noch nicht definiert, wird nun mit 3686400 definiert"
#define F_CPU 1000000UL
#endif

#include <stdint.h>
#include <util/delay.h>

// set bit
static inline void BIT_SET(volatile uint8_t* target, uint8_t bit) __attribute__((always_inline));
static inline void BIT_SET(volatile uint8_t* target, uint8_t bit) { *target |= (1 << bit); };

// set clear
static inline void BIT_CLEAR(volatile uint8_t* target, uint8_t bit) __attribute__((always_inline));
static inline void BIT_CLEAR(volatile uint8_t* target, uint8_t bit) { *target &= ~(1 << bit); };

void pulse_sck()
{
  PORTB |= (1 << PB2);
  _delay_ms(10); // Eine Sekunde +/-1/10000 Sekunde warten...
  PORTB ^= (1 << PB2);
}

void print_data(uint16_t data)
{
  BIT_CLEAR(&PORTB, PB4);
  _delay_ms(50);
  BIT_SET(&PORTB, PB4);

  for (uint16_t i = 0; i < 16; i++)
  {
    data & 0x1 << i ? BIT_SET(&PORTB, PB4) : BIT_CLEAR(&PORTB, PB4);
    pulse_sck();
  }

  BIT_CLEAR(&PORTB, PB3);
  _delay_ms(50);
  BIT_SET(&PORTB, PB3);
}

int main(void)
{
  DDRB = 0xFF;

  BIT_CLEAR(&PORTB, PB5);
  _delay_ms(200);
  BIT_SET(&PORTB, PB5);
  BIT_CLEAR(&PORTB, PB5);
  _delay_ms(200);
  BIT_SET(&PORTB, PB5);

  while (1)
  { // Endlosschleife

    uint16_t data = 1;
    for (; data < UINT16_MAX; data++)
    {
      // clear register (reset)
      print_data(data | data << 6);
    }

    _delay_ms(1000); // Eine Sekunde +/-1/10000 Sekunde warten...
  }
  return 0;
}
..