16 Jul 2012

usart problem 2!!!!!!!!!!!!!!!!!!!!!!!!!!!1

The main reason that minicom why serial programs we get errors is before you transmit or receive you should check the following conditions:

1. Baud rate 
2. Frequency

these two things should be same in the program and in the minicom if you are transmitting the program with the baud rate of 9600 and you have configured the baud rate of the minicom as the 115200 what do you think you will get output. You will get the junk values in the terminal . In order to get sync with the transmission you should make it 9600 in the hyperterminal. In detail i will should you my errors and how did i rectify them.

see the program which i have programmed has the baud rate of 9600 bits per second and i configured the terminal as the 115200 bits per second . So no sync in between both of them . So you get the following output.

usart junk value due mismatch sync

So in order to get your data as the data you are transmitting in the program if there is sync or have baud rate same then you get the transmission as below

 How to configure the baudrate in minicom

 open minicom using the minicom -s before you do this connect serial port with serial wire. And as i explained in previous post in detail here lets discuss how to change the baudrate

Assume previously you have the baudrate of 115200 and you need to change it to 9600 .
Now change the baudrate what you need.

 you press 'C' for 9600 baud rate and then press ESC now you will see your baud rate


You got your required baudrate so continue working with your application . 
And also make that hardware / software flow control : NO
enjoy..................


                                    PROBLEM3

 







minicom problems!!!!!!!!!!!!!!!!!

(usart )
Common problems and solutions :

Q. Trying to open minicom to complete the installation and i keep getting is  "minicom : cannot open /dev/tty8 : Permission denied "
Sol : Type minicom -s  and change the port of access to /dev/ttyUSB0


use the command  minicom -s as shown


and then change the port name which is showing the as permission denied to /dev/ttyUSB0 and your frequency as required by default hardware/software flow control should be : NO


now press A to change the port  this is the default port which is showing permission denied. Now you need to change it so


press A  and type /dev/ttyUSB0 in the place of the ttyS0 or something .

Now change hardware flow control to NO if it is already unselected then leave it.  Press ESC for comming out of those selections.

Even though it doesn't open minicom then first connect the serial port for the board and try the whole thing again .

Now you get your minicom to work . enjoy .................

Problem2 : Baudrate selection config 

XMODEM PROTOCOL

XMODEM USING MINICOM: 

XMODEM is one of the serial communication protocols which is used to write/read  the data to/from microcontroller serially. So in order to do that you need to have some medium to communicate that medium is xmodem .

XMODEM is used to transmit the files to/from PC.

This is having many models like:
1. XMODEM - CRC
2. XMODEM - CHECKSUM
3. XMODEM - 1K
4. XMODEM - 1KG

Firstly lets discuss about XMODEM - CRC  in detail as we are using it presently:

You send your data in the form of packets :
A Packet consists of

1. Start of header           <   soh    >     1 byte
2. Packet number           <   pk no >     1 byte
3. ~Packet number        <~(pk no)>    1 byte
4. 128 bytes of data       <   data    > 128byte
5. 2 bytes of check sum <    crc     >     2byte
                                                            -------------
                                                            133 byte
                                                            -------------
In this protocol the data packet is in the format :


The file is divided into packets and send according to acknowledgements . Before sending another packet acknowledgement should be sent to say that we received the packet successfully or return No Acknowledgement so that the same packet will be retransmitted .

Packet number starts from value 1 and goes upto 255 and then start from 0 . 
Checksum is calculated by taking a 256 modulus of the sum of all ASCII values of each of 128 bytes in the data block.

The data flow is given :


The receiver will be sending 'C' to transmitter i.e:XMODEM to say that i am ready to receive data waits for 3 seconds and then timeout and again resend 'C' this will be continuing  until we receive data.

If we get the data then send the acknowledgement to the minicom so that xmodem will come to know that packet was received successfully and then this continues and if something goes wrong some error in the packet or not received it sends <NAK> (No Acknowledgement ) so that it transmit the same packet to the receiver. 

To verify that whole data is transmitted it sends EOT at the end which is nothing but End Of Transmission we should be checking for EOT. 

At receiver side you should build the code to receive the data don't bother about transmission as it is simple it is done by the hyperterminal. I will show you this clearly in next post.

In next post we will discuss about the XMODEM - checksum it is similar as the crc little changes were present.

9 Jul 2012

LocK Bits in detail

LOCK BITS :

          Before we discuss these bits lets take a practical example in day to day life until now we are dealing with the byke example right . we discussed fuses are like gares which are used to ride the microcontroller and in the same way you protect your byke with a Lock right to protect it from being stolen . In the same way you have your developed a project and now you burn this code to the microcontroller there are chances that someone can hack your code from it right so in order to protect your code you lock your microcontroller after all the code is written one time . so that others cannot steel your code.

You have different combination of locks over here for that You refer the data sheet MEMORY PROGRAMMING section you will mostly find this information at the beginning itself ok.

Real time scenario:
           Ya assume that you wrote a bootloader . Now your bootloader is writting your application section from bootloader section so while writting you should be careful that it never erases or never writes into the bootloader section so you need to lock that perticular section in order to disable the access to that section ok. Now By using the lock bits you can do this protection .

Ya i will explain you the lock bits in atmega8 ok......

Same way as fuse bits here also
0 --> Programmed
1 --> Unprogrammed

Lock bits are 6 in number
     ------               Reserved
     ------               Reserved
1. BLB12   --      1
2. BLB11   --      1
3. BLB02   --      1
4. BLB01   --      1
5. BL2       --      1 
6. BL1       --      1

Selecting the BL2  & BL1 is based on your requirement the below values you use
                        1          1          -->    No memory lock features
                        1          0          -->    Disable programming Flash and EEPROM
                        0          1          -->    Disable programming and verification of Flash and EEPROM in any mode.

In the same way comes
BLB02 &BLB01 (APPLICATION PART)
    1             1            -->   No restrictions for SPM or LPM for accessing APP sec.
    1             0            -->   SPM NO write to APP sec.
    0             0            -->   1. NO write to APP sec by the SPM.
                                         2. LPM executing from the bootloader section is not allowed to read from APP sec.
                                         3. If Interrupt vectors are placed in BOOT  sec interrupts are disabled while executing from the APP section.
    0             1            -->    only ( 2 ) & ( 3 ) points are enabled.   

BLB12 & BLB11  (BOOTLOADER PART):
    1             1            -->   

      



LoW FuSe bits

LOW FUSE BITS:

     As i explained what are the uses of fuses and how they are to be used now we will only discuss what LOW FUSE BITS are used for .


         FUSES            DEFAULT settings
     1. BODLEVEL   ----    1
     2. BODEN         ----    1
     3. SUT1             ----    1
     4. SUT0             ----    0
     5. CKSEL3        ----    0
     6. CKSEL2        ----    0
     7. CKSEL1        ----    0
     8. CKSEL0        ----    1

BODLEVEL  --   This fuse bit we set when we need the brown out detector. Like you have a application which should Reset when the input voltage is less than 4.5 V and another as when ever the voltage goes below 2.7 V it should get reset .

So, the first requirement can be achieved without enabling this fuse you get the trigger level of 4.5V and for second requirement you need to enable or program the fuse to '0' so that trigger level changes to 2.7V (this is used when you need you circuit to work even you have voltage less than 5 . In some conditions it require .

BODEN        - - This fuse bit we set for enabling the Brown Out Detector .

SUT1  ,  SUT0   :
                       This by default setted to the maximum startup time. In order to change the startup time we use them. There are different levels of startups you should refer datasheet in clock source section . Based on your application you should program these bits

CKSEL3 , CKSEL2, CKSEL1, CKSEL0 :

                       These fuses are used for selecting the frequency of the clock at which it should run . For different frequencies these fuses changes same as i said garing the microcontroller before it starts working. These fuse bits are like gares if you don't gare them properly you may loose your microcontroller or it may not work as you like it to work.

Finally what i mean to tell Read these bits clearly in data before you program it because you may messed up with the fuse setting some time so before setting fuse bits make  yourself  comfortable before you decided to write them on MC . ok

At beginning it looks like it is difficult once when you are some practice you automatically program for what ever you require ok.

Learn them well .........................................

How to work with them in avrdude :   click here

After this will go  to Lock bits which are also important to be discussed  in next tutorial . Link to Lock bits

8 Jul 2012

FuSe Bits and their functionality

Hai.........
Lets discuss about the Fuse bits which are perticularly important in atmega or avr microcontrollers .

Ya i will give some example to understand clearly i know that most of us know bike or car to ride right so lets think you have a bike and you need to ride it that has gares ok so you sit on bike and start it after that in order to move you need to step into bike/car and give your first gare to move the vehicle right in the same there are some conditions to be met in order to run the avr microcontroller . Even though you write program into microcontroller you need to gare it with fuse bits . We should give the clear gares how to work . ok

Now lets come to the atmega8 here you have fuses bits which are
  1. High fuse bits  (8 bits)
  2. Low fuse bits (8 bits)
and there are some other bits named  "EXTENDED FUSE BITS " which are not present in this microcontroller for some controllers with high performance have these bits depending on their working same as having different set of gares for different capacity bikes .

By Default the fuse bits are set to some value. you can check it by using the commands listed in the below 

Here the value 1 indicates the "UNPROGRAMMED"
                         0 indicates  "PROGRAMMED"

High Fuse Bits:
I will give you the high fuse bits which are present in the atmega8
         Bits                            Default values
  • RSTDISBL     -->        1
  • WDTON         -->        1
  • SPIEN           -->         0
  • CKOPT          -->         1
  • EESAVE        -->         1
  • BOOTSZ1      -->         0
  • BOOTSZ0      -->         0
  • BOOTRST     -->          1
So , these are the fuse bits which are called HIGH FUSE BITS.
WDTON   --  This bit is programmed when we use the watch dog timer i.e the watch dog timer doesn't work perfectly if you don't enable this if you are using the predefined library functions.
                   [WATCH DOG TIMER RELATED BIT]
SPIEN     -- This fuse should be programmed when you are using the serial peripheral interconnect protocol and This must be always enabled if you want to communicate through this interface.
               note:  Never ever make this bit unprogrammed until you think you don,t need but you never come to this . I prefer not to touch this bit at all. let this be programmed.
                   [ SPI RELATED BIT]

CKOPT    --  This fuse is used to select whether you need the internal clock or external clock to your microcontroller. In order to understand this clearly you should be clear with clock concept and what bits are related to the clock.
                   [CLOCK RELATED BIT]


EESAVE  --  This is used while EEPROM programming . we think if we just used the EEPROM related registers and dump the values we needed into the eeprom it will store the values right no this concept some what different you should enable the EESAVE gare like gare of a byke and then program the eeprom values into the microcontroller eeprom. ok
So, what  you do is write program and burn the hex file and then set the fuses.

BOOTSZ0, BOOTSZ1:
                     In breif microcontroller has two sections in memory locations
                     1. Application and
                     2. Bootloader section
lets about these things in detail in next coming tutorials .
These fuses are used to configure the size of the bootloader and flash they are specified in the data sheet different microcontrollers have different locations and sizes.
            Bootloader concept is a vast subject so upto to now know this only you can write the flash to itself using it . In this section all store program memory commands are executed  and in application section load program memory instructions are executed i.e: reads the falsh that it it couldn't write to flash are.
   Bootloader section    --- write to flash area of its own
   Application section   ---  Reads the flash and execute the written program .

BOOTRST -- This fuse bit is used for selecting reset position. As i said flash will have two sections . So, Two sections means we can set the RESET position to bootloader or application section. Lets say you need when ever you reset you should activate your bootloader section then PROGRAM this bit else if you want your application itself to execute after the RESET is pressed then it jumps to the location of application section 0x0000 where your application program is written.
             Reset vector to bootloader section  ---  0   (programmed)
             Reset vector to application section  ---  1  (unprogrammed)
How to burn the fuse bits: click here

You can Read next tutorial for the Low fuse bits
                                          

5 Jul 2012

General compiling steps & Library creation

General Steps of compilation of C file:

               \ /
                |                 .c    
                |                  |
      Preprocessing      |                gcc -E file.c
                |                 .i
                |                  |
        Compiling           |               gcc -c file.c
                |                 .s
                |                  |
       Assembler           |               gcc -S file.c
                |                 .o (asm)
                |                  |
          Linker              |      
                |                .exe
                |
          executable                       gcc  file.c  -o  foo



   General execution:
               
               gcc file.c                -->  gives executable file
               gcc  -c  file.c          -->  gives the object file

Creating the Dynamic and Static Libraries  :

 Static Library:
    Static library has the extention of  (.a) . You should know that when ever you call the function of this library the whole code is dumped into the main code while compilation time so that the whole size of the program increases but the execution speed increases. But the main requirement is the file should be small and the speed should be also fast right . so we go to the dynamic libraries.
   Ok lets discuss how to create a static library and how to link it to the required file.


1. All file first make them as object files using the command 
                gcc   -c  file1.c file2.c       -->   file1.o  file2.o
2. Now you create using this object files your static library file
               ar cr  libswap.a  file1.o file2.o   --> gives the output of libswap.a  
3. Now you have created the library now link it to the main program
               gcc -Wall main.c  libswap.a  -o  swap
      The above command tells that main in linked with libswap.a  library and executable is renamed as the swap if the library (.a) is in the same file other wise you should give the path of the library file where it is located. This i will dicuss in the dynamic library. ok just here i showed creating and linking the main and library in the same file.


Dynamic Library:
    The good thing about this is when a function is called then pointer goes to the location where it is located and execute over there and come back to the main when it is done with the function . It just saves lot of memory and execution speed is also good.That is why most of the operating systems like unix and linux uses such type of libraries mostly.


    So lets learn how to create the Dynamic Libraries:
1. gcc -shared  -fPIC  -I ../../include   swap1.c  -o  ../../library/libswap.so 
          Ya now i feel you feel some difficulty its very simple i will tell you 
-shared   -->  is used to produce shared object which can be linked with other objects to form an executable.
-fPIC      -->  compiler directive to output position independent   code

2. gcc  -I  ../include/   -lswap  -L ../Library/  swap_main.c  -o  swap_main

here it tells that including the folder name where the .h files are located and linking the library where it is located (the folder paths we should specify from current directory) thats it very simple na. 

Don't still deep into it you should know one thing in embedded field or any other field read only what is required . Don't try read the whole stuff from scratch it will be helpful but you will loose your valuable time which is precious if you don't have any work like targets then you can.
 
              

4 Jul 2012

Reading from Flash is little Endian style

Suppose  You have a hex line as show below
     : 10 0000 00 0C9434000C944F000C944F00 4F

The machine instruction 940C is saved in the .hex file as 0C94 ok

CODE:  in hex file
0x0000: 0C
0x0001: 94
0x0002: 34
0x0003: 00
0x0004: 0C
0x0005: 94
0x0006: 4F
0x0007: 00
0x0008: 0C
0x0009: 94
0x000A: 4F
0x000B: 00

How ever when you switch on the power to an avr it makes 16bit opcode fetch which is little- endian. Finally it reads the code in:
0x0000  : 0c
0x0001  : 94

as 0x940C  and passes it to the instruction decoder which identifies it as a jump op code . This again  make a second fetch as part of this same opcode this time it picks up

0x0002  :  34
0x0003  :  00

which again it reads as little endian and therefore treats as WORD address 0x0034 (which is BYTE address 0x0068). So after reading the first 4 bytes in two 16 bits chunk it has determined it has "JMP 0x0068" and sets PC to be that address. (really 0x0034 in fact - it's just GCC that interprets things byte wise to be common across all architectures).

So, the bytes are programmed in exactly the order they appear in the .hex at increasing byte addresses but when the AVR core makes fetches (two bytes, 16bits at a time it treats them as  little endian using the lower addressed of the two bytes as the lower part of each 16bit fetch. So it's not when programming hex that little endian ness comes into play - it's when the data/code is later fetched back from the flash that the endianness issue applies.

So, finally you can say that data or code is fetched in little endian model.

Hex file format and how to read it?



Using Vi editor you could open this .hex file in previous section i showed you how to create a hex file and now we are going to learn how to read a hex file.
What all the things it consists you will learn.

$ vi file.hex

Now you could see the first line in the picture that is represented in the form

:10 0000  00 8F EF 87 BB 18 BA 60 E0 81 E0 90 E0 E7 E0 F0 E0 B6

RED : Indicates the number of bytes is being written

BLUE : Indicates the starting address of the data being written

yellow: indicates the type of record . These were of 5 types:
             1. 00  -->  data record
             2. 01  -->  end of the record
             3. 02  -->  extended segment address record
             4. 04  -->  extended linear address record
             5. 05  -->  start linear address record

Blue : indicates the data

Black: indicates the checksum .

Now lets discuss about the checksum how it is calculated.
suppose you have the hex line give below:
:02 0000 02 1400  E8
Its nothing but 2's complement of whole except the checksum because we are calculating it right.


    now 01h+(~(02h + 00h + 00h + 02h + 14h +00h))
                   0000 0010 = 02h
                   0000 0000 = 00h
                   0000 0000 = 00h
                   0000 0010 = 02h
                   0001 0100 = 14h
                   0000 0000 = 00h  (+)
                  -----------------------------
                ~(0001 1000 )  =  1110 0111
                                              0000 0001 (+)
                  -------------------------------------------------------
                                               1110 1000 = E8 checksum
                  -------------------------------------------------------
          For all the lines it is in the same way take the whole line add up all the bytes until checksum and do 1s compliment for the result and then add the 01h the complement of result so that you will get the checksum .
        
I hope everyone got how the checksum is calculated right .
--------------------------------------------------------------------------------------------------------------------
Now lets discuss in detail about the type of records in detail ok. Lets go ........

Type 00 Record
          
              As i told you this will indicate the record is of data type so the type tells that it is the data record .
               This thing no need to tell in detail . This basic information is enough to understand ok.

Type 01 Record
           
               This record tells that it is the end of the record so this will be the last line in all hex file what ever it matters until you do something wrong .
                A perfectly executed hex file will have perfect format what i am describing here.
                And here checksum is calculated in the form:
                                     :00000001 FF
        This is calculated like this 01h+(~(00+00+00+01) )= 0xFF
The address in the end of record is meaning less so we can ignore it.

Type 02 Record   (Extended segment address record)


         1. Extended segment address record is also called HEX-86 record.
           2. Always have two data bytes and appear as follows

                        :02 0000 02 1400   E8
           3. Address field is always 0000h
         
Now the real part comes when an extended segment address record is read, the extended segment address  stored in the data field is saved and is applied to subsequent records read from the Intel HEX file. The segment address remains effective until changed by another extended address record.

The absolute-memory address of a data record is obtained by adding the address field in the record to the shifted-address data from the extended segment address record. The following example illustrates this process.

Address from data record's address field  =           2340
Extended segment address rec data field   =        1400
                                                                        -------------------
Absolute memory address                                00016340
                                                                        -------------------


Type 04 Record: (Extended linear Address Record)
         
         1. it is called 32-bit address records and Hex386 records.
         2. The upper 16bits (16-31) contains address of data .
    The extended linear address record  always have two data bytes and appears as follows:
                         :02 0000 04 FFFF FC
          FFFF   --> upper 16 bits of address
When an extended linear address record is read, the extended linear address stored in the data field is saved and is applied to subsequent records read from the Intel Hex file. The linear address remains effective until changed by another extended address record.

The absolute-memory address of a data record is obtained by adding the address field in the record to the shifted address data from the extended linear address record. The following example illustrates this process.

Address from the data record's address field =           2360
Extended linear address record data field      =  FFFF
                                                                            --------------------
Absolute-memory address                               =  FFFF2360   (32 bit)
                                                                            --------------------


Type 05 Record : Start linear address record .
       
          1. Only for MDK-ARM
          2. Specify the start address of the application
          3. contains 32 bit address (always 4 data bytes ) appear as
                   :04 0000 05 000000CD 2A

         000000CD --> starting address of the application.

Start linear address specifies the address of the __main(pre-main) function but not the address of the startup code which usually calls __main after calling Systeminit().
                    An odd linear start address specifies that  __main is compiled for the Thumb instruction set.

                    The start linear address Record can appear anywhere in hex file. In most cases this record can be ignored because it does not contain information which is needed to program flash memory .





3 Jul 2012

Creating the binary file and see how it is represented

#include <avr/io.h>
int main()
{
       DDRB = 0xFF;
       while (1)
       {
              PORTB ^=0xFF;
        }

}

So this is your file.c and you wana create the binary format of this file use this command:
avr-objcopy    -I  binary   -O   ihex  file.c   file.hex

so that you can see the output in the hexadecimal but it represents the binary values only.

see this for clear understanding:
:10 0000  00  23 69 6E 63 6C 75 64 65 20 3C 61 76 72 2F 69 6F 3D
                      #    i    n   c   l    u    d  e   '  '  <   a   v   r    /    i    o

:10 0010  00  2E 68 3E 0D 0A 0D 0A 69 6E 74 50 6D 61 69 6E 28 A6
                       .    h    >  \r   \n   \r   \n   i   n    t   ' '   m  a   i    n    (

:10 0020  00  76 6F 69 64 29 20 7B 0D 0A 09 44 44 52 42 20 3D C1
                       v   o   i    d    )  ' '    {   \r   \n   \t  D  D   R   B  ' '   =

:10 0030  00  20 30 78 46 46 3B 0D 0A 09 77 68 69 6C 65 20 28 B0
                      '  '  0   x    F  F   ;     \r  \n   \t   w  h   i    l    e   ' '   (

:10 0040  00  31 29 20 7B 0D 0A 09 09 50 4F 52 54 42 20 5E 3D  50
                       1   )   '  '  {    \r   \n  \t   \t  P   O   R   T  B  '  '  ^   =

:10 0050  00  30 78 46 46 3B 0D 0A 09 7D 0D 0A 7D 0D 0A EB
                      

Steps for compilation using usbasp programmer

______________________________________________________________________
Compilation steps using avrdude:
----------------------------------------------------------------------------------------------------------------
avr-gcc   -g   -Os   -mmcu=atmega8  -c   file.c
avr-gcc   file.o    -o  file
avr-objcopy   -j .text  -j  .data   -O  ihex  file   file.hex
avrdude    -c  usbasp  -p  m8  -U  file.hex
option of gcc and objcopy:

-g          --> for debugging symbols
-Os        --> for optimisation of the program there are 4 levels in the place of ' s ' you can place 1, 2, 3 , 4.
-c          -->  for the object file creation
-o          -->  Renaming the elf file or executable
-j           -->  used for the seperation of the section from the elf file
ihex       -->  is used to create the hex file 
options for avrdude :

-c          -->  to tell the microcontrollerthat is the programmer  being used
-p          -->  to tell the microcontroller which is being used
-U          -->  to tell that perticular file to be burnt or written.
______________________________________________________________________
Setting the fuse bit commands :
----------------------------------------------------------------------------------------------------------------
Writing fuses :
      avrdude   -c  usbasp  -p  m8  -U   lfuse:w:0xD9:m  -U  hfuse:w:0xD1:m

Reading fuses :
avrdude -v   -c  usbasp  -p  m8  -U  lfuse:r:low.txt:r  -U  hfuse:r:high.txt:r

Never ever make SPI fuse to '1' if you make it you couldn't program your microcontroller as it dissables the function. Again using Parallel programmer you should make that pin as high which is very costly . so , never even try doing this ok. if you have parallel programmer try this otherwise no need.

Once you did this its no use until you reprogram it . you couldn't do this with your programmer because your programmer itself is not read by the microcontroller if you dissable that pin. so be carefull.
________________________________________________________________________
Setting the lock bits :
-------------------------------------------------------------------------------------------------------------------
Same as the fuse bits programming but these bits have special feature that it can protect your application section and bootloader section as well preventing others to see your hex file or not even to read the sections . Nice know but we don't use at present . so lets go into how to compile

avrdude   -c  usbasp  -p  m8  -U  lock:w:0x3f:m 
_________________________________________________________________________
EEPROM PROGRAMMING :
---------------------------------------------------------------------------------------------------------------------
In order to make eeprom perfectly work you should make EESAVE fuse bit programmed . EESAVE = '0'.
If you don't make it programmed and even though you store the values at the eeprom they doen't store they will also be get erased while flash write . everything will be cleared. so in order to tell the microcontroller to no clear the eeprom we use EESAVE fuse bit which will be present in high fuse. 

Keep this in mind while you are programming an eeprom program . 
Lets deal with this section someother time in detail.ok .i hope in this session you learnt how to compile the file .

Here are the Steps for creating the binary file of a perticular file see this POST


sample .hex written in microcontroller (format in which it is written)

      enable program mode
      signature bits 
      fuse and lock bits
     eeprom bytes  
      chip erase 
      write to flash 
      page write
 AC530000 30000000 30000100 30000200 50000000 50000000 50000000 58080000 58080000 58080000 A001FC00 A001FD00 A001FE00 A001FF00 AC800000 AC530000
chiperase pm-mode
----------------------------------------------------------------------------------------------------------------------------------------------------
 4000 0022 4800 00C0     4000 0134 4800 01C0 4000 0233 4800 02C0 4000 0332 4800 03C0 4000 0431
  wr flash addr0000         addr    0001           addr 0002       addr 0003
 4800 04C0 4000 0530 4800 05C0 40 00 06 2F 48 00 06 C0 40 00 07 2E 48 00 07 C0 40 00 08 2D 48 00 08 C0 40 00 09 2C 48 00 09 C0 40 00 0A 2B 48 00
 0A C0 40 00 0B 2A 48 00 0B C0 40 00 0C 29 48 00 0C C0 40 00 0D 28 48 00 0D C0 40 00 0E 27 48 00 0E C0 40 00 0F 26 48 00 0F C0 40 00 10 25 48 00 10 C0
 40 00 11 24 48 00 11 C0 40 00 12 23 48 00 12 C0 40 00 13 4A 48 00 13 C0 40 00 14 4B 48 00 14 C0 40 00 15 4C 48 00 15 C0 40 00 16 4D 48 00 16 C0 40 00
 17 4E 48 00 17 C0 40 00 18 4F 48 00 18 C0 40 00 19 50 48 00 19 C0 40 00 1A 51 48 00 1A C0 40 00 1B 52 48 00 1B C0 40 00 1C 53 48 00 1C C0 40 00 1D 54
 48 00 1D C0 40 00 1E 55 48 00 1E C0 40 00 1F 56 48 00 1F C0 --4C001F00--28001F00--

 40002057 4800 20C0 4000 2158 4800 21 C0 40 00 22 59 48 00 22 C0 40 00 23 11 48 00 23 24 40 00 24 1F 48 00 24 BE 40 00 25 CF 48 00 25 E5 40 00 26 D4 48 00 26 E0 40 00 27 DE 48 00 27 BF 40 00 28 CD 48 00 28 BF 40 00 29 10 48 00 29 E0 40 00 2A A0 48 00 2A E6 40 00 2B B0 48 00 2B E0 40 00 2C E2 48 00 2C EB 40 00 2D F1 48 00 2D E0 40 00 2E 02 48 00 2E C0 40 00 2F 05 48 00 2F 90 40 00 30 0D 48 00 30 92 40 00 31 A0 48 00 31 36 40 00 32 B1 48 00 32 07 40 00 33 D9 48 00 33 F7 40 00 34 4C 48 00 34 D0 40 00 35 A1 48 00 35 C0 40 00 36 C9 48 00 36 CF 40 00 37 9B 48 00 37 01 40 00 38 AC 48 00 38 01 40 00 39 60 48 00 39 5C 40 00 3A 7D 48 00 3A 4B 40 00 3B 80 48 00 3B 4F 40 00 3C 9F 48 00 3C 4F 40 00 3D F3 48 00 3D E0 40 00 3E 66 48 00 3E 0F 40 00 3F 77 48 00 3F 1F --4C003F00--28003F00-- 40 00 40 88 48 00 40 1F
                                                        prg memory   
 40 00 41 99 48 00 41 1F 40 00 42 FA 48 00 42 95 40 00 43 D1 48 00 43 F7 40 00 44 E4 48 00 44 E0 40 00 45 22 48 00 45 0F 40 00 46 33 48 00 46 1F 40 00
 47 44 48 00 47 1F 40 00 48 55 48 00 48 1F 40 00 49 EA 48 00 49 95 40 00 4A D1 48 00 4A F7 40 00 4B 69 48 00 4B D0 40 00 4C 21 48 00 4C 50 40 00 4D 30
 48 00 4D 40 40 00 4E 1B 48 00 4E B8 40 00 4F 88 48 00 4F E1 40 00 50 8A 48 00 50 B9 40 00 51 86 48 00 51 E8 40 00 52 80 48 00 52 BD 40 00 53 30 48 00
 53 BD 40 00 54 29 48 00 54 B9 40 00 55 08 48 00 55 95 40 00 56 E8 48 00 56 2F 40 00 57 F0 48 00 57 E0 40 00 58 E0 48 00 58 31 40 00 59 F1 48 00 59 05
 40 00 5A 10 48 00 5A F5 40 00 5B ED 48 00 5B 5E 40 00 5C FF 48 00 5C 4F 40 00 5D 09 48 00 5D 94 40 00 5E 80 48 00 5E E3 40 00 5F 1D 48 00 5F C0 --4C005F00=28005F00-- 40 00 60 81 48 00 60 E3 40 00 61 1B 48 00 61 C0 40 00 62 82 48 00 62 E3 40 00 63 19 48 00 63 C0 40 00 64 83 48 00 64 E3 40 00 65 17
 48 00 65 C0 40 00 66 84 48 00 66 E3 40 00 67 15 48 00 67 C0 40 00 68 85 48 00 68 E3 40 00 69 13 48 00 69 C0 40 00 6A 86 48 00 6A E3 40 00 6B 11 48 00
 6B C0 40 00 6C 87 48 00 6C E3 40 00 6D 0F 48 00 6D C0 40 00 6E 88 48 00 6E E3 40 00 6F 0D 48 00 6F C0 40 00 70 89 48 00 70 E3 40 00 71 0B 48 00 71 C0
 40 00 72 81 48 00 72 E4 40 00 73 09 48 00 73 C0 40 00 74 82 48 00 74 E4 40 00 75 07 48 00 75 C0 40 00 76 83 48 00 76 E4 40 00 77 05 48 00 77 C0 40 00
 78 84 48 00 78 E4 40 00 79 03 48 00 79 C0 40 00 7A 85 48 00 7A E4 40 00 7B 01 48 00 7B C0 40 00 7C 86 48 00 7C E4 40 00 7D 5D 48 00 7D 9B 40 00 7E FE
 48 00 7E CF 40 00 7F 8C 48 00 7F B9 --4C007F00=28007F00-- 40 00 80 08 48 00 80 95 40 00 81 60 48 00 81 E8 40 00 82 75 48 00 82 E2 40 00 83 80 48 00
                       
 83 E0 40 00 84 90 48 00 84 E0 40 00 85 B1 48 00 85 DF 40 00 86 8A 48 00 86 E0 40 00 87 CE 48 00 87 DF 40 00 88 8F 48 00 88 EF 40 00 89 94 48 00 89 E3
 40 00 8A AC 48 00 8A E0 40 00 8B 81 48 00 8B 50 40 00 8C 90 48 00 8C 40 40 00 8D A0 48 00 8D 40 40 00 8E E1 48 00 8E F7 40 00 8F 00 48 00 8F C0 40 00
 90 00 48 00 90 00 40 00 91 8C 48 00 91 E0 40 00 92 C3 48 00 92 DF 40 00 93 8F 48 00 93 EF 40 00 94 94 48 00 94 E3 40 00 95 AC 48 00 95 E0 40 00 96 81
 48 00 96 50 40 00 97 90 48 00 97 40 40 00 98 A0 48 00 98 40 40 00 99 E1 48 00 99 F7 40 00 9A 00 48 00 9A C0 40 00 9B 00 48 00 9B 00 40 00 9C 8B 48 00
 9C E0 40 00 9D B8 48 00 9D DF 40 00 9E 8F 48 00 9E EF 40 00 9F 94 48 00 9F E3 --4C009F00=28009F00-- 40 00 A0 AC 48 00 A0 E0 40 00 A1 81 48 00 A1 50

 40 00 A2 90 48 00 A2 40 40 00 A3 A0 48 00 A3 40 40 00 A4 E1 48 00 A4 F7 40 00 A5 00 48 00 A5 C0 40 00 A6 00 48 00 A6 00 40 00 A7 8D 48 00 A7 E0 40 00
 A8 AD 48 00 A8 DF 40 00 A9 8F 48 00 A9 EF 40 00 AA 94 48 00 AA E3 40 00 AB AC 48 00 AB E0 40 00 AC 81 48 00 AC 50 40 00 AD 90 48 00 AD 40 40 00 AE A0  48 00 AE 40 40 00 AF E1 48 00 AF F7 40 00 B0 00 48 00 B0 C0 40 00 B1 00 48 00 B1 00 40 00 B2 80 48 00 B2 E2 40 00 B3 A2 48 00 B3 DF 40 00 B4 D1 48 00  B4 CF 40 00 B5 A1 48 00 B5 E2 40 00 B6 1A 48 00 B6 2E 40 00 B7 AA 48 00 B7 1B 40 00 B8 BB 48 00 B8 1B 40 00 B9 FD 48 00 B9 01 40 00 BA 0D 48 00 BA C0  40 00 BB AA 48 00 BB 1F 40 00 BC BB 48 00 BC 1F 40 00 BD EE 48 00 BD 1F 40 00 BE FF 48 00 BE 1F 40 00 BF A2 48 00 BF 17 --4C00BF00=2800BF00-- 40 00

 C0 B3 48 00 C0 07 40 00 C1 E4 48 00 C1 07 40 00 C2 F5 48 00 C2 07 40 00 C3 20 48 00 C3 F0 40 00 C4 A2 48 00 C4 1B 40 00 C5 B3 48 00 C5 0B 40 00 C6 E4
 48 00 C6 0B 40 00 C7 F5 48 00 C7 0B 40 00 C8 66 48 00 C8 1F 40 00 C9 77 48 00 C9 1F 40 00 CA 88 48 00 CA 1F 40 00 CB 99 48 00 CB 1F 40 00 CC 1A 48 00
 CC 94 40 00 CD 69 48 00 CD F7 40 00 CE 60 48 00 CE 95 40 00 CF 70 48 00 CF 95 40 00 D0 80 48 00 D0 95 40 00 D1 90 48 00 D1 95 40 00 D2 9B 48 00 D2 01 40 00 D3 AC 48 00 D3 01 40 00 D4 BD 48 00 D4 01 40 00 D5 CF 48 00 D5 01 40 00 D6 08 48 00 D6 95 40 00 D7 F8 48 00 D7 94 40 00 D8 FF 48 00 D8 CF --4C00D800=2800D800--
------------------------------------------------------------------------------------------------------------------------------------------------------
 20 00 00 00 28 00 00 00 20 00 01 00 28 00 01 00 20 00 02 00 28 00 02 00 20 00 03 00 28 00 03 00 20 00 04 00 28 00 04 00 20 00 05 00
 28 00 05 00 20 00 06 00 28 00 06 00 20 00 07 00 28 00 07 00 20 00 08 00 28 00 08 00 20 00 09 00 28 00 09 00 20 00 0A 00 28 00 0A 00 20 00 0B 00 28 00
 0B 00 20 00 0C 00 28 00 0C 00 20 00 0D 00 28 00 0D 00 20 00 0E 00 28 00 0E 00 20 00 0F 00 28 00 0F 00 20 00 10 00 28 00 10 00 20 00 11 00 28 00 11 00
 20 00 12 00 28 00 12 00 20 00 13 00 28 00 13 00 20 00 14 00 28 00 14 00 20 00 15 00 28 00 15 00 20 00 16 00 28 00 16 00 20 00 17 00 28 00 17 00 20 00
 18 00 28 00 18 00 20 00 19 00 28 00 19 00 20 00 1A 00 28 00 1A 00 20 00 1B 00 28 00 1B 00 20 00 1C 00 28 00 1C 00 20 00 1D 00 28 00 1D 00 20 00 1E 00
 28 00 1E 00 20 00 1F 00 28 00 1F 00 20 00 20 00 28 00 20 00 20 00 21 00 28 00 21 00 20 00 22 00 28 00 22 00 20 00 23 00 28 00 23 00 20 00 24 00 28 00
 24 00 20 00 25 00 28 00 25 00 20 00 26 00 28 00 26 00 20 00 27 00 28 00 27 00 20 00 28 00 28 00 28 00 20 00 29 00 28 00 29 00 20 00 2A 00 28 00 2A 00
 20 00 2B 00 28 00 2B 00 20 00 2C 00 28 00 2C 00 20 00 2D 00 28 00 2D 00 20 00 2E 00 28 00 2E 00 20 00 2F 00 28 00 2F 00 20 00 30 00 28 00 30 00 20 00
 31 00 28 00 31 00 20 00 32 00 28 00 32 00 20 00 33 00 28 00 33 00 20 00 34 00 28 00 34 00 20 00 35 00 28 00 35 00 20 00 36 00 28 00 36 00 20 00 37 00
 28 00 37 00 20 00 38 00 28 00 38 00 20 00 39 00 28 00 39 00 20 00 3A 00 28 00 3A 00 20 00 3B 00 28 00 3B 00 20 00 3C 00 28 00 3C 00 20 00 3D 00 28 00
 3D 00 20 00 3E 00 28 00 3E 00 20 00 3F 00 28 00 3F 00 20 00 40 00 28 00 40 00 20 00 41 00 28 00 41 00 20 00 42 00 28 00 42 00 20 00 43 00 28 00 43 00
 20 00 44 00 28 00 44 00 20 00 45 00 28 00 45 00 20 00 46 00 28 00 46 00 20 00 47 00 28 00 47 00 20 00 48 00 28 00 48 00 20 00 49 00 28 00 49 00 20 00
 4A 00 28 00 4A 00 20 00 4B 00 28 00 4B 00 20 00 4C 00 28 00 4C 00 20 00 4D 00 28 00 4D 00 20 00 4E 00 28 00 4E 00 20 00 4F 00 28 00 4F 00 20 00 50 00
 28 00 50 00 20 00 51 00 28 00 51 00 20 00 52 00 28 00 52 00 20 00 53 00 28 00 53 00 20 00 54 00 28 00 54 00 20 00 55 00 28 00 55 00 20 00 56 00 28 00
 56 00 20 00 57 00 28 00 57 00 20 00 58 00 28 00 58 00 20 00 59 00 28 00 59 00 20 00 5A 00 28 00 5A 00 20 00 5B 00 28 00 5B 00 20 00 5C 00 28 00 5C 00
 20 00 5D 00 28 00 5D 00 20 00 5E 00 28 00 5E 00 20 00 5F 00 28 00 5F 00 20 00 60 00 28 00 60 00 20 00 61 00 28 00 61 00 20 00 62 00 28 00 62 00 20 00
 63 00 28 00 63 00 20 00 64 00 28 00 64 00 20 00 65 00 28 00 65 00 20 00 66 00 28 00 66 00 20 00 67 00 28 00 67 00 20 00 68 00 28 00 68 00 20 00 69 00
 28 00 69 00 20 00 6A 00 28 00 6A 00 20 00 6B 00 28 00 6B 00 20 00 6C 00 28 00 6C 00 20 00 6D 00 28 00 6D 00 20 00 6E 00 28 00 6E 00 20 00 6F 00 28 00
 6F 00 20 00 70 00 28 00 70 00 20 00 71 00 28 00 71 00 20 00 72 00 28 00 72 00 20 00 73 00 28 00 73 00 20 00 74 00 28 00 74 00 20 00 75 00 28 00 75 00
 20 00 76 00 28 00 76 00 20 00 77 00 28 00 77 00 20 00 78 00 28 00 78 00 20 00 79 00 28 00 79 00 20 00 7A 00 28 00 7A 00 20 00 7B 00 28 00 7B 00 20 00
 7C 00 28 00 7C 00 20 00 7D 00 28 00 7D 00 20 00 7E 00 28 00 7E 00 20 00 7F 00 28 00 7F 00 20 00 80 00 28 00 80 00 20 00 81 00 28 00 81 00 20 00 82 00
 28 00 82 00 20 00 83 00 28 00 83 00 20 00 84 00 28 00 84 00 20 00 85 00 28 00 85 00 20 00 86 00 28 00 86 00 20 00 87 00 28 00 87 00 20 00 88 00 28 00
 88 00 20 00 89 00 28 00 89 00 20 00 8A 00 28 00 8A 00 20 00 8B 00 28 00 8B 00 20 00 8C 00 28 00 8C 00 20 00 8D 00 28 00 8D 00 20 00 8E 00 28 00 8E 00
 20 00 8F 00 28 00 8F 00 20 00 90 00 28 00 90 00 20 00 91 00 28 00 91 00 20 00 92 00 28 00 92 00 20 00 93 00 28 00 93 00 20 00 94 00 28 00 94 00 20 00
 95 00 28 00 95 00 20 00 96 00 28 00 96 00 20 00 97 00 28 00 97 00 20 00 98 00 28 00 98 00 20 00 99 00 28 00 99 00 20 00 9A 00 28 00 9A 00 20 00 9B 00
 28 00 9B 00 20 00 9C 00 28 00 9C 00 20 00 9D 00 28 00 9D 00 20 00 9E 00 28 00 9E 00 20 00 9F 00 28 00 9F 00 20 00 A0 00 28 00 A0 00 20 00 A1 00 28 00
 A1 00 20 00 A2 00 28 00 A2 00 20 00 A3 00 28 00 A3 00 20 00 A4 00 28 00 A4 00 20 00 A5 00 28 00 A5 00 20 00 A6 00 28 00 A6 00 20 00 A7 00 28 00 A7 00
 20 00 A8 00 28 00 A8 00 20 00 A9 00 28 00 A9 00 20 00 AA 00 28 00 AA 00 20 00 AB 00 28 00 AB 00 20 00 AC 00 28 00 AC 00 20 00 AD 00 28 00 AD 00 20 00
 AE 00 28 00 AE 00 20 00 AF 00 28 00 AF 00 20 00 B0 00 28 00 B0 00 20 00 B1 00 28 00 B1 00 20 00 B2 00 28 00 B2 00 20 00 B3 00 28 00 B3 00 20 00 B4 00
 28 00 B4 00 20 00 B5 00 28 00 B5 00 20 00 B6 00 28 00 B6 00 20 00 B7 00 28 00 B7 00 20 00 B8 00 28 00 B8 00 20 00 B9 00 28 00 B9 00 20 00 BA 00 28 00
 BA 00 20 00 BB 00 28 00 BB 00 20 00 BC 00 28 00 BC 00 20 00 BD 00 28 00 BD 00 20 00 BE 00 28 00 BE 00 20 00 BF 00 28 00 BF 00 20 00 C0 00 28 00 C0 00 20 00 C1 00 28 00 C1 00 20 00 C2 00 28 00 C2 00 20 00 C3 00 28 00 C3 00 20 00 C4 00 28 00 C4 00 20 00 C5 00 28 00 C5 00 20 00 C6 00 28 00 C6 00 20 00 C7 00 28 00 C7 00 20 00 C8 00 28 00 C8 00 20 00 C9 00 28 00 C9 00 20 00 CA 00 28 00 CA 00 20 00 CB 00 28 00 CB 00 20 00 CC 00 28 00 CC 00 20 00 CD 00 28 00 CD 00 20 00 CE 00 28 00 CE 00 20 00 CF 00 28 00 CF 00 20 00 D0 00 28 00 D0 00 20 00 D1 00 28 00 D1 00 20 00 D2 00 28 00 D2 00 20 00 D3 00 28 00 D3 00 20 00 D4 00 28 00 D4 00 20 00 D5 00 28 00 D5 00 20 00 D6 00 28 00 D6 00 20 00 D7 00 28 00 D7 00 20 00 D8 00 28 00 D8 00
------------------------------------------------------------------------------------------------------------------------------------------------------
 --50000000=50000000=50000000=58080000=58080000=58080000-AC530000-30000000=30000100=30000200-50000000=50000000=50000000--58080000=58080000=58080000   - A001FC00=A001FD00=A001FE00=A001FF00--
------------------------------------------------------------------------------------------------------------------------------------------------------
 20 00 00 00 28 00 00 00 20 00 01 00 28 00 01 00 20 00 02 00 28 00 02 00 20 00 03 00
 28 00 03 00 20 00 04 00 28 00 04 00 20 00 05 00 28 00 05 00 20 00 06 00 28 00 06 00 20 00 07 00 28 00 07 00 20 00 08 00 28 00 08 00 20 00 09 00 28 00
 09 00 20 00 0A 00 28 00 0A 00 20 00 0B 00 28 00 0B 00 20 00 0C 00 28 00 0C 00 20 00 0D 00 28 00 0D 00 20 00 0E 00 28 00 0E 00 20 00 0F 00 28 00 0F 00
 20 00 10 00 28 00 10 00 20 00 11 00 28 00 11 00 20 00 12 00 28 00 12 00 20 00 13 00 28 00 13 00 20 00 14 00 28 00 14 00 20 00 15 00 28 00 15 00 20 00
 16 00 28 00 16 00 20 00 17 00 28 00 17 00 20 00 18 00 28 00 18 00 20 00 19 00 28 00 19 00 20 00 1A 00 28 00 1A 00 20 00 1B 00 28 00 1B 00 20 00 1C 00
 28 00 1C 00 20 00 1D 00 28 00 1D 00 20 00 1E 00 28 00 1E 00 20 00 1F 00 28 00 1F 00 20 00 20 00 28 00 20 00 20 00 21 00 28 00 21 00 20 00 22 00 28 00
 22 00 20 00 23 00 28 00 23 00 20 00 24 00 28 00 24 00 20 00 25 00 28 00 25 00 20 00 26 00 28 00 26 00 20 00 27 00 28 00 27 00 20 00 28 00 28 00 28 00
 20 00 29 00 28 00 29 00 20 00 2A 00 28 00 2A 00 20 00 2B 00 28 00 2B 00 20 00 2C 00 28 00 2C 00 20 00 2D 00 28 00 2D 00 20 00 2E 00 28 00 2E 00 20 00
 2F 00 28 00 2F 00 20 00 30 00 28 00 30 00 20 00 31 00 28 00 31 00 20 00 32 00 28 00 32 00 20 00 33 00 28 00 33 00 20 00 34 00 28 00 34 00 20 00 35 00
 28 00 35 00 20 00 36 00 28 00 36 00 20 00 37 00 28 00 37 00 20 00 38 00 28 00 38 00 20 00 39 00 28 00 39 00 20 00 3A 00 28 00 3A 00 20 00 3B 00 28 00
 3B 00 20 00 3C 00 28 00 3C 00 20 00 3D 00 28 00 3D 00 20 00 3E 00 28 00 3E 00 20 00 3F 00 28 00 3F 00 20 00 40 00 28 00 40 00 20 00 41 00 28 00 41 00
 20 00 42 00 28 00 42 00 20 00 43 00 28 00 43 00 20 00 44 00 28 00 44 00 20 00 45 00 28 00 45 00 20 00 46 00 28 00 46 00 20 00 47 00 28 00 47 00 20 00
 48 00 28 00 48 00 20 00 49 00 28 00 49 00 20 00 4A 00 28 00 4A 00 20 00 4B 00 28 00 4B 00 20 00 4C 00 28 00 4C 00 20 00 4D 00 28 00 4D 00 20 00 4E 00
 28 00 4E 00 20 00 4F 00 28 00 4F 00 20 00 50 00 28 00 50 00 20 00 51 00 28 00 51 00 20 00 52 00 28 00 52 00 20 00 53 00 28 00 53 00 20 00 54 00 28 00
 54 00 20 00 55 00 28 00 55 00 20 00 56 00 28 00 56 00 20 00 57 00 28 00 57 00 20 00 58 00 28 00 58 00 20 00 59 00 28 00 59 00 20 00 5A 00 28 00 5A 00
 20 00 5B 00 28 00 5B 00 20 00 5C 00 28 00 5C 00 20 00 5D 00 28 00 5D 00 20 00 5E 00 28 00 5E 00 20 00 5F 00 28 00 5F 00 20 00 60 00 28 00 60 00 20 00
 61 00 28 00 61 00 20 00 62 00 28 00 62 00 20 00 63 00 28 00 63 00 20 00 64 00 28 00 64 00 20 00 65 00 28 00 65 00 20 00 66 00 28 00 66 00 20 00 67 00
 28 00 67 00 20 00 68 00 28 00 68 00 20 00 69 00 28 00 69 00 20 00 6A 00 28 00 6A 00 20 00 6B 00 28 00 6B 00 20 00 6C 00 28 00 6C 00 20 00 6D 00 28 00
 6D 00 20 00 6E 00 28 00 6E 00 20 00 6F 00 28 00 6F 00 20 00 70 00 28 00 70 00 20 00 71 00 28 00 71 00 20 00 72 00 28 00 72 00 20 00 73 00 28 00 73 00
 20 00 74 00 28 00 74 00 20 00 75 00 28 00 75 00 20 00 76 00 28 00 76 00 20 00 77 00 28 00 77 00 20 00 78 00 28 00 78 00 20 00 79 00 28 00 79 00 20 00
 7A 00 28 00 7A 00 20 00 7B 00 28 00 7B 00 20 00 7C 00 28 00 7C 00 20 00 7D 00 28 00 7D 00 20 00 7E 00 28 00 7E 00 20 00 7F 00 28 00 7F 00 20 00 80 00
 28 00 80 00 20 00 81 00 28 00 81 00 20 00 82 00 28 00 82 00 20 00 83 00 28 00 83 00 20 00 84 00 28 00 84 00 20 00 85 00 28 00 85 00 20 00 86 00 28 00
 86 00 20 00 87 00 28 00 87 00 20 00 88 00 28 00 88 00 20 00 89 00 28 00 89 00 20 00 8A 00 28 00 8A 00 20 00 8B 00 28 00 8B 00 20 00 8C 00 28 00 8C 00
 20 00 8D 00 28 00 8D 00 20 00 8E 00 28 00 8E 00 20 00 8F 00 28 00 8F 00 20 00 90 00 28 00 90 00 20 00 91 00 28 00 91 00 20 00 92 00 28 00 92 00 20 00
 93 00 28 00 93 00 20 00 94 00 28 00 94 00 20 00 95 00 28 00 95 00 20 00 96 00 28 00 96 00 20 00 97 00 28 00 97 00 20 00 98 00 28 00 98 00 20 00 99 00
 28 00 99 00 20 00 9A 00 28 00 9A 00 20 00 9B 00 28 00 9B 00 20 00 9C 00 28 00 9C 00 20 00 9D 00 28 00 9D 00 20 00 9E 00 28 00 9E 00 20 00 9F 00 28 00
 9F 00 20 00 A0 00 28 00 A0 00 20 00 A1 00 28 00 A1 00 20 00 A2 00 28 00 A2 00 20 00 A3 00 28 00 A3 00 20 00 A4 00 28 00 A4 00 20 00 A5 00 28 00 A5 00
 20 00 A6 00 28 00 A6 00 20 00 A7 00 28 00 A7 00 20 00 A8 00 28 00 A8 00 20 00 A9 00 28 00 A9 00 20 00 AA 00 28 00 AA 00 20 00 AB 00 28 00 AB 00 20 00
 AC 00 28 00 AC 00 20 00 AD 00 28 00 AD 00 20 00 AE 00 28 00 AE 00 20 00 AF 00 28 00 AF 00 20 00 B0 00 28 00 B0 00 20 00 B1 00 28 00 B1 00 20 00 B2 00
 28 00 B2 00 20 00 B3 00 28 00 B3 00 20 00 B4 00 28 00 B4 00 20 00 B5 00 28 00 B5 00 20 00 B6 00 28 00 B6 00 20 00 B7 00 28 00 B7 00 20 00 B8 00 28 00
 B8 00 20 00 B9 00 28 00 B9 00 20 00 BA 00 28 00 BA 00 20 00 BB 00 28 00 BB 00 20 00 BC 00 28 00 BC 00 20 00 BD 00 28 00 BD 00 20 00 BE 00 28 00 BE 00
 20 00 BF 00 28 00 BF 00 20 00 C0 00 28 00 C0 00 20 00 C1 00 28 00 C1 00 20 00 C2 00 28 00 C2 00 20 00 C3 00 28 00 C3 00 20 00 C4 00 28 00 C4 00 20 00
 C5 00 28 00 C5 00 20 00 C6 00 28 00 C6 00 20 00 C7 00 28 00 C7 00 20 00 C8 00 28 00 C8 00 20 00 C9 00 28 00 C9 00 20 00 CA 00 28 00 CA 00 20 00 CB 00
 28 00 CB 00 20 00 CC 00 28 00 CC 00 20 00 CD 00 28 00 CD 00 20 00 CE 00 28 00 CE 00 20 00 CF 00 28 00 CF 00 20 00 D0 00 28 00 D0 00 20 00 D1 00 28 00
 D1 00 20 00 D2 00 28 00 D2 00 20 00 D3 00 28 00 D3 00 20 00 D4 00 28 00 D4 00 20 00 D5 00 28 00 D5 00 20 00 D6 00 28 00 D6 00 20 00 D7 00 28 00 D7 00
 20 00 D8 00 28 00 D8 00 20 00 D9 00 28 00 D9 00 20 00 DA 00 28 00 DA 00 20 00 DB 00 28 00 DB 00 20 00 DC 00 28 00 DC 00 20 00 DD 00 28 00 DD 00 20 00
 DE 00 28 00 DE 00 20 00 DF 00 28 00 DF 00 20 00 E0 00 28 00 E0 00 20 00 E1 00 28 00 E1 00 20 00 E2 00 28 00 E2 00 20 00 E3 00 28 00 E3 00 20 00 E4 00
 28 00 E4 00 20 00 E5 00 28 00 E5 00 20 00 E6 00 28 00 E6 00 20 00 E7 00 28 00 E7 00 20 00 E8 00 28 00 E8 00 20 00 E9 00 28 00 E9 00 20 00 EA 00 28 00
 EA 00 20 00 EB 00 28 00 EB 00 20 00 EC 00 28 00 EC 00 20 00 ED 00 28 00 ED 00 20 00 EE 00 28 00 EE 00 20 00 EF 00 28 00 EF 00 20 00 F0 00 28 00 F0 00
 20 00 F1 00 28 00 F1 00 20 00 F2 00 28 00 F2 00 20 00 F3 00 28 00 F3 00 20 00 F4 00 28 00 F4 00 20 00 F5 00 28 00 F5 00 20 00 F6 00 28 00 F6 00 20 00
 F7 00 28 00 F7 00 20 00 F8 00 28 00 F8 00 20 00 F9 00 28 00 F9 00 20 00 FA 00 28 00 FA 00 20 00 FB 00 28 00 FB 00 20 00 FC 00 28 00 FC 00 20 00 FD 00
 28 00 FD 00 20 00 FE 00 28 00 FE 00 20 00 FF 00 28 00 FF 00 --58000000--

Steps how a programmer writes the hex file into microcontroller

Do You know how microcontroller writes .hex file into microcontroller most of us don't know how it writes right . There is a pattern how it writes into microcontroller . It follows a sequence while writting .hex into microcontroller there are some SPM (store program memory) commands which should be send and then send address and then data .

Some microcontrollers write data in the form of word and some write in the form of bytes. you should see this while you are developing something new like bootloader or something els.

If mc is word addressable first it loads the lower byte with data and then higher byte with next data of same address as it is word addressable. (remember).

Generally avr-gcc writes the code in byte form so what ever the address we need to change in the microcontroller you need to double the address and give it to gcc .

Suppose you want to write the code from 0xC00 in the flash which is word addressable how you should give this in avr-gcc is
                                                    0xC00 * 2 = 0x1800
in the chang section if you need to change the address location where to write.else if microcontroller is byte addressable you can write it directly 0xC00. There is no need to manipulate the addresses .

Ok leave this is brief i will explain you in the later sessions.

Now lets know what a Programmer does in the Microcontroller if it wants to write .hex file into the flash .

Steps it follows :

1. program enable mode (0)

2. check signature bits

3. read low fuse bits

4. read high fuse bits

5. read last 4bytes of the eeprom because it stores number of times the chip erase has been done .

6. program enable mode again (1)
   (address is word address here so )

7. load the data into the flash first low add (40) 1st data and then to high of the same address (48) 2nd data into the flash.

8. load until whole page is loaded and then send the command Write PAGE the flash page loading last addersss

9. now read the page with last address

10. now reads each word in flash from starting address

11. and again reads the fuse bits and lock bits

This was the mechanism followed by the USBASP programmer of any other programmer to write program into the flash .

In order to understand clearly what this means see this Post
which tells you how it is writting.

How a .hex file is written in the microcontroller

AC530000  --> program enable
AC800000  --> chip erase
40000ioo  --> load program memory page low  
010000000 0000xxxx xxx 0 0000 iiiiiiii
                                              |          |__________data in
                                              |__________________load at address

Write data i to Program memory page at word address b. Data Low byte must be loaded before Data High byte is applied within the same address
                                      
48000ioo  --> load program memory page high

4c00 3f 00--> write program memory page       
01001100 0000 0000 001 xxxxx xxxxxxxx
                                 |_______ write at this address
                            
280 03f 00--> read program meory at word address
00101000 0000 aaaa bbbbbbbb  oooooooo
                                     |                        |______ data out
                                     |___________________ at word address

300000000-->read signature bits
300000100                                
300000200                        
00110000 00xxxxxx xxxxxx aa oooooooo                                 
                                              |          |____ out signature
                                              |________address of the signature

Programming Enable                                     $AC $53 $00 $00
Chip Erase (Program Memory/EEPROM)     $AC $80 $00 $00

 Poll RDY/BSY                                                $F0 $00 $00 data byte out
Load Extended Address byte(1)                     $4D $00 Extended adr $00

Load Program Memory Page, High byte       $48 adr MSB adr LSB high data byte in
Load Program Memory Page, Low byte        $40 adr MSB adr LSB low data byte in
Load EEPROM Memory Page (page access)(1)$C1 $00 adr LSB data byte in

Read Program Memory, High byte                   $28 adr MSB adr LSB high data byte out
Read Program Memory, Low byte                    $20 adr MSB adr LSB low data byte out
Read EEPROM Memory     $A0 adr MSB adr LSB data byte out
Read Lock bits                    $58 $00 $00 data byte out
Read Signature Byte           $30 $00 0000 000aa data byte out
Read Fuse bits                     $50 $00 $00 data byte out
Read Fuse High bits            $58 $08 $00 data byte out
Read Extended Fuse Bits    $50 $08 $00 data byte out
Read Calibration Byte         $38 $00 $0b00 000bb data byte out

Write Program Memory Page   $4C 000a aaaa aa00 0000 $00
Write EEPROM Memory           $C0 adr MSB adr LSB data byte in
Write EEPROM Memory Page (page access)  $C2 adr MSB adr LSB $00
Write Lock bits                          $AC $E0 $00 data byte in
Write Fuse bits                          $AC $A0 $00 data byte in
Write Fuse High bits                 $AC $A8 $00 data byte in
Write Extended Fuse Bits         $AC $A4 $00 data byte in

you can check the sample writting of the programmer into the microcontroller:

click here 

You won't get this until you see the above link . if you don't get please put a comment ok. i will be more specific. 

2 Jul 2012

PINS

PIN TERMINOLOGY:

             Same way as Ports . Remember the number of Ports you have is equal to number of pins because there are fixed number of pins for a microcontroller right.

Do you remember i told you you should access whole port even you want to access only one pin. In the same way you should access whole PINX for even you need only one pin to access. X = A, B, C ,D.

Lets take an example so that it makes you clear all the things.

You use PINB when you are checking if something is coming to microcontroller . eg: consider switch when you press a switch it sends a signal of 5v right so you need a application if you press a switch you should do some task lets assume toggle led. so you should be checking that pin right whether the pin is getting signal or not so at that time you use PINB (for checking incoming signal to microcontroller).

ACCESS 2:
PROGRAM:
             #include <avr/io.h>
              int main()
              {
                    DDRB = 0x00;     //configuring as inputs
                    DDRC = 0xff;      //configuring as outputs
                    while(1)
                     {
                           if(PINB & (1 << PB0)) //switch is connected to pinb 0
                           {
                                 PORTC = (1 << PC0);
                            }
                            PORTC = 0x00;
                      }
                }
as we connected switch to the Pinb0 so we are checking that pin continuoesly. 

And you may be thinking which i made PORTC = 0x00; in the program because in order to see whether it is blinking or not you should make it 0. try commenting that .you will get the output once.
ACCESS 3:
                    Replace (1<< PB0) with _BV(PB0).
Now i think you are quite familier with the access of ports.

some of the input devices to the microcontroller :
1. switch
2. Matrix keypad
3. Potency variation
4. ADC
5. Usart receiver etc..........
            _____________________________________________________
PINB  | PB7  | PB6  |  PB5  |  PB4  |  PB3|  PB2  | PB1  | PB0  |
           --------------------------------------------------------------------------------------
 This looks like this in the microcontroller. so , you got it right if you want to check that microcontroller is getting some input we use PINx .

 Though it may be looking as a simple concept for some of you but many don't understand at the beginning so this is for just them who are beginners.

ok, then lets meet in next session........................................