SlideShare a Scribd company logo
1 of 12
Download to read offline
ī„ ī„ 

     ī„  ī„ ī†Šī…šī…°ī…Ĩī…Ŋī…ģī…ī„ ī…Œī…‚ī…Ŋī…šī…’ī…‹ī…Ŋī…ģī…ī„ ī†Ēī…ī…Ŋī…šī…‰

                     â€ĢīēīģŸīē˜īē īēŽīē­īē īēīģŸīģŒīģ¤īģ īģ´īē”â€Ŧ

              ī„  ī„ ī†Šī…šī…Ŗī…Ģī„ ī†Ēī†Ļī…˜ī…‚ī…’ī…ģī…ī„ ī†Ēī…Ąī…ģī…ī…ģī…

                          ī„ ī„ 




                          ī„ ī„ 




                   Programming
      Embedded Systems Microcontroller

You Can Practice Microcontroller Programming Easily Now!
      WALID BALID, Tuesday, December 15, 2009
Practical Class 11                                                           Programming Microcontrollers

      Exp.30: Programming Internal EEPROM                   EEPROMīˆ ī‹’ī‹ŽīŠŧī‰Ąī‰ī‰ĻīŠģī‰īˆ ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ ī‹’īŠ‰ī‰Ēī‰‰īˆ īˆēī‹†ī‹Œī‰‘ī‹ī‰’īŠģī‰īˆ ī‹’ī‰‰ī‰Ēī‰–ī‰ŽīŠģī‰

                                                                                         īˆ  īˆ īˆēī‹’ī‰‰ī‰Ēī‰–ī‰ŽīŠģī‰īˆ ī‹…īŠŋīˆ ī‹’ī‹ī‰‚īŠŦīŠģī‰
                                                  īˆ  īˆ  īˆŽīˆ’ī‰‚īŠ¨ī‹€īŠŧīŠģīˆ īˆ¨EEPROMīˆŠīˆ ī‹’ī‹ŽīŠŧī‰Ąī‰ī‰ĻīŠģī‰īˆ ī‰ī‰‚ī‹Žī‹ąīŠ¨īŠī‰īˆ ī‹‘ī‰ĒīŠˇī‰ī‰§īˆ ī‹’īŠ‰ī‰Ēī‰‰ī‹‹īˆ ī‰Šī‰‚ī‹€ī‰’ī‰Žī‰­ī‰

                                                                                             īˆ  īˆ īˆēī‹‘ī‰Šī‰ī‰ĻīŠģī‰īˆ īŠĄī‹ąīŠ‹




īˆ  īˆ 

      Faculty of Electrical and Electronic Eng.             241              Automatic Control & Automation Dept.
ī‹‘ī‰ĒīŠŦī‰ļīŠī‰īˆ ī‰ī‰‚ī‹€īŠ¸ī‰šī‰ŽīŠī‰īˆ ī‹’īŠ‰ī‰Ēī‰‰                                                                             īˆ  īˆ  ī‹‘ī‰Ēī‰˛īŠ§īˆ ī‹’ī‹ī‰Ĩī‰‚īŠ‡ī‰īˆ ī‹’ī‰ŽīŠŧīŠ†ī‰

                                                                                               īˆ  īˆ īˆēī‹‘ī‰Šī‰ī‰ĻīŠģī‰īˆ īŠŊī‹€īŠ§īˆ ī‰ ī‰Ēī‰ą
īˆ ī‹īŠŧī‰ŽīŠŧī‰Žī‰ŽīŠģī‰īˆ īŠžī‰‚ī‰ļī‰ī‹œī‰īˆ ī‰¨īŠ°ī‹„īŠŋī‹‹īˆ ī‰ĒīŠŦī‰ļīŠī‰īˆ ī‹īŠ¸ī‰šī‰Žī‹€īŠŧīŠģ UART1īˆ ī‹’ī‹ŽīŠŧī‰ŽīŠŧī‰Žī‰ŽīŠģī‰īˆ ī‹‘ī‰¨īŠ¯ī‰‚ī‹„īŠģī‰īˆ īŠ”ī‰‰īˆ ī‹’ī‹€ī‹–ī‹īŠŋīˆ ī‹‘ī‰Šī‰ī‰Ĩīˆ ī‹“īŠŧīŠ§īˆ ī‹Šī‹īŠ§ī‰ƒīˆ ī‹‘ī‰Šī‰ī‰ĻīŠģī‰īˆ ī‹ī‹ŒīŠ„
īˆ īˆ’ī‰‚īŠ¨ī‹€īŠŧīŠģīˆ  ī‹’ī‹ŽīŠŧī‰Ąī‰ī‰ĻīŠģī‰īˆ  ī‰ī‰‚ī‹Žī‹ąīŠ¨īŠī‰īˆ  ī‹‘ī‰ĒīŠˇī‰ī‰§īˆ  īŠ•ī‰‡ī‹‹īˆ  ī‹…īŠŋīˆ  ī‹’ī‰‰ī‰‚ī‰ŽīŠ¸īŠģī‰ī‹‹īˆ  ī‹‘ī‹•ī‰ī‰ĒīŠ´īŠŧīŠģīˆ  ī‰—īŠŋī‰‚ī‹ƒī‰Ēī‰‰īˆ  ī‹’ī‰‰ī‰‚ī‰ŽīŠ¸ī‰‰īˆ  ī‹‚ī‹ŒīŠ´ī‹ƒīˆ  īŠ˛ī‹Œī‰­īˆ  īˆŽī‰‹ī‰­ī‰‚ī‰šīŠŧīŠģīˆ  RS232
                                                                       .ī‹’ī‹ŽīŠŧī‰ŽīŠŧī‰Žī‰ŽīŠģī‰īˆ ī‹‘ī‰¨īŠ¯ī‰‚ī‹„īŠģī‰īˆ ī‹‚ī‰ī‰Ļī‰ĸī‰Žī‰­ī‰‚ī‰‰īˆ īˆ¨EEPROMīˆŠ

                                                                                            īˆ  īˆ īˆēī‹‘ī‰Ļī‹ī‰ĻīŠ†ī‰īˆ ī‰ī‰‚ī‹€ī‹ŽīŠŧīŠ¨ī‰ŽīŠģī‰
                īˆ  īˆ  ī‹’ī‹€ī‹ŽīŠŧīŠ¨ī‰ŽīŠģī‰                                          īˆ  īˆ  ī‹’ī‹€ī‹ŽīŠŧīŠ¨ī‰ŽīŠģī‰īˆ ī‰ ī‰Ēī‰ą
                                            īˆ īŠŠīŠŋīˆ  īˆ¨ī‹’ī‹€ī‹–ī‰ī‰Ĩīˆ  ī‹‘ī‰ĒīŠˇī‰ī‰§|ī‹’ī‹ŽīŠŧī‰Ąī‰ī‰Ĩīˆ  ī‰ī‰‚ī‹Žī‹ąīŠ¨īŠŋ|ī‹’ī‹Žī‰•ī‰Šī‰‚ī‰Ąīˆ  ī‰ī‰‚ī‹Žī‹ąīŠ¨īŠŋīˆŠīˆ  ī‹‘ī‰ĒīŠˇī‰ī‰§īˆ  īŠŸīˆ  īŠžī‹Œī‰šī‰ŽīŠŋīˆ  īŠąī‹ī‰ĒīŠ¨ī‰
Dim Var As [xram|Sram|Eram]
Type [at Location][overlay]                                                     īˆ  īˆ īˆŽī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ īŠŸīˆ īŠžī‹Œī‰šī‰ŽīŠī‰īˆ īŠŠīŠŗī‹ŒīŠŋīˆ ī‰Ļī‹ī‰ĻīŠ„īˆ ī‰Šī‰‚ī‹Žī‰Ą

Examples:                                   īˆ ī‹ī‹īˆ ī‹…īŠģīˆ ī‹‰ī‹ƒī‰ƒīˆ ī‹ī‰ƒīˆ ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ īŠŸīˆ ī‹īŠģī‰‚ī‹Žī‰Ąīˆ īŠžī‹Œī‰šī‰ŽīŠŋīˆ īŠ˛ī‰ĒīŠ¨īŠī‰īˆ īŠžī‹Œī‰šī‰ŽīŠī‰īˆ īŠŊīŠ¨īŠīˆ ī‰Šī‰‚ī‹Žī‰Ąīˆ īˆēoverlay
Dim Sram_var As Sram Byte At &H10
                                              īˆŽī‹†ī‰ī‹Œī‹„īŠ¨īŠģī‰īˆ ī‹“īŠŧīŠ§īˆ īŠžī‹Œī‰šī‰ŽīŠŋīˆ ī‹’ī‰‰ī‰‚ī‰ŽīŠˇīˆ īŠŸīˆ ī‹‘ī‰Šī‹Œī‹ąīŠˆī‰īˆ ī‹…ī‹€īŠ¸ī‰īˆ ī‹…īŠ¸īŠģī‹‹īˆ ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ īŠŸīˆ ī‹’ī‰™ī‰‚ī‰ŽīŠŋīˆ ī‰Ŧī‰–ī‰™
Dim Eprm_var As Eram Byte At &H80
Writeeeprom Var , Address                             īˆŽAddressīˆ ī‹†ī‰ī‹Œī‹„īŠ¨īŠģī‰īˆ ī‰Ļī‹„īŠ§īˆ EEPROMīˆ ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ īŠ•ī‰‡īˆ īˆ¨VarīˆŠīˆ ī‹’ī‹€ī‹ŽīŠŗīˆ ī‹’ī‰‰ī‰‚ī‰ŽīŠˇ
Writeeeprom Var , Label                           īˆŽLabelīˆ ī‹’ī‰ŽīŠ¯ī‹īŠģī‰īˆ ī‰Ļī‹„īŠ§īˆ īŠŠī‰šī‹Œī‰Žī‰ŽīŠģīˆ EEPROMīˆ ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ īŠ•ī‰‡īˆ īˆ¨VarīˆŠīˆ ī‹’ī‹€ī‹ŽīŠŗīˆ ī‹’ī‰‰ī‰‚ī‰ŽīŠˇ
Readeeprom Var , Address                               īˆŽAddressīˆ ī‹†ī‰ī‹Œī‹„īŠ¨īŠģī‰īˆ ī‰Ļī‹„īŠ§īˆ EEPROMīˆ ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ ī‹…īŠŋīˆ īˆ¨VarīˆŠīˆ ī‹’ī‹€ī‹ŽīŠŗīˆ ī‹‘ī‹•ī‰ī‰ĒīŠŗ
Readeeprom Var , Label                            īˆŽLabelīˆ ī‹’ī‰ŽīŠ¯ī‹īŠģī‰īˆ ī‰Ļī‹„īŠ§īˆ ī‹’īŠ¨ī‰šī‹Œī‰ŽīŠī‰īˆ EEPROMīˆ ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ ī‹…īŠŋīˆ īˆ¨VarīˆŠīˆ ī‹’ī‹€ī‹ŽīŠŗīˆ ī‹‘ī‹•ī‰ī‰ĒīŠŗ
                                            īˆ ī‹‘ī‰Ēī‰ąī‰‚ī‰ŠīŠŋīˆ ī‹ī‹‡īˆ īˆžīŠģī‰ī‹‹īˆ  DATAīˆ ī‹’ī‹€ī‹ŽīŠŧīŠ¨ī‰ŽīŠģī‰īˆ īŠŸīˆ ī‹‘ī‰Ĩī‹Œī‰•ī‹ŒīŠī‰īˆ ī‰ī‰‚ī‹ƒī‰‚ī‹Žī‰ŠīŠģī‰īˆ ī‹…ī‹ī‰ŦīŠ…īˆ īŠ•ī‰‡īˆ ī‹ī‰•īˆ–īŠī‰īˆ ī‹‰ī‹Žī‰•ī‹Œī‰
$eeprom
                                                      īˆ  īˆ īˆŽEPPīˆ ī‹ī‹–ī‰‚ī‹„ī‰‘īˆ īŠąīŠŧīŠŋīˆ ī‰Ļī‹ŽīŠģī‹Œī‰īˆ ī‹ī‰Žī‹Žī‰­ī‹‹īˆ īˆŦEEPROMīˆ ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ īŠŸīˆ ī‹‰ī‹Žī‰•ī‹Œī‰ŽīŠģī‰īˆ ī‰ĻīŠ¨ī‰‰
$data                                               īˆ  īˆ īˆŽī‰—īŠŋī‰‚ī‹ƒīˆ•īŠģī‰īˆ ī‹‘ī‰ĒīŠˇī‰ī‰§īˆ īŠŸīˆ ī‰‚ī‹ˆī‹„ī‹ī‰ŦīŠ…īˆ ī‹ī‰Žī‹Žī‰­īˆ ī‹’ī‹ŽīŠģī‰‚ī‰ŽīŠģī‰īˆ ī‰ī‰‚ī‹ƒī‰‚ī‹Žī‰ŠīŠģī‰īˆ ī‹†ī‰ƒīˆ īŠ•ī‰‡īˆ ī‹ī‰•īˆ–īŠī‰īˆ ī‹‰ī‹Žī‰•ī‹Œī‰
                                                 īˆ  īˆ īˆŽIntel HEXīˆ ī‹’īŠŦī‹Žī‰ļī‰‰īˆ EPPīˆ īŠąīŠŧīŠī‰īˆ īŠŸīˆ ī‰ī‰‚ī‹ƒī‰‚ī‹Žī‰ŠīŠģī‰īˆ ī‹…ī‹ī‰ŦīŠ…īˆ īŠ•ī‰‡īˆ ī‹ī‰•īˆ–īŠī‰īˆ ī‹‰ī‹Žī‰•ī‹Œī‰
$eepromhex
                                                                    īˆŽ$eepromīˆ ī‹’ī‹€ī‹ŽīŠŧīŠ¨ī‰ŽīŠģī‰īˆ īŠŠīŠŋīˆ ī‹‚ī‰Ļī‰ĸī‰Žī‰Žī‹īˆ ī‹†ī‰ƒīˆ ī‰‹īŠīˆ ī‹‰ī‹Žī‰•ī‹Œī‰ŽīŠģī‰īˆ ī‰ī‰¨ī‹‡
$eepleave                                        īˆ  īˆ īˆŽEEPROMīˆ ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ ī‹īŠŠīˆ ī‹‚ī‰ĻīŠ§ī‹‹īˆ EPPīˆ īŠąīŠŧīŠŋīˆ ī‰Ļī‹ŽīŠģī‹Œī‰īˆ ī‹‚ī‰ĻīŠ§īˆ īŠ•ī‰‡īˆ ī‹ī‰•īˆ–īŠī‰īˆ ī‹‰ī‹Žī‰•ī‹Œī‰

$default Sram | Xram | Eram

Examples:
$default Sram                                              īˆ  īˆ īˆŽ$defaultīˆ ī‹‰ī‹Žī‰•ī‹Œī‰ŽīŠŧīŠģīˆ ī‹’ī‹ŽīŠģī‰‚ī‰ŽīŠģī‰īˆ ī‰ī‹œī‹Œī‰šī‰ŽīŠī‰īˆ īŠŠī‹ŽīŠšīˆ ī‰Ŧī‰–ī‰™īˆ īŠŠīŠŗī‹ŒīŠŋīˆ īŠ”ī‹ŽīŠ¨ī‰
Dim A As Byte , B As Byte

$default Eram
Dim C As Byte , D As Byte

$end $default                                     īˆ  īˆ īˆŽīŠĩī‰‰ī‰‚ī‰ŽīŠģī‰īˆ ī‹‰ī‹Žī‰•ī‹Œī‰ŽīŠģī‰īˆ ī‹‚ī‰ī‰Ļī‰ĸī‰Žī‰­ī‰‚ī‰‰īˆ ī‰‚ī‹‡īˆ—ī‹ŽīŠŦī‰īˆ īˆƒīˆ īˆžīŠģī‰īˆ ī‹’ī‹Žī‰šī‰īˆ–īŠ¯ī‹œī‰īˆ ī‰ī‰ī‰Ĩī‰ī‰ĻīŠ§ī‹ĸī‰īˆ ī‹‘ī‰Ĩī‰‚īŠ¨ī‰Žī‰­ī‰
$noramclear                                            īˆ  īˆ īˆŽī‹’ī‹—ī‹Žī‹ˆī‰ŽīŠģī‰īˆ ī‰Ļī‹„īŠ§īˆ SRAMīˆ ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ ī‹”ī‹Œī‰ŽīŠŠīˆ īˆ—īŠ°ī‰ļī‰īˆ ī‹‚ī‰ĻīŠ§īˆ īŠ•ī‰‡īˆ ī‹ī‰•īˆ–īŠī‰īˆ ī‹‰ī‹Žī‰•ī‹Œī‰
$romstart = address                                            īˆ  īˆ īˆŽī‰Ĩī‰Ļīˆī‰īˆ ī‹†ī‰ī‹Œī‹„īŠ¨īŠģī‰īˆ ī‹…īŠŋīˆ ī‹§ī‹•ī‰ī‰Ļī‰Žī‰‰ī‰īˆ ī‰—īŠŋī‰‚ī‹ƒīˆ•īŠģī‰īˆ ī‹…ī‹ī‰ŦīŠ…īˆ īŠ•ī‰‡īˆ ī‹ī‰•īˆ–īŠī‰īˆ ī‹‰ī‹Žī‰•ī‹Œī‰

īˆ ī‰Ļī‹„īŠ§īˆ īŠŠī‰šī‹Œī‰ŽīŠī‰īˆ  EEPROMīˆ ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ ī‹…īŠŋīˆ īŠžī‹‹ī‹žī‰īˆ ī‰ī‹ī‰‚ī‰ŠīŠģī‰īˆ ī‹‚ī‰ī‰Ļī‰ĸī‰Žī‰­ī‰īˆ ī‰ĻīŠ¨ī‰‰īˆ  AVRīˆ ī‹’īŠŧī‹–ī‰‚īŠ¨īŠģīˆ ī‹’ī‹Žī‹„īŠ°īŠģī‰īˆ ī‹’īŠ´ī‹Žī‰‘ī‹ŒīŠģī‰īˆ īŠŸīˆ ī‹“ī‰ĩī‹Œī‹īˆ īˆēī‹’īŠ¤ī‰™ī‹īŠŋ
                       īˆ  īˆ īˆŽī‹‘ī‰Ēī‰‰ī‰‚īŠ§īˆ ī‹’īŠģī‰‚ī‰™īˆ ī‹ī‰ƒīˆ ī‹‹ī‰ƒīˆ īˆ’ī‰‚īŠ¨īŠī‰īˆ īˆ—īŠ°ī‰ļī‰īˆ ī‹•ī‰‚ī‹„ī‰‘ī‰ƒīˆ ī‰ī‹ī‰‚ī‰ŠīŠģī‰īˆ ī‰ī‰¨ī‹‡īˆ ī‹’ī‹€ī‹ŽīŠŗīˆ īˆ—īŠŦī‰Žī‰īˆ ī‹†ī‰ƒīˆ ī‹…īŠ¸īŠ™īˆ ī‹‰ī‹ƒī‹žīˆ ī‰ĒīŠ°ī‰ĩīˆ ī‹†ī‰ī‹Œī‹„īŠ¨īŠģī‰

ī‹’ī‰ŽīŠ—ī‹žī‰ī‹‹īˆ ī‹īŠģī‹ ī‰īˆ ī‹īŠ¸ī‰šī‰ŽīŠģī‰īˆ ī‹’ī‰­ī‰Ļī‹„ī‹‡īˆ ī‹ī‰ŽīŠŗ                         242                            ī‹’ī‹Žī‹ƒī‹‹īˆ–īŠ¸īŠģī‹ĸī‰ī‹‹īˆ ī‹’ī‹Žī‹–ī‰‚ī‰‰ī‰Ēī‹ˆīŠ¸īŠģī‰īˆ ī‹’ī‰­ī‰Ļī‹„īˆšī‰īˆ ī‹’ī‹ŽīŠŧīŠˇ
Practical Class 11                                         Programming Microcontrollers

                                                           īˆ  īˆ īˆē(1)īˆ ī‹‘ī‰Šī‰ī‰ĻīŠģī‰īˆ īŠŊī‹ŽīŠŦī‰˛ī‰īˆ ī‰—īŠŋī‰‚ī‹ƒī‰Ēī‰‰

$regfile = "m128def.dat"
                                                                  īˆ  īˆ īˆŽī‰ī‰‚ī‹ˆī‹Žī‰•ī‹Œī‰ŽīŠģī‰
$crystal = 4000000
$baud = 9600
'------------------
Dim B As Byte , I As Byte                              SRAMīˆ ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ īŠŸīˆ ī‰ī‹œī‹Œī‰šī‰ŽīŠŋīˆ īŠąī‹ī‰ĒīŠ¨ī‰
Dim W As Word , S As String * 5

Dim Eb As Eram Byte At 13
Dim Ei As Eram Integer At 14                        EEPROMīˆ ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ īŠŸīˆ ī‰ī‹œī‹Œī‰šī‰ŽīŠŋīˆ īŠąī‹ī‰ĒīŠ¨ī‰
Dim El As Eram Long At 16
Dim Es As Eram String * 5 At 20
'------------------
Do
   S = "ABCDE" : Es = S
   S = ""
   S = Es : Print S
                                                  īˆ SRAMīˆ  ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ  īŠŸīˆ  īŠžī‹Œī‰šī‰ŽīŠŋīˆ  ī‹’ī‹€ī‹ŽīŠŗīˆ  ī‰Ĩī‰‚ī‹„ī‰­ī‰‡
                                                         .EEPROMīˆ ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ īŠŸīˆ īŠžī‹Œī‰šī‰ŽīŠŋīˆ īŠ•ī‰‡
   B = 10 : Eb = B
   B = 0
   B = Eb : Print B
'/------

   For I = 0 To 4                                 īˆ ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ īŠŸīˆ  ī‰Ĩī‰ĻīŠŠīˆ ī‹†ī‰ī‹Œī‹„īŠ§īˆ ī‰Ļī‹„īŠ§īˆ ī‹’ī‹€ī‹ŽīŠŗīˆ  ī‹‘ī‹•ī‰ī‰ĒīŠŗ
      Readeeprom B , I                             īˆŽSRAMīˆ ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ īŠŸīˆ īŠžī‹Œī‰šī‰ŽīŠŋīˆ īŠ•ī‰‡īˆ EPROM
      Print B
   Next I
'/------                                                               īˆ  īˆ 
    S = "abcde" : W = 10000                       īˆ SRAMīˆ  ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ  īŠŸīˆ  īŠžī‹Œī‰šī‰ŽīŠŋīˆ  ī‹’ī‹€ī‹ŽīŠŗīˆ  ī‰Ĩī‰‚ī‹„ī‰­ī‰‡
    Writeeeprom S , 5
                                                   īˆŽEEPROMīˆ ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ īŠŸīˆ ī‰Ĩī‰ĻīŠŠīˆ ī‹†ī‰ī‹Œī‹„īŠ§īˆ īŠ•ī‰‡
    Writeeeprom W , 11

   S = "" : W = 0                                 īˆ ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ īŠŸīˆ  ī‰Ĩī‰ĻīŠŠīˆ ī‹†ī‰ī‹Œī‹„īŠ§īˆ ī‰Ļī‹„īŠ§īˆ ī‹’ī‹€ī‹ŽīŠŗīˆ ī‹‘ī‹•ī‰ī‰ĒīŠŗ
   Readeeprom S , 5 : Print S
   Readeeprom W , 11 : Print W                     īˆŽSRAMīˆ ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ īŠŸīˆ īŠžī‹Œī‰šī‰ŽīŠŋīˆ īŠ•ī‰‡īˆ EPROM
'/------

   Restore Lbl
   Read B : Print B                               īˆ ī‹’ī‰ŽīŠ¯ī‹œīˆ ī‰Ļī‹„īŠ§īˆ SRAMīˆ ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ īŠ•ī‰‡īˆ ī‹ī‹ŽīŠŗīˆ īŠŊī‹Žī‹€īŠ„
   Read B : Print B                                īˆŽROMīˆ ī‰—īŠŋī‰‚ī‹ƒīˆ•īŠģī‰īˆ ī‹‘ī‰ĒīŠˇī‰ī‰§īˆ īŠŸīˆ ī‹’ī‹ƒī‰ŦīŠ‹ī‹‹īˆ ī‹‘ī‰Ĩī‰ĻīŠŠ
Loop
End
'------------------                                         īˆŽROMīˆ ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ īŠŸīˆ ī‹ī‹ŽīŠŗīˆ ī‹…ī‹ī‰ŦīŠ…
Lbl:
Data 10 , 12
'------------------                                     īˆŽEEPROMīˆ ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ īŠŸīˆ ī‹ī‹ŽīŠŗīˆ ī‹…ī‹ī‰ŦīŠ…
$eeprom
   Data 1 , 2 , 3 , 4 , 5
$data

                                                                                      īˆ  īˆ 

                                                                                      īˆ  īˆ 
Faculty of Electrical and Electronic Eng.   243     Automatic Control & Automation Dept.
ī‹‘ī‰ĒīŠŦī‰ļīŠī‰īˆ ī‰ī‰‚ī‹€īŠ¸ī‰šī‰ŽīŠī‰īˆ ī‹’īŠ‰ī‰Ēī‰‰                                         īˆ  īˆ  ī‹‘ī‰Ēī‰˛īŠ§īˆ ī‹’ī‹ī‰Ĩī‰‚īŠ‡ī‰īˆ ī‹’ī‰ŽīŠŧīŠ†ī‰

                                                  īˆ  īˆ īˆē(2)īˆ ī‹‘ī‰Šī‰ī‰ĻīŠģī‰īˆ īŠŊī‹ŽīŠŦī‰˛ī‰īˆ ī‰—īŠŋī‰‚ī‹ƒī‰Ēī‰‰

$regfile = "m128def.dat"
$crystal = 4000000
$baud = 9600                                             īˆ  īˆ īˆŽī‰ī‰‚ī‹ˆī‹Žī‰•ī‹Œī‰ŽīŠģī‰
$eepromhex
$eepleave
'------------------
Dim Var As Sram Byte At &H200
'------------------                    īˆ ī‰Ļī‹„īŠ§īˆ  EEPROMīˆ  ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ  īŠŸīˆ  ī‹ī‹ŽīŠŗīˆ  ī‹…ī‹ī‰ŦīŠ…
$eeprom
   Label1:                                                      īˆŽī‹‘ī‰Ĩī‰ĻīŠŠīˆ ī‰ī‰‚ī‰ŽīŠ¯ī‹œ
   Data 1 , 2 , 3 , 4 , 5

   Label2:
   Data 10 , 20 , 30 , 40 , 50
$data
'------------------                    īˆ ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ īŠŸīˆ  ī‹‘ī‰Ĩī‰ĻīŠŠīˆ  ī‹’ī‰ŽīŠ¯ī‹œīˆ ī‰Ļī‹„īŠ§īˆ ī‹’ī‹€ī‹ŽīŠŗīˆ ī‹‘ī‹•ī‰ī‰ĒīŠŗ
   Readeeprom Var , Label1              īˆŽSRAMīˆ ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ īŠŸīˆ īŠžī‹Œī‰šī‰ŽīŠŋīˆ īŠ•ī‰‡īˆ EPROM
      Print Var
         Readeeprom Var
            Print Var
'/------
                                       īˆ ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ īŠŸīˆ  ī‹‘ī‰Ĩī‰ĻīŠŠīˆ  ī‹’ī‰ŽīŠ¯ī‹œīˆ ī‰Ļī‹„īŠ§īˆ ī‹’ī‹€ī‹ŽīŠŗīˆ ī‹‘ī‹•ī‰ī‰ĒīŠŗ
                                        īˆŽSRAMīˆ ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ īŠŸīˆ īŠžī‹Œī‰šī‰ŽīŠŋīˆ īŠ•ī‰‡īˆ EPROM
   Readeeprom Var , Label2
      Print Var
         Readeeprom Var
            Print Var                                          īˆ  īˆ 
'/------

                                       īˆ SRAMīˆ  ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ  īŠŸīˆ  īŠžī‹Œī‰šī‰ŽīŠŋīˆ  ī‹’ī‹€ī‹ŽīŠŗīˆ  ī‰Ĩī‰‚ī‹„ī‰­ī‰‡
    Var = 100
    Writeeeprom Var , Label1           īˆŽī‹‘ī‰Ĩī‰ĻīŠŠīˆ ī‹’ī‰ŽīŠ¯ī‹œīˆ ī‰Ļī‹„īŠ§īˆŽEEPROMīˆ ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ īŠ•ī‰‡
    Var = 101
    Writeeeprom Var

   Readeeprom Var , Label1
      Print Var
   Readeeprom Var
      Print Var
'/------


   Var = 0
   Writeeeprom Var , 3
      Readeeprom Var , 3
         Print Var
End


                                                                               īˆ  īˆ 
                                          īˆ  īˆ īˆ                                    īˆ 



ī‹’ī‰ŽīŠ—ī‹žī‰ī‹‹īˆ ī‹īŠģī‹ ī‰īˆ ī‹īŠ¸ī‰šī‰ŽīŠģī‰īˆ ī‹’ī‰­ī‰Ļī‹„ī‹‡īˆ ī‹ī‰ŽīŠŗ     244             ī‹’ī‹Žī‹ƒī‹‹īˆ–īŠ¸īŠģī‹ĸī‰ī‹‹īˆ ī‹’ī‹Žī‹–ī‰‚ī‰‰ī‰Ēī‹ˆīŠ¸īŠģī‰īˆ ī‹’ī‰­ī‰Ļī‹„īˆšī‰īˆ ī‹’ī‹ŽīŠŧīŠˇ
Practical Class 11                                                     Programming Microcontrollers

      Exp.31: Interfacing with I2C                            I2Cīˆ īŠžī‹ŒīŠˇī‹Œī‰ī‹‹īˆ•īŠģī‰īˆ īˆēī‹†ī‹Œī‰‘ī‹ī‰’īŠģī‰ī‹‹īˆ ī‹‘ī‰Ļī‰™ī‰ī‹ŒīŠģī‰īˆ ī‹’ī‰‰ī‰Ēī‰–ī‰ŽīŠģī‰

                                                                                   īˆ  īˆ īˆēī‹’ī‰‰ī‰Ēī‰–ī‰ŽīŠģī‰īˆ ī‹…īŠŋīˆ ī‹’ī‹ī‰‚īŠŦīŠģī‰
  īˆ ī‹…īŠŋī‰ŦīŠģī‰īˆ  ī‰Ļī‹ŽīŠģī‹Œī‰īˆ  ī‹‘ī‰Šī‰ī‰Ĩī‹‹īˆ  EEPROMīˆ  ī‹’ī‹ŽīŠŧī‰ŽīŠŧī‰Žī‰īˆ  ī‰ī‰‚ī‹Žī‹ąīŠ¨īŠŋīˆ  ī‹‘ī‰ĒīŠˇī‰ī‰§īˆ  ī‹’īŠ‰ī‰Ēī‰‰īˆ  īŠžī‹ī‰Ąīˆ  ī‹…īŠŋīˆ  I2Cīˆ  īŠžī‹ŒīŠˇī‹Œī‰ī‹‹īˆ•īŠģī‰īˆ  īŠŊī‹€īŠ§īˆ  ī‰ƒī‰Ļī‰ŠīŠŋīˆ  ī‹’ī‰­ī‰ī‰Šī‰Ĩ
                                                                                       īˆ  īˆ  .RTC ī‹īŠ´ī‹ŽīŠ´īŠ‡ī‰

                                                                                       īˆ  īˆ īˆēī‹‘ī‰Šī‰ī‰ĻīŠģī‰īˆ īŠĄī‹ąīŠ‹




īˆ  īˆ 


      Faculty of Electrical and Electronic Eng.      245               Automatic Control & Automation Dept.
ī‹‘ī‰ĒīŠŦī‰ļīŠī‰īˆ ī‰ī‰‚ī‹€īŠ¸ī‰šī‰ŽīŠī‰īˆ ī‹’īŠ‰ī‰Ēī‰‰                                                                 īˆ  īˆ  ī‹‘ī‰Ēī‰˛īŠ§īˆ ī‹’ī‹ī‰Ĩī‰‚īŠ‡ī‰īˆ ī‹’ī‰ŽīŠŧīŠ†ī‰

                                                                                 īˆēI2Cīˆ īŠžī‹ŒīŠˇī‹Œī‰ī‹‹īˆ•īŠģī‰īˆ īŠŊī‹€īŠ§īˆ ī‰ƒī‰Ļī‰ŠīŠŋ
  īˆ īŠ˛ī‰Ļī‹ˆī‰‰īˆ  Philipsīˆ ī‹’īŠˇī‰Ēī‰ąīˆ īŠŊī‰ŠīŠŗīˆ ī‹…īŠŋīˆ  1980īˆ ī‹‚ī‰‚īŠ§īˆ īŠŊī‹–ī‰ī‹‹ī‰ƒīˆ īŠŸīˆ īˆ¨Inter-Integrated CircuitīˆŠīˆ  I2Cīˆ  īŠžī‹ŒīŠˇī‹Œī‰ī‹‹īˆ•īŠģī‰īˆ īˆ•ī‰ŽīŠ¨ī‹ī‹‹īˆ ī‰Ēī‹ī‹Œī‹ąī‰īˆ īˆƒ
  īˆ ī‰Ģī‰‚īŠ°īŠŧī‰ŽīŠģī‰īˆ ī‹‘ī‰Ŧī‹ˆī‰•ī‰ƒīˆ īŠŸīˆ ī‰ī‰‚ī‹Žī‹ąī‹Žīˆī‰īˆ ī‰ŧīŠ¨ī‰‰īˆ īŠŠīŠŋīˆ ī‹īŠ¸ī‰šī‰ŽīŠŋīˆ īŠĄī‰‰ī‰Šīˆ īŠŊī‰•ī‰ƒīˆ ī‹…īŠŋī‹‹īˆ īˆ¨TVīˆŠīˆ ī‹’ī‹Žī‹ƒī‹‹īˆ–īŠ¸īŠģī‹ĸī‰īˆ ī‰ī‰‚ī‰–ī‰Žī‹„īŠī‰īˆ īŠŠī‹Žī‹„ī‰ļī‰īˆ ī‹’īŠ°īŠŧīŠˇīˆ ī‰ŧī‹ŽīŠ°īŠ…
                       īˆ  īˆ īˆŽīˆ¨Two Wire InterfaceīˆŠīˆ TWIīˆ ī‹ĩī‰‚ī‰ēī‹ī‰ƒīˆ ī‹“ī‹€ī‰Žī‹ī‹‹īˆ ī‹’ī‹Žī‹ƒī‹‹īˆ–īŠ¸īŠģī‹ĸī‰īˆ ī‹‘ī‰Ŧī‹ˆī‰•ī‹žī‰īˆ īŠŸīˆ ī‹ĩī‰‚īŠŋī‰ī‰Ļī‰ĸī‰Žī‰­ī‰īˆ ī‰Ēī‰’īŠˇī‹žī‰īˆ īˆ•ī‰ŽīŠ¨ī‹ī‹‹
                                                                                                            īˆ  īˆ 
  īˆ īˆŦīˆ¨SDA, SCKīˆŠīˆ  īŠ”ī‹ąī‰Ąīˆ  ī‹“īŠŧīŠ§īˆ  ī‰Ļī‹€ī‰ŽīŠ¨ī‰īˆ  īˆžīŠģī‰īˆ  ī‹’ī‹„īŠŋī‰ī‰Ŧī‰ŽīŠī‰īˆ  ī‹īŠŧī‰ŽīŠŧī‰Žī‰ŽīŠģī‰īˆ  īŠžī‰‚ī‰ļī‰ī‹œī‰īˆ  ī‰ī‹œī‹ŒīŠˇī‹Œī‰ī‹‹ī‰Ēī‰‰īˆ  ī‹…īŠŋīˆ  I2Cīˆ  īŠžī‹ŒīŠˇī‹Œī‰ī‹‹īˆ•īŠģī‰īˆ  īŠąī‹„ī‰ļī‹
  īˆ īŠĄīŠˆī‰īˆ ī‰‚īŠŋī‰ƒīˆ īˆŦī‰¯īŠ¸īŠ¨īŠģī‰īˆ ī‹‹ī‰ƒīˆ īŠŊī‰ŠīŠ´ī‰Žī‰ŽīŠī‰īˆ īŠ•ī‰‡īˆ īŠŊī‰­ī‰ĒīŠī‰īˆ ī‹…īŠŋīˆ ī‰ī‰‚ī‹ƒī‰‚ī‹Žī‰ŠīŠģī‰īˆ ī‹Šī‰‚īŠƒī‰īˆ ī‹†ī‹ŒīŠ¸ī‹īˆ ī‹†ī‰ƒīˆ ī‰‚īŠŋī‰ˆīŠ¯īˆ īˆŦī‹Šī‰‚īŠƒī‹œī‰īˆ ī‹ī‹–ī‰‚ī‹„ī‰‘īˆ ī‹ĩī‰‚ī‹€ī‹–ī‰ī‰Ĩīˆ  SDAīˆ īŠĄīŠˆī‰
  īˆ īŠŸīˆ  ī‹Šī‰‚īŠƒī‹œī‰īˆ  ī‹ī‹–ī‰‚ī‹„ī‰‘īˆ  ī‹†ī‹ŒīŠ¸ī‹ī‹‹īˆ  One-Master<>Multi-Slavesīˆ  ī‰ƒī‰Ļī‰ŠīŠŋīˆ  ī‰Ļī‹€ī‰ŽīŠ¨ī‰īˆ  īˆžīŠģī‰īˆ  ī‹’ī‹€īŠ¤ī‹ƒī‹žī‰īˆ  īŠŸīˆ  ī‹Šī‰‚īŠƒī‹œī‰īˆ  ī‹ī‰Ĩī‰‚ī‰™ī‰ƒīˆ  ī‹Œī‹ˆīŠ¯īˆ  SCK
                                                     īˆŽMulti-Master<>Multi-Slavesīˆ ī‰ƒī‰Ļī‰ŠīŠŋīˆ ī‹“īŠŧīŠ§īˆ ī‰Ļī‹€ī‰ŽīŠ¨ī‰īˆ īˆžīŠģī‰īˆ ī‹’ī‹€īŠ¤ī‹ƒī‹žī‰

  īˆ īŠŊī‰•ī‰ƒīˆ ī‹…īŠŋīˆ īŠŊī‹€īŠ¨ī‹ī‹‹īˆ īˆŦī‹’ī‹ąī‰­ī‹Œī‰ŽīŠŋī‹‹īˆ ī‹’ī‰ēīŠ°ī‰ĸī‹„īŠŋīˆ īŠŊīŠ´ī‹ƒīˆ ī‰ī‰‚īŠ§ī‰Ēī‰­īˆ ī‰Ļī‹„īŠ§īˆ  Chip-to-Chipīˆ īŠĄī‰‰ī‰Šīˆ īŠŊī‰•ī‰ƒīˆ ī‹…īŠŋīˆ īŠžī‹ŒīŠˇī‹Œī‰ī‹‹īˆ•īŠģī‰īˆ ī‰ī‰¨ī‹‡īˆ ī‹‚ī‰Ļī‰ĸī‰Žī‰Žī‹
  īˆ īˆ¨Multi-SlaveīˆŠīˆ ī‰Ĩī‰‚īŠ´īŠŋīˆ ī‹…īŠŋīˆ ī‰Ēī‰’īŠˇī‰ƒī‹‹īˆ īˆ¨MasterīˆŠīˆ  ī‰Ļī‹Žī‰™ī‹‹īˆ  ī‰Ļī‹–ī‰‚īŠŗīˆ īŠŊīŠ´ī‹„īŠģī‰īˆ  īŠĄī‰Ąīˆ ī‹“īŠŧīŠ§īˆ ī‰Ļī‰•ī‰ī‹Œī‰Žī‹īˆ ī‹†ī‰ƒīˆ ī‹…īŠ¸īŠ™īˆ ī‰“ī‹Žī‰™īˆ  Multi-Drop Bus
  īˆ ī‰Ĩī‹Œī‰•ī‹‹īˆ ī‰Ēī‰’īŠˇī‰ƒīˆ ī‹…īŠŋīˆ ī‹Šī‰Ĩī‰ī‰ĻīŠ§ī‰‡īˆ ī‹…īŠ¸īŠ™īˆ  ī‰‚ī‹€īŠˇīˆ īˆŦīˆ¨Master<>SlaveīˆŠīˆ  ī‹’īŠ¤ī‰šīŠŧīŠģī‰īˆ ī‰¯īŠ°ī‹ƒīˆ īŠŸīˆ ī‹ĩī‰‚īŠ¨īŠŋīˆ īŠĄīŠ´īŠ¯īˆ ī‹…ī‹ī‰Ģī‰‚ī‹ˆī‰•īˆ īŠ”ī‰‰īˆ ī‰‹ī‰ŋī‰‚ī‰ĸī‰ŽīŠģī‰īˆ ī‹ī‰Žī‹ī‹‹
                                               īˆ  īˆ īˆŽīˆ¨Multi-SlaveīˆŠīˆ ī‰Ĩī‰‚īŠ´īŠŋīˆ ī‹…īŠŋīˆ ī‰Ēī‰’īŠˇī‰ƒī‹‹ īˆ¨Multi-MasterīˆŠīˆ ī‰Ļī‹–ī‰‚īŠŗīˆ ī‹…īŠŋīˆ ī‰Ēī‰’īŠˇī‰ƒ

  īˆ īˆŦSDA, SCKīˆ ī‹īŠ¸īŠģīˆ īŠŠīŠ¯ī‰Šīˆ ī‰ī‰‚īŠŋī‹‹ī‰‚īŠ´īŠŋīˆ īŠĄī‰‰ī‰Šīˆ ī‹ī‰Žī‹īˆ īŠšīŠģī‰¨īŠģīˆ īˆŦOpen collectorīˆ īŠĒī‹Œī‹ƒīˆ ī‹…īŠŋīˆ ī‹Œī‹‡īˆ  I2Cīˆ īŠžī‹ŒīŠˇī‹Œī‰ī‹‹īˆ•īŠģī‰īˆ īŠŸīˆ ī‹‘ī‰Ŧī‹ˆī‰•ī‹žī‰īˆ ī‰˜ī‰Ēī‰Ą
                                                             īˆ  īˆ īˆŽâ€œ1”īˆ īŠ”ī‹ąīŠˆī‰īˆ ī‹īŠˇīˆ ī‹’īŠģī‰‚ī‰™īˆ ī‹†ī‹ŒīŠ¸ī‰īˆ ī‹’īŠģī‰‚ī‹ąī‰ŠīŠģī‰īˆ īŠžī‰‚ī‰™īˆ īŠŸī‹‹

  īˆ ī‹‹ī‰ƒīˆ īˆŦīˆ¨112 nodesīˆŠīˆ  7-Bitīˆ ī‹…īŠŋīˆ īŠąīŠģī‹›īŠŋīˆ īˆ¨Unique AddressīˆŠīˆ ī‰Ļī‹ī‰ĒīŠ¯īˆ ī‹†ī‰ī‹Œī‹„īŠ§īˆ īŠšīŠŧīŠ™īˆ  I²Cīˆ īŠžī‹ŒīŠˇī‹Œī‰ī‹‹īˆ•īŠģī‰īˆ īŠĩīŠ¯ī‹‹īˆ īŠŊī‹€īŠ¨ī‹īˆ ī‰Ģī‰‚ī‹ˆī‰•īˆ īŠŊīŠˇ
  īˆ ī‹…īŠŋīˆ ī‹‰īŠ¨īŠŋīˆ ī‰‹ī‰ŋī‰‚ī‰ĸī‰ŽīŠģī‰īˆ ī‰Ĩī‰ī‰ĒīŠī‰īˆ  ī‰Ĩī‰‚īŠ´īŠī‰īˆ  ī‰Ģī‰‚ī‹ˆīŠ†ī‰īˆ ī‰Ļī‹ī‰Ļī‰šī‰ŽīŠģīˆ ī‹†ī‰ī‹Œī‹„īŠ¨īŠģī‰īˆ ī‰ī‰¨ī‹‡īˆ ī‹‚ī‰Ļī‰ĸī‰Žī‰Žī‹īˆ īˆ¨1008 nodesīˆŠīˆ  10-bitīˆ ī‹†ī‰ī‹Œī‹„īŠ¨ī‰‰īˆ ī‰ĒīŠ¯ī‹Œī‰Žī‹īˆ ī‹†ī‰ƒīˆ ī‹…īŠ¸īŠ™
                                                                                                īˆ  īˆ īˆŽī‰Ļī‹–ī‰‚īŠ´īŠģī‰īˆ īŠŊī‰ŠīŠŗ

  īˆ ī‰Ģī‹‹ī‰‚ī‰–ī‰Žī‰īˆ ī‹œīˆ ī‹†ī‰ƒīˆ ī‰‹īŠīˆ ī‹’īŠ¨ī‰ŽīŠŧīŠģīˆ ī‹’ī‹Žī‹€īŠ¤īŠ§ī‹žī‰īˆ ī‹’ī‹€ī‹ŽīŠ´īŠģī‰īˆ ī‹†ī‰ƒīˆ ī‰“ī‹Žī‰™īˆ īŠĄīŠˆī‰īˆ ī‹’īŠ¨ī‰­īˆ ī‹“īŠŧīŠ§īˆ ī‹‘ī‰Ēī‰ąī‰‚ī‰ŠīŠŋīˆ ī‰Ļī‹€ī‰ŽīŠ¨ī‹īˆ īŠŊīŠ´ī‹„īŠģī‰īˆ īŠĄī‰Ąīˆ ī‹“īŠŧīŠ§īˆ ī‹‘ī‰Ŧī‹ˆī‰•ī‹žī‰īˆ ī‰Ĩī‰ĻīŠ§īˆ ī‹†ī‰‡
                                                         īˆ  īˆ īˆŽ10pFīˆ ī‰Ĩī‹‹ī‰ĻīŠīˆ ī‰Ģī‰‚ī‹ˆī‰•īˆ īŠŊīŠˇīˆ ī‹’īŠ¨ī‰­īˆ ī‹†ī‹ŒīŠ¸ī‰īˆ ī‹ĩī‰‚ī‰ŠīŠģī‰‚īŠĢī‹‹īˆ īˆŦ400pF

                                                                                                            īˆ  īˆ 




īˆ  īˆ 


      ī‹’ī‰ŽīŠ—ī‹žī‰ī‹‹īˆ ī‹īŠģī‹ ī‰īˆ ī‹īŠ¸ī‰šī‰ŽīŠģī‰īˆ ī‹’ī‰­ī‰Ļī‹„ī‹‡īˆ ī‹ī‰ŽīŠŗ                    246                      ī‹’ī‹Žī‹ƒī‹‹īˆ–īŠ¸īŠģī‹ĸī‰ī‹‹īˆ ī‹’ī‹Žī‹–ī‰‚ī‰‰ī‰Ēī‹ˆīŠ¸īŠģī‰īˆ ī‹’ī‰­ī‰Ļī‹„īˆšī‰īˆ ī‹’ī‹ŽīŠŧīŠˇ
Practical Class 11                                                        Programming Microcontrollers




                                            īˆ  īˆ 
                                                                                                    īˆ  īˆ 

                                                             īˆ  īˆ īˆēI2Cīˆ īŠžī‰‚ī‰ļī‰ī‹œī‰īˆ īŠžī‹ŒīŠˇī‹Œī‰īˆ•īŠģīˆ ī‹™ī‹‹ī‰‚ī‰ŽīŠī‰ī‹‹īˆ ī‰ī‰ī‰Ŧī‹ŽīŠī‰
             īˆ  īˆ īˆ¨AdvantagesīˆŠīˆ ī‹…ī‰­ī‰‚īˆī‰                           īˆ  īˆ īˆ¨DisadvantagesīˆŠīˆ ī‹™ī‹‹ī‰‚ī‰ŽīŠī‰
īˆŽīŠ”ī‹ąī‰Ąīˆ ī‹‚ī‰ī‰Ļī‰ĸī‰Žī‰­ī‰‚ī‰‰īˆ Slaveīˆ ī‹…īŠŋīˆ ī‰Ēī‰’īŠˇī‰ƒīˆ īŠŠīŠŋīˆ ī‰‹ī‰ŋī‰‚ī‰ĸī‰ŽīŠģī‰īˆ ī‹…īŠ¸īŠ™ Ãŧ                        .(3meter)īˆ ī‹‘īˆ—ī‰ļīŠŗīˆ īŠžī‰‚ī‰ļī‰ī‹œī‰īˆ ī‹’īŠ¯ī‰‚ī‰ŽīŠŋ ×
                 īˆŽīŠĩī‹Žī‰Šī‹ąī‰ŽīŠģī‰īˆ īŠŊī‹ˆī‰­ī‹‹īˆ īˆŦī‹’ī‰ēīŠ°ī‰ĸī‹„īŠŋīˆ ī‹•ī‰‚ī‹„ī‰ŠīŠģī‰īˆ ī‹’īŠ°īŠŧīŠˇ Ãŧ              īˆŽ400Khzīˆ ī‰Ģī‹‹ī‰‚ī‰–ī‰Žī‰īˆ ī‹œīˆ ī‹’ī‰ēīŠ°ī‰ĸī‹„īŠŋīˆ ī‰ī‰‚īŠ§ī‰Ēī‰­ ×
   īˆŽī‹ĩī‰‚ī‹ŽīŠ‰ī‰Ēī‰‰ī‹‹īˆ ī‰‹īŠŧī‰ĩīˆ ī‹†ī‰‚ī‹ŽīŠ¸īŠˇīˆ ī‰ĒīŠ¯ī‹Œī‰ŽīŠŋī‹‹īˆ īˆŦī‹‚ī‰ī‰Ļī‰ĸī‰Žī‰­ī‹œī‰īˆ īŠŠī‹–ī‰‚ī‰ą Ãŧ                           īˆŽī‹‘ī‰Ŧī‹ˆī‰•ī‹žī‰īˆ īˆ ī‹…ī‹ī‹‹ī‰‚ī‹„īŠ§īˆ īŠŸīˆ ī‹’ī‹ī‰Ĩī‹‹ī‰ĻīŠŠ ×
īˆ īˆ—ī‰‘ī‰„ī‰īˆ ī‹ī‰ƒīˆ ī‹†ī‹‹ī‰Ĩīˆ īŠŊīŠŗī‰‚ī‹„īŠģī‰īˆ ī‹…īŠŋīˆ ī‰Ģī‰‚ī‹ˆī‰•īˆ ī‹ī‰ƒīˆ īŠŊī‰ĩī‹‹ī‹‹īˆ īŠŊī‰ļīŠ¯īˆ ī‹…īŠ¸īŠ™ Ãŧ
                        īˆŽīˆ—ī‹ŽīŠŦī‰īˆ ī‹ī‹žīˆ ī‹’ī‰•ī‰‚īŠ‡ī‰īˆ ī‹‹ī‰ƒīˆ ī‹‚ī‰‚īŠ¤ī‹„īŠģī‰īˆ ī‹“īŠŧīŠ§




Faculty of Electrical and Electronic Eng.              247          Automatic Control & Automation Dept.
ī‹‘ī‰ĒīŠŦī‰ļīŠī‰īˆ ī‰ī‰‚ī‹€īŠ¸ī‰šī‰ŽīŠī‰īˆ ī‹’īŠ‰ī‰Ēī‰‰                                                                      īˆ  īˆ  ī‹‘ī‰Ēī‰˛īŠ§īˆ ī‹’ī‹ī‰Ĩī‰‚īŠ‡ī‰īˆ ī‹’ī‰ŽīŠŧīŠ†ī‰

                                     Interfacing I2C EEPROM
Description:

I²C is an abbreviation of Inter Integrated Circuit and is a protocol for serial communication between
Integrated Circuits, it is also called Two Wire Interface (TWI). The bus is used for communication
between microcontrollers and peripheral devices like memories, temperature sensors and I/O
expanders. An EEPROM is a Electrically Erasable and Programmable Read Only Memory.

  EEPROM Model                    Size             Internally Organized                Address (hex)
AT24C01                        128 Bytes          128 x 8    = 1024   bits             00000 >> 0007F
AT24C02                        256 Bytes          256 x 8    = 2048   bits             00000 >> 000FF
AT24C04                        512 Bytes          512 x 8    = 4096   bits             00000 >> 001FF
AT24C08                        1 Kbyte            1024 x 8 = 8192     bits             00000 >> 003FF
AT24C16                        2 Kbyte            2048 x 8 = 16384 bits                00000 >> 007FF
AT24C32                        4 Kbyte            4096 x 8 = 32768 bits                00000 >> 00FFF
AT24C64                        8 Kbyte            8192 x 8 = 65536 bits                00000 >> 01FFF
AT24C128                       16 Kbyte           16384 x 8 = 131072 bits              00000 >> 03FFF
AT24C256                       32 Kbyte           32768 x 8 = 262144 bits              00000 >> 07FFF
AT24C512                       64 Kbyte           65536 x 8 = 524288 bits              00000 >> 0FFFF
AT24C1024                      128 Kbyte          131072 x 8 = 1048576 bits            00000 >> 1FFFF

The communication of the bus goes along two lines: SDA (Serial Data) and SCL (Serial Clock). Each I²C
device has a unique 7-bit address (Device Select Code). The most significant bits are fixed and
assigned to a specific device category (e.g. b1010 is assigned to serial EEPROMS). The three less
significant bits (A2,A1 and A0) are programmable and used to address the device. The three bits
allows eight different I2C address combinations and therefore allowing up to eight different devices of
that type to operate on the same I2C-bus. The I2C address is send in the 1st byte, the lest signi icant bit
of the first byte is used to indicate if the master is going to write(0) or read(1) from the slave.




The device that sends data along the bus is called master, a device that receives the data is called
slave. The master starts the transmission with a start signal and stops the transmission with a stop
signal on the SDA line. During the start and stop signals the SCL line has to be high. After the master
has started the data-transmission with a start signal, the master writes a device address byte to the

ī‹’ī‰ŽīŠ—ī‹žī‰ī‹‹īˆ ī‹īŠģī‹ ī‰īˆ ī‹īŠ¸ī‰šī‰ŽīŠģī‰īˆ ī‹’ī‰­ī‰Ļī‹„ī‹‡īˆ ī‹ī‰ŽīŠŗ                       248                        ī‹’ī‹Žī‹ƒī‹‹īˆ–īŠ¸īŠģī‹ĸī‰ī‹‹īˆ ī‹’ī‹Žī‹–ī‰‚ī‰‰ī‰Ēī‹ˆīŠ¸īŠģī‰īˆ ī‹’ī‰­ī‰Ļī‹„īˆšī‰īˆ ī‹’ī‹ŽīŠŧīŠˇ
Practical Class 11                                                          Programming Microcontrollers

slave. Each data byte has to have a length of 8 bits. The slave has to acknowledge the reception of the
data byte with a acknowledge-bit (ACK).




A write operation requires a device address bytes, two address bytes and the data-byte. Upon receive
of the address the EEPROM sends an ACK and then clocks in the data-byte. The EEPROM sends again
an ACK and the microcontrollers sends a stop-signal to terminate the write sequence.




All devices from 32K – 512K will require no system changes and can be interchanged with only the
page size differences to consider.

Low Density Random Read:




Faculty of Electrical and Electronic Eng.           249               Automatic Control & Automation Dept.
ī‹‘ī‰ĒīŠŦī‰ļīŠī‰īˆ ī‰ī‰‚ī‹€īŠ¸ī‰šī‰ŽīŠī‰īˆ ī‹’īŠ‰ī‰Ēī‰‰                                                                       īˆ  īˆ  ī‹‘ī‰Ēī‰˛īŠ§īˆ ī‹’ī‹ī‰Ĩī‰‚īŠ‡ī‰īˆ ī‹’ī‰ŽīŠŧīŠ†ī‰

Medium and High Density Random Read:




                                          AT24C32 (4 Kbyte)
       4096 * 8 = 32768 bits                  0000 >> 0FFF                                      32 byte page

            &H0000                       Saturday [128 Set]
                                                    128 x 4 = 215 Bytes

                                                  512Bytes                &H01FF
                               &H0200 Sunday [128 Set]
                                                128 x 4 = 215 Bytes

                                                  512Bytes                &H03FF
                               &H0400 Monday [128 Set]
                                               128 x 4 = 215 Bytes

                                                  512Bytes                &H05FF
                               &H0600 Tuesday [128 Set]
                                                128 x 4 = 215 Bytes

                                                  512Bytes                &H07FF
                               &H0800 Wednesday [128 Set]
                                              128 x 4 = 215 Bytes

                                                  512Bytes                &H09FF
                               &H0A00 Thursday [128 Set]
                                                128 x 4 = 215 Bytes

                                                  512Bytes                &H0BFF
                               &H0C00 Friday [128 Set]
                                                 128 x 4 = 215 Bytes

                                                  512Bytes                &H0DFF
                               &H0E00                 NON USED AREA


                                                  512Bytes                                     &H0FFF
[




ī‹’ī‰ŽīŠ—ī‹žī‰ī‹‹īˆ ī‹īŠģī‹ ī‰īˆ ī‹īŠ¸ī‰šī‰ŽīŠģī‰īˆ ī‹’ī‰­ī‰Ļī‹„ī‹‡īˆ ī‹ī‰ŽīŠŗ                          250                          ī‹’ī‹Žī‹ƒī‹‹īˆ–īŠ¸īŠģī‹ĸī‰ī‹‹īˆ ī‹’ī‹Žī‹–ī‰‚ī‰‰ī‰Ēī‹ˆīŠ¸īŠģī‰īˆ ī‹’ī‰­ī‰Ļī‹„īˆšī‰īˆ ī‹’ī‹ŽīŠŧīŠˇ
Practical Class 11                                                                         Programming Microcontrollers

Software:

The BASCOM-AVR compiler is used to make a program that writes and reads one byte from the EEPROM. BASCOM has
several embedded commands to control the I2C bus.

In BASCOM-AVR you irst have to con igure the ports you use for the SDA and SCL lines of the I2C bus. Then you send the
device address to select the EEPROM that is connected to the I2C bus. After that you send two bytes to the EEPROM to select
the address in the EEPROM to which you want to write the data. The last byte to send in a write sequence is the data byte.


$regfile = "m16def.dat"
$crystal = 2000000
$lib "I2C_TWI.LBX"
$baud = 9600
'---------------------------
Config Scl = Portc.0
Config Sda = Portc.1
Config Twi = 100000                                                                '100KHZ
'---------------------------
Const Addressw = 160                                                        '&B10100000 slave write address
Const Addressr = 161                                                        '&B10100001 slave read address
'---------------------------
Dim Adres_h As Byte , Adres_l As Byte
Dim Rd_value As Byte , Wr_value As Byte
'---------------------------
Do
   Input "Wr_value:" , Wr_value
   Input "Adres_l:" , Adres_l
   Input "Adres_h:" , Adres_h

    Gosub Write_eeprom
    Gosub Read_eeprom

    Print "Error W: " ; Err
    print "Wr_value: " ; Wr_value

   Print "Error R: " ; Err
   Print "Rd_value: " ; Rd_value
Loop
End
'---------------------------
Write_eeprom:
    I2cstart                                                                          'Start condition
    I2cwbyte Addressw                                                                 'Slave address
    I2cwbyte Adres_h                                                                  'H address of EEPROM
    I2cwbyte Adres_l                                                                  'L address of EEPROM
    I2cwbyte Wr_value                                                                 'Value to write
    I2cstop                                                                           'Stop condition
    Waitms 10                                                                         'Wait for 10 milliseconds
Return
'---------------------------
Read_eeprom:
   I2cstart                                                                           'Generate start
   I2cwbyte Addressw                                                                  'Slave adsress
   I2cwbyte Adres_h                                                                   'H address of EEPROM
   I2cwbyte Adres_l                                                                   'L address of EEPROM
   I2cstart                                                                           'Repeated start
   I2cwbyte Addressr                                                                  'Slave address (read)
   I2crbyte Rd_value , Nack                                                           'Read byte
   I2cstop                                                                            'Generate stop
Return
'---------------------------


                                                                                                                       īˆ  īˆ 
Faculty of Electrical and Electronic Eng.                     251                   Automatic Control & Automation Dept.

More Related Content

Viewers also liked

Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture4
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture4Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture4
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture4AL-AWAIL for Electronic Engineering
 
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture3
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture3Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture3
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture3AL-AWAIL for Electronic Engineering
 
fire preventing robot ppt copy
fire preventing robot ppt   copyfire preventing robot ppt   copy
fire preventing robot ppt copysunil958
 
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture10
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture10Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture10
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture10AL-AWAIL for Electronic Engineering
 
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture...
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture...Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture...
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture...AL-AWAIL for Electronic Engineering
 
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture8
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture8Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture8
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture8AL-AWAIL for Electronic Engineering
 
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture12
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture12Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture12
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture12AL-AWAIL for Electronic Engineering
 
Embedded System Microcontroller Interactive Course using BASCOM-AVR -Lecture5
Embedded System Microcontroller Interactive Course using BASCOM-AVR -Lecture5Embedded System Microcontroller Interactive Course using BASCOM-AVR -Lecture5
Embedded System Microcontroller Interactive Course using BASCOM-AVR -Lecture5AL-AWAIL for Electronic Engineering
 

Viewers also liked (9)

Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture4
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture4Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture4
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture4
 
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture3
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture3Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture3
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture3
 
fire preventing robot ppt copy
fire preventing robot ppt   copyfire preventing robot ppt   copy
fire preventing robot ppt copy
 
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture10
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture10Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture10
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture10
 
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture...
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture...Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture...
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture...
 
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture8
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture8Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture8
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture8
 
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture12
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture12Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture12
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture12
 
Embedded System Microcontroller Interactive Course using BASCOM-AVR -Lecture5
Embedded System Microcontroller Interactive Course using BASCOM-AVR -Lecture5Embedded System Microcontroller Interactive Course using BASCOM-AVR -Lecture5
Embedded System Microcontroller Interactive Course using BASCOM-AVR -Lecture5
 
RF Based Home Automation System
RF Based Home Automation SystemRF Based Home Automation System
RF Based Home Automation System
 

Similar to Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture11

rom-140919103032-phpapp02.pptx
rom-140919103032-phpapp02.pptxrom-140919103032-phpapp02.pptx
rom-140919103032-phpapp02.pptxRAJCHATTERJEE24
 
Open MP cheet sheet
Open MP cheet sheetOpen MP cheet sheet
Open MP cheet sheetPiyush Mittal
 
Reversing & malware analysis training part 4 assembly programming basics
Reversing & malware analysis training part 4   assembly programming basics Reversing & malware analysis training part 4   assembly programming basics
Reversing & malware analysis training part 4 assembly programming basics Abdulrahman Bassam
 
Read Only Memory
Read Only Memory Read Only Memory
Read Only Memory rohitladdu
 
X Mas 3
X Mas 3X Mas 3
X Mas 3z3a
 
XS Japan 2008 Services English
XS Japan 2008 Services EnglishXS Japan 2008 Services English
XS Japan 2008 Services EnglishThe Linux Foundation
 
Topic 11- Read Only Memory (ROM).pptx
Topic 11- Read Only Memory (ROM).pptxTopic 11- Read Only Memory (ROM).pptx
Topic 11- Read Only Memory (ROM).pptxMartMantilla1
 
Digital logic devices
Digital logic devicesDigital logic devices
Digital logic devicesNisarg Amin
 
Primary Memory: RAM, ROM and their Types
Primary Memory: RAM, ROM and their TypesPrimary Memory: RAM, ROM and their Types
Primary Memory: RAM, ROM and their TypesHem Pokhrel
 
Ram and rom pp1
Ram and rom pp1Ram and rom pp1
Ram and rom pp1StutiNagar
 
The 8051 Microcontroller and Embedded Systems
The 8051 Microcontroller and Embedded SystemsThe 8051 Microcontroller and Embedded Systems
The 8051 Microcontroller and Embedded SystemsAvijeet Negel
 
ROM(Read Only Memory )
ROM(Read Only Memory )ROM(Read Only Memory )
ROM(Read Only Memory )rohitladdu
 
Bootloader and MMU (english)
Bootloader and MMU (english)Bootloader and MMU (english)
Bootloader and MMU (english)Sneeker Yeh
 
Memory And Storages
Memory And StoragesMemory And Storages
Memory And StoragesArsalan Qureshi
 
Reversing & Malware Analysis Training Part 4 - Assembly Programming Basics
Reversing & Malware Analysis Training Part 4 - Assembly Programming BasicsReversing & Malware Analysis Training Part 4 - Assembly Programming Basics
Reversing & Malware Analysis Training Part 4 - Assembly Programming Basicssecurityxploded
 
SEMICONDUCTOR MEMORIES(RAM &ROM).pptx
SEMICONDUCTOR MEMORIES(RAM &ROM).pptxSEMICONDUCTOR MEMORIES(RAM &ROM).pptx
SEMICONDUCTOR MEMORIES(RAM &ROM).pptxMomin24
 

Similar to Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture11 (20)

Memory management
Memory managementMemory management
Memory management
 
rom-140919103032-phpapp02.pptx
rom-140919103032-phpapp02.pptxrom-140919103032-phpapp02.pptx
rom-140919103032-phpapp02.pptx
 
Open MP cheet sheet
Open MP cheet sheetOpen MP cheet sheet
Open MP cheet sheet
 
Reversing & malware analysis training part 4 assembly programming basics
Reversing & malware analysis training part 4   assembly programming basics Reversing & malware analysis training part 4   assembly programming basics
Reversing & malware analysis training part 4 assembly programming basics
 
Read Only Memory
Read Only Memory Read Only Memory
Read Only Memory
 
X Mas 3
X Mas 3X Mas 3
X Mas 3
 
XS Japan 2008 Services English
XS Japan 2008 Services EnglishXS Japan 2008 Services English
XS Japan 2008 Services English
 
L12-Forwarding.ppt
L12-Forwarding.pptL12-Forwarding.ppt
L12-Forwarding.ppt
 
Topic 11- Read Only Memory (ROM).pptx
Topic 11- Read Only Memory (ROM).pptxTopic 11- Read Only Memory (ROM).pptx
Topic 11- Read Only Memory (ROM).pptx
 
Digital logic devices
Digital logic devicesDigital logic devices
Digital logic devices
 
Primary Memory: RAM, ROM and their Types
Primary Memory: RAM, ROM and their TypesPrimary Memory: RAM, ROM and their Types
Primary Memory: RAM, ROM and their Types
 
Ram and rom pp1
Ram and rom pp1Ram and rom pp1
Ram and rom pp1
 
Open mp intro_01
Open mp intro_01Open mp intro_01
Open mp intro_01
 
Dual port ram
Dual port ramDual port ram
Dual port ram
 
The 8051 Microcontroller and Embedded Systems
The 8051 Microcontroller and Embedded SystemsThe 8051 Microcontroller and Embedded Systems
The 8051 Microcontroller and Embedded Systems
 
ROM(Read Only Memory )
ROM(Read Only Memory )ROM(Read Only Memory )
ROM(Read Only Memory )
 
Bootloader and MMU (english)
Bootloader and MMU (english)Bootloader and MMU (english)
Bootloader and MMU (english)
 
Memory And Storages
Memory And StoragesMemory And Storages
Memory And Storages
 
Reversing & Malware Analysis Training Part 4 - Assembly Programming Basics
Reversing & Malware Analysis Training Part 4 - Assembly Programming BasicsReversing & Malware Analysis Training Part 4 - Assembly Programming Basics
Reversing & Malware Analysis Training Part 4 - Assembly Programming Basics
 
SEMICONDUCTOR MEMORIES(RAM &ROM).pptx
SEMICONDUCTOR MEMORIES(RAM &ROM).pptxSEMICONDUCTOR MEMORIES(RAM &ROM).pptx
SEMICONDUCTOR MEMORIES(RAM &ROM).pptx
 

Recently uploaded

microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersChitralekhaTherkar
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
18-04-UA_REPORT_MEDIALITERAĐĄY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAĐĄY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAĐĄY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAĐĄY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 

Recently uploaded (20)

Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of Powders
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
CÃŗdigo Creativo y Arte de Software | Unidad 1
CÃŗdigo Creativo y Arte de Software | Unidad 1CÃŗdigo Creativo y Arte de Software | Unidad 1
CÃŗdigo Creativo y Arte de Software | Unidad 1
 
18-04-UA_REPORT_MEDIALITERAĐĄY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAĐĄY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAĐĄY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAĐĄY_INDEX-DM_23-1-final-eng.pdf
 

Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture11

  • 1. ī„ ī„  ī„  ī„ ī†Šī…šī…°ī…Ĩī…Ŋī…ģī…ī„ ī…Œī…‚ī…Ŋī…šī…’ī…‹ī…Ŋī…ģī…ī„ ī†Ēī…ī…Ŋī…šī…‰ â€ĢīēīģŸīē˜īē īēŽīē­īē īēīģŸīģŒīģ¤īģ īģ´īē”â€Ŧ ī„  ī„ ī†Šī…šī…Ŗī…Ģī„ ī†Ēī†Ļī…˜ī…‚ī…’ī…ģī…ī„ ī†Ēī…Ąī…ģī…ī…ģī… ī„ ī„  ī„ ī„  Programming Embedded Systems Microcontroller You Can Practice Microcontroller Programming Easily Now! WALID BALID, Tuesday, December 15, 2009
  • 2. Practical Class 11 Programming Microcontrollers Exp.30: Programming Internal EEPROM EEPROMīˆ ī‹’ī‹ŽīŠŧī‰Ąī‰ī‰ĻīŠģī‰īˆ ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ ī‹’īŠ‰ī‰Ēī‰‰īˆ īˆēī‹†ī‹Œī‰‘ī‹ī‰’īŠģī‰īˆ ī‹’ī‰‰ī‰Ēī‰–ī‰ŽīŠģī‰ īˆ  īˆ īˆēī‹’ī‰‰ī‰Ēī‰–ī‰ŽīŠģī‰īˆ ī‹…īŠŋīˆ ī‹’ī‹ī‰‚īŠŦīŠģī‰ īˆ  īˆ  īˆŽīˆ’ī‰‚īŠ¨ī‹€īŠŧīŠģīˆ īˆ¨EEPROMīˆŠīˆ ī‹’ī‹ŽīŠŧī‰Ąī‰ī‰ĻīŠģī‰īˆ ī‰ī‰‚ī‹Žī‹ąīŠ¨īŠī‰īˆ ī‹‘ī‰ĒīŠˇī‰ī‰§īˆ ī‹’īŠ‰ī‰Ēī‰‰ī‹‹īˆ ī‰Šī‰‚ī‹€ī‰’ī‰Žī‰­ī‰ īˆ  īˆ īˆēī‹‘ī‰Šī‰ī‰ĻīŠģī‰īˆ īŠĄī‹ąīŠ‹ īˆ  īˆ  Faculty of Electrical and Electronic Eng. 241 Automatic Control & Automation Dept.
  • 3. ī‹‘ī‰ĒīŠŦī‰ļīŠī‰īˆ ī‰ī‰‚ī‹€īŠ¸ī‰šī‰ŽīŠī‰īˆ ī‹’īŠ‰ī‰Ēī‰‰ īˆ  īˆ  ī‹‘ī‰Ēī‰˛īŠ§īˆ ī‹’ī‹ī‰Ĩī‰‚īŠ‡ī‰īˆ ī‹’ī‰ŽīŠŧīŠ†ī‰ īˆ  īˆ īˆēī‹‘ī‰Šī‰ī‰ĻīŠģī‰īˆ īŠŊī‹€īŠ§īˆ ī‰ ī‰Ēī‰ą īˆ ī‹īŠŧī‰ŽīŠŧī‰Žī‰ŽīŠģī‰īˆ īŠžī‰‚ī‰ļī‰ī‹œī‰īˆ ī‰¨īŠ°ī‹„īŠŋī‹‹īˆ ī‰ĒīŠŦī‰ļīŠī‰īˆ ī‹īŠ¸ī‰šī‰Žī‹€īŠŧīŠģ UART1īˆ ī‹’ī‹ŽīŠŧī‰ŽīŠŧī‰Žī‰ŽīŠģī‰īˆ ī‹‘ī‰¨īŠ¯ī‰‚ī‹„īŠģī‰īˆ īŠ”ī‰‰īˆ ī‹’ī‹€ī‹–ī‹īŠŋīˆ ī‹‘ī‰Šī‰ī‰Ĩīˆ ī‹“īŠŧīŠ§īˆ ī‹Šī‹īŠ§ī‰ƒīˆ ī‹‘ī‰Šī‰ī‰ĻīŠģī‰īˆ ī‹ī‹ŒīŠ„ īˆ īˆ’ī‰‚īŠ¨ī‹€īŠŧīŠģīˆ  ī‹’ī‹ŽīŠŧī‰Ąī‰ī‰ĻīŠģī‰īˆ  ī‰ī‰‚ī‹Žī‹ąīŠ¨īŠī‰īˆ  ī‹‘ī‰ĒīŠˇī‰ī‰§īˆ  īŠ•ī‰‡ī‹‹īˆ  ī‹…īŠŋīˆ  ī‹’ī‰‰ī‰‚ī‰ŽīŠ¸īŠģī‰ī‹‹īˆ  ī‹‘ī‹•ī‰ī‰ĒīŠ´īŠŧīŠģīˆ  ī‰—īŠŋī‰‚ī‹ƒī‰Ēī‰‰īˆ  ī‹’ī‰‰ī‰‚ī‰ŽīŠ¸ī‰‰īˆ  ī‹‚ī‹ŒīŠ´ī‹ƒīˆ  īŠ˛ī‹Œī‰­īˆ  īˆŽī‰‹ī‰­ī‰‚ī‰šīŠŧīŠģīˆ  RS232 .ī‹’ī‹ŽīŠŧī‰ŽīŠŧī‰Žī‰ŽīŠģī‰īˆ ī‹‘ī‰¨īŠ¯ī‰‚ī‹„īŠģī‰īˆ ī‹‚ī‰ī‰Ļī‰ĸī‰Žī‰­ī‰‚ī‰‰īˆ īˆ¨EEPROMīˆŠ īˆ  īˆ īˆēī‹‘ī‰Ļī‹ī‰ĻīŠ†ī‰īˆ ī‰ī‰‚ī‹€ī‹ŽīŠŧīŠ¨ī‰ŽīŠģī‰ īˆ  īˆ  ī‹’ī‹€ī‹ŽīŠŧīŠ¨ī‰ŽīŠģī‰ īˆ  īˆ  ī‹’ī‹€ī‹ŽīŠŧīŠ¨ī‰ŽīŠģī‰īˆ ī‰ ī‰Ēī‰ą īˆ īŠŠīŠŋīˆ  īˆ¨ī‹’ī‹€ī‹–ī‰ī‰Ĩīˆ  ī‹‘ī‰ĒīŠˇī‰ī‰§|ī‹’ī‹ŽīŠŧī‰Ąī‰ī‰Ĩīˆ  ī‰ī‰‚ī‹Žī‹ąīŠ¨īŠŋ|ī‹’ī‹Žī‰•ī‰Šī‰‚ī‰Ąīˆ  ī‰ī‰‚ī‹Žī‹ąīŠ¨īŠŋīˆŠīˆ  ī‹‘ī‰ĒīŠˇī‰ī‰§īˆ  īŠŸīˆ  īŠžī‹Œī‰šī‰ŽīŠŋīˆ  īŠąī‹ī‰ĒīŠ¨ī‰ Dim Var As [xram|Sram|Eram] Type [at Location][overlay] īˆ  īˆ īˆŽī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ īŠŸīˆ īŠžī‹Œī‰šī‰ŽīŠī‰īˆ īŠŠīŠŗī‹ŒīŠŋīˆ ī‰Ļī‹ī‰ĻīŠ„īˆ ī‰Šī‰‚ī‹Žī‰Ą Examples: īˆ ī‹ī‹īˆ ī‹…īŠģīˆ ī‹‰ī‹ƒī‰ƒīˆ ī‹ī‰ƒīˆ ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ īŠŸīˆ ī‹īŠģī‰‚ī‹Žī‰Ąīˆ īŠžī‹Œī‰šī‰ŽīŠŋīˆ īŠ˛ī‰ĒīŠ¨īŠī‰īˆ īŠžī‹Œī‰šī‰ŽīŠī‰īˆ īŠŊīŠ¨īŠīˆ ī‰Šī‰‚ī‹Žī‰Ąīˆ īˆēoverlay Dim Sram_var As Sram Byte At &H10 īˆŽī‹†ī‰ī‹Œī‹„īŠ¨īŠģī‰īˆ ī‹“īŠŧīŠ§īˆ īŠžī‹Œī‰šī‰ŽīŠŋīˆ ī‹’ī‰‰ī‰‚ī‰ŽīŠˇīˆ īŠŸīˆ ī‹‘ī‰Šī‹Œī‹ąīŠˆī‰īˆ ī‹…ī‹€īŠ¸ī‰īˆ ī‹…īŠ¸īŠģī‹‹īˆ ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ īŠŸīˆ ī‹’ī‰™ī‰‚ī‰ŽīŠŋīˆ ī‰Ŧī‰–ī‰™ Dim Eprm_var As Eram Byte At &H80 Writeeeprom Var , Address īˆŽAddressīˆ ī‹†ī‰ī‹Œī‹„īŠ¨īŠģī‰īˆ ī‰Ļī‹„īŠ§īˆ EEPROMīˆ ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ īŠ•ī‰‡īˆ īˆ¨VarīˆŠīˆ ī‹’ī‹€ī‹ŽīŠŗīˆ ī‹’ī‰‰ī‰‚ī‰ŽīŠˇ Writeeeprom Var , Label īˆŽLabelīˆ ī‹’ī‰ŽīŠ¯ī‹īŠģī‰īˆ ī‰Ļī‹„īŠ§īˆ īŠŠī‰šī‹Œī‰Žī‰ŽīŠģīˆ EEPROMīˆ ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ īŠ•ī‰‡īˆ īˆ¨VarīˆŠīˆ ī‹’ī‹€ī‹ŽīŠŗīˆ ī‹’ī‰‰ī‰‚ī‰ŽīŠˇ Readeeprom Var , Address īˆŽAddressīˆ ī‹†ī‰ī‹Œī‹„īŠ¨īŠģī‰īˆ ī‰Ļī‹„īŠ§īˆ EEPROMīˆ ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ ī‹…īŠŋīˆ īˆ¨VarīˆŠīˆ ī‹’ī‹€ī‹ŽīŠŗīˆ ī‹‘ī‹•ī‰ī‰ĒīŠŗ Readeeprom Var , Label īˆŽLabelīˆ ī‹’ī‰ŽīŠ¯ī‹īŠģī‰īˆ ī‰Ļī‹„īŠ§īˆ ī‹’īŠ¨ī‰šī‹Œī‰ŽīŠī‰īˆ EEPROMīˆ ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ ī‹…īŠŋīˆ īˆ¨VarīˆŠīˆ ī‹’ī‹€ī‹ŽīŠŗīˆ ī‹‘ī‹•ī‰ī‰ĒīŠŗ īˆ ī‹‘ī‰Ēī‰ąī‰‚ī‰ŠīŠŋīˆ ī‹ī‹‡īˆ īˆžīŠģī‰ī‹‹īˆ  DATAīˆ ī‹’ī‹€ī‹ŽīŠŧīŠ¨ī‰ŽīŠģī‰īˆ īŠŸīˆ ī‹‘ī‰Ĩī‹Œī‰•ī‹ŒīŠī‰īˆ ī‰ī‰‚ī‹ƒī‰‚ī‹Žī‰ŠīŠģī‰īˆ ī‹…ī‹ī‰ŦīŠ…īˆ īŠ•ī‰‡īˆ ī‹ī‰•īˆ–īŠī‰īˆ ī‹‰ī‹Žī‰•ī‹Œī‰ $eeprom īˆ  īˆ īˆŽEPPīˆ ī‹ī‹–ī‰‚ī‹„ī‰‘īˆ īŠąīŠŧīŠŋīˆ ī‰Ļī‹ŽīŠģī‹Œī‰īˆ ī‹ī‰Žī‹Žī‰­ī‹‹īˆ īˆŦEEPROMīˆ ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ īŠŸīˆ ī‹‰ī‹Žī‰•ī‹Œī‰ŽīŠģī‰īˆ ī‰ĻīŠ¨ī‰‰ $data īˆ  īˆ īˆŽī‰—īŠŋī‰‚ī‹ƒīˆ•īŠģī‰īˆ ī‹‘ī‰ĒīŠˇī‰ī‰§īˆ īŠŸīˆ ī‰‚ī‹ˆī‹„ī‹ī‰ŦīŠ…īˆ ī‹ī‰Žī‹Žī‰­īˆ ī‹’ī‹ŽīŠģī‰‚ī‰ŽīŠģī‰īˆ ī‰ī‰‚ī‹ƒī‰‚ī‹Žī‰ŠīŠģī‰īˆ ī‹†ī‰ƒīˆ īŠ•ī‰‡īˆ ī‹ī‰•īˆ–īŠī‰īˆ ī‹‰ī‹Žī‰•ī‹Œī‰ īˆ  īˆ īˆŽIntel HEXīˆ ī‹’īŠŦī‹Žī‰ļī‰‰īˆ EPPīˆ īŠąīŠŧīŠī‰īˆ īŠŸīˆ ī‰ī‰‚ī‹ƒī‰‚ī‹Žī‰ŠīŠģī‰īˆ ī‹…ī‹ī‰ŦīŠ…īˆ īŠ•ī‰‡īˆ ī‹ī‰•īˆ–īŠī‰īˆ ī‹‰ī‹Žī‰•ī‹Œī‰ $eepromhex īˆŽ$eepromīˆ ī‹’ī‹€ī‹ŽīŠŧīŠ¨ī‰ŽīŠģī‰īˆ īŠŠīŠŋīˆ ī‹‚ī‰Ļī‰ĸī‰Žī‰Žī‹īˆ ī‹†ī‰ƒīˆ ī‰‹īŠīˆ ī‹‰ī‹Žī‰•ī‹Œī‰ŽīŠģī‰īˆ ī‰ī‰¨ī‹‡ $eepleave īˆ  īˆ īˆŽEEPROMīˆ ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ ī‹īŠŠīˆ ī‹‚ī‰ĻīŠ§ī‹‹īˆ EPPīˆ īŠąīŠŧīŠŋīˆ ī‰Ļī‹ŽīŠģī‹Œī‰īˆ ī‹‚ī‰ĻīŠ§īˆ īŠ•ī‰‡īˆ ī‹ī‰•īˆ–īŠī‰īˆ ī‹‰ī‹Žī‰•ī‹Œī‰ $default Sram | Xram | Eram Examples: $default Sram īˆ  īˆ īˆŽ$defaultīˆ ī‹‰ī‹Žī‰•ī‹Œī‰ŽīŠŧīŠģīˆ ī‹’ī‹ŽīŠģī‰‚ī‰ŽīŠģī‰īˆ ī‰ī‹œī‹Œī‰šī‰ŽīŠī‰īˆ īŠŠī‹ŽīŠšīˆ ī‰Ŧī‰–ī‰™īˆ īŠŠīŠŗī‹ŒīŠŋīˆ īŠ”ī‹ŽīŠ¨ī‰ Dim A As Byte , B As Byte $default Eram Dim C As Byte , D As Byte $end $default īˆ  īˆ īˆŽīŠĩī‰‰ī‰‚ī‰ŽīŠģī‰īˆ ī‹‰ī‹Žī‰•ī‹Œī‰ŽīŠģī‰īˆ ī‹‚ī‰ī‰Ļī‰ĸī‰Žī‰­ī‰‚ī‰‰īˆ ī‰‚ī‹‡īˆ—ī‹ŽīŠŦī‰īˆ īˆƒīˆ īˆžīŠģī‰īˆ ī‹’ī‹Žī‰šī‰īˆ–īŠ¯ī‹œī‰īˆ ī‰ī‰ī‰Ĩī‰ī‰ĻīŠ§ī‹ĸī‰īˆ ī‹‘ī‰Ĩī‰‚īŠ¨ī‰Žī‰­ī‰ $noramclear īˆ  īˆ īˆŽī‹’ī‹—ī‹Žī‹ˆī‰ŽīŠģī‰īˆ ī‰Ļī‹„īŠ§īˆ SRAMīˆ ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ ī‹”ī‹Œī‰ŽīŠŠīˆ īˆ—īŠ°ī‰ļī‰īˆ ī‹‚ī‰ĻīŠ§īˆ īŠ•ī‰‡īˆ ī‹ī‰•īˆ–īŠī‰īˆ ī‹‰ī‹Žī‰•ī‹Œī‰ $romstart = address īˆ  īˆ īˆŽī‰Ĩī‰Ļīˆī‰īˆ ī‹†ī‰ī‹Œī‹„īŠ¨īŠģī‰īˆ ī‹…īŠŋīˆ ī‹§ī‹•ī‰ī‰Ļī‰Žī‰‰ī‰īˆ ī‰—īŠŋī‰‚ī‹ƒīˆ•īŠģī‰īˆ ī‹…ī‹ī‰ŦīŠ…īˆ īŠ•ī‰‡īˆ ī‹ī‰•īˆ–īŠī‰īˆ ī‹‰ī‹Žī‰•ī‹Œī‰ īˆ ī‰Ļī‹„īŠ§īˆ īŠŠī‰šī‹Œī‰ŽīŠī‰īˆ  EEPROMīˆ ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ ī‹…īŠŋīˆ īŠžī‹‹ī‹žī‰īˆ ī‰ī‹ī‰‚ī‰ŠīŠģī‰īˆ ī‹‚ī‰ī‰Ļī‰ĸī‰Žī‰­ī‰īˆ ī‰ĻīŠ¨ī‰‰īˆ  AVRīˆ ī‹’īŠŧī‹–ī‰‚īŠ¨īŠģīˆ ī‹’ī‹Žī‹„īŠ°īŠģī‰īˆ ī‹’īŠ´ī‹Žī‰‘ī‹ŒīŠģī‰īˆ īŠŸīˆ ī‹“ī‰ĩī‹Œī‹īˆ īˆēī‹’īŠ¤ī‰™ī‹īŠŋ īˆ  īˆ īˆŽī‹‘ī‰Ēī‰‰ī‰‚īŠ§īˆ ī‹’īŠģī‰‚ī‰™īˆ ī‹ī‰ƒīˆ ī‹‹ī‰ƒīˆ īˆ’ī‰‚īŠ¨īŠī‰īˆ īˆ—īŠ°ī‰ļī‰īˆ ī‹•ī‰‚ī‹„ī‰‘ī‰ƒīˆ ī‰ī‹ī‰‚ī‰ŠīŠģī‰īˆ ī‰ī‰¨ī‹‡īˆ ī‹’ī‹€ī‹ŽīŠŗīˆ īˆ—īŠŦī‰Žī‰īˆ ī‹†ī‰ƒīˆ ī‹…īŠ¸īŠ™īˆ ī‹‰ī‹ƒī‹žīˆ ī‰ĒīŠ°ī‰ĩīˆ ī‹†ī‰ī‹Œī‹„īŠ¨īŠģī‰ ī‹’ī‰ŽīŠ—ī‹žī‰ī‹‹īˆ ī‹īŠģī‹ ī‰īˆ ī‹īŠ¸ī‰šī‰ŽīŠģī‰īˆ ī‹’ī‰­ī‰Ļī‹„ī‹‡īˆ ī‹ī‰ŽīŠŗ 242 ī‹’ī‹Žī‹ƒī‹‹īˆ–īŠ¸īŠģī‹ĸī‰ī‹‹īˆ ī‹’ī‹Žī‹–ī‰‚ī‰‰ī‰Ēī‹ˆīŠ¸īŠģī‰īˆ ī‹’ī‰­ī‰Ļī‹„īˆšī‰īˆ ī‹’ī‹ŽīŠŧīŠˇ
  • 4. Practical Class 11 Programming Microcontrollers īˆ  īˆ īˆē(1)īˆ ī‹‘ī‰Šī‰ī‰ĻīŠģī‰īˆ īŠŊī‹ŽīŠŦī‰˛ī‰īˆ ī‰—īŠŋī‰‚ī‹ƒī‰Ēī‰‰ $regfile = "m128def.dat" īˆ  īˆ īˆŽī‰ī‰‚ī‹ˆī‹Žī‰•ī‹Œī‰ŽīŠģī‰ $crystal = 4000000 $baud = 9600 '------------------ Dim B As Byte , I As Byte SRAMīˆ ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ īŠŸīˆ ī‰ī‹œī‹Œī‰šī‰ŽīŠŋīˆ īŠąī‹ī‰ĒīŠ¨ī‰ Dim W As Word , S As String * 5 Dim Eb As Eram Byte At 13 Dim Ei As Eram Integer At 14 EEPROMīˆ ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ īŠŸīˆ ī‰ī‹œī‹Œī‰šī‰ŽīŠŋīˆ īŠąī‹ī‰ĒīŠ¨ī‰ Dim El As Eram Long At 16 Dim Es As Eram String * 5 At 20 '------------------ Do S = "ABCDE" : Es = S S = "" S = Es : Print S īˆ SRAMīˆ  ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ  īŠŸīˆ  īŠžī‹Œī‰šī‰ŽīŠŋīˆ  ī‹’ī‹€ī‹ŽīŠŗīˆ  ī‰Ĩī‰‚ī‹„ī‰­ī‰‡ .EEPROMīˆ ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ īŠŸīˆ īŠžī‹Œī‰šī‰ŽīŠŋīˆ īŠ•ī‰‡ B = 10 : Eb = B B = 0 B = Eb : Print B '/------ For I = 0 To 4 īˆ ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ īŠŸīˆ  ī‰Ĩī‰ĻīŠŠīˆ ī‹†ī‰ī‹Œī‹„īŠ§īˆ ī‰Ļī‹„īŠ§īˆ ī‹’ī‹€ī‹ŽīŠŗīˆ  ī‹‘ī‹•ī‰ī‰ĒīŠŗ Readeeprom B , I īˆŽSRAMīˆ ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ īŠŸīˆ īŠžī‹Œī‰šī‰ŽīŠŋīˆ īŠ•ī‰‡īˆ EPROM Print B Next I '/------ īˆ  īˆ  S = "abcde" : W = 10000 īˆ SRAMīˆ  ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ  īŠŸīˆ  īŠžī‹Œī‰šī‰ŽīŠŋīˆ  ī‹’ī‹€ī‹ŽīŠŗīˆ  ī‰Ĩī‰‚ī‹„ī‰­ī‰‡ Writeeeprom S , 5 īˆŽEEPROMīˆ ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ īŠŸīˆ ī‰Ĩī‰ĻīŠŠīˆ ī‹†ī‰ī‹Œī‹„īŠ§īˆ īŠ•ī‰‡ Writeeeprom W , 11 S = "" : W = 0 īˆ ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ īŠŸīˆ  ī‰Ĩī‰ĻīŠŠīˆ ī‹†ī‰ī‹Œī‹„īŠ§īˆ ī‰Ļī‹„īŠ§īˆ ī‹’ī‹€ī‹ŽīŠŗīˆ ī‹‘ī‹•ī‰ī‰ĒīŠŗ Readeeprom S , 5 : Print S Readeeprom W , 11 : Print W īˆŽSRAMīˆ ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ īŠŸīˆ īŠžī‹Œī‰šī‰ŽīŠŋīˆ īŠ•ī‰‡īˆ EPROM '/------ Restore Lbl Read B : Print B īˆ ī‹’ī‰ŽīŠ¯ī‹œīˆ ī‰Ļī‹„īŠ§īˆ SRAMīˆ ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ īŠ•ī‰‡īˆ ī‹ī‹ŽīŠŗīˆ īŠŊī‹Žī‹€īŠ„ Read B : Print B īˆŽROMīˆ ī‰—īŠŋī‰‚ī‹ƒīˆ•īŠģī‰īˆ ī‹‘ī‰ĒīŠˇī‰ī‰§īˆ īŠŸīˆ ī‹’ī‹ƒī‰ŦīŠ‹ī‹‹īˆ ī‹‘ī‰Ĩī‰ĻīŠŠ Loop End '------------------ īˆŽROMīˆ ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ īŠŸīˆ ī‹ī‹ŽīŠŗīˆ ī‹…ī‹ī‰ŦīŠ… Lbl: Data 10 , 12 '------------------ īˆŽEEPROMīˆ ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ īŠŸīˆ ī‹ī‹ŽīŠŗīˆ ī‹…ī‹ī‰ŦīŠ… $eeprom Data 1 , 2 , 3 , 4 , 5 $data īˆ  īˆ  īˆ  īˆ  Faculty of Electrical and Electronic Eng. 243 Automatic Control & Automation Dept.
  • 5. ī‹‘ī‰ĒīŠŦī‰ļīŠī‰īˆ ī‰ī‰‚ī‹€īŠ¸ī‰šī‰ŽīŠī‰īˆ ī‹’īŠ‰ī‰Ēī‰‰ īˆ  īˆ  ī‹‘ī‰Ēī‰˛īŠ§īˆ ī‹’ī‹ī‰Ĩī‰‚īŠ‡ī‰īˆ ī‹’ī‰ŽīŠŧīŠ†ī‰ īˆ  īˆ īˆē(2)īˆ ī‹‘ī‰Šī‰ī‰ĻīŠģī‰īˆ īŠŊī‹ŽīŠŦī‰˛ī‰īˆ ī‰—īŠŋī‰‚ī‹ƒī‰Ēī‰‰ $regfile = "m128def.dat" $crystal = 4000000 $baud = 9600 īˆ  īˆ īˆŽī‰ī‰‚ī‹ˆī‹Žī‰•ī‹Œī‰ŽīŠģī‰ $eepromhex $eepleave '------------------ Dim Var As Sram Byte At &H200 '------------------ īˆ ī‰Ļī‹„īŠ§īˆ  EEPROMīˆ  ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ  īŠŸīˆ  ī‹ī‹ŽīŠŗīˆ  ī‹…ī‹ī‰ŦīŠ… $eeprom Label1: īˆŽī‹‘ī‰Ĩī‰ĻīŠŠīˆ ī‰ī‰‚ī‰ŽīŠ¯ī‹œ Data 1 , 2 , 3 , 4 , 5 Label2: Data 10 , 20 , 30 , 40 , 50 $data '------------------ īˆ ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ īŠŸīˆ  ī‹‘ī‰Ĩī‰ĻīŠŠīˆ  ī‹’ī‰ŽīŠ¯ī‹œīˆ ī‰Ļī‹„īŠ§īˆ ī‹’ī‹€ī‹ŽīŠŗīˆ ī‹‘ī‹•ī‰ī‰ĒīŠŗ Readeeprom Var , Label1 īˆŽSRAMīˆ ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ īŠŸīˆ īŠžī‹Œī‰šī‰ŽīŠŋīˆ īŠ•ī‰‡īˆ EPROM Print Var Readeeprom Var Print Var '/------ īˆ ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ īŠŸīˆ  ī‹‘ī‰Ĩī‰ĻīŠŠīˆ  ī‹’ī‰ŽīŠ¯ī‹œīˆ ī‰Ļī‹„īŠ§īˆ ī‹’ī‹€ī‹ŽīŠŗīˆ ī‹‘ī‹•ī‰ī‰ĒīŠŗ īˆŽSRAMīˆ ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ īŠŸīˆ īŠžī‹Œī‰šī‰ŽīŠŋīˆ īŠ•ī‰‡īˆ EPROM Readeeprom Var , Label2 Print Var Readeeprom Var Print Var īˆ  īˆ  '/------ īˆ SRAMīˆ  ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ  īŠŸīˆ  īŠžī‹Œī‰šī‰ŽīŠŋīˆ  ī‹’ī‹€ī‹ŽīŠŗīˆ  ī‰Ĩī‰‚ī‹„ī‰­ī‰‡ Var = 100 Writeeeprom Var , Label1 īˆŽī‹‘ī‰Ĩī‰ĻīŠŠīˆ ī‹’ī‰ŽīŠ¯ī‹œīˆ ī‰Ļī‹„īŠ§īˆŽEEPROMīˆ ī‹‘ī‰ĒīŠˇī‰ī‰¨īŠģī‰īˆ īŠ•ī‰‡ Var = 101 Writeeeprom Var Readeeprom Var , Label1 Print Var Readeeprom Var Print Var '/------ Var = 0 Writeeeprom Var , 3 Readeeprom Var , 3 Print Var End īˆ  īˆ  īˆ  īˆ īˆ  īˆ  ī‹’ī‰ŽīŠ—ī‹žī‰ī‹‹īˆ ī‹īŠģī‹ ī‰īˆ ī‹īŠ¸ī‰šī‰ŽīŠģī‰īˆ ī‹’ī‰­ī‰Ļī‹„ī‹‡īˆ ī‹ī‰ŽīŠŗ 244 ī‹’ī‹Žī‹ƒī‹‹īˆ–īŠ¸īŠģī‹ĸī‰ī‹‹īˆ ī‹’ī‹Žī‹–ī‰‚ī‰‰ī‰Ēī‹ˆīŠ¸īŠģī‰īˆ ī‹’ī‰­ī‰Ļī‹„īˆšī‰īˆ ī‹’ī‹ŽīŠŧīŠˇ
  • 6. Practical Class 11 Programming Microcontrollers Exp.31: Interfacing with I2C I2Cīˆ īŠžī‹ŒīŠˇī‹Œī‰ī‹‹īˆ•īŠģī‰īˆ īˆēī‹†ī‹Œī‰‘ī‹ī‰’īŠģī‰ī‹‹īˆ ī‹‘ī‰Ļī‰™ī‰ī‹ŒīŠģī‰īˆ ī‹’ī‰‰ī‰Ēī‰–ī‰ŽīŠģī‰ īˆ  īˆ īˆēī‹’ī‰‰ī‰Ēī‰–ī‰ŽīŠģī‰īˆ ī‹…īŠŋīˆ ī‹’ī‹ī‰‚īŠŦīŠģī‰ īˆ ī‹…īŠŋī‰ŦīŠģī‰īˆ  ī‰Ļī‹ŽīŠģī‹Œī‰īˆ  ī‹‘ī‰Šī‰ī‰Ĩī‹‹īˆ  EEPROMīˆ  ī‹’ī‹ŽīŠŧī‰ŽīŠŧī‰Žī‰īˆ  ī‰ī‰‚ī‹Žī‹ąīŠ¨īŠŋīˆ  ī‹‘ī‰ĒīŠˇī‰ī‰§īˆ  ī‹’īŠ‰ī‰Ēī‰‰īˆ  īŠžī‹ī‰Ąīˆ  ī‹…īŠŋīˆ  I2Cīˆ  īŠžī‹ŒīŠˇī‹Œī‰ī‹‹īˆ•īŠģī‰īˆ  īŠŊī‹€īŠ§īˆ  ī‰ƒī‰Ļī‰ŠīŠŋīˆ  ī‹’ī‰­ī‰ī‰Šī‰Ĩ īˆ  īˆ  .RTC ī‹īŠ´ī‹ŽīŠ´īŠ‡ī‰ īˆ  īˆ īˆēī‹‘ī‰Šī‰ī‰ĻīŠģī‰īˆ īŠĄī‹ąīŠ‹ īˆ  īˆ  Faculty of Electrical and Electronic Eng. 245 Automatic Control & Automation Dept.
  • 7. ī‹‘ī‰ĒīŠŦī‰ļīŠī‰īˆ ī‰ī‰‚ī‹€īŠ¸ī‰šī‰ŽīŠī‰īˆ ī‹’īŠ‰ī‰Ēī‰‰ īˆ  īˆ  ī‹‘ī‰Ēī‰˛īŠ§īˆ ī‹’ī‹ī‰Ĩī‰‚īŠ‡ī‰īˆ ī‹’ī‰ŽīŠŧīŠ†ī‰ īˆēI2Cīˆ īŠžī‹ŒīŠˇī‹Œī‰ī‹‹īˆ•īŠģī‰īˆ īŠŊī‹€īŠ§īˆ ī‰ƒī‰Ļī‰ŠīŠŋ īˆ īŠ˛ī‰Ļī‹ˆī‰‰īˆ  Philipsīˆ ī‹’īŠˇī‰Ēī‰ąīˆ īŠŊī‰ŠīŠŗīˆ ī‹…īŠŋīˆ  1980īˆ ī‹‚ī‰‚īŠ§īˆ īŠŊī‹–ī‰ī‹‹ī‰ƒīˆ īŠŸīˆ īˆ¨Inter-Integrated CircuitīˆŠīˆ  I2Cīˆ  īŠžī‹ŒīŠˇī‹Œī‰ī‹‹īˆ•īŠģī‰īˆ īˆ•ī‰ŽīŠ¨ī‹ī‹‹īˆ ī‰Ēī‹ī‹Œī‹ąī‰īˆ īˆƒ īˆ ī‰Ģī‰‚īŠ°īŠŧī‰ŽīŠģī‰īˆ ī‹‘ī‰Ŧī‹ˆī‰•ī‰ƒīˆ īŠŸīˆ ī‰ī‰‚ī‹Žī‹ąī‹Žīˆī‰īˆ ī‰ŧīŠ¨ī‰‰īˆ īŠŠīŠŋīˆ ī‹īŠ¸ī‰šī‰ŽīŠŋīˆ īŠĄī‰‰ī‰Šīˆ īŠŊī‰•ī‰ƒīˆ ī‹…īŠŋī‹‹īˆ īˆ¨TVīˆŠīˆ ī‹’ī‹Žī‹ƒī‹‹īˆ–īŠ¸īŠģī‹ĸī‰īˆ ī‰ī‰‚ī‰–ī‰Žī‹„īŠī‰īˆ īŠŠī‹Žī‹„ī‰ļī‰īˆ ī‹’īŠ°īŠŧīŠˇīˆ ī‰ŧī‹ŽīŠ°īŠ… īˆ  īˆ īˆŽīˆ¨Two Wire InterfaceīˆŠīˆ TWIīˆ ī‹ĩī‰‚ī‰ēī‹ī‰ƒīˆ ī‹“ī‹€ī‰Žī‹ī‹‹īˆ ī‹’ī‹Žī‹ƒī‹‹īˆ–īŠ¸īŠģī‹ĸī‰īˆ ī‹‘ī‰Ŧī‹ˆī‰•ī‹žī‰īˆ īŠŸīˆ ī‹ĩī‰‚īŠŋī‰ī‰Ļī‰ĸī‰Žī‰­ī‰īˆ ī‰Ēī‰’īŠˇī‹žī‰īˆ īˆ•ī‰ŽīŠ¨ī‹ī‹‹ īˆ  īˆ  īˆ īˆŦīˆ¨SDA, SCKīˆŠīˆ  īŠ”ī‹ąī‰Ąīˆ  ī‹“īŠŧīŠ§īˆ  ī‰Ļī‹€ī‰ŽīŠ¨ī‰īˆ  īˆžīŠģī‰īˆ  ī‹’ī‹„īŠŋī‰ī‰Ŧī‰ŽīŠī‰īˆ  ī‹īŠŧī‰ŽīŠŧī‰Žī‰ŽīŠģī‰īˆ  īŠžī‰‚ī‰ļī‰ī‹œī‰īˆ  ī‰ī‹œī‹ŒīŠˇī‹Œī‰ī‹‹ī‰Ēī‰‰īˆ  ī‹…īŠŋīˆ  I2Cīˆ  īŠžī‹ŒīŠˇī‹Œī‰ī‹‹īˆ•īŠģī‰īˆ  īŠąī‹„ī‰ļī‹ īˆ īŠĄīŠˆī‰īˆ ī‰‚īŠŋī‰ƒīˆ īˆŦī‰¯īŠ¸īŠ¨īŠģī‰īˆ ī‹‹ī‰ƒīˆ īŠŊī‰ŠīŠ´ī‰Žī‰ŽīŠī‰īˆ īŠ•ī‰‡īˆ īŠŊī‰­ī‰ĒīŠī‰īˆ ī‹…īŠŋīˆ ī‰ī‰‚ī‹ƒī‰‚ī‹Žī‰ŠīŠģī‰īˆ ī‹Šī‰‚īŠƒī‰īˆ ī‹†ī‹ŒīŠ¸ī‹īˆ ī‹†ī‰ƒīˆ ī‰‚īŠŋī‰ˆīŠ¯īˆ īˆŦī‹Šī‰‚īŠƒī‹œī‰īˆ ī‹ī‹–ī‰‚ī‹„ī‰‘īˆ ī‹ĩī‰‚ī‹€ī‹–ī‰ī‰Ĩīˆ  SDAīˆ īŠĄīŠˆī‰ īˆ īŠŸīˆ  ī‹Šī‰‚īŠƒī‹œī‰īˆ  ī‹ī‹–ī‰‚ī‹„ī‰‘īˆ  ī‹†ī‹ŒīŠ¸ī‹ī‹‹īˆ  One-Master<>Multi-Slavesīˆ  ī‰ƒī‰Ļī‰ŠīŠŋīˆ  ī‰Ļī‹€ī‰ŽīŠ¨ī‰īˆ  īˆžīŠģī‰īˆ  ī‹’ī‹€īŠ¤ī‹ƒī‹žī‰īˆ  īŠŸīˆ  ī‹Šī‰‚īŠƒī‹œī‰īˆ  ī‹ī‰Ĩī‰‚ī‰™ī‰ƒīˆ  ī‹Œī‹ˆīŠ¯īˆ  SCK īˆŽMulti-Master<>Multi-Slavesīˆ ī‰ƒī‰Ļī‰ŠīŠŋīˆ ī‹“īŠŧīŠ§īˆ ī‰Ļī‹€ī‰ŽīŠ¨ī‰īˆ īˆžīŠģī‰īˆ ī‹’ī‹€īŠ¤ī‹ƒī‹žī‰ īˆ īŠŊī‰•ī‰ƒīˆ ī‹…īŠŋīˆ īŠŊī‹€īŠ¨ī‹ī‹‹īˆ īˆŦī‹’ī‹ąī‰­ī‹Œī‰ŽīŠŋī‹‹īˆ ī‹’ī‰ēīŠ°ī‰ĸī‹„īŠŋīˆ īŠŊīŠ´ī‹ƒīˆ ī‰ī‰‚īŠ§ī‰Ēī‰­īˆ ī‰Ļī‹„īŠ§īˆ  Chip-to-Chipīˆ īŠĄī‰‰ī‰Šīˆ īŠŊī‰•ī‰ƒīˆ ī‹…īŠŋīˆ īŠžī‹ŒīŠˇī‹Œī‰ī‹‹īˆ•īŠģī‰īˆ ī‰ī‰¨ī‹‡īˆ ī‹‚ī‰Ļī‰ĸī‰Žī‰Žī‹ īˆ īˆ¨Multi-SlaveīˆŠīˆ ī‰Ĩī‰‚īŠ´īŠŋīˆ ī‹…īŠŋīˆ ī‰Ēī‰’īŠˇī‰ƒī‹‹īˆ īˆ¨MasterīˆŠīˆ  ī‰Ļī‹Žī‰™ī‹‹īˆ  ī‰Ļī‹–ī‰‚īŠŗīˆ īŠŊīŠ´ī‹„īŠģī‰īˆ  īŠĄī‰Ąīˆ ī‹“īŠŧīŠ§īˆ ī‰Ļī‰•ī‰ī‹Œī‰Žī‹īˆ ī‹†ī‰ƒīˆ ī‹…īŠ¸īŠ™īˆ ī‰“ī‹Žī‰™īˆ  Multi-Drop Bus īˆ ī‰Ĩī‹Œī‰•ī‹‹īˆ ī‰Ēī‰’īŠˇī‰ƒīˆ ī‹…īŠŋīˆ ī‹Šī‰Ĩī‰ī‰ĻīŠ§ī‰‡īˆ ī‹…īŠ¸īŠ™īˆ  ī‰‚ī‹€īŠˇīˆ īˆŦīˆ¨Master<>SlaveīˆŠīˆ  ī‹’īŠ¤ī‰šīŠŧīŠģī‰īˆ ī‰¯īŠ°ī‹ƒīˆ īŠŸīˆ ī‹ĩī‰‚īŠ¨īŠŋīˆ īŠĄīŠ´īŠ¯īˆ ī‹…ī‹ī‰Ģī‰‚ī‹ˆī‰•īˆ īŠ”ī‰‰īˆ ī‰‹ī‰ŋī‰‚ī‰ĸī‰ŽīŠģī‰īˆ ī‹ī‰Žī‹ī‹‹ īˆ  īˆ īˆŽīˆ¨Multi-SlaveīˆŠīˆ ī‰Ĩī‰‚īŠ´īŠŋīˆ ī‹…īŠŋīˆ ī‰Ēī‰’īŠˇī‰ƒī‹‹ īˆ¨Multi-MasterīˆŠīˆ ī‰Ļī‹–ī‰‚īŠŗīˆ ī‹…īŠŋīˆ ī‰Ēī‰’īŠˇī‰ƒ īˆ īˆŦSDA, SCKīˆ ī‹īŠ¸īŠģīˆ īŠŠīŠ¯ī‰Šīˆ ī‰ī‰‚īŠŋī‹‹ī‰‚īŠ´īŠŋīˆ īŠĄī‰‰ī‰Šīˆ ī‹ī‰Žī‹īˆ īŠšīŠģī‰¨īŠģīˆ īˆŦOpen collectorīˆ īŠĒī‹Œī‹ƒīˆ ī‹…īŠŋīˆ ī‹Œī‹‡īˆ  I2Cīˆ īŠžī‹ŒīŠˇī‹Œī‰ī‹‹īˆ•īŠģī‰īˆ īŠŸīˆ ī‹‘ī‰Ŧī‹ˆī‰•ī‹žī‰īˆ ī‰˜ī‰Ēī‰Ą īˆ  īˆ īˆŽâ€œ1”īˆ īŠ”ī‹ąīŠˆī‰īˆ ī‹īŠˇīˆ ī‹’īŠģī‰‚ī‰™īˆ ī‹†ī‹ŒīŠ¸ī‰īˆ ī‹’īŠģī‰‚ī‹ąī‰ŠīŠģī‰īˆ īŠžī‰‚ī‰™īˆ īŠŸī‹‹ īˆ ī‹‹ī‰ƒīˆ īˆŦīˆ¨112 nodesīˆŠīˆ  7-Bitīˆ ī‹…īŠŋīˆ īŠąīŠģī‹›īŠŋīˆ īˆ¨Unique AddressīˆŠīˆ ī‰Ļī‹ī‰ĒīŠ¯īˆ ī‹†ī‰ī‹Œī‹„īŠ§īˆ īŠšīŠŧīŠ™īˆ  I²Cīˆ īŠžī‹ŒīŠˇī‹Œī‰ī‹‹īˆ•īŠģī‰īˆ īŠĩīŠ¯ī‹‹īˆ īŠŊī‹€īŠ¨ī‹īˆ ī‰Ģī‰‚ī‹ˆī‰•īˆ īŠŊīŠˇ īˆ ī‹…īŠŋīˆ ī‹‰īŠ¨īŠŋīˆ ī‰‹ī‰ŋī‰‚ī‰ĸī‰ŽīŠģī‰īˆ ī‰Ĩī‰ī‰ĒīŠī‰īˆ  ī‰Ĩī‰‚īŠ´īŠī‰īˆ  ī‰Ģī‰‚ī‹ˆīŠ†ī‰īˆ ī‰Ļī‹ī‰Ļī‰šī‰ŽīŠģīˆ ī‹†ī‰ī‹Œī‹„īŠ¨īŠģī‰īˆ ī‰ī‰¨ī‹‡īˆ ī‹‚ī‰Ļī‰ĸī‰Žī‰Žī‹īˆ īˆ¨1008 nodesīˆŠīˆ  10-bitīˆ ī‹†ī‰ī‹Œī‹„īŠ¨ī‰‰īˆ ī‰ĒīŠ¯ī‹Œī‰Žī‹īˆ ī‹†ī‰ƒīˆ ī‹…īŠ¸īŠ™ īˆ  īˆ īˆŽī‰Ļī‹–ī‰‚īŠ´īŠģī‰īˆ īŠŊī‰ŠīŠŗ īˆ ī‰Ģī‹‹ī‰‚ī‰–ī‰Žī‰īˆ ī‹œīˆ ī‹†ī‰ƒīˆ ī‰‹īŠīˆ ī‹’īŠ¨ī‰ŽīŠŧīŠģīˆ ī‹’ī‹Žī‹€īŠ¤īŠ§ī‹žī‰īˆ ī‹’ī‹€ī‹ŽīŠ´īŠģī‰īˆ ī‹†ī‰ƒīˆ ī‰“ī‹Žī‰™īˆ īŠĄīŠˆī‰īˆ ī‹’īŠ¨ī‰­īˆ ī‹“īŠŧīŠ§īˆ ī‹‘ī‰Ēī‰ąī‰‚ī‰ŠīŠŋīˆ ī‰Ļī‹€ī‰ŽīŠ¨ī‹īˆ īŠŊīŠ´ī‹„īŠģī‰īˆ īŠĄī‰Ąīˆ ī‹“īŠŧīŠ§īˆ ī‹‘ī‰Ŧī‹ˆī‰•ī‹žī‰īˆ ī‰Ĩī‰ĻīŠ§īˆ ī‹†ī‰‡ īˆ  īˆ īˆŽ10pFīˆ ī‰Ĩī‹‹ī‰ĻīŠīˆ ī‰Ģī‰‚ī‹ˆī‰•īˆ īŠŊīŠˇīˆ ī‹’īŠ¨ī‰­īˆ ī‹†ī‹ŒīŠ¸ī‰īˆ ī‹ĩī‰‚ī‰ŠīŠģī‰‚īŠĢī‹‹īˆ īˆŦ400pF īˆ  īˆ  īˆ  īˆ  ī‹’ī‰ŽīŠ—ī‹žī‰ī‹‹īˆ ī‹īŠģī‹ ī‰īˆ ī‹īŠ¸ī‰šī‰ŽīŠģī‰īˆ ī‹’ī‰­ī‰Ļī‹„ī‹‡īˆ ī‹ī‰ŽīŠŗ 246 ī‹’ī‹Žī‹ƒī‹‹īˆ–īŠ¸īŠģī‹ĸī‰ī‹‹īˆ ī‹’ī‹Žī‹–ī‰‚ī‰‰ī‰Ēī‹ˆīŠ¸īŠģī‰īˆ ī‹’ī‰­ī‰Ļī‹„īˆšī‰īˆ ī‹’ī‹ŽīŠŧīŠˇ
  • 8. Practical Class 11 Programming Microcontrollers īˆ  īˆ  īˆ  īˆ  īˆ  īˆ īˆēI2Cīˆ īŠžī‰‚ī‰ļī‰ī‹œī‰īˆ īŠžī‹ŒīŠˇī‹Œī‰īˆ•īŠģīˆ ī‹™ī‹‹ī‰‚ī‰ŽīŠī‰ī‹‹īˆ ī‰ī‰ī‰Ŧī‹ŽīŠī‰ īˆ  īˆ īˆ¨AdvantagesīˆŠīˆ ī‹…ī‰­ī‰‚īˆī‰ īˆ  īˆ īˆ¨DisadvantagesīˆŠīˆ ī‹™ī‹‹ī‰‚ī‰ŽīŠī‰ īˆŽīŠ”ī‹ąī‰Ąīˆ ī‹‚ī‰ī‰Ļī‰ĸī‰Žī‰­ī‰‚ī‰‰īˆ Slaveīˆ ī‹…īŠŋīˆ ī‰Ēī‰’īŠˇī‰ƒīˆ īŠŠīŠŋīˆ ī‰‹ī‰ŋī‰‚ī‰ĸī‰ŽīŠģī‰īˆ ī‹…īŠ¸īŠ™ Ãŧ .(3meter)īˆ ī‹‘īˆ—ī‰ļīŠŗīˆ īŠžī‰‚ī‰ļī‰ī‹œī‰īˆ ī‹’īŠ¯ī‰‚ī‰ŽīŠŋ × īˆŽīŠĩī‹Žī‰Šī‹ąī‰ŽīŠģī‰īˆ īŠŊī‹ˆī‰­ī‹‹īˆ īˆŦī‹’ī‰ēīŠ°ī‰ĸī‹„īŠŋīˆ ī‹•ī‰‚ī‹„ī‰ŠīŠģī‰īˆ ī‹’īŠ°īŠŧīŠˇ Ãŧ īˆŽ400Khzīˆ ī‰Ģī‹‹ī‰‚ī‰–ī‰Žī‰īˆ ī‹œīˆ ī‹’ī‰ēīŠ°ī‰ĸī‹„īŠŋīˆ ī‰ī‰‚īŠ§ī‰Ēī‰­ × īˆŽī‹ĩī‰‚ī‹ŽīŠ‰ī‰Ēī‰‰ī‹‹īˆ ī‰‹īŠŧī‰ĩīˆ ī‹†ī‰‚ī‹ŽīŠ¸īŠˇīˆ ī‰ĒīŠ¯ī‹Œī‰ŽīŠŋī‹‹īˆ īˆŦī‹‚ī‰ī‰Ļī‰ĸī‰Žī‰­ī‹œī‰īˆ īŠŠī‹–ī‰‚ī‰ą Ãŧ īˆŽī‹‘ī‰Ŧī‹ˆī‰•ī‹žī‰īˆ īˆ ī‹…ī‹ī‹‹ī‰‚ī‹„īŠ§īˆ īŠŸīˆ ī‹’ī‹ī‰Ĩī‹‹ī‰ĻīŠŠ × īˆ īˆ—ī‰‘ī‰„ī‰īˆ ī‹ī‰ƒīˆ ī‹†ī‹‹ī‰Ĩīˆ īŠŊīŠŗī‰‚ī‹„īŠģī‰īˆ ī‹…īŠŋīˆ ī‰Ģī‰‚ī‹ˆī‰•īˆ ī‹ī‰ƒīˆ īŠŊī‰ĩī‹‹ī‹‹īˆ īŠŊī‰ļīŠ¯īˆ ī‹…īŠ¸īŠ™ Ãŧ īˆŽīˆ—ī‹ŽīŠŦī‰īˆ ī‹ī‹žīˆ ī‹’ī‰•ī‰‚īŠ‡ī‰īˆ ī‹‹ī‰ƒīˆ ī‹‚ī‰‚īŠ¤ī‹„īŠģī‰īˆ ī‹“īŠŧīŠ§ Faculty of Electrical and Electronic Eng. 247 Automatic Control & Automation Dept.
  • 9. ī‹‘ī‰ĒīŠŦī‰ļīŠī‰īˆ ī‰ī‰‚ī‹€īŠ¸ī‰šī‰ŽīŠī‰īˆ ī‹’īŠ‰ī‰Ēī‰‰ īˆ  īˆ  ī‹‘ī‰Ēī‰˛īŠ§īˆ ī‹’ī‹ī‰Ĩī‰‚īŠ‡ī‰īˆ ī‹’ī‰ŽīŠŧīŠ†ī‰ Interfacing I2C EEPROM Description: I²C is an abbreviation of Inter Integrated Circuit and is a protocol for serial communication between Integrated Circuits, it is also called Two Wire Interface (TWI). The bus is used for communication between microcontrollers and peripheral devices like memories, temperature sensors and I/O expanders. An EEPROM is a Electrically Erasable and Programmable Read Only Memory. EEPROM Model Size Internally Organized Address (hex) AT24C01 128 Bytes 128 x 8 = 1024 bits 00000 >> 0007F AT24C02 256 Bytes 256 x 8 = 2048 bits 00000 >> 000FF AT24C04 512 Bytes 512 x 8 = 4096 bits 00000 >> 001FF AT24C08 1 Kbyte 1024 x 8 = 8192 bits 00000 >> 003FF AT24C16 2 Kbyte 2048 x 8 = 16384 bits 00000 >> 007FF AT24C32 4 Kbyte 4096 x 8 = 32768 bits 00000 >> 00FFF AT24C64 8 Kbyte 8192 x 8 = 65536 bits 00000 >> 01FFF AT24C128 16 Kbyte 16384 x 8 = 131072 bits 00000 >> 03FFF AT24C256 32 Kbyte 32768 x 8 = 262144 bits 00000 >> 07FFF AT24C512 64 Kbyte 65536 x 8 = 524288 bits 00000 >> 0FFFF AT24C1024 128 Kbyte 131072 x 8 = 1048576 bits 00000 >> 1FFFF The communication of the bus goes along two lines: SDA (Serial Data) and SCL (Serial Clock). Each I²C device has a unique 7-bit address (Device Select Code). The most significant bits are fixed and assigned to a specific device category (e.g. b1010 is assigned to serial EEPROMS). The three less significant bits (A2,A1 and A0) are programmable and used to address the device. The three bits allows eight different I2C address combinations and therefore allowing up to eight different devices of that type to operate on the same I2C-bus. The I2C address is send in the 1st byte, the lest signi icant bit of the first byte is used to indicate if the master is going to write(0) or read(1) from the slave. The device that sends data along the bus is called master, a device that receives the data is called slave. The master starts the transmission with a start signal and stops the transmission with a stop signal on the SDA line. During the start and stop signals the SCL line has to be high. After the master has started the data-transmission with a start signal, the master writes a device address byte to the ī‹’ī‰ŽīŠ—ī‹žī‰ī‹‹īˆ ī‹īŠģī‹ ī‰īˆ ī‹īŠ¸ī‰šī‰ŽīŠģī‰īˆ ī‹’ī‰­ī‰Ļī‹„ī‹‡īˆ ī‹ī‰ŽīŠŗ 248 ī‹’ī‹Žī‹ƒī‹‹īˆ–īŠ¸īŠģī‹ĸī‰ī‹‹īˆ ī‹’ī‹Žī‹–ī‰‚ī‰‰ī‰Ēī‹ˆīŠ¸īŠģī‰īˆ ī‹’ī‰­ī‰Ļī‹„īˆšī‰īˆ ī‹’ī‹ŽīŠŧīŠˇ
  • 10. Practical Class 11 Programming Microcontrollers slave. Each data byte has to have a length of 8 bits. The slave has to acknowledge the reception of the data byte with a acknowledge-bit (ACK). A write operation requires a device address bytes, two address bytes and the data-byte. Upon receive of the address the EEPROM sends an ACK and then clocks in the data-byte. The EEPROM sends again an ACK and the microcontrollers sends a stop-signal to terminate the write sequence. All devices from 32K – 512K will require no system changes and can be interchanged with only the page size differences to consider. Low Density Random Read: Faculty of Electrical and Electronic Eng. 249 Automatic Control & Automation Dept.
  • 11. ī‹‘ī‰ĒīŠŦī‰ļīŠī‰īˆ ī‰ī‰‚ī‹€īŠ¸ī‰šī‰ŽīŠī‰īˆ ī‹’īŠ‰ī‰Ēī‰‰ īˆ  īˆ  ī‹‘ī‰Ēī‰˛īŠ§īˆ ī‹’ī‹ī‰Ĩī‰‚īŠ‡ī‰īˆ ī‹’ī‰ŽīŠŧīŠ†ī‰ Medium and High Density Random Read: AT24C32 (4 Kbyte) 4096 * 8 = 32768 bits 0000 >> 0FFF 32 byte page &H0000 Saturday [128 Set] 128 x 4 = 215 Bytes 512Bytes &H01FF &H0200 Sunday [128 Set] 128 x 4 = 215 Bytes 512Bytes &H03FF &H0400 Monday [128 Set] 128 x 4 = 215 Bytes 512Bytes &H05FF &H0600 Tuesday [128 Set] 128 x 4 = 215 Bytes 512Bytes &H07FF &H0800 Wednesday [128 Set] 128 x 4 = 215 Bytes 512Bytes &H09FF &H0A00 Thursday [128 Set] 128 x 4 = 215 Bytes 512Bytes &H0BFF &H0C00 Friday [128 Set] 128 x 4 = 215 Bytes 512Bytes &H0DFF &H0E00 NON USED AREA 512Bytes &H0FFF [ ī‹’ī‰ŽīŠ—ī‹žī‰ī‹‹īˆ ī‹īŠģī‹ ī‰īˆ ī‹īŠ¸ī‰šī‰ŽīŠģī‰īˆ ī‹’ī‰­ī‰Ļī‹„ī‹‡īˆ ī‹ī‰ŽīŠŗ 250 ī‹’ī‹Žī‹ƒī‹‹īˆ–īŠ¸īŠģī‹ĸī‰ī‹‹īˆ ī‹’ī‹Žī‹–ī‰‚ī‰‰ī‰Ēī‹ˆīŠ¸īŠģī‰īˆ ī‹’ī‰­ī‰Ļī‹„īˆšī‰īˆ ī‹’ī‹ŽīŠŧīŠˇ
  • 12. Practical Class 11 Programming Microcontrollers Software: The BASCOM-AVR compiler is used to make a program that writes and reads one byte from the EEPROM. BASCOM has several embedded commands to control the I2C bus. In BASCOM-AVR you irst have to con igure the ports you use for the SDA and SCL lines of the I2C bus. Then you send the device address to select the EEPROM that is connected to the I2C bus. After that you send two bytes to the EEPROM to select the address in the EEPROM to which you want to write the data. The last byte to send in a write sequence is the data byte. $regfile = "m16def.dat" $crystal = 2000000 $lib "I2C_TWI.LBX" $baud = 9600 '--------------------------- Config Scl = Portc.0 Config Sda = Portc.1 Config Twi = 100000 '100KHZ '--------------------------- Const Addressw = 160 '&B10100000 slave write address Const Addressr = 161 '&B10100001 slave read address '--------------------------- Dim Adres_h As Byte , Adres_l As Byte Dim Rd_value As Byte , Wr_value As Byte '--------------------------- Do Input "Wr_value:" , Wr_value Input "Adres_l:" , Adres_l Input "Adres_h:" , Adres_h Gosub Write_eeprom Gosub Read_eeprom Print "Error W: " ; Err print "Wr_value: " ; Wr_value Print "Error R: " ; Err Print "Rd_value: " ; Rd_value Loop End '--------------------------- Write_eeprom: I2cstart 'Start condition I2cwbyte Addressw 'Slave address I2cwbyte Adres_h 'H address of EEPROM I2cwbyte Adres_l 'L address of EEPROM I2cwbyte Wr_value 'Value to write I2cstop 'Stop condition Waitms 10 'Wait for 10 milliseconds Return '--------------------------- Read_eeprom: I2cstart 'Generate start I2cwbyte Addressw 'Slave adsress I2cwbyte Adres_h 'H address of EEPROM I2cwbyte Adres_l 'L address of EEPROM I2cstart 'Repeated start I2cwbyte Addressr 'Slave address (read) I2crbyte Rd_value , Nack 'Read byte I2cstop 'Generate stop Return '--------------------------- īˆ  īˆ  Faculty of Electrical and Electronic Eng. 251 Automatic Control & Automation Dept.