// vim:set et sw=2 ts=2 tw=120: #define __AVR_ATtiny85__ #include #include // (1) #ifndef F_CPU #warning "F_CPU war noch nicht definiert, wird nun mit 3686400 definiert" #define F_CPU 1000000UL #endif #include #include // 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; }