Skip to content

Commit

Permalink
hexeditor for Arduino eeprom added
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisMicro committed Jan 22, 2020
1 parent 7c02251 commit 9662e36
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 24 deletions.
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,10 @@ The parameters have the following meaning
Hint: minicom can not display all graphics correctly because it supports only VT102 or ANSI and not VT220. Therefore it seems to have some problems with the colors. To solve this, change the terminal type manually to ‘ansi’. Also it seems to have some issues with the graphical symbols for lines and corners.



## Examples

### Temperature Demo
The "temperature_demo" displays bar graphs of a simulated disk storage.

<p align="center">
<img src="screenshot.png" width="640"/>
</p>

### Hex Editor Demo
### Hex Editor EEPROM Demo
Here is the "hexeditor_demo".

<p align="center">
Expand All @@ -72,5 +65,13 @@ static uint16_t memmoryStartAddress = 0x100; // ATMEGA RAM start
hexedit (memmoryStartAddress);
...
```
For detailed information see the "hexeditor_demo".
For detailed information see the "hexeditor_demo" or "hexeditor_eeprom" Arduino sketch in the examples folder.


### Temperature Demo
The "temperature_demo" displays bar graphs of a simulated disk storage.

<p align="center">
<img src="screenshot.png" width="640"/>
</p>

76 changes: 76 additions & 0 deletions examples/hexeditor_eeprom/hexeditor_eeprom.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*-----------------------------------------------------------------------------------------------------------------
How to use the hexadecimal editor of MCURSES
to edit the EEPROM values of an ARDUINO
What:
With this example you can edit the EEPROM-Memory contents of the ARDUINO.
Why:
This may be useful to change the EEPROM contents directly in the microcontroller
Hint:
to exit the editor, press two times ESC
Revision History:
V1.0 2019 01 22 ChrisMicro, initial version
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
---------------------------------------------------------------------------------------------------------------*/

#include <EEPROM.h>
#include "hexedit.h"


void Arduino_putchar(uint8_t c)
{
Serial.write(c);
}

char Arduino_getchar()
{
while (!Serial.available());
return Serial.read();
}

void Arduino_writeEEPROM(uint16_t address, uint8_t value)
{
if(address<EEPROM.length()) EEPROM.write(address, value);
}

uint8_t Arduino_readEEPROM(uint16_t address)
{
if(address<EEPROM.length()) return (uint8_t) EEPROM.read(address);
else return 0;
}

void setup()
{

Serial.begin(115200);

setFunction_putchar(Arduino_putchar); // tell the library which output channel shall be used
setFunction_getchar(Arduino_getchar); // tell the library which input channel shall be used
setFunction_readMemory(Arduino_readEEPROM);
setFunction_writeMemory(Arduino_writeEEPROM);

initscr(); // initialize mcurses

}

void loop()
{
static uint16_t memmoryStartAddress = 0;

hexedit (memmoryStartAddress);

clear();
char str[] = "hexadecimal editor stopped";
Serial.println(str);

delay(3000);
}
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name=ncurses
name=mcurses
version=0.1
author=ChrisMicro
maintainer=ChrisMicro
Expand Down
30 changes: 30 additions & 0 deletions src/hexedit.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Revision History:
* V1.0 2015 xx xx Frank Meyer, original version
* V1.1 2017 01 14 ChrisMicro, converted to Arduino example
* V1.2 2019 01 22 ChrisMicro, memory access functions can now be set
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -47,6 +48,7 @@ void hexedit(uint16_t offset);

#define IS_HEX(ch) (((ch) >= 'A' && (ch) <= 'F') || ((ch) >= 'a' && (ch) <= 'f') || ((ch) >= '0' && (ch) <= '9'))

/*
#ifdef unix
#define PEEK(x) memory[x]
#define POKE(x,v) memory[x] = (v)
Expand All @@ -55,6 +57,34 @@ unsigned char memory[65536];
#define PEEK(x) *((unsigned char *) (x))
#define POKE(x,v) *((unsigned char *) (x)) = (v)
#endif
*/
// default functions are RAM access functons by pointers
uint8_t peekMemory(uint16_t address)
{
uint8_t *p;
return p[address];
}
void pokeMemory(uint16_t address, uint8_t value)
{
uint8_t *p;
p[address]=value;
}

uint8_t (*FunctionPointer_readMemory)(uint16_t address)=peekMemory; // set default function
void (*FunctionPointer_writeMemory)(uint16_t address, uint8_t value)=pokeMemory; // set default function

#define PEEK(x) FunctionPointer_readMemory(x)
#define POKE(x,v) FunctionPointer_writeMemory(x,v)

void setFunction_readMemory(uint8_t (*functionPointer)(uint16_t address))
{
FunctionPointer_readMemory = functionPointer;
}

void setFunction_writeMemory(void (*functionPointer)(uint8_t ch))
{
FunctionPointer_writeMemory = functionPointer;
}

/*---------------------------------------------------------------------------------------------------------------------------------------------------
* itox: convert a decimal value 0-15 into hexadecimal digit
Expand Down
30 changes: 16 additions & 14 deletions src/hexedit.h
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
/*
* hexedit.h
*
* Created: 18.01.2017 08:24:04
* Author: ChrisMicro
*/
hexedit.h
Created: 18.01.2017 08:24:04
Author: ChrisMicro
*/

#ifdef __cplusplus
extern "C"
{
#endif
#endif

#ifndef HEXEDIT_H_
#define HEXEDIT_H_

#ifndef HEXEDIT_H_
#define HEXEDIT_H_
#include "mcurses.h"

#include "mcurses.h"
void hexedit (uint16_t offset);
void hexedit (uint16_t offset);
void setFunction_readMemory(uint8_t (*functionPointer)(uint16_t address));
void setFunction_writeMemory(void (*functionPointer)(uint8_t ch));

#endif /* HEXEDIT_H_ */
#endif /* HEXEDIT_H_ */

#ifdef __cplusplus
#ifdef __cplusplus
}
#endif
#endif

0 comments on commit 9662e36

Please sign in to comment.