#define F_CPU 8000000UL
#include <avr/eeprom.h>
#include <avr/io.h>
#include <util/delay.h>
class Car
{
private:
bool getKey(void) const;
public:
Car(void);
void run(void);
void write(bool onebyte = false) const;
};
Car::Car(void)
{
DDRB = 0x01;
PORTB = 0x01;
DDRD = 0x00; // PD7设为输入
PORTD = 0x80; // PD7设为带上拉电阻的输入
}
bool Car::getKey(void) const
{
return ((PIND & 0x80) == 0);
}
void Car::run(void)
{
while (1)
{
if (getKey())
{
_delay_ms(1000);
PORTB ^= 0x01;
}
else
PORTB = 0x00;
}
}
void Car::write(bool onebyte) const
{
if (onebyte)
eeprom_write_byte((uint8_t *)15, 0xa3);
else
eeprom_write_block("This is a string.", (void *)0, 17);
}
int main(void)
{
Car car;
car.run();
return 0;
}