Created
May 14, 2019 11:13
-
-
Save avr-programmierung/cf528a040ce27b57c6bc9afdaa9f73db to your computer and use it in GitHub Desktop.
ATmega88 @ 8MHz soft serial
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* soft_serial_01.c ATmega88 @ 8MHz */ | |
#include <avr/io.h> | |
void soft_serial (uint8_t data) // Funktion soft_serial | |
{ | |
for (uint8_t i=0; i<=7; i++) // for-Schleife 8 mal ausführen | |
{ | |
if (data & 1) // Wenn data an Stelle 0 = 1 | |
PORTD |= (1<<PD0); // Data serial = 1 | |
else | |
PORTD &= ~(1<<PD0); // Data serial = 0 | |
PORTD |= (1<<PD1); // PD1 = 1 (CLK = low) | |
PORTD &= ~(1<<PD1); // PD1 = 0 (CLK = high) | |
data = data >> 1; // data um 1 Stelle nach rechts schieben | |
} | |
} | |
int main(void) | |
{ | |
uint8_t data = 0xAA; // data = 1010 1010 | |
DDRD = 0xFF; // Richtungsregister PORTD = Ausgang | |
PORTD = 0x04; // PD2 (RCK) = HIGH, 0x04 = 0000 0100 | |
while(1) | |
{ | |
soft_serial(data); // Funktionsaufruf und Übergabe von data | |
PORTD &= ~(1<<PD2); // PD2 = 0 (Takt = LOW für RCK) | |
PORTD |= (1<<PD2); // PD2 = 1 (Takt = HIGH für RCK -> Ausgabe Schieberegister) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment