Na ja, wen ich das verwende
Code:
/*
Funktion zum Tasten entprellen
taster([PORTx], ([PDx]|[PDy]|[PDz]|.usw ))
Ich lese den PIND, PD0 ein und gebe ihn entprellt wider am PORTB aus.
Test Bort ist das STK500 mit Atmega644 8MHz.
PORTB ist auf LED's, und PORTD ist auf Taster geschaltet.
*/
#include <avr/io.h>
#include <stdint.h>
#ifndef F_CPU
#warning "F_CPU war noch nicht definiert, wird nun mit 8000000 Hz definiert"
#define F_CPU 8000000UL /* Quarz mit 8000000 Hz */
#endif
#include <util/delay.h> /* bei alter avr-libc: #include <avr/delay.h> */
//Funktions Prototypen
uint8_t taster(uint8_t* pinx, uint8_t px);
int main (void)
{
DDRB = 0xff; //PORTB Ausgang
while(1) //Hauptschleife
{
if(taster(PIND, PD0)) //Taster0 Abfragen
{
PORTB = PD0; //LED0 Einschalten
}
} //Hauptschleife Ende
return 0;
} //Main Ende
//Funktion, taster([PORTx], ([PDx]|[PDy]|[PDz]|.usw ))
uint8_t taster(uint8_t* pinx, uint8_t px)
{
if( *pinx & (1 << px))
{
_delay_ms(10);
}
else
{
return 0;
}
if( *pinx & (1 << px))
{
return *pinx;
}
else
{
return 0;
}
}
Dan kommt das
Code:
Build started 1.8.2011 at 18:52:40
avr-gcc -mmcu=atmega644 -Wall -gdwarf-2 -std=gnu99 -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -MD -MP -MT Taster.o -MF dep/Taster.o.d -c ../Taster.c
../Taster.c:13:2: warning: #warning "F_CPU war noch nicht definiert, wird nun mit 8000000 Hz definiert"
../Taster.c: In function 'main':
../Taster.c:33: warning: passing argument 1 of 'taster' makes pointer from integer without a cast
../Taster.c:20: note: expected 'uint8_t *' but argument is of type 'uint8_t'
avr-gcc -mmcu=atmega644 -Wl,-Map=Taster.map Taster.o -o Taster.elf
avr-objcopy -O ihex -R .eeprom -R .fuse -R .lock -R .signature Taster.elf Taster.hex
avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 --no-change-warnings -O ihex Taster.elf Taster.eep || exit 0
avr-objdump -h -S Taster.elf > Taster.lss
AVR Memory Usage
----------------
Device: atmega644
Program: 202 bytes (0.3% Full)
(.text + .data + .bootloader)
Data: 0 bytes (0.0% Full)
(.data + .bss + .noinit)
Build succeeded with 2 Warnings...
Und ale LED's Sind An.
Danke
by Ferdinand.
Lesezeichen