目前共有3篇帖子。 內容轉換:不轉換▼
 
點擊 回復
391 2
【程序】在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

回復帖子

內容:
用戶名: 您目前是匿名發表
驗證碼:
(快捷鍵:Ctrl+Enter)
 

本帖信息

點擊數:391 回複數:2
評論數: ?
作者: 巨大八爪鱼
最後回復:巨大八爪鱼
最後回復時間:2017-2-1 22:18
 
©2010-2024 Arslanbar Ver2.0
除非另有聲明,本站採用創用CC姓名標示-相同方式分享 3.0 Unported許可協議進行許可。