Object oriented with notepad/avr

Go To Last Post
22 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi every one,

 I am working on a project which include using OOP in may code.

so my questions are :

1-Is it possible to make a C++ code for the AVR

2-Is it possible to make the C++ code in the programmer note pad

3-Is it possible to provide me a code including the use of C++ OOP with avr if Question2 is valid in the programmer note pad IDE

4-Is it possible to provide me a code including the use of the stucts with avr in the programmer note pad IDE

Last Edited: Thu. Jul 12, 2018 - 10:35 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

1) yes

2) Yes

3)

#include <avr/io.h>

class Foo {
public:    
    void bar(uint8_t n) {
        PORTB = n;
    }
};

Foo obj;

int main(void) {
    obj.bar(0x55);
}

4)

#include <avr/io.h>

struct Foo {
    int n;
    char c;
};

Foo bar;

int main(void) {
    bar.n = 12345;
    bar.c = 'x';
}

For (3) and (4) I actually used my favourite editor (Notepad++) and then built on the command like:

D:\atmel_avr\avr8-gnu-toolchain\bin>avr-gcc -Os -mmcu=atmega16 avr.cpp -o avr.elf

D:\atmel_avr\avr8-gnu-toolchain\bin>avr-objdump -S avr.elf

avr.elf:     file format elf32-avr


Disassembly of section .text:

00000000 <__vectors>:
   0:   0c 94 2a 00     jmp     0x54    ; 0x54 <__ctors_end>
   4:   0c 94 3c 00     jmp     0x78    ; 0x78 <__bad_interrupt>
   8:   0c 94 3c 00     jmp     0x78    ; 0x78 <__bad_interrupt>
   c:   0c 94 3c 00     jmp     0x78    ; 0x78 <__bad_interrupt>
  10:   0c 94 3c 00     jmp     0x78    ; 0x78 <__bad_interrupt>
  14:   0c 94 3c 00     jmp     0x78    ; 0x78 <__bad_interrupt>
  18:   0c 94 3c 00     jmp     0x78    ; 0x78 <__bad_interrupt>
  1c:   0c 94 3c 00     jmp     0x78    ; 0x78 <__bad_interrupt>
  20:   0c 94 3c 00     jmp     0x78    ; 0x78 <__bad_interrupt>
  24:   0c 94 3c 00     jmp     0x78    ; 0x78 <__bad_interrupt>
  28:   0c 94 3c 00     jmp     0x78    ; 0x78 <__bad_interrupt>
  2c:   0c 94 3c 00     jmp     0x78    ; 0x78 <__bad_interrupt>
  30:   0c 94 3c 00     jmp     0x78    ; 0x78 <__bad_interrupt>
  34:   0c 94 3c 00     jmp     0x78    ; 0x78 <__bad_interrupt>
  38:   0c 94 3c 00     jmp     0x78    ; 0x78 <__bad_interrupt>
  3c:   0c 94 3c 00     jmp     0x78    ; 0x78 <__bad_interrupt>
  40:   0c 94 3c 00     jmp     0x78    ; 0x78 <__bad_interrupt>
  44:   0c 94 3c 00     jmp     0x78    ; 0x78 <__bad_interrupt>
  48:   0c 94 3c 00     jmp     0x78    ; 0x78 <__bad_interrupt>
  4c:   0c 94 3c 00     jmp     0x78    ; 0x78 <__bad_interrupt>
  50:   0c 94 3c 00     jmp     0x78    ; 0x78 <__bad_interrupt>

00000054 <__ctors_end>:
  54:   11 24           eor     r1, r1
  56:   1f be           out     0x3f, r1        ; 63
  58:   cf e5           ldi     r28, 0x5F       ; 95
  5a:   d4 e0           ldi     r29, 0x04       ; 4
  5c:   de bf           out     0x3e, r29       ; 62
  5e:   cd bf           out     0x3d, r28       ; 61

00000060 <__do_clear_bss>:
  60:   20 e0           ldi     r18, 0x00       ; 0
  62:   a0 e6           ldi     r26, 0x60       ; 96
  64:   b0 e0           ldi     r27, 0x00       ; 0
  66:   01 c0           rjmp    .+2             ; 0x6a <.do_clear_bss_start>

00000068 <.do_clear_bss_loop>:
  68:   1d 92           st      X+, r1

0000006a <.do_clear_bss_start>:
  6a:   a3 36           cpi     r26, 0x63       ; 99
  6c:   b2 07           cpc     r27, r18
  6e:   e1 f7           brne    .-8             ; 0x68 <.do_clear_bss_loop>
  70:   0e 94 3e 00     call    0x7c    ; 0x7c <main>
  74:   0c 94 49 00     jmp     0x92    ; 0x92 <_exit>

00000078 <__bad_interrupt>:
  78:   0c 94 00 00     jmp     0       ; 0x0 <__vectors>

0000007c <main>:
  7c:   e0 e6           ldi     r30, 0x60       ; 96
  7e:   f0 e0           ldi     r31, 0x00       ; 0
  80:   89 e3           ldi     r24, 0x39       ; 57
  82:   90 e3           ldi     r25, 0x30       ; 48
  84:   91 83           std     Z+1, r25        ; 0x01
  86:   80 83           st      Z, r24
  88:   88 e7           ldi     r24, 0x78       ; 120
  8a:   82 83           std     Z+2, r24        ; 0x02
  8c:   80 e0           ldi     r24, 0x00       ; 0
  8e:   90 e0           ldi     r25, 0x00       ; 0
  90:   08 95           ret

00000092 <_exit>:
  92:   f8 94           cli

00000094 <__stop_program>:
  94:   ff cf           rjmp    .-2             ; 0x94 <__stop_program>

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

1st Thank you very much for your quick reply, secondly This is what happened.:(

what do you suggest?

Attachment(s): 

Last Edited: Thu. Jul 12, 2018 - 10:38 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It helps if you put the image in your post, so that we can see it - like this:

 

 

For instructions, see Tip #1

 

If you want it compiled as C++ (rahter than 'C'), then you have to:

  • either give your filename the .cpp extension,
  • or use an explicit command line option to force the compiler to treat it as C++

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

As Andy said you called the file main.c not main.cpp. When you invoke avr-gcc it is intelligent (it's known as a "compiler driver") and it uses the file extensions to know where to send files. .c file are sent to the C compiler (with preprocessing), .cpp files (also .cc) are sent to the C++ compiler with preprocessing, .S files are sent to the assembler with preprocessing and .s files are sent direct to the assembler.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
When you invoke avr-gcc it is intelligent 

It's not just GCC - many (most? all?) other compilers recognise .c to mean "this is a 'C' file" and .cpp to mean "this is a C++ file"

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

AND so i tried the first suggestion and unfortunately it didn't work , could you explain the second suggestion please?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

@@OMAR@AVR@@ wrote:
i tried the first suggestion and unfortunately it didn't work

What do you mean, "didn't work"

 

Tell us exactly what happened - it should work!

 

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Note that specifying the language is a general GCC option - not specific to AVR.

 

General GCC documentation is here: https://gcc.gnu.org/onlinedocs/

 

About specifying language options: https://gcc.gnu.org/onlinedocs/gcc/Standards.html

 

AVR specific: https://gcc.gnu.org/wiki/avr-gcc

 

AVR GCC Library: https://www.nongnu.org/avr-libc/

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

Why are you trying to use Programmers Notepad? That was the "IDE" that shipped as a part of "WinAVR" about 10..15 years ago. These days it shows its age. In Windows Atmel Studio 7 is a FAR better choice for an IDE.  If there's some reason you dont want to use AS7 then consider trying Eclipse(CDT) or Code::Blocks as they are far better developed IDEs than PN.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

well actually you are right am trying to use an old IDE because, It's simple and i have written all my libraries on it but ill try AS7,thank you 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The message indicates that you have not properly configured your project.

 

I know nothing about PN, so I can't help you there

 

@@OMAR@AVR@@ wrote:
i have written all my libraries on it

So you're the experienced one, then!

 

 ill try AS7,thank you 

Probably a good idea.

 

But do take the time to view the getting started videos - so that you know what you're doing:

 

http://www.microchip.com/mplab/avr-support/atmel-studio-7 - at the bottom of the page

 

 

PS

 

What's with the sudden run on fingerprint sensors ... ?

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

So no one spotted the typo then ?

 

main.ccp instead of main.cpp

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The file you are trying to compile is called "main.ccp"; it should be called "main.cpp" instead  (.ccp is an unknown extension for the build tools, whereas .cpp means "c++").

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ha ha - no !

 

But, apparently, PN has recognised it as C++

 

Has the OP deliberately configured PN to recognise .ccp ?

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

When I saw Programmers Notepad, It immediately triggered memories of the old WinAVR, which is pretty old as Clawson mentioned in #11.

Your screenshot shows you are actually using gcc (winavr 2010110) 4.3.3 and that is pretty old. You really should use a more recent compiler, especially if you want to experiment with C++.

You can keep using PN if you want, but the compiler reallyy should be updated.

Microchip distributes binaries of recent versions of the AVR-GCC compiler.

But this should be a good moment for you to update the whole programming environment, including your editor / IDE

 

If you use PN, you probably also use makefiles. Instead of relying on automatic rules, it is probably better to explicitly tell avr-gcc for which C++ standard to compile. The ISOCPP committee has a goal of updating the standard every 3 years.

https://isocpp.org/

Paul van der Hoeven.
Bunch of old projects with AVR's:
http://www.hoevendesign.com

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well i totally agree with you and another user suggested the same idea an i did so but am facing some troubles now regarding the uploading of the hex file using usbasp, could you help?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That's an entirely separate question - so should be in a separate thread.

 

A moderator can move it ...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i did a separate thread for it but i thought i could the answer faster

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Paulvdh wrote:
You can keep using PN if you want, ...
Cliff's mention of Notepad++ in #2 is of interest.

Notepad++ plug-ins include

  • SVN though there's a simple file lock/unlock plug-in if don't want a complete SCM
  • to extend by C# and .NET
  • file indexing

Paulvdh wrote:
Microchip distributes binaries of recent versions of the AVR-GCC compiler.
Current is Microchip AVR GCC 3.6.1 :

http://www.microchip.com/mplab/avr-support/avr-and-arm-toolchains-(c-compilers)

Microchip AVR GCC 3.5.4 is also in NuGet.

NuGet doesn't have much AVR though there's a loader that communicates with an Arduino bootloader (usual Arduino AVR though includes mega1284)

NuGet Gallery

ArduinoUploader 3.2.0

https://www.nuget.org/packages/ArduinoUploader/

A library to upload an Intel HEX file (e.g. compiled sketches) directly to an Arduino over a (USB) serial port without having to use the Arduino IDE (or avrdude).

...

 


Notepad++ Home

https://notepad-plus-plus.org/

Plugin Central - Notepad++ Wiki

http://docs.notepad-plus-plus.org/index.php?title=Plugin_Central

...

Open File In Solution (OFIS) lets you index specific folders and possible specific types of resources (xml-, cpp, py-files) for a fast indexing of files. If you have used Visual Assist for Visual Studio or Eclipse you know how it works, ...

...

https://www.nuget.org/packages?q=AVR

https://github.com/christophediericx/ArduinoSketchUploader#compatibility

 

"Dare to be naïve." - Buckminster Fuller