作者共发了3篇帖子。 内容转换:不转换▼
 
点击 回复
410 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)
 

本帖信息

点击数:410 回复数:2
评论数: ?
作者:巨大八爪鱼
最后回复:巨大八爪鱼
最后回复时间:2017-2-1 22:18
 
©2010-2024 Arslanbar Ver2.0
除非另有声明,本站采用知识共享署名-相同方式共享 3.0 Unported许可协议进行许可。