This is meant to be a tutorial in using SysOverride.
As a background, the EEPROM driver in Tiny212 and Tiny412 devices does not work properly. This unit uses the new SysOverride feature of the latest compiler version to fix the issue by replacing the faulty driver elements with correct versions.
Notice that the latest compiler version must be used and the project must be optimised. (But using AVRco without the optimiser on these devices is pretty much impossible anyway).
In the main program just add TINY_EEPROM to your uses list an make sure TINY_EEPROM is in your uses list.
If you want to share your own drivers with the community please do so here.
Regards
As a background, the EEPROM driver in Tiny212 and Tiny412 devices does not work properly. This unit uses the new SysOverride feature of the latest compiler version to fix the issue by replacing the faulty driver elements with correct versions.
Notice that the latest compiler version must be used and the project must be optimised. (But using AVRco without the optimiser on these devices is pretty much impossible anyway).
In the main program just add TINY_EEPROM to your uses list an make sure TINY_EEPROM is in your uses list.
Code
Unit TINY_EEPROM;
interface
uses;
const
type
var
implementation
type
const
{$IDATA}
var
procedure _CompleteEEWrite;
begin
asm;
;LDS _ACCBLO, 1000h ; NVMCTRLA
;CPI _ACCBLO, 013h ; are we already in Erase and write mode?
;BREQ _PrepEEWriteExit ; yes - just write
CALL SYSTEM._EEpWaitReady
LDI _ACCBHI, 000h ; CCP allow NVMCTRA to be changed
LDI _ACCBLO, 09Dh
OUT 034h, _ACCBLO
STS 1000h, _ACCBHI ; NVMCTRLA
CALL SYSTEM._EEpWaitReady
LDI _ACCBHI, 03h ;EEBRWR EEPROM Erase and Write Enable
OUT 034h, _ACCBLO
STS 1000h, _ACCBHI ; NVMCTRLA
_PrepEEWriteExit:
endasm;
end;
SysOverride WriteEEp8;
begin
// pointer in Z
// value in _ACCA
asm;
CALL SYSTEM._EEpWaitReady
ST Z, _ACCA
CALL TINY_EEPROM._CompleteEEWrite
RET
endasm;
end;
SysOverride _WriteEEp16;
begin
// pointer in Z
// value in _ACCB, _ACCA and also in _ACCCALO and _ACCCAHI, for some reason
asm;
CALL SYSTEM._EEpWaitReady
ST Z+, _ACCALO
CALL TINY_EEPROM._CompleteEEWrite
ST Z+, _ACCAHI
CALL TINY_EEPROM._CompleteEEWrite
RET
endasm;
end;
SysOverride _WriteEEp24;
begin
// pointer in Z
// value in _ACCB, _ACCA, _ACCCALO
asm;
CALL SYSTEM._EEpWaitReady
ST Z+, _ACCB
CALL TINY_EEPROM._CompleteEEWrite
ST Z+, _ACCA
CALL TINY_EEPROM._CompleteEEWrite
ST Z+, _ACCALO
CALL TINY_EEPROM._CompleteEEWrite
RET
endasm;
end;
SysOverride _WriteEEp32;
begin
// pointer in Z
// value in _ACCB, _ACCA, _ACCCALO, _ACCCAHI _ACCA and _ACCB are copies to _ACCBHI and _ACCBLO
asm;
CALL SYSTEM._EEpWaitReady
ST Z+, _ACCB
CALL TINY_EEPROM._CompleteEEWrite
ST Z+, _ACCA
CALL TINY_EEPROM._CompleteEEWrite
ST Z+, _ACCALO
CALL TINY_EEPROM._CompleteEEWrite
ST Z+, _ACCAHI
CALL TINY_EEPROM._CompleteEEWrite
RET
endasm;
end;
SysOverride _WriteEEp64;
begin
// pointer in Z
// value in _ACCB, _ACCA, _ACCCALO, _ACCCAHI, _ACCCDLO, _ACCDHI, _ACCCELO, _ACCCEHI _ACCA and _ACCB are copies to _ACCBHI and _ACCBLO
asm;
CALL SYSTEM._EEpWaitReady
ST Z+, _ACCB
CALL TINY_EEPROM._CompleteEEWrite
ST Z+, _ACCA
CALL TINY_EEPROM._CompleteEEWrite
ST Z+, _ACCALO
CALL TINY_EEPROM._CompleteEEWrite
ST Z+, _ACCAHI
CALL TINY_EEPROM._CompleteEEWrite
ST Z+, _ACCDLO
CALL TINY_EEPROM._CompleteEEWrite
ST Z+, _ACCDHI
CALL TINY_EEPROM._CompleteEEWrite
ST Z+, _ACCELO
CALL TINY_EEPROM._CompleteEEWrite
ST Z+, _ACCEHI
CALL TINY_EEPROM._CompleteEEWrite
RET
endasm;
end;
initialization
end TINY_EEPROM.
just 'USE TINY_EEPROM' the unit to fix, certainly the word issue. I don't claim that it is the complete answer.
Remember, this is a community project now. I will do what I can but you must do your part too.
Denken Sie daran, dass es sich hier um ein Gemeinschaftsprojekt handelt. Ich werde tun, was ich kann, aber Sie müssen auch Ihren Teil dazu beitragen.
Regards
interface
uses;
const
type
var
implementation
type
const
{$IDATA}
var
procedure _CompleteEEWrite;
begin
asm;
;LDS _ACCBLO, 1000h ; NVMCTRLA
;CPI _ACCBLO, 013h ; are we already in Erase and write mode?
;BREQ _PrepEEWriteExit ; yes - just write
CALL SYSTEM._EEpWaitReady
LDI _ACCBHI, 000h ; CCP allow NVMCTRA to be changed
LDI _ACCBLO, 09Dh
OUT 034h, _ACCBLO
STS 1000h, _ACCBHI ; NVMCTRLA
CALL SYSTEM._EEpWaitReady
LDI _ACCBHI, 03h ;EEBRWR EEPROM Erase and Write Enable
OUT 034h, _ACCBLO
STS 1000h, _ACCBHI ; NVMCTRLA
_PrepEEWriteExit:
endasm;
end;
SysOverride WriteEEp8;
begin
// pointer in Z
// value in _ACCA
asm;
CALL SYSTEM._EEpWaitReady
ST Z, _ACCA
CALL TINY_EEPROM._CompleteEEWrite
RET
endasm;
end;
SysOverride _WriteEEp16;
begin
// pointer in Z
// value in _ACCB, _ACCA and also in _ACCCALO and _ACCCAHI, for some reason
asm;
CALL SYSTEM._EEpWaitReady
ST Z+, _ACCALO
CALL TINY_EEPROM._CompleteEEWrite
ST Z+, _ACCAHI
CALL TINY_EEPROM._CompleteEEWrite
RET
endasm;
end;
SysOverride _WriteEEp24;
begin
// pointer in Z
// value in _ACCB, _ACCA, _ACCCALO
asm;
CALL SYSTEM._EEpWaitReady
ST Z+, _ACCB
CALL TINY_EEPROM._CompleteEEWrite
ST Z+, _ACCA
CALL TINY_EEPROM._CompleteEEWrite
ST Z+, _ACCALO
CALL TINY_EEPROM._CompleteEEWrite
RET
endasm;
end;
SysOverride _WriteEEp32;
begin
// pointer in Z
// value in _ACCB, _ACCA, _ACCCALO, _ACCCAHI _ACCA and _ACCB are copies to _ACCBHI and _ACCBLO
asm;
CALL SYSTEM._EEpWaitReady
ST Z+, _ACCB
CALL TINY_EEPROM._CompleteEEWrite
ST Z+, _ACCA
CALL TINY_EEPROM._CompleteEEWrite
ST Z+, _ACCALO
CALL TINY_EEPROM._CompleteEEWrite
ST Z+, _ACCAHI
CALL TINY_EEPROM._CompleteEEWrite
RET
endasm;
end;
SysOverride _WriteEEp64;
begin
// pointer in Z
// value in _ACCB, _ACCA, _ACCCALO, _ACCCAHI, _ACCCDLO, _ACCDHI, _ACCCELO, _ACCCEHI _ACCA and _ACCB are copies to _ACCBHI and _ACCBLO
asm;
CALL SYSTEM._EEpWaitReady
ST Z+, _ACCB
CALL TINY_EEPROM._CompleteEEWrite
ST Z+, _ACCA
CALL TINY_EEPROM._CompleteEEWrite
ST Z+, _ACCALO
CALL TINY_EEPROM._CompleteEEWrite
ST Z+, _ACCAHI
CALL TINY_EEPROM._CompleteEEWrite
ST Z+, _ACCDLO
CALL TINY_EEPROM._CompleteEEWrite
ST Z+, _ACCDHI
CALL TINY_EEPROM._CompleteEEWrite
ST Z+, _ACCELO
CALL TINY_EEPROM._CompleteEEWrite
ST Z+, _ACCEHI
CALL TINY_EEPROM._CompleteEEWrite
RET
endasm;
end;
initialization
end TINY_EEPROM.
just 'USE TINY_EEPROM' the unit to fix, certainly the word issue. I don't claim that it is the complete answer.
Remember, this is a community project now. I will do what I can but you must do your part too.
Denken Sie daran, dass es sich hier um ein Gemeinschaftsprojekt handelt. Ich werde tun, was ich kann, aber Sie müssen auch Ihren Teil dazu beitragen.
Regards
If you want to share your own drivers with the community please do so here.
Regards