Initial EEPROM contents in Atmega644 - atmega

I am working on a project using a Atmega644 and want to include EEPROM data in the initial programming.
I am using MPLAB X and the XC8 compiler (version 2.31) and for programming I am using a PICkit4.
I know that the xc8 compiler for PIC MCUs has the __EEPROM_DATA() macro, that would be pretty much perfect for my usecase. The AVR version of the compiler, however does not appear to have this macro (I tried both with and without CCI syntax...), as it does not recognize the call and just throws an error when trying to compile.
I have looked through the manual for the compiler, but it does not list any macros/functions to do this.
I tried adding the macro myself, by copying it from the PIC compiler to a header in my project, but it seems to contain assembly instructions that do not exist on the atmega and I couldn't even find those in documentation for the PIC (Otherwise I would have tried to find an equivalent instruction and replace them)...
Is there another way to include the initial EEPROM data in the project, so it gets written to the mcu during programming?

__EEPROM_DATA() macro is supported only for 8-bit PIC baseline and mid-range devices. There is also __eeprom qualifier to position variables in EEPROM. But none of these are for AVR chips.
Microchip supports AVR chips in XC8 using avr headers. There is an eeprom header which has some macros defined. One of these macros is EEMEM. You can use it to set EEPROM values at programming time. Here is how you use it:
#include <avr/eeprom.h>
char EEMEM nums[] = { 1, 2, 3, 4, 5 };
There is good information regarding the usage of this macro in this and this SO answers. Make sure to have a look at them.
I also recommend you to take a look at MPLAB XC8 C Compiler User's Guide for AVR MCU in case you didn't know about it.

Related

9 axes motion shield

I am having some issues getting stock code to compile for my 9 axes motion shield. I have a github repository with all of the motion libraries I have, the example code, and the error messages I am getting.
I am using Arduino 1.7.1 IDE on Windows 7 64-bit.
I have tried using sample code for the sensor instead of for the shield and could not get that to compile either. I have tested example code built into the IDE to ensure that I can compile something and I was even able to interface with my Arduino MEGA 2560 with said code.
I have searched Google and Stack exchange a fair bit and have not managed to come up with any solutions.
The main error I can not figure out is:
"
C:\Users\LJI_eric\Documents\Arduino\sketch_mar20a\sketch_mar20a.ino: In function 'void setup()':
sketch_mar20a:63: error: 'OPERATION_MODE_NDOF' was not declared in this scope
mySensor.setOperationMode(OPERATION_MODE_NDOF);"
OPERATION_MODE_NDOF is a mode that is defined in BNO055.h and is an array of operation modes. I tried several other modes to no avail.
I would appreciate any and all help.
On line 84, 87 and 91 you have made a new line inside a string. You can not do that on the Arduino. If you want to break a string up in more lines you should end the string where you would break it, and start the string again on the new line, like this.
Serial.println("Move the device around and then place it at one position.\n"
"Change the threshold and duration to increase the difficulty level.");
Then you should change OPERATION_MODE_NDOF to BNO055_OPERATION_MODE_NDOF

`_naked`: Trying to compile legacy 8051 (FX2) code with SDCC, newer version stumbles

I have legacy code for an embedded 8051 core (in a cypress FX2) that used to compile with other versions of SDCC. However, current SDCC doesn't know the _naked qualifier:
delay.c:27: syntax error: token -> '_naked' ; column 21
as triggered by
static void
udelay1 (void) _naked
{
_asm ; lcall that got us here took 4 bus cycles
ret ; 4 bus cycles
_endasm;
}
and other occurrences.
As _naked practically is supposed to tell the C compiler to "nah, ignore the fact that you're a C compiler and understand that you'd need to save frame context", I don't feel like I should just #define it away.
Is there any solution to this? Should I just go ahead and manually inline the assembler wherever a _naked function is used? I feel like I'd betraying the compiler on a CALL there, and that would change the timing.
_naked was replaced by __naked in newer versions of SDCC. Same applies to asm/__asm, at/__at, interrupt,bit,xdata/__….
So, this turned out to be an exercise in regex replacements.
I'm still having linker/ranlib/mostly ar problems, and CMake ignores what I instruct it to use as compilers, but oh well.

make the middle letter blink

I've already solved this by not displaying the last letter of the word then locating the last letter and making it blink then I displayed the word inversely minus the last letter of course.
#include<string.h>
#include<conio.h>
#include<iostream.h>
#include<stdio.h>
char text[255];
int txtposition,txtlength;
void main()
{
clrscr();
gets(text);
txtlength=strlen(text);
char lastchar=text[txtlength-1];
cout<<"Your text is: ";
for(txtposition=0;txtposition<txtlength-1;txtposition++)
{
cout<<text[txtposition];
}
textcolor(WHITE+128);
cprintf("%c", lastchar);
for(txtposition=txtlength-2;txtposition>=0;txtposition--)
{
cout<<text[txtposition];
}
getch();
}
Thank you for all your help!
To make the middle character blink, either your output terminal needs to be capable to present blinking characters using a special terminal control code as described here, or use the gotoxy() function from a separate thread, that displays a ' ' or the actual character, alternating for a specific blink frequency.
The standard C++ library does not provide any facility for making characters blink.
You can do that in platform-specific ways, but it's worth noting that Windows console windows do not (as far as I know) directly support text blinking, like the original IBM PC's text screen mode did. On the original IBM PC one bit of the color specification could be configured to either yield high intensity or blinking, with blinking control as the default. I always reconfigured it to high intensity in my programs, and in the corresponding mechanism for Windows console windows the bits always determine color.
So, it would be complicated to do even in Windows, unless you're running in a DOSBox, which emulates the old PC. I don't know what functionality it offers. Maybe it even does blinking.
But you can easily mark the relevant letters in other ways.
For example, you could use
uppercase versus lowercase,
underlining characters placed on the next line,
parentheses (as you did in your example here),
colors (platform specific),
a different font, boldness, whatever.
I recommend updating to a modern compiler, if you have an ordinary modern PC. Compilers are free. Also you need better learning material, e.g. void main is non-standard and is only accepted by a few compilers.
Looks like for Turbo C/C++ you can you use the Graphics library and/or builtin conio functions. ( https://answers.yahoo.com/question/index?qid=20080813072809AAEguz0 )
But the above is not portable as the graphics library is specific to Turbo and conio is specific to some dos based compilers/libraries.
If you move to the a complier like gcc/g++ then you might want to look at curses library: http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/

Arduino IDE maximum PROGMEM char array length

I am trying to use a single 4KB string in my arduino sketch but this always seems to give a whole bunch of java errors in the console and never compiles. I believe, I am using it correctly:
const char sequence[] PROGMEM = {"0F0FF0 ... 0F0F0FF"};
By trial-and-error I determined that the maximum length I can get to compile successfully is 1104 characters. This doesn't seem to make much sense. Is there some unknown limitation in the compiler or is it an issue with the IDE? I'm using 1.0.5 but I get the same results in 1.6.5 as well. I'd really rather not split the array. Reading online, the size limit should be 32KB, which is far higher, than what I need.
Any help or explanation appreciated, please and thank you.
It's a limitation of the IDE, not the compiler. If you make it a single string still, but use C's string concatenation, it will compile. eg.
const char sequence[] PROGMEM = {
"0F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF0"
"0F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF0"
...
"0F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF00F0F0FF0"
};

Unix write() function (libc)

I am making a C application in Unix that uses raw tty input.
I am calling write() to characters on the display, but I want to manipulate the cursor:
ssize_t
write(int d, const void *buf, size_t nbytes);
I've noticed that if buf has the value 8 (I mean char tmp = 8, then passing &tmp), it will move the cursor/pointer backward on the screen.
I was wondering where I could find all the codes, for example, I wish to move the cursor forward but I cannot seem to find it via Google.
Is there a page that lists all the code for the write() function please?
Thank you very much,
Jary
8 is just the ascii code for backspace. You can type man ascii and look at all the values (the man page on my Ubuntu box has friendlier names for the values). If you want to do more complicated things you may want to look at a library like ncurses.
You have just discovered that character code 8 is backspace (control-H).
You would probably be best off using the curses library to manage the screen. However, you can find out what control sequences curses knows about by using infocmp to decompile the terminfo entry for your terminal. The format isn't particularly easy to understand, but it is relatively comprehensive. The alternative is to find a manual for the terminal, which tends to be rather hard.
For instance, I'm using a color Xterm window; infocmp says:
# Reconstructed via infocmp from file: /usr/share/terminfo/78/xterm-color
xterm-color|nxterm|generic color xterm,
am, km, mir, msgr, xenl,
colors#8, cols#80, it#8, lines#24, ncv#, pairs#64,
acsc=``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~,
bel=^G, bold=\E[1m, clear=\E[H\E[2J, cr=^M,
csr=\E[%i%p1%d;%p2%dr, cub=\E[%p1%dD, cub1=^H,
cud=\E[%p1%dB, cud1=^J, cuf=\E[%p1%dC, cuf1=\E[C,
cup=\E[%i%p1%d;%p2%dH, cuu=\E[%p1%dA, cuu1=\E[A,
dch=\E[%p1%dP, dch1=\E[P, dl=\E[%p1%dM, dl1=\E[M, ed=\E[J,
el=\E[K, enacs=\E)0, home=\E[H, ht=^I, hts=\EH, il=\E[%p1%dL,
il1=\E[L, ind=^J,
is2=\E[m\E[?7h\E[4l\E>\E7\E[r\E[?1;3;4;6l\E8, kbs=^H,
kcub1=\EOD, kcud1=\EOB, kcuf1=\EOC, kcuu1=\EOA,
kdch1=\E[3~, kf1=\E[11~, kf10=\E[21~, kf11=\E[23~,
kf12=\E[24~, kf13=\E[25~, kf14=\E[26~, kf15=\E[28~,
kf16=\E[29~, kf17=\E[31~, kf18=\E[32~, kf19=\E[33~,
kf2=\E[12~, kf20=\E[34~, kf3=\E[13~, kf4=\E[14~,
kf5=\E[15~, kf6=\E[17~, kf7=\E[18~, kf8=\E[19~, kf9=\E[20~,
kfnd=\E[1~, kich1=\E[2~, kmous=\E[M, knp=\E[6~, kpp=\E[5~,
kslt=\E[4~, meml=\El, memu=\Em, op=\E[m, rc=\E8, rev=\E[7m,
ri=\EM, rmacs=^O, rmcup=\E[2J\E[?47l\E8, rmir=\E[4l,
rmkx=\E[?1l\E>, rmso=\E[m, rmul=\E[m,
rs2=\E[m\E[?7h\E[4l\E>\E7\E[r\E[?1;3;4;6l\E8, sc=\E7,
setab=\E[4%p1%dm, setaf=\E[3%p1%dm, sgr0=\E[m, smacs=^N,
smcup=\E7\E[?47h, smir=\E[4h, smkx=\E[?1h\E=, smso=\E[7m,
smul=\E[4m, tbc=\E[3g, u6=\E[%i%d;%dR, u7=\E[6n,
u8=\E[?1;2c, u9=\E[c,
That contains information about box drawing characters, code sequences generated by function keys, various cursor movement sequences, and so on.
You can find out more about X/Open Curses (v4.2) in HTML. However, that is officially obsolete, superseded by X/Open Curses v7, which you can download for free in PDF.
If you're using write just so you have low-level cursor control, I think you are using the wrong tool for the job. There are command codes for many types of terminal. VT100 codes, for example, are sequences of the form "\x1b[...", but rather than sending raw codes, you'd be much better off using a library like ncurses.

Resources