设置 | 登录 | 注册

作者共发了3篇帖子。

【程序】在Atmel Studio 7中用C++寫的AVR程序

1楼 巨大八爪鱼 2017-2-1 22:13

#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;
}

2楼 巨大八爪鱼 2017-2-1 22:14
不過遺憾的是,由於沒有頭文件<iostream>和<string>,所以沒法使用std::string字符串類。
3楼 巨大八爪鱼 2017-2-1 22:18
默認情況下,new和delete運算符也無法使用:
嚴重性 代碼 說明 項目 文件 行
錯誤  undefined reference to `operator new[](unsigned int)' GccApplication2 E:\用戶的文檔\Octopus\Documents\Atmel Studio\7.0\GccApplication2\GccApplication2\main.cpp 52
錯誤  ld returned 1 exit status GccApplication2 collect2.exe 0
錯誤  recipe for target 'GccApplication2.elf' failed GccApplication2 E:\用戶的文檔\Octopus\Documents\Atmel Studio\7.0\GccApplication2\GccApplication2\Debug\Makefile 108
錯誤  undefined reference to `operator delete[](void*)' GccApplication2 E:\用戶的文檔\Octopus\Documents\Atmel Studio\7.0\GccApplication2\GccApplication2\main.cpp 52

内容转换:

回复帖子
内容:
用户名: 您目前是匿名发表。
验证码:
看不清?换一张
©2010-2025 Purasbar Ver3.0 [手机版] [桌面版]
除非另有声明,本站采用知识共享署名-相同方式共享 3.0 Unported许可协议进行许可。