How reading data from the internal Flash memory of the ATtiny2313 ?
This AVR has 2k (2048 bytes) of Flash memory. Flash memory can be written for 1000 times quaranteed (probably 10 times more) This memory can be used for two purposes, program storage or data storage, or both. When you want to store all ASCII characters (I will take the ASCII set of the SLO2016), that are 0 to 127 = 128 characters in, you need 128 x 5 bytes = 640 bytes of memory space) Here a few characters on the dotmatrix display:

Here a few of the 128 symbols of the ASCII set now in Flash memory.
The AVR is not an extremely complecated microcontroller, simply put a table at the end of your code, like this:
.CSEG
ASCII:
.db 0b01111111,0b00001001 ;char0
.db 0b00011001,0b00101001 ;char0
.db 0b01000110,'#' ;char0
This data presents one ASCII sign (the R) The Flash memory is 16bit wide, I did split the table up this way, so you can see the rowsdata very clearly. The '#' sign is the end symbol, in the routine you can do a compare:
cpi data, '#'
When it reaches this point, let the routine branch to another routine, or back to the mainloop, whatever. Or you can set an end label, at the end of the ASCII table, like this:
.db 0b01000110,0b00110010
end_ASCII:
Remember that when the Z pointers are at end of the table, they are exually sitting on top of the label 'end_ASCII', and that means the data you read are all 1's, because at init Flash was filled with 1's. Now you wonder, how can you walk through the Flash memory ? First you must initialize the Z pointers (set them at begin table), use these two lines of assembly:
ldi ZL, LOW(ASCII*2) ;set Low memory pointer
ldi ZH, HIGH(ASCII*2) ;set High memory pointer
You can see clearly the Low and High pointer. Now you can use an instruction called 'lpm' (load program memory) for reading the data from the internal Flash memory of the AVR, the reading starts right away from the label called 'ASCII:' The data from the table will be stored in r0 (first register of the AT90S2313), 'lpm' does this. Once it's in r0, you can use it in your program, you can set the data e.i. to PORTB, like this:
lpm ;loads the data in r0
out PORTB, data ;sets the data at PORTB pins
Don't forget to define 'data' , so:
.def data = r0
Now you still wonder, how can I fetch the next byte from the Flash memory ? You can use:
inc ZL ;increases Lower pointer by one
This line will fetch from the next low address in memory. It is not nessesary to organize the memory, simply put the table at the end of the program. When the program gets larger the data will be shifted forward automatically by the assembler. The assembler will give an errormessage when the end of the memory is reached. With this trick you have to be carefull, your table can't be to long, because when the low byte (ZL) will continue adding up, the high byte (ZH) will stay the same the whole time, and then you've got a major problem! So than use this:
adiw ZL, 1 ;increases Z pointers by one
I.e. suppose you start at 0x02FA (02 = high byte; ZH, FA = low byte; ZL), when reaching 0x02FF, it should go to 0x0300, but if you only use ZL it will go back to 0x0200 instead of 0x0300! Here an example program, which blinks two LEDs (or when the '#' is changed from postion it will walk 8 LEDs on PORTB) from memory. Here the SLO2016 ASCII set which I'm gonna use :)

The table consists of 128 characters (128 x 5 bytes x 8 bits = 5120 bits totall)
With the 128 bytes internal EEPROM of the AT90S2313 you can store up to 128 characters max. , not very much text can be stored, but enough for a short message, little story, anouncement, a few prices of some products i.e. , valuta courses, etc. So the number 65 (0x41) stored in EEPROM will display the 'A' , etc. You can take the rest of the Flash memory for permanent words or special characters, just make another table. The permanent words can be a few standard words, this saves editing.
How to store/load data from and to the internal SRAM memory of the AT90S2313 ?
First of all, RAM = Random Access Memory, S means Static. There are to ways to do this. One is direct, the other is indirect by means of the so called Y pointers (YL and YH) Remember that the data in SRAM will be gone when you take the power off the AT90S2313. In this example the indirect methode. The SRAM area for the AT90S2313 starts at location $60 = 0x0060 = 0x60, so first define this number:
.equ SRAM = 0x60
Next setup the Y pointer:
ldi YL, SRAM ;set memory pointer
Now the Y pointer is set to SRAM location 0x60 (start of SRAM) How can I store data in an SRAM location ? This is very simple. Suppose you want to store temporary (one byte) data in the first SRAM location, then do this:
st Y, temp ;store data in SRAM
Now the data in the register 'temp' sits in the first SRAM location, because the Y pointer was set to that position in the first place. Now how can I store the same temporary data in the 2nd SRAM location ? Simply increase the Y pointer, or even simpler, use the '+' sign, like this:
st Y+, temp ;store data in next SRAM location
The '+' sign means move Y one position upwards, if you wanna go downwards, then use the '-' sign, but in front of the Y:
st -Y, temp ;store data in one SRAM location lower
So now you can move the Y pointer up- or downwards. Now how to read data back from SRAM in a register ? Use the instruction LD (load):
ld temp, Y ;load data from SRAM
You again can use the parameters '+' or '-' . What also can be used are two other instructions STD and LDD (indirect store/load), with these two you can very easely store/load data to/from any location without changing the Y pointer's position. The Y pointer will come back to the last set position. Here an example:
ldd temp, Y+1 ;load Y+1 into temp
std Y+0, temp ;store temp into Y+0
Y+1 means; load/store from/to one position upward in memory, you can also use names instead of numbers:
.equ value = 6
std Y+value, data ;store data into Y+value (Y+6)
Change the position of the Y pointers with:
adiw YL, 1 ;move Y pointers one position upward
or
sbiw YL, 1 ;move Y pointers one position downward
On the next pages you will find more about this moving message sign project....
[back to top]