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

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

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

                 ī„  ī„ ī†Ēī…Ąī…Ŋī…‚ī…•ī…ģī…ī„ ī†Ēī…Ąī…ģī…ī…ģī…

                          ī„ ī„ 




                          ī„ ī„ 




                   Programming
      Embedded Systems Microcontroller

You Can Practice Microcontroller Programming Easily Now!
      WALID BALID, Tuesday, December 15, 2009
ī‹‘ī‰ĒīŠŦī‰ļīŠī‰īˆ ī‰ī‰‚ī‹€īŠ¸ī‰šī‰ŽīŠī‰īˆ ī‹’īŠ‰ī‰Ēī‰‰                                                                         īˆ  īˆ  ī‹’ī‰ŽīŠŋī‰‚īŠˆī‰īˆ ī‹’ī‰ŽīŠŧīŠ†ī‰

      Exp.14: 7-Segment Single Display                    īˆ  īˆ īˆ īŠŠī‹ąīŠŗīˆ īŠŠī‰Šī‰ŽīŠģī‰īˆ ī‰ī‰ī‰§īˆ ī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰īˆ ī‰ī‰‚ī‰™ī‹ŒīŠģīˆ īˆēī‹‘ī‰Ēī‰˛īŠ§īˆ ī‹’īŠ¨ī‰‰ī‰ī‰ĒīŠģī‰īˆ ī‹’ī‰‰ī‰Ēī‰–ī‰ŽīŠģī‰


                                                                                            īˆ  īˆ īˆēī‹’ī‰‰ī‰Ēī‰–ī‰ŽīŠģī‰īˆ ī‹…īŠŋīˆ ī‹’ī‹ī‰‚īŠŦīŠģī‰
                                                               īˆ  īˆ  īˆŽīˆ¨7-SegmentīˆŠīˆ ī‹’ī‹ŽīŠ§ī‰‚ī‰Šī‰­īˆ ī‰Šī‰‚ī‹ˆīŠŖī‰‡īˆ ī‹’ī‰™ī‹ŒīŠģīˆ ī‹’īŠ‰ī‰Ēī‰‰ī‹‹īˆ īŠŊī‹Žī‰ĩī‹Œī‰
                                                                                             īˆ  īˆ īˆēīŠŊī‹Žī‰ĩī‹Œī‰ŽīŠģī‰īˆ īŠĄī‹ąīŠ‹




īˆ  īˆ 
                                                                                             īˆ  īˆ īˆēī‹‘ī‰Šī‰ī‰ĻīŠģī‰īˆ īŠŊī‹€īŠ§īˆ ī‰ ī‰Ēī‰ą
                                     īˆ  īˆ īˆēīŠŊī‰™ī‰ī‰ĒīŠŋīˆ ī‰”ī‹ī‰‘īˆ ī‹“īŠŧīŠ§īˆ ī‹’ī‹ŽīŠ§ī‰‚ī‰Šī‰ŽīŠģī‰īˆ ī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰īˆ ī‰ī‰‚ī‰™ī‹ŒīŠŧīŠģīˆ īŠŊī‹ŽīŠŦī‰˛ī‰ŽīŠģī‰īˆ ī‰—īŠŋī‰‚ī‹ƒī‰Ēī‰‰īˆ ī‹’ī‰‰ī‰‚ī‰ŽīŠ¸ī‰‰īˆ ī‹‚ī‹ŒīŠ´ī‹ƒīˆ īŠ˛ī‹Œī‰­
                                                           īˆŽ0 – 9īˆ ī‹ī‰Ēī‰˛īŠ§īˆ ī‰Ĩī‰ī‰ĻīŠ¨īŠˇīˆ ī‹’ī‹ī‰Ĩī‰ĒīŠ¯īˆ ī‰Šī‰‚ī‹ˆīŠŖī‰‡īˆ ī‹’ī‰™ī‹ŒīŠģīˆ īŠŊī‹ŽīŠŦī‰˛ī‰īˆ  īˆ­1
                                                          īˆŽ0 – 99īˆ ī‹ī‰Ēī‰˛īŠ§īˆ ī‰Ĩī‰ī‰ĻīŠ¨īŠˇīˆ ī‹’ī‹Žī‹–ī‰‚ī‹„ī‰‘īˆ ī‰Šī‰‚ī‹ˆīŠŖī‰‡īˆ ī‹’ī‰™ī‹ŒīŠģīˆ īŠŊī‹ŽīŠŦī‰˛ī‰īˆ  īˆ­2
                                                       īˆŽ0 – 9999īˆ ī‹ī‰Ēī‰˛īŠ§īˆ ī‰Ĩī‰ī‰ĻīŠ¨īŠˇīˆ ī‹’ī‹ŽīŠ§ī‰‚ī‰‰ī‰Šīˆ ī‰Šī‰‚ī‹ˆīŠŖī‰‡īˆ ī‹’ī‰™ī‹ŒīŠģīˆ īŠŊī‹ŽīŠŦī‰˛ī‰īˆ  īˆ­3
      īˆ īˆ—īŠ°ī‰˛ī‰īˆ ī‹’ī‹€ī‹ŽīŠ´ī‰‰īˆ ī‹‘ī‰Ēī‰ąī‰‚ī‰ŠīŠŋīˆ īŠĩīŠŧīŠ¨ī‰Žī‹īˆ īˆŦī‹’ī‰™ī‹ŒīŠŧīŠģī‰īˆ ī‹“īŠŧīŠ§īˆ ī‹‚ī‰‚īŠŗī‰Šī‹žī‰īˆ ī‰Šī‰‚ī‹ˆīŠŖī‰‡īˆ īŠšīŠģī‰§īˆ īŠŸīˆ ī‰‚īŠ–īˆ īŠŠī‹ąīŠŗīˆ īŠŠī‰Šī‰ŽīŠģī‰īˆ ī‰ī‰ī‰§īˆ ī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰īˆ ī‹’ī‰™ī‹ŒīŠģīˆ īŠŊī‹ŽīŠŦī‰˛ī‰īˆ ī‹’ī‹ŽīŠŧī‹€īŠ§īˆ ī‹†ī‰‡
      īˆ ī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰īˆ ī‹’ī‰™ī‹ŒīŠģīˆ ī‹’ī‹Žī‹„ī‰‰īˆ ī‹’īŠ¯ī‰ĒīŠ¨īŠŋīˆ ī‰‹īŠīˆ ī‹‰ī‹ƒī‰ˆīŠ¯īˆ ī‹īŠŗī‰Šī‹žī‰īˆ ī‹…īŠŋīˆ ī‹īŠŗī‰Šīˆ īŠŊīŠˇīˆ īˆ—īŠ°ī‰˛ī‰īˆ ī‹’īŠ¯ī‰ĒīŠ¨īŠŋīˆ īŠŊī‰•ī‰ƒīˆ ī‹…īŠŋī‹‹īˆ īˆŦī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰īˆ ī‹’ī‰™ī‹ŒīŠģīˆ ī‹īŠŗī‰Šī‰ƒīˆ ī‹…īŠŋīˆ ī‹īŠŗī‰Šīˆ īŠŊīŠˇ
                                                                                              īˆ  īˆ īˆŽīŠŠī‹ąīŠŗīˆ īŠŠī‰Šī‰ŽīŠģī‰īˆ ī‰ī‰ī‰§
                                            īˆ  īˆ īˆŽīŠŠī‹ąīŠŗīˆ īŠŠī‰Šī‰ŽīŠģī‰īˆ ī‰ī‰ī‰§īˆ ī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰īˆ īˆ ī‰ī‰‚ī‰™ī‹ŒīŠŧīŠģīˆ ī‹īŠŧī‰Ąī‰ī‰ĻīŠģī‰īˆ īŠĄī‹ąī‰ĸīŠī‰īˆ īŠ”ī‰Šī‹īˆ ī‹īŠģī‰‚ī‰ŽīŠģī‰īˆ īŠŊīŠ¸ī‰˛īŠģī‰
      ī‹’ī‰ŽīŠ—ī‹žī‰ī‹‹īˆ ī‹īŠģī‹ ī‰īˆ ī‹īŠ¸ī‰šī‰ŽīŠģī‰īˆ ī‹’ī‰­ī‰Ļī‹„ī‹‡īˆ ī‹ī‰ŽīŠŗ                        92                       ī‹’ī‹Žī‹ƒī‹‹īˆ–īŠ¸īŠģī‹ĸī‰ī‹‹īˆ ī‹’ī‹Žī‹–ī‰‚ī‰‰ī‰Ēī‹ˆīŠ¸īŠģī‰īˆ ī‹’ī‰­ī‰Ļī‹„īˆšī‰īˆ ī‹’ī‹ŽīŠŧīŠˇ
Practical Class 5                                                                          Programming Microcontrollers




  īˆ īˆŦīˆ¨ī‹’īŠ¨ī‹ąīŠŗīˆ īŠŊīŠ¸īŠģīˆ ī‹ī‹–ī‹Œī‰šīˆ ī‹ī‹–ī‰‚ī‹„ī‰‘īˆŠīˆ ī‹’ī‹Žī‹–ī‹Œī‰šīˆ ī‰ī‰‚ī‹Žī‹–ī‰‚ī‹„ī‰‘īˆ ī‹’īŠ¨ī‰Šī‰­īˆ ī‹“īŠŧīŠ§īˆ ī‹ī‹ŒīŠ„īˆ ī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰īˆ ī‹’ī‰™ī‹ŒīŠģīˆ ī‹†ī‰ƒīˆ ī‹Šī‹īŠ§ī‰ƒīˆ īŠŊīŠ¸ī‰˛īŠģī‰īˆ ī‹…īŠŋīˆ ī‰œī‰šī‰ī‹‹īˆ ī‹Œī‹‡īˆ ī‰‚ī‹€īŠˇ
                                                                             īˆ  īˆ īˆŽī‹’ī‹ī‰Ēī‰˛īŠ¨īŠģī‰īˆ ī‹’īŠŧī‰ĩī‰‚īŠ°īŠŧīŠģīˆ ī‹…īŠŋī‰‚ī‰‘īˆ ī‹ī‹–ī‹Œī‰šīˆ ī‹ī‹–ī‰‚ī‹„ī‰‘īˆ īŠ•ī‰‡īˆ ī‹’īŠ¯ī‰‚ī‰šī‹ĸī‰‚ī‰‰
  īˆ  īˆ īˆŽīˆ¨CCīˆŠīˆ īŠēīˆ–ī‰˛īŠŋīˆ īŠĄī‰Šī‹ˆīŠŋīˆ ī‹‹ī‰ƒīˆ īˆ¨CAīˆŠīˆ īŠēīˆ–ī‰˛īŠŋīˆ ī‰ĻīŠ¨ī‰ļīŠŋīˆ ī‰‚īŠŋī‰‡īˆ īˆŦīŠ”ī‰ŽīŠ´ī‹ī‰Ēī‰ŋīˆ ī‹”ī‰Ļī‰™ī‰ˆī‰‰īˆ ī‹’īŠģī‹Œī‰ĩī‹ŒīŠŋīˆ ī‹†ī‹ŒīŠ¸ī‰īˆ ī‹’ī‹Žī‹–ī‹Œī‰ēīŠģī‰īˆ ī‰ī‰‚ī‹Žī‹–ī‰‚ī‹„ī‰’īŠģī‰īˆ īŠŠī‹ŽīŠšīˆ ī‹†ī‰‡
                          īˆ  īˆ īˆŽīŠēīˆ–ī‰˛īŠī‰īˆ ī‰ĻīŠ¨ī‰ļīŠī‰īˆ ī‹’īŠŧī‰ĩī‹‹īˆ ī‰œī‰šī‹Œī‹ŽīŠ¯īˆ ī‹ī‰Šī‰‚ī‰Žī‹ŽīŠģī‰īˆ ī‰‚īŠŋī‰ƒī‹‹īˆ īˆŦīŠēīˆ–ī‰˛īŠī‰īˆ īŠĄī‰Šī‹ˆīŠī‰īˆ ī‹’īŠŧī‰ĩī‹‹īˆ ī‰œī‰šī‹Œī‹īˆ īˆŸī‹Žī‹€ī‹ŽīŠģī‰īˆ īŠŊīŠ¸ī‰˛īŠģī‰
  īˆ īŠ˛ī‰ĒīŠīˆ ī‰‚ī‹ˆī‹„īŠŋīˆ ī‹‘ī‰Ļī‰™ī‰ī‹‹īˆ īŠŊīŠˇīˆ īŠ•ī‰‡īˆ ī‹‘ī‰Šī‰‚ī‰ąī‹ĸī‰īˆ ī‹ī‰Žī‹īˆ ī‹’ī‹ī‰Ēī‰˛īŠ¨īŠģī‰īˆ ī‹’īŠŧī‰ĩī‰‚īŠ°īŠģī‰īˆ ī‹’ī‹ąīŠ´ī‹ƒīˆ īŠ•ī‰‡īˆ ī‹’īŠ¯ī‰‚ī‰šī‹ĸī‰‚ī‰‰īˆ ī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰īˆ ī‹’ī‰™ī‹ŒīŠģīˆ īŠŸīˆ ī‹’īŠ¨ī‰Šī‰ŽīŠģī‰īˆ īŠŠī‹ąīŠ´īŠģī‰īˆ ī‹†ī‰‡
         īˆ  īˆ īˆēīŠŊīŠ¸ī‰˛īŠģī‰īˆ īŠŸīˆ ī‰‚ī‹€īŠˇīˆ ī‰ī‰‚īŠˇī‰Ēī‰˛īŠģī‰īˆ īŠŊīŠˇīˆ īŠŊī‰ŠīŠŗīˆ ī‹…īŠŋīˆ ī‰Ļī‹€ī‰ŽīŠ¨īŠŋīˆ ī‹īŠī‰‚īŠ§īˆ ī‰Ŧī‹ŽīŠŋī‰Ēī‰īˆ ī‹Œī‹‡īˆ ī‹’īŠ¨ī‹ąīŠŗīˆ īŠŊīŠ¸īŠģīˆ ī‰Ŧī‹ŽīŠŋīˆ–īŠģī‰īˆ ī‰ī‰¨ī‹‡īˆ ī‹†ī‰‡īˆ īˆŦīˆ¨A,â€Ļ..,HīˆŠ




                    īˆ  īˆ                            īˆ īˆ īˆ īˆ īˆ īˆ īˆ īˆ īˆ īˆ īˆ īˆ īˆ īˆ īˆ īˆ īˆ īˆ īˆ īˆ īˆ īˆ īˆ īˆ īˆ īˆ īˆ īˆ īˆ īˆ īˆ īˆ īˆ īˆ īˆ īˆ 
                                                                                                                           īˆ  īˆ 
  īˆ ī‹’ī‰Šī‰Žī‹„īŠģī‰‚ī‰‰īˆ ī‰ī‰¨īŠ¸ī‹‡ī‹‹īˆ B,Cīˆ īŠ”ī‰ŽīŠ¨ī‹ąīŠ´īŠģī‰īˆ īŠŊī‹ŽīŠŦī‰˛ī‰īˆ ī‰‹īŠīˆ ī‹‰ī‹ƒī‰ˆīŠ¯īˆ īˆŦī‹’ī‹ŽīŠ§ī‰‚ī‰Šī‰ŽīŠģī‰īˆ ī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰īˆ ī‹’ī‰™ī‹ŒīŠģīˆ ī‹“īŠŧīŠ§īˆ īˆ¨1īˆŠīˆ ī‹īŠŗī‰ĒīŠģī‰īˆ ī‰Šī‰‚ī‹ˆīŠŖī‰‡īˆ īŠŊī‰•ī‰ƒīˆ ī‹…īŠŋīˆ ī‹īŠģī‰‚ī‰ŽīŠģī‰‚ī‰‰ī‹‹
                                                                                                            īˆ  īˆ īˆ īˆŽī‹‚ī‰‚īŠŗī‰Šī‹žī‰īˆ ī‹īŠŗī‰‚ī‰ŠīŠģ




īˆ  īˆ 
                                                                                                                           īˆ  īˆ 
  īˆ ī‰ī‰ī‰§īˆ ī‹”ī‰Ēī‰Ąī‰ƒī‹‹īˆ ī‰ĒīŠŦī‰ļīŠŋīˆ ī‹īŠ¸ī‰šī‰ŽīŠīˆ PortCīˆ ī‹’ī‰‰ī‰ī‹Œī‰ŠīŠģī‰īˆ īŠŠīŠŋīˆ ī‹’īŠģī‹Œī‰ĩī‹ŒīŠŋīˆ īŠēīˆ–ī‰˛īŠŋīˆ ī‰ĻīŠ¨ī‰ļīŠŋīˆ ī‰ī‰ī‰§īˆ ī‹’ī‹ŽīŠ§ī‰‚ī‰Šī‰­īˆ ī‰Šī‰‚ī‹ˆīŠŖī‰‡īˆ ī‹’ī‰ąī‰‚ī‰ąīˆ ī‰‚ī‹„ī‹ī‰ĻīŠģīˆ ī‹‰ī‹ƒī‰‡īˆ ī‰žī‰ĒīŠ°ī‰‰
                                                      īˆ  īˆ īˆēī‹īŠģī‰‚ī‰ŽīŠģī‰īˆ īŠŊīŠ¸ī‰˛īŠģī‰īˆ īŠŸīˆ ī‰‚ī‹€īŠˇīˆ PortDīˆ ī‹’ī‰‰ī‰ī‹Œī‰ŠīŠģī‰īˆ īŠŠīŠŋīˆ ī‹’īŠģī‹Œī‰ĩī‹ŒīŠŋīˆ īŠēīˆ–ī‰˛īŠŋīˆ īŠĄī‰Šī‹ˆīŠŋ
      Faculty of Electrical and Electronic Eng.                         93                 Automatic Control & Automation Dept.
ī‹‘ī‰ĒīŠŦī‰ļīŠī‰īˆ ī‰ī‰‚ī‹€īŠ¸ī‰šī‰ŽīŠī‰īˆ ī‹’īŠ‰ī‰Ēī‰‰                                                                   īˆ  īˆ  ī‹’ī‰ŽīŠŋī‰‚īŠˆī‰īˆ ī‹’ī‰ŽīŠŧīŠ†ī‰




     īˆ  īˆ 
īˆ ī‹“īŠŧīŠ§īˆ ī‹īŠ´ī‹ąī‹„īŠŋīˆ ī‰ĒīŠ°ī‰ĩīˆ īŠŠī‰šī‹‹īˆ ī‹īŠŦī‰Šī‹„ī‹īˆ īˆŦīˆ¨īŠēīˆ–ī‰˛īŠī‰īˆ īŠĄī‰Šī‹ˆīŠī‰īˆ ī‰ī‰ī‰§īˆŠīˆ ī‹’ī‹ī‹ŒīŠŧīŠ¨īŠģī‰īˆ ī‹’ī‰™ī‹ŒīŠŧīŠģī‰īˆ īŠŸīˆ ī‹’īŠ¨ī‹ąīŠŗīˆ ī‹ī‰ƒīˆ īŠŊī‹ŽīŠŦī‰˛ī‰īˆ īŠŊī‰•ī‰ƒīˆ ī‹…īŠŋīˆ ī‹‰ī‹ƒī‰ˆīŠ¯īˆ ī‹īŠģī‰‚ī‰ŽīŠģī‰‚ī‰‰ī‹‹
                                                              īˆ  īˆ īˆ īˆŽī‹’īŠ¨ī‹ąīŠ´īŠģī‰īˆ īŠŠīŠŋīˆ īŠžī‹Œī‰ĩī‹ŒīŠī‰īˆ ī‹īŠ¸ī‰šī‰ŽīŠī‰īˆ ī‰‹ī‹ąīŠŗ
                                            PortCīˆ ī‹’ī‰‰ī‰ī‹Œī‰ŠīŠģī‰īˆ ī‹“īŠŧīŠ§īˆ ī‹’ī‹€ī‹ŽīŠ´īŠģī‰                  īˆ ī‰Œī‹ŒīŠŧī‹ąīŠī‰īˆ ī‹īŠŗī‰ĒīŠģī‰
           īˆ  īˆ    :â€Ģ-7 اīģŸīģ˜īģ„īģŠ اīģŸīąĩ īą” ī°˛ īēŽ ī˛ģīģžâ€ŦH 6-G 5-F 4-E 3-D 2-C 1-B 0-A                   īˆ  īˆ  ī‹Šī‰Šī‰‚ī‹ˆīŠŖī‰‡

          A.B.C.D.E.F             1    1     0        0   0      0     0       0                      0
              B.C                 1    1     1        1   1      0     0        1                     1
           A.B.D.E.G              1    0     1        0   0      1     0       0                      2
           A.B.C.D.G              1    0     1        1   0      0     0       0                      3
            B.C.F.G               1    0     0        1   1      0     0        1                     4
           A.C.D.F.G              1    0     0        1   0      0     1       0                      5
          A.C.D.E.F.G             1    0     0        0   0      0     1       0                      6
             A.B.C                1    1     1        1   1      0     0       0                      7
         A.B.C.D.E.F.G            1    0     0        0   0      0     0       0                      8
          A.B.C.D.F.G             1    0     0        1   0      0     0       0                      9
ī‹’ī‰ŽīŠ—ī‹žī‰ī‹‹īˆ ī‹īŠģī‹ ī‰īˆ ī‹īŠ¸ī‰šī‰ŽīŠģī‰īˆ ī‹’ī‰­ī‰Ļī‹„ī‹‡īˆ ī‹ī‰ŽīŠŗ                     94                    ī‹’ī‹Žī‹ƒī‹‹īˆ–īŠ¸īŠģī‹ĸī‰ī‹‹īˆ ī‹’ī‹Žī‹–ī‰‚ī‰‰ī‰Ēī‹ˆīŠ¸īŠģī‰īˆ ī‹’ī‰­ī‰Ļī‹„īˆšī‰īˆ ī‹’ī‹ŽīŠŧīŠˇ
Practical Class 5                                                                           Programming Microcontrollers

                                         īˆ  īˆ īˆēī‹īŠŧī‹ī‰‚īŠŋīˆ ī‰Ĩī‰ĻīŠīˆ ī‹†ī‰ƒīˆ ī‹…īŠ¸īŠ™īˆ ī‹’ī‹ī‰Ēī‰˛īŠ§īˆ ī‰ī‰­īˆ ī‹‹ī‰ƒīˆ ī‹’ī‹ī‰Ēī‰˛īŠ§īˆ īŠ•ī‰‡īˆ ī‹ī‹–ī‰‚ī‹„ī‰’īŠģī‰īˆ ī‹ī‹ŽīŠ´īŠģī‰īˆ īŠŊī‹ī‹Œī‰šī‰Žī‰‰īˆ ī‹īŠģī‰‚ī‰ŽīŠģī‰‚ī‰‰ī‹‹




īˆ  īˆ 
       &HC0              &HF9      &HA4           &HB0       &H99        &H92        &H82        &HF8        &H80       &H90


  īˆ ī‹’ī‰­ī‹ŒīŠ¸īŠ¨īŠŋīˆ ī‹’īŠģī‰‚īŠ‡ī‰īˆ ī‹…īŠ¸īŠģī‹‹īˆ īˆŦīˆ¨īŠēīˆ–ī‰˛īŠī‰īˆ ī‰ĻīŠ¨ī‰ļīŠī‰īˆ ī‰ī‰ī‰§īˆŠīˆ ī‹’ī‹ŽīŠŧīŠ°ī‰ŽīŠģī‰īˆ ī‹’ī‰™ī‹ŒīŠŧīŠģī‰īˆ īŠŊī‹ŽīŠŦī‰˛ī‰īˆ īŠŊī‰•ī‰ƒīˆ ī‹…īŠŋīˆ ī‹ī‹ŽīŠ´īŠģī‰īˆ ī‰Œī‰‚ī‰Žī‰™īˆ ī‹…īŠ¸īŠ™īˆ ī‹‰ī‹ƒī‰ˆīŠ¯īˆ īŠŊī‰’īŠī‰‚ī‰‰ī‹‹
                            īˆ  īˆ īˆ īˆŽī‰‚ī‹ˆīŠŧī‹ŽīŠŦī‰˛ī‰īˆ ī‰Ĩī‰ī‰ĒīŠī‰īˆ ī‹’īŠ¨ī‹ąīŠ´īŠģī‰īˆ īŠŠīŠŋīˆ īŠžī‹Œī‰ĩī‹ŒīŠī‰īˆ ī‹īŠ¸ī‰šī‰ŽīŠī‰īˆ ī‰‹ī‹ąīŠŗīˆ ī‹“īŠŧīŠ§īˆ ī‹īŠ´ī‹ąī‹„īŠŋīˆ ī‰Ļī‰™ī‰ī‹‹īˆ īŠŠī‰šī‹‹īˆ ī‹īŠŦī‰Šī‹„ī‹īˆ ī‹‰ī‹ƒī‹žīˆ īˆŦī‹ĩī‰‚īŠŋī‰‚īŠ—

                  īˆ  īˆ    :â€ĢاīģŸīģ˜īģ„īģŠ اīģŸīąĩ īą” ī°˛ īēŽ ī˛ģīģžâ€Ŧ                    PortCīˆ ī‹’ī‰‰ī‰ī‹Œī‰ŠīŠģī‰īˆ ī‹“īŠŧīŠ§īˆ ī‹’ī‹€ī‹ŽīŠ´īŠģī‰                        īˆ ī‰Œī‹ŒīŠŧī‹ąīŠī‰īˆ ī‹īŠŗī‰ĒīŠģī‰
                                                   7-H 6-G 5-F 4-E 3-D 2-C 1-B 0-A                              īˆ  īˆ  ī‹Šī‰Šī‰‚ī‹ˆīŠŖī‰‡

                 A.B.C.D.E.F                        0    0          1        1   1      1         1      1                     0
                     B.C                            0    0          0        0   0      1         1      0                     1
                  A.B.D.E.G                         0    1          0        1   1      0         1      1                     2
                  A.B.C.D.G                         0    1          0        0   1      1         1      1                     3
                   B.C.F.G                          0    1          1        0   0      1         1      0                     4
                  A.C.D.F.G                         0    1          1        0   1      1         0      1                     5
                 A.C.D.E.F.G                        0    1          1        1   1      1         0      1                     6
                    A.B.C                           0    0          0        0   0      1         1      1                     7
                A.B.C.D.E.F.G                       0    1          1        1   1      1         1      1                     8
                 A.B.C.D.F.G                        0    1          1        0   1      1         1      1                     9
                                                                                                                             īˆ  īˆ 
                                         īˆ  īˆ īˆēī‹īŠŧī‹ī‰‚īŠŋīˆ ī‰Ĩī‰ĻīŠīˆ ī‹†ī‰ƒīˆ ī‹…īŠ¸īŠ™īˆ ī‹’ī‹ī‰Ēī‰˛īŠ§īˆ ī‰ī‰­īˆ ī‹‹ī‰ƒīˆ ī‹’ī‹ī‰Ēī‰˛īŠ§īˆ īŠ•ī‰‡īˆ ī‹ī‹–ī‰‚ī‹„ī‰’īŠģī‰īˆ ī‹ī‹ŽīŠ´īŠģī‰īˆ īŠŊī‹ī‹Œī‰šī‰Žī‰‰īˆ ī‹īŠģī‰‚ī‰ŽīŠģī‰‚ī‰‰ī‹‹




īˆ  īˆ 
       &H3F              &H06     &H5B            &H4F   &H66            &H6D        &H7D        &H07        &H7F       &H6F


      īˆ īŠēīˆ–ī‰˛īŠŋīˆ īŠĄī‰Šī‹ˆīŠŋīˆ īŠĒī‹Œī‹ƒīˆ ī‹…īŠŋīˆ ī‰Šī‰‚ī‹ˆīŠŖī‰‡īˆ ī‹’ī‰ąī‰‚ī‰ąīˆ īŠ•ī‰‡īˆ īŠēīˆ–ī‰˛īŠŋīˆ ī‰ĻīŠ¨ī‰ļīŠŋīˆ īŠĒī‹Œī‹ƒīˆ ī‹…īŠŋīˆ ī‰Šī‰‚ī‹ˆīŠŖī‰‡īˆ ī‹’ī‰ąī‰‚ī‰ąīˆ īŠ”ī‰‰īˆ īˆ—īŠ°ī‰˛ī‰ŽīŠģī‰īˆ ī‹ī‹ŽīŠŗīˆ īŠŊī‹ī‹ŒīŠ„īˆ ī‰Ļī‹„īŠ§īˆ īˆēī‹’īŠ¤ī‰™ī‹īŠŋ
                                                                    īˆ  īˆ īˆŽīˆ¨255 DECīˆŠīˆ &HFFīˆ ī‹’ī‹€ī‹ŽīŠ´īŠģī‰īˆ ī‹…īŠŋīˆ ī‹’ī‹€ī‹ŽīŠ´īŠģī‰īˆ ī‰ ī‰Ēī‰ŋīˆ ī‹īŠ°īŠ¸ī‹īˆ ī‹‰ī‹ƒī‰ˆīŠ¯

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

                                                                                           īˆ  īˆ īˆēī‹‘ī‰Ļī‹ī‰ĻīŠ†ī‰īˆ ī‰ī‰‚ī‹€ī‹ŽīŠŧīŠ¨ī‰ŽīŠģī‰
īˆ īŠēī‰‚ī‹„ī‹‡ī‹‹īˆ  īˆŦīˆ¨LUT: Look-Up TableīˆŠīˆ  ī‰ī‰‚ī‹ƒī‰‚ī‹Žī‰‰īˆ  īŠžī‹‹ī‰ĻīŠ€īˆ  ī‹“ī‹€ī‰Žī‹īˆ  ī‰‚īŠŋīˆ  ī‹…ī‹€ī‰šīˆ  ī‰—īŠŋī‰‚ī‹ƒīˆ•īŠģī‰īˆ  īŠŸīˆ  ī‰‚ī‹ˆī‹„ī‹ī‰ŦīŠ…īˆ  ī‹…īŠ¸īŠ™īˆ  īˆ—īŠ°ī‰˛ī‰ŽīŠģī‰īˆ  ī‹ī‹ŽīŠŗīˆ  ī‹†ī‰‡
                               īˆ  īˆ īˆŽī‰ī‰‚ī‹ƒī‰‚ī‹Žī‰ŠīŠģī‰īˆ īŠžī‹‹ī‰ī‰Ļī‰•īˆ ī‹…īŠŋīˆ ī‹‘ī‹•ī‰ī‰ĒīŠ´īŠģī‰ī‹‹īˆ ī‹…ī‹ī‰Ŧī‰ĸī‰ŽīŠŧīŠģīˆ ī‹”ī‰Ēī‰Ąī‹žī‰īˆ ī‰ī‰‚ī‹€ī‹ŽīŠŧīŠ¨ī‰ŽīŠģī‰īˆ ī‰ŧīŠ¨ī‰‰ī‹‹īˆ īŠ”ī‰Žī‹Žī‰­ī‰‚ī‰­ī‰ƒīˆ īŠ”ī‰Žī‹Žī‹€ī‹ŽīŠŧīŠ¨ī‰
                īˆ  īˆ  ī‹’ī‹ŽīŠ‰īˆ•īŠģī‰īˆ ī‹’ī‹€ī‹ŽīŠŧīŠ¨ī‰ŽīŠģī‰                                        īˆ  īˆ  ī‹’ī‹€ī‹ŽīŠŧīŠ¨ī‰ŽīŠģī‰īˆ ī‰ ī‰Ēī‰ą
                                                         īˆ ī‹’ī‰ŽīŠ¯ī‹œīˆ ī‰Ļī‹„īŠ§īˆ ī‰—īŠŋī‰‚ī‹ƒīˆ•īŠģī‰īˆ ī‹‘ī‰ĒīŠˇī‰ī‰§īˆ īˆ īŠŸīˆ īˆ¨ī‹’ī‹ŽīŠ¯ī‰ĒīŠŠīˆŦī‹’ī‹Žī‹€īŠŗī‰ŠīˆŠīˆ ī‰ī‰‚ī‹ƒī‰‚ī‹Žī‰‰īˆ ī‹…ī‹ī‰ŦīŠ…
Data var1 , â€Ļ , varn
                                                                          īˆ  īˆ .0īˆ īŠŊī‹ŽīŠģī‰ĻīŠģī‰īˆ ī‹‰īŠģīˆ īŠžī‹‹ī‹žī‰īˆ ī‰Ēī‰ļī‹„īŠ¨īŠģī‰īˆ ī‹†ī‰ƒīˆ ī‰“ī‹Žī‰™īˆ īˆŦī‹’ī‹„ī‹ŽīŠ¨īŠŋ
                                                         īˆ labelīˆ ī‹’ī‰ŽīŠ¯ī‹īŠģī‰īˆ ī‰Ļī‹„īŠ§īˆ  Dataīˆ īŠŸīˆ ī‹†ī‰ŦīŠ‹īˆ  LUTīˆ ī‹…īŠŋīˆ ī‹’ī‹€ī‹ŽīŠŗīˆ ī‰‹īŠŧī‰•
var = Lookup(Index , label)
                                                                                            īˆ  īˆ īˆŽIndexīˆ īŠŊī‹ŽīŠģī‰ĻīŠģī‰īˆ ī‹‰īŠģī‹‹
                                                         īˆ ī‹’ī‰ŽīŠ¯ī‹īŠģī‰īˆ  ī‰Ļī‹„īŠ§īˆ  Dataīˆ  īŠŸīˆ  ī‹†ī‰ŦīŠ‹īˆ  LUTīˆ  ī‹…īŠŋīˆ  īŠ˛ī‰ĒīŠŠīˆ  ī‰‹īŠŧī‰•
Var = Lookupstr(Index , Label)
                                                                                  īˆ  īˆ īˆŽIndexīˆ īŠŊī‹ŽīŠģī‰ĻīŠģī‰īˆ ī‹‰īŠģī‹‹īˆ label
                                                         īˆ īŠŸīˆ  ī‹†ī‰ŦīŠ‹īˆ  īˆ¨valueīˆŠīˆ  ī‹’ī‹€ī‹ŽīŠŗīˆ  īˆ¨IndexīˆŠīˆ  īŠŊī‹ŽīŠģī‰Ĩīˆ  ī‹…īŠ§īˆ  ī‰“ī‰šī‰ŠīŠģī‰
Var = Lookdown(value,Label,Entries)                      īˆ ī‰Ĩī‰ĻīŠ§īˆ ī‹…ī‹€ī‰šīˆ ī‰“ī‰šī‰ŠīŠģī‰īˆ ī‹ī‰Žī‹Žī‹īˆ ī‹†ī‰ƒīˆ ī‹“īŠŧīŠ§īˆ  labelīˆ ī‹’ī‰ŽīŠ¯ī‹īŠģī‰īˆ ī‰Ļī‹„īŠ§īˆ  Data
                                                                               īˆ  īˆ īˆŽīˆ¨EntriesīˆŠīˆ ī‰Ēī‰ĩī‰‚ī‹„īŠ¨īŠģī‰īˆ ī‹…īŠŋīˆ ī‰Ĩī‰ĻīŠŠ
                                                        īˆ īˆ īŠŸīˆ  ī‰Ĩī‹Œī‰•ī‹ŒīŠŋīˆ  ī‰Ēī‰ļī‹„īŠ§īˆ  īŠžī‹‹ī‰ƒīˆ  īŠ•ī‰‡īˆ  ī‰ī‰‚ī‹ƒī‰‚ī‹Žī‰‰īˆ  īˆ¨ī‰Ĩī‰ī‰ĻīŠ§īˆŠīˆ  ī‰Ēī‰ąī‹›īŠŋīˆ  īŠŠī‰šī‹Œī‰‰īˆ  ī‹‚ī‹ŒīŠ´ī‰
Restore Label                                            īˆ ī‹‘ī‹•ī‰ī‰ĒīŠŗīˆ īŠŊī‰•ī‰ƒīˆ ī‹…īŠŋīˆ  labelīˆ ī‹’ī‰ŽīŠ¯ī‹īŠģī‰īˆ ī‰Ļī‹„īŠ§īˆ  Dataīˆ īŠŸīˆ ī‹†ī‰ŦīŠ‹īˆ  LUT
                                                                           Read Varīˆ īˆ īˆēī‹’ī‹€ī‹ŽīŠŧīŠ¨ī‰īˆ ī‹‚ī‰ī‰Ļī‰ĸī‰Žī‰­ī‰‚ī‰‰īˆ ī‰ī‰‚ī‹ƒī‰‚ī‹Žī‰ŠīŠģī‰
                                                         īˆ īˆƒīˆ  īˆžīŠģī‰ī‹‹īˆ  Dataīˆ  īŠŸīˆ  ī‹†ī‰ŦīŠ‹īˆ  LUTīˆ  īˆ  īŠŸīˆ  ī‹‘ī‰Ĩī‹Œī‰•ī‹ŒīŠī‰īˆ  ī‹ī‹ŽīŠ´īŠģī‰īˆ  ī‹‘ī‹•ī‰ī‰ĒīŠŗ
Read Var                                                 īˆ īŠ•ī‰‡īˆ  ī‹ī‹‡ī‰Ĩī‰‚ī‹„ī‰­ī‰‡ī‹‹īˆ  Restoreīˆ  ī‹’ī‹€ī‹ŽīŠŧīŠ¨ī‰ŽīŠģī‰īˆ  ī‹‚ī‰ī‰Ļī‰ĸī‰Žī‰­ī‰‚ī‰‰īˆ  ī‰‚ī‹ˆī‹ŽīŠģī‰‡īˆ  ī‹‘ī‰Šī‰‚ī‰ąī‹ĸī‰
                                                                                                  īˆ  īˆ īˆŽVarīˆ īŠžī‹Œī‰šī‰ŽīŠī‰
                                                                                                                īˆ  īˆ 
                                                                                                                īˆ  īˆ 
                                                                                                                īˆ  īˆ 
                                                                                                                īˆ  īˆ 
                                                                                                                īˆ  īˆ 
                                                                                                                īˆ  īˆ 
                                                                                                                īˆ  īˆ 
                                                                                                                īˆ  īˆ 
                                                                                                                īˆ  īˆ 
                                                                                                                īˆ  īˆ 
                                                                                                                īˆ  īˆ 
                                                                                                                īˆ  īˆ 
ī‹’ī‰ŽīŠ—ī‹žī‰ī‹‹īˆ ī‹īŠģī‹ ī‰īˆ ī‹īŠ¸ī‰šī‰ŽīŠģī‰īˆ ī‹’ī‰­ī‰Ļī‹„ī‹‡īˆ ī‹ī‰ŽīŠŗ                            96                         ī‹’ī‹Žī‹ƒī‹‹īˆ–īŠ¸īŠģī‹ĸī‰ī‹‹īˆ ī‹’ī‹Žī‹–ī‰‚ī‰‰ī‰Ēī‹ˆīŠ¸īŠģī‰īˆ ī‹’ī‰­ī‰Ļī‹„īˆšī‰īˆ ī‹’ī‹ŽīŠŧīŠˇ
Practical Class 5                                                                Programming Microcontrollers

                                               īˆ  īˆ īˆēīˆ¨0-9īˆ ī‹ī‰Ēī‰˛īŠ§īˆ ī‰Ĩī‰ī‰ĻīŠ¨īŠˇīˆ ī‹’ī‹ī‰Ĩī‰ĒīŠ¯īˆ ī‰Šī‰‚ī‹ˆīŠŖī‰‡īˆ ī‹’ī‰™ī‹ŒīŠģīˆŠīˆ ī‹‘ī‰Šī‰ī‰ĻīŠģī‰īˆ īŠŊī‹ŽīŠŦī‰˛ī‰īˆ ī‰—īŠŋī‰‚ī‹ƒī‰Ēī‰‰
                                            īˆ  īˆ īˆŽSW34īˆ ī‰ ī‰‚ī‰ŽīŠ°īŠī‰īˆ ī‹…īŠŋīˆ 4īˆ īŠŊī‰ĩī‹ŒīŠģī‰īˆ ī‹’ī‹ąīŠ´ī‹ƒīˆ īŠļī‹īŠĢī‰‡īˆ ī‰‹īŠīˆ  īˆēīŠŊī‹Žī‰ĩī‹Œī‰ŽīŠģī‰īˆ ī‰ī‰‚ī‰ŠīŠŧī‹ąī‰ŽīŠŋ
$regfile = "m128def.dat"
$crystal = 8000000                                                            īˆ  īˆ īˆŽī‰ī‰‚ī‹ˆī‹Žī‰•ī‹Œī‰ŽīŠģī‰
'---------------------
                                                                īˆ  īˆ īˆŽī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰īˆ ī‹’ī‰ąī‰‚ī‰ąīˆ ī‰‚ī‹ˆīŠ¨īŠŋīˆ īŠŊī‰ĩī‹ŒīŠī‰īˆ ī‹’ī‰‰ī‰ī‹Œī‰ŠīŠģī‰īˆ īŠąī‹ī‰ĒīŠ¨ī‰
Config Porta = Output
Segment Alias Porta                                           īˆ ī‰Ēī‹ˆīŠ¤ī‰īˆ ī‹ī‹‡ī‹‹īˆ īˆ¨&H81īˆŠīˆ ī‹’ī‰‰ī‰ī‹Œī‰ŠīŠģī‰īˆ ī‹“īŠŧīŠ§īˆ ī‹’ī‹ŽīŠģī‹‹ī‹žī‰īˆ ī‹’ī‹€ī‹ŽīŠ´īŠģī‰īˆ īŠ”ī‹ŽīŠ¨ī‰
Porta = &H81                                                         īˆ  īˆ ī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰īˆ ī‹’ī‰ąī‰‚ī‰ąīˆ ī‹“īŠŧīŠ§īˆ ī‰ĒīŠ°ī‰ĩīˆ ī‹īŠŗī‰ĒīŠģī‰
Config Portc.4 = Output                                                            īˆ  īˆ 
Ctr1 Alias Portc.4
Reset Ctr1                                                  īˆ  īˆ ī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰īˆ ī‹’ī‰™ī‹ŒīŠŧīŠģīˆ īŠēīˆ–ī‰˛īŠī‰īˆ ī‰ĻīŠ¨ī‰ļīŠī‰‚ī‰‰īˆ ī‹īŠ¸ī‰šī‰ŽīŠģī‰īˆ ī‰‹ī‹ąīŠŗīˆ īŠąī‹ī‰ĒīŠ¨ī‰
'---------------------
Dim I As Byte                                                               īˆ  īˆ ī‰ī‹œī‹Œī‰šī‰ŽīŠī‰īˆ īŠąī‹ī‰ĒīŠ¨ī‰
'---------------------
Do
   For I = 0 To 9
      Segment = Lookup(i , Seg)                                      īˆ  īˆ īˆēī‰‚ī‹ˆī‹ŽīŠ¯īˆ ī‹ī‰Žī‹īˆ ī‹ī‰Žī‹Žī‹–ī‰ĒīŠģī‰īˆ ī‰—īŠŋī‰‚ī‹ƒīˆ•īŠģī‰īˆ ī‹’īŠ´īŠŧī‰™
      Waitms 1000
   Next I
                                                                īˆ īˆ¨SegīˆŠīˆ ī‹’ī‰ŽīŠ¯ī‹īŠģī‰īˆ ī‰Ļī‹„īŠ§īˆ īˆ¨DataīˆŠīˆ īŠŸīˆ ī‹’ī‹ƒī‰Ŧī‰ĸīŠī‰īˆ ī‹ī‹ŽīŠ´īŠģī‰īˆ ī‹‘ī‹•ī‰ī‰ĒīŠŗ
Loop                                                          īˆ  īˆ īˆŽī‹”ī‰Ēī‰Ąī‹žīˆ ī‹ŒīŠŧī‰īˆ ī‹’ī‹€ī‹ŽīŠŗīˆ īˆŦīˆ¨LookupīˆŠīˆ ī‹’ī‹€ī‹ŽīŠŧīŠ¨ī‰ŽīŠģī‰īˆ ī‹‚ī‰ī‰Ļī‰ĸī‰Žī‰­ī‰‚ī‰‰
End
'---------------------

Seg:                                                                   īˆ  īˆ īˆŽī‰ī‰‚ī‹ƒī‰‚ī‹Žī‰ŠīŠģī‰īˆ ī‹…ī‹ī‰ŦīŠ…īˆ īŠžī‹‹ī‰Ļī‰•īˆ ī‹’ī‰ŽīŠ¯ī‹œ
Data &H81 , &HF3 , &H49 , &H61 , &H33 ,
&H25 , &H05 , &HF1 , &H01 , &H21




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

                               īˆ  īˆ īˆēīˆ¨0 – 99īˆ ī‹ī‰Ēī‰˛īŠ§īˆ ī‰Ĩī‰ī‰ĻīŠ¨īŠˇīˆ ī‹’ī‹Žī‹–ī‰‚ī‹„ī‰‘īˆ ī‰Šī‰‚ī‹ˆīŠŖī‰‡īˆ ī‹’ī‰™ī‹ŒīŠģīˆ īŠŊī‹ŽīŠŦī‰˛ī‰īˆŠīˆ ī‹‘ī‰Šī‰ī‰ĻīŠģī‰īˆ īŠŊī‹ŽīŠŦī‰˛ī‰īˆ ī‰—īŠŋī‰‚ī‹ƒī‰Ēī‰‰
                                   īˆ  īˆ īˆŽSW34īˆ ī‰ ī‰‚ī‰ŽīŠ°īŠī‰īˆ ī‹…īŠŋīˆ 4,5īˆ īŠŊī‰ĩī‹ŒīŠģī‰īˆ īˆžī‹ąīŠ´ī‹ƒīˆ īŠļī‹īŠĢī‰‡īˆ ī‰‹īŠ īˆēīŠŊī‹Žī‰ĩī‹Œī‰ŽīŠģī‰īˆ ī‰ī‰‚ī‰ŠīŠŧī‹ąī‰ŽīŠŋ
$regfile = "m128def.dat"
$crystal = 8000000                                                      īˆ  īˆ īˆŽī‰ī‰‚ī‹ˆī‹Žī‰•ī‹Œī‰ŽīŠģī‰
'---------------------
Config Porta = Output                                   īˆ ī‰ī‰‚ī‰ąī‰‚ī‰˛īŠģīˆ ī‰ī‰‚ī‹ƒī‰‚ī‹Žī‰ŠīŠģī‰īˆ īŠĸī‹Œī‹ąī‰Ąīˆ ī‰‚ī‹ˆīŠ¨īŠŋīˆ īŠŊī‰ĩī‹ŒīŠī‰īˆ ī‹’ī‰‰ī‰ī‹Œī‰ŠīŠģī‰īˆ īŠąī‹ī‰ĒīŠ¨ī‰
Segment Alias Porta
Porta = &H81                                                              īˆ  īˆ īˆŽī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰
Config Portc.4 = Output                                 īˆ ī‰Ēī‹ˆīŠ¤ī‰īˆ ī‹ī‹‡ī‹‹īˆ īˆ¨&H81īˆŠīˆ ī‹’ī‰‰ī‰ī‹Œī‰ŠīŠģī‰īˆ ī‹“īŠŧīŠ§īˆ ī‹’ī‹ŽīŠģī‹‹ī‹žī‰īˆ ī‹’ī‹€ī‹ŽīŠ´īŠģī‰īˆ īŠ”ī‹ŽīŠ¨ī‰
Display1 Alias Portc.4                                         īˆ  īˆ ī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰īˆ ī‹’ī‰ąī‰‚ī‰ąīˆ ī‹“īŠŧīŠ§īˆ ī‰ĒīŠ°ī‰ĩīˆ ī‹īŠŗī‰ĒīŠģī‰
Config Portc.5 = Output                                 īˆ ī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰īˆ ī‹’ī‰™ī‹ŒīŠŧīŠģīˆ īŠēīˆ–ī‰˛īŠī‰īˆ ī‰ĻīŠ¨ī‰ļīŠī‰‚ī‰‰īˆ ī‹īŠ¸ī‰šī‰ŽīŠģī‰īˆ ī‰‹ī‹ąīŠŗīˆ īŠąī‹ī‰ĒīŠ¨ī‰
Display2 Alias Portc.5
                                                                       īˆ  īˆ īˆŽī‹’ī‹Žī‹ƒī‰‚ī‰’īŠģī‰ī‹‹īˆ īŠ•ī‹‹ī‹žī‰
Set Display1 : Set Display2                                      īˆ  īˆ īˆŽī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰īˆ īˆžī‰™ī‹ŒīŠģīˆ ī‹īŠˇīˆ ī‹•ī‰‚īŠ°ī‰ŋī‰‡
'---------------------
Dim I As Byte , J As Byte                                             īˆ  īˆ ī‰ī‹œī‹Œī‰šī‰ŽīŠī‰īˆ īŠąī‹ī‰ĒīŠ¨ī‰
'---------------------

Do
     For I = 0 To 9
        For J = 0 To 9                                         īˆ  īˆ īˆēī‰‚ī‹ˆī‹ŽīŠ¯īˆ ī‹ī‰Žī‹īˆ ī‹ī‰Žī‹Žī‹–ī‰ĒīŠģī‰īˆ ī‰—īŠŋī‰‚ī‹ƒīˆ•īŠģī‰īˆ ī‹’īŠ´īŠŧī‰™
           Segment = Lookup(i , Seg)
           Reset Display1 : Waitms 20                     īˆ īˆ¨SegīˆŠīˆ ī‹’ī‰ŽīŠ¯ī‹īŠģī‰īˆ ī‰Ļī‹„īŠ§īˆ īˆ¨DataīˆŠīˆ īŠŸīˆ ī‹’ī‹ƒī‰Ŧī‰ĸīŠī‰īˆ ī‹ī‹ŽīŠ´īŠģī‰īˆ ī‹‘ī‹•ī‰ī‰ĒīŠŗ
           Set Display1
                                                        īˆ  īˆ īˆŽī‹”ī‰Ēī‰Ąī‹žīˆ ī‹ŒīŠŧī‰īˆ ī‹’ī‹€ī‹ŽīŠŗīˆ īˆŦīˆ¨LookupīˆŠīˆ ī‹’ī‹€ī‹ŽīŠŧīŠ¨ī‰ŽīŠģī‰īˆ ī‹‚ī‰ī‰Ļī‰ĸī‰Žī‰­ī‰‚ī‰‰
         Segment = Lookup(j , Seg)                               īˆ  īˆ īˆŽīŠ•ī‹‹ī‹žī‰īˆ ī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰īˆ ī‹’ī‰™ī‹ŒīŠģīˆ īŠŊī‹ŽīŠŦī‰˛ī‰
         Reset Display2 : Waitms 20
         Set Display2                                     īˆ  īˆ īˆŽī‹’ī‹Žī‹ƒī‰‚ī‰’īŠģī‰īˆ īŠŊī‹ŽīŠŦī‰˛ī‰ī‹‹īˆ īŠ•ī‹‹ī‹žī‰īˆ ī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰īˆ ī‹’ī‰™ī‹ŒīŠģīˆ īŠ˛ī‰‚īŠ´ī‹ī‰‡
      Next J
   Next I
                                                                      īˆ  īˆ īˆŽīˆŽīˆŽī‹’ī‹ŽīŠŧī‹€īŠ¨īŠģī‰īˆ ī‰Šī‰ī‰ĒīŠ¸ī‰
Loop

End
'---------------------
Seg:
Data &H81 , &HF3 , &H49 , &H61 , &H33 ,                          īˆ  īˆ īˆŽī‰ī‰‚ī‹ƒī‰‚ī‹Žī‰ŠīŠģī‰īˆ ī‹…ī‹ī‰ŦīŠ…īˆ īŠžī‹‹ī‰Ļī‰•īˆ ī‹’ī‰ŽīŠ¯ī‹œ
&H25 , &H05 , &HF1 , &H01 , &H21




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

                                     īˆ  īˆ īˆēīˆ¨0 – 9999īˆ ī‹ī‰Ēī‰˛īŠ§īˆ ī‰Ĩī‰ī‰ĻīŠ¨īŠˇīˆ ī‹’ī‹ŽīŠ§ī‰‚ī‰‰ī‰Šīˆ ī‰Šī‰‚ī‹ˆīŠŖī‰‡īˆ ī‹’ī‰™ī‹ŒīŠģīˆ īŠŊī‹ŽīŠŦī‰˛ī‰īˆŠīˆ ī‹‘ī‰Šī‰ī‰ĻīŠģī‰īˆ īŠŊī‹ŽīŠŦī‰˛ī‰īˆ ī‰—īŠŋī‰‚ī‹ƒī‰Ēī‰‰
$regfile = "m128def.dat"
$crystal = 8000000                                                               īˆ  īˆ īˆŽī‰ī‰‚ī‹ˆī‹Žī‰•ī‹Œī‰ŽīŠģī‰
'---------------------
Config Porta = Output
Segment Alias Porta                                              īˆ ī‰ī‰‚ī‰ąī‰‚ī‰˛īŠģīˆ ī‰ī‰‚ī‹ƒī‰‚ī‹Žī‰ŠīŠģī‰īˆ īŠĸī‹Œī‹ąī‰Ąīˆ ī‰‚ī‹ˆīŠ¨īŠŋīˆ īŠŊī‰ĩī‹ŒīŠī‰īˆ ī‹’ī‰‰ī‰ī‹Œī‰ŠīŠģī‰īˆ īŠąī‹ī‰ĒīŠ¨ī‰
Porta = &H81
                                                                                  īˆ  īˆ īˆŽī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰
Config Portc =          &B11110000                              īˆ ī‰Ēī‹ˆīŠ¤ī‰īˆ ī‹ī‹‡ī‹‹īˆ īˆ¨&H81īˆŠīˆ ī‹’ī‰‰ī‰ī‹Œī‰ŠīŠģī‰īˆ ī‹“īŠŧīŠ§īˆ ī‹’ī‹ŽīŠģī‹‹ī‹žī‰īˆ ī‹’ī‹€ī‹ŽīŠ´īŠģī‰īˆ īŠ”ī‹ŽīŠ¨ī‰
Display1 Alias          Portc.4
Display2 Alias          Portc.5                                         īˆ  īˆ ī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰īˆ ī‹’ī‰ąī‰‚ī‰ąīˆ ī‹“īŠŧīŠ§īˆ ī‰ĒīŠ°ī‰ĩīˆ ī‹īŠŗī‰ĒīŠģī‰
Display3 Alias          Portc.6                                   īˆ ī‰ī‰‚ī‰™ī‹ŒīŠŧīŠģīˆ īŠēīˆ–ī‰˛īŠī‰īˆ ī‰ĻīŠ¨ī‰ļīŠī‰‚ī‰‰īˆ ī‹īŠ¸ī‰šī‰ŽīŠģī‰īˆ ī‰Œī‰‚ī‹ąīŠŗī‰ƒīˆ īŠąī‹ī‰ĒīŠ¨ī‰
Display4 Alias          Portc.7
                                                                               īˆ  īˆ īˆŽī‹’īŠ¨ī‰‰ī‰Šī‹žī‰īˆ ī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰
Set Display1 : Set Display2
Set Display3 : Set Display4
                                                                          īˆ  īˆ īˆŽī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰īˆ ī‰ī‰‚ī‰™ī‹ŒīŠģīˆ īŠŊīŠˇīˆ ī‹•ī‰‚īŠ°ī‰ŋī‰‡
'---------------------
Dim I As Byte , J As Byte
Dim K As Byte , L As Byte                                                     īˆ  īˆ ī‰ī‹œī‹Œī‰šī‰ŽīŠī‰īˆ īŠąī‹ī‰ĒīŠ¨ī‰
'---------------------
Do
   For I = 0 To 9
      For J = 0 To 9
         For K = 0 To 9
            For L = 0 To 9
               Segment = Lookup(i , Seg)
               Reset Display1 : Waitms 7
               Set Display1
                                                                       īˆ  īˆ īˆēī‰‚ī‹ˆī‹ŽīŠ¯īˆ ī‹ī‰Žī‹īˆ ī‹ī‰Žī‹Žī‹–ī‰ĒīŠģī‰īˆ ī‰—īŠŋī‰‚ī‹ƒīˆ•īŠģī‰īˆ ī‹’īŠ´īŠŧī‰™
                        Segment = Lookup(j , Seg)
                        Reset Display2 : Waitms 7                 īˆ īˆ¨SegīˆŠīˆ ī‹’ī‰ŽīŠ¯ī‹īŠģī‰īˆ ī‰Ļī‹„īŠ§īˆ īˆ¨DataīˆŠīˆ īŠŸīˆ ī‹’ī‹ƒī‰Ŧī‰ĸīŠī‰īˆ ī‹ī‹ŽīŠ´īŠģī‰īˆ ī‹‘ī‹•ī‰ī‰ĒīŠŗ
                        Set Display2                             īˆ  īˆ īˆŽī‹”ī‰Ēī‰Ąī‹žīˆ ī‹ŒīŠŧī‰īˆ ī‹’ī‹€ī‹ŽīŠŗīˆ īˆŦīˆ¨LookupīˆŠīˆ ī‹’ī‹€ī‹ŽīŠŧīŠ¨ī‰ŽīŠģī‰īˆ ī‹‚ī‰ī‰Ļī‰ĸī‰Žī‰­ī‰‚ī‰‰
                        Segment = Lookup(k , Seg)                         īˆ  īˆ īˆŽīŠ•ī‹‹ī‹žī‰īˆ ī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰īˆ ī‹’ī‰™ī‹ŒīŠģīˆ īŠŊī‹ŽīŠŦī‰˛ī‰
                        Reset Display3 : Waitms 7
                        Set Display3                               īˆ  īˆ īˆŽī‹’ī‹Žī‹ƒī‰‚ī‰’īŠģī‰īˆ īŠŊī‹ŽīŠŦī‰˛ī‰ī‹‹īˆ īŠ•ī‹‹ī‹žī‰īˆ ī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰īˆ ī‹’ī‰™ī‹ŒīŠģīˆ īŠ˛ī‰‚īŠ´ī‹ī‰‡
                                                                                 īˆ  īˆ īˆŽīˆŽīˆŽīˆŽī‰ī‰¨īŠ¸ī‹‡ī‹‹
                Segment = Lookup(l , Seg)
                Reset Display4 : Waitms 7                                     īˆ  īˆ īˆŽīˆŽīˆŽī‹’ī‹ŽīŠŧī‹€īŠ¨īŠģī‰īˆ ī‰Šī‰ī‰ĒīŠ¸ī‰
                Set Display4
             Next L
         Next K
      Next J
   Next I
Loop

End
'---------------------
Seg:
Data &H81 , &HF3 , &H49 , &H61 , &H33 ,                                  īˆ  īˆ īˆŽī‰ī‰‚ī‹ƒī‰‚ī‹Žī‰ŠīŠģī‰īˆ ī‹…ī‹ī‰ŦīŠ…īˆ īŠžī‹‹ī‰Ļī‰•īˆ ī‹’ī‰ŽīŠ¯ī‹œ
&H25 , &H05 , &HF1 , &H01 , &H21

                                                                                                                 ī„ ī„ 

                                                                                                                 ī„ ī„ 

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

      Exp.15: Real Time Clock                             īˆ  īˆ ī‹īŠ´ī‹ŽīŠ´īŠ‡ī‰īˆ ī‹…īŠŋī‰ŦīŠģī‰īˆ ī‰ī‹ŽīŠŗī‹Œī‰īˆ ī‹’īŠ§ī‰‚ī‰­īˆ īˆēī‹‘ī‰Ēī‰˛īŠ§īˆ ī‹’ī‰ŽīŠŋī‰‚īŠˆī‰īˆ ī‹’ī‰‰ī‰Ēī‰–ī‰ŽīŠģī‰

                                                                                          īˆ  īˆ īˆēī‹’ī‰‰ī‰Ēī‰–ī‰ŽīŠģī‰īˆ ī‹…īŠŋīˆ ī‹’ī‹ī‰‚īŠŦīŠģī‰
                                                         īˆ  īˆ īˆŽī‹īŠ´ī‹ŽīŠ´īŠ‡ī‰īˆ ī‹…īŠŋī‰ŦīŠģī‰īˆ īŠŸīˆ ī‰Ŗī‹ī‰Šī‰‚ī‰ī‹‹īˆ ī‰ī‹ŽīŠŗī‹Œī‰īˆ ī‹’īŠ§ī‰‚ī‰­īˆ īŠŊī‹ŽīŠŦī‰˛ī‰ī‹‹īˆ ī‹’īŠ‰ī‰Ēī‰‰
                                                                                           īˆ  īˆ īˆēīŠŊī‹Žī‰ĩī‹Œī‰ŽīŠģī‰īˆ īŠĄī‹ąīŠ‹




īˆ  īˆ 
                                                                                            īˆ  īˆ īˆēīŠŊī‹Žī‰ĩī‹Œī‰īˆ ī‰ī‰‚ī‰ŠīŠŧī‹ąī‰ŽīŠŋ
                                                                                     īˆ  īˆ īˆŽSW2īˆ ī‰ ī‰‚ī‰ŽīŠ°īŠī‰īˆ īŠļī‹īŠĢī‰‡īˆ ī‰‹īŠ
                                                                                                                īˆ  īˆ 
                                                                                             īˆ  īˆ īˆēī‹‘ī‰Šī‰ī‰ĻīŠģī‰īˆ īŠŊī‹€īŠ§īˆ ī‰ ī‰Ēī‰ą
                                     īˆ ī‰Ŗī‹ī‰Šī‰‚ī‰ŽīŠģī‰ī‹‹īˆ ī‰ī‹ŽīŠŗī‹Œī‰ŽīŠģī‰īˆ ī‹’ī‹€ī‹ŽīŠŗīˆ ī‰žī‰ĒīŠ§ī‹‹īˆ ī‰ī‹ŽīŠŗī‹Œī‰īˆ ī‹’īŠ§ī‰‚ī‰­īˆ īŠŊī‹ŽīŠŦī‰˛ī‰ŽīŠģīˆ ī‰—īŠŋī‰‚ī‹ƒī‰Ēī‰‰īˆ ī‹’ī‰‰ī‰‚ī‰ŽīŠ¸ī‰‰īˆ ī‹‚ī‹ŒīŠ´ī‹ƒīˆ īŠ˛ī‹Œī‰­
                                                                             īˆ  īˆ īˆŽī‹’ī‹ŽīŠģī‰‚ī‰Žī‰Žī‹ī‰ĒīŠ¸īŠģī‰īˆ ī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰īˆ ī‹’ī‰ąī‰‚ī‰ąīˆ ī‹“īŠŧīŠ§
                                     īˆ īŠŊī‰Ąī‰ī‰Ĩīˆ  ī‹‘ī‰Ĩī‹Œī‰•ī‹ŒīŠī‰īˆ  īˆ¨RTCīˆŠīˆ  ī‹īŠ´ī‹ŽīŠ´īŠ‡ī‰īˆ  ī‹…īŠŋī‰ŦīŠģī‰īˆ  īŠŸīˆ  ī‰ī‹ŽīŠŗī‹Œī‰ŽīŠģī‰īˆ  ī‹‘ī‰Ļī‰™ī‹‹īˆ  īŠŊī‹ŽīŠŦī‰˛ī‰īˆ  īŠŊī‰•ī‰ƒīˆ  ī‹…īŠŋīˆ  ī‹‰ī‹ƒī‰‡
                                     īˆ ī‰Œī‰‚ī‹ąīŠŗī‹žī‰īˆ  ī‹“īŠŧīŠ§īˆ  32.786 KHZīˆ  ī‹‰ī‰Žī‹€ī‹ŽīŠŗīˆ  ī‹īŠģī‰‚ī‰Žī‰Žī‹ī‰ĒīŠˇīˆ  ī‰Ģī‰ī‰Ŧī‹‡īˆ  īŠŊī‰ĩī‹‹īˆ  ī‰‹īŠīˆ  ī‹‰ī‹ƒī‰ˆīŠ¯īˆ  īˆ’ī‰‚īŠ¨īŠ
                                                                                                    īˆ  īˆ īˆŽTOSC1,2

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

                                                                                            īˆ  īˆ īˆēī‹‘ī‰Ļī‹ī‰ĻīŠ†ī‰īˆ ī‰ī‰‚ī‹€ī‹ŽīŠŧīŠ¨ī‰ŽīŠģī‰
                           īˆ  īˆ īˆŽī‹’ī‹ŽīŠŧī‰Ąī‰ī‰ĻīŠģī‰īˆ ī‹īŠ´ī‹ŽīŠ´īŠ‡ī‰īˆ ī‹…īŠŋī‰ŦīŠģī‰īˆ ī‹’īŠ§ī‰‚ī‰­īˆ īŠŸīˆ ī‹’īŠŋī‰Ļī‰ĸī‰Žī‰ŽīŠī‰īˆ ī‹‘ī‰Ļī‹ī‰ĻīŠ†ī‰īˆ ī‰ī‰‚ī‹€ī‹ŽīŠŧīŠ¨ī‰ŽīŠģī‰īˆ ī‰œī‰šī‹Œī‹īˆ ī‹īŠģī‰‚ī‰ŽīŠģī‰īˆ īŠžī‹‹ī‰ĻīŠ†ī‰
                    īˆ  īˆ  ī‹’ī‹ŽīŠ‰īˆ•īŠģī‰īˆ ī‹’ī‹€ī‹ŽīŠŧīŠ¨ī‰ŽīŠģī‰                                   īˆ  īˆ  ī‹’ī‹€ī‹ŽīŠŧīŠ¨ī‰ŽīŠģī‰īˆ ī‰ ī‰Ēī‰ą
Config Clock = Soft | User                                       īˆ  īˆ īˆŽīˆ¨ī‹ī‰•ī‰Šī‰‚ī‰Ąīˆ īˆ |īˆ īˆ ī‹’ī‹ŽīŠŧī‰Ąī‰ī‰ĨīˆŠīˆ ī‹īŠ´ī‹ŽīŠ´īŠ‡ī‰īˆ ī‹…īŠŋī‰ŦīŠģī‰īˆ ī‹’īŠ§ī‰‚ī‰­īˆ īŠąī‹ī‰ĒīŠ¨ī‰
Config Date = Dmy , Separator = Char                  īˆ  īˆ ī‹’ī‹„ī‰ŽīŠģī‰ī‹‹īˆ ī‰Ēī‹ˆī‰˛īŠģī‰ī‹‹īˆ ī‹‚ī‹Œī‹ŽīŠģī‰īˆ īŠ”ī‰‰īˆ īŠŊī‰ĩī‰ī‹ŒīŠ°īŠģī‰ī‹‹īˆ ī‰Ŗī‹ī‰Šī‰‚ī‰ŽīŠģī‰īˆ ī‰žī‰ĒīŠ§īˆ īŠŊīŠ¸ī‰ąīˆ īŠ”ī‹ŽīŠ¨ī‰
Time$ = "hh:mm:ss"                                                 īˆ  īˆ īˆŽī‰ī‹ŽīŠŗī‹Œī‰ŽīŠģī‰īˆ ī‰‚ī‹ˆī‹„īŠŋīˆ ī‰ƒī‰Ļī‰Šī‹īˆ ī‰ī‹ŽīŠŗī‹Œī‰ŽīŠŧīŠģīˆ ī‹’ī‹Žī‰šī‰īˆ–īŠ¯ī‰īˆ ī‹’ī‹€ī‹ŽīŠŗīˆ īŠ”ī‹ŽīŠ¨ī‰
Date$ = "mm/dd/yy"                                                   īˆ  īˆ īˆŽī‰Ŗī‹ī‰Šī‰‚ī‰ŽīŠģī‰īˆ ī‰‚ī‹ˆī‹„īŠŋīˆ ī‰ƒī‰Ļī‰Šī‹īˆ ī‰Ŗī‹ī‰Šī‰‚ī‰ŽīŠŧīŠģīˆ ī‹’ī‹Žī‰šī‰īˆ–īŠ¯ī‰īˆ ī‹’ī‹€ī‹ŽīŠŗīˆ īŠ”ī‹ŽīŠ¨ī‰
Var = Time$                                                                            īˆ  īˆ ī‰īŠŗī‹ŒīŠŧīŠģīˆ ī‹’ī‹ŽīŠģī‰‚īŠ‡ī‰īˆ ī‹’ī‹€ī‹ŽīŠ´īŠģī‰īˆ ī‹‘ī‹•ī‰ī‰ĒīŠŗ
Var = Date$                                                                           īˆ  īˆ ī‰Ŗī‹ī‰Šī‰‚ī‰ŽīŠŧīŠģīˆ ī‹’ī‹ŽīŠģī‰‚īŠ‡ī‰īˆ ī‹’ī‹€ī‹ŽīŠ´īŠģī‰īˆ ī‹‘ī‹•ī‰ī‰ĒīŠŗ


                                                                                        īˆ  īˆ īˆēī‹‘ī‰Šī‰ī‰ĻīŠģī‰īˆ īŠŊī‹ŽīŠŦī‰˛ī‰īˆ ī‰—īŠŋī‰‚ī‹ƒī‰Ēī‰‰
$regfile = "m128def.dat"
$crystal = 8000000                                                                 Directives
'----------------------
Config Lcdpin = Pin , Db4 = Portc.4 , Db5 =
Portc.5 , Db6 = Portc.6 , Db7 = Portc.7 , E
= Portc.2 , Rs = Portc.3                                                īˆ  īˆ Configure the LCD display
Config Lcd = 20 * 4
'----------------------
Config Clock = Soft                                            īˆ  īˆ īˆŽīˆ’ī‰‚īŠ¨ī‹€īŠŧīŠģīˆ ī‹’ī‹ŽīŠŧī‰Ąī‰ī‰ĻīŠģī‰īˆ ī‹īŠ´ī‹ŽīŠ´īŠ‡ī‰īˆ ī‰ī‹ŽīŠŗī‹Œī‰ŽīŠģī‰īˆ ī‹’īŠ§ī‰‚ī‰­īˆ īŠąī‹ī‰ĒīŠ¨ī‰
Config Date = Dmy , Separator = /
Enable Interrupts                                                   īˆ  īˆ ī‹’ī‹„ī‰ŽīŠģī‰/ī‰Ēī‹ˆī‰˛īŠģī‰/ī‹‚ī‹Œī‹ŽīŠģī‰īˆ ī‰Šī‰‚ī‹ˆīŠŖī‰‡īˆ īŠĄīŠ˜īˆ īŠąī‹ī‰ĒīŠ¨ī‰
                                                                                      īˆ  īˆ 
Time$ = "16:59:00"
Date$ = "14/04/08"                                             īˆ  īˆ ī‰ī‹ŽīŠŗī‹Œī‰ŽīŠģī‰ī‹‹īˆ ī‰Ŗī‹ī‰Šī‰‚ī‰ŽīŠŧīŠģīˆ īˆ¨ī‹‘ī‰Ēī‹ī‰‚īŠ¨īŠŋīˆŠīˆ ī‹’ī‹Žī‹–ī‰ī‰Ļī‰Žī‰‰ī‹œī‰īˆ ī‹ī‹ŽīŠ´īŠģī‰īˆ īŠąī‹ī‰ĒīŠ¨ī‰
----------------------
Do
   Print Time$                                                         īˆ  īˆ īˆēī‰‚ī‹ˆī‹ŽīŠ¯īˆ ī‹ī‰Žī‹īˆ ī‹ī‰Žī‹Žī‹–ī‰ĒīŠģī‰īˆ ī‰—īŠŋī‰‚ī‹ƒīˆ•īŠģī‰īˆ ī‹’īŠ´īŠŧī‰™
   Print Date$
                                                             īˆ  īˆ īˆ’ī‰‚īŠ¨ī‹€īŠŧīŠģīˆ ī‹’ī‹ŽīŠŧī‰ŽīŠŧī‰Žī‰ŽīŠģī‰īˆ ī‹‘ī‰¨īŠ¯ī‰‚ī‹„īŠģī‰īˆ ī‹“īŠŧīŠ§īˆ ī‰Ŗī‹ī‰Šī‰‚ī‰ŽīŠģī‰ī‹‹īˆ ī‰ī‹ŽīŠŗī‹Œī‰ŽīŠģī‰īˆ ī‰Šī‰‚ī‹ˆīŠŖī‰‡
    Lcd Time$ : Locate 2 , 1 : Lcd Date$
                                                                    īˆ ī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰īˆ ī‹’ī‰ąī‰‚ī‰ąīˆ ī‹“īŠŧīŠ§īˆ ī‰Ŗī‹ī‰Šī‰‚ī‰ŽīŠģī‰ī‹‹īˆ ī‰ī‹ŽīŠŗī‹Œī‰ŽīŠģī‰īˆ ī‰žī‰ĒīŠ§
   Wait 1                                                                      īˆ  īˆ īˆŽī‹’ī‹ŽīŠģī‰‚ī‰Žī‰Žī‹ī‰ĒīŠ¸īŠģī‰
   Cls
Loop




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

      Exp.16: DAC using Ladder R-2R                īˆ  īˆ ī‹ī‹ˆī‰‰ī‰‚ī‰˛ī‰ŽīŠģī‰īˆ ī‹ī‹€īŠŗī‰ĒīŠģī‰īˆ īŠŊī‹ī‹Œī‰šī‰ŽīŠģī‰īˆ īˆēī‹‘ī‰Ēī‰˛īŠ§īˆ ī‹’ī‰­ī‰Ĩī‰‚ī‰ŽīŠģī‰īˆ ī‹’ī‰‰ī‰Ēī‰–ī‰ŽīŠģī‰

                                                                               īˆ  īˆ īˆēī‹’ī‰‰ī‰Ēī‰–ī‰ŽīŠģī‰īˆ ī‹…īŠŋīˆ ī‹’ī‹ī‰‚īŠŦīŠģī‰
                                      īˆ  īˆ īˆŽī‹ī‹ˆī‰‰ī‰‚ī‰˛ī‰ŽīŠģī‰īˆ ī‹ī‹€īŠŗī‰ĒīŠģī‰īˆ īŠŊī‹ī‹Œī‰šī‰ŽīŠģī‰īˆ ī‰žī‰ī‰ĒīŠĢī‹žīˆ R-2Rīˆ ī‰Šī‰Ĩī‹œīˆ ī‹’īŠ¸ī‰Šī‰ąīˆ ī‹‚ī‰ī‰Ļī‰ĸī‰Žī‰­ī‰
                                                                                īˆ  īˆ īˆēīŠŊī‹Žī‰ĩī‹Œī‰ŽīŠģī‰īˆ īŠĄī‹ąīŠ‹




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

                                                                                             īˆ  īˆ īˆēīŠŊī‹Žī‰ĩī‹Œī‰īˆ ī‰ī‰‚ī‰ŠīŠŧī‹ąī‰ŽīŠŋ
                                                īˆ  īˆ īˆŽīˆ’ī‰‚īŠ¨īŠī‰īˆ īŠŠīŠŋīˆ ī‰Šī‰Ĩī‹œīˆ ī‹’īŠ¸ī‰Šī‰ąīˆ īŠŊī‰ĩī‹ŒīŠģīˆ SW37īˆ ī‰ ī‰‚ī‰ŽīŠ°īŠī‰īˆ īŠĸī‰‚īŠ´ī‹ƒīˆ īŠŠī‹ŽīŠšīˆ īŠļī‹īŠĢī‰‡īˆ ī‰‹īŠ
                                                        īˆŽī‹’ī‹ŽīŠģī‰‚ī‰Žī‰Žī‹ī‰ĒīŠ¸īŠģī‰īˆ ī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰īˆ ī‹’ī‰ąī‰‚ī‰ąīˆ īŠŊī‹ŽīŠŦī‰˛ī‰ŽīŠģīˆ SW2īˆ ī‰ ī‰‚ī‰ŽīŠ°īŠī‰īˆ īŠļī‹īŠĢī‰‡īˆ ī‰‹īŠ
                                                                                              īˆ  īˆ īˆēī‹‘ī‰Šī‰ī‰ĻīŠģī‰īˆ īŠŊī‹€īŠ§īˆ ī‰ ī‰Ēī‰ą
īˆ īŠ˛ī‹Œī‰­ī‹‹īˆ īˆŦī‰Šī‰Ĩī‹œīˆ ī‹’īŠ¸ī‰Šī‰ąīˆ ī‰˜ī‰Ēī‰Ąīˆ ī‹“īŠŧīŠ§īˆ ī‰Ēī‹ˆīŠ¤ī‹īˆ ī‹ī‹ˆī‰‰ī‰‚ī‰˛ī‰īˆ ī‰Ļī‹ˆī‰•īˆ ī‹…īŠ§īˆ īˆ•īŠ¨ī‰īˆ ī‹’ī‹Žī‹€īŠŗī‰Šīˆ ī‹’ī‹€ī‹ŽīŠŗīˆ ī‰Ļī‹ŽīŠģī‹Œī‰Žī‰‰īˆ ī‹‚ī‹ŒīŠ´ī‹īˆ  ī‰—īŠŋī‰‚ī‹ƒī‰Ēī‰‰īˆ ī‹’ī‰‰ī‰‚ī‰ŽīŠ¸ī‰‰īˆ ī‹‚ī‹ŒīŠ´ī‹ƒīˆ īŠ˛ī‹Œī‰­
                                             īˆ  īˆ īˆŽī‹’ī‹ŽīŠģī‰‚ī‰Žī‰Žī‹ī‰ĒīŠ¸īŠģī‰īˆ ī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰īˆ ī‹’ī‰ąī‰‚ī‰ąīˆ ī‹“īŠŧīŠ§īˆ ī‹‰ī‰šī‰ĒīŠ§ī‹‹īˆ ī‰Ļī‹ˆīŠ†ī‰īˆ ī‰ī‰¨ī‹‡īˆ ī‹’ī‹€ī‹ŽīŠŗīˆ ī‰Œī‰‚ī‰ŽīŠīˆ ī‹‚ī‹ŒīŠ´ī‹ƒ
īˆ īˆŦī‹’īŠ¸ī‰Šī‰˛īŠģī‰īˆ  īŠŊī‰Ąī‰ī‰ĻīŠŋīˆ  ī‹…īŠŋīˆ  īŠŊī‰Ąī‰ĻīŠŋīˆ  īŠŊīŠˇīˆ  ī‹“īŠŧīŠ§īˆ  īˆ¨0 or 1īˆŠīˆ  ī‹’ī‹Žī‹€īŠŗī‰Šīˆ  ī‹ī‹ŽīŠŗīˆ  īŠžī‰‚ī‰Ąī‰Ĩī‰‡īˆ  ī‹Œī‹‡īˆ  ī‰Šī‰Ĩī‹œīˆ  ī‹’īŠ¸ī‰Šī‰˛īŠģīˆ  ī‹’ī‹Žī‰­ī‰‚ī‰­ī‹žī‰īˆ  ī‹‘ī‰ĒīŠ¸īŠ°īŠģī‰īˆ  ī‹†ī‰‡
                     īˆ  īˆ īˆŽī‰‚ī‹ˆīŠŧī‰Ąī‰ī‰ĻīŠŋīˆ ī‹“īŠŧīŠ§īˆ ī‹’īŠ´ī‰Šī‹ąīŠī‰īˆ ī‹’ī‹Žī‹€īŠŗī‰ĒīŠģī‰īˆ ī‹ī‹ŽīŠ´īŠģī‰‚ī‰‰īˆ ī‹‘ī‰Ēī‰ąī‰‚ī‰ŠīŠŋīˆ ī‹’īŠŗī‹īŠ§īˆ ī‰‚īˆšīˆ ī‹’ī‹Žī‹ˆī‰‰ī‰‚ī‰˛ī‰īˆ ī‹’ī‹€ī‹ŽīŠŗīˆ ī‹“īŠŧīŠ§īˆ ī‰‚ī‹ˆī‰•ī‰Ēī‰Ąīˆ īŠŸīˆ īŠžī‹Œī‰ļīŠ‡ī‰ī‹‹
īˆ īˆ 0-255īˆ  ī‹…īŠŋīˆ  ī‰ ī‹‹ī‰īˆ–ī‰Žī‰­īˆ  ī‹’īŠ¸ī‰Šī‰˛īŠģī‰īˆ  īŠŊī‰Ąī‰ī‰ĻīŠŋīˆ  ī‹“īŠŧīŠ§īˆ  ī‹’ī‹Žī‹€īŠŗī‰ĒīŠģī‰īˆ  ī‹ī‹ŽīŠ´īŠģī‰īˆ  ī‹†ī‰ˆīŠ¯īˆ  īˆŦ8-bitīˆ  ī‹’īŠŗī‰Ļī‰‰īˆ  ī‰Šī‰Ĩī‹œīˆ  ī‹’īŠ¸ī‰Šī‰ąīˆ  īŠŊī‰•ī‰ƒīˆ  ī‹…īŠŋīˆ  ī‹‚ī‰‚īŠ§īˆ  īŠŊīŠ¸ī‰˛ī‰‰
                             īˆŽ   0-5VDCīˆ ī‹’īŠ¸ī‰Šī‰˛īŠģī‰īˆ ī‰˜ī‰Ēī‰Ąīˆ īŠŸīˆ ī‹ĩī‰‚ī‹Žī‹ąī‰Ąīˆ ī‹ĩī‰‚ī‹Žī‹ˆī‰‰ī‰‚ī‰˛ī‰īˆ ī‹ĩī‰ī‰Ļī‹ˆī‰•īˆ ī‰—ī‰Žī‹„ī‹īˆ ī‹Šī‰Šī‹‹ī‰Ļī‰‰īˆ ī‹ī‰¨īŠģī‰ī‹‹īˆ īˆ¨00000000>>11111111īˆŠ
                                                V OUT = V REF x VAL / 2N
 Digital Input
   0 ~ 255




                                                                                                  Analog Output
                                                                                                     0 ~ 5V



            īˆ  īˆ 
                                                                                                               īˆ  īˆ 
                  īˆ  īˆ īˆēī‹’ī‹ŽīŠģī‰‚ī‰ŽīŠģī‰īˆ ī‹’īŠŗī‹īŠ¨īŠģī‰‚ī‰‰īˆ ī‹‰ī‰‰ī‰‚ī‰Žī‰™īˆ ī‹…īŠ¸īŠ™īˆ īˆ ī‹’ī‰•ī‰Šī‰Ĩīˆ īŠŊīŠˇīˆ ī‹’ī‹€ī‹ŽīŠŗīˆ ī‹†ī‰ˆīŠ¯īˆ ØŒ8-bitīˆ ī‹’īŠŗī‰Ļī‰‰īˆ ī‰Šī‰Ĩī‹œīˆ ī‹’īŠ¸ī‰Šī‰ąīˆ īŠŊī‰•ī‰ƒīˆ ī‹…īŠŋīˆ ī‹‰ī‹ƒī‰ˆīŠ¯īˆ ī‹īŠģī‰‚ī‰ŽīŠģī‰‚ī‰‰ī‹‹
                                         Vstep = VM / 2N = 5 / 255 = 0.019 Volt
īˆ ī‹’ī‰•ī‰Šī‰ĻīŠģī‰īˆ ī‰Ļī‹ˆīŠ€īˆ ī‹ĩī‰‚ī‰‰ī‹‹ī‰Ēī‰ēīŠŋīˆ ī‹’īŠ¸ī‰Šī‰˛īŠģī‰īˆ īŠŊī‰Ąī‰Ĩīˆ ī‹“īŠŧīŠ§īˆ ī‹’ī‹Žī‹€īŠŗī‰ĒīŠģī‰īˆ ī‹’ī‹€ī‹ŽīŠ´īŠģī‰īˆ ī‹…īŠ§īˆ ī‹‘ī‰Šī‰‚ī‰ŠīŠ§īˆ ī‹†ī‹ŒīŠ¸ī‹Žī‰­īˆ ī‹’īŠ¸ī‰Šī‰˛īŠģī‰īˆ ī‰˜ī‰Ēī‰Ąīˆ ī‰Ļī‹ˆī‰•īˆ ī‹†ī‰ˆīŠ¯īˆ ī‹īŠģī‰‚ī‰ŽīŠģī‰‚ī‰‰ī‹‹
                                                                                       īˆ  īˆ īˆŽī‹Šī‹īŠ§ī‰ƒīˆ ī‰Œī‹Œī‰Žīˆī‰īˆ ī‰Ļī‰™ī‰ī‹ŒīŠģī‰
                                                   Vout = Digval x V step
       īˆ  īˆ īˆēīŠŊīŠ¸ī‰˛īŠģī‰‚ī‰‰īˆ ī‰‹īŠīˆ ī‰˜ī‰ĒīŠˆī‰īˆ ī‰Ļī‹ˆī‰•īˆ ī‹†ī‰ˆīŠ¯ 1000 0001=129īˆ ī‹…īŠ¸ī‰ŽīŠģī‹‹īˆ ī‹’īŠ¸ī‰Šī‰˛īŠģī‰īˆ īŠŊī‰Ąī‰Ĩīˆ ī‹“īŠŧīŠ§īˆ ī‹’ī‹Žī‹€īŠŗī‰Šīˆ ī‹’ī‹€ī‹ŽīŠŗīˆ īŠŊī‰•ī‰ƒīˆ ī‹…īŠŋīˆ ī‹īŠģī‰‚ī‰ŽīŠģī‰‚ī‰‰ī‹‹
                                                  129 x 0.019 = 2.451V
 Faculty of Electrical and Electronic Eng.                    103              Automatic Control & Automation Dept.
ī‹‘ī‰ĒīŠŦī‰ļīŠī‰īˆ ī‰ī‰‚ī‹€īŠ¸ī‰šī‰ŽīŠī‰īˆ ī‹’īŠ‰ī‰Ēī‰‰                                                               īˆ  īˆ  ī‹’ī‰ŽīŠŋī‰‚īŠˆī‰īˆ ī‹’ī‰ŽīŠŧīŠ†ī‰

  īˆ īŠŸīˆ ī‰‚ī‹€īŠˇīˆ  ī‹’īŠ¸ī‰Šī‰˛īŠģī‰īˆ ī‰˜ī‰Ēī‰Ąīˆ īŠŸīˆ īŠžī‰ŦīŠ§īˆ ī‹‘ī‰Šī‰ī‰Ĩīˆ ī‹’īŠ¯ī‰‚ī‰šī‰‡īˆ ī‰‹īŠīˆ ī‹‰ī‹ƒī‰ˆīŠ¯īˆ ī‹’ī‹ŽīŠ´ī‹ŽīŠ´ī‰™īˆ ī‰ī‰‚īŠ´ī‹Žī‰Šī‹ąī‰īˆ īŠ•ī‰‡īˆ ī‰Šī‰Ĩī‹œīˆ ī‹’īŠ¸ī‰Šī‰ąīˆ ī‰˜ī‰Ēī‰Ąīˆ īŠŊī‹Žī‰ĩī‹Œī‰īˆ īŠŊī‰•ī‰ƒīˆ ī‹…īŠŋ
                                                                                     īˆ  īˆ īˆēī‹īŠģī‰‚ī‰ŽīŠģī‰īˆ īŠŊīŠ¸ī‰˛īŠģī‰




īˆ  īˆ 
                                                                                                      īˆ  īˆ 
  īˆ ī‹†ī‰ƒīˆ ī‰“ī‹ŽīŠīˆ īˆ¨V2īˆŠīˆ īŠŊī‹€īŠ‡ī‰īˆ īŠŠīŠŋīˆ īŠžī‹Œī‰ĩī‹ŒīŠī‰īˆ ī‰Ļī‹ˆīŠ†ī‰ī‹‹īˆ īˆ¨V1īˆŠīˆ ī‹’ī‰Šī‰˛īŠģī‰īˆ ī‰˜ī‰Ēī‰Ąīˆ īŠŸīˆ ī‰Ļī‹ˆīŠ†ī‰īˆ īŠ”ī‰‰īˆ īŠŊī‰ļīŠ°īŠģī‰īˆ ī‹Œī‹‡īˆ īŠžī‰ŦīŠ¨īŠģī‰īˆ ī‹‘ī‰Šī‰ī‰Ĩīˆ ī‹…īŠŋīˆ ī‹’ī‹ī‰‚īŠŦīŠģī‰īˆ ī‹†ī‰‡
  īˆ ī‹’īŠŧīŠ¸ī‰˛īŠŋīˆ ī‰‚ī‹„ī‹ī‰ĻīŠģīˆ ī‰Ēī‹ˆīŠ¤ī‹Žī‰­īˆ ī‹…īŠ¸īŠģī‹‹īˆ īˆŽī‰‚ī‹ˆīŠŧī‹€īŠ§īˆ ī‹“īŠŧīŠ§īˆ ī‰Ēī‰‘ī‹›ī‹īˆ ī‹œīˆ ī‹īŠˇīˆ ī‹’īŠ¸ī‰Šī‰˛īŠģī‰īˆ ī‹…īŠŋīˆ ī‹†ī‹ŒīŠ¸ī‹īˆ ī‹œī‹‹īˆ īŠžī‰Ģī‰‚īŠ¨īŠģī‰īˆ ī‹…īŠŋīˆ ī‹†ī‹ŒīŠ¸ī‹īˆ ī‰Šī‰‚ī‹Žī‰ŽīŠģī‰īˆ ī‰Šī‰ī‰Ēī‰–ī‰Žī‰­ī‰
                                     īˆ ī‹‘ī‰Šī‰ī‰ĻīŠģī‰īˆ  īŠŸīˆ  īŠžī‰Ģī‰‚īŠ¨īŠˇīˆ  ī‹ī‰ĸī‰ēīŠī‰īˆ  ī‹‚ī‰ī‰Ļī‰ĸī‰Žī‰­ī‰īˆ  ī‹’ī‰–ī‹Žī‰Žī‹ƒīˆ  īˆ¨ī‹’ī‹Žī‹ąīŠˆī‰īˆ  ī‹‚ī‰ĻīŠ§īˆŠīˆ  ī‹’ī‹ŽīŠ´ī‹ŽīŠ´ī‰™
                                                                                             īˆ  īˆ īˆŽī‹’īŠ´ī‰‰ī‰‚ī‰ŽīŠģī‰
                                     īˆ ī‰Ļī‹ˆīŠ†ī‰īˆ  īŠžī‰‚īˆ‘īˆ  ī‹šī‹‹ī‰‚ī‰ŽīŠŋīˆ  ī‹ī‰ĸī‰ēīŠī‰īˆ  ī‹’ī‹ī‰¨īŠŦī‰īˆ  ī‰Ļī‹ˆī‰•īˆ  ī‹†ī‹ŒīŠˇīˆ  īŠžī‰‚ī‰™īˆ  īŠŸ īˆ  īˆ­1
                                     īˆ ī‹†ī‹ŒīŠ¸ī‹īˆ  ī‹…īŠģīˆ  ī‹ī‰ĸī‰ēīŠī‰īˆ  ī‰˜ī‰Ēī‰Ąīˆ  ī‰Ļī‹ˆī‰•īˆ  ī‹†ī‰ˆīŠ¯īˆ  īˆŦī‹‰īŠŧī‰Ąī‰Ĩīˆ  ī‹“īŠŧīŠ§īˆ  ī‹ī‹€īŠ¤īŠ§ī‹žī‰
                                     īˆ īˆŦīˆ¨0-to-VccīˆŠīˆ  ī‹ī‰ĸī‰ēī‹€īŠŧīŠģīˆ  īŠŊī‰Ąī‰ĻīŠģī‰īˆ  ī‰Ļī‹ˆī‰•īˆ  īŠžī‰‚īŠ‰īˆ  īŠŊīŠŋī‰‚īŠˇīˆ  ī‹“īŠŧīŠ§
                                     īˆ  īˆ īˆŽ4.5Vīˆ ī‹īŠģī‰ī‹Œī‰™īˆ ī‹ī‰ƒīˆ īˆ¨Vcc - 0.5VīˆŠīˆ īŠŊī‹ŽīŠŧīŠ´ī‰‰īˆ īŠŊīŠŗī‰ƒīˆ ī‹†ī‹ŒīŠ¸ī‹Žī‰­īˆ ī‰‚īŠ˜ī‰‡ī‹‹
                                     īˆ ī‰Ļī‹ˆī‰•īˆ īŠžī‰‚īŠ‰īˆ īŠŊīŠŋī‰‚īŠˇīˆ ī‹“īŠŧīŠ§īˆ ī‹ī‹ąī‰Ąīˆ īˆ—īŠĢīˆ ī‹ī‰ĸī‰ēīŠī‰īˆ ī‰˜ī‰Ēī‰Ąīˆ ī‹†ī‰ƒīˆ ī‰‚ī‹€īŠˇ īˆ  īˆ­2
                                     īˆ ī‹’ī‹„ī‹ŽīŠ¨īŠŋīˆ  ī‹’ī‰Šī‰ŽīŠ§īˆ  ī‹“ī‰Žī‰™īˆ  ī‹ĩī‰‚ī‹Žī‹ąī‰Ąīˆ  ī‹†ī‹ŒīŠ¸ī‹Žī‰­īˆ  ī‰‚īŠ˜ī‰‡ī‹‹īˆ  īˆŦī‹ī‰ĸī‰ēī‹€īŠŧīŠģīˆ  ī‰˜ī‰ĒīŠˆī‰
                                           īˆŽīˆ¨3.9Vīˆ ī‰ī‰¨ī‹‡īˆ ī‰‚ī‹„īŠģī‰‚ī‰’īŠŋīˆ īŠŸīˆŠīˆ ī‹‰ī‰ŽīŠ°ī‹ƒīˆ ī‹ī‰ĸī‰ēīŠī‰īˆ ī‰ī‰‚īŠ°ī‰ĩī‰ī‹ŒīŠīˆ ī‹ĩī‰‚īŠ¨ī‰Šī‰
                                     īˆ īŠ•ī‰‡īˆ  ī‹ī‰ĸī‰ēī‹€īŠŧīŠģīˆ ī‹’ī‹ī‰¨īŠŦī‰ŽīŠģī‰īˆ ī‰Ļī‹ˆī‰•īˆ ī‹‘ī‰Ĩī‰‚ī‹ī‰Ŧī‰‰īˆ īŠ•ī‹‹ī‹žī‰īˆ ī‹’īŠŧīŠ¸ī‰˛īŠī‰īˆ ī‹…īŠŋīˆ ī‰ˇīŠŧī‰ĸī‰ŽīŠģī‰īˆ ī‹…īŠ¸īŠ™
                                                                                  īˆ  īˆ īˆŽ5Vīˆ ī‹…īŠŋīˆ ī‹ĩī‹œī‰Ļī‰‰īˆ 6.5V
                                     īˆ ī‹’ī‹ī‰ĒīŠ°ī‰ĩīˆ ī‹’ī‹ąīŠ´ī‹ƒīˆ īŠ•ī‰‡īˆ D7īˆ ī‹’ī‹ąīŠ´ī‹„īŠģī‰īˆ īŠŊī‰ĩī‹Œī‰‰īˆ ī‰‚ī‹ˆīŠŧī‰™īˆ ī‹…īŠ¸ī‹€ī‹ŽīŠ¯īˆ ī‹’ī‹Žī‹ƒī‰‚ī‰’īŠģī‰īˆ ī‹’īŠŧīŠ¸ī‰˛īŠī‰īˆ ī‰‚īŠŋī‰ƒ
                                                        īˆ  īˆ īˆŽīŠĄīŠ´īŠ¯ 0 to 2.5V īˆ ī‰˜ī‰ĒīŠˆī‰īˆ īŠžī‰‚īŠ‰īˆ ī‰œī‰Šī‰ļī‹īˆ ī‹īŠģī‰‚ī‰ŽīŠģī‰‚ī‰‰ī‹‹

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




                                                                    5.5V ~ 12V




                    īˆ  īˆ 
                                                                                       īˆ  īˆ īˆēī‹‘ī‰Ļī‹ī‰ĻīŠ†ī‰īˆ ī‰ī‰‚ī‹€ī‹ŽīŠŧīŠ¨ī‰ŽīŠģī‰
          īˆ  īˆ īˆŽī‹’ī‹Žī‰šī‰‚ī‹ī‰ĒīŠģī‰īˆ ī‰‹ī‹ī‰ĒīŠ´ī‰ŽīŠģī‰īˆ ī‰ī‰‚ī‹€ī‹ŽīŠŧīŠ¨ī‰īˆ ī‰ŧīŠ¨ī‰‰īˆ ī‰ĒīŠˇī‰§īˆ ī‰Ļī‹ŽīŠ†ī‰īˆ ī‹…īŠŋīˆ ī‹…īŠ¸īŠģī‹‹īˆ ī‹’ī‰‰ī‰Ēī‰–ī‰ŽīŠģī‰īˆ ī‹Šī‰¨ī‹‡īˆ īŠŸīˆ ī‹‘ī‰Ļī‹ī‰Ļī‰•īˆ ī‰ī‰‚ī‹€ī‹ŽīŠŧīŠ¨ī‰īˆ īŠēī‰‚ī‹„ī‹‡īˆ ī‰¯ī‹ŽīŠģ
                    īˆ  īˆ  ī‹’ī‹ŽīŠ‰īˆ•īŠģī‰īˆ ī‹’ī‹€ī‹ŽīŠŧīŠ¨ī‰ŽīŠģī‰                                 īˆ  īˆ  ī‹’ī‹€ī‹ŽīŠŧīŠ¨ī‰ŽīŠģī‰īˆ ī‰ ī‰Ēī‰ą
                                                            īˆ  īˆ īˆēīŠžī‰‚ī‰’īŠŋīˆ īˆŽī‹’ī‰šī‹Žī‰šī‰ĩīˆ ī‹’ī‹€ī‹ŽīŠŗīˆ ī‰Œī‰ĒīŠŗī‰ƒīˆ īŠ•ī‰‡īˆ ī‹’ī‰‰ī‰ĒīŠ´īŠŋīˆ īˆ¨xīˆŠīˆ ī‹’ī‹€ī‹ŽīŠ´īŠģī‰īˆ īŠĒī‰‚ī‰•ī‰Šī‰‡
Var = Round(x)                                                Round(2.3) = 2 , Round(2.8) = 3
                                                       īˆ  īˆ Round(-2.3)   = -2 , Round(-2.8) = -3
Var = Int(source)              Ex: Int(134.567)=134                         īˆ  īˆ ī‹ī‰Ēī‰ŽīŠˇīˆ ī‰Ĩī‰ĻīŠ¨īŠģīˆ ī‰œī‹Žī‰šī‰ļīŠģī‰īˆ ī‹ī‰ŽīŠ´īŠģī‰īˆ īŠĒī‰‚ī‰•ī‰Šī‰‡
Var = Frac(source) Ex: Frac(134.567)=567                                  īˆ  īˆ īˆ ī‹ī‰Ēī‰ŽīŠˇīˆ ī‰Ĩī‰ĻīŠ¨īŠģīˆ ī‹ī‰Ēī‰ŽīŠ¸īŠģī‰īˆ ī‹ī‰ŽīŠ´īŠģī‰īˆ īŠĒī‰‚ī‰•ī‰Šī‰‡
Var = Fix(x)                   EX: Fix(12.98)=12            īˆ  īˆ īˆŽī‰ĒīŠŦī‰ĩī‹žī‰īˆ ī‹’ī‰šī‹Žī‰šī‰ļīŠģī‰īˆ ī‹’ī‹€ī‹ŽīŠ´īŠģī‰īˆ īŠ•ī‰‡īˆ īˆ¨xīˆŠīˆ ī‹ī‰Ēī‰ŽīŠˇīˆ ī‰Ĩī‰ĻīŠ§īˆ ī‰‹ī‹ī‰ĒīŠ´ī‰
                                                             Var=-1 ī‹†ī‰ˆīŠ¯ x<0īˆ ī‰ī‹ƒī‰‚īŠˇīˆ ī‰ī‰§ī‰‡īˆ īˆŽīˆ¨xīˆŠīˆ ī‰Ĩī‰ĻīŠ¨īŠģī‰īˆ ī‹‘ī‰Šī‰‚ī‰ąī‰‡īˆ ī‰Ļī‹ī‰ĻīŠ„
Var = Sgn(x)
                                                                                     Var=1 ī‹†ī‰ˆīŠ¯ x>0īˆ ī‰ī‹ƒī‰‚īŠˇīˆ ī‰ī‰§ī‰‡


                                                                                     īˆ  īˆ īˆēī‹‘ī‰Šī‰ī‰ĻīŠģī‰īˆ īŠŊī‹ŽīŠŦī‰˛ī‰īˆ ī‰—īŠŋī‰‚ī‹ƒī‰Ēī‰‰
$regfile = "m128def.dat"
$crystal = 8000000                                              īˆ  īˆ īˆŽī‰ī‰‚ī‹ˆī‹Žī‰•ī‹Œī‰ŽīŠģī‰
'-----------------------
Config Lcdpin = Pin , Db4 = Portc.4 , Db5 =
Portc.5 , Db6 = Portc.6 , Db7 = Portc.7 , E īˆ  īˆ īˆŽī‹īŠ¸ī‰šī‰ŽīŠī‰īˆ īŠŠīŠŋīˆ ī‹’īŠŧī‰ĩī‹ŒīŠī‰īˆ ī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰īˆ ī‹’ī‰ąī‰‚ī‰ąīˆ ī‰Œī‰‚ī‹ąīŠŗī‰ƒīˆ īŠąī‹ī‰ĒīŠ¨ī‰
= Portc.2 , Rs = Portc.3
Config Lcd = 20 * 4
                                                        īˆ  īˆ ī‰Šī‰‚ī‹ˆīŠ¤īŠģī‰īˆ ī‹’ī‰ąī‰‚ī‰ąīˆ īŠŊī‹ī‰Ĩī‹ŒīŠŋīˆ īŠąī‹ī‰ĒīŠ¨ī‰
'----------------------
Config Porte = Output                             īˆ  īˆ īˆŽī‰Šī‰Ĩī‹œīˆ ī‹’īŠ¸ī‰Šī‰ąīˆ īŠŠīŠŋīˆ ī‹’īŠģī‹Œī‰ĩī‹ŒīŠī‰īˆ ī‹’ī‰‰ī‰ī‹Œī‰ŠīŠģī‰īˆ īŠąī‹ī‰ĒīŠ¨ī‰
Digital Alias Porte
'-----------------------                                             īˆ  īˆ 
Dim I As Byte , V_out As Single
Const Vlot_step = 5 / 255                               īˆ  īˆ īˆŽī‰ī‹œī‹Œī‰šī‰ŽīŠī‰ī‹‹īˆ ī‰ī‰‰ī‰ī‹Œī‰’īŠģī‰īˆ īŠąī‹ī‰ĒīŠ¨ī‰
'-----------------------
Cls
Do
                                                     īˆ  īˆ īˆēī‰‚ī‹ˆī‹ŽīŠ¯īˆ ī‹ī‰Žī‹īˆ ī‹ī‰Žī‹Žī‹–ī‰ĒīŠģī‰īˆ ī‰—īŠŋī‰‚ī‹ƒīˆ•īŠģī‰īˆ ī‹’īŠ´īŠŧī‰™
   For I = 0 To 255
      Digital = I                             īˆ īˆ¨ī‰Šī‰Ĩī‹œīˆ ī‹’īŠ¸ī‰Šī‰ąīˆ īŠŊī‰Ąī‰ĨīˆŠīˆ ī‹’ī‰‰ī‰ī‹Œī‰ŠīŠģī‰īˆ ī‰˜ī‰Ēī‰Ąīˆ ī‹“īŠŧīŠ§īˆ ī‹’ī‹Žī‹€īŠŗī‰Šīˆ ī‹ī‹ŽīŠŗīˆ ī‰Ļī‹ŽīŠģī‹Œī‰
      V_out = I * Vlot_step
      Lcd "DAC OUT= " ; V_out                īˆ  īˆ īˆŽī‹’īŠ¸ī‰Šī‰˛īŠģī‰īˆ ī‰˜ī‰Ēī‰Ąīˆ ī‹“īŠŧīŠ§īˆ ī‹ī‹ˆī‰‰ī‰‚ī‰˛ī‰īˆ ī‰Ļī‹ˆī‰•īˆ ī‰‚ī‹ˆī‹„īŠ§īˆ ī‰„ī‰˛ī‹„ī‹īˆ īˆžīŠģī‰ī‹‹
      Wait 1 : Cls                           īˆ ī‹’ī‰ąī‰‚ī‰ąīˆ ī‹“īŠŧīŠ§īˆ ī‰‚ī‹ˆī‰šī‰ĒīŠ§ī‹‹īˆ ī‹ī‹ˆī‰‰ī‰‚ī‰˛ī‰ŽīŠģī‰īˆ ī‰˜ī‰ĒīŠˆī‰īˆ ī‰Ļī‹ˆī‰•īˆ ī‹’ī‹€ī‹ŽīŠŗīˆ ī‰Œī‰‚ī‰Žī‰™
   Next I
Loop                                                      īˆ  īˆ īˆŽī‹’ī‹ŽīŠģī‰‚ī‰Žī‰Žī‹ī‰ĒīŠ¸īŠģī‰īˆ ī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰
End

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

      Exp.17: Analog Comparator                                        īˆ  īˆ ī‹ī‹ˆī‰‰ī‰‚ī‰˛ī‰ŽīŠģī‰īˆ ī‹†ī‰Šī‰‚īŠ´īŠī‰īˆ īˆēī‹‘ī‰Ēī‰˛īŠ§īˆ ī‹’īŠ¨ī‰‰ī‰‚ī‰ŽīŠģī‰īˆ ī‹’ī‰‰ī‰Ēī‰–ī‰ŽīŠģī‰

                                                                                           īˆ  īˆ īˆēī‹’ī‰‰ī‰Ēī‰–ī‰ŽīŠģī‰īˆ ī‹…īŠŋīˆ ī‹’ī‹ī‰‚īŠŦīŠģī‰
                                     īˆ  īˆ īˆŽī‹’ī‹Žī‹ˆī‰‰ī‰‚ī‰˛ī‰ŽīŠģī‰īˆ ī‹‘ī‰Šī‰‚ī‰ąī‹ĸī‰īˆ ī‹’ī‹ƒī‰Šī‰‚īŠ´īŠŋīˆ ī‰žī‰ī‰ĒīŠĢī‰ƒīˆ īŠŸīˆ īˆ’ī‰‚īŠ¨ī‹€īŠŧīŠģīˆ ī‹īŠŧī‰Ąī‰ī‰ĻīŠģī‰īˆ ī‹ī‹ˆī‰‰ī‰‚ī‰˛ī‰ŽīŠģī‰īˆ ī‹†ī‰Šī‰‚īŠ´īŠī‰īˆ ī‰Šī‰‚ī‹€ī‰’ī‰Žī‰­ī‰
                                                                                            īˆ  īˆ īˆēīŠŊī‹Žī‰ĩī‹Œī‰ŽīŠģī‰īˆ īŠĄī‹ąīŠ‹




īˆ  īˆ 
                                                                                             īˆ  īˆ īˆēīŠŊī‹Žī‰ĩī‹Œī‰īˆ ī‰ī‰‚ī‰ŠīŠŧī‹ąī‰ŽīŠŋ
                                                                                     īˆ  īˆ īˆŽSW2īˆ ī‰ ī‰‚ī‰ŽīŠ°īŠī‰īˆ īŠļī‹īŠĢī‰‡īˆ ī‰‹īŠ
                          īˆ  īˆ īˆŽī‹ī‹ˆī‰‰ī‰‚ī‰˛ī‰ŽīŠģī‰īˆ ī‹†ī‰Šī‰‚īŠ´īŠī‰īˆ ī‰Œī‰‚ī‹ąīŠŗī‰ƒīˆ īŠŠīŠŋīˆ ī‰‚ī‹ˆīŠŧī‰ĩī‹‹īˆ ī‰ī‹ŽīŠģīˆ JP11, JP12īˆ īˆ¨JumpersīˆŠīˆ īŠŊī‰ĩī‹ŒīŠģī‰īˆ īˆžī‹ąīŠ´ī‹ƒīˆ īŠŠī‰šī‹‹īˆ ī‰‹īŠ
                                                                                              īˆ  īˆ īˆēī‹‘ī‰Šī‰ī‰ĻīŠģī‰īˆ īŠŊī‹€īŠ§īˆ ī‰ ī‰Ēī‰ą
          īˆ  īˆ īˆŽīŠ”ī‰ŽīŠ°īŠŧī‰ŽīŠ‹īˆ īŠ”ī‰Žī‹Žī‹ˆī‰‰ī‰‚ī‰˛ī‰īˆ īŠ”ī‰ī‰Šī‰‚ī‰ąī‰‡īˆ ī‹’ī‹ƒī‰Šī‰‚īŠ´īŠŋīˆ īŠŊī‰•ī‰ƒīˆ ī‹…īŠŋīˆ īˆ’ī‰‚īŠ¨ī‹€īŠŧīŠģīˆ ī‹ī‹ˆī‰‰ī‰‚ī‰˛ī‰ŽīŠģī‰īˆ ī‹†ī‰Šī‰‚īŠ´īŠī‰īˆ īŠŊī‹ŽīŠŦī‰˛ī‰ŽīŠģīˆ ī‰—īŠŋī‰‚ī‹ƒī‰Ēī‰‰īˆ ī‹’ī‰‰ī‰‚ī‰ŽīŠ¸ī‰‰īˆ ī‹‚ī‹ŒīŠ´ī‹ƒīˆ īŠ˛ī‹Œī‰­


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

īˆ ī‹“īŠŧīŠ§īˆ īŠĩī‰Šī‹ąīŠī‰īˆ ī‰Ļī‹ˆīŠ†ī‰īˆ ī‹…īŠŋīˆ īˆ•īŠˇī‰ƒīˆ īˆ¨ī‹†ī‰Šī‰‚īŠ´ī‹€īŠŧīŠģīˆ ī‰‹ī‰•ī‹ŒīŠī‰īˆ īŠŊī‰Ąī‰ĻīŠī‰īˆŠīˆ  ANI0īˆ ī‰‹ī‹ąīŠ´īŠģī‰īˆ ī‹“īŠŧīŠ§īˆ īŠĩī‰Šī‹ąīŠī‰īˆ ī‹ī‹ˆī‰‰ī‰‚ī‰˛ī‰ŽīŠģī‰īˆ ī‰Ļī‹ˆīŠ†ī‰īˆ ī‹†ī‹ŒīŠˇīˆ īŠžī‰‚ī‰™īˆ īŠŸ
īˆ ī‰Ļī‹ˆīŠ†ī‰īˆ ī‹†ī‹ŒīŠˇīˆ īŠžī‰‚ī‰™īˆ īŠŸīˆ ī‰‚īŠŋī‰ƒī‹‹īˆ īˆŦHighīˆ ī‹”ī‹Œī‰Žī‰ŽīŠī‰īˆ īŠŸīˆ ī‰œī‰Šī‰ļī‹īˆ ī‹†ī‰Šī‰‚īŠ´īŠī‰īˆ ī‰˜ī‰Ēī‰Ąīˆ ī‹†ī‰ˆīŠ¯īˆ īˆ¨ī‹†ī‰Šī‰‚īŠ´ī‹€īŠŧīŠģīˆ  ī‰‹īŠģī‰‚ī‰ŽīŠģī‰īˆ īŠŊī‰Ąī‰ĻīŠī‰īˆŠīˆ  īˆ  AIN1īˆ ī‰‹ī‹ąīŠ´īŠģī‰
        īˆ  īˆ īˆŽLowīˆ ī‹”ī‹Œī‰Žī‰ŽīŠī‰īˆ īŠŸīˆ ī‰œī‰Šī‰ļī‹īˆ ī‹†ī‰Šī‰‚īŠ´īŠī‰īˆ ī‰˜ī‰Ēī‰Ąīˆ ī‹†ī‰ˆīŠ¯īˆ AIN0īˆ ī‰‹ī‹ąīŠ´īŠģī‰īˆ ī‹“īŠŧīŠ§īˆ īŠĩī‰Šī‹ąīŠī‰īˆ ī‰Ļī‹ˆīŠ†ī‰īˆ ī‹…īŠŋīˆ īˆ•īŠˇī‰ƒīˆ ANI1īˆ ī‰‹ī‹ąīŠ´īŠģī‰īˆ ī‹“īŠŧīŠ§
īˆ ī‹‹ī‰ƒīˆ īŠŊī‹ŽīŠŦī‰˛ī‰īˆ īŠŊī‰•ī‰ƒīˆ ī‹…īŠŋīˆ ī‹†ī‰ī‰Ŧī‰Ąīˆ īŠŸīˆ īŠŊī‹–ī‰ī‹Œī‰ŽīŠģī‰īˆ ī‹”ī‹Œī‰Žī‰ŽīŠŋīˆ ī‰žī‰‚īŠ°īŠŽī‰īˆ ī‹‹ī‰ƒīˆ  īŠĒī‰‚īŠ°ī‰ī‰Šī‰īˆ ī‰°ī‰‚ī‹ŽīŠŗīˆ ī‰ī‰‚īŠ´ī‹Žī‰Šī‹ąī‰īˆ īŠŸīˆ ī‹†ī‰Šī‰‚īŠ´īŠī‰īˆ ī‰ī‰¨ī‹‡īˆ ī‹‚ī‰ī‰Ļī‰ĸī‰Žī‰­ī‰īˆ ī‹…īŠ¸īŠ™
                                                                                           īˆ  īˆ īˆŽī‹Šī‰‚ī‹ŽīŠī‰īˆ ī‹’ī‰ĸī‰ēīŠŋīˆ īŠ˛ī‰‚īŠ´ī‹ī‰‡
īˆ īŠšīŠŧīŠ™īˆ ī‹ī‹ˆī‰‰ī‰‚ī‰˛ī‰ŽīŠģī‰īˆ ī‹†ī‰Šī‰‚īŠ´īŠī‰īˆ ī‹†ī‰ƒīˆ  ī‰‚ī‹€īŠˇīˆ  1ī‰Ĩī‰ī‰ĻīŠ§/ī‰īŠŗī‹›ī‹€īŠŧīŠģīˆ īŠšī‰ŽīŠī‰īˆ ī‹’ī‰‘ī‰Ĩī‰‚ī‰™īˆ ī‹’īŠ¨ī‰ŋī‰‚īŠ´īŠŋīˆ ī‰ ī‰ĻīŠ´īŠģīˆ ī‹‚ī‰Ļī‰ĸī‰Žī‰Žī‹īˆ ī‹†ī‰ƒīˆ ī‹…īŠ¸īŠ™īˆ ī‹†ī‰Šī‰‚īŠ´īŠī‰īˆ ī‰˜ī‰Ēī‰Ąīˆ ī‹†ī‰‡
           īˆ  īˆ īˆŽī‹’ī‹ƒī‰Šī‰‚īŠ´īŠī‰īˆ ī‹•ī‰‚ī‹„ī‰‘ī‰ƒīˆ ī‹’ī‹ˆī‰ŠīŠ†ī‰īˆ īˆ—īŠŦī‰īˆ ī‹‹ī‰ƒīˆ ī‹’ī‹ąī‰‰ī‰‚īˆšī‰īˆ ī‹‹ī‰ƒīˆ ī‹‘ī‰ĻīŠ§ī‰‚ī‰ļīŠģī‰īˆ ī‹’ī‹ˆī‰ŠīŠ†ī‰īˆ ī‹“īŠŧīŠ§īˆ ī‹†ī‹ŒīŠ¸ī‰ŽīŠģīˆ ī‰‚ī‹‡ī‰Ĩī‰ī‰ĻīŠ§ī‰‡īˆ ī‹…īŠ¸īŠ™īˆ ī‹’ī‰ĩī‰‚ī‰Ąīˆ ī‹’īŠ¨ī‰ŋī‰‚īŠ´īŠŋ
                                                                                                                 īˆ  īˆ 
                                                                                          īˆ  īˆ īˆēī‹‘ī‰Ļī‹ī‰ĻīŠ†ī‰īˆ ī‰ī‰‚ī‹€ī‹ŽīŠŧīŠ¨ī‰ŽīŠģī‰
                           īˆ  īˆ īˆŽī‹’ī‹ŽīŠŧī‰Ąī‰ī‰ĻīŠģī‰īˆ ī‹īŠ´ī‹ŽīŠ´īŠ‡ī‰īˆ ī‹…īŠŋī‰ŦīŠģī‰īˆ ī‹’īŠ§ī‰‚ī‰­īˆ īŠŸīˆ ī‹’īŠŋī‰Ļī‰ĸī‰Žī‰ŽīŠī‰īˆ ī‹‘ī‰Ļī‹ī‰ĻīŠ†ī‰īˆ ī‰ī‰‚ī‹€ī‹ŽīŠŧīŠ¨ī‰ŽīŠģī‰īˆ ī‰œī‰šī‹Œī‹īˆ ī‹īŠģī‰‚ī‰ŽīŠģī‰īˆ īŠžī‹‹ī‰ĻīŠ†ī‰
                    īˆ  īˆ  ī‹’ī‹ŽīŠ‰īˆ•īŠģī‰īˆ ī‹’ī‹€ī‹ŽīŠŧīŠ¨ī‰ŽīŠģī‰                                    īˆ  īˆ  ī‹’ī‹€ī‹ŽīŠŧīŠ¨ī‰ŽīŠģī‰īˆ ī‰ ī‰Ēī‰ą
                                                       īˆ ī‰Œī‰‚ī‹ąīŠŗī‰ƒīˆ ī‹…īŠ§īˆ  ī‹ī‹ˆī‰‰ī‰‚ī‰˛ī‰ŽīŠģī‰īˆ  ī‹†ī‰Šī‰‚īŠ´īŠī‰īˆ  īŠŊī‰ļīŠ¯īˆ  |īˆ  īŠŊī‰ĩī‹‹īˆ īˆēīˆ¨Aci=On|offīˆŠ
                                                                                                     īˆ  īˆ īˆŽīˆ’ī‰‚īŠ¨īŠī‰īˆ ī‹‘ī‰¨īŠ¯ī‰‚ī‹ƒ
                                                       īˆ īŠĄīŠ˜īˆ  īŠŸīˆ  1ī‰īŠŗī‹›īŠī‰īˆ  ī‹†ī‰ˆīŠ¯īˆ  īˆĸīˆĸīˆ  īŠŊī‰•ī‰ƒīˆ  ī‹…īŠŋīˆ  īˆēīˆ¨Compare=On|offīˆŠ
                                                                        īˆ  īˆ īˆŽī‹ī‹ˆī‰‰ī‰‚ī‰˛ī‰ŽīŠģī‰īˆ ī‹†ī‰Šī‰‚īŠ´īŠī‰īˆ ī‰ ī‰ĻīŠ´ī‰‰īˆ ī‹‚ī‹ŒīŠ´ī‹Žī‰­īˆ īŠšī‰ŽīŠī‰īˆ ī‹’ī‰‘ī‰Ĩī‰‚ī‰™
                                                     īˆ  īˆ īˆēī‹†ī‰Šī‰‚īŠ´īŠī‰īˆ ī‹’īŠ¨ī‰ŋī‰‚īŠ´īŠŋīˆ ī‰‚ī‹‡ī‰Ļī‹„īŠ§īˆ īŠŊīŠ¨īŠ°ī‰Žī‰īˆ ī‰ī‹œī‰‚ī‰™īˆ ī‰”ī‹ī‰‘īˆ ī‰Ļī‰•ī‹Œī‹īˆ īˆēīˆ¨TriggerīˆŠ
Config Aci= On|off ,
Compare= On|off ,                                      īˆ ī‹’īŠ¨ī‰ŋī‰‚īŠ´īŠŋīˆ  ī‰”ī‰ĻīŠ„īˆ  īŠ˛ī‹Œī‰­ (Ain0 > Ain1) :Rising
Trigger = TOGGLE|RISING|FALLING                        īˆ ī‹“īŠŧīŠ§īˆ ī‰Ļī‹ˆīŠ†ī‰īˆ ī‹…īŠŋīˆ īˆ•īŠˇī‰ƒīˆ īˆĸAin0īˆĸīˆ ī‰‹ī‹ąīŠ´īŠģī‰īˆ ī‹“īŠŧīŠ§īˆ ī‰Ļī‹ˆīŠ†ī‰īˆ ī‰œī‰Šī‰ļī‹īˆ ī‰‚īŠŋī‰Ļī‹„īŠ§
                                                                                                    īˆ īˆŽīˆĸAin1īˆĸīˆ ī‰‹ī‹ąīŠ´īŠģī‰
                                                             īˆ ī‹’īŠ¨ī‰ŋī‰‚īŠ´īŠŋīˆ ī‰”ī‰ĻīŠ„īˆ īŠ˛ī‹Œī‰­ (Ain0 < Ain1) :Falling
                                                        īˆ ī‹“īŠŧīŠ§īˆ ī‰Ļī‹ˆīŠ†ī‰īˆ ī‹…īŠŋīˆ ī‰ĒīŠŦī‰ĩī‰ƒīˆ īˆĸAin0īˆĸīˆ ī‰‹ī‹ąīŠ´īŠģī‰īˆ ī‹“īŠŧīŠ§īˆ ī‰Ļī‹ˆīŠ†ī‰īˆ ī‰œī‰Šī‰ļī‹īˆ ī‰‚īŠŋī‰Ļī‹„īŠ§
                                                                                                     īˆŽīˆĸAin1īˆĸīˆ ī‰‹ī‹ąīŠ´īŠģī‰
                                                      īˆ  īˆ (Ain0 > Ain1 and Ain0 < Ain1) :Toggle
Enable Aci                                                               īˆ  īˆ īˆŽī‹ī‹ˆī‰‰ī‰‚ī‰˛ī‰ŽīŠģī‰īˆ ī‹†ī‰Šī‰‚īŠ´īŠī‰īˆ ī‹’īŠ¨ī‰ŋī‰‚īŠ´īŠŋīˆ īŠŊī‹ŽīŠ¨īŠ°ī‰
                                                       īˆ ī‰—īŠŋī‰‚ī‹ƒī‰Ēī‰‰īˆ  īŠ•ī‰‡īˆ  ī‰ŦīŠ°īŠŗī‰‡īˆ  ī‹ī‹ˆī‰‰ī‰‚ī‰˛ī‰ŽīŠģī‰īˆ  ī‹†ī‰Šī‰‚īŠ´īŠī‰īˆ  ī‹’īŠ¨ī‰ŋī‰‚īŠ´īŠŋīˆ  ī‰īŠŧī‰ļī‰™īˆ  īŠžī‰‚ī‰™īˆ  īŠŸ
On Aci label
                                                                           īˆ  īˆ īˆŽīˆĸlabelīˆĸīˆ ī‹’ī‰ŽīŠ¯ī‹īŠģī‰īˆ ī‹…īŠ§īˆ ī‰Ĩī‹Œī‰•ī‹ŒīŠī‰īˆ ī‹’īŠ¨ī‰ŋī‰‚īŠ´īŠī‰
Start Ac                                                                         īˆ  īˆ īˆŽī‹‰īŠŧī‹€īŠ§īˆ ī‰ƒī‰Ļī‰‰ī‹‹īˆ ī‹ī‹ˆī‰‰ī‰‚ī‰˛ī‰ŽīŠģī‰īˆ ī‹†ī‰Šī‰‚īŠ´īŠī‰īˆ ī‹’ī‹ī‰¨īŠŦī‰
Stop Ac                                                                 īˆ  īˆ īˆŽī‹’ī‹ī‰¨īŠŦī‰ŽīŠģī‰īˆ ī‹…īŠ§īˆ ī‹‰īŠŧī‰ļīŠ¯ī‹‹īˆ ī‹ī‹ˆī‰‰ī‰‚ī‰˛ī‰ŽīŠģī‰īˆ ī‹†ī‰Šī‰‚īŠ´īŠī‰īˆ īŠ˛ī‰‚īŠ´ī‹ī‰‡
                                                       īˆ ī‹ī‰ƒīˆ  ī‹‚ī‰ī‰Ļī‰ĸī‰Žī‰­ī‰īˆ  ī‰Ļī‹„īŠ§īˆ  ī‹‰ī‹„īŠŋīˆ  ī‰Ļī‰‰ī‹œīˆ  ī‹ī‰¨īŠģī‰īˆ  ī‹‚ī‰‚īŠ¨īŠģī‰īˆ  ī‰ī‰‚īŠ¨ī‰ŋī‰‚īŠ´īŠī‰īˆ  ī‹īŠŧīŠ§īˆ  īŠŊī‹ŽīŠ¨īŠ°ī‰
Enable Interrupts
                                                                                     īˆ  īˆ īˆŽīˆ’ī‰‚īŠ¨īŠī‰īˆ īŠŸīˆ ī‰Ēī‰ļī‹„īŠ§īˆ ī‹ī‹žīˆ ī‹’īŠ¨ī‰ŋī‰‚īŠ´īŠŋ
                                                       īˆ īˆ—ī‰Ąī‰„ī‰īˆ ī‹ī‹‡ī‹‹īˆ īˆĸAssemblyīˆĸīˆ īŠŠī‹Žī‹€ī‰–ī‰ŽīŠģī‰īˆ ī‹’īŠŦīŠģīˆ ī‰ī‰‚ī‹€ī‹ŽīŠŧīŠ¨ī‰īˆ ī‹…īŠŋīˆ ī‹’ī‹€ī‹ŽīŠŧīŠ¨ī‰ŽīŠģī‰īˆ ī‹Šī‰¨ī‹‡īˆ 
nop
                                                                                      īˆ  īˆ īˆŽī‹‘ī‰Ļī‰™ī‰ī‹‹īˆ ī‹’īŠģī‰…īˆ ī‹‘ī‰Šī‹‹ī‰Ĩīˆ ī‰Šī‰ī‰ĻīŠ´īŠ–īˆ īˆŸīŠŋī‰Ģ



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

                                                                          īˆ  īˆ īˆēī‹‘ī‰Šī‰ī‰ĻīŠģī‰īˆ īŠŊī‹ŽīŠŦī‰˛ī‰īˆ ī‰—īŠŋī‰‚ī‹ƒī‰Ēī‰‰
$regfile = "m128def.dat"
$crystal = 8000000                                          īˆ  īˆ īˆŽī‰ī‰‚ī‹ˆī‹Žī‰•ī‹Œī‰ŽīŠģī‰
'-----------------------
Config Lcdpin = Pin , Db4 = Portc.4 , Db5 =
Portc.5 , Db6 = Portc.6 , Db7 = Portc.7 ,   īˆ  īˆ īˆŽī‹īŠ¸ī‰šī‰ŽīŠī‰īˆ īŠŠīŠŋīˆ ī‹’īŠŧī‰ĩī‹ŒīŠī‰īˆ ī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰īˆ ī‹’ī‰ąī‰‚ī‰ąīˆ ī‰Œī‰‚ī‹ąīŠŗī‰ƒīˆ īŠąī‹ī‰ĒīŠ¨ī‰
E = Portc.2 , Rs = Portc.3
Config Lcd = 20 * 4
                                                     īˆ  īˆ ī‰Šī‰‚ī‹ˆīŠ¤īŠģī‰īˆ ī‹’ī‰ąī‰‚ī‰ąīˆ īŠŊī‹ī‰Ĩī‹ŒīŠŋīˆ īŠąī‹ī‰ĒīŠ¨ī‰

Config Aci = On , Compare = Off , Trigger =         īˆ ī‰Ļī‹ˆīŠ†ī‰īˆ īˆ—īŠŦī‰īˆ ī‹…īŠ§īˆ ī‰ ī‰ĻīŠ´ī‹īˆ ī‰“ī‹ŽīŠīˆ ī‹ī‹ˆī‰‰ī‰‚ī‰˛ī‰ŽīŠģī‰īˆ ī‹†ī‰Šī‰‚īŠ´īŠī‰īˆ ī‰Ĩī‰ī‰ĻīŠ§ī‰‡
Rising
On Aci Isr_aci                                                    īˆ  īˆ īˆŽī‹‰ī‹ŽīŠŧī‰Ąī‰ĻīŠŋīˆ ī‹“īŠŧīŠ§
Enable Aci                                          īˆ īŠžī‹Œī‰ļī‰™īˆ ī‰Ļī‹„īŠ§īˆ ī‹†ī‰Šī‰‚īŠ´ī‹€īŠŧīŠģīˆ ī‹’īŠ¨ī‰ŋī‰‚īŠ´īŠī‰īˆ ī‹’īŠŋī‰Ļī‰Ąīˆ ī‰—īŠŋī‰‚ī‹ƒī‰Ēī‰‰īˆ īŠ•ī‰‡īˆ ī‰ŦīŠ°īŠ´īŠģī‰
Start Ac
Enable Interrupts                                                   īˆ  īˆ īˆŽī‹’īŠ¨ī‰ŋī‰‚īŠ´īŠī‰
'-----------------------                                      īˆ  īˆ ī‹ī‹ˆī‰‰ī‰‚ī‰˛ī‰ŽīŠģī‰īˆ ī‹†ī‰Šī‰‚īŠ´īŠī‰īˆ īŠŊī‹ŽīŠŦī‰˛ī‰
Dim I As Byte
'-----------------------
Cls                                                   īˆ ī‹…īŠ¸īŠ™īˆ ī‹’īŠĢī‰Šī‰‚īŠ¯īˆ ī‹’īŠ´īŠŧī‰™īˆ ī‹ī‹‡ī‹‹īˆ ī‹ī‰Žī‹Žī‹–ī‰ĒīŠģī‰īˆ ī‰—īŠŋī‰‚ī‹ƒīˆ•īŠģī‰īˆ ī‹’īŠ´īŠŧī‰™
Do
   nop                                                       īˆ  īˆ īˆŽī‰Œī‹ŒīŠĢī‰ĒīŠŋīˆ īŠ”ī‰ī‹‹ī‰Šīˆ ī‹ī‰ƒīˆ ī‹’ī‰‰ī‰‚ī‰ŽīŠˇ
Loop                                                                    īˆ  īˆ 
End
'-----------------------

Isr_aci:                                               īˆ  īˆ ī‹ī‹ˆī‰‰ī‰‚ī‰˛ī‰ŽīŠģī‰īˆ ī‹†ī‰Šī‰‚īŠ´īŠī‰īˆ ī‹’īŠ¨ī‰ŋī‰‚īŠ´īŠŋīˆ ī‹’īŠŋī‰Ļī‰Ąīˆ ī‰—īŠŋī‰‚ī‹ƒī‰Ēī‰‰
   Cls
   I = I + 1                                        īˆ ī‹’ī‰ąī‰‚ī‰ąīˆ ī‹“īŠŧīŠ§īˆ ī‰‚ī‹ˆī‰šī‰ĒīŠ¨ī‹ī‹‹īˆ ī‹ī‹ˆī‰‰ī‰‚ī‰˛ī‰ŽīŠģī‰īˆ ī‹†ī‰Šī‰‚īŠ´īŠī‰īˆ ī‰ī‰‚īŠ¨ī‰ŋī‰‚īŠ´īŠŋīˆ ī‰ĻīŠ¨ī‹
   Lcd "change: " ; I                                                īˆ  īˆ ī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰
   Waitms 100
Return
                                          īˆ  īˆ 

                                          īˆ  īˆ 




                               īˆ  īˆ 




ī‹’ī‰ŽīŠ—ī‹žī‰ī‹‹īˆ ī‹īŠģī‹ ī‰īˆ ī‹īŠ¸ī‰šī‰ŽīŠģī‰īˆ ī‹’ī‰­ī‰Ļī‹„ī‹‡īˆ ī‹ī‰ŽīŠŗ               108                       ī‹’ī‹Žī‹ƒī‹‹īˆ–īŠ¸īŠģī‹ĸī‰ī‹‹īˆ ī‹’ī‹Žī‹–ī‰‚ī‰‰ī‰Ēī‹ˆīŠ¸īŠģī‰īˆ ī‹’ī‰­ī‰Ļī‹„īˆšī‰īˆ ī‹’ī‹ŽīŠŧīŠˇ

More Related Content

Viewers also liked

Control in Electric Vechicle Transportation Systems
Control in Electric Vechicle Transportation SystemsControl in Electric Vechicle Transportation Systems
Control in Electric Vechicle Transportation SystemsKamel Alhomsi
 
Mechatronics Programs
Mechatronics  ProgramsMechatronics  Programs
Mechatronics ProgramsEmad Ezzat
 
Decision support systems (ch4)
Decision support systems (ch4)Decision support systems (ch4)
Decision support systems (ch4)DrSamahAhmed
 
Decision support systems (ch1)
Decision support systems (ch1)Decision support systems (ch1)
Decision support systems (ch1)DrSamahAhmed
 
Ø´ØąØ­ Protecting stp topology
Ø´ØąØ­ Protecting stp topologyØ´ØąØ­ Protecting stp topology
Ø´ØąØ­ Protecting stp topologyAli Elsayed Saleh
 
Ccnp m
Ccnp mCcnp m
Ccnp mmohamdy11
 
Ø´Ų‡Ø§Ø¯ØŠ اŲ„ CCNP
Ø´Ų‡Ø§Ø¯ØŠ اŲ„ CCNPØ´Ų‡Ø§Ø¯ØŠ اŲ„ CCNP
Ø´Ų‡Ø§Ø¯ØŠ اŲ„ CCNPrayan7312
 
Aaa security
Aaa securityAaa security
Aaa securityAbubaker1000
 
Cisco certs guide - iTawy
Cisco certs guide - iTawyCisco certs guide - iTawy
Cisco certs guide - iTawyiTawy Community
 
Nature of Electricity
Nature of Electricity Nature of Electricity
Nature of Electricity Aalwan Aziz
 
ØŦŲˆØ¯ØŠ اŲ„Ų‚Ø¯ØąØŠ Power quality
ØŦŲˆØ¯ØŠ اŲ„Ų‚Ø¯ØąØŠ Power qualityØŦŲˆØ¯ØŠ اŲ„Ų‚Ø¯ØąØŠ Power quality
ØŦŲˆØ¯ØŠ اŲ„Ų‚Ø¯ØąØŠ Power qualityDr. Munthear Alqaderi
 
GIS: Geographic Information Systems
GIS: Geographic Information SystemsGIS: Geographic Information Systems
GIS: Geographic Information Systemsaalaa gaffar
 
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 - Lecture6
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture6Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture6
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture6AL-AWAIL for Electronic Engineering
 
Embedded System Microcontroller Interactive Course using BASCOM-AVR -Lecture7
Embedded System Microcontroller Interactive Course using BASCOM-AVR -Lecture7Embedded System Microcontroller Interactive Course using BASCOM-AVR -Lecture7
Embedded System Microcontroller Interactive Course using BASCOM-AVR -Lecture7AL-AWAIL for Electronic Engineering
 
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture9
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture9Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture9
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture9AL-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
 
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture11
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture11Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture11
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture11AL-AWAIL for Electronic Engineering
 

Viewers also liked (20)

Control in Electric Vechicle Transportation Systems
Control in Electric Vechicle Transportation SystemsControl in Electric Vechicle Transportation Systems
Control in Electric Vechicle Transportation Systems
 
Mechatronics Programs
Mechatronics  ProgramsMechatronics  Programs
Mechatronics Programs
 
Decision support systems (ch4)
Decision support systems (ch4)Decision support systems (ch4)
Decision support systems (ch4)
 
Decision support systems (ch1)
Decision support systems (ch1)Decision support systems (ch1)
Decision support systems (ch1)
 
Ø´ØąØ­ Protecting stp topology
Ø´ØąØ­ Protecting stp topologyØ´ØąØ­ Protecting stp topology
Ø´ØąØ­ Protecting stp topology
 
Ccnp m
Ccnp mCcnp m
Ccnp m
 
Ø´Ų‡Ø§Ø¯ØŠ اŲ„ CCNP
Ø´Ų‡Ø§Ø¯ØŠ اŲ„ CCNPØ´Ų‡Ø§Ø¯ØŠ اŲ„ CCNP
Ø´Ų‡Ø§Ø¯ØŠ اŲ„ CCNP
 
1
11
1
 
Aaa security
Aaa securityAaa security
Aaa security
 
Cisco certs guide - iTawy
Cisco certs guide - iTawyCisco certs guide - iTawy
Cisco certs guide - iTawy
 
Nature of Electricity
Nature of Electricity Nature of Electricity
Nature of Electricity
 
ØŦŲˆØ¯ØŠ اŲ„Ų‚Ø¯ØąØŠ Power quality
ØŦŲˆØ¯ØŠ اŲ„Ų‚Ø¯ØąØŠ Power qualityØŦŲˆØ¯ØŠ اŲ„Ų‚Ø¯ØąØŠ Power quality
ØŦŲˆØ¯ØŠ اŲ„Ų‚Ø¯ØąØŠ Power quality
 
GIS: Geographic Information Systems
GIS: Geographic Information SystemsGIS: Geographic Information Systems
GIS: Geographic Information Systems
 
AVR PPT
AVR PPTAVR PPT
AVR PPT
 
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 - Lecture6
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture6Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture6
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture6
 
Embedded System Microcontroller Interactive Course using BASCOM-AVR -Lecture7
Embedded System Microcontroller Interactive Course using BASCOM-AVR -Lecture7Embedded System Microcontroller Interactive Course using BASCOM-AVR -Lecture7
Embedded System Microcontroller Interactive Course using BASCOM-AVR -Lecture7
 
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture9
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture9Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture9
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture9
 
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
 
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture11
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture11Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture11
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture11
 

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

Decoder for digital electronics
Decoder for digital electronicsDecoder for digital electronics
Decoder for digital electronicsIIT, KANPUR INDIA
 
Decoder for digital electronics
Decoder for digital electronicsDecoder for digital electronics
Decoder for digital electronicsKamil Hussain
 
343logic-design-lab-manual-10 esl38-3rd-sem-2011
343logic-design-lab-manual-10 esl38-3rd-sem-2011343logic-design-lab-manual-10 esl38-3rd-sem-2011
343logic-design-lab-manual-10 esl38-3rd-sem-2011e11ie
 
Senior Project Presentation
Senior Project PresentationSenior Project Presentation
Senior Project PresentationTim Heath
 
Assessment questions probability
Assessment questions  probabilityAssessment questions  probability
Assessment questions probabilityErik Tjersland
 
Pma individual assignment ii
Pma  individual assignment iiPma  individual assignment ii
Pma individual assignment iichandraswami
 
86254 162058-ee2255-digital-logic-circuits
86254 162058-ee2255-digital-logic-circuits86254 162058-ee2255-digital-logic-circuits
86254 162058-ee2255-digital-logic-circuitsLekashri Subramanian
 

Similar to Embedded System Microcontroller Interactive Course using BASCOM-AVR -Lecture5 (8)

Decoder for digital electronics
Decoder for digital electronicsDecoder for digital electronics
Decoder for digital electronics
 
Decoder for digital electronics
Decoder for digital electronicsDecoder for digital electronics
Decoder for digital electronics
 
343logic-design-lab-manual-10 esl38-3rd-sem-2011
343logic-design-lab-manual-10 esl38-3rd-sem-2011343logic-design-lab-manual-10 esl38-3rd-sem-2011
343logic-design-lab-manual-10 esl38-3rd-sem-2011
 
Senior Project Presentation
Senior Project PresentationSenior Project Presentation
Senior Project Presentation
 
Assessment questions probability
Assessment questions  probabilityAssessment questions  probability
Assessment questions probability
 
00857a
00857a00857a
00857a
 
Pma individual assignment ii
Pma  individual assignment iiPma  individual assignment ii
Pma individual assignment ii
 
86254 162058-ee2255-digital-logic-circuits
86254 162058-ee2255-digital-logic-circuits86254 162058-ee2255-digital-logic-circuits
86254 162058-ee2255-digital-logic-circuits
 

Recently uploaded

ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 

Recently uploaded (20)

ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 

Embedded System Microcontroller Interactive Course using BASCOM-AVR -Lecture5

  • 1. ī„ ī„  ī„  ī„ ī†Šī…šī…°ī…Ĩī…Ŋī…ģī…ī„ ī…Œī…‚ī…Ŋī…šī…’ī…‹ī…Ŋī…ģī…ī„ ī†Ēī…ī…Ŋī…šī…‰ â€ĢīēīģŸīē˜īē īēŽīē­īē īēīģŸīģŒīģ¤īģ īģ´īē”â€Ŧ ī„  ī„ ī†Ēī…Ąī…Ŋī…‚ī…•ī…ģī…ī„ ī†Ēī…Ąī…ģī…ī…ģī… ī„ ī„  ī„ ī„  Programming Embedded Systems Microcontroller You Can Practice Microcontroller Programming Easily Now! WALID BALID, Tuesday, December 15, 2009
  • 2. ī‹‘ī‰ĒīŠŦī‰ļīŠī‰īˆ ī‰ī‰‚ī‹€īŠ¸ī‰šī‰ŽīŠī‰īˆ ī‹’īŠ‰ī‰Ēī‰‰ īˆ  īˆ  ī‹’ī‰ŽīŠŋī‰‚īŠˆī‰īˆ ī‹’ī‰ŽīŠŧīŠ†ī‰ Exp.14: 7-Segment Single Display īˆ  īˆ īˆ īŠŠī‹ąīŠŗīˆ īŠŠī‰Šī‰ŽīŠģī‰īˆ ī‰ī‰ī‰§īˆ ī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰īˆ ī‰ī‰‚ī‰™ī‹ŒīŠģīˆ īˆēī‹‘ī‰Ēī‰˛īŠ§īˆ ī‹’īŠ¨ī‰‰ī‰ī‰ĒīŠģī‰īˆ ī‹’ī‰‰ī‰Ēī‰–ī‰ŽīŠģī‰ īˆ  īˆ īˆēī‹’ī‰‰ī‰Ēī‰–ī‰ŽīŠģī‰īˆ ī‹…īŠŋīˆ ī‹’ī‹ī‰‚īŠŦīŠģī‰ īˆ  īˆ  īˆŽīˆ¨7-SegmentīˆŠīˆ ī‹’ī‹ŽīŠ§ī‰‚ī‰Šī‰­īˆ ī‰Šī‰‚ī‹ˆīŠŖī‰‡īˆ ī‹’ī‰™ī‹ŒīŠģīˆ ī‹’īŠ‰ī‰Ēī‰‰ī‹‹īˆ īŠŊī‹Žī‰ĩī‹Œī‰ īˆ  īˆ īˆēīŠŊī‹Žī‰ĩī‹Œī‰ŽīŠģī‰īˆ īŠĄī‹ąīŠ‹ īˆ  īˆ  īˆ  īˆ īˆēī‹‘ī‰Šī‰ī‰ĻīŠģī‰īˆ īŠŊī‹€īŠ§īˆ ī‰ ī‰Ēī‰ą īˆ  īˆ īˆēīŠŊī‰™ī‰ī‰ĒīŠŋīˆ ī‰”ī‹ī‰‘īˆ ī‹“īŠŧīŠ§īˆ ī‹’ī‹ŽīŠ§ī‰‚ī‰Šī‰ŽīŠģī‰īˆ ī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰īˆ ī‰ī‰‚ī‰™ī‹ŒīŠŧīŠģīˆ īŠŊī‹ŽīŠŦī‰˛ī‰ŽīŠģī‰īˆ ī‰—īŠŋī‰‚ī‹ƒī‰Ēī‰‰īˆ ī‹’ī‰‰ī‰‚ī‰ŽīŠ¸ī‰‰īˆ ī‹‚ī‹ŒīŠ´ī‹ƒīˆ īŠ˛ī‹Œī‰­ īˆŽ0 – 9īˆ ī‹ī‰Ēī‰˛īŠ§īˆ ī‰Ĩī‰ī‰ĻīŠ¨īŠˇīˆ ī‹’ī‹ī‰Ĩī‰ĒīŠ¯īˆ ī‰Šī‰‚ī‹ˆīŠŖī‰‡īˆ ī‹’ī‰™ī‹ŒīŠģīˆ īŠŊī‹ŽīŠŦī‰˛ī‰īˆ  īˆ­1 īˆŽ0 – 99īˆ ī‹ī‰Ēī‰˛īŠ§īˆ ī‰Ĩī‰ī‰ĻīŠ¨īŠˇīˆ ī‹’ī‹Žī‹–ī‰‚ī‹„ī‰‘īˆ ī‰Šī‰‚ī‹ˆīŠŖī‰‡īˆ ī‹’ī‰™ī‹ŒīŠģīˆ īŠŊī‹ŽīŠŦī‰˛ī‰īˆ  īˆ­2 īˆŽ0 – 9999īˆ ī‹ī‰Ēī‰˛īŠ§īˆ ī‰Ĩī‰ī‰ĻīŠ¨īŠˇīˆ ī‹’ī‹ŽīŠ§ī‰‚ī‰‰ī‰Šīˆ ī‰Šī‰‚ī‹ˆīŠŖī‰‡īˆ ī‹’ī‰™ī‹ŒīŠģīˆ īŠŊī‹ŽīŠŦī‰˛ī‰īˆ  īˆ­3 īˆ īˆ—īŠ°ī‰˛ī‰īˆ ī‹’ī‹€ī‹ŽīŠ´ī‰‰īˆ ī‹‘ī‰Ēī‰ąī‰‚ī‰ŠīŠŋīˆ īŠĩīŠŧīŠ¨ī‰Žī‹īˆ īˆŦī‹’ī‰™ī‹ŒīŠŧīŠģī‰īˆ ī‹“īŠŧīŠ§īˆ ī‹‚ī‰‚īŠŗī‰Šī‹žī‰īˆ ī‰Šī‰‚ī‹ˆīŠŖī‰‡īˆ īŠšīŠģī‰§īˆ īŠŸīˆ ī‰‚īŠ–īˆ īŠŠī‹ąīŠŗīˆ īŠŠī‰Šī‰ŽīŠģī‰īˆ ī‰ī‰ī‰§īˆ ī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰īˆ ī‹’ī‰™ī‹ŒīŠģīˆ īŠŊī‹ŽīŠŦī‰˛ī‰īˆ ī‹’ī‹ŽīŠŧī‹€īŠ§īˆ ī‹†ī‰‡ īˆ ī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰īˆ ī‹’ī‰™ī‹ŒīŠģīˆ ī‹’ī‹Žī‹„ī‰‰īˆ ī‹’īŠ¯ī‰ĒīŠ¨īŠŋīˆ ī‰‹īŠīˆ ī‹‰ī‹ƒī‰ˆīŠ¯īˆ ī‹īŠŗī‰Šī‹žī‰īˆ ī‹…īŠŋīˆ ī‹īŠŗī‰Šīˆ īŠŊīŠˇīˆ īˆ—īŠ°ī‰˛ī‰īˆ ī‹’īŠ¯ī‰ĒīŠ¨īŠŋīˆ īŠŊī‰•ī‰ƒīˆ ī‹…īŠŋī‹‹īˆ īˆŦī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰īˆ ī‹’ī‰™ī‹ŒīŠģīˆ ī‹īŠŗī‰Šī‰ƒīˆ ī‹…īŠŋīˆ ī‹īŠŗī‰Šīˆ īŠŊīŠˇ īˆ  īˆ īˆŽīŠŠī‹ąīŠŗīˆ īŠŠī‰Šī‰ŽīŠģī‰īˆ ī‰ī‰ī‰§ īˆ  īˆ īˆŽīŠŠī‹ąīŠŗīˆ īŠŠī‰Šī‰ŽīŠģī‰īˆ ī‰ī‰ī‰§īˆ ī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰īˆ īˆ ī‰ī‰‚ī‰™ī‹ŒīŠŧīŠģīˆ ī‹īŠŧī‰Ąī‰ī‰ĻīŠģī‰īˆ īŠĄī‹ąī‰ĸīŠī‰īˆ īŠ”ī‰Šī‹īˆ ī‹īŠģī‰‚ī‰ŽīŠģī‰īˆ īŠŊīŠ¸ī‰˛īŠģī‰ ī‹’ī‰ŽīŠ—ī‹žī‰ī‹‹īˆ ī‹īŠģī‹ ī‰īˆ ī‹īŠ¸ī‰šī‰ŽīŠģī‰īˆ ī‹’ī‰­ī‰Ļī‹„ī‹‡īˆ ī‹ī‰ŽīŠŗ 92 ī‹’ī‹Žī‹ƒī‹‹īˆ–īŠ¸īŠģī‹ĸī‰ī‹‹īˆ ī‹’ī‹Žī‹–ī‰‚ī‰‰ī‰Ēī‹ˆīŠ¸īŠģī‰īˆ ī‹’ī‰­ī‰Ļī‹„īˆšī‰īˆ ī‹’ī‹ŽīŠŧīŠˇ
  • 3. Practical Class 5 Programming Microcontrollers īˆ īˆŦīˆ¨ī‹’īŠ¨ī‹ąīŠŗīˆ īŠŊīŠ¸īŠģīˆ ī‹ī‹–ī‹Œī‰šīˆ ī‹ī‹–ī‰‚ī‹„ī‰‘īˆŠīˆ ī‹’ī‹Žī‹–ī‹Œī‰šīˆ ī‰ī‰‚ī‹Žī‹–ī‰‚ī‹„ī‰‘īˆ ī‹’īŠ¨ī‰Šī‰­īˆ ī‹“īŠŧīŠ§īˆ ī‹ī‹ŒīŠ„īˆ ī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰īˆ ī‹’ī‰™ī‹ŒīŠģīˆ ī‹†ī‰ƒīˆ ī‹Šī‹īŠ§ī‰ƒīˆ īŠŊīŠ¸ī‰˛īŠģī‰īˆ ī‹…īŠŋīˆ ī‰œī‰šī‰ī‹‹īˆ ī‹Œī‹‡īˆ ī‰‚ī‹€īŠˇ īˆ  īˆ īˆŽī‹’ī‹ī‰Ēī‰˛īŠ¨īŠģī‰īˆ ī‹’īŠŧī‰ĩī‰‚īŠ°īŠŧīŠģīˆ ī‹…īŠŋī‰‚ī‰‘īˆ ī‹ī‹–ī‹Œī‰šīˆ ī‹ī‹–ī‰‚ī‹„ī‰‘īˆ īŠ•ī‰‡īˆ ī‹’īŠ¯ī‰‚ī‰šī‹ĸī‰‚ī‰‰ īˆ  īˆ īˆŽīˆ¨CCīˆŠīˆ īŠēīˆ–ī‰˛īŠŋīˆ īŠĄī‰Šī‹ˆīŠŋīˆ ī‹‹ī‰ƒīˆ īˆ¨CAīˆŠīˆ īŠēīˆ–ī‰˛īŠŋīˆ ī‰ĻīŠ¨ī‰ļīŠŋīˆ ī‰‚īŠŋī‰‡īˆ īˆŦīŠ”ī‰ŽīŠ´ī‹ī‰Ēī‰ŋīˆ ī‹”ī‰Ļī‰™ī‰ˆī‰‰īˆ ī‹’īŠģī‹Œī‰ĩī‹ŒīŠŋīˆ ī‹†ī‹ŒīŠ¸ī‰īˆ ī‹’ī‹Žī‹–ī‹Œī‰ēīŠģī‰īˆ ī‰ī‰‚ī‹Žī‹–ī‰‚ī‹„ī‰’īŠģī‰īˆ īŠŠī‹ŽīŠšīˆ ī‹†ī‰‡ īˆ  īˆ īˆŽīŠēīˆ–ī‰˛īŠī‰īˆ ī‰ĻīŠ¨ī‰ļīŠī‰īˆ ī‹’īŠŧī‰ĩī‹‹īˆ ī‰œī‰šī‹Œī‹ŽīŠ¯īˆ ī‹ī‰Šī‰‚ī‰Žī‹ŽīŠģī‰īˆ ī‰‚īŠŋī‰ƒī‹‹īˆ īˆŦīŠēīˆ–ī‰˛īŠī‰īˆ īŠĄī‰Šī‹ˆīŠī‰īˆ ī‹’īŠŧī‰ĩī‹‹īˆ ī‰œī‰šī‹Œī‹īˆ īˆŸī‹Žī‹€ī‹ŽīŠģī‰īˆ īŠŊīŠ¸ī‰˛īŠģī‰ īˆ īŠ˛ī‰ĒīŠīˆ ī‰‚ī‹ˆī‹„īŠŋīˆ ī‹‘ī‰Ļī‰™ī‰ī‹‹īˆ īŠŊīŠˇīˆ īŠ•ī‰‡īˆ ī‹‘ī‰Šī‰‚ī‰ąī‹ĸī‰īˆ ī‹ī‰Žī‹īˆ ī‹’ī‹ī‰Ēī‰˛īŠ¨īŠģī‰īˆ ī‹’īŠŧī‰ĩī‰‚īŠ°īŠģī‰īˆ ī‹’ī‹ąīŠ´ī‹ƒīˆ īŠ•ī‰‡īˆ ī‹’īŠ¯ī‰‚ī‰šī‹ĸī‰‚ī‰‰īˆ ī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰īˆ ī‹’ī‰™ī‹ŒīŠģīˆ īŠŸīˆ ī‹’īŠ¨ī‰Šī‰ŽīŠģī‰īˆ īŠŠī‹ąīŠ´īŠģī‰īˆ ī‹†ī‰‡ īˆ  īˆ īˆēīŠŊīŠ¸ī‰˛īŠģī‰īˆ īŠŸīˆ ī‰‚ī‹€īŠˇīˆ ī‰ī‰‚īŠˇī‰Ēī‰˛īŠģī‰īˆ īŠŊīŠˇīˆ īŠŊī‰ŠīŠŗīˆ ī‹…īŠŋīˆ ī‰Ļī‹€ī‰ŽīŠ¨īŠŋīˆ ī‹īŠī‰‚īŠ§īˆ ī‰Ŧī‹ŽīŠŋī‰Ēī‰īˆ ī‹Œī‹‡īˆ ī‹’īŠ¨ī‹ąīŠŗīˆ īŠŊīŠ¸īŠģīˆ ī‰Ŧī‹ŽīŠŋīˆ–īŠģī‰īˆ ī‰ī‰¨ī‹‡īˆ ī‹†ī‰‡īˆ īˆŦīˆ¨A,â€Ļ..,HīˆŠ īˆ  īˆ  īˆ īˆ īˆ īˆ īˆ īˆ īˆ īˆ īˆ īˆ īˆ īˆ īˆ īˆ īˆ īˆ īˆ īˆ īˆ īˆ īˆ īˆ īˆ īˆ īˆ īˆ īˆ īˆ īˆ īˆ īˆ īˆ īˆ īˆ īˆ īˆ  īˆ  īˆ  īˆ ī‹’ī‰Šī‰Žī‹„īŠģī‰‚ī‰‰īˆ ī‰ī‰¨īŠ¸ī‹‡ī‹‹īˆ B,Cīˆ īŠ”ī‰ŽīŠ¨ī‹ąīŠ´īŠģī‰īˆ īŠŊī‹ŽīŠŦī‰˛ī‰īˆ ī‰‹īŠīˆ ī‹‰ī‹ƒī‰ˆīŠ¯īˆ īˆŦī‹’ī‹ŽīŠ§ī‰‚ī‰Šī‰ŽīŠģī‰īˆ ī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰īˆ ī‹’ī‰™ī‹ŒīŠģīˆ ī‹“īŠŧīŠ§īˆ īˆ¨1īˆŠīˆ ī‹īŠŗī‰ĒīŠģī‰īˆ ī‰Šī‰‚ī‹ˆīŠŖī‰‡īˆ īŠŊī‰•ī‰ƒīˆ ī‹…īŠŋīˆ ī‹īŠģī‰‚ī‰ŽīŠģī‰‚ī‰‰ī‹‹ īˆ  īˆ īˆ īˆŽī‹‚ī‰‚īŠŗī‰Šī‹žī‰īˆ ī‹īŠŗī‰‚ī‰ŠīŠģ īˆ  īˆ  īˆ  īˆ  īˆ ī‰ī‰ī‰§īˆ ī‹”ī‰Ēī‰Ąī‰ƒī‹‹īˆ ī‰ĒīŠŦī‰ļīŠŋīˆ ī‹īŠ¸ī‰šī‰ŽīŠīˆ PortCīˆ ī‹’ī‰‰ī‰ī‹Œī‰ŠīŠģī‰īˆ īŠŠīŠŋīˆ ī‹’īŠģī‹Œī‰ĩī‹ŒīŠŋīˆ īŠēīˆ–ī‰˛īŠŋīˆ ī‰ĻīŠ¨ī‰ļīŠŋīˆ ī‰ī‰ī‰§īˆ ī‹’ī‹ŽīŠ§ī‰‚ī‰Šī‰­īˆ ī‰Šī‰‚ī‹ˆīŠŖī‰‡īˆ ī‹’ī‰ąī‰‚ī‰ąīˆ ī‰‚ī‹„ī‹ī‰ĻīŠģīˆ ī‹‰ī‹ƒī‰‡īˆ ī‰žī‰ĒīŠ°ī‰‰ īˆ  īˆ īˆēī‹īŠģī‰‚ī‰ŽīŠģī‰īˆ īŠŊīŠ¸ī‰˛īŠģī‰īˆ īŠŸīˆ ī‰‚ī‹€īŠˇīˆ PortDīˆ ī‹’ī‰‰ī‰ī‹Œī‰ŠīŠģī‰īˆ īŠŠīŠŋīˆ ī‹’īŠģī‹Œī‰ĩī‹ŒīŠŋīˆ īŠēīˆ–ī‰˛īŠŋīˆ īŠĄī‰Šī‹ˆīŠŋ Faculty of Electrical and Electronic Eng. 93 Automatic Control & Automation Dept.
  • 4. ī‹‘ī‰ĒīŠŦī‰ļīŠī‰īˆ ī‰ī‰‚ī‹€īŠ¸ī‰šī‰ŽīŠī‰īˆ ī‹’īŠ‰ī‰Ēī‰‰ īˆ  īˆ  ī‹’ī‰ŽīŠŋī‰‚īŠˆī‰īˆ ī‹’ī‰ŽīŠŧīŠ†ī‰ īˆ  īˆ  īˆ ī‹“īŠŧīŠ§īˆ ī‹īŠ´ī‹ąī‹„īŠŋīˆ ī‰ĒīŠ°ī‰ĩīˆ īŠŠī‰šī‹‹īˆ ī‹īŠŦī‰Šī‹„ī‹īˆ īˆŦīˆ¨īŠēīˆ–ī‰˛īŠī‰īˆ īŠĄī‰Šī‹ˆīŠī‰īˆ ī‰ī‰ī‰§īˆŠīˆ ī‹’ī‹ī‹ŒīŠŧīŠ¨īŠģī‰īˆ ī‹’ī‰™ī‹ŒīŠŧīŠģī‰īˆ īŠŸīˆ ī‹’īŠ¨ī‹ąīŠŗīˆ ī‹ī‰ƒīˆ īŠŊī‹ŽīŠŦī‰˛ī‰īˆ īŠŊī‰•ī‰ƒīˆ ī‹…īŠŋīˆ ī‹‰ī‹ƒī‰ˆīŠ¯īˆ ī‹īŠģī‰‚ī‰ŽīŠģī‰‚ī‰‰ī‹‹ īˆ  īˆ īˆ īˆŽī‹’īŠ¨ī‹ąīŠ´īŠģī‰īˆ īŠŠīŠŋīˆ īŠžī‹Œī‰ĩī‹ŒīŠī‰īˆ ī‹īŠ¸ī‰šī‰ŽīŠī‰īˆ ī‰‹ī‹ąīŠŗ PortCīˆ ī‹’ī‰‰ī‰ī‹Œī‰ŠīŠģī‰īˆ ī‹“īŠŧīŠ§īˆ ī‹’ī‹€ī‹ŽīŠ´īŠģī‰ īˆ ī‰Œī‹ŒīŠŧī‹ąīŠī‰īˆ ī‹īŠŗī‰ĒīŠģī‰ īˆ  īˆ  :â€Ģ-7 اīģŸīģ˜īģ„īģŠ اīģŸīąĩ īą” ī°˛ īēŽ ī˛ģīģžâ€ŦH 6-G 5-F 4-E 3-D 2-C 1-B 0-A īˆ  īˆ  ī‹Šī‰Šī‰‚ī‹ˆīŠŖī‰‡ A.B.C.D.E.F 1 1 0 0 0 0 0 0 0 B.C 1 1 1 1 1 0 0 1 1 A.B.D.E.G 1 0 1 0 0 1 0 0 2 A.B.C.D.G 1 0 1 1 0 0 0 0 3 B.C.F.G 1 0 0 1 1 0 0 1 4 A.C.D.F.G 1 0 0 1 0 0 1 0 5 A.C.D.E.F.G 1 0 0 0 0 0 1 0 6 A.B.C 1 1 1 1 1 0 0 0 7 A.B.C.D.E.F.G 1 0 0 0 0 0 0 0 8 A.B.C.D.F.G 1 0 0 1 0 0 0 0 9 ī‹’ī‰ŽīŠ—ī‹žī‰ī‹‹īˆ ī‹īŠģī‹ ī‰īˆ ī‹īŠ¸ī‰šī‰ŽīŠģī‰īˆ ī‹’ī‰­ī‰Ļī‹„ī‹‡īˆ ī‹ī‰ŽīŠŗ 94 ī‹’ī‹Žī‹ƒī‹‹īˆ–īŠ¸īŠģī‹ĸī‰ī‹‹īˆ ī‹’ī‹Žī‹–ī‰‚ī‰‰ī‰Ēī‹ˆīŠ¸īŠģī‰īˆ ī‹’ī‰­ī‰Ļī‹„īˆšī‰īˆ ī‹’ī‹ŽīŠŧīŠˇ
  • 5. Practical Class 5 Programming Microcontrollers īˆ  īˆ īˆēī‹īŠŧī‹ī‰‚īŠŋīˆ ī‰Ĩī‰ĻīŠīˆ ī‹†ī‰ƒīˆ ī‹…īŠ¸īŠ™īˆ ī‹’ī‹ī‰Ēī‰˛īŠ§īˆ ī‰ī‰­īˆ ī‹‹ī‰ƒīˆ ī‹’ī‹ī‰Ēī‰˛īŠ§īˆ īŠ•ī‰‡īˆ ī‹ī‹–ī‰‚ī‹„ī‰’īŠģī‰īˆ ī‹ī‹ŽīŠ´īŠģī‰īˆ īŠŊī‹ī‹Œī‰šī‰Žī‰‰īˆ ī‹īŠģī‰‚ī‰ŽīŠģī‰‚ī‰‰ī‹‹ īˆ  īˆ  &HC0 &HF9 &HA4 &HB0 &H99 &H92 &H82 &HF8 &H80 &H90 īˆ ī‹’ī‰­ī‹ŒīŠ¸īŠ¨īŠŋīˆ ī‹’īŠģī‰‚īŠ‡ī‰īˆ ī‹…īŠ¸īŠģī‹‹īˆ īˆŦīˆ¨īŠēīˆ–ī‰˛īŠī‰īˆ ī‰ĻīŠ¨ī‰ļīŠī‰īˆ ī‰ī‰ī‰§īˆŠīˆ ī‹’ī‹ŽīŠŧīŠ°ī‰ŽīŠģī‰īˆ ī‹’ī‰™ī‹ŒīŠŧīŠģī‰īˆ īŠŊī‹ŽīŠŦī‰˛ī‰īˆ īŠŊī‰•ī‰ƒīˆ ī‹…īŠŋīˆ ī‹ī‹ŽīŠ´īŠģī‰īˆ ī‰Œī‰‚ī‰Žī‰™īˆ ī‹…īŠ¸īŠ™īˆ ī‹‰ī‹ƒī‰ˆīŠ¯īˆ īŠŊī‰’īŠī‰‚ī‰‰ī‹‹ īˆ  īˆ īˆ īˆŽī‰‚ī‹ˆīŠŧī‹ŽīŠŦī‰˛ī‰īˆ ī‰Ĩī‰ī‰ĒīŠī‰īˆ ī‹’īŠ¨ī‹ąīŠ´īŠģī‰īˆ īŠŠīŠŋīˆ īŠžī‹Œī‰ĩī‹ŒīŠī‰īˆ ī‹īŠ¸ī‰šī‰ŽīŠī‰īˆ ī‰‹ī‹ąīŠŗīˆ ī‹“īŠŧīŠ§īˆ ī‹īŠ´ī‹ąī‹„īŠŋīˆ ī‰Ļī‰™ī‰ī‹‹īˆ īŠŠī‰šī‹‹īˆ ī‹īŠŦī‰Šī‹„ī‹īˆ ī‹‰ī‹ƒī‹žīˆ īˆŦī‹ĩī‰‚īŠŋī‰‚īŠ— īˆ  īˆ  :â€ĢاīģŸīģ˜īģ„īģŠ اīģŸīąĩ īą” ī°˛ īēŽ ī˛ģīģžâ€Ŧ PortCīˆ ī‹’ī‰‰ī‰ī‹Œī‰ŠīŠģī‰īˆ ī‹“īŠŧīŠ§īˆ ī‹’ī‹€ī‹ŽīŠ´īŠģī‰ īˆ ī‰Œī‹ŒīŠŧī‹ąīŠī‰īˆ ī‹īŠŗī‰ĒīŠģī‰ 7-H 6-G 5-F 4-E 3-D 2-C 1-B 0-A īˆ  īˆ  ī‹Šī‰Šī‰‚ī‹ˆīŠŖī‰‡ A.B.C.D.E.F 0 0 1 1 1 1 1 1 0 B.C 0 0 0 0 0 1 1 0 1 A.B.D.E.G 0 1 0 1 1 0 1 1 2 A.B.C.D.G 0 1 0 0 1 1 1 1 3 B.C.F.G 0 1 1 0 0 1 1 0 4 A.C.D.F.G 0 1 1 0 1 1 0 1 5 A.C.D.E.F.G 0 1 1 1 1 1 0 1 6 A.B.C 0 0 0 0 0 1 1 1 7 A.B.C.D.E.F.G 0 1 1 1 1 1 1 1 8 A.B.C.D.F.G 0 1 1 0 1 1 1 1 9 īˆ  īˆ  īˆ  īˆ īˆēī‹īŠŧī‹ī‰‚īŠŋīˆ ī‰Ĩī‰ĻīŠīˆ ī‹†ī‰ƒīˆ ī‹…īŠ¸īŠ™īˆ ī‹’ī‹ī‰Ēī‰˛īŠ§īˆ ī‰ī‰­īˆ ī‹‹ī‰ƒīˆ ī‹’ī‹ī‰Ēī‰˛īŠ§īˆ īŠ•ī‰‡īˆ ī‹ī‹–ī‰‚ī‹„ī‰’īŠģī‰īˆ ī‹ī‹ŽīŠ´īŠģī‰īˆ īŠŊī‹ī‹Œī‰šī‰Žī‰‰īˆ ī‹īŠģī‰‚ī‰ŽīŠģī‰‚ī‰‰ī‹‹ īˆ  īˆ  &H3F &H06 &H5B &H4F &H66 &H6D &H7D &H07 &H7F &H6F īˆ īŠēīˆ–ī‰˛īŠŋīˆ īŠĄī‰Šī‹ˆīŠŋīˆ īŠĒī‹Œī‹ƒīˆ ī‹…īŠŋīˆ ī‰Šī‰‚ī‹ˆīŠŖī‰‡īˆ ī‹’ī‰ąī‰‚ī‰ąīˆ īŠ•ī‰‡īˆ īŠēīˆ–ī‰˛īŠŋīˆ ī‰ĻīŠ¨ī‰ļīŠŋīˆ īŠĒī‹Œī‹ƒīˆ ī‹…īŠŋīˆ ī‰Šī‰‚ī‹ˆīŠŖī‰‡īˆ ī‹’ī‰ąī‰‚ī‰ąīˆ īŠ”ī‰‰īˆ īˆ—īŠ°ī‰˛ī‰ŽīŠģī‰īˆ ī‹ī‹ŽīŠŗīˆ īŠŊī‹ī‹ŒīŠ„īˆ ī‰Ļī‹„īŠ§īˆ īˆēī‹’īŠ¤ī‰™ī‹īŠŋ īˆ  īˆ īˆŽīˆ¨255 DECīˆŠīˆ &HFFīˆ ī‹’ī‹€ī‹ŽīŠ´īŠģī‰īˆ ī‹…īŠŋīˆ ī‹’ī‹€ī‹ŽīŠ´īŠģī‰īˆ ī‰ ī‰Ēī‰ŋīˆ ī‹īŠ°īŠ¸ī‹īˆ ī‹‰ī‹ƒī‰ˆīŠ¯ Faculty of Electrical and Electronic Eng. 95 Automatic Control & Automation Dept.
  • 6. ī‹‘ī‰ĒīŠŦī‰ļīŠī‰īˆ ī‰ī‰‚ī‹€īŠ¸ī‰šī‰ŽīŠī‰īˆ ī‹’īŠ‰ī‰Ēī‰‰ īˆ  īˆ  ī‹’ī‰ŽīŠŋī‰‚īŠˆī‰īˆ ī‹’ī‰ŽīŠŧīŠ†ī‰ īˆ  īˆ īˆēī‹‘ī‰Ļī‹ī‰ĻīŠ†ī‰īˆ ī‰ī‰‚ī‹€ī‹ŽīŠŧīŠ¨ī‰ŽīŠģī‰ īˆ īŠēī‰‚ī‹„ī‹‡ī‹‹īˆ  īˆŦīˆ¨LUT: Look-Up TableīˆŠīˆ  ī‰ī‰‚ī‹ƒī‰‚ī‹Žī‰‰īˆ  īŠžī‹‹ī‰ĻīŠ€īˆ  ī‹“ī‹€ī‰Žī‹īˆ  ī‰‚īŠŋīˆ  ī‹…ī‹€ī‰šīˆ  ī‰—īŠŋī‰‚ī‹ƒīˆ•īŠģī‰īˆ  īŠŸīˆ  ī‰‚ī‹ˆī‹„ī‹ī‰ŦīŠ…īˆ  ī‹…īŠ¸īŠ™īˆ  īˆ—īŠ°ī‰˛ī‰ŽīŠģī‰īˆ  ī‹ī‹ŽīŠŗīˆ  ī‹†ī‰‡ īˆ  īˆ īˆŽī‰ī‰‚ī‹ƒī‰‚ī‹Žī‰ŠīŠģī‰īˆ īŠžī‹‹ī‰ī‰Ļī‰•īˆ ī‹…īŠŋīˆ ī‹‘ī‹•ī‰ī‰ĒīŠ´īŠģī‰ī‹‹īˆ ī‹…ī‹ī‰Ŧī‰ĸī‰ŽīŠŧīŠģīˆ ī‹”ī‰Ēī‰Ąī‹žī‰īˆ ī‰ī‰‚ī‹€ī‹ŽīŠŧīŠ¨ī‰ŽīŠģī‰īˆ ī‰ŧīŠ¨ī‰‰ī‹‹īˆ īŠ”ī‰Žī‹Žī‰­ī‰‚ī‰­ī‰ƒīˆ īŠ”ī‰Žī‹Žī‹€ī‹ŽīŠŧīŠ¨ī‰ īˆ  īˆ  ī‹’ī‹ŽīŠ‰īˆ•īŠģī‰īˆ ī‹’ī‹€ī‹ŽīŠŧīŠ¨ī‰ŽīŠģī‰ īˆ  īˆ  ī‹’ī‹€ī‹ŽīŠŧīŠ¨ī‰ŽīŠģī‰īˆ ī‰ ī‰Ēī‰ą īˆ ī‹’ī‰ŽīŠ¯ī‹œīˆ ī‰Ļī‹„īŠ§īˆ ī‰—īŠŋī‰‚ī‹ƒīˆ•īŠģī‰īˆ ī‹‘ī‰ĒīŠˇī‰ī‰§īˆ īˆ īŠŸīˆ īˆ¨ī‹’ī‹ŽīŠ¯ī‰ĒīŠŠīˆŦī‹’ī‹Žī‹€īŠŗī‰ŠīˆŠīˆ ī‰ī‰‚ī‹ƒī‰‚ī‹Žī‰‰īˆ ī‹…ī‹ī‰ŦīŠ… Data var1 , â€Ļ , varn īˆ  īˆ .0īˆ īŠŊī‹ŽīŠģī‰ĻīŠģī‰īˆ ī‹‰īŠģīˆ īŠžī‹‹ī‹žī‰īˆ ī‰Ēī‰ļī‹„īŠ¨īŠģī‰īˆ ī‹†ī‰ƒīˆ ī‰“ī‹Žī‰™īˆ īˆŦī‹’ī‹„ī‹ŽīŠ¨īŠŋ īˆ labelīˆ ī‹’ī‰ŽīŠ¯ī‹īŠģī‰īˆ ī‰Ļī‹„īŠ§īˆ  Dataīˆ īŠŸīˆ ī‹†ī‰ŦīŠ‹īˆ  LUTīˆ ī‹…īŠŋīˆ ī‹’ī‹€ī‹ŽīŠŗīˆ ī‰‹īŠŧī‰• var = Lookup(Index , label) īˆ  īˆ īˆŽIndexīˆ īŠŊī‹ŽīŠģī‰ĻīŠģī‰īˆ ī‹‰īŠģī‹‹ īˆ ī‹’ī‰ŽīŠ¯ī‹īŠģī‰īˆ  ī‰Ļī‹„īŠ§īˆ  Dataīˆ  īŠŸīˆ  ī‹†ī‰ŦīŠ‹īˆ  LUTīˆ  ī‹…īŠŋīˆ  īŠ˛ī‰ĒīŠŠīˆ  ī‰‹īŠŧī‰• Var = Lookupstr(Index , Label) īˆ  īˆ īˆŽIndexīˆ īŠŊī‹ŽīŠģī‰ĻīŠģī‰īˆ ī‹‰īŠģī‹‹īˆ label īˆ īŠŸīˆ  ī‹†ī‰ŦīŠ‹īˆ  īˆ¨valueīˆŠīˆ  ī‹’ī‹€ī‹ŽīŠŗīˆ  īˆ¨IndexīˆŠīˆ  īŠŊī‹ŽīŠģī‰Ĩīˆ  ī‹…īŠ§īˆ  ī‰“ī‰šī‰ŠīŠģī‰ Var = Lookdown(value,Label,Entries) īˆ ī‰Ĩī‰ĻīŠ§īˆ ī‹…ī‹€ī‰šīˆ ī‰“ī‰šī‰ŠīŠģī‰īˆ ī‹ī‰Žī‹Žī‹īˆ ī‹†ī‰ƒīˆ ī‹“īŠŧīŠ§īˆ  labelīˆ ī‹’ī‰ŽīŠ¯ī‹īŠģī‰īˆ ī‰Ļī‹„īŠ§īˆ  Data īˆ  īˆ īˆŽīˆ¨EntriesīˆŠīˆ ī‰Ēī‰ĩī‰‚ī‹„īŠ¨īŠģī‰īˆ ī‹…īŠŋīˆ ī‰Ĩī‰ĻīŠŠ īˆ īˆ īŠŸīˆ  ī‰Ĩī‹Œī‰•ī‹ŒīŠŋīˆ  ī‰Ēī‰ļī‹„īŠ§īˆ  īŠžī‹‹ī‰ƒīˆ  īŠ•ī‰‡īˆ  ī‰ī‰‚ī‹ƒī‰‚ī‹Žī‰‰īˆ  īˆ¨ī‰Ĩī‰ī‰ĻīŠ§īˆŠīˆ  ī‰Ēī‰ąī‹›īŠŋīˆ  īŠŠī‰šī‹Œī‰‰īˆ  ī‹‚ī‹ŒīŠ´ī‰ Restore Label īˆ ī‹‘ī‹•ī‰ī‰ĒīŠŗīˆ īŠŊī‰•ī‰ƒīˆ ī‹…īŠŋīˆ  labelīˆ ī‹’ī‰ŽīŠ¯ī‹īŠģī‰īˆ ī‰Ļī‹„īŠ§īˆ  Dataīˆ īŠŸīˆ ī‹†ī‰ŦīŠ‹īˆ  LUT Read Varīˆ īˆ īˆēī‹’ī‹€ī‹ŽīŠŧīŠ¨ī‰īˆ ī‹‚ī‰ī‰Ļī‰ĸī‰Žī‰­ī‰‚ī‰‰īˆ ī‰ī‰‚ī‹ƒī‰‚ī‹Žī‰ŠīŠģī‰ īˆ īˆƒīˆ  īˆžīŠģī‰ī‹‹īˆ  Dataīˆ  īŠŸīˆ  ī‹†ī‰ŦīŠ‹īˆ  LUTīˆ  īˆ  īŠŸīˆ  ī‹‘ī‰Ĩī‹Œī‰•ī‹ŒīŠī‰īˆ  ī‹ī‹ŽīŠ´īŠģī‰īˆ  ī‹‘ī‹•ī‰ī‰ĒīŠŗ Read Var īˆ īŠ•ī‰‡īˆ  ī‹ī‹‡ī‰Ĩī‰‚ī‹„ī‰­ī‰‡ī‹‹īˆ  Restoreīˆ  ī‹’ī‹€ī‹ŽīŠŧīŠ¨ī‰ŽīŠģī‰īˆ  ī‹‚ī‰ī‰Ļī‰ĸī‰Žī‰­ī‰‚ī‰‰īˆ  ī‰‚ī‹ˆī‹ŽīŠģī‰‡īˆ  ī‹‘ī‰Šī‰‚ī‰ąī‹ĸī‰ īˆ  īˆ īˆŽVarīˆ īŠžī‹Œī‰šī‰ŽīŠī‰ īˆ  īˆ  īˆ  īˆ  īˆ  īˆ  īˆ  īˆ  īˆ  īˆ  īˆ  īˆ  īˆ  īˆ  īˆ  īˆ  īˆ  īˆ  īˆ  īˆ  īˆ  īˆ  īˆ  īˆ  ī‹’ī‰ŽīŠ—ī‹žī‰ī‹‹īˆ ī‹īŠģī‹ ī‰īˆ ī‹īŠ¸ī‰šī‰ŽīŠģī‰īˆ ī‹’ī‰­ī‰Ļī‹„ī‹‡īˆ ī‹ī‰ŽīŠŗ 96 ī‹’ī‹Žī‹ƒī‹‹īˆ–īŠ¸īŠģī‹ĸī‰ī‹‹īˆ ī‹’ī‹Žī‹–ī‰‚ī‰‰ī‰Ēī‹ˆīŠ¸īŠģī‰īˆ ī‹’ī‰­ī‰Ļī‹„īˆšī‰īˆ ī‹’ī‹ŽīŠŧīŠˇ
  • 7. Practical Class 5 Programming Microcontrollers īˆ  īˆ īˆēīˆ¨0-9īˆ ī‹ī‰Ēī‰˛īŠ§īˆ ī‰Ĩī‰ī‰ĻīŠ¨īŠˇīˆ ī‹’ī‹ī‰Ĩī‰ĒīŠ¯īˆ ī‰Šī‰‚ī‹ˆīŠŖī‰‡īˆ ī‹’ī‰™ī‹ŒīŠģīˆŠīˆ ī‹‘ī‰Šī‰ī‰ĻīŠģī‰īˆ īŠŊī‹ŽīŠŦī‰˛ī‰īˆ ī‰—īŠŋī‰‚ī‹ƒī‰Ēī‰‰ īˆ  īˆ īˆŽSW34īˆ ī‰ ī‰‚ī‰ŽīŠ°īŠī‰īˆ ī‹…īŠŋīˆ 4īˆ īŠŊī‰ĩī‹ŒīŠģī‰īˆ ī‹’ī‹ąīŠ´ī‹ƒīˆ īŠļī‹īŠĢī‰‡īˆ ī‰‹īŠīˆ  īˆēīŠŊī‹Žī‰ĩī‹Œī‰ŽīŠģī‰īˆ ī‰ī‰‚ī‰ŠīŠŧī‹ąī‰ŽīŠŋ $regfile = "m128def.dat" $crystal = 8000000 īˆ  īˆ īˆŽī‰ī‰‚ī‹ˆī‹Žī‰•ī‹Œī‰ŽīŠģī‰ '--------------------- īˆ  īˆ īˆŽī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰īˆ ī‹’ī‰ąī‰‚ī‰ąīˆ ī‰‚ī‹ˆīŠ¨īŠŋīˆ īŠŊī‰ĩī‹ŒīŠī‰īˆ ī‹’ī‰‰ī‰ī‹Œī‰ŠīŠģī‰īˆ īŠąī‹ī‰ĒīŠ¨ī‰ Config Porta = Output Segment Alias Porta īˆ ī‰Ēī‹ˆīŠ¤ī‰īˆ ī‹ī‹‡ī‹‹īˆ īˆ¨&H81īˆŠīˆ ī‹’ī‰‰ī‰ī‹Œī‰ŠīŠģī‰īˆ ī‹“īŠŧīŠ§īˆ ī‹’ī‹ŽīŠģī‹‹ī‹žī‰īˆ ī‹’ī‹€ī‹ŽīŠ´īŠģī‰īˆ īŠ”ī‹ŽīŠ¨ī‰ Porta = &H81 īˆ  īˆ ī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰īˆ ī‹’ī‰ąī‰‚ī‰ąīˆ ī‹“īŠŧīŠ§īˆ ī‰ĒīŠ°ī‰ĩīˆ ī‹īŠŗī‰ĒīŠģī‰ Config Portc.4 = Output īˆ  īˆ  Ctr1 Alias Portc.4 Reset Ctr1 īˆ  īˆ ī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰īˆ ī‹’ī‰™ī‹ŒīŠŧīŠģīˆ īŠēīˆ–ī‰˛īŠī‰īˆ ī‰ĻīŠ¨ī‰ļīŠī‰‚ī‰‰īˆ ī‹īŠ¸ī‰šī‰ŽīŠģī‰īˆ ī‰‹ī‹ąīŠŗīˆ īŠąī‹ī‰ĒīŠ¨ī‰ '--------------------- Dim I As Byte īˆ  īˆ ī‰ī‹œī‹Œī‰šī‰ŽīŠī‰īˆ īŠąī‹ī‰ĒīŠ¨ī‰ '--------------------- Do For I = 0 To 9 Segment = Lookup(i , Seg) īˆ  īˆ īˆēī‰‚ī‹ˆī‹ŽīŠ¯īˆ ī‹ī‰Žī‹īˆ ī‹ī‰Žī‹Žī‹–ī‰ĒīŠģī‰īˆ ī‰—īŠŋī‰‚ī‹ƒīˆ•īŠģī‰īˆ ī‹’īŠ´īŠŧī‰™ Waitms 1000 Next I īˆ īˆ¨SegīˆŠīˆ ī‹’ī‰ŽīŠ¯ī‹īŠģī‰īˆ ī‰Ļī‹„īŠ§īˆ īˆ¨DataīˆŠīˆ īŠŸīˆ ī‹’ī‹ƒī‰Ŧī‰ĸīŠī‰īˆ ī‹ī‹ŽīŠ´īŠģī‰īˆ ī‹‘ī‹•ī‰ī‰ĒīŠŗ Loop īˆ  īˆ īˆŽī‹”ī‰Ēī‰Ąī‹žīˆ ī‹ŒīŠŧī‰īˆ ī‹’ī‹€ī‹ŽīŠŗīˆ īˆŦīˆ¨LookupīˆŠīˆ ī‹’ī‹€ī‹ŽīŠŧīŠ¨ī‰ŽīŠģī‰īˆ ī‹‚ī‰ī‰Ļī‰ĸī‰Žī‰­ī‰‚ī‰‰ End '--------------------- Seg: īˆ  īˆ īˆŽī‰ī‰‚ī‹ƒī‰‚ī‹Žī‰ŠīŠģī‰īˆ ī‹…ī‹ī‰ŦīŠ…īˆ īŠžī‹‹ī‰Ļī‰•īˆ ī‹’ī‰ŽīŠ¯ī‹œ Data &H81 , &HF3 , &H49 , &H61 , &H33 , &H25 , &H05 , &HF1 , &H01 , &H21 Faculty of Electrical and Electronic Eng. 97 Automatic Control & Automation Dept.
  • 8. ī‹‘ī‰ĒīŠŦī‰ļīŠī‰īˆ ī‰ī‰‚ī‹€īŠ¸ī‰šī‰ŽīŠī‰īˆ ī‹’īŠ‰ī‰Ēī‰‰ īˆ  īˆ  ī‹’ī‰ŽīŠŋī‰‚īŠˆī‰īˆ ī‹’ī‰ŽīŠŧīŠ†ī‰ īˆ  īˆ īˆēīˆ¨0 – 99īˆ ī‹ī‰Ēī‰˛īŠ§īˆ ī‰Ĩī‰ī‰ĻīŠ¨īŠˇīˆ ī‹’ī‹Žī‹–ī‰‚ī‹„ī‰‘īˆ ī‰Šī‰‚ī‹ˆīŠŖī‰‡īˆ ī‹’ī‰™ī‹ŒīŠģīˆ īŠŊī‹ŽīŠŦī‰˛ī‰īˆŠīˆ ī‹‘ī‰Šī‰ī‰ĻīŠģī‰īˆ īŠŊī‹ŽīŠŦī‰˛ī‰īˆ ī‰—īŠŋī‰‚ī‹ƒī‰Ēī‰‰ īˆ  īˆ īˆŽSW34īˆ ī‰ ī‰‚ī‰ŽīŠ°īŠī‰īˆ ī‹…īŠŋīˆ 4,5īˆ īŠŊī‰ĩī‹ŒīŠģī‰īˆ īˆžī‹ąīŠ´ī‹ƒīˆ īŠļī‹īŠĢī‰‡īˆ ī‰‹īŠ īˆēīŠŊī‹Žī‰ĩī‹Œī‰ŽīŠģī‰īˆ ī‰ī‰‚ī‰ŠīŠŧī‹ąī‰ŽīŠŋ $regfile = "m128def.dat" $crystal = 8000000 īˆ  īˆ īˆŽī‰ī‰‚ī‹ˆī‹Žī‰•ī‹Œī‰ŽīŠģī‰ '--------------------- Config Porta = Output īˆ ī‰ī‰‚ī‰ąī‰‚ī‰˛īŠģīˆ ī‰ī‰‚ī‹ƒī‰‚ī‹Žī‰ŠīŠģī‰īˆ īŠĸī‹Œī‹ąī‰Ąīˆ ī‰‚ī‹ˆīŠ¨īŠŋīˆ īŠŊī‰ĩī‹ŒīŠī‰īˆ ī‹’ī‰‰ī‰ī‹Œī‰ŠīŠģī‰īˆ īŠąī‹ī‰ĒīŠ¨ī‰ Segment Alias Porta Porta = &H81 īˆ  īˆ īˆŽī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰ Config Portc.4 = Output īˆ ī‰Ēī‹ˆīŠ¤ī‰īˆ ī‹ī‹‡ī‹‹īˆ īˆ¨&H81īˆŠīˆ ī‹’ī‰‰ī‰ī‹Œī‰ŠīŠģī‰īˆ ī‹“īŠŧīŠ§īˆ ī‹’ī‹ŽīŠģī‹‹ī‹žī‰īˆ ī‹’ī‹€ī‹ŽīŠ´īŠģī‰īˆ īŠ”ī‹ŽīŠ¨ī‰ Display1 Alias Portc.4 īˆ  īˆ ī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰īˆ ī‹’ī‰ąī‰‚ī‰ąīˆ ī‹“īŠŧīŠ§īˆ ī‰ĒīŠ°ī‰ĩīˆ ī‹īŠŗī‰ĒīŠģī‰ Config Portc.5 = Output īˆ ī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰īˆ ī‹’ī‰™ī‹ŒīŠŧīŠģīˆ īŠēīˆ–ī‰˛īŠī‰īˆ ī‰ĻīŠ¨ī‰ļīŠī‰‚ī‰‰īˆ ī‹īŠ¸ī‰šī‰ŽīŠģī‰īˆ ī‰‹ī‹ąīŠŗīˆ īŠąī‹ī‰ĒīŠ¨ī‰ Display2 Alias Portc.5 īˆ  īˆ īˆŽī‹’ī‹Žī‹ƒī‰‚ī‰’īŠģī‰ī‹‹īˆ īŠ•ī‹‹ī‹žī‰ Set Display1 : Set Display2 īˆ  īˆ īˆŽī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰īˆ īˆžī‰™ī‹ŒīŠģīˆ ī‹īŠˇīˆ ī‹•ī‰‚īŠ°ī‰ŋī‰‡ '--------------------- Dim I As Byte , J As Byte īˆ  īˆ ī‰ī‹œī‹Œī‰šī‰ŽīŠī‰īˆ īŠąī‹ī‰ĒīŠ¨ī‰ '--------------------- Do For I = 0 To 9 For J = 0 To 9 īˆ  īˆ īˆēī‰‚ī‹ˆī‹ŽīŠ¯īˆ ī‹ī‰Žī‹īˆ ī‹ī‰Žī‹Žī‹–ī‰ĒīŠģī‰īˆ ī‰—īŠŋī‰‚ī‹ƒīˆ•īŠģī‰īˆ ī‹’īŠ´īŠŧī‰™ Segment = Lookup(i , Seg) Reset Display1 : Waitms 20 īˆ īˆ¨SegīˆŠīˆ ī‹’ī‰ŽīŠ¯ī‹īŠģī‰īˆ ī‰Ļī‹„īŠ§īˆ īˆ¨DataīˆŠīˆ īŠŸīˆ ī‹’ī‹ƒī‰Ŧī‰ĸīŠī‰īˆ ī‹ī‹ŽīŠ´īŠģī‰īˆ ī‹‘ī‹•ī‰ī‰ĒīŠŗ Set Display1 īˆ  īˆ īˆŽī‹”ī‰Ēī‰Ąī‹žīˆ ī‹ŒīŠŧī‰īˆ ī‹’ī‹€ī‹ŽīŠŗīˆ īˆŦīˆ¨LookupīˆŠīˆ ī‹’ī‹€ī‹ŽīŠŧīŠ¨ī‰ŽīŠģī‰īˆ ī‹‚ī‰ī‰Ļī‰ĸī‰Žī‰­ī‰‚ī‰‰ Segment = Lookup(j , Seg) īˆ  īˆ īˆŽīŠ•ī‹‹ī‹žī‰īˆ ī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰īˆ ī‹’ī‰™ī‹ŒīŠģīˆ īŠŊī‹ŽīŠŦī‰˛ī‰ Reset Display2 : Waitms 20 Set Display2 īˆ  īˆ īˆŽī‹’ī‹Žī‹ƒī‰‚ī‰’īŠģī‰īˆ īŠŊī‹ŽīŠŦī‰˛ī‰ī‹‹īˆ īŠ•ī‹‹ī‹žī‰īˆ ī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰īˆ ī‹’ī‰™ī‹ŒīŠģīˆ īŠ˛ī‰‚īŠ´ī‹ī‰‡ Next J Next I īˆ  īˆ īˆŽīˆŽīˆŽī‹’ī‹ŽīŠŧī‹€īŠ¨īŠģī‰īˆ ī‰Šī‰ī‰ĒīŠ¸ī‰ Loop End '--------------------- Seg: Data &H81 , &HF3 , &H49 , &H61 , &H33 , īˆ  īˆ īˆŽī‰ī‰‚ī‹ƒī‰‚ī‹Žī‰ŠīŠģī‰īˆ ī‹…ī‹ī‰ŦīŠ…īˆ īŠžī‹‹ī‰Ļī‰•īˆ ī‹’ī‰ŽīŠ¯ī‹œ &H25 , &H05 , &HF1 , &H01 , &H21 ī‹’ī‰ŽīŠ—ī‹žī‰ī‹‹īˆ ī‹īŠģī‹ ī‰īˆ ī‹īŠ¸ī‰šī‰ŽīŠģī‰īˆ ī‹’ī‰­ī‰Ļī‹„ī‹‡īˆ ī‹ī‰ŽīŠŗ 98 ī‹’ī‹Žī‹ƒī‹‹īˆ–īŠ¸īŠģī‹ĸī‰ī‹‹īˆ ī‹’ī‹Žī‹–ī‰‚ī‰‰ī‰Ēī‹ˆīŠ¸īŠģī‰īˆ ī‹’ī‰­ī‰Ļī‹„īˆšī‰īˆ ī‹’ī‹ŽīŠŧīŠˇ
  • 9. Practical Class 5 Programming Microcontrollers īˆ  īˆ īˆēīˆ¨0 – 9999īˆ ī‹ī‰Ēī‰˛īŠ§īˆ ī‰Ĩī‰ī‰ĻīŠ¨īŠˇīˆ ī‹’ī‹ŽīŠ§ī‰‚ī‰‰ī‰Šīˆ ī‰Šī‰‚ī‹ˆīŠŖī‰‡īˆ ī‹’ī‰™ī‹ŒīŠģīˆ īŠŊī‹ŽīŠŦī‰˛ī‰īˆŠīˆ ī‹‘ī‰Šī‰ī‰ĻīŠģī‰īˆ īŠŊī‹ŽīŠŦī‰˛ī‰īˆ ī‰—īŠŋī‰‚ī‹ƒī‰Ēī‰‰ $regfile = "m128def.dat" $crystal = 8000000 īˆ  īˆ īˆŽī‰ī‰‚ī‹ˆī‹Žī‰•ī‹Œī‰ŽīŠģī‰ '--------------------- Config Porta = Output Segment Alias Porta īˆ ī‰ī‰‚ī‰ąī‰‚ī‰˛īŠģīˆ ī‰ī‰‚ī‹ƒī‰‚ī‹Žī‰ŠīŠģī‰īˆ īŠĸī‹Œī‹ąī‰Ąīˆ ī‰‚ī‹ˆīŠ¨īŠŋīˆ īŠŊī‰ĩī‹ŒīŠī‰īˆ ī‹’ī‰‰ī‰ī‹Œī‰ŠīŠģī‰īˆ īŠąī‹ī‰ĒīŠ¨ī‰ Porta = &H81 īˆ  īˆ īˆŽī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰ Config Portc = &B11110000 īˆ ī‰Ēī‹ˆīŠ¤ī‰īˆ ī‹ī‹‡ī‹‹īˆ īˆ¨&H81īˆŠīˆ ī‹’ī‰‰ī‰ī‹Œī‰ŠīŠģī‰īˆ ī‹“īŠŧīŠ§īˆ ī‹’ī‹ŽīŠģī‹‹ī‹žī‰īˆ ī‹’ī‹€ī‹ŽīŠ´īŠģī‰īˆ īŠ”ī‹ŽīŠ¨ī‰ Display1 Alias Portc.4 Display2 Alias Portc.5 īˆ  īˆ ī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰īˆ ī‹’ī‰ąī‰‚ī‰ąīˆ ī‹“īŠŧīŠ§īˆ ī‰ĒīŠ°ī‰ĩīˆ ī‹īŠŗī‰ĒīŠģī‰ Display3 Alias Portc.6 īˆ ī‰ī‰‚ī‰™ī‹ŒīŠŧīŠģīˆ īŠēīˆ–ī‰˛īŠī‰īˆ ī‰ĻīŠ¨ī‰ļīŠī‰‚ī‰‰īˆ ī‹īŠ¸ī‰šī‰ŽīŠģī‰īˆ ī‰Œī‰‚ī‹ąīŠŗī‰ƒīˆ īŠąī‹ī‰ĒīŠ¨ī‰ Display4 Alias Portc.7 īˆ  īˆ īˆŽī‹’īŠ¨ī‰‰ī‰Šī‹žī‰īˆ ī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰ Set Display1 : Set Display2 Set Display3 : Set Display4 īˆ  īˆ īˆŽī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰īˆ ī‰ī‰‚ī‰™ī‹ŒīŠģīˆ īŠŊīŠˇīˆ ī‹•ī‰‚īŠ°ī‰ŋī‰‡ '--------------------- Dim I As Byte , J As Byte Dim K As Byte , L As Byte īˆ  īˆ ī‰ī‹œī‹Œī‰šī‰ŽīŠī‰īˆ īŠąī‹ī‰ĒīŠ¨ī‰ '--------------------- Do For I = 0 To 9 For J = 0 To 9 For K = 0 To 9 For L = 0 To 9 Segment = Lookup(i , Seg) Reset Display1 : Waitms 7 Set Display1 īˆ  īˆ īˆēī‰‚ī‹ˆī‹ŽīŠ¯īˆ ī‹ī‰Žī‹īˆ ī‹ī‰Žī‹Žī‹–ī‰ĒīŠģī‰īˆ ī‰—īŠŋī‰‚ī‹ƒīˆ•īŠģī‰īˆ ī‹’īŠ´īŠŧī‰™ Segment = Lookup(j , Seg) Reset Display2 : Waitms 7 īˆ īˆ¨SegīˆŠīˆ ī‹’ī‰ŽīŠ¯ī‹īŠģī‰īˆ ī‰Ļī‹„īŠ§īˆ īˆ¨DataīˆŠīˆ īŠŸīˆ ī‹’ī‹ƒī‰Ŧī‰ĸīŠī‰īˆ ī‹ī‹ŽīŠ´īŠģī‰īˆ ī‹‘ī‹•ī‰ī‰ĒīŠŗ Set Display2 īˆ  īˆ īˆŽī‹”ī‰Ēī‰Ąī‹žīˆ ī‹ŒīŠŧī‰īˆ ī‹’ī‹€ī‹ŽīŠŗīˆ īˆŦīˆ¨LookupīˆŠīˆ ī‹’ī‹€ī‹ŽīŠŧīŠ¨ī‰ŽīŠģī‰īˆ ī‹‚ī‰ī‰Ļī‰ĸī‰Žī‰­ī‰‚ī‰‰ Segment = Lookup(k , Seg) īˆ  īˆ īˆŽīŠ•ī‹‹ī‹žī‰īˆ ī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰īˆ ī‹’ī‰™ī‹ŒīŠģīˆ īŠŊī‹ŽīŠŦī‰˛ī‰ Reset Display3 : Waitms 7 Set Display3 īˆ  īˆ īˆŽī‹’ī‹Žī‹ƒī‰‚ī‰’īŠģī‰īˆ īŠŊī‹ŽīŠŦī‰˛ī‰ī‹‹īˆ īŠ•ī‹‹ī‹žī‰īˆ ī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰īˆ ī‹’ī‰™ī‹ŒīŠģīˆ īŠ˛ī‰‚īŠ´ī‹ī‰‡ īˆ  īˆ īˆŽīˆŽīˆŽīˆŽī‰ī‰¨īŠ¸ī‹‡ī‹‹ Segment = Lookup(l , Seg) Reset Display4 : Waitms 7 īˆ  īˆ īˆŽīˆŽīˆŽī‹’ī‹ŽīŠŧī‹€īŠ¨īŠģī‰īˆ ī‰Šī‰ī‰ĒīŠ¸ī‰ Set Display4 Next L Next K Next J Next I Loop End '--------------------- Seg: Data &H81 , &HF3 , &H49 , &H61 , &H33 , īˆ  īˆ īˆŽī‰ī‰‚ī‹ƒī‰‚ī‹Žī‰ŠīŠģī‰īˆ ī‹…ī‹ī‰ŦīŠ…īˆ īŠžī‹‹ī‰Ļī‰•īˆ ī‹’ī‰ŽīŠ¯ī‹œ &H25 , &H05 , &HF1 , &H01 , &H21 ī„ ī„  ī„ ī„  Faculty of Electrical and Electronic Eng. 99 Automatic Control & Automation Dept.
  • 10. ī‹‘ī‰ĒīŠŦī‰ļīŠī‰īˆ ī‰ī‰‚ī‹€īŠ¸ī‰šī‰ŽīŠī‰īˆ ī‹’īŠ‰ī‰Ēī‰‰ īˆ  īˆ  ī‹’ī‰ŽīŠŋī‰‚īŠˆī‰īˆ ī‹’ī‰ŽīŠŧīŠ†ī‰ Exp.15: Real Time Clock īˆ  īˆ ī‹īŠ´ī‹ŽīŠ´īŠ‡ī‰īˆ ī‹…īŠŋī‰ŦīŠģī‰īˆ ī‰ī‹ŽīŠŗī‹Œī‰īˆ ī‹’īŠ§ī‰‚ī‰­īˆ īˆēī‹‘ī‰Ēī‰˛īŠ§īˆ ī‹’ī‰ŽīŠŋī‰‚īŠˆī‰īˆ ī‹’ī‰‰ī‰Ēī‰–ī‰ŽīŠģī‰ īˆ  īˆ īˆēī‹’ī‰‰ī‰Ēī‰–ī‰ŽīŠģī‰īˆ ī‹…īŠŋīˆ ī‹’ī‹ī‰‚īŠŦīŠģī‰ īˆ  īˆ īˆŽī‹īŠ´ī‹ŽīŠ´īŠ‡ī‰īˆ ī‹…īŠŋī‰ŦīŠģī‰īˆ īŠŸīˆ ī‰Ŗī‹ī‰Šī‰‚ī‰ī‹‹īˆ ī‰ī‹ŽīŠŗī‹Œī‰īˆ ī‹’īŠ§ī‰‚ī‰­īˆ īŠŊī‹ŽīŠŦī‰˛ī‰ī‹‹īˆ ī‹’īŠ‰ī‰Ēī‰‰ īˆ  īˆ īˆēīŠŊī‹Žī‰ĩī‹Œī‰ŽīŠģī‰īˆ īŠĄī‹ąīŠ‹ īˆ  īˆ  īˆ  īˆ īˆēīŠŊī‹Žī‰ĩī‹Œī‰īˆ ī‰ī‰‚ī‰ŠīŠŧī‹ąī‰ŽīŠŋ īˆ  īˆ īˆŽSW2īˆ ī‰ ī‰‚ī‰ŽīŠ°īŠī‰īˆ īŠļī‹īŠĢī‰‡īˆ ī‰‹īŠ īˆ  īˆ  īˆ  īˆ īˆēī‹‘ī‰Šī‰ī‰ĻīŠģī‰īˆ īŠŊī‹€īŠ§īˆ ī‰ ī‰Ēī‰ą īˆ ī‰Ŗī‹ī‰Šī‰‚ī‰ŽīŠģī‰ī‹‹īˆ ī‰ī‹ŽīŠŗī‹Œī‰ŽīŠģī‰īˆ ī‹’ī‹€ī‹ŽīŠŗīˆ ī‰žī‰ĒīŠ§ī‹‹īˆ ī‰ī‹ŽīŠŗī‹Œī‰īˆ ī‹’īŠ§ī‰‚ī‰­īˆ īŠŊī‹ŽīŠŦī‰˛ī‰ŽīŠģīˆ ī‰—īŠŋī‰‚ī‹ƒī‰Ēī‰‰īˆ ī‹’ī‰‰ī‰‚ī‰ŽīŠ¸ī‰‰īˆ ī‹‚ī‹ŒīŠ´ī‹ƒīˆ īŠ˛ī‹Œī‰­ īˆ  īˆ īˆŽī‹’ī‹ŽīŠģī‰‚ī‰Žī‰Žī‹ī‰ĒīŠ¸īŠģī‰īˆ ī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰īˆ ī‹’ī‰ąī‰‚ī‰ąīˆ ī‹“īŠŧīŠ§ īˆ īŠŊī‰Ąī‰ī‰Ĩīˆ  ī‹‘ī‰Ĩī‹Œī‰•ī‹ŒīŠī‰īˆ  īˆ¨RTCīˆŠīˆ  ī‹īŠ´ī‹ŽīŠ´īŠ‡ī‰īˆ  ī‹…īŠŋī‰ŦīŠģī‰īˆ  īŠŸīˆ  ī‰ī‹ŽīŠŗī‹Œī‰ŽīŠģī‰īˆ  ī‹‘ī‰Ļī‰™ī‹‹īˆ  īŠŊī‹ŽīŠŦī‰˛ī‰īˆ  īŠŊī‰•ī‰ƒīˆ  ī‹…īŠŋīˆ  ī‹‰ī‹ƒī‰‡ īˆ ī‰Œī‰‚ī‹ąīŠŗī‹žī‰īˆ  ī‹“īŠŧīŠ§īˆ  32.786 KHZīˆ  ī‹‰ī‰Žī‹€ī‹ŽīŠŗīˆ  ī‹īŠģī‰‚ī‰Žī‰Žī‹ī‰ĒīŠˇīˆ  ī‰Ģī‰ī‰Ŧī‹‡īˆ  īŠŊī‰ĩī‹‹īˆ  ī‰‹īŠīˆ  ī‹‰ī‹ƒī‰ˆīŠ¯īˆ  īˆ’ī‰‚īŠ¨īŠ īˆ  īˆ īˆŽTOSC1,2 ī‹’ī‰ŽīŠ—ī‹žī‰ī‹‹īˆ ī‹īŠģī‹ ī‰īˆ ī‹īŠ¸ī‰šī‰ŽīŠģī‰īˆ ī‹’ī‰­ī‰Ļī‹„ī‹‡īˆ ī‹ī‰ŽīŠŗ 100 ī‹’ī‹Žī‹ƒī‹‹īˆ–īŠ¸īŠģī‹ĸī‰ī‹‹īˆ ī‹’ī‹Žī‹–ī‰‚ī‰‰ī‰Ēī‹ˆīŠ¸īŠģī‰īˆ ī‹’ī‰­ī‰Ļī‹„īˆšī‰īˆ ī‹’ī‹ŽīŠŧīŠˇ
  • 11. Practical Class 5 Programming Microcontrollers īˆ  īˆ īˆēī‹‘ī‰Ļī‹ī‰ĻīŠ†ī‰īˆ ī‰ī‰‚ī‹€ī‹ŽīŠŧīŠ¨ī‰ŽīŠģī‰ īˆ  īˆ īˆŽī‹’ī‹ŽīŠŧī‰Ąī‰ī‰ĻīŠģī‰īˆ ī‹īŠ´ī‹ŽīŠ´īŠ‡ī‰īˆ ī‹…īŠŋī‰ŦīŠģī‰īˆ ī‹’īŠ§ī‰‚ī‰­īˆ īŠŸīˆ ī‹’īŠŋī‰Ļī‰ĸī‰Žī‰ŽīŠī‰īˆ ī‹‘ī‰Ļī‹ī‰ĻīŠ†ī‰īˆ ī‰ī‰‚ī‹€ī‹ŽīŠŧīŠ¨ī‰ŽīŠģī‰īˆ ī‰œī‰šī‹Œī‹īˆ ī‹īŠģī‰‚ī‰ŽīŠģī‰īˆ īŠžī‹‹ī‰ĻīŠ†ī‰ īˆ  īˆ  ī‹’ī‹ŽīŠ‰īˆ•īŠģī‰īˆ ī‹’ī‹€ī‹ŽīŠŧīŠ¨ī‰ŽīŠģī‰ īˆ  īˆ  ī‹’ī‹€ī‹ŽīŠŧīŠ¨ī‰ŽīŠģī‰īˆ ī‰ ī‰Ēī‰ą Config Clock = Soft | User īˆ  īˆ īˆŽīˆ¨ī‹ī‰•ī‰Šī‰‚ī‰Ąīˆ īˆ |īˆ īˆ ī‹’ī‹ŽīŠŧī‰Ąī‰ī‰ĨīˆŠīˆ ī‹īŠ´ī‹ŽīŠ´īŠ‡ī‰īˆ ī‹…īŠŋī‰ŦīŠģī‰īˆ ī‹’īŠ§ī‰‚ī‰­īˆ īŠąī‹ī‰ĒīŠ¨ī‰ Config Date = Dmy , Separator = Char īˆ  īˆ ī‹’ī‹„ī‰ŽīŠģī‰ī‹‹īˆ ī‰Ēī‹ˆī‰˛īŠģī‰ī‹‹īˆ ī‹‚ī‹Œī‹ŽīŠģī‰īˆ īŠ”ī‰‰īˆ īŠŊī‰ĩī‰ī‹ŒīŠ°īŠģī‰ī‹‹īˆ ī‰Ŗī‹ī‰Šī‰‚ī‰ŽīŠģī‰īˆ ī‰žī‰ĒīŠ§īˆ īŠŊīŠ¸ī‰ąīˆ īŠ”ī‹ŽīŠ¨ī‰ Time$ = "hh:mm:ss" īˆ  īˆ īˆŽī‰ī‹ŽīŠŗī‹Œī‰ŽīŠģī‰īˆ ī‰‚ī‹ˆī‹„īŠŋīˆ ī‰ƒī‰Ļī‰Šī‹īˆ ī‰ī‹ŽīŠŗī‹Œī‰ŽīŠŧīŠģīˆ ī‹’ī‹Žī‰šī‰īˆ–īŠ¯ī‰īˆ ī‹’ī‹€ī‹ŽīŠŗīˆ īŠ”ī‹ŽīŠ¨ī‰ Date$ = "mm/dd/yy" īˆ  īˆ īˆŽī‰Ŗī‹ī‰Šī‰‚ī‰ŽīŠģī‰īˆ ī‰‚ī‹ˆī‹„īŠŋīˆ ī‰ƒī‰Ļī‰Šī‹īˆ ī‰Ŗī‹ī‰Šī‰‚ī‰ŽīŠŧīŠģīˆ ī‹’ī‹Žī‰šī‰īˆ–īŠ¯ī‰īˆ ī‹’ī‹€ī‹ŽīŠŗīˆ īŠ”ī‹ŽīŠ¨ī‰ Var = Time$ īˆ  īˆ ī‰īŠŗī‹ŒīŠŧīŠģīˆ ī‹’ī‹ŽīŠģī‰‚īŠ‡ī‰īˆ ī‹’ī‹€ī‹ŽīŠ´īŠģī‰īˆ ī‹‘ī‹•ī‰ī‰ĒīŠŗ Var = Date$ īˆ  īˆ ī‰Ŗī‹ī‰Šī‰‚ī‰ŽīŠŧīŠģīˆ ī‹’ī‹ŽīŠģī‰‚īŠ‡ī‰īˆ ī‹’ī‹€ī‹ŽīŠ´īŠģī‰īˆ ī‹‘ī‹•ī‰ī‰ĒīŠŗ īˆ  īˆ īˆēī‹‘ī‰Šī‰ī‰ĻīŠģī‰īˆ īŠŊī‹ŽīŠŦī‰˛ī‰īˆ ī‰—īŠŋī‰‚ī‹ƒī‰Ēī‰‰ $regfile = "m128def.dat" $crystal = 8000000 Directives '---------------------- Config Lcdpin = Pin , Db4 = Portc.4 , Db5 = Portc.5 , Db6 = Portc.6 , Db7 = Portc.7 , E = Portc.2 , Rs = Portc.3 īˆ  īˆ Configure the LCD display Config Lcd = 20 * 4 '---------------------- Config Clock = Soft īˆ  īˆ īˆŽīˆ’ī‰‚īŠ¨ī‹€īŠŧīŠģīˆ ī‹’ī‹ŽīŠŧī‰Ąī‰ī‰ĻīŠģī‰īˆ ī‹īŠ´ī‹ŽīŠ´īŠ‡ī‰īˆ ī‰ī‹ŽīŠŗī‹Œī‰ŽīŠģī‰īˆ ī‹’īŠ§ī‰‚ī‰­īˆ īŠąī‹ī‰ĒīŠ¨ī‰ Config Date = Dmy , Separator = / Enable Interrupts īˆ  īˆ ī‹’ī‹„ī‰ŽīŠģī‰/ī‰Ēī‹ˆī‰˛īŠģī‰/ī‹‚ī‹Œī‹ŽīŠģī‰īˆ ī‰Šī‰‚ī‹ˆīŠŖī‰‡īˆ īŠĄīŠ˜īˆ īŠąī‹ī‰ĒīŠ¨ī‰ īˆ  īˆ  Time$ = "16:59:00" Date$ = "14/04/08" īˆ  īˆ ī‰ī‹ŽīŠŗī‹Œī‰ŽīŠģī‰ī‹‹īˆ ī‰Ŗī‹ī‰Šī‰‚ī‰ŽīŠŧīŠģīˆ īˆ¨ī‹‘ī‰Ēī‹ī‰‚īŠ¨īŠŋīˆŠīˆ ī‹’ī‹Žī‹–ī‰ī‰Ļī‰Žī‰‰ī‹œī‰īˆ ī‹ī‹ŽīŠ´īŠģī‰īˆ īŠąī‹ī‰ĒīŠ¨ī‰ ---------------------- Do Print Time$ īˆ  īˆ īˆēī‰‚ī‹ˆī‹ŽīŠ¯īˆ ī‹ī‰Žī‹īˆ ī‹ī‰Žī‹Žī‹–ī‰ĒīŠģī‰īˆ ī‰—īŠŋī‰‚ī‹ƒīˆ•īŠģī‰īˆ ī‹’īŠ´īŠŧī‰™ Print Date$ īˆ  īˆ īˆ’ī‰‚īŠ¨ī‹€īŠŧīŠģīˆ ī‹’ī‹ŽīŠŧī‰ŽīŠŧī‰Žī‰ŽīŠģī‰īˆ ī‹‘ī‰¨īŠ¯ī‰‚ī‹„īŠģī‰īˆ ī‹“īŠŧīŠ§īˆ ī‰Ŗī‹ī‰Šī‰‚ī‰ŽīŠģī‰ī‹‹īˆ ī‰ī‹ŽīŠŗī‹Œī‰ŽīŠģī‰īˆ ī‰Šī‰‚ī‹ˆīŠŖī‰‡ Lcd Time$ : Locate 2 , 1 : Lcd Date$ īˆ ī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰īˆ ī‹’ī‰ąī‰‚ī‰ąīˆ ī‹“īŠŧīŠ§īˆ ī‰Ŗī‹ī‰Šī‰‚ī‰ŽīŠģī‰ī‹‹īˆ ī‰ī‹ŽīŠŗī‹Œī‰ŽīŠģī‰īˆ ī‰žī‰ĒīŠ§ Wait 1 īˆ  īˆ īˆŽī‹’ī‹ŽīŠģī‰‚ī‰Žī‰Žī‹ī‰ĒīŠ¸īŠģī‰ Cls Loop Faculty of Electrical and Electronic Eng. 101 Automatic Control & Automation Dept.
  • 12. ī‹‘ī‰ĒīŠŦī‰ļīŠī‰īˆ ī‰ī‰‚ī‹€īŠ¸ī‰šī‰ŽīŠī‰īˆ ī‹’īŠ‰ī‰Ēī‰‰ īˆ  īˆ  ī‹’ī‰ŽīŠŋī‰‚īŠˆī‰īˆ ī‹’ī‰ŽīŠŧīŠ†ī‰ Exp.16: DAC using Ladder R-2R īˆ  īˆ ī‹ī‹ˆī‰‰ī‰‚ī‰˛ī‰ŽīŠģī‰īˆ ī‹ī‹€īŠŗī‰ĒīŠģī‰īˆ īŠŊī‹ī‹Œī‰šī‰ŽīŠģī‰īˆ īˆēī‹‘ī‰Ēī‰˛īŠ§īˆ ī‹’ī‰­ī‰Ĩī‰‚ī‰ŽīŠģī‰īˆ ī‹’ī‰‰ī‰Ēī‰–ī‰ŽīŠģī‰ īˆ  īˆ īˆēī‹’ī‰‰ī‰Ēī‰–ī‰ŽīŠģī‰īˆ ī‹…īŠŋīˆ ī‹’ī‹ī‰‚īŠŦīŠģī‰ īˆ  īˆ īˆŽī‹ī‹ˆī‰‰ī‰‚ī‰˛ī‰ŽīŠģī‰īˆ ī‹ī‹€īŠŗī‰ĒīŠģī‰īˆ īŠŊī‹ī‹Œī‰šī‰ŽīŠģī‰īˆ ī‰žī‰ī‰ĒīŠĢī‹žīˆ R-2Rīˆ ī‰Šī‰Ĩī‹œīˆ ī‹’īŠ¸ī‰Šī‰ąīˆ ī‹‚ī‰ī‰Ļī‰ĸī‰Žī‰­ī‰ īˆ  īˆ īˆēīŠŊī‹Žī‰ĩī‹Œī‰ŽīŠģī‰īˆ īŠĄī‹ąīŠ‹ īˆ  īˆ  ī‹’ī‰ŽīŠ—ī‹žī‰ī‹‹īˆ ī‹īŠģī‹ ī‰īˆ ī‹īŠ¸ī‰šī‰ŽīŠģī‰īˆ ī‹’ī‰­ī‰Ļī‹„ī‹‡īˆ ī‹ī‰ŽīŠŗ 102 ī‹’ī‹Žī‹ƒī‹‹īˆ–īŠ¸īŠģī‹ĸī‰ī‹‹īˆ ī‹’ī‹Žī‹–ī‰‚ī‰‰ī‰Ēī‹ˆīŠ¸īŠģī‰īˆ ī‹’ī‰­ī‰Ļī‹„īˆšī‰īˆ ī‹’ī‹ŽīŠŧīŠˇ
  • 13. Practical Class 5 Programming Microcontrollers īˆ  īˆ īˆēīŠŊī‹Žī‰ĩī‹Œī‰īˆ ī‰ī‰‚ī‰ŠīŠŧī‹ąī‰ŽīŠŋ īˆ  īˆ īˆŽīˆ’ī‰‚īŠ¨īŠī‰īˆ īŠŠīŠŋīˆ ī‰Šī‰Ĩī‹œīˆ ī‹’īŠ¸ī‰Šī‰ąīˆ īŠŊī‰ĩī‹ŒīŠģīˆ SW37īˆ ī‰ ī‰‚ī‰ŽīŠ°īŠī‰īˆ īŠĸī‰‚īŠ´ī‹ƒīˆ īŠŠī‹ŽīŠšīˆ īŠļī‹īŠĢī‰‡īˆ ī‰‹īŠ īˆŽī‹’ī‹ŽīŠģī‰‚ī‰Žī‰Žī‹ī‰ĒīŠ¸īŠģī‰īˆ ī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰īˆ ī‹’ī‰ąī‰‚ī‰ąīˆ īŠŊī‹ŽīŠŦī‰˛ī‰ŽīŠģīˆ SW2īˆ ī‰ ī‰‚ī‰ŽīŠ°īŠī‰īˆ īŠļī‹īŠĢī‰‡īˆ ī‰‹īŠ īˆ  īˆ īˆēī‹‘ī‰Šī‰ī‰ĻīŠģī‰īˆ īŠŊī‹€īŠ§īˆ ī‰ ī‰Ēī‰ą īˆ īŠ˛ī‹Œī‰­ī‹‹īˆ īˆŦī‰Šī‰Ĩī‹œīˆ ī‹’īŠ¸ī‰Šī‰ąīˆ ī‰˜ī‰Ēī‰Ąīˆ ī‹“īŠŧīŠ§īˆ ī‰Ēī‹ˆīŠ¤ī‹īˆ ī‹ī‹ˆī‰‰ī‰‚ī‰˛ī‰īˆ ī‰Ļī‹ˆī‰•īˆ ī‹…īŠ§īˆ īˆ•īŠ¨ī‰īˆ ī‹’ī‹Žī‹€īŠŗī‰Šīˆ ī‹’ī‹€ī‹ŽīŠŗīˆ ī‰Ļī‹ŽīŠģī‹Œī‰Žī‰‰īˆ ī‹‚ī‹ŒīŠ´ī‹īˆ  ī‰—īŠŋī‰‚ī‹ƒī‰Ēī‰‰īˆ ī‹’ī‰‰ī‰‚ī‰ŽīŠ¸ī‰‰īˆ ī‹‚ī‹ŒīŠ´ī‹ƒīˆ īŠ˛ī‹Œī‰­ īˆ  īˆ īˆŽī‹’ī‹ŽīŠģī‰‚ī‰Žī‰Žī‹ī‰ĒīŠ¸īŠģī‰īˆ ī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰īˆ ī‹’ī‰ąī‰‚ī‰ąīˆ ī‹“īŠŧīŠ§īˆ ī‹‰ī‰šī‰ĒīŠ§ī‹‹īˆ ī‰Ļī‹ˆīŠ†ī‰īˆ ī‰ī‰¨ī‹‡īˆ ī‹’ī‹€ī‹ŽīŠŗīˆ ī‰Œī‰‚ī‰ŽīŠīˆ ī‹‚ī‹ŒīŠ´ī‹ƒ īˆ īˆŦī‹’īŠ¸ī‰Šī‰˛īŠģī‰īˆ  īŠŊī‰Ąī‰ī‰ĻīŠŋīˆ  ī‹…īŠŋīˆ  īŠŊī‰Ąī‰ĻīŠŋīˆ  īŠŊīŠˇīˆ  ī‹“īŠŧīŠ§īˆ  īˆ¨0 or 1īˆŠīˆ  ī‹’ī‹Žī‹€īŠŗī‰Šīˆ  ī‹ī‹ŽīŠŗīˆ  īŠžī‰‚ī‰Ąī‰Ĩī‰‡īˆ  ī‹Œī‹‡īˆ  ī‰Šī‰Ĩī‹œīˆ  ī‹’īŠ¸ī‰Šī‰˛īŠģīˆ  ī‹’ī‹Žī‰­ī‰‚ī‰­ī‹žī‰īˆ  ī‹‘ī‰ĒīŠ¸īŠ°īŠģī‰īˆ  ī‹†ī‰‡ īˆ  īˆ īˆŽī‰‚ī‹ˆīŠŧī‰Ąī‰ī‰ĻīŠŋīˆ ī‹“īŠŧīŠ§īˆ ī‹’īŠ´ī‰Šī‹ąīŠī‰īˆ ī‹’ī‹Žī‹€īŠŗī‰ĒīŠģī‰īˆ ī‹ī‹ŽīŠ´īŠģī‰‚ī‰‰īˆ ī‹‘ī‰Ēī‰ąī‰‚ī‰ŠīŠŋīˆ ī‹’īŠŗī‹īŠ§īˆ ī‰‚īˆšīˆ ī‹’ī‹Žī‹ˆī‰‰ī‰‚ī‰˛ī‰īˆ ī‹’ī‹€ī‹ŽīŠŗīˆ ī‹“īŠŧīŠ§īˆ ī‰‚ī‹ˆī‰•ī‰Ēī‰Ąīˆ īŠŸīˆ īŠžī‹Œī‰ļīŠ‡ī‰ī‹‹ īˆ īˆ 0-255īˆ  ī‹…īŠŋīˆ  ī‰ ī‹‹ī‰īˆ–ī‰Žī‰­īˆ  ī‹’īŠ¸ī‰Šī‰˛īŠģī‰īˆ  īŠŊī‰Ąī‰ī‰ĻīŠŋīˆ  ī‹“īŠŧīŠ§īˆ  ī‹’ī‹Žī‹€īŠŗī‰ĒīŠģī‰īˆ  ī‹ī‹ŽīŠ´īŠģī‰īˆ  ī‹†ī‰ˆīŠ¯īˆ  īˆŦ8-bitīˆ  ī‹’īŠŗī‰Ļī‰‰īˆ  ī‰Šī‰Ĩī‹œīˆ  ī‹’īŠ¸ī‰Šī‰ąīˆ  īŠŊī‰•ī‰ƒīˆ  ī‹…īŠŋīˆ  ī‹‚ī‰‚īŠ§īˆ  īŠŊīŠ¸ī‰˛ī‰‰ īˆŽ 0-5VDCīˆ ī‹’īŠ¸ī‰Šī‰˛īŠģī‰īˆ ī‰˜ī‰Ēī‰Ąīˆ īŠŸīˆ ī‹ĩī‰‚ī‹Žī‹ąī‰Ąīˆ ī‹ĩī‰‚ī‹Žī‹ˆī‰‰ī‰‚ī‰˛ī‰īˆ ī‹ĩī‰ī‰Ļī‹ˆī‰•īˆ ī‰—ī‰Žī‹„ī‹īˆ ī‹Šī‰Šī‹‹ī‰Ļī‰‰īˆ ī‹ī‰¨īŠģī‰ī‹‹īˆ īˆ¨00000000>>11111111īˆŠ V OUT = V REF x VAL / 2N Digital Input 0 ~ 255 Analog Output 0 ~ 5V īˆ  īˆ  īˆ  īˆ  īˆ  īˆ īˆēī‹’ī‹ŽīŠģī‰‚ī‰ŽīŠģī‰īˆ ī‹’īŠŗī‹īŠ¨īŠģī‰‚ī‰‰īˆ ī‹‰ī‰‰ī‰‚ī‰Žī‰™īˆ ī‹…īŠ¸īŠ™īˆ īˆ ī‹’ī‰•ī‰Šī‰Ĩīˆ īŠŊīŠˇīˆ ī‹’ī‹€ī‹ŽīŠŗīˆ ī‹†ī‰ˆīŠ¯īˆ ØŒ8-bitīˆ ī‹’īŠŗī‰Ļī‰‰īˆ ī‰Šī‰Ĩī‹œīˆ ī‹’īŠ¸ī‰Šī‰ąīˆ īŠŊī‰•ī‰ƒīˆ ī‹…īŠŋīˆ ī‹‰ī‹ƒī‰ˆīŠ¯īˆ ī‹īŠģī‰‚ī‰ŽīŠģī‰‚ī‰‰ī‹‹ Vstep = VM / 2N = 5 / 255 = 0.019 Volt īˆ ī‹’ī‰•ī‰Šī‰ĻīŠģī‰īˆ ī‰Ļī‹ˆīŠ€īˆ ī‹ĩī‰‚ī‰‰ī‹‹ī‰Ēī‰ēīŠŋīˆ ī‹’īŠ¸ī‰Šī‰˛īŠģī‰īˆ īŠŊī‰Ąī‰Ĩīˆ ī‹“īŠŧīŠ§īˆ ī‹’ī‹Žī‹€īŠŗī‰ĒīŠģī‰īˆ ī‹’ī‹€ī‹ŽīŠ´īŠģī‰īˆ ī‹…īŠ§īˆ ī‹‘ī‰Šī‰‚ī‰ŠīŠ§īˆ ī‹†ī‹ŒīŠ¸ī‹Žī‰­īˆ ī‹’īŠ¸ī‰Šī‰˛īŠģī‰īˆ ī‰˜ī‰Ēī‰Ąīˆ ī‰Ļī‹ˆī‰•īˆ ī‹†ī‰ˆīŠ¯īˆ ī‹īŠģī‰‚ī‰ŽīŠģī‰‚ī‰‰ī‹‹ īˆ  īˆ īˆŽī‹Šī‹īŠ§ī‰ƒīˆ ī‰Œī‹Œī‰Žīˆī‰īˆ ī‰Ļī‰™ī‰ī‹ŒīŠģī‰ Vout = Digval x V step īˆ  īˆ īˆēīŠŊīŠ¸ī‰˛īŠģī‰‚ī‰‰īˆ ī‰‹īŠīˆ ī‰˜ī‰ĒīŠˆī‰īˆ ī‰Ļī‹ˆī‰•īˆ ī‹†ī‰ˆīŠ¯ 1000 0001=129īˆ ī‹…īŠ¸ī‰ŽīŠģī‹‹īˆ ī‹’īŠ¸ī‰Šī‰˛īŠģī‰īˆ īŠŊī‰Ąī‰Ĩīˆ ī‹“īŠŧīŠ§īˆ ī‹’ī‹Žī‹€īŠŗī‰Šīˆ ī‹’ī‹€ī‹ŽīŠŗīˆ īŠŊī‰•ī‰ƒīˆ ī‹…īŠŋīˆ ī‹īŠģī‰‚ī‰ŽīŠģī‰‚ī‰‰ī‹‹ 129 x 0.019 = 2.451V Faculty of Electrical and Electronic Eng. 103 Automatic Control & Automation Dept.
  • 14. ī‹‘ī‰ĒīŠŦī‰ļīŠī‰īˆ ī‰ī‰‚ī‹€īŠ¸ī‰šī‰ŽīŠī‰īˆ ī‹’īŠ‰ī‰Ēī‰‰ īˆ  īˆ  ī‹’ī‰ŽīŠŋī‰‚īŠˆī‰īˆ ī‹’ī‰ŽīŠŧīŠ†ī‰ īˆ īŠŸīˆ ī‰‚ī‹€īŠˇīˆ  ī‹’īŠ¸ī‰Šī‰˛īŠģī‰īˆ ī‰˜ī‰Ēī‰Ąīˆ īŠŸīˆ īŠžī‰ŦīŠ§īˆ ī‹‘ī‰Šī‰ī‰Ĩīˆ ī‹’īŠ¯ī‰‚ī‰šī‰‡īˆ ī‰‹īŠīˆ ī‹‰ī‹ƒī‰ˆīŠ¯īˆ ī‹’ī‹ŽīŠ´ī‹ŽīŠ´ī‰™īˆ ī‰ī‰‚īŠ´ī‹Žī‰Šī‹ąī‰īˆ īŠ•ī‰‡īˆ ī‰Šī‰Ĩī‹œīˆ ī‹’īŠ¸ī‰Šī‰ąīˆ ī‰˜ī‰Ēī‰Ąīˆ īŠŊī‹Žī‰ĩī‹Œī‰īˆ īŠŊī‰•ī‰ƒīˆ ī‹…īŠŋ īˆ  īˆ īˆēī‹īŠģī‰‚ī‰ŽīŠģī‰īˆ īŠŊīŠ¸ī‰˛īŠģī‰ īˆ  īˆ  īˆ  īˆ  īˆ ī‹†ī‰ƒīˆ ī‰“ī‹ŽīŠīˆ īˆ¨V2īˆŠīˆ īŠŊī‹€īŠ‡ī‰īˆ īŠŠīŠŋīˆ īŠžī‹Œī‰ĩī‹ŒīŠī‰īˆ ī‰Ļī‹ˆīŠ†ī‰ī‹‹īˆ īˆ¨V1īˆŠīˆ ī‹’ī‰Šī‰˛īŠģī‰īˆ ī‰˜ī‰Ēī‰Ąīˆ īŠŸīˆ ī‰Ļī‹ˆīŠ†ī‰īˆ īŠ”ī‰‰īˆ īŠŊī‰ļīŠ°īŠģī‰īˆ ī‹Œī‹‡īˆ īŠžī‰ŦīŠ¨īŠģī‰īˆ ī‹‘ī‰Šī‰ī‰Ĩīˆ ī‹…īŠŋīˆ ī‹’ī‹ī‰‚īŠŦīŠģī‰īˆ ī‹†ī‰‡ īˆ ī‹’īŠŧīŠ¸ī‰˛īŠŋīˆ ī‰‚ī‹„ī‹ī‰ĻīŠģīˆ ī‰Ēī‹ˆīŠ¤ī‹Žī‰­īˆ ī‹…īŠ¸īŠģī‹‹īˆ īˆŽī‰‚ī‹ˆīŠŧī‹€īŠ§īˆ ī‹“īŠŧīŠ§īˆ ī‰Ēī‰‘ī‹›ī‹īˆ ī‹œīˆ ī‹īŠˇīˆ ī‹’īŠ¸ī‰Šī‰˛īŠģī‰īˆ ī‹…īŠŋīˆ ī‹†ī‹ŒīŠ¸ī‹īˆ ī‹œī‹‹īˆ īŠžī‰Ģī‰‚īŠ¨īŠģī‰īˆ ī‹…īŠŋīˆ ī‹†ī‹ŒīŠ¸ī‹īˆ ī‰Šī‰‚ī‹Žī‰ŽīŠģī‰īˆ ī‰Šī‰ī‰Ēī‰–ī‰Žī‰­ī‰ īˆ ī‹‘ī‰Šī‰ī‰ĻīŠģī‰īˆ  īŠŸīˆ  īŠžī‰Ģī‰‚īŠ¨īŠˇīˆ  ī‹ī‰ĸī‰ēīŠī‰īˆ  ī‹‚ī‰ī‰Ļī‰ĸī‰Žī‰­ī‰īˆ  ī‹’ī‰–ī‹Žī‰Žī‹ƒīˆ  īˆ¨ī‹’ī‹Žī‹ąīŠˆī‰īˆ  ī‹‚ī‰ĻīŠ§īˆŠīˆ  ī‹’ī‹ŽīŠ´ī‹ŽīŠ´ī‰™ īˆ  īˆ īˆŽī‹’īŠ´ī‰‰ī‰‚ī‰ŽīŠģī‰ īˆ ī‰Ļī‹ˆīŠ†ī‰īˆ  īŠžī‰‚īˆ‘īˆ  ī‹šī‹‹ī‰‚ī‰ŽīŠŋīˆ  ī‹ī‰ĸī‰ēīŠī‰īˆ  ī‹’ī‹ī‰¨īŠŦī‰īˆ  ī‰Ļī‹ˆī‰•īˆ  ī‹†ī‹ŒīŠˇīˆ  īŠžī‰‚ī‰™īˆ  īŠŸ īˆ  īˆ­1 īˆ ī‹†ī‹ŒīŠ¸ī‹īˆ  ī‹…īŠģīˆ  ī‹ī‰ĸī‰ēīŠī‰īˆ  ī‰˜ī‰Ēī‰Ąīˆ  ī‰Ļī‹ˆī‰•īˆ  ī‹†ī‰ˆīŠ¯īˆ  īˆŦī‹‰īŠŧī‰Ąī‰Ĩīˆ  ī‹“īŠŧīŠ§īˆ  ī‹ī‹€īŠ¤īŠ§ī‹žī‰ īˆ īˆŦīˆ¨0-to-VccīˆŠīˆ  ī‹ī‰ĸī‰ēī‹€īŠŧīŠģīˆ  īŠŊī‰Ąī‰ĻīŠģī‰īˆ  ī‰Ļī‹ˆī‰•īˆ  īŠžī‰‚īŠ‰īˆ  īŠŊīŠŋī‰‚īŠˇīˆ  ī‹“īŠŧīŠ§ īˆ  īˆ īˆŽ4.5Vīˆ ī‹īŠģī‰ī‹Œī‰™īˆ ī‹ī‰ƒīˆ īˆ¨Vcc - 0.5VīˆŠīˆ īŠŊī‹ŽīŠŧīŠ´ī‰‰īˆ īŠŊīŠŗī‰ƒīˆ ī‹†ī‹ŒīŠ¸ī‹Žī‰­īˆ ī‰‚īŠ˜ī‰‡ī‹‹ īˆ ī‰Ļī‹ˆī‰•īˆ īŠžī‰‚īŠ‰īˆ īŠŊīŠŋī‰‚īŠˇīˆ ī‹“īŠŧīŠ§īˆ ī‹ī‹ąī‰Ąīˆ īˆ—īŠĢīˆ ī‹ī‰ĸī‰ēīŠī‰īˆ ī‰˜ī‰Ēī‰Ąīˆ ī‹†ī‰ƒīˆ ī‰‚ī‹€īŠˇ īˆ  īˆ­2 īˆ ī‹’ī‹„ī‹ŽīŠ¨īŠŋīˆ  ī‹’ī‰Šī‰ŽīŠ§īˆ  ī‹“ī‰Žī‰™īˆ  ī‹ĩī‰‚ī‹Žī‹ąī‰Ąīˆ  ī‹†ī‹ŒīŠ¸ī‹Žī‰­īˆ  ī‰‚īŠ˜ī‰‡ī‹‹īˆ  īˆŦī‹ī‰ĸī‰ēī‹€īŠŧīŠģīˆ  ī‰˜ī‰ĒīŠˆī‰ īˆŽīˆ¨3.9Vīˆ ī‰ī‰¨ī‹‡īˆ ī‰‚ī‹„īŠģī‰‚ī‰’īŠŋīˆ īŠŸīˆŠīˆ ī‹‰ī‰ŽīŠ°ī‹ƒīˆ ī‹ī‰ĸī‰ēīŠī‰īˆ ī‰ī‰‚īŠ°ī‰ĩī‰ī‹ŒīŠīˆ ī‹ĩī‰‚īŠ¨ī‰Šī‰ īˆ īŠ•ī‰‡īˆ  ī‹ī‰ĸī‰ēī‹€īŠŧīŠģīˆ ī‹’ī‹ī‰¨īŠŦī‰ŽīŠģī‰īˆ ī‰Ļī‹ˆī‰•īˆ ī‹‘ī‰Ĩī‰‚ī‹ī‰Ŧī‰‰īˆ īŠ•ī‹‹ī‹žī‰īˆ ī‹’īŠŧīŠ¸ī‰˛īŠī‰īˆ ī‹…īŠŋīˆ ī‰ˇīŠŧī‰ĸī‰ŽīŠģī‰īˆ ī‹…īŠ¸īŠ™ īˆ  īˆ īˆŽ5Vīˆ ī‹…īŠŋīˆ ī‹ĩī‹œī‰Ļī‰‰īˆ 6.5V īˆ ī‹’ī‹ī‰ĒīŠ°ī‰ĩīˆ ī‹’ī‹ąīŠ´ī‹ƒīˆ īŠ•ī‰‡īˆ D7īˆ ī‹’ī‹ąīŠ´ī‹„īŠģī‰īˆ īŠŊī‰ĩī‹Œī‰‰īˆ ī‰‚ī‹ˆīŠŧī‰™īˆ ī‹…īŠ¸ī‹€ī‹ŽīŠ¯īˆ ī‹’ī‹Žī‹ƒī‰‚ī‰’īŠģī‰īˆ ī‹’īŠŧīŠ¸ī‰˛īŠī‰īˆ ī‰‚īŠŋī‰ƒ īˆ  īˆ īˆŽīŠĄīŠ´īŠ¯ 0 to 2.5V īˆ ī‰˜ī‰ĒīŠˆī‰īˆ īŠžī‰‚īŠ‰īˆ ī‰œī‰Šī‰ļī‹īˆ ī‹īŠģī‰‚ī‰ŽīŠģī‰‚ī‰‰ī‹‹ ī‹’ī‰ŽīŠ—ī‹žī‰ī‹‹īˆ ī‹īŠģī‹ ī‰īˆ ī‹īŠ¸ī‰šī‰ŽīŠģī‰īˆ ī‹’ī‰­ī‰Ļī‹„ī‹‡īˆ ī‹ī‰ŽīŠŗ 104 ī‹’ī‹Žī‹ƒī‹‹īˆ–īŠ¸īŠģī‹ĸī‰ī‹‹īˆ ī‹’ī‹Žī‹–ī‰‚ī‰‰ī‰Ēī‹ˆīŠ¸īŠģī‰īˆ ī‹’ī‰­ī‰Ļī‹„īˆšī‰īˆ ī‹’ī‹ŽīŠŧīŠˇ
  • 15. Practical Class 5 Programming Microcontrollers 5.5V ~ 12V īˆ  īˆ  īˆ  īˆ īˆēī‹‘ī‰Ļī‹ī‰ĻīŠ†ī‰īˆ ī‰ī‰‚ī‹€ī‹ŽīŠŧīŠ¨ī‰ŽīŠģī‰ īˆ  īˆ īˆŽī‹’ī‹Žī‰šī‰‚ī‹ī‰ĒīŠģī‰īˆ ī‰‹ī‹ī‰ĒīŠ´ī‰ŽīŠģī‰īˆ ī‰ī‰‚ī‹€ī‹ŽīŠŧīŠ¨ī‰īˆ ī‰ŧīŠ¨ī‰‰īˆ ī‰ĒīŠˇī‰§īˆ ī‰Ļī‹ŽīŠ†ī‰īˆ ī‹…īŠŋīˆ ī‹…īŠ¸īŠģī‹‹īˆ ī‹’ī‰‰ī‰Ēī‰–ī‰ŽīŠģī‰īˆ ī‹Šī‰¨ī‹‡īˆ īŠŸīˆ ī‹‘ī‰Ļī‹ī‰Ļī‰•īˆ ī‰ī‰‚ī‹€ī‹ŽīŠŧīŠ¨ī‰īˆ īŠēī‰‚ī‹„ī‹‡īˆ ī‰¯ī‹ŽīŠģ īˆ  īˆ  ī‹’ī‹ŽīŠ‰īˆ•īŠģī‰īˆ ī‹’ī‹€ī‹ŽīŠŧīŠ¨ī‰ŽīŠģī‰ īˆ  īˆ  ī‹’ī‹€ī‹ŽīŠŧīŠ¨ī‰ŽīŠģī‰īˆ ī‰ ī‰Ēī‰ą īˆ  īˆ īˆēīŠžī‰‚ī‰’īŠŋīˆ īˆŽī‹’ī‰šī‹Žī‰šī‰ĩīˆ ī‹’ī‹€ī‹ŽīŠŗīˆ ī‰Œī‰ĒīŠŗī‰ƒīˆ īŠ•ī‰‡īˆ ī‹’ī‰‰ī‰ĒīŠ´īŠŋīˆ īˆ¨xīˆŠīˆ ī‹’ī‹€ī‹ŽīŠ´īŠģī‰īˆ īŠĒī‰‚ī‰•ī‰Šī‰‡ Var = Round(x) Round(2.3) = 2 , Round(2.8) = 3 īˆ  īˆ Round(-2.3) = -2 , Round(-2.8) = -3 Var = Int(source) Ex: Int(134.567)=134 īˆ  īˆ ī‹ī‰Ēī‰ŽīŠˇīˆ ī‰Ĩī‰ĻīŠ¨īŠģīˆ ī‰œī‹Žī‰šī‰ļīŠģī‰īˆ ī‹ī‰ŽīŠ´īŠģī‰īˆ īŠĒī‰‚ī‰•ī‰Šī‰‡ Var = Frac(source) Ex: Frac(134.567)=567 īˆ  īˆ īˆ ī‹ī‰Ēī‰ŽīŠˇīˆ ī‰Ĩī‰ĻīŠ¨īŠģīˆ ī‹ī‰Ēī‰ŽīŠ¸īŠģī‰īˆ ī‹ī‰ŽīŠ´īŠģī‰īˆ īŠĒī‰‚ī‰•ī‰Šī‰‡ Var = Fix(x) EX: Fix(12.98)=12 īˆ  īˆ īˆŽī‰ĒīŠŦī‰ĩī‹žī‰īˆ ī‹’ī‰šī‹Žī‰šī‰ļīŠģī‰īˆ ī‹’ī‹€ī‹ŽīŠ´īŠģī‰īˆ īŠ•ī‰‡īˆ īˆ¨xīˆŠīˆ ī‹ī‰Ēī‰ŽīŠˇīˆ ī‰Ĩī‰ĻīŠ§īˆ ī‰‹ī‹ī‰ĒīŠ´ī‰ Var=-1 ī‹†ī‰ˆīŠ¯ x<0īˆ ī‰ī‹ƒī‰‚īŠˇīˆ ī‰ī‰§ī‰‡īˆ īˆŽīˆ¨xīˆŠīˆ ī‰Ĩī‰ĻīŠ¨īŠģī‰īˆ ī‹‘ī‰Šī‰‚ī‰ąī‰‡īˆ ī‰Ļī‹ī‰ĻīŠ„ Var = Sgn(x) Var=1 ī‹†ī‰ˆīŠ¯ x>0īˆ ī‰ī‹ƒī‰‚īŠˇīˆ ī‰ī‰§ī‰‡ īˆ  īˆ īˆēī‹‘ī‰Šī‰ī‰ĻīŠģī‰īˆ īŠŊī‹ŽīŠŦī‰˛ī‰īˆ ī‰—īŠŋī‰‚ī‹ƒī‰Ēī‰‰ $regfile = "m128def.dat" $crystal = 8000000 īˆ  īˆ īˆŽī‰ī‰‚ī‹ˆī‹Žī‰•ī‹Œī‰ŽīŠģī‰ '----------------------- Config Lcdpin = Pin , Db4 = Portc.4 , Db5 = Portc.5 , Db6 = Portc.6 , Db7 = Portc.7 , E īˆ  īˆ īˆŽī‹īŠ¸ī‰šī‰ŽīŠī‰īˆ īŠŠīŠŋīˆ ī‹’īŠŧī‰ĩī‹ŒīŠī‰īˆ ī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰īˆ ī‹’ī‰ąī‰‚ī‰ąīˆ ī‰Œī‰‚ī‹ąīŠŗī‰ƒīˆ īŠąī‹ī‰ĒīŠ¨ī‰ = Portc.2 , Rs = Portc.3 Config Lcd = 20 * 4 īˆ  īˆ ī‰Šī‰‚ī‹ˆīŠ¤īŠģī‰īˆ ī‹’ī‰ąī‰‚ī‰ąīˆ īŠŊī‹ī‰Ĩī‹ŒīŠŋīˆ īŠąī‹ī‰ĒīŠ¨ī‰ '---------------------- Config Porte = Output īˆ  īˆ īˆŽī‰Šī‰Ĩī‹œīˆ ī‹’īŠ¸ī‰Šī‰ąīˆ īŠŠīŠŋīˆ ī‹’īŠģī‹Œī‰ĩī‹ŒīŠī‰īˆ ī‹’ī‰‰ī‰ī‹Œī‰ŠīŠģī‰īˆ īŠąī‹ī‰ĒīŠ¨ī‰ Digital Alias Porte '----------------------- īˆ  īˆ  Dim I As Byte , V_out As Single Const Vlot_step = 5 / 255 īˆ  īˆ īˆŽī‰ī‹œī‹Œī‰šī‰ŽīŠī‰ī‹‹īˆ ī‰ī‰‰ī‰ī‹Œī‰’īŠģī‰īˆ īŠąī‹ī‰ĒīŠ¨ī‰ '----------------------- Cls Do īˆ  īˆ īˆēī‰‚ī‹ˆī‹ŽīŠ¯īˆ ī‹ī‰Žī‹īˆ ī‹ī‰Žī‹Žī‹–ī‰ĒīŠģī‰īˆ ī‰—īŠŋī‰‚ī‹ƒīˆ•īŠģī‰īˆ ī‹’īŠ´īŠŧī‰™ For I = 0 To 255 Digital = I īˆ īˆ¨ī‰Šī‰Ĩī‹œīˆ ī‹’īŠ¸ī‰Šī‰ąīˆ īŠŊī‰Ąī‰ĨīˆŠīˆ ī‹’ī‰‰ī‰ī‹Œī‰ŠīŠģī‰īˆ ī‰˜ī‰Ēī‰Ąīˆ ī‹“īŠŧīŠ§īˆ ī‹’ī‹Žī‹€īŠŗī‰Šīˆ ī‹ī‹ŽīŠŗīˆ ī‰Ļī‹ŽīŠģī‹Œī‰ V_out = I * Vlot_step Lcd "DAC OUT= " ; V_out īˆ  īˆ īˆŽī‹’īŠ¸ī‰Šī‰˛īŠģī‰īˆ ī‰˜ī‰Ēī‰Ąīˆ ī‹“īŠŧīŠ§īˆ ī‹ī‹ˆī‰‰ī‰‚ī‰˛ī‰īˆ ī‰Ļī‹ˆī‰•īˆ ī‰‚ī‹ˆī‹„īŠ§īˆ ī‰„ī‰˛ī‹„ī‹īˆ īˆžīŠģī‰ī‹‹ Wait 1 : Cls īˆ ī‹’ī‰ąī‰‚ī‰ąīˆ ī‹“īŠŧīŠ§īˆ ī‰‚ī‹ˆī‰šī‰ĒīŠ§ī‹‹īˆ ī‹ī‹ˆī‰‰ī‰‚ī‰˛ī‰ŽīŠģī‰īˆ ī‰˜ī‰ĒīŠˆī‰īˆ ī‰Ļī‹ˆī‰•īˆ ī‹’ī‹€ī‹ŽīŠŗīˆ ī‰Œī‰‚ī‰Žī‰™ Next I Loop īˆ  īˆ īˆŽī‹’ī‹ŽīŠģī‰‚ī‰Žī‰Žī‹ī‰ĒīŠ¸īŠģī‰īˆ ī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰ End Faculty of Electrical and Electronic Eng. 105 Automatic Control & Automation Dept.
  • 16. ī‹‘ī‰ĒīŠŦī‰ļīŠī‰īˆ ī‰ī‰‚ī‹€īŠ¸ī‰šī‰ŽīŠī‰īˆ ī‹’īŠ‰ī‰Ēī‰‰ īˆ  īˆ  ī‹’ī‰ŽīŠŋī‰‚īŠˆī‰īˆ ī‹’ī‰ŽīŠŧīŠ†ī‰ Exp.17: Analog Comparator īˆ  īˆ ī‹ī‹ˆī‰‰ī‰‚ī‰˛ī‰ŽīŠģī‰īˆ ī‹†ī‰Šī‰‚īŠ´īŠī‰īˆ īˆēī‹‘ī‰Ēī‰˛īŠ§īˆ ī‹’īŠ¨ī‰‰ī‰‚ī‰ŽīŠģī‰īˆ ī‹’ī‰‰ī‰Ēī‰–ī‰ŽīŠģī‰ īˆ  īˆ īˆēī‹’ī‰‰ī‰Ēī‰–ī‰ŽīŠģī‰īˆ ī‹…īŠŋīˆ ī‹’ī‹ī‰‚īŠŦīŠģī‰ īˆ  īˆ īˆŽī‹’ī‹Žī‹ˆī‰‰ī‰‚ī‰˛ī‰ŽīŠģī‰īˆ ī‹‘ī‰Šī‰‚ī‰ąī‹ĸī‰īˆ ī‹’ī‹ƒī‰Šī‰‚īŠ´īŠŋīˆ ī‰žī‰ī‰ĒīŠĢī‰ƒīˆ īŠŸīˆ īˆ’ī‰‚īŠ¨ī‹€īŠŧīŠģīˆ ī‹īŠŧī‰Ąī‰ī‰ĻīŠģī‰īˆ ī‹ī‹ˆī‰‰ī‰‚ī‰˛ī‰ŽīŠģī‰īˆ ī‹†ī‰Šī‰‚īŠ´īŠī‰īˆ ī‰Šī‰‚ī‹€ī‰’ī‰Žī‰­ī‰ īˆ  īˆ īˆēīŠŊī‹Žī‰ĩī‹Œī‰ŽīŠģī‰īˆ īŠĄī‹ąīŠ‹ īˆ  īˆ  īˆ  īˆ īˆēīŠŊī‹Žī‰ĩī‹Œī‰īˆ ī‰ī‰‚ī‰ŠīŠŧī‹ąī‰ŽīŠŋ īˆ  īˆ īˆŽSW2īˆ ī‰ ī‰‚ī‰ŽīŠ°īŠī‰īˆ īŠļī‹īŠĢī‰‡īˆ ī‰‹īŠ īˆ  īˆ īˆŽī‹ī‹ˆī‰‰ī‰‚ī‰˛ī‰ŽīŠģī‰īˆ ī‹†ī‰Šī‰‚īŠ´īŠī‰īˆ ī‰Œī‰‚ī‹ąīŠŗī‰ƒīˆ īŠŠīŠŋīˆ ī‰‚ī‹ˆīŠŧī‰ĩī‹‹īˆ ī‰ī‹ŽīŠģīˆ JP11, JP12īˆ īˆ¨JumpersīˆŠīˆ īŠŊī‰ĩī‹ŒīŠģī‰īˆ īˆžī‹ąīŠ´ī‹ƒīˆ īŠŠī‰šī‹‹īˆ ī‰‹īŠ īˆ  īˆ īˆēī‹‘ī‰Šī‰ī‰ĻīŠģī‰īˆ īŠŊī‹€īŠ§īˆ ī‰ ī‰Ēī‰ą īˆ  īˆ īˆŽīŠ”ī‰ŽīŠ°īŠŧī‰ŽīŠ‹īˆ īŠ”ī‰Žī‹Žī‹ˆī‰‰ī‰‚ī‰˛ī‰īˆ īŠ”ī‰ī‰Šī‰‚ī‰ąī‰‡īˆ ī‹’ī‹ƒī‰Šī‰‚īŠ´īŠŋīˆ īŠŊī‰•ī‰ƒīˆ ī‹…īŠŋīˆ īˆ’ī‰‚īŠ¨ī‹€īŠŧīŠģīˆ ī‹ī‹ˆī‰‰ī‰‚ī‰˛ī‰ŽīŠģī‰īˆ ī‹†ī‰Šī‰‚īŠ´īŠī‰īˆ īŠŊī‹ŽīŠŦī‰˛ī‰ŽīŠģīˆ ī‰—īŠŋī‰‚ī‹ƒī‰Ēī‰‰īˆ ī‹’ī‰‰ī‰‚ī‰ŽīŠ¸ī‰‰īˆ ī‹‚ī‹ŒīŠ´ī‹ƒīˆ īŠ˛ī‹Œī‰­ ī‹’ī‰ŽīŠ—ī‹žī‰ī‹‹īˆ ī‹īŠģī‹ ī‰īˆ ī‹īŠ¸ī‰šī‰ŽīŠģī‰īˆ ī‹’ī‰­ī‰Ļī‹„ī‹‡īˆ ī‹ī‰ŽīŠŗ 106 ī‹’ī‹Žī‹ƒī‹‹īˆ–īŠ¸īŠģī‹ĸī‰ī‹‹īˆ ī‹’ī‹Žī‹–ī‰‚ī‰‰ī‰Ēī‹ˆīŠ¸īŠģī‰īˆ ī‹’ī‰­ī‰Ļī‹„īˆšī‰īˆ ī‹’ī‹ŽīŠŧīŠˇ
  • 17. Practical Class 5 Programming Microcontrollers īˆ ī‹“īŠŧīŠ§īˆ īŠĩī‰Šī‹ąīŠī‰īˆ ī‰Ļī‹ˆīŠ†ī‰īˆ ī‹…īŠŋīˆ īˆ•īŠˇī‰ƒīˆ īˆ¨ī‹†ī‰Šī‰‚īŠ´ī‹€īŠŧīŠģīˆ ī‰‹ī‰•ī‹ŒīŠī‰īˆ īŠŊī‰Ąī‰ĻīŠī‰īˆŠīˆ  ANI0īˆ ī‰‹ī‹ąīŠ´īŠģī‰īˆ ī‹“īŠŧīŠ§īˆ īŠĩī‰Šī‹ąīŠī‰īˆ ī‹ī‹ˆī‰‰ī‰‚ī‰˛ī‰ŽīŠģī‰īˆ ī‰Ļī‹ˆīŠ†ī‰īˆ ī‹†ī‹ŒīŠˇīˆ īŠžī‰‚ī‰™īˆ īŠŸ īˆ ī‰Ļī‹ˆīŠ†ī‰īˆ ī‹†ī‹ŒīŠˇīˆ īŠžī‰‚ī‰™īˆ īŠŸīˆ ī‰‚īŠŋī‰ƒī‹‹īˆ īˆŦHighīˆ ī‹”ī‹Œī‰Žī‰ŽīŠī‰īˆ īŠŸīˆ ī‰œī‰Šī‰ļī‹īˆ ī‹†ī‰Šī‰‚īŠ´īŠī‰īˆ ī‰˜ī‰Ēī‰Ąīˆ ī‹†ī‰ˆīŠ¯īˆ īˆ¨ī‹†ī‰Šī‰‚īŠ´ī‹€īŠŧīŠģīˆ  ī‰‹īŠģī‰‚ī‰ŽīŠģī‰īˆ īŠŊī‰Ąī‰ĻīŠī‰īˆŠīˆ  īˆ  AIN1īˆ ī‰‹ī‹ąīŠ´īŠģī‰ īˆ  īˆ īˆŽLowīˆ ī‹”ī‹Œī‰Žī‰ŽīŠī‰īˆ īŠŸīˆ ī‰œī‰Šī‰ļī‹īˆ ī‹†ī‰Šī‰‚īŠ´īŠī‰īˆ ī‰˜ī‰Ēī‰Ąīˆ ī‹†ī‰ˆīŠ¯īˆ AIN0īˆ ī‰‹ī‹ąīŠ´īŠģī‰īˆ ī‹“īŠŧīŠ§īˆ īŠĩī‰Šī‹ąīŠī‰īˆ ī‰Ļī‹ˆīŠ†ī‰īˆ ī‹…īŠŋīˆ īˆ•īŠˇī‰ƒīˆ ANI1īˆ ī‰‹ī‹ąīŠ´īŠģī‰īˆ ī‹“īŠŧīŠ§ īˆ ī‹‹ī‰ƒīˆ īŠŊī‹ŽīŠŦī‰˛ī‰īˆ īŠŊī‰•ī‰ƒīˆ ī‹…īŠŋīˆ ī‹†ī‰ī‰Ŧī‰Ąīˆ īŠŸīˆ īŠŊī‹–ī‰ī‹Œī‰ŽīŠģī‰īˆ ī‹”ī‹Œī‰Žī‰ŽīŠŋīˆ ī‰žī‰‚īŠ°īŠŽī‰īˆ ī‹‹ī‰ƒīˆ  īŠĒī‰‚īŠ°ī‰ī‰Šī‰īˆ ī‰°ī‰‚ī‹ŽīŠŗīˆ ī‰ī‰‚īŠ´ī‹Žī‰Šī‹ąī‰īˆ īŠŸīˆ ī‹†ī‰Šī‰‚īŠ´īŠī‰īˆ ī‰ī‰¨ī‹‡īˆ ī‹‚ī‰ī‰Ļī‰ĸī‰Žī‰­ī‰īˆ ī‹…īŠ¸īŠ™ īˆ  īˆ īˆŽī‹Šī‰‚ī‹ŽīŠī‰īˆ ī‹’ī‰ĸī‰ēīŠŋīˆ īŠ˛ī‰‚īŠ´ī‹ī‰‡ īˆ īŠšīŠŧīŠ™īˆ ī‹ī‹ˆī‰‰ī‰‚ī‰˛ī‰ŽīŠģī‰īˆ ī‹†ī‰Šī‰‚īŠ´īŠī‰īˆ ī‹†ī‰ƒīˆ  ī‰‚ī‹€īŠˇīˆ  1ī‰Ĩī‰ī‰ĻīŠ§/ī‰īŠŗī‹›ī‹€īŠŧīŠģīˆ īŠšī‰ŽīŠī‰īˆ ī‹’ī‰‘ī‰Ĩī‰‚ī‰™īˆ ī‹’īŠ¨ī‰ŋī‰‚īŠ´īŠŋīˆ ī‰ ī‰ĻīŠ´īŠģīˆ ī‹‚ī‰Ļī‰ĸī‰Žī‰Žī‹īˆ ī‹†ī‰ƒīˆ ī‹…īŠ¸īŠ™īˆ ī‹†ī‰Šī‰‚īŠ´īŠī‰īˆ ī‰˜ī‰Ēī‰Ąīˆ ī‹†ī‰‡ īˆ  īˆ īˆŽī‹’ī‹ƒī‰Šī‰‚īŠ´īŠī‰īˆ ī‹•ī‰‚ī‹„ī‰‘ī‰ƒīˆ ī‹’ī‹ˆī‰ŠīŠ†ī‰īˆ īˆ—īŠŦī‰īˆ ī‹‹ī‰ƒīˆ ī‹’ī‹ąī‰‰ī‰‚īˆšī‰īˆ ī‹‹ī‰ƒīˆ ī‹‘ī‰ĻīŠ§ī‰‚ī‰ļīŠģī‰īˆ ī‹’ī‹ˆī‰ŠīŠ†ī‰īˆ ī‹“īŠŧīŠ§īˆ ī‹†ī‹ŒīŠ¸ī‰ŽīŠģīˆ ī‰‚ī‹‡ī‰Ĩī‰ī‰ĻīŠ§ī‰‡īˆ ī‹…īŠ¸īŠ™īˆ ī‹’ī‰ĩī‰‚ī‰Ąīˆ ī‹’īŠ¨ī‰ŋī‰‚īŠ´īŠŋ īˆ  īˆ  īˆ  īˆ īˆēī‹‘ī‰Ļī‹ī‰ĻīŠ†ī‰īˆ ī‰ī‰‚ī‹€ī‹ŽīŠŧīŠ¨ī‰ŽīŠģī‰ īˆ  īˆ īˆŽī‹’ī‹ŽīŠŧī‰Ąī‰ī‰ĻīŠģī‰īˆ ī‹īŠ´ī‹ŽīŠ´īŠ‡ī‰īˆ ī‹…īŠŋī‰ŦīŠģī‰īˆ ī‹’īŠ§ī‰‚ī‰­īˆ īŠŸīˆ ī‹’īŠŋī‰Ļī‰ĸī‰Žī‰ŽīŠī‰īˆ ī‹‘ī‰Ļī‹ī‰ĻīŠ†ī‰īˆ ī‰ī‰‚ī‹€ī‹ŽīŠŧīŠ¨ī‰ŽīŠģī‰īˆ ī‰œī‰šī‹Œī‹īˆ ī‹īŠģī‰‚ī‰ŽīŠģī‰īˆ īŠžī‹‹ī‰ĻīŠ†ī‰ īˆ  īˆ  ī‹’ī‹ŽīŠ‰īˆ•īŠģī‰īˆ ī‹’ī‹€ī‹ŽīŠŧīŠ¨ī‰ŽīŠģī‰ īˆ  īˆ  ī‹’ī‹€ī‹ŽīŠŧīŠ¨ī‰ŽīŠģī‰īˆ ī‰ ī‰Ēī‰ą īˆ ī‰Œī‰‚ī‹ąīŠŗī‰ƒīˆ ī‹…īŠ§īˆ  ī‹ī‹ˆī‰‰ī‰‚ī‰˛ī‰ŽīŠģī‰īˆ  ī‹†ī‰Šī‰‚īŠ´īŠī‰īˆ  īŠŊī‰ļīŠ¯īˆ  |īˆ  īŠŊī‰ĩī‹‹īˆ īˆēīˆ¨Aci=On|offīˆŠ īˆ  īˆ īˆŽīˆ’ī‰‚īŠ¨īŠī‰īˆ ī‹‘ī‰¨īŠ¯ī‰‚ī‹ƒ īˆ īŠĄīŠ˜īˆ  īŠŸīˆ  1ī‰īŠŗī‹›īŠī‰īˆ  ī‹†ī‰ˆīŠ¯īˆ  īˆĸīˆĸīˆ  īŠŊī‰•ī‰ƒīˆ  ī‹…īŠŋīˆ  īˆēīˆ¨Compare=On|offīˆŠ īˆ  īˆ īˆŽī‹ī‹ˆī‰‰ī‰‚ī‰˛ī‰ŽīŠģī‰īˆ ī‹†ī‰Šī‰‚īŠ´īŠī‰īˆ ī‰ ī‰ĻīŠ´ī‰‰īˆ ī‹‚ī‹ŒīŠ´ī‹Žī‰­īˆ īŠšī‰ŽīŠī‰īˆ ī‹’ī‰‘ī‰Ĩī‰‚ī‰™ īˆ  īˆ īˆēī‹†ī‰Šī‰‚īŠ´īŠī‰īˆ ī‹’īŠ¨ī‰ŋī‰‚īŠ´īŠŋīˆ ī‰‚ī‹‡ī‰Ļī‹„īŠ§īˆ īŠŊīŠ¨īŠ°ī‰Žī‰īˆ ī‰ī‹œī‰‚ī‰™īˆ ī‰”ī‹ī‰‘īˆ ī‰Ļī‰•ī‹Œī‹īˆ īˆēīˆ¨TriggerīˆŠ Config Aci= On|off , Compare= On|off , īˆ ī‹’īŠ¨ī‰ŋī‰‚īŠ´īŠŋīˆ  ī‰”ī‰ĻīŠ„īˆ  īŠ˛ī‹Œī‰­ (Ain0 > Ain1) :Rising Trigger = TOGGLE|RISING|FALLING īˆ ī‹“īŠŧīŠ§īˆ ī‰Ļī‹ˆīŠ†ī‰īˆ ī‹…īŠŋīˆ īˆ•īŠˇī‰ƒīˆ īˆĸAin0īˆĸīˆ ī‰‹ī‹ąīŠ´īŠģī‰īˆ ī‹“īŠŧīŠ§īˆ ī‰Ļī‹ˆīŠ†ī‰īˆ ī‰œī‰Šī‰ļī‹īˆ ī‰‚īŠŋī‰Ļī‹„īŠ§ īˆ īˆŽīˆĸAin1īˆĸīˆ ī‰‹ī‹ąīŠ´īŠģī‰ īˆ ī‹’īŠ¨ī‰ŋī‰‚īŠ´īŠŋīˆ ī‰”ī‰ĻīŠ„īˆ īŠ˛ī‹Œī‰­ (Ain0 < Ain1) :Falling īˆ ī‹“īŠŧīŠ§īˆ ī‰Ļī‹ˆīŠ†ī‰īˆ ī‹…īŠŋīˆ ī‰ĒīŠŦī‰ĩī‰ƒīˆ īˆĸAin0īˆĸīˆ ī‰‹ī‹ąīŠ´īŠģī‰īˆ ī‹“īŠŧīŠ§īˆ ī‰Ļī‹ˆīŠ†ī‰īˆ ī‰œī‰Šī‰ļī‹īˆ ī‰‚īŠŋī‰Ļī‹„īŠ§ īˆŽīˆĸAin1īˆĸīˆ ī‰‹ī‹ąīŠ´īŠģī‰ īˆ  īˆ (Ain0 > Ain1 and Ain0 < Ain1) :Toggle Enable Aci īˆ  īˆ īˆŽī‹ī‹ˆī‰‰ī‰‚ī‰˛ī‰ŽīŠģī‰īˆ ī‹†ī‰Šī‰‚īŠ´īŠī‰īˆ ī‹’īŠ¨ī‰ŋī‰‚īŠ´īŠŋīˆ īŠŊī‹ŽīŠ¨īŠ°ī‰ īˆ ī‰—īŠŋī‰‚ī‹ƒī‰Ēī‰‰īˆ  īŠ•ī‰‡īˆ  ī‰ŦīŠ°īŠŗī‰‡īˆ  ī‹ī‹ˆī‰‰ī‰‚ī‰˛ī‰ŽīŠģī‰īˆ  ī‹†ī‰Šī‰‚īŠ´īŠī‰īˆ  ī‹’īŠ¨ī‰ŋī‰‚īŠ´īŠŋīˆ  ī‰īŠŧī‰ļī‰™īˆ  īŠžī‰‚ī‰™īˆ  īŠŸ On Aci label īˆ  īˆ īˆŽīˆĸlabelīˆĸīˆ ī‹’ī‰ŽīŠ¯ī‹īŠģī‰īˆ ī‹…īŠ§īˆ ī‰Ĩī‹Œī‰•ī‹ŒīŠī‰īˆ ī‹’īŠ¨ī‰ŋī‰‚īŠ´īŠī‰ Start Ac īˆ  īˆ īˆŽī‹‰īŠŧī‹€īŠ§īˆ ī‰ƒī‰Ļī‰‰ī‹‹īˆ ī‹ī‹ˆī‰‰ī‰‚ī‰˛ī‰ŽīŠģī‰īˆ ī‹†ī‰Šī‰‚īŠ´īŠī‰īˆ ī‹’ī‹ī‰¨īŠŦī‰ Stop Ac īˆ  īˆ īˆŽī‹’ī‹ī‰¨īŠŦī‰ŽīŠģī‰īˆ ī‹…īŠ§īˆ ī‹‰īŠŧī‰ļīŠ¯ī‹‹īˆ ī‹ī‹ˆī‰‰ī‰‚ī‰˛ī‰ŽīŠģī‰īˆ ī‹†ī‰Šī‰‚īŠ´īŠī‰īˆ īŠ˛ī‰‚īŠ´ī‹ī‰‡ īˆ ī‹ī‰ƒīˆ  ī‹‚ī‰ī‰Ļī‰ĸī‰Žī‰­ī‰īˆ  ī‰Ļī‹„īŠ§īˆ  ī‹‰ī‹„īŠŋīˆ  ī‰Ļī‰‰ī‹œīˆ  ī‹ī‰¨īŠģī‰īˆ  ī‹‚ī‰‚īŠ¨īŠģī‰īˆ  ī‰ī‰‚īŠ¨ī‰ŋī‰‚īŠ´īŠī‰īˆ  ī‹īŠŧīŠ§īˆ  īŠŊī‹ŽīŠ¨īŠ°ī‰ Enable Interrupts īˆ  īˆ īˆŽīˆ’ī‰‚īŠ¨īŠī‰īˆ īŠŸīˆ ī‰Ēī‰ļī‹„īŠ§īˆ ī‹ī‹žīˆ ī‹’īŠ¨ī‰ŋī‰‚īŠ´īŠŋ īˆ īˆ—ī‰Ąī‰„ī‰īˆ ī‹ī‹‡ī‹‹īˆ īˆĸAssemblyīˆĸīˆ īŠŠī‹Žī‹€ī‰–ī‰ŽīŠģī‰īˆ ī‹’īŠŦīŠģīˆ ī‰ī‰‚ī‹€ī‹ŽīŠŧīŠ¨ī‰īˆ ī‹…īŠŋīˆ ī‹’ī‹€ī‹ŽīŠŧīŠ¨ī‰ŽīŠģī‰īˆ ī‹Šī‰¨ī‹‡īˆ  nop īˆ  īˆ īˆŽī‹‘ī‰Ļī‰™ī‰ī‹‹īˆ ī‹’īŠģī‰…īˆ ī‹‘ī‰Šī‹‹ī‰Ĩīˆ ī‰Šī‰ī‰ĻīŠ´īŠ–īˆ īˆŸīŠŋī‰Ģ Faculty of Electrical and Electronic Eng. 107 Automatic Control & Automation Dept.
  • 18. ī‹‘ī‰ĒīŠŦī‰ļīŠī‰īˆ ī‰ī‰‚ī‹€īŠ¸ī‰šī‰ŽīŠī‰īˆ ī‹’īŠ‰ī‰Ēī‰‰ īˆ  īˆ  ī‹’ī‰ŽīŠŋī‰‚īŠˆī‰īˆ ī‹’ī‰ŽīŠŧīŠ†ī‰ īˆ  īˆ īˆēī‹‘ī‰Šī‰ī‰ĻīŠģī‰īˆ īŠŊī‹ŽīŠŦī‰˛ī‰īˆ ī‰—īŠŋī‰‚ī‹ƒī‰Ēī‰‰ $regfile = "m128def.dat" $crystal = 8000000 īˆ  īˆ īˆŽī‰ī‰‚ī‹ˆī‹Žī‰•ī‹Œī‰ŽīŠģī‰ '----------------------- Config Lcdpin = Pin , Db4 = Portc.4 , Db5 = Portc.5 , Db6 = Portc.6 , Db7 = Portc.7 , īˆ  īˆ īˆŽī‹īŠ¸ī‰šī‰ŽīŠī‰īˆ īŠŠīŠŋīˆ ī‹’īŠŧī‰ĩī‹ŒīŠī‰īˆ ī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰īˆ ī‹’ī‰ąī‰‚ī‰ąīˆ ī‰Œī‰‚ī‹ąīŠŗī‰ƒīˆ īŠąī‹ī‰ĒīŠ¨ī‰ E = Portc.2 , Rs = Portc.3 Config Lcd = 20 * 4 īˆ  īˆ ī‰Šī‰‚ī‹ˆīŠ¤īŠģī‰īˆ ī‹’ī‰ąī‰‚ī‰ąīˆ īŠŊī‹ī‰Ĩī‹ŒīŠŋīˆ īŠąī‹ī‰ĒīŠ¨ī‰ Config Aci = On , Compare = Off , Trigger = īˆ ī‰Ļī‹ˆīŠ†ī‰īˆ īˆ—īŠŦī‰īˆ ī‹…īŠ§īˆ ī‰ ī‰ĻīŠ´ī‹īˆ ī‰“ī‹ŽīŠīˆ ī‹ī‹ˆī‰‰ī‰‚ī‰˛ī‰ŽīŠģī‰īˆ ī‹†ī‰Šī‰‚īŠ´īŠī‰īˆ ī‰Ĩī‰ī‰ĻīŠ§ī‰‡ Rising On Aci Isr_aci īˆ  īˆ īˆŽī‹‰ī‹ŽīŠŧī‰Ąī‰ĻīŠŋīˆ ī‹“īŠŧīŠ§ Enable Aci īˆ īŠžī‹Œī‰ļī‰™īˆ ī‰Ļī‹„īŠ§īˆ ī‹†ī‰Šī‰‚īŠ´ī‹€īŠŧīŠģīˆ ī‹’īŠ¨ī‰ŋī‰‚īŠ´īŠī‰īˆ ī‹’īŠŋī‰Ļī‰Ąīˆ ī‰—īŠŋī‰‚ī‹ƒī‰Ēī‰‰īˆ īŠ•ī‰‡īˆ ī‰ŦīŠ°īŠ´īŠģī‰ Start Ac Enable Interrupts īˆ  īˆ īˆŽī‹’īŠ¨ī‰ŋī‰‚īŠ´īŠī‰ '----------------------- īˆ  īˆ ī‹ī‹ˆī‰‰ī‰‚ī‰˛ī‰ŽīŠģī‰īˆ ī‹†ī‰Šī‰‚īŠ´īŠī‰īˆ īŠŊī‹ŽīŠŦī‰˛ī‰ Dim I As Byte '----------------------- Cls īˆ ī‹…īŠ¸īŠ™īˆ ī‹’īŠĢī‰Šī‰‚īŠ¯īˆ ī‹’īŠ´īŠŧī‰™īˆ ī‹ī‹‡ī‹‹īˆ ī‹ī‰Žī‹Žī‹–ī‰ĒīŠģī‰īˆ ī‰—īŠŋī‰‚ī‹ƒīˆ•īŠģī‰īˆ ī‹’īŠ´īŠŧī‰™ Do nop īˆ  īˆ īˆŽī‰Œī‹ŒīŠĢī‰ĒīŠŋīˆ īŠ”ī‰ī‹‹ī‰Šīˆ ī‹ī‰ƒīˆ ī‹’ī‰‰ī‰‚ī‰ŽīŠˇ Loop īˆ  īˆ  End '----------------------- Isr_aci: īˆ  īˆ ī‹ī‹ˆī‰‰ī‰‚ī‰˛ī‰ŽīŠģī‰īˆ ī‹†ī‰Šī‰‚īŠ´īŠī‰īˆ ī‹’īŠ¨ī‰ŋī‰‚īŠ´īŠŋīˆ ī‹’īŠŋī‰Ļī‰Ąīˆ ī‰—īŠŋī‰‚ī‹ƒī‰Ēī‰‰ Cls I = I + 1 īˆ ī‹’ī‰ąī‰‚ī‰ąīˆ ī‹“īŠŧīŠ§īˆ ī‰‚ī‹ˆī‰šī‰ĒīŠ¨ī‹ī‹‹īˆ ī‹ī‹ˆī‰‰ī‰‚ī‰˛ī‰ŽīŠģī‰īˆ ī‹†ī‰Šī‰‚īŠ´īŠī‰īˆ ī‰ī‰‚īŠ¨ī‰ŋī‰‚īŠ´īŠŋīˆ ī‰ĻīŠ¨ī‹ Lcd "change: " ; I īˆ  īˆ ī‰Šī‰‚ī‹ˆīŠŖī‹ĸī‰ Waitms 100 Return īˆ  īˆ  īˆ  īˆ  īˆ  īˆ  ī‹’ī‰ŽīŠ—ī‹žī‰ī‹‹īˆ ī‹īŠģī‹ ī‰īˆ ī‹īŠ¸ī‰šī‰ŽīŠģī‰īˆ ī‹’ī‰­ī‰Ļī‹„ī‹‡īˆ ī‹ī‰ŽīŠŗ 108 ī‹’ī‹Žī‹ƒī‹‹īˆ–īŠ¸īŠģī‹ĸī‰ī‹‹īˆ ī‹’ī‹Žī‹–ī‰‚ī‰‰ī‰Ēī‹ˆīŠ¸īŠģī‰īˆ ī‹’ī‰­ī‰Ļī‹„īˆšī‰īˆ ī‹’ī‹ŽīŠŧīŠˇ