Hallo Guten Tag
Ich habe mir einen Atmega8 besorgt, einen kleinen USB Programmierer und das auch alles zum Laufen bekommen, mit dem Atmel Studio 7. Den ersten Code habe ich auch schon hochgeladen (Momentan eine LED die SOS blinkt)
Ich weiß leider nicht, ob ich hier richtig bin mit meinem Anliegen. Ich würde hier gerne meine kleinen Fortschritte vorstellen und Fragen stellen, warum dies und jenes gerade nicht funktioniert...vielleicht macht sich ja jemand die Mühe, mir dabei behilflich zu sein und mir über die Schulter zu schauen.
Ich fange einfach mal an, ein Bild von meinem kleinen Projekt zu posten und den dazugehörigen Code:
Die LED ist am pin C5, der als ausgang definiert ist, dranne. Diese funktioniert auch und blinkt im SOS-Modus
Der Pin C4 direkt da drunter soll als Eingang definiert sein.
Wenn ich jetzt durch den Button ein High signal an pin C4 schicke, soll die LED im SOS Modus blinken...diese blinkt aber unabhängig von dem Button dauerhaft im SOS Modus.
Die Blaue LED leuchtet, wenn ich den Button drücke, dieser funktioniert also..jemand eine Ahnung wo der Fehler ist :)?
code:
// MyAtmelBlink.c
// put LED on PC5
#ifndef F_CPU // if F_CPU was not defined in Project -> Properties
#define F_CPU 1000000UL // define it now as 1 MHz unsigned long
#endif
#include <avr/io.h> // this is always included in AVR programs
#include <util/delay.h> // add this to use the delay function
///////////////////////////////////////////////////////////////////////////////////////////////////
int main(void) {
DDRC |= (1 << PC5); // set Port C pin PC5 for output
DDRC &= ~(1 << PC4); // set Port C pin PC4 for intput
while (1)
{ // begin infinite loop
if (PORTC ^= (1 << PC4))
{
PORTC &= ~(1 << PC5);
}
else
{
PORTC ^= (1 << PC5); // flip state of LED on PC5
_delay_ms(250); // delay 1/2 second
PORTC &= ~(1 << PC5);
_delay_ms(250);
PORTC ^= (1 << PC5); // flip state of LED on PC5
_delay_ms(250); // delay 1/2 second
PORTC &= ~(1 << PC5);
_delay_ms(250);
PORTC ^= (1 << PC5); // flip state of LED on PC5
_delay_ms(250); // delay 1/2 second
PORTC &= ~(1 << PC5);
_delay_ms(250);
PORTC ^= (1 << PC5); // flip state of LED on PC5
_delay_ms(1000);
PORTC &= ~(1 << PC5);
_delay_ms(250);
PORTC ^= (1 << PC5); // flip state of LED on PC5
_delay_ms(1000);
PORTC &= ~(1 << PC5);
_delay_ms(250);
PORTC ^= (1 << PC5); // flip state of LED on PC5
_delay_ms(1000);
PORTC &= ~(1 << PC5);
_delay_ms(250);
PORTC ^= (1 << PC5); // flip state of LED on PC5
_delay_ms(250); // delay 1/2 second
PORTC &= ~(1 << PC5);
_delay_ms(250);
PORTC ^= (1 << PC5); // flip state of LED on PC5
_delay_ms(250); // delay 1/2 second
PORTC &= ~(1 << PC5);
_delay_ms(250);
PORTC ^= (1 << PC5); // flip state of LED on PC5
_delay_ms(250); // delay 1/2 second
PORTC &= ~(1 << PC5);
_delay_ms(5000);
}
}
return(0); // should never get here, this is to prevent a compiler warning
}
Alles anzeigen