Dick Cappels' project pages -This page, its contents and referenced files are copyright 2002 by Richard Cappels

HOME

EEPROM AND EEPROM INTERPRETER
(This is one of three pages for this project. See the bottom of this page for more)



On-Chip EEPROM

 

The 64 byte EEPROM on the ATtiny12 is accessible by the host via the DS Interface. Five of the locations within the EEPROM have been allocated, four related to the EEPROM interpreter and one for the EEPROM checksum, which is checked during chip initialization. The enrite EEPROM space may be allocated by the programmer for nonvolitile data storage for the host and for program and constant storage for the EEPROM Interpreter.

From the point of view of access via the DS Interface,the EEPROM is organized as 4 pages of 16 bytes. Only the current page is directly addressable by the DS Interface. The current page is determined by control register bits 4 and 5. The entire 64 byte space appears as one continuous block to the interpreter during execution.

Read and Write access as well as generation of a checksum, if desired, are controlled with EEPROM write comamnds ($4A commands), EEPROM read comamnds ($5A commands), and the Bless EEPROM comamnd (comamnd $7X).

Take note that the EEPROM in the ATtiny12 has a limited number of write cycles, beyond which the manufacturer does not gurantee operation. See the manufacturer's data sheet for details.

EEPROM Interpreter

The Clock/Calenadrar/Alarm chip is equipped with an intepreter that will interpret instructions stored in the 64 byte on-chip EEPROM. The interpreter can be used for simple tasks in response to power-on initialization, an alarm, an external event, or a command via the DS Interface. Each of the first three mechanisms (power-on, alarm, and external event) has a corresponding location in the EEPROM where the start address is stored, and an enable flag (zero=true) in EEPROM location zero. There is an EEPROM Interpreter Inhibit bit in the Control Register, and in order for a routine to execute, both the EEPROM inhibit bit in the control register and bit corresponding to that particular routine in EEPROM location $00 must be clear,

 

    

 

A ZERO written to a flag bit indicates that the corresponding code is present in the EEPROM.The use of a zero instead of a one to indicate that code is present stems from the fact that the EEPROM'serased state is $FF.This EEPROM location must be written by using the EEPROM write instruction ($40).
PROGRAM                           START VECTOR LOCATION        EEPROM LOCATION $00 BIT 
Power up initiization program EEPROM location $01 4
Alarm program EEPROM location $02 5
External event program EEPROM location $03 6

The bits in EEPROM location $00 corresponding to the three pre-defined events must be written with a ZERO in order to enable their respecitve pieces of code.

For example, if the only program in EEPROM memory was one to handle external events and it started at EEPROM location $20, the first four memory locations would be programmed like this:

EEPROM LOCATION         VALUE AT LOCATION         COMMENT
$00 $BF FLAG TO INDICATE EXTERNAL EVENT CODE IS PRESENT
$01 XX START UP PROGRAM -NOT PRESENT SO DON'T CARE
$02 XX ALARM PROGRAM -NOT PRESENT SO DON'T CARE
$03 $20 EXTERNAL EVENT PROGRAM STARTS AT $20

Interpreter Command set

$00   Reset clock to zero
$02 Output pin high (reset alarm)
$03 Output pin low
$04 OR [next byte] with control register
$05 AND [next byte] with control register
$0C Set Alarm to [next byte]
$0D Increment registerA
$0E Load alarm mask with [next byte]
$0F Load register A with [next byte]
$C0 Jump to [next byte] if registerA = [3rd byte]
$C1 Jump to [next byte] if registerA � [3rd byte]
$80 Jump to [next byte] unconditionally
$81 Jump to [next byte] if register = data register
$82 Jump to [next byte] if register � data register
$83 Jump to [next byte] if input pin is high
$84 Jump to [next byte] if input pin is low
$FF Stop execution of program (end of program)

$00 Reset clock to zero
Causes
all of the time registers (registeres 3 throught 8) to be set to zero and their contents to be copied to the clock's timekeeping registers. Instruction completes after the clocks' timekeeping registers have been cleared, which occurs within one second after the instruction is called.

Example program that resets the clock when the alarm is triggered


EEPROM LOCATION VALUE AT LOCATION COMMENT

$00                     $DF             FLAG TO INDICATE ALARM CODE IS PRESENT
$01 $XX START UP PROGRAM -NOT PRESENT SO DON'T CARE
$02 $03 ALARM PROGRAM STARTS AT $0A
...
$0A $00 INSTRUCTION CODE TO SET CLOCK TO ZERO
$0B $FF INSTRUCTION CODE TO STOP PROGRAM EXECUTION

$02 Output pin high (reset alarm)
$03 Output pin low

Causes the output pin (pin 1) to be set high($02) or low ($03), depending up the insturction.The output pin is open drain and needs an external pull-up.

Example program that resets the clock when the alarm is triggered


EEPROM LOCATION VALUE AT LOCATION COMMENT

$00                     $DF              FLAG TO INDICATE ALARM CODE IS PRESENT
$01 $XX START UP PROGRAM -NOT PRESENT SO DON'T CARE
$02 $0A ALARM PROGRAM STARTS AT $0A
...
$0A $02 INSTRUCTION CODE TO SET DATA OUPUT PIN HIGH
$0B $FF INSTRUCTION CODE TO STOP PROGRAM EXECUTION

 

$04 OR [next byte] with control register
$05 AND [next byte] with control register

Causes the byte in the control reigster to be replaced with the content of the control register to be ORed (in the case of instruction $05) or ANDed (in the case of instruction $05) with the constant following the instruction. Execution continues with the byte after the constant.

Exaplme program that clears the Alarm Enable flag (bit 6) in the Control Register:


$00 $DF FLAG TO INDICATE ALARM CODE IS PRESENT
$01 $XX START UP PROGRAM -NOT PRESENT SO DON'T CARE
$02 $0A ALARM PROGRAM STARTS WITH AT $0A
...
$0A $05 INSTRUCTION CODE TO AND NEXT BYTE WITH CONTROL REGISTER
$0B $BF BIT 6 OF CONTROL REGISTER CLEARED
$0C $FF INSTRUCTION TO STOP PROGRAM EXECUTION


$0C Set Alarm to [next byte]


    

Causes the six bytes following the instruction to be loaded into the alarm register. The insturction format is:

[instruction code] [year] [month] [day] [hour] [minute] [second]

Exaplme program that sets the alarm as a result of power-on initialization to Year: 2010, Month: April, Day: 15, Hour: 23, Minute: 59, Second: 59.This assumes the programmer had adopted the convention that year 00 is the year 2000. Execution resumes with the seventh address following the instruction.

$00                     $EF              FLAG TO INDICATE STARTUP CODE IS PRESENT
$01 $05 START UP PROGRAM STARTS AT $05
...
$05 $0C INSTRUCTION CODE TO SET ALARM ACCORDING TO NEXT 6 BYTES
$06 $0A YEAR
$07 $04 MONTH
$08 $0F DAY
$09 $17 HOUR
$0A $3B MINUTE
$0B $3B SECOND
$0C $FF INSTRUCTION TO STOP PROGRAM EXECUTION


A more practical use might be to set the timer for, example, July 1, which would be useful as a 6 month timer for such uses as a reminder to change the batteries in the smoke alarms, or change the furnace filters in a home.

$0D Increment registerA

Causes the the contents of resgisterA (DS Interface register 1) to be incremented by one. If the value of the data in the resigser is $FF prior to execution of this instruction, this instruction will cause the value to roll over to $00.


$0E Load alarm mask with [next byte]
$0F Load register A with [next byte]

 

Causes the Alarm Mask register (in the case of instrution $0E) or Register A (in the case of instruction $0F) to be loaded with the value contained at the address following the instruction. Execution continues with the byte after the constant.

Example program that loads register A with $00 as a result of power-on initialization.

$00                     $EF              FLAG TO INDICATE STARTUP CODE IS PRESENT
$01 $05 START UP PROGRAM STARTS AT $05
...
$05 $0F INSTRUCTION CODE TO LOAD REGISTER A WITH A CONSTANT
$06 $00 THE VALUE TO BELOADED INTO REGISTER A
$07 $FF INSTRUCTION TO STOP PROGRAM EXECUTION


$C0 Jump to [next byte] if registerA = [3rd byte]
$C1 Jump to [next byte] if registerA � [3rd byte]

Conditional jump based on a comparison of the value in registerA and a constant. Causes a jump if the value in regsiterA is eaqual to the constant (in the case of instruction $C0) or not equal (in the case of instruction $C1) constant. Execution continues at the third location following the instruction if the jump is not taken..

Example: increment register A and jump to location $20 if register = $0A after being incremented:


$00 $BF FLAG TO INDICATE EXTERNAL EVENT CODE IS PRESENT
$01 $XX START UP ADDRESS -DON'T CARE
$02 $XX ALARM PROGRAM STARTS -DON'T CARE
$02 $10 EXTERNAL EVENT CODE STARTS AT $10
...
$10 $0D INSTRUCTION TO INCREMENT REGISTERA
$11 $C0 INSTRUCTION TO JUMP IF REGISTERA EQUALS NEXT BYTE
$12 $20 JUMP ADDRESS
$13 $0A VALUE REGISTERA IS TESTED AGAINST
$14 $XX (PROGRAM CONTINUES IF REGISTERA NOT EQUAL TO $0A)
...
$20 (PROGRAM JUMPS TO HERE IF REGISTER A IS EQUAL TO $0A)

$80 Jump to [next byte] unconditionally
$81 Jump to [next byte] if registerA = data register
$82 Jump to [next byte] if registerA � data register
$83 Jump to [next byte] if input pin is high
$84 Jump to [next byte] if input pin is low

These instructions cause a jump to the address contained at the location following the instruction, provided that the assocaited condition is true.Execution resumes at the location following the constant if the jump is not taken.

Example:Jump to location $20 if the input pin (pin 7) is low.


$10 $84 INSTRUCTION TO JUMP IF INPUT PIN IS LOW
$06 $20 ADDRESS TO JUMP TO IF INPUT PIN IS LOW
$07 $XX (PROGRAM EXECUTION CONTINUES HERE IS INPUT PIN IS HIGH)
...
$20 $XX (PROGRAM EXECUTION JUMPS TO HERE IF INPUT PIN IS LOW)

$FF Stop execution of program (end of program)

When this instruction is encountered, the EEPROM Interpreter stops program execution.

 

 

Return to (click) CLOCK/CALENDAR/ALARM/EEPROM INTERPRETER OVERVIEW

Return to (click) CLOCK/CALENDAR/ALARM

Use of information presented on this page is for personal, nonprofit educational and noncommercial use only. This material (including object files) is copyrighted by Richard Cappels and may not be republished or used directly for commercial purposes. For commercial license, click HERE.

 HOME
Please see the liability disclaimer on the HOME page.
Contents ©2002 Richard Cappels All Rights Reserved. http://www.projects.cappels.org/