Picbasic Farsi

  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Picbasic Farsi as PDF for free.

More details

  • Words: 12,491
  • Pages: 68
‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫ﻓﺼﻞ ﺍﻭﻝ‪:‬‬

‫‪۱‬‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫‪۲‬‬

‫‪PIC Basic‬‬ ‫ﺳﺎﺩﮔﯽ ﻭﺁﺳﺎﻧﯽ ﻣﻬﻤﺘﺮﻳﻦ ﻭﻳﮋﮔﯽ ﻳﮏ ﺯﺑﺎﻥ ﺑﺮﻧﺎﻣﻪ ﻧﻮﻳﺴﯽ ﺳﻄﺢ ﺑﺎﻻ ﻣﯽ ﺑﺎﺷﺪ ﮐﻪ ﻣﻮﺟﺐ ﺷـﺪﻩ ﺍﺳـﺖ‬ ‫ﺑﻄﻮﺭ ﮔﺴﺘﺮﺩﻩ ﺍﯼ ﺩﺭ ﻣﻴﮑﺮﻭﮐﻨﺘﺮﻟﺮ ﻫﺎ ﺑﺮﺍﯼ ﮐﺎﺭﻫﺎﯼ ﺑﺰﺭﮒ ﺍﺳﺘﻔﺎﺩﻩ ﺷﻮﺩ‪ .‬ﺯﺑﺎﻥ ﺑﺮﻧﺎﻣﻪ ﻧﻮﻳﺴﯽ ﺳﻄﺢ ﺑﺎﻻ‬ ‫ﺑﺎ ﺑﮑﺎﺭﮔﻴﺮﯼ ﺗﻮﺍﺑﻊ ﺁﻣﺎﺩﻩ ﺯﻣﺎﻥ ﺑﺮﻧﺎﻣﻪ ﻧﻮﻳﺴﯽ ﺭﺍ ﮐﻮﺗﺎﻩ ﻣﯽ ﮐﻨﺪ ﻭ ﻫﻤﭽﻨﻴﻦ ﭘﻴﭽﻴﺪﮔﯽ ﺑﺮﻧﺎﻣـﻪ ﺗﻨﻬـﺎ ﺑـﻪ‬ ‫ﻣﻮﺿﻮﻉ ﺍﺻﻠﯽ ﻣﻮﺭﺩ ﻧﻈﺮ ﮐﺎﺭﺑﺮ ﻣﺤﺪﻭﺩ ﻣﯽ ﺷﻮﺩ‪ .‬ﺑﺮﻧﺎﻣﻪ ﻧﻮﻳﺲ ﻣﯽ ﺗﻮﺍﻧﺪ ﺗﻤﺮﮐﺰ ﺑﻴﺸـﺘﺮﯼ ﺑـﺮ ﺭﻭﯼ ﮐـﺎﺭ‬ ‫ﻣﻮﺭﺩ ﻧﻈﺮ ﺧﻮﺩ ﺩﺍﺷﺘﻪ ﺑﺎﺷﺪ ﻭ ﺍﺯ ﺍﺗﻼﻑ ﻭﻗﺖ ﺑﺮ ﺭﻭﯼ ﻧﻮﺷﺘﻦ ﮐﺪﻫﺎﯼ ﺟﺎﻧﺒﯽ ﮐﻪ ﺩﺍﺋﻤـﺎ ﺩﺭ ﭘـﺮﻭﮊﻩ ﻫـﺎﯼ‬ ‫ﻣﺨﺘﻠﻒ ﺗﮑﺮﺍﺭ ﻣﯽ ﺷﻮﺩ ﺟﻠﻮﮔﻴﺮﯼ ﮐﻨﺪ‪ .‬ﻣﺜﻼ ﺩﺭ ﺑﺴﻴﺎﺭﯼ ﺍﺯ ﭘﺮﻭﮊﻫﺎ ﺑﻪ ﺑﺮﻧﺎﻣﻪ ﺑﺮﺍﯼ ﺍﺭﺳﺎﻝ ﺍﻃﻼﻋﺎﺕ ﺑـﻪ‬ ‫ﻗﻄﻌﻪ ﺩﻳﮕﺮ ﻳﺎ ﮐﺎﻣﭙﻴﻮﺗﺮ ﻧﻴﺎﺯ ﺍﺳﺖ ﻭ ﻳﺎ ﻧﻤﺎﻳﺶ ﭘﻴﻐﺎﻣﯽ ﺑﺮ ﺭﻭﯼ ﻧﻤﺎﻳﺸﮕﺮ ‪ LCD‬ﻭﻳﺎ ﺗﻮﻟﻴﺪ ﭘﺎﻟﺲ ‪PWM‬‬ ‫ﻭ ﻏﻴﺮﻩ ﻧﻴﺎﺯ ﺍﺳﺖ ﮐﻪ ﻫﻤﻪ ﺍﻳﻨﻬﺎ ﺑﺼﻮﺭﺕ ﺁﻣﺎﺩﻩ ﺩﺭ ﻳﮏ ﺯﺑﺎﻥ ﺳﻄﺢ ﺑﺎﻻ ﻣﺎﻧﻨﺪ ‪ PIC Basic‬ﻣﻮﺟﻮﺩ ﺍﺳﺖ‪.‬‬ ‫ﺑﺮﺍﯼ ﻧﻮﺷﺘﻦ ﻭﮐﺎﻣﭙﺎﻳﻞ ﮐﺮﺩﻥ ﺑﺮﻧﺎﻣﻪ ‪ PIC Basic‬ﺍﺯ ﻧﺮﻡ ﺍﻓـﺰﺍﺭﯼ ‪ Micro CODE STUDIO‬ﻧﺴـﺨﻪ‬ ‫‪ 1.4‬ﺷﺮﮐﺖ ‪ Mecanique‬ﺍﺳﺘﻔﺎﺩﻩ ﻣﯽ ﮐﻨﻴﻢ ‪ .‬ﺑﺮﻧﺎﻣﻪ ﺧﻮﺩ ﺭﺍ ﺩﺭ ﺍﻳﻦ ﻭﻳﺮﺍﻳﺸﮕﺮ ﻣﯽ ﻧﻮﻳﺴﻴﻢ ﻭ ﺑﺎﭘﺴﻮﻧﺪ‬ ‫‪ .BAS‬ﺫﺧﻴﺮﻩ ﻣﯽ ﮐﻨﻴﻢ ‪ .‬ﺑﺎ ﮐﺎﻣﭙﺎﻳﻞ ﺍﻳﻦ ﺑﺮﻧﺎﻣﻪ ﺩﻭ ﻣﺮﺣﻠﻪ ﭘﺸﺖ ﺳﺮ ﻫﻢ ﺭﻭﯼ ﻣﯽ ﺩﻫﺪ ‪ ،‬ﻣﺮﺣﻠﻪ ﻳـﮏ‬ ‫ﮐﺎﻣﭙﺎﻳﻠﺮ ﻓﺎﻳﻞ ‪ BAS‬ﺭﺍ ﺑﻪ ﮐﺪ ﺍﺳﻤﺒﻠﯽ ﺗﺒﺪﻳﻞ ﻣﯽ ﮐﻨﺪ ﻭ ﺑﺎ ﻫﻤﺎﻥ ﺍﺳﻢ ﻭ ﭘﺴـﻮﻧﺪ ‪ .ASM‬ﺫﺧﻴـﺮﻩ ﻣـﯽ‬ ‫ﮐﻨﺪ ﻭ ﺩﺭ ﻣﺮﺣﻠﻪ ﺑﻌﺪ ﻓﺎﻳﻞ‪ ASM‬ﺗﻮﺳﻂ ﺍﺳﻤﺒﻠﺮ ﺑﻪ ﮐـﺪ ‪ HEX‬ﺗﺒـﺪﻳﻞ ﻣـﯽ ﺷـﻮﺩ ﻭﺑـﺮﺍﯼ ﺭﻳﺨـﺘﻦ ﺩﺭ‬ ‫ﺣﺎﻓﻈﻪ ﺑﺮﻧﺎﻣﻪ ﻧﻮﻳﺴﯽ ﻣﻴﮑﺮﻭﮐﻨﺘﺮﻟﺮ ﺁﻣﺎﺩﻩ ﻣﯽ ﺷﻮﺩ‪ .‬ﻧﺮﻡ ﺍﻓﺰﺍﺭ ‪ Micro CODE STUDIO‬ﺍﺯ ﻃﺮﻳﻖ ﻧﺮﻡ‬ ‫ﺍﻓﺰﺍﺭ ‪ EPIC Win‬ﮐﺪ ‪ HEX‬ﺭﺍ ﺩﺭ ﻣﻴﮑﺮﻭﮐﻨﺘﺮﻟﺮ ﻣﯽ ﺭﻳﺰﺩ‪ .‬ﺩﺭ ﺯﻳﺮ‪ ،‬ﺑﺮﻧﺎﻣﻪ ‪ BLINK‬ﺑﻌﻨﻮﺍﻥ ﻣﺜﺎﻝ ﻧﺸﺎﻥ‬ ‫ﺩﺍﺩﻩ ﺷﺪﻩ ﺍﺳﺖ‪.‬‬

‫ﺷﮑﻞ ‪ (1-1.‬ﺑﺮﻧﺎﻣﻪ ‪ BLINK‬ﺑﻪ ﺯﺑﺎﻥ ﺑﻴﺴﻴﮏ‬

‫‪۳‬‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫ﺷﮑﻞ ‪ (1-2.‬ﺗﺒﺪﻳﻞ ﺑﻪ ﻓﺎﻳﻞ ‪ ، HEX‬ﺑﺮﻧﺎﻣﻪ‬

‫‪BLINK‬‬

‫‪ .۲-۱‬ﻋﻨﺎﺻﺮ ﭘﺎﻳﻪ ﺯﺑﺎﻥ ‪PIC BASIC‬‬

‫‪.۱ -۱-۱‬ﺷﻨﺎﺳﻪ ﻫﺎ‬ ‫ﺷﻨﺎﺳﻪ ﻫﺎ ﺑﺮﺍﯼ ﻧﺎﻣﻴﺪﻥ ﻳﮑﯽ ﺍﺯ ﻋﻨﺎﺻﺮ ‪ PIC BASIC‬ﺍﺳﺘﻔﺎﺩﻩ ﻣﯽ ﺷﻮﺩ‪ .‬ﺷﻨﺎﺳﻪ ﻫﺎ ﻋﻼﻭﻩ ﺑﺮ ﺍﺳـﺘﻔﺎﺩﻩ‬ ‫ﺍﺯ ﺣﺮﻭﻑ ‪ ،‬ﺍﺯ ﺍﻋﺪﺍﺩ ﻧﻴﺰ ﻣﯽ ﺗﻮﺍﻧﺪ ﺍﺳﺘﻔﺎﺩﻩ ﺷﻮﺩ ﺑﺎ ﺍﻳﻦ ﻣﺤـﺪﻭﺩﻳﺖ ﮐـﻪ ﺩﺭﺍﺑﺘـﺪﺍﯼ ﮐﻠﻤـﻪ ﺁﻭﺭﺩﻩ ﻧﺸـﻮﺩ‪.‬‬ ‫ﺷﻨﺎﺳﻪ ﺑﻪ ﮐﻮﭼﮑﯽ ﻳﺎ ﺑﺰﺭﮔﯽ ﺣﺮﻑ ﺣﺴﺎﺱ ﻧﻴﺴﺖ ﻭ ﻃﻮﻝ ﺁﻥ ﺣﺪﺍﮐﺜﺮ ‪ ۳۲‬ﮐﺎﺭﮐﺘﺮ ﻣﯽ ﺑﺎﺷﺪ‪.‬‬ ‫‪Symbol Tester = PORTA.0‬‬ ‫‪Symbol LED_0 = PORTB.0‬‬

‫‪ .۱ -۱-۲‬ﺑﺮﭼﺴﺒﻬﺎ‬ ‫ﺑﺮﺍﯼ ﻣﺸﺨﺺ ﮐﺮﺩﻥ ﺧﻄﯽ ﮐﻪ ﺑﺮﻧﺎﻣﻪ ﺑﻪ ﺁﻧﺠﺎ ﺟﻬﺶ ﻣﯽ ﮐﻨﺪ ﺑﮑﺎﺭ ﻣﯽ ﺭﻭﺩ‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫‪.۱ -۱-۳‬‬

‫‪۴‬‬

‫ﺛﺎﺑﺘﻬﺎ‬ ‫‪Name_constants con value_constants‬‬

‫ﺑﺎ ﺍﻳﻦ ﺩﺳﺘﻮﺭ ﻣﯽ ﺗﻮﺍﻥ ﺑﻪ ﻣﻘﺎﺩﻳﺮ ﺛﺎﺑﺘﯽ ﮐﻪ ﺩﺭ ﺑﺮﻧﺎﻣﻪ ﮐﺎﺭﺑﺮﺩ ﺧﺎﺻﯽ ﺩﺍﺭﻧﺪ ﺍﺳﻢ ﺩﺍﺩ ﺗﺎ ﺑﺮﻧﺎﻣﻪ ﺑـﺎﺯﺧﻮﺍﻧﯽ‬ ‫ﺭﺍﺣﺘﺘﺮﯼ ﺩﺍﺷﺘﻪ ﺑﺎﺷﺪ‬

‫ﺛﺎﺑﺘﻬﺎ ﻣﯽ ﺗﻮﺍﻧﻨﺪ ﺩﺳﻴﻤﺎﻝ ‪ ،‬ﻫﮕﺰﺍﺩﺳﻴﻤﺎﻝ ﻭ ﻳﺎ ﺑﺎﻳﻨﺮﯼ ﺑﺎﺷﺪ ‪ .‬ﺛﺎﺑﺘﻬﺎﯼ ﺩﺳﻴﻤﺎﻝ ﺑﺪﻭﻥ ﭘﺸﻮﻧﺪ ﻧﻮﺷﺘﻪ ﻣﯽ‬ ‫ﺷﻮﺩ ﻭ ﺛﺎﺑﺘﻬﺎﯼ ﻫﮕﺰﺍ ﺩﺳﻴﻤﺎﻝ ﺑﺎ ﭘﻴﺸﻮﻧﺪ ‪ $‬ﻭﺑﺎﻳﻨﺮﯼ ﺑﺎ ‪ %‬ﻧﺸﺎﻥ ﺩﺍﺩﻩ ﻣﯽ ﺷﻮﻧﺪ‪.‬‬

‫‪.۱ -۱-۴‬‬

‫ﻣﺘﻐﻴﺮﻫﺎ‬ ‫‪Name_variable var Type_variable‬‬

‫ﻣﺘﻐﻴﺮﻫﺎ ﺩﺭ ﻣﻮﻗﻌﻴﺘﻬﺎﯼ ‪ RAM‬ﻣﻴﮑﺮﻭﮐﻨﺘﺮﻟﺮ ﺫﺧﻴﺮﻩ ﻣﯽ ﺷﻮﻧﺪ ﻭ ﺑﻪ ﺍﻳﻦ ﻣﻌﻨﯽ ﺍﺳﺖ ﮐﻪ ﺗﻌﺪﺍﺩ ﻣﺘﻐﻴﺮﻫﺎ‬ ‫ﺑﻪ ﺍﻧﺪﺍﺯﻩ ‪ RAM‬ﻣﻴﮑﺮﻭﮐﻨﺘﺮﻟﺮ ﻣﻮﺭﺩ ﻧﻈﺮ ﺑﺴﺘﮕﯽ ﺩﺍﺭﺩ‪ .‬ﺗﻌﺮﻳﻒ ﻣﺘﻐﻴﺮ ﺑﺎ ﮐﻠﻤﻪ ‪ VAR‬ﺻﻮﺭﺕ ﻣﯽ ﮔﻴـﺮﺩ‪.‬‬ ‫‪ PIC BASIC‬ﻣﺘﻐﻴﺮﻫـﺎﯼ ﺍﺯ ﻧــﻮﻉ ‪ ۰) bit‬ﻭ ‪ ۰ ) byte ، ( ۱‬ﺗـﺎ ‪ ( ۲۵۵‬ﻭ ‪ ۰ ) word‬ﺗــﺎ ‪ ( ۶۵۵۳۵‬ﺭﺍ‬ ‫ﭘﺸﺘﻴﺒﺎﻧﯽ ﻣﯽ ﮐﻨﺪ‪.‬‬

‫‪.۱ -۱-۵‬ﺁﺭﺍﻳﻪ ﻫﺎ‬ ‫]‪Name_sequence var type_element [number of the elements‬‬ ‫ﻣﺘﻐﻴﺮ ﺁﺭﺍﻳﻪ ﺍﯼ ﺍﺯ ﺗﻌﺪﺍﺩﯼ ﻣﺘﻐﻴﺮ ﻣﺘﻮﺍﻟﯽ ﺗﺸﮑﻴﻞ ﺷﺪﻩ ﺍﺳﺖ ﮐﻪ ﺑﺎ ﺍﺳﻢ ‪ Type_element‬ﻧﺸـﺎﻥ ﺩﺍﺩﻩ‬

‫ﻣﯽ ﺷﻮﺩ‪ .‬ﺍﻳﻦ ﻣﺘﻐﻴﺮ ﻣﯽ ﺗﻮﺍﻧﺪ ﺑﻴﺘﯽ ﻳﺎ ﺑﺎﻳﺘﯽ ﻭ ﻳﺎ ﮐﻠﻤﻪ ﺑﺎﺷﺪ‪ .‬ﺗﻌﺪﺍﺩ ﻋﻨﺎﺻﺮ ﺁﺭﺍﻳﻪ ﺩﺭ ﺩﺍﺧـﻞ"] [" ﻧﺸـﺎﻥ‬ ‫ﺩﺍﺩﻩ ﻣﯽ ﺷﻮﻧﺪ‪ .‬ﻫﺮ ﻋﻨﺼﺮ ﺑﺎ ﻳﮏ ﺷﺎﺧﺺ ﻣﺸﺨﺺ ﻣﯽ ﺷﻮﺩ ﮐﻪ ﺍﻭﻟﻴﻦ ﻋﻨﺼـﺮ ﺑـﺎ ﺷـﺎﺧﺺ ﺻـﻔﺮ ﻗﺎﺑـﻞ‬ ‫ﺩﺳﺘﺮﺳﯽ ﺍﺳﺖ ﻭﺗﻌﺪﺍﺩ ﺍﻳﻦ ﺷﺎﺧﺼﻬﺎ ﺑﺴﺘﮕﯽ ﺑﻪ ﺣﺎﻓﻈﻪ ‪ RAM‬ﻣﻴﮑﺮﻭﮐﻨﺘﺮﻟﺮ ﺩﺍﺭﺩ‪ .‬ﻣﻘﺪﺍﺭ ﻣﺎﮐﺰﻳﻤﻢ ﺁﺭﺍﻳﻪ‬ ‫ﺩﺭ ﺟﺪﻭﻝ ﺯﻳﺮ ﻧﺸﺎﻥ ﺩﺍﺩﻩ ﺷﺪﻩ ﺍﺳﺖ‪.‬‬

‫‪۵‬‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫ﺍﻧﺪﺍﺯﻩ ﺁﺭﺍﻳﻪ‬ ‫ﺗﻌﺪﺍﺩ ﻣﺎﮐﺰﻳﻤﻢ ﻋﻨﺎﺻﺮ‬

‫ﻧﻮﻉ ﻋﻨﺎﺻﺮ ﺁﺭﺍﻳﻪ‬

‫‪256‬‬

‫‪BIT‬‬

‫*‪96‬‬

‫‪BYTE‬‬

‫*‪48‬‬

‫‪WORD‬‬

‫* ﻭﺍﺑﺴﺘﻪ ﺑﻪ ﻧﻮﻉ ﻣﻴﮑﺮﻭﮐﻨﺘﺮﻟﺮ‬

‫ﺟﺪﻭﻝ ‪۱ -۱‬‬

‫‪ ۱۰‬ﺍﻟﻤﺎﻥ ﭘﺸﺖ ﺳﺮﻫﻢ ﺍﺯ ﻧﻮﻉ ‪) byte‬ﺁﺭﺍﻳﻪ ‪۱۰‬‬

‫ﺍﻟﻤﺎﻧﻪ('‬

‫]‪Sequence1 var byte[10‬‬

‫]‪ Sequence1[0‬ﺍﻭﻟﻴﻦ ﻋﻨﺼﺮ ﺁﺭﺍﻳﻪ ﺭﺍ ﺩﺭ ﺑﺮ ﺩﺍﺭﺩ ﻭ ]‪ Sequence1[9‬ﺁﺧﺮﻳﻦ ﻋﻨﺼﺮ ﺭﺍ ﺩﺭ ﺑﺮ ﺩﺍﺭﺩ‪.‬‬ ‫‪.۱ -۱-۶‬‬

‫ﺍﺻﻼﺡ ﮐﻨﻨﺪﻩ ﻫﺎ‬ ‫‪new_name var old_name‬‬

‫ﺑﻮﺳﻴﻠﻪ ﺍﺻﻼﺡ ﮐﻨﻨﺪﻩ ﻫﺎ ﺍﻳﻦ ﺍﻣﮑﺎﻥ ﺍﻳﺠﺎﺩ ﻣﯽ ﺷﻮﺩ ﮐﻪ ﺍﺳﻢ ﺟﺪﻳﺪﯼ ﺑﺮﺍﯼ ﻣﺘﻐﻴﺮ ﺍﺯ ﻗﺒﻞ ﺗﻌﺮﻳـﻒ ﺷـﺪﻩ‬ ‫ﺍﻧﺘﺨﺎﺏ ﮐﻨﻴﻢ‪ .‬ﺍﻳﻦ ﺩﺳﺘﻮﺭ ﺑﻨﺪﺭﺕ ﺍﺳﺘﻔﺎﺩﻩ ﻣﯽ ﺷﻮﺩ‪.‬‬

‫‪.۱ -۱-۷‬‬

‫ﺳﻤﺒﻠﻬﺎ‬ ‫‪symbol old_name = new_name‬‬

‫ﺳﻤﺒﻠﻬﺎ ﺷﺒﻴﻪ ﺍﺻﻼﺡ ﮐﻨﻨﺪﻩ ﻫﺎ ﺍﺳﻢ ﺟﺪﻳﺪﯼ ﺍﺯ ﻳﮏ ﻣﺘﻐﻴﺮ ﻳﺎ ﻳﮏ ﺛﺎﺑﺖ ﺭﺍ ﺑﻪ ﻳﮏ ﺍﺳﻢ ﻗـﺪﻳﻤﯽ ﻧﺴـﺒﺖ‬ ‫ﻣﯽ ﺩﻫﻨﺪ‪.‬‬

‫ﺩﺳﺘﻮﺭ ‪INCLUDE‬‬

‫‪.۱ -۱-۸‬‬ ‫ﺩﺳﺘﻮﺭ ‪ INCLUDE‬ﺑﺮﺍﯼ ﻭﺍﺭﺩ ﮐﺮﺩﻥ ﻳﮏ ﺑﺨﺶ ﺍﺯ ﻓﺎﻳﻞ ‪ BASIC‬ﺑﮑﺎﺭ ﻣﯽ ﺭﻭﺩ‪ .‬ﺩﺭ ﺍﻳﻦ ﻓﺎﻳـﻞ ﻣﻤﮑـﻦ‬ ‫ﺍﺳﺖ ﭼﻨﺪﻳﻦ ﺗﻌﺮﻳﻒ ﺍﺯ ﻣﺘﻐﻴﺮﻫﺎ ﻭ ﻳﺎ ﺯﻳﺮﺑﺮﻧﺎﻣﻪ ﻫﺎ ﺫﺧﻴﺮﻩ ﺷﺪﻩ ﺑﺎﺷﺪ ﮐﻪ ﺩﺭ ﻗﺴﻤﺘﻬﺎﯼ ﻣﺨﺘﻠـﻒ ﺑﺮﻧﺎﻣـﻪ‬ ‫ﺑﮑﺎﺭ ﺭﻓﺘﻪ ﺑﺎﺷﺪ‪ .‬ﺍﺳﺘﻔﺎﺩﻩ ﺍﺯ ﺯﻳﺮ ﺑﺮﻧﺎﻣﻪ ﻫﺎ ﻭ ﻣﺘﻐﻴﺮﻫﺎﯼ ﻓﺎﻳﻞ ﺍﻟﺤﺎﻗﯽ ﺷﺒﻴﻪ ﺍﻳﻦ ﺍﺳﺖ ﮐﻪ ﺍﻳﻦ ﺯﻳﺮﺑﺮﻧﺎﻣـﻪ‬ ‫ﻫﺎ ﻭ ﻣﺘﻐﻴﺮﻫﺎ ﺭﺍ ﺧﻮﺩﺗﺎﻥ ﺩﺭ ﺑﺮﻧﺎﻣﻪ ﻧﻮﺷﺘﻪ ﺍﻳﺪ‪.‬‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫‪۶‬‬

‫ﺗﻮﺿﻴﺤﺎﺕ‬ ‫‪.۱ -۱-۹‬‬ ‫ﺗﻮﺿﻴﺤﺎﺕ ﺑﺮﺍﯼ ﺑﻬﺘﺮ ﻓﻬﻤﻴﺪﻥ ﺑﺮﻧﺎﻣﻪ ﺑﮑﺎﺭ ﺑﺮﺩﻩ ﻣﯽ ﺷﻮﺩ‪ .‬ﻭ ﺑﺮﺍﯼ ﺍﺳﺘﻔﺎﺩﻩ ﺍﺯ ﺁﻥ ﺍﺯ ﻋﻼﻣﺖ " ' " ﺍﺳﺘﻔﺎﺩﻩ‬ ‫ﻣﯽ ﮐﻨﻴﻢ‬ ‫‪ .۱ -۱-۱۰‬ﺧﻂ ﺑﺮﻧﺎﻣﻪ ﺑﺎ ﺩﺳﺘﻮﺭﺍﺕ ﺑﻴﺸﺘﺮ‬ ‫ﺑﺮﺍﯼ ﻣﺘﺮﺍﮐﻢ ﮐﺮﺩﻥ ﻭ ﺩﻳﺪ ﺑﻴﺸﺘﺮ ﻳﮏ ﺑﺮﻧﺎﻣﻪ ﻣﯽ ﺗﻮﺍﻥ ﺩﺳﺘﻮﺭﺍﺕ ﺭﺍ ﺩﺳﺘﻪ ﺑﻨﺪﯼ ﮐﺮﺩ ﻭﻫﺮ ﺩﺳـﺘﻪ ﺭﺍ ﺩﺭ‬ ‫ﻳﮏ ﺧﻂ ﺟﺎﯼ ﺩﺍﺩ‪ .‬ﻭﺑﺎ ﻋﻼﻣﺖ " ‪ " :‬ﺩﺳﺘﻮﺭﺍﺕ ﺩﺭ ﻳﮏ ﺧﻂ ﺍﺯ ﻳﮑﺪﻳﮕﺮ ﺟﺪﺍ ﻣﯽ ﺷﻮﻧﺪ‪.‬‬ ‫‪B2 = B0‬‬ ‫‪B0 = B1‬‬ ‫‪B1 = B2‬‬

‫ﺳﻪ ﺩﺳﺘﻮﺭ ﺑﺎﻻ ﻣﯽ ﺗﻮﺍﻧﻨﺪ ﺩﺭ ﻳﮏ ﺧﻂ ﻗﺮﺍﺭ ﺑﮕﻴﺮﻧﺪ‪.‬‬ ‫‪B2 = B0 : B0 = B1 : B1 = B2‬‬

‫‪ .۱ -۱-۱۱‬ﺍﻧﺘﻘﺎﻝ ﻳﮏ ﺩﺳﺘﻮﺭ ﺑﻪ ﺧﻂ ﺩﻳﮕﺮ‬ ‫ﮔﺎﻫﯽ ﺍﺗﻔﺎﻕ ﻣﯽ ﺍﻓﺘﺪ ﮐﻪ ﻳﮏ ﺩﺳﺘﻮﺭ ﺑﻴﺸﺘﺮ ﺍﺯ ﺍﻧﺪﺍﺯﻩ ﻳﮏ ﺧﻂ ﻧﻴﺎﺯ ﺩﺍﺭﺩ ﻭ ﻳـﺎ ﺑـﺮﺍﯼ ﺭﻭﻳـﺖ ﺑﻬﺘـﺮ ﻻﺯﻡ‬ ‫ﺍﺳﺖ ﺩﻧﺒﺎﻟﻪ ﺩﺳﺘﻮﺭ ﺩﺭ ﺧﻂ ﺑﻌﺪﯼ ﺑﺎﺷﺪ ﺑﺮﺍﯼ ﺍﻳـﻦ ﮐـﺎﺭ ﺍﺯ ﻋﻼﻣـﺖ " _ " ﺍﺳـﺘﻔﺎﺩﻩ ﻣـﯽ ﮐﻨـﻴﻢ‪ .‬ﺑـﺮﺍﯼ‬ ‫ﺩﺳﺘﻮﺭﺍﺕ ‪ brunch ، lookup‬ﻭ ‪ sound‬ﺑﻴﺸﺘﺮ ﻣﻤﮑﻦ ﺍﺳﺖ ﺍﻳﻦ ﺣﺎﻟﺖ ﭘﻴﺶ ﺑﻴﺎﻳﺪ‪.‬‬ ‫_‪lookup KeyPress,["1","4","7","*","2","5","8","0","3",‬‬ ‫‪"6","9","#","N"],var1‬‬

‫‪.۱ -۱-۱۲‬‬

‫ﺗﻌﺮﻳﻒ ) ‪( DEFINE‬‬ ‫‪DEFINE the value parameter‬‬

‫ﺩﺳﺘﻮﺭﺍﺕ ﺯﺑﺎﻥ ‪ PIC BASIC‬ﺩﺍﺭﺍﯼ ﭘﺎﺭﺍﻣﺘﺮﻫﺎﯼ ﻫﺴﺘﻨﺪ ﮐﻪ ﺍﺯ ﭘﻴﺶ ﺗﻌﺮﻳﻒ ﺷﺪﻩ ﺍﺳﺖ ﻭ ﻣﯽ ﺗﻮﺍﻥ ﺑـﺎ‬ ‫ﺍﻳﻦ ﺩﺳﺘﻮﺭ ﭘﺎﺭﺍﻣﺘﺮﻫﺎﯼ ﺍﺯ ﭘﻴﺶ ﺗﻌﻴﻴﻦ ﺷﺪﻩ ﺁﻧﻬﺎ ﺭﺍ ﺗﻐﻴﻴﺮ ﺩﺍﺩ‪ .‬ﺑﺮﺍﯼ ﻣﺜﺎﻝ ﻓﺮﮐﺎﻧﺲ ﺍﺳﻴﻼﺗﻮﺭ ﺍﺯ ﭘﻴﺶ‬

‫‪۷‬‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫ﺗﻌﺮﻳﻒ ﺷﺪﻩ ‪ ۴‬ﻣﮕﺎ ﻫﺮﺗﺰ ﻣﯽ ﺑﺎﺷﺪ ﺩﺭ ﻧﺘﻴﺠﻪ ﺑﺴﻴﺎﺭﯼ ﺍﺯ ﺩﺳﺘﻮﺭﺍﺕ ﮐﻪ ﻭﺍﺑﺴﺘﻪ ﺑﻪ ﮐﻼﮎ ﺍﺳـﻴﻼﺗﻮﺭ ﻣـﯽ‬ ‫ﺑﺎﺷﻨﺪ ﺧﻮﺩ ﺭﺍ ﺑﺎ ﻓﺮﮐﺎﻧﺲ ‪ ۴‬ﻣﮕﺎ ﻫﺮﺗﺰ ﺗﻨﻈﻴﻢ ﻣﯽ ﮐﻨﻨﺪ ﻭ ﺍﮔﺮ ﺍﺳﻴﻼﺗﻮﺭ ‪ ۱۲‬ﻣﮕﺎ ﻫﺮﺗﺰ ﻗﺮﺍﺭ ﺩﺍﺩﻩ ﺷﻮﺩ ﮐﺎﺭ‬ ‫ﺍﻳﻦ ﺩﺳﺘﻮﺭﺍﺕ ﺍﺯ ﺣﺎﻟﺖ ﺗﻨﻈﻴﻢ ﺷﺪﻩ ﺩﺭ ﻣﯽ ﺁﻳﺪ‪ .‬ﺑﻨﺎﺑﺮﺍﻳﻦ ﺑﺎ ﺍﻳﻦ ﺩﺳﺘﻮﺭ ﺑﺮﺍﺣﺘـﯽ ﻓﺮﮐـﺎﻧﺲ ﺍﺳـﻴﻼﺗﻮﺭ ﺭﺍ‬ ‫ﺗﻌﻴﻴﻦ ﻣﯽ ﮐﻨﻴﻢ‪ .‬ﺑﻪ ﺟﺪﻭﻝ ‪ ۲-۲‬ﻣﺮﺍﺟﻌﻪ ﮐﻨﻴﺪ‪.‬‬ ‫‪.۱ -۱-۱۳‬‬ ‫ﻗﺒﻞ ﺍﺯ ﻭﺍﺭﺩ ﮐﺮﺩﻥ ﺯﻳﺮ ﺑﺮﻧﺎﻣﻪ ﻭﻗﻔﻪ ‪ ،‬ﻻﺯﻡ ﺍﺳﺖ ﮐﻪ ﻭﻗﻔﻪ ﻫﺎ ﻏﻴﺮ ﻓﻌﺎﻝ ﺷﻮﻧﺪ ﺗﺎ ﺍﺯ ﻭﻗﻔﻪ ﺟﺪﻳﺪ ﺟﻠﻮﮔﻴﺮﯼ‬ ‫ﺷﻮﺩ‪ .‬ﺑﻪ ﻋﺒﺎﺭﺕ ﺩﻳﮕﺮ ﺩﺳﺘﻮﺭ ‪ DISABLE‬ﺑﻴﺖ ‪ GIE‬ﺭﺍ ﺍﺯ ﺭﺟﻴﺴﺘﺮ ‪ INTCON‬ﺑﺎﺯﻧﺸﺎﻧﺪﻩ ﻣﯽ ﮐﻨﺪ‪.‬‬ ‫‪Desable‬‬ ‫ﻏﻴﺮ ﻓﻌﺎﻝ ﮐﺮﺩﻥ ﺍﻳﻨﺘﺮﺍﭘﺘﻬﺎ '‬ ‫‪DISABLE‬‬

‫‪Myint:‬‬ ‫‪led = 1‬‬ ‫‪….‬‬ ‫‪Resume‬‬ ‫‪Enable‬‬

‫‪.۱ -۱-۱۴‬‬ ‫ﺑﻌﺪ ﺍﺯ ﺍﺗﻤﺎﻡ ﺍﺟﺮﺍﯼ ﺯﻳﺮ ﺑﺮﻧﺎﻣﻪ ﻭﻗﻔﻪ ‪ ،‬ﻭﻗﻔﻪ ﺑﺎﻳﺴﺘﯽ ﺩﻭﺑﺎﺭﻩ ﻓﻌﺎﻝ ﺷﻮﺩ ﮐﻪ ﺑﺎ ﺩﺳﺘﻮﺭ ‪ ENABLE‬ﺻـﻮﺭﺕ‬ ‫ﻣﯽ ﮔﻴﺮﺩ‪ .‬ﺩﺭ ﻭﺍﻗﻊ ﺑﻴﺖ ‪ GIE‬ﻧﺸﺎﻧﺪﻩ ﻣﯽ ﺷﻮﺩ‪.‬‬ ‫‪ENABLE‬‬

‫‪.۱ -۱-۱۵‬‬

‫‪ON INTERRUPT‬‬ ‫‪On interrupt LABEL‬‬

‫ﺑﺎ ﺍﻳﻦ ﺩﺳﺘﻮﺭ ﺑﺮ ﭼﺴﺐ ﻣﮑﺎﻧﯽ ﺭﺍ ﮐﻪ ﻫﻨﮕﺎﻡ ﺭﻭﯼ ﺩﺍﺩﻥ ﻭﻗﻔﻪ ﺑﻪ ﺁﻧﺠﺎ ﭘﺮﺵ ﺻﻮﺭﺕ ﻣﯽ ﮔﻴﺮﺩ ﺭﺍ ﻣﺸﺨﺺ‬ ‫ﻣﯽ ﮐﻨﺪ‪ .‬ﺑﺮﭼﺴﺐ ﺩﺭ ﺍﺑﺘﺪﺍﯼ ﺯﻳﺮ ﺑﺮﻧﺎﻣﻪ ﻭﻗﻔﻪ ﻗﺮﺍﺭ ﺩﺍﺭﺩ‪.‬‬

DEFINE ‫ﮊﻭﭘﻴﻦﺍﺯ ﺩﺳﺘﻮﺭ‬ ‫ﺍﺳﺘﻔﺎﺩﻩ‬ ‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ‬

۸ ‫ﭘﺎﺭﺍﻣﺘﺮﻫﺎ‬ I2C_HOLD

‫ﺗﻮﺿﻴﺤﺎﺕ‬

1

I2C_INTERNAL

I2C_SCLOUT

1

1

‫ﺍﻳﻦ ﺣﺎﻟﺖ ﺭﻭﯼ ﮐﺪﺍﻡ ﺩﺳﺘﻮﺭ ﺻﻮﺭﺕ ﻣﯽ ﻳﺮﺩ‬

pause 12C transfer while the tact is on a low level

I2COUT, I2COUT

internal EEPROM in series 16Cexxx and 12Cxxx of the PIC microcontroller

I2COUT, I2COUT

serial tact is a bipolar at the place of an open collector

I2CWRITE, I2CREAD

I2C_SLOW

1

for the tact > BMHz OSC with the devices of a standard velocity

I2CWRITE, I2CREAD

LCD_DREG

PORTD

LCD data port

LCDOUT, LCDIN

Initial bit of a data 0 or 4

LCDOUT, LCDIN

RS (Register select) port

LCDOUT, LCDIN

RS (Register select) pin

LCDOUT, LCDIN

enable port

LCDOUT, LCDIN

enable bit

LCDOUT, LCDIN

read/write port

LCDOUT, LCDIN

read/write bit

LCDOUT, LCDIN

No of LCD lines

LCDOUT, LCDIN

LCD_DBIT

0

LCD_RSREG

PORTD

LCD_RSBIT

4

LCD_EREG LCD_EBIT

PORTD 3

LCD_RWREG

PORTD

LCD_RWBIT LCD_LINES

2 2

LCD_INSTRUCTIONUS

LCD_DATAUS

OSC

the time of delay of 2000 instruction in microseconds (us)

the time of delay of data in LCDOUT, LCDIN microseconds

50

tact of the oscillator in all instructions of the serial MHz: 3(3.58) 4 8 10 12 16 transfer and next pause 20 25 32 33 40

4

OSCCAL_1K

1

setting of OSCCAL for PIC12C671/CE673 microcontrollers

OSCCAL_2K

1

the number of data bits

SER2_BITS

LCDOUT, LCDIN

8

SHIFT_PAUSEUS BUTTON_PAUSE CHAR_PACING

50

the slowing of the tact of transfer

SHIFTOUT, SHIFTIN

instruction LFSR in 18Cxxx microcontrollers

LFSR

10

BUTTON

1000

SEROUT, SERIN

HSER_BAUD

2400

HSEROUT, HSERIN

HSER_SPBRG

25

HSEROUT, HSERIN 1-2

‫ﺟﺪﻭﻝ‬

‫‪۹‬‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫‪RESUME .۱ -۱-۱۶‬‬ ‫ﺑﺎﺯﮔﺸﺖ ﺍﺯ ﺯﻳﺮ ﺑﺮﻧﺎﻣﻪ ﻭﻗﻔﻪ ﺭﺍ ﺑﻪ ﺑﺮﻧﺎﻣﻪ ﺍﺻﻠﯽ ﺑﺮ ﻋﻬﺪﻩ ﺩﺍﺭﺩ‬

‫‪ .۱-۲‬ﻋﻤﻠﮕﺮﻫﺎ‬ ‫‪.۱ -۲-۱‬ﻋﻤﻠﮕﺮﻫﺎﯼ ﺭﻳﺎﺿﯽ‬ ‫ﻋﻤﻠﮕﺮﻫﺎﯼ ﺭﻳﺎﺿﯽ ﺑﺎ ﺩﻗﺖ ‪ ۱۶‬ﺑﻴﺘﯽ ﺑﺎ ﻣﻘﺎﺩﻳﺮ ﺑﺪﻭﻥ ﻋﻼﻣﺖ ) ‪ ۰‬ﺗﺎ ‪ ( ۶۵۵۳۵‬ﮐﺎﺭ ﻣﯽ ﮐﻨﻨﺪ‪.‬‬ ‫)‪A = (B + C) * (D - E‬‬

‫ﺟﺪﻭﻝ ﺯﻳﺮ ﻋﻤﻠﮕﺮﻫﺎﯼ ﺭﻳﺎﺿﯽ ﮐﻪ ‪ PIC BASIC‬ﭘﺸﺘﻴﺒﺎﻧﯽ ﻣﯽ ﮐﻨﺪ ﺭﺍ ﻧﺸﺎﻥ ﻣﯽ ﺩﻫﺪ‪.‬‬ ‫ﺷﺮح ﻋﻤﻠﮕﺮﻫﺎ‬ ‫ﺷﺮﺡ‬

‫ﻋﻤﻠﮕﺮ‬

‫ﺷﺮﺡ‬

‫ﻋﻤﻠﮕﺮ‬

‫ﻗﺪﺭ ﻣﻄﻠﻖ ﻳﮏ ﻋﺪﺩ‬

‫‪ABS‬‬

‫ﺟﻤﻊ‬

‫‪+‬‬

‫ﮐﺴﯿﻨﻮس ﯾﮏ زاوﯾﻪ‬

‫‪COS‬‬

‫ﺗﻔﺮﻳﻖ‬

‫‪-‬‬

‫ﺩﻳﮑﺪ ﮐﺮﺩﻥ ﺑﻴﺘﯽ‬

‫‪DCD‬‬

‫ﺿﺮﺏ‬

‫*‬

‫ﻣﻘﺪﺍﺭ ﻳﮏ ﺭﻗﻢ ﺍﺯ ﻳﮏ ﻋﺪﺩ ﺩﺳﻴﻤﺎﻝ‬

‫‪DIG‬‬

‫ﻧﺘﺎﻳﺞ ﺩﺭ ‪ ۱۶‬ﺑﻴﺖ ﺑﺎﻻ ﻗﺮﺍﺭ ﻣﯽ ﮔﻴﺮﺩ‬

‫**‬

‫ﻣﺎﮐﺰﻳﻤﻢ ﺩﻭ ﻋﺪﺩ‬

‫‪MAX‬‬

‫ﻧﺘﺎﻳﺞ ﺩﺭ ‪ ۱۶‬ﺑﻴﺖ ﺑﺎﻻ ﻗﺮﺍﺭ ﻣﯽ ﮔﻴﺮﺩ‬

‫‪*/‬‬

‫ﻣﻴﻨﻴﻤﻢ ﺩﻭﻋﺪﺩ‬

‫‪MIN‬‬

‫ﺗﻘﺴﻴﻢ‬

‫‪/‬‬

‫ﮐﺪﻳﻨﮓ ﺑﺮ ﺍﺳﺎﺱ ﺣﻖ ﺗﻘﺪﻡ‬

‫‪NCD‬‬

‫ﺑﺎﻗﻴﻤﺎﻧﺪﻩ‬

‫‪//‬‬

‫ﺑﺮﮔﺮﺩﺍﻧﺪﻥ ﺑﻴﺖ‬

‫‪REV‬‬

‫ﺷﻴﻔﺖ ﺑﻪ ﭼﭗ‬

‫<<‬

‫ﺳﻴﻨﻮﺱ ﻳﮏ ﺯﺍﻭﻳﻪ‬

‫‪SIN‬‬

‫ﺷﻴﻔﺖ ﺑﻪ ﺭﺍﺳﺖ‬

‫>>‬

‫ﺭﻳﺸﻪ ﺩﻭﻡ ﻳﮏ ﻋﺪﺩ‬

‫‪SQR‬‬

‫ﺍﻧﺘﻘﺎﻝ ﻣﻘﺪﺍﺭ‬

‫=‬

‫ﺟﺪﻭﻝ ‪(۱-۳‬‬

‫ﻧﮑﺎﺕ ﻭ ﻣﺜﺎﻟﻬﺎ‪:‬‬ ‫ﺿﺮﺏ ‪ PIC BASIC :‬ﺍﺯ ﺿﺮﺏ ﺍﻋﺪﺍﺩ ﺑﻄﻮﺭ ﮐﺎﻣﻞ ﭘﺸﺘﻴﺒﺎﻧﯽ ﻧﻤﯽ ﮐﻨﺪ ﺑﻠﮑﻪ ﻣﻘﺪﺍﺭ ﺣﺎﺻﻞ ﺭﺍ ﺩﺭ ﺩﻭ‬ ‫×‬ ‫‪ ۱۶‬ﺑﻴﺘﯽ ﻗﺮﺍﺭ ﻣﯽ ﺩﻫﺪ‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫‪۱۰‬‬

‫× ﺗﻘﺴﻴﻢ ‪ :‬ﺩﺭ ‪ PIC BASIC‬ﺗﻘﺴﻴﻢ ﺑﺼﻮﺭﺕ ‪۱۶‬ﺑﻴﺘﯽ ﺍﻧﺠﺎﻡ ﻣﯽ ﮔﻴﺮﺩ ﻭ ﻫﻤﭽﻨﻴﻦ ﻣـﯽ ﺗـﻮﺍﻥ ﺑﺎﻗﻴﻤﺎﻧـﺪﻩ‬ ‫ﺗﻘﺴﻴﻢ ﺭﺍ ﺟﺪﺍﮔﺎﻧﻪ ﺑﺪﺳﺖ ﺁﻭﺭﺩ‪ .‬ﺩﺭ ﻣﺜﺎﻝ ﺯﻳﺮ ﺍﻳﻦ ﺩﻭ ﺣﺎﻟﺖ ﻧﺸﺎﻥ ﺩﺍﺩﻩ ﺷﺪﻩ ﺍﺳﺖ‪.‬‬

‫ﺷﻴﻔﺖ ﺩﺍﺩﻥ ‪ :‬ﻋﻤﻠﮕﺮ ﺷﻴﻔﺖ ﻣﯽ ﺗﻮﺍﻧﺪ ﺗﻌﺪﺍﺩ ‪ ۰‬ﺗﺎ ‪ ۱۵‬ﺷﻴﻔﺖ ﺑﻪ ﭼـﭗ ﻭ ﻳـﺎ ﺭﺍﺳـﺖ ﺭﺍ ﭘﺸـﺘﻴﺒﺎﻧﯽ‬ ‫×‬ ‫ﮐﻨﺪ‪.‬‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫×‬

‫‪۱۱‬‬

‫ﻗﺪﺭ ﻣﻄﻠﻖ ‪ :‬ﺍﮔﺮ ﻳﮏ ‪ BYTE‬ﺑﻴﺸﺘﺮ ﺍﺯ ‪) 127‬ﺑﻴﺖ ‪ MSB‬ﺁﻥ ﻳﮏ ( ﺑﺎﺷـﺪ ‪ ABS‬ﻣﻘـﺪﺍﺭ – ‪256‬‬

‫‪ value‬ﺭﺍ ﺑﺮ ﻣﯽ ﮔﺮﺩﺍﻧﺪ‪ .‬ﺍﮔﺮ ﻳﮏ ‪ WORD‬ﺑﺰﺭﮔﺘﺮ ﺍﺯ ‪ ) 32767‬ﺑﻴﺖ ‪ MSB‬ﺁﻥ ﻳﮏ ﺍﺳـﺖ ( ﺑﺎﺷـﺪ ‪،‬‬ ‫‪ ABS‬ﻣﻘﺪﺍﺭ ‪ 65535 – value‬ﺭﺍ ﺑﺮ ﻣﯽ ﮔﺮﺩﺍﻧﺪ‪.‬‬ ‫‪B1 = ABS B0‬‬

‫‪ COS‬ﻭ ‪ : SIN‬ﺯﺍﻭﻳﻪ ‪ ۰‬ﺗﺎ ‪ ۳۵۹‬ﻣﻮﺭﺩ ﻧﻴﺎﺯ ﺍﻳﻦ ﻋﻤﻠﮕﺮ ﺑﺼﻮﺭﺕ ﻳﮏ ﻋـﺪﺩ ‪ ۰‬ﺗـﺎ ‪ ۲۵۵‬ﺗـﺎﻣﻴﻦ ﻣـﯽ‬ ‫×‬ ‫ﺷﻮﺩ ﻭﺑﺮﺍﯼ ﺍﻳﻦ ﺗﺒﺪﻳﻞ ﻣﯽ ﺗﻮﺍﻥ ﺍﺯ ﻳﮏ ‪ lookup table‬ﺍﺳﺘﻔﺎﺩﻩ ﮐﻨﻴﻢ‪.‬‬

‫‪ : DCD‬ﺍﻳﻦ ﻋﻤﻠﮕﺮ ﻣﻘﺪﺍﺭ ‪ ۰‬ﺗﺎ ‪ ۱۵‬ﺭﺍ ﺗﺒﺪﻳﻞ ﺑﻪ ﺷﻤﺎﺭﻩ ﺑﻴﺖ ﻣﯽ ﮐﻨﻨﺪ‪ .‬ﺍﮔـﺮ ﻣﻘـﺪﺍﺭ ﺻـﻔﺮ ﺭﺍ ﻗـﺮﺍﺭ‬ ‫×‬ ‫ﺩﻫﻴﻢ ﺑﻴﺖ ﺻﻔﺮﻡ ﻳﮏ ﻣﯽ ﺷﻮﺩ ﻭ ﺑﻘﻴﻪ ﺻﻔﺮ ﻣﯽ ﺷﻮﻧﺪ‪.‬‬

‫‪ : DIG‬ﺗﻌﺪﺍﺩ ﺭﻗﻤﻬﺎﯼ ﮐﻪ ﻧﺸﺎﻥ ﻣﯽ ﺩﻫﻨﺪ ﺑﻴﻦ ‪ ۰‬ﺗﺎ ‪ ۳‬ﻣﯽ ﺑﺎﺷﺪ ﮐﻪ ﻋﺪﺩ ‪ ۰‬ﺁﺧﺮﻳﻦ ﺭﻗﻢ ﺍﺯ ﺳـﻤﺖ‬ ‫×‬ ‫ﺭﺍﺳﺖ ﻣﯽ ﺑﺎﺷﺪ‪.‬‬

‫‪۱۲‬‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫×‬

‫ﺗﻌﻴﻴﻦ ﻣﻘﺪﺍﺭ ﻣﺎﮐﺰﻳﻤﻢ ﻭ ﻣﻴﻨﻴﻤﻢ ‪ :‬ﺑﺮﺍﯼ ﻣﺤﺪﻭﺩ ﮐﺮﺩﻥ ﻣﻘﺎﺩﻳﺮ ﺑﻪ ﻳﮏ ﻋﺪﺩ ﺍﺳﺘﻔﺎﺩﻩ ﻣﯽ ﺷﻮﺩ‬ ‫‪B1 = B0 MAX 100‬‬

‫ﻣﺤﺘﻮﺍﯼ ‪ B1‬ﻣﻘﺪﺍﺭ ﺑﺰﺭﮔﺘﺮ ﺑﻴﻦ ‪ B0‬ﻭ ‪ ۱۰۰‬ﻣﯽ ﺑﺎﺷﺪ ) ‪ B1‬ﻣﻘﺪﺍﺭﯼ ﺑﻴﻦ ‪ ۱۰۰‬ﻭ ‪ ۲۵۵‬ﻣﯽ ﺑﺎﺷﺪ(‬ ‫‪B1 = B0 MIN 100‬‬

‫ﻣﺤﺘﻮﺍﯼ ‪ B1‬ﻣﻘﺪﺍﺭ ﮐﻮﭼﮑﺘﺮ ﺑﻴﻦ ‪ B0‬ﻭ ‪ ۱۰۰‬ﻣﯽ ﺑﺎﺷﺪ ) ‪ B1‬ﻣﻘﺪﺍﺭﯼ ﺑﻴﻦ ‪ ۱۰۰‬ﻭ ‪ ۰‬ﻣﯽ ﺑﺎﺷﺪ(‬ ‫×‬

‫‪ : NCD‬ﺷﻤﺎﺭﻩ ﺍﻭﻟﻴﻦ ﺑﻴﺘﯽ ﮐﻪ ﺍﺯ ﺳﻤﺖ ﭼﭗ ﻳﮏ ﺍﺳﺖ ﺭﺍ ﻣﯽ ﺩﻫﺪ‬

‫‪ : REV‬ﺗﻌﺪﺍﺩ ﺑﻴﺘﻬﺎﯼ ﮐﻪ ﻣﯽ ﺗﻮﺍﻧﻨﺪ ﻳﮏ ﺷﻮﻧﺪ ‪ ۱‬ﺗﺎ ‪ ۱۶‬ﻣﯽ ﺑﺎﺷﺪ ﻭ ﺑﺎ ﺗﻮﺟﻪ ﺑﻪ ﻋـﺪﺩ ﻣـﻮﺭﺩ ﻧﻈـﺮ‬ ‫×‬ ‫ﺑﻴﺘﻬﺎﯼ ﭘﺎﻳﻴﻨﺘﺮ ﻣﻌﮑﻮﺱ ﻣﯽ ﺷﻮﻧﺪ‪.‬‬

‫×‬

‫‪ : SQR‬ﺭﻳﺸﻪ ﺩﻭﻡ ﻋﺪﺩ ﻣﻮﺭﺩ ﻧﻈﺮ ﺩﺭ ﻳﮏ ﺑﺎﻳﺖ ﻗﺮﺍﺭ ﻣﯽ ﮔﻴﺮﺩ‪.‬‬

‫‪۱۳‬‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫‪.۱ -۲-۲‬‬

‫ﻋﻤﻠﮕﺮﻫﺎﯼ ﺑﻴﺘﯽ‬

‫ﻋﻤﻠﮕﺮ ﻫﺎﯼ ﺑﻴﺘﯽ‬ ‫ﻋﻤﻠﮕﺮﻫﺎ‬

‫ﺗﻮﺿﻴﺢ‬ ‫‪ AND‬ﻣﻨﻄﻘﯽ ﺭﻭﯼ ﺑﻴﺘﻬﺎ‬

‫&‬

‫‪ OR‬ﻣﻨﻄﻘﯽ ﺭﻭﯼ ﺑﻴﺘﻬﺎ‬

‫|‬

‫‪ XOR‬ﻣﻨﻄﻘﯽ ﺭﻭﯼ ﺑﻴﺘﻬﺎ‬

‫^‬

‫‪ NOT‬ﻣﻨﻄﻘﯽ ﺭﻭﯼ ﺑﻴﺘﻬﺎ‬

‫~‬

‫‪ NAND‬ﻣﻨﻄﻘﯽ ﺭﻭﯼ ﺑﻴﺘﻬﺎ‬

‫‪&/‬‬

‫‪ NOR‬ﻣﻨﻄﻘﯽ ﺭﻭﯼ ﺑﻴﺘﻬﺎ‬

‫‪|/‬‬

‫‪ NXOR‬ﻣﻨﻄﻘﯽ ﺭﻭﯼ ﺑﻴﺘﻬﺎ‬

‫‪^/‬‬

‫ﺟﺪﻭﻝ ‪۱-۴‬‬

‫‪.۱ -۲-۳‬‬

‫ﻋﻤﻠﮕﺮﻫﺎﯼ ﻣﻘﺎﻳﺴﻪ ﺍﯼ‬

‫ﻋﻤﻠﮕﺮﻫﺎﯼ ﻣﻘﺎﻳﺴﻪ ﺍﯼ‬ ‫ﺗﻮﺿﻴﺢ‬ ‫ﺗﺴﺎﻭﯼ‬

‫ﻋﻤﻠﮕﺮ‬ ‫== ‪= or‬‬

‫ﻧﺎﻣﺴﺎﻭﯼ‬

‫|=! ‪<> or‬‬

‫ﮐﻮﭼﮑﺘﺮ ﺍﺯ‬

‫<‬

‫ﺑﺰﺭﮔﺘﺮ ﺍﺯ‬

‫>‬

‫ﮐﻮﭼﮑﺘﺮ ﺍﺯ‬

‫=<‬

‫ﺑﺰﺭﮔﺘﺮﺍﺯ‬

‫=>‬

‫ﺟﺪﻭﻝ ‪۱-۵‬‬

‫‪۱۴‬‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫‪.۱ -۲-۴‬‬

‫ﻋﻤﻠﮕﺮﻫﺎﯼ ﻣﻨﻄﻘﯽ‬ ‫ﻋﻤﻠﮕﺮﻫﺎﯼ ﻣﻨﻄﻘﯽ‬ ‫ﺷﺮﺡ‬

‫ﻋﻤﻠﮕﺮ‬

‫‪ AND‬ﻣﻨﻄﻘﯽ‬

‫&& ‪AND or‬‬

‫‪ OR‬ﻣﻨﻄﻘﯽ‬

‫|| ‪OR or‬‬

‫‪ XOR‬ﻣﻨﻄﻘﯽ‬

‫^^ ‪XOR or‬‬

‫‪ NOT‬ﻣﻨﻄﻘﯽ‬

‫‪NOT‬‬

‫‪ NAND‬ﻣﻨﻄﻘﯽ‬

‫‪NOT AND‬‬

‫‪ NOR‬ﻣﻨﻄﻘﯽ‬

‫‪NOT OR‬‬

‫‪ NXOR‬ﻣﻨﻄﻘﯽ‬

‫‪NOT XOR‬‬

‫ﺟﺪﻭﻝ ‪۱-۶‬‬

‫‪۱۵‬‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫ﺩﺳﺘﻮﺭﺍﺕ ‪PICBasic‬‬

‫‪(۱‬‬ ‫‪(۲‬‬ ‫‪(۳‬‬ ‫‪(۴‬‬

‫‪.۱ -۳‬‬ ‫ﺩﺳﺘﻮﺭﺍﺕ ﺑﻪ ﭼﻬﺎﺭ ﺑﺨﺶ ﺗﻘﺴﻴﻢ ﻣﯽ ﺷﻮﻧﺪ‬ ‫ﺩﺳﺘﻮﺭﻫﺎﯼ ﺷﺎﺧﻪ ﺍﯼ ) ﻣﺎﻧﻨﺪ ‪( IF‬‬ ‫ﺩﺳﺘﻮﺭﻫﺎﯼ ﺗﮑﺮﺍﺭﮐﻨﻨﺪﻩ ) ‪ FOR … NEXT‬ﻭ ‪( WHILE … WEND‬‬ ‫ﺩﺳﺘﻮﺭﻫﺎﯼ ﭘﺮﺵ ﺑﻪ ﺧﻂ ) ‪ ( GOTO‬ﻳﺎ ﻳﮏ ﺯﻳﺮﺑﺮﻧﺎﻣـﻪ ) ‪، CALL ، BRANCHL ، BRANCH‬‬ ‫‪( RETURN ، GOSUB‬‬ ‫ﺩﺳﺘﻮﺭﻫﺎﯼ ﺩﺳﺘﻴﺎﺑﯽ ﺑﻪ ﻭﺳﺎﻳﻞ ﺟﺎﻧﺒﯽ ) ﻣﺜﻼ ﺍﺭﺗﺒﺎﻁ ﺑﺎ ‪ (LCD‬ﺑﺎ ﺍﻳﻦ ﺩﺳﺘﻮﺭﺍﺕ ﺑﺮﻧﺎﻣﻪ ﻧﻮﻳﺲ ﻓﮑﺮ ﺧﻮﺩ‬ ‫ﺭﺍ ﺑﺮ ﺭﻭﯼ ﻣﺎﻫﻴﺖ ﺍﺻﻠﯽ ﺑﺮﻧﺎﻣﻪ ﺧﻮﺩ ﻣﺘﻤﺮﮐﺰ ﻣﯽ ﮐﻨﺪ ﻭ ﺍﺯ ﺍﺗﻼﻑ ﻭﻗﺖ ﺧﻮﺩ ﺑﺮ ﺭﻭﯼ ﻣـﻮﺍﺭﺩﯼ ﻫﻤﭽـﻮﻥ‬ ‫ﺍﺭﺗﺒﺎﻁ ﺑﺎ ‪ LCD‬ﺟﻠﻮﮔﻴﺮﯼ ﻣﯽ ﮐﻨﺪ ‪.‬‬ ‫ﺩﺳﺘﻮﺭﺍﺕ ﺑﻪ ﺗﺮﺗﻴﺐ ﺣﺮﻭﻑ ﺍﻟﻔﺒﺎ ﻻﺗﻴﻦ ‪:‬‬ ‫‪ : @.۱ -۳-۱‬ﻭﺍﺭﺩ ﮐﺮﺩﻥ ﻳﮏ ﺧﻂ ﺑﺮﻧﺎﻣﻪ ﺑﺎ ﮐﺪ ﺍﺳﻤﺒﻠﯽ‬ ‫ﺗﺮﮐﻴﺐ‪:‬‬ ‫‪@ assembler's instruction‬‬

‫ﺷﺮﺡ‪:‬‬ ‫ﺍﮔﺮ ﺩﺭ ﺍﺑﺘﺪﺍﯼ ﺧﻂ ﺍﺯ ﻋﻼﻣﺖ @ ﺍﺳﺘﻔﺎﺩﻩ ﺷﻮﺩ ﮐﺪ ﺍﺳﻤﺒﻠﯽ ﺭﺍ ﺩﺭ ﺗﺮﮐﻴﺐ ﺑﺮ ﻧﺎﻣﻪ ‪ PicBasic‬ﻣﯽ ﺗﻮﺍﻥ‬ ‫ﻧﻮﺷﺖ‪ .‬ﺩﺳﺘﻮﺭ @ ﺑﺮﺍﯼ ﺍﻟﺤﺎﻕ ﮐﺘﺎﺑﺨﺎﻧﻪ ﻫﺎﯼ ﻧﻮﺷﺘﻪ ﺷﺪﻩ ﺑﻪ ﺯﺑﺎﻥ ﺍﺳﻤﺒﻠﯽ ﻧﻴﺰ ﺍﺳﺘﻔﺎﺩﻩ ﻣﯽ ﺷﻮﺩ‪ .‬ﺗﻮﺟﻪ‬ ‫ﮐﻨﻴﺪ ﺩﺭ ﺻﻮﺭﺕ ﺍﺳﺘﻔﺎﺩﻩ ﺍﺯ ﻣﺘﻐﻴﺮﻫﺎﯼ ﺩﺭﻭﻥ ﺑﺮﻧﺎﻣﻪ ﺩﺭ ﺍﻳﻦ ﻗﺴﻤﺖ ﻗﺒﻞ ﺍﺯ ﻧـﺎﻡ ﻣﺘﻐﻴـﺮ ﺍﺯ ﺧـﻂ ﺯﻳـﺮ )‬ ‫ﺩﺷﺖ ( ﺍﺳﺘﻔﺎﺩﻩ ﻣﯽ ﺷﻮﺩ‪.‬‬ ‫ﺩﺭ ﻣﺜﺎﻝ ﺯﻳﺮ ﻣﺘﻐﻴﺮ ‪ B0‬ﺩﺭ ﺩﺳﺘﻮﺭ @ ﺑﺼﻮﺭﺕ ‪ _B0‬ﺑﮑﺎﺭ ﺑﺮﺩﻩ ﻣﯽ ﺷﻮﺩ‪.‬‬ ‫ﻣﺜﺎﻝ ‪:‬‬ ‫‪byte‬‬ ‫ﻧﺸﺎﻧﻪ ﮔﺬﺍﺭﯼ ﺑﻴﺖ ﻫﻔﺘﻢ ﺍﺯ ﻣﺘﻐﻴﺮ ‪' B0‬‬

‫‪bsf‬‬

‫‪_B0,7‬‬

‫‪Loop‬‬

‫‪.۱ -۳-۲‬‬ ‫ﺗﺮﮐﻴﺐ ‪:‬‬

‫‪B0‬‬ ‫‪var‬‬ ‫‪Main:‬‬ ‫@‬ ‫‪Loop: goto‬‬ ‫‪End‬‬

‫‪ ASM … ENDASM‬ﻭﺍﺭﺩ ﮐﺮﺩﻥ ﻳﮏ ﺑﻠﻮﮎ ﺍﺯ ﺩﺳﺘﻮﺭﺍﺕ ﺍﺳﻤﺒﻠﯽ‬ ‫‪ASM‬‬ ‫‪/‬‬

‫ﺩﺳﺘﻮﺭﺍﺕ ﺍﺳﻤﺒﻠﯽ‬ ‫‪/‬‬ ‫‪ENDASM‬‬

‫‪۱۶‬‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫ﺷﺮﺡ ‪:‬‬ ‫ﺩﺳﺘﻮﺭﺍﺕ ﺑﻴﻦ ‪ ASM‬ﻭ ‪ ENDASM‬ﺍﺯ ﻧﻮﻉ ﺍﺳﻤﺒﻠﯽ ﻣﯽ ﺑﺎﺷﺪ‪ .‬ﺣﺪﺍﮐﺜﺮ ﮐﺪ ﺍﺳﻤﺒﻠﯽ ﻧﻮﺷﺘﻪ ﺷـﺪﻩ ﺑـﻪ‬ ‫ﻣﻘﺪﺍﺭ ﺣﺎﻓﻈﻪ ﻗﺎﺑﻞ ﺑﺮﻧﺎﻣﻪ ﻧﻮﻳﺴﯽ ﺁﻥ ﻣﻴﮑﺮﻭﮐﻨﺘﺮﻟﺮ ﻭﺍﺑﺴﺘﻪ ﺍﺳﺖ‪ .‬ﻣﺜﻼ ﺩﺭ ﻣﻴﮑﺮﻭﮐﻨﺘﺮﻟـﺮ ‪PIC16F877‬‬ ‫ﮐﺪ ﺍﺳﻤﺒﻠﺮ ﺣﺪﺍﮐﺜﺮ ‪ 8K‬ﻣﯽ ﺑﺎﺷﺪ‪.‬‬ ‫ﻣﺜﺎﻝ ‪:‬‬ ‫‪Main:‬‬ ‫‪asm‬‬ ‫ﻧﺸﺎﻧﺪﻥ ‪' RA0‬‬

‫ﺑﺎﺯ ﻧﺸﺎﻧﺪﻥ ‪' RB0‬‬

‫‪PORTA,0‬‬

‫‪bsf‬‬

‫‪PORTB,3‬‬

‫‪bcf‬‬ ‫‪endasm‬‬ ‫‪Loop: goto Loop‬‬ ‫‪end‬‬

‫‪.۱ -۳-۳‬‬ ‫ﺗﺮﮐﻴﺐ ‪:‬‬

‫‪ ADCIN‬ﺩﺭﻳﺎﻓﺖ ﻣﻘﺎﺩﻳﺮ ﺍﺯ ﻭﺭﻭﺩﯼ ﻣﺒﺪﻝ ‪A/D‬‬ ‫‪ADCIN channel, variable‬‬

‫ﺷﺮﺡ ‪:‬‬

‫‪ ADCIN‬ﺗﺒﺪﻳﻞ ﺁﻧﺎﻟﻮﮒ ﺑﻪ ﺩﻳﺠﻴﺘﺎﻝ )‪ ( A/D‬ﺭﺍ ﺍﺯ ﻳﮏ ﺳﻴﮕﻨﺎﻝ ﺁﻧـﺎﻟﻮﮒ ﻭﺭﻭﺩﯼ ﺩﺭ ﻣﻴﮑﺮﻭﮐﻨﺘﺮﻟﺮﻫـﺎﯼ‬ ‫ﮐﻪ ﻣﺒﺪﻝ ‪ A/D‬ﺩﺍﺭﻧﺪ‪ ،‬ﺍﻧﺠﺎﻡ ﺩﻫﺪ )ﻣﺎﻧﻨﺪ ‪ ( PIC16F877‬ﻣﻘﺪﺍﺭ ﺧﻮﺍﻧﺪﻩ ﺷـﺪﻩ ﺩﺭ ﺩﺍﺧـﻞ ﻣﺘﻐﻴـﺮ ﺑﮑـﺎﺭ‬ ‫ﺭﻓﺘـﻪ ﺫﺧﻴــﺮﻩ ﻣــﯽ ﺷـﻮﺩ ‪ .‬ﻗﺒــﻞ ﺍﺯ ﺍﺳــﺘﻔﺎﺩﻩ ﺍﺯ ﺩﺳـﺘﻮﺭ ‪ ADCIN‬ﺭﺟﻴﺴــﺘﺮ ‪ TRIS‬ﻣﺮﺑﻮﻃــﻪ ﺑﺎﻳﺴــﺘﯽ‬ ‫ﻣﻘﺪﺍﺭﺩﻫﯽ ﺍﻭﻟﻴﻪ ﺷﻮﺩ ﺗﺎ ﭘﺎﻳﻪ ﻣﻮﺭﺩ ﺍﺳﺘﻔﺎﺩﻩ ﺑﻄﻮﺭ ﻣﺸـﺨﺺ ﺑﺼـﻮﺭﺕ ﻭﺭﻭﺩﯼ ﺩﺭ ﺁﻳـﺪ‪ .‬ﺑﻌـﻼﻭﻩ ﺍﻳﻨﮑـﻪ ﺍﺯ‬ ‫ﺭﺟﻴﺴﺘﺮ ‪ ADCON1‬ﺑﺮﺍﯼ ﻣﺸﺨﺺ ﮐﺮﺩﻥ ﺍﻳﻨﮑﻪ ﭘﻴﻨﻬﺎﯼ ﻭﺭﻭﺩﯼ ﺑﻪ ﺣﺎﻟﺖ ﺁﻧﺎﻟﻮﮒ ﺑﺎﺷﺪ ﻳـﺎ ﺩﻳﺠﻴﺘـﺎﻝ‬ ‫ﺍﺳﺘﻔﺎﺩﻩ ﻣﯽ ﺷﻮﺩ‪ .‬ﺑﺮﺍﯼ ﺗﻨﻈﻴﻢ ‪ A/D‬ﻋـﻼﻭﻩ ﺑـﺮ ﺍﺳـﺘﻔﺎﺩﻩ ﺍﺯ ‪ DEFINE‬ﻣـﯽ ﺗـﻮﺍﻥ ﺑﺼـﻮﺭﺕ ﻣﺴـﺘﻘﻴﻢ‬ ‫ﺭﺟﻴﺴﺘﺮﻫﺎﯼ ﻣﺮﺑﻮﻁ ﺑﻪ ‪ A/D‬ﺭﺍ ﻣﻘﺪﺍﺭ ﺩﻫﯽ ﮐﺮﺩ‪.‬‬ ‫ﻣﺜﺎﻝ ‪:‬‬ ‫‪DEFINE ADC_BITS 8‬‬ ‫ﻧﺘﺎﻳﺞ ﺗﺒﺪﻳﻞ ﺷﺪﻩ ‪۸،۱۰‬ﻳﺎ ‪ ۱۲‬ﺑﻴﺘﯽ ﻣﯽ ﺑﺎﺷﺪ '‬ ‫‪DEFINE ADC_CLOCK 3‬‬ ‫ﮐﻼﮎ ﻣﺒﺪﻝ ﺁﻧﺎﻟﻮﮒ ﺑﻪ ﺩﻳﺠﻴﺘﺎﻝ '‬ ‫‪DEFINE ADC_SAMPLEUS 10‬‬ ‫ﺯﻣﺎﻧﺒﻨﺪﯼ ﻧﻤﻮﻧﻪ ﺑﺮﺩﺍﺭﯼ ﻣﻮﺭﺩ ﻧﻈﺮ '‬ ‫ﻫﻤﻪ ﭘﻴﻨﻬﺎﯼ ﭘﻮﺭﺕ ‪ A‬ﻭﺭﻭﺩﯼ ﻣﯽ ﺑﺎﺷﻨﺪ '‬

‫ﭘﻮﺭﺕ ‪ A‬ﺩﺭ ﺣﺎﻟﺖ ﻭﺭﻭﺩﯼ ﺁﻧﺎﻟﻮﮒ ﺍﺳﺖ '‬

‫ﺧﻮﺍﻧﺪﻥ ﮐﺎﻧﺎﻝ ‪ ۰‬ﻭ ﺫﺧﻴﺮﻩ ﻧﺘﺎﻳﺞ ﺩﺍﺧﻞ ﻣﺘﻐﻴﺮ‪' B0‬‬

‫‪B0 var byte‬‬ ‫‪Main :‬‬ ‫‪TRISA = $FF‬‬ ‫‪ADCON1 = 0‬‬ ‫‪adcin 0, B0‬‬ ‫‪Loop : goto Loop‬‬ ‫‪end‬‬

‫‪۱۷‬‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫‪.۱ -۳-۴‬‬ ‫ﺗﺮﮐﻴﺐ ‪:‬‬

‫‪ BRANCH‬ﭘﺮﻳﺪﻥ ﺑﻪ ﺑﺮﭼﺴﺐ ﻣﺸﺨﺺ ﺷﺪﻩ ﺗﻮﺳﻂ ﺷﺎﺧﺺ‬ ‫]}‪BRANCH index, [label1 {label...‬‬

‫ﺷﺮﺡ ‪:‬‬ ‫ﺑﺎ ﺗﻮﺟﻪ ﺑﻪ ﻣﻘﺪﺍﺭ ﺷﺎﺧﺺ ﭘﺮﺵ ﺑﻪ ﺑﺮﭼﺴﺐ ﻫﻢ ﻧﻈﻴﺮ ﺁﻥ ﺍﻧﺠﺎﻡ ﻣﯽ ﮔﻴﺮﺩ‪ .‬ﻣﺜﻼ ﺍﮔﺮ ﺷﺎﺧﺺ ﺻﻔﺮ ﺑﺎﺷﺪ‬ ‫ﭘﺮﺵ ﺑﻪ ﺍﻭﻟﻴﻦ ﺑﺮﭼﺴﺐ ﻗﺮﺍﺭ ﮔﺮﻓﺘﻪ ﺩﺭ ﺑﺮﺍﮐﺖ ﺻﻮﺭﺕ ﻣﯽ ﮔﻴﺮﺩ ﻭ ﺍﮔﺮ ‪ ۱‬ﺑﺎﺷﺪ ﭘﺮﺵ ﺑﻪ ﺩﻭﻣﻴﻦ ﺑﺮﭼﺴﺐ‬ ‫ﺻﻮﺭﺕ ﻣﯽ ﮔﻴﺮﺩ ﻭ ﺍﮔﺮ ﺷﺎﺧﺺ ﺑﺮﺍﺑﺮ ﺗﻌﺪﺍﺩ ﺑﺮﭼﺴﺒﻬﺎ ﻳﺎ ﺑﻴﺸﺘﺮ ﺍﺯ ﺁﻥ ﺑﺎﺷﺪ ﻫـﻴﭻ ﭘﺮﺷـﯽ ﺻـﻮﺭﺕ ﻧﻤـﯽ‬ ‫ﮔﻴﺮﺩ ﻭﺩﺳﺘﻮﺭ ﺑﻌﺪﯼ ﺍﺟﺮﺍ ﻣﯽ ﺷﻮﺩ‪.‬‬ ‫ﺩﺭ ﺿﻤﻦ ﺷﺎﺧﺺ ﻳﮏ ﻣﺘﻐﻴﺮ ﻳﮏ ﺑﺎﻳﺘﯽ ﺍﺳﺖ ﻭ ﺣﺪﺍﮐﺜﺮ ﺑﺮﺍﯼ ‪ ۲۵۵‬ﺑﺮﭼﺴﺐ ﺍﻳـﻦ ﺩﺳـﺘﻮﺭ ﻗﺎﺑـﻞ ﺍﺟـﺮﺍ‬ ‫ﺍﺳﺖ‪).‬ﺑﺮﺍﯼ ‪ ۲۵۶ 18CXXX‬ﺑﺮﭼﺴﺐ (‬ ‫ﺑﺎ ﺍﺳﺘﻔﺎﺩﻩ ﺍﺯ ‪ IF … THEN‬ﻧﻴﺰ ﺷﺒﻴﻪ ﺩﺳﺘﻮﺭ ‪ BRANCH‬ﻋﻤﻞ ﮐﺮﺩ‪.‬‬ ‫‪lab1‬‬ ‫‪lab2‬‬ ‫‪lab3‬‬

‫‪B0 = 0 then‬‬ ‫‪B0 = 1 then‬‬ ‫‪B0 = 2 then‬‬

‫‪If‬‬ ‫‪If‬‬ ‫‪If‬‬

‫ﻣﺜﺎﻝ‪:‬‬ ‫‪byte‬‬ ‫] ‪B0,[ lab1 , lab2 , lab3‬‬ ‫‪Loop‬‬

‫‪.۱ -۳-۵‬‬ ‫ﺗﺮﮐﻴﺐ ‪:‬‬

‫‪B0‬‬ ‫‪var‬‬ ‫‪Branch‬‬ ‫‪Loop: goto‬‬ ‫‪Lab1:‬‬ ‫‪Lab2:‬‬ ‫‪Lab3:‬‬ ‫‪end‬‬

‫‪ BRANCHL‬ﭘﺮﺷﯽ ﺑﻠﻨﺪ ﺑﻪ ﺑﺮﭼﺴﺐ ﻧﻈﻴﺮ ﺷﺎﺧﺺ‬ ‫]}‪BRANCHL index, [ label1 {label...‬‬

‫ﺷﺮﺡ ‪:‬‬ ‫ﺍﻳﻦ ﺩﺳﺘﻮﺭ ﮐﺎﻣﻼ ﺷﺒﻴﻪ ﺩﺳﺘﻮﺭ ‪ BRANCH‬ﻣﯽ ﺑﺎﺷﺪ ﺗﻨﻬﺎ ﺗﻔـﺎﻭﺕ ﺁﻥ ﺍﻳـﻦ ﺍﺳـﺖ ﮐـﻪ ‪BRANCHL‬‬ ‫ﭘﺮﺵ ﺑﻪ ﻣﻮﻗﻌﻴﺘﻬﺎﯼ ﻗﺮﺍﺭ ﮔﺮﻓﺘﻪ ﺩﺭ ﮐﺪ ﺳﮕﻤﻨﺘﻬﺎﯼ ﺩﻳﮕﺮ ﺭﺍ ﻧﻴﺰ ﻣﺤﻘﻖ ﺑﺴﺎﺯﺩ ‪.‬‬ ‫ﮐﺪ ﺑﺪﺳﺖ ﺁﻣﺪﻩ ﺍﺯ ‪ BRANCHL‬ﺗﻘﺮﻳﺒﺎ ﺩﻭ ﺑﺮﺍﺑﺮ ﺑﺰﺭﮔﺘﺮ ﺍﺯ ﮐﺪ ‪ BRANCH‬ﻣﯽ ﺑﺎﺷﺪ‪ .‬ﺍﮔﺮ ﭘﺮﺷﻬﺎ ﺗﻨﻬﺎ‬ ‫ﻗﺮﺍﺭ ﺍﺳﺖ ﺩﺭ ﻳﮏ ﮐﺪ ﺳﮕﻤﻨﺖ ﺭﻭﯼ ﺑﺪﻫﺪ ﻭ ﻳﺎ ﮐﺪ ﺑﺮﻧﺎﻣﻪ ﺩﺭ ﻳﮏ ﮐﺪ ﺳﮕﻤﻨﺖ ﻣﯽ ﺑﺎﺷﺪ ﻭ ﻳـﺎ ﺣﺎﻓﻈـﻪ‬ ‫ﻣﻴﮑﺮﻭﮐﻨﺘﺮﻟﺮ ﻣﻮﺭﺩ ﻧﻈﺮ ﮐﻤﺘﺮ ﺍﺯ ﻳﮏ ﮐـﺪ ﺳـﮕﻤﻨﺖ ) ﮐﻤﺘـﺮ ﺍﺯ ‪ ۲‬ﮐﻴﻠـﻮ ﺑﺎﻳـﺖ ( ﺑﺎﺷـﺪ ﺑﻬﺘـﺮ ﺍﺳـﺖ ﺍﺯ‬ ‫‪ BRANCH‬ﺍﺳﺘﻔﺎﺩﻩ ﺷﻮﺩ ﺯﻳﺮﺍ ﺣﺎﻓﻈﻪ ﺍﺳﺘﻔﺎﺩﻩ ﺷﺪﻩ ﺑﺮﺍﯼ ﮐﺪﻫﺎﯼ ﺑﺮﻧﺎﻣﻪ ﺭﺍ ﮐﺎﻫﺶ ﻣﯽ ﺩﻫﺪ‪.‬‬ ‫‪ ۱۲۷‬ﺑﺮﭼﺴﺐ )‪ ۲۵۶‬ﺗﺎ ﺑﺮﺍﯼ ‪ ( 18CXXX‬ﻣﯽ ﺗﻮﺍﻥ ﺑﺎ ﺩﺳﺘﻮﺭ ‪ BRANCHL‬ﺁﺩﺭﺱ ﺩﻫﯽ ﮐﺮﺩ‪.‬‬ ‫ﻣﺜﺎﻝ‪:‬‬ ‫] ‪B0 , [ Lab1 , Lab2 , Lab3‬‬

‫‪B0‬‬ ‫‪var‬‬ ‫‪byte‬‬ ‫‪Main:‬‬ ‫‪branchl‬‬

‫‪۱۸‬‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫‪Loop:‬‬ ‫‪goto Loop‬‬ ‫‪Lab1: /‬‬ ‫‪/‬‬ ‫‪Lab2:/‬‬ ‫‪/‬‬ ‫‪Lab3:/‬‬ ‫‪/‬‬ ‫‪end‬‬

‫‪.۱ -۳-۶‬‬ ‫ﺗﺮﮐﻴﺐ ‪:‬‬

‫‪ : BUTTON‬ﺧﻮﺍﻧﺪﻥ ﺣﺎﻟﺖ ﺩﮐﻤﻪ ﺭﻭﯼ ﭘﻴﻦ ﻭﺭﻭﺩﯼ‬ ‫‪BUTTON Pin, State, Delay, Speed, Variable, Action, Label‬‬

‫ﺷﺮﺡ ‪:‬‬ ‫ﺩﺳﺘﻮﺭ ‪ BUTTON‬ﺗﻤﺎﺱ ﻟﺮﺯﺍﻥ ﻧﺎﺷﯽ ﺍﺯ ﻓﺸﺮﺩﻥ ﺩﮐﻤـﻪ ﺭﺍ ﺣـﺬﻑ ﻣـﯽ ﮐﻨـﺪ )‪ (Debouncing‬ﺍﻳـﻦ‬ ‫ﺣﺎﻟﺖ ﺭﺍ ﺗﻮﺳﻂ ﺗﺎﺧﻴﺮ ﺩﺭﺍﺟﺮﺍﯼ ﺑﺮﻧﺎﻣﻪ ﺩﺭ ﻫﺮ ﺑﺎﺭ ﺗﮑﺮﺍﺭ ﺍﻧﺠﺎﻡ ﻣﯽ ﺩﻫـﺪ ﺗـﺎﺧﻴﺮ ‪ Debouncing‬ﭘـﻴﺶ‬ ‫ﻓـﺮﺽ ‪ ۱۰‬ﻣﻴﻠــﯽ ﺛﺎﻧﻴـﻪ ﻣــﯽ ﺑﺎﺷــﺪ ﮐـﻪ ﺑــﺮﺍﯼ ﺗﻐﻴﻴــﺮ ﺁﻥ ﺍﺯ ‪DEFINE BUTTON_PAUSE‬‬ ‫)‪ TIME(ms‬ﺍﺳﺘﻔﺎﺩﻩ ﻣﯽ ﮐﻨﻴﻢ ‪ .‬ﻣﺜﻼ ﺩﮐﻤﻪ ﺑﺎ ﺗﺎﺧﻴﺮ ‪ ۵۰ Debouncing‬ﻣﻴﻠﯽ ﺛﺎﻧﻴـﻪ ﺑﺼـﻮﺭﺕ ﺯﻳـﺮ‬ ‫ﺗﻌﻴﻴﻦ ﻣﯽ ﺷﻮﺩ ‪.‬‬ ‫‪DEFINE BUTTON_PAUSE 50‬‬

‫ﺗﻜﺮﺍﺭ ﺧﻮﺩﮐﺎﺭ ﮐﻪ ﺗﻮﺳﻂ ‪ Speed‬ﺗﻌﻴﻴﻦ ﻣﯽ ﺷﻮﺩ ﺩﺭ ﺣﻘﻴﻘـﺖ ﻣـﺪﺕ ﻓﺸـﺮﺩﻩ ﻧﮕـﻪ ﺩﺍﺷـﺘﻦ ﮐﻠﻴـﺪ ﺭﺍ‬ ‫ﺗﻌﻴﻴﻦ ﻣﯽ ﮐﻨﺪ‪ .‬ﺩﺳﺘﻮﺭ ‪ BUTTON‬ﻣﻌﻤﻮﻻ ﺩﺭ ﻳﮏ ﺣﻠﻘﻪ ﺑﻪ ﮐﺎﺭ ﻣﯽ ﺭﻭﺩ ﺗﺎ ﺯﺩﻩ ﺷﺪﻥ ﮐﻠﻴـﺪ ﺭﺍ ﭼـﮏ‬ ‫ﮐﻨﺪ ‪.‬‬ ‫‪ : pin‬ﺷﻤﺎﺭﻩ ﭘﺎﻳﻪ ﺭﺍ ﻧﺸﺎﻥ ﻣﯽ ﺩﻫﺪ ﮐﻪ ﻣﻤﮑﻦ ﺍﺳﺖ ﻳﮏ ﻋﺪﺩ ﺑﻴﻦ ‪۰‬ﺗﺎ ‪ ۱۵‬ﻳﺎ ﻳﮏ ﻣﺘﻐﻴﺮ ﮐﻪ ﻣﻘـﺪﺍﺭﺵ‬ ‫ﺑﻴﻦ ‪ ۰‬ﺗﺎ ‪ ۱۵‬ﻣﯽ ﺑﺎﺷﺪ ﻳﺎ ﺍﺳﻢ ﭘﻴﻦ ) ﻣﺎﻧﻨﺪ ‪ ( PORTA.0‬ﺑﺎﺷﺪ ‪.‬‬ ‫‪ : State‬ﻭﺿﻌﻴﺖ ﭘﺎﻳﻪ ﺑﻪ ﻫﻨﮕﺎﻡ ﻓﺸﺎﺭ ﺩﺍﺩﻥ ﮐﻠﻴﺪ ) ‪ ۰‬ﻳﺎ ‪( ۱‬‬ ‫‪ : Delay‬ﻣﻴﺰﺍﻥ ﺗﺎﺧﻴﺮ ﻗﺒﻞ ﺍﺯ ﺷﺮﻭﻉ ﺗﮑﺮﺍﺭ ﺧﻮﺩﮐﺎﺭ ) ‪۰‬ﺗﺎ ‪( ۲۵۵‬‬ ‫‪ : Speed‬ﻧﺮﺥ ﺗﮑﺮﺍﺭ ﺧﻮﺩﮐﺎﺭ ) ‪۰‬ﺗﺎ ‪( ۲۵۵‬‬ ‫‪ : Variable‬ﻣﺘﻐﻴﺮ ﻳﮏ ﺑﺎﻳﺘﯽ ﻣﻮﺭﺩ ﻧﻴﺎﺯ ﺑﺮﺍﯼ ﺗﺎﺧﻴﺮ ﺗﮑﺮﺍﺭ ‪ .‬ﻗﺒﻞ ﺍﺯ ﺍﺳﺘﻔﺎﺩﻩ ﺑﺎﻳﺪ ﺑﺎ ﻋـﺪﺩ ﺻـﻔﺮ ﻣﻘـﺪﺍﺭ‬ ‫ﺩﻫﯽ ﺍﻭﻟﻴﻪ ﺷﺪﻩ ﺑﺎﺷﺪ‪.‬‬ ‫‪ : Action‬ﻭﺿﻌﻴﺖ ﭘﺎﻳﻪ ﺑﺮﺍﯼ ﺍﺟﺮﺍﯼ ﻓﺮﻣﺎﻥ ‪. GOTO‬‬ ‫"‪ : "۰‬ﺍﮔﺮ ﻓﺸﺎﺭ ﺩﺍﺩﻩ ﻧﺸﺪﻩ ﺑﺎﺷﺪ‪.‬‬ ‫"‪ : "۱‬ﺍﮔﺮ ﻓﺸﺎﺭ ﺩﺍﺩﻩ ﺷﺪﻩ ﺑﺎﺷﺪ‪.‬‬ ‫‪ : Lable‬ﻧﻘﻄﻪ ﺍﯼ ﺍﺟﺮﺍﯼ ﺑﺮﻧﺎﻣﻪ ﺩﺭ ﺻﻮﺭﺕ ﺻﺤﻴﺢ ﺑﻮﺩﻥ ‪ ، Action‬ﺑﺎﻳﺪ ﺍﺯ ﺁﻧﺠﺎ ﺍﺩﺍﻣﻪ ﭘﻴﺪﺍ ﮐﻨﺪ‪.‬‬

‫‪۱۹‬‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫ﻣﺜﺎﻝ ‪:‬‬ ‫‪DEFINE‬‬ ‫‪BUTTON_PAUSE 50‬‬ ‫‪TRISA = 0‬‬ ‫‪TRISB = 255‬‬ ‫‪B0‬‬ ‫‪var‬‬ ‫‪byte‬‬ ‫‪Main:‬‬ ‫‪B0 = 0‬‬ ‫‪Button PORTB.0 , 0 , 100 , 10 , B0 , 1 , Led‬‬ ‫‪Goto‬‬ ‫‪Main‬‬ ‫‪Led:‬‬ ‫‪Toggle PORTA.0‬‬ ‫‪Goto‬‬ ‫‪Main‬‬ ‫‪End‬‬

‫‪ : CALL .۱ -۳-۷‬ﻓﺮﺍﺧﻮﺍﻧﯽ ﺯﻳﺮ ﺑﺮﻧﺎﻣﻪ ﻫﺎﯼ ﺍﺳﻤﺒﻠﯽ‬ ‫ﺗﺮﮐﻴﺐ ‪:‬‬ ‫‪CALL label‬‬

‫ﺷﺮﺡ ‪:‬‬ ‫ﺯﻳﺮ ﺑﺮﻧﺎﻣﻪ ﺑﺎ ﻧﺎﻡ ‪ label‬ﺭﺍ ﺩﺭ ﺯﺑﺎﻥ ﺍﺳﻤﺒﻠﯽ ﻓﺮﺍﺧﻮﺍﻧﯽ ﻣﯽ ﮐﻨﺪ‪.‬‬ ‫ﻣﺜﺎﻝ‪:‬‬ ‫ﺩﺭ ﺍﻳﻦ ﻣﺜﺎﻝ ﻓﺎﻳﻞ "‪ "init.asm‬ﺑﻪ ﺑﺮﻧﺎﻣﻪ ﺍﻟﺤﺎﻕ ﺷﺪﻩ ﺍﺳﺖ‪.‬‬ ‫‪@ include‬‬ ‫"‪"init.asm‬‬ ‫‪Main:‬‬ ‫‪Call init_sys‬‬ ‫‪Loop:‬‬ ‫‪Goto Loop‬‬ ‫‪End‬‬

‫‪ : CLEAR .۱ -۳-۸‬ﻣﻘﺪﺍﺭ ﻫﻤﻪ ﻣﺘﻐﻴﺮﻫﺎ ﺭﺍ ﺑﻪ ﺻﻔﺮ ﺗﻐﻴﻴﺮ ﺩﺍﺩﻥ‬ ‫ﺗﺮﮐﻴﺐ ‪:‬‬ ‫‪CLEAR‬‬

‫ﺷﺮﺡ ‪:‬‬ ‫ﺑﺎ ﺩﺳﺘﻮﺭ ‪ CLEAR‬ﺗﻤﺎﻡ ﺭﺟﻴﺴﺘﺮﻫﺎﯼ ‪ RAM‬ﺩﺭ ﻫﻤﻪ ﺩﻳﺘﺎ ﺑﺎﻧﮑﻬﺎ ﺑﻪ ﺻﻔﺮ ﺗﻐﻴﻴﺮ ﻣﯽ ﻳﺎﺑﺪ‪ .‬ﺍﻳﻦ ﺩﺳﺘﻮﺭ ‪،‬‬ ‫ﺑﺮﺍﯼ ﺍﻳﻨﮑﻪ ﺗﻤﺎﻡ ﻣﺘﻐﻴﺮﻫﺎ ﺭﺍ ﺑﻄﻮﺭ ﻫﻤﺰﻣﺎﻥ ﺻﻔﺮ ﮐﻨﻴﻢ ﻣﻨﺎﺳﺐ ﺍﺳﺖ‪.‬‬ ‫ﻣﺜﺎﻝ ‪:‬‬ ‫‪Clear‬‬ ‫‪Main:‬‬ ‫‪Goto Main‬‬ ‫‪End‬‬

‫‪۲۰‬‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫‪ : CLEARWDT .۱ -۳-۹‬ﺑﺎﺯ ﻧﺸﺎﻧﺪﻥ ﺗﺎﻳﻤﺮ ‪) Watchdog‬ﺳﮓ ﻧﮕﻬﺒﺎﻥ (‬ ‫ﺗﺮﮐﻴﺐ ‪:‬‬ ‫‪CLEARWDT‬‬

‫ﺗﻮﺿﻴﺢ ‪:‬‬ ‫ﺑﺎﺯ ﻧﺸﺎﻧﺪﻥ ﺗـﺎﻳﻤﺮ ‪ Watchdog‬ﺭﺍ ﺑﺮﻋﻬـﺪﻩ ﺩﺍﺭﺩ ‪ .‬ﺍﻳـﻦ ﺩﺳـﺘﻮﺭ ﻣـﯽ ﺗﻮﺍﻧـﺪ ﺑﻌـﺪ ﺍﺯ ﺭﺍﻩ ﺍﻧـﺪﺍﺯﯼ ﺗـﺎﻳﻤﺮ‬ ‫‪ ، Watchdog‬ﺍﺯ ﻫﻨﮓ ﺷﺪﻥ ﻣﻴﮑﺮﻭﮐﻨﺘﺮﻟﺮ ﺟﻠﻮﮔﻴﺮﯼ ﮐﻨﺪ‪.‬‬ ‫ﻣﺜﺎﻝ ‪:‬‬ ‫‪Clearwdt‬‬ ‫‪Main:‬‬ ‫‪Goto Main‬‬ ‫‪End‬‬

‫‪ : COUNT .۱ -۳-۱۰‬ﺷﻤﺮﺩﻥ ﭘﺎﻟﺴﻬﺎﯼ ﺭﻭﯼ ﭘﻴﻦ ﻭﺭﻭﺩﯼ‬ ‫ﺗﺮﮐﻴﺐ ‪:‬‬ ‫‪COUNT Pin , Period , No_Impulses‬‬

‫ﺷﺮﺡ ‪:‬‬ ‫ﺍﻳﻦ ﺩﺳﺘﻮﺭ ﺗﻌﺪﺍﺩ ﺿﺮﺑﻪ ﻫﺎﯼ ﺭﻭﯼ ﭘﻴﻦ ﻣﻮﺭﺩ ﻧﻈﺮ ﺭﺍ ﺩﺭ ﻣـﺪﺕ ﺯﻣـﺎﻥ ﺗﻌﺮﻳـﻒ ﺷـﺪﻩ ) ‪ ( Period‬ﻣـﯽ‬ ‫ﺷﻤﺮﺩ ﻭ ﺩﺭ ﻣﺘﻐﻴﺮ ‪ No_Impulse‬ﺫﺧﻴﺮﻩ ﻣﯽ ﮐﻨﺪ ‪ .‬ﭘﻴﻦ ﺑﻄﻮﺭ ﺍﺗﻮﻣﺎﺗﻴﮏ ﺑﺼﻮﺭﺕ ﻭﺭﻭﺩﯼ ﻃﺮﺍﺣﯽ ﻣـﯽ‬ ‫ﺷﻮﺩ‪ Period .‬ﺑﺮ ﺣﺴﺐ ﻣﻴﻠﯽ ﺛﺎﻧﻴﻪ ﺗﻌﺮﻳﻒ ﻣﯽ ﺷﻮﺩ ‪ .‬ﺍﮔﺮ ﺍﺳـﻴﻼﺗﻮﺭ ‪ ۴‬ﻣﮕـﺎﻫﺮﺗﺰ ﺑﺎﺷـﺪ‪ ،‬ﭼـﮏ ﮐـﺮﺩﻥ‬ ‫ﻭﺿﻌﻴﺖ ﭘﻴﻦ ﻫﺮ ‪ ۲۰‬ﻣﻴﮑﺮﻭ ﺛﺎﻧﻴﻪ ﺍﻧﺠﺎﻡ ﻣﯽ ﮔﻴﺮﺩ‪ .‬ﺍﮔﺮ ﺧﻮﺍﺳﺘﻪ ﺑﺎﺷﻴﻢ ﺑﺎ ﺍﺳﻴﻼﺗﻮﺭ ﺩﻳﮕـﺮﯼ ﮐـﺎﺭ ﮐﻨـﻴﻢ‬ ‫ﺑﺎﻳﺪ ﺍﺯ ‪ DEFINE OSC‬ﺍﺳﺘﻔﺎﺩﻩ ﮐﻨﻴﻢ ‪.‬‬ ‫‪ Pin‬ﻣﻤﮑﻦ ﺍﺳﺖ ﻳﮏ ﻋﺪﺩ ﺑﻴﻦ ‪۰‬ﺗﺎ ‪ ۱۵‬ﻳﺎ ﻳﮏ ﻣﺘﻐﻴﺮ ﮐﻪ ﻣﻘﺪﺍﺭﺵ ﺑﻴﻦ ‪ ۰‬ﺗﺎ ‪ ۱۵‬ﺍﺳﺖ ﻳﺎ ﺍﺳـﻢ ﭘـﻴﻦ )‬ ‫ﻣﺎﻧﻨﺪ ‪ ( PORTA.0‬ﺑﺎﺷﺪ‪.‬‬ ‫ﺩﺭ ﺍﻳﻦ ﺭﻭﺵ ﻣﺎ ﺑﻪ ﺁﺳﺎﻧﯽ ﻓﺮﮐﺎﻧﺲ ﻳﮏ ﺳﻴﮕﻨﺎﻝ ﺭﺍ ﺑﺼﻮﺭﺕ ﺳﺎﺩﻩ ﺍﯼ ﺍﺯ ﺭﻭﯼ ﺗﻌﺪﺍﺩ ﺍﻳﻤﭙﺎﻟﺴﻬﺎ ﻣﺤﺎﺳﺒﻪ‬ ‫ﻣﯽ ﮐﻨﻴﻢ‪ .‬ﺑﺎﻻﺗﺮﻳﻦ ﻓﺮﮐﺎﻧﺲ ﻗﺎﺑﻞ ﻣﺤﺎﺳﺒﻪ ﺑﺎ ﺍﺳﻴﻼﺗﻮﺭ ‪۴‬ﻣﮕﺎﻫﺮﺗﺰ ﻫﺴـﺖ ‪۲۵‬ﮐﻴﻠـﻮ ﻫﺮﺗـﺰ ﺍﺳـﺖ ﻭ ﺍﮔـﺮ‬ ‫ﺍﺳﻴﻼﺗﻮﺭ ‪ ۲۰‬ﻣﮕﺎﻫﺮﺗﺰ ﺍﺳﺘﻔﺎﺩﻩ ﺷﻮﺩ ﺗﺎ ‪ ۱۲۵‬ﮐﻴﻠﻮﻫﺮﺗﺰ ﺭﺍ ﻣﯽ ﺗﻮﺍﻥ ﻣﺤﺎﺳﺒﻪ ﮐﺮﺩ ‪.‬‬ ‫ﻣﺜﺎﻝ ‪:‬‬ ‫‪W0 var‬‬ ‫‪byte‬‬ ‫‪TRISA = $FF‬‬ ‫‪Main:‬‬ ‫ﺷﻤﺮﺩﻥ ﺿﺮﺑﻪ ﻫﺎ ﺩﺭ ﻳﮏ ﺛﺎﻧﻴﻪ' ‪Count PORTA.0,1000,W0‬‬ ‫‪PORTB = W0‬‬ ‫‪Goto Main‬‬ ‫‪End‬‬

‫‪۲۱‬‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫‪ : DATA .۱ -۳-۱۱‬ﻧﻮﺷﺘﻦ ﺩﺭ ‪ EEPROM‬ﺩﺍﺧﻠﯽ ﺩﺭ ﺍﺑﺘﺪﺍﯼ ﺑﺮﻧﺎﻣﻪ‬ ‫ﺗﺮﮐﻴﺐ ‪:‬‬ ‫…‪{Lable} DATA {@PoCadr},constant, constant,‬‬

‫ﺷﺮﺡ ‪:‬‬

‫‪ DATA‬ﻣﻘﺎﺩﻳﺮ ﺛﺎﺑﺖ ﺭﺍ ﺩﺭ ﺩﺍﺧﻞ ‪ EEPROM‬ﺩﺍﺧﻠﯽ ﺩﺭ ﺍﺑﺘﺪﺍﯼ ﻧﻮﺷﺘﻦ ﮐﺪ ﻣﻴﮑﺮﻭﮐﻨﺘﺮﻟﺮ ﺫﺧﻴﺮﻩ ﻣﯽ‬ ‫ﮐﻨﺪ‪ .‬ﺍﮔﺮ ﺁﺩﺭﺱ ﺩﺭ ﺩﺳﺘﻮﺭ ﻣﻮﺭﺩ ﻧﻈﺮ ﺣﺬﻑ ﺷﺪﻩ ﺑﺎﺷﺪ ﺛﺎﺑﺘﻬﺎ ﺍﺯ ﺁﺩﺭﺱ ﺻﻔﺮ ﺫﺧﻴﺮﻩ ﻣﯽ ﺷﻮﺩ ‪.‬‬ ‫ﺛﺎﺑﺖ ﻣﻤﮑﻦ ﺍﺳﺖ ﺍﺯ ﻧﻮﻉ ‪ INTEGER‬ﻳﺎ ‪ STRING‬ﺑﺎﺷـﺪ ﻳـﮏ ﺛﺎﺑـﺖ ‪ STRING‬ﺑﺼـﻮﺭﺕ ﺑﺎﻳﺘﻬـﺎﯼ‬ ‫ﻣﺘﻮﺍﻟﯽ ﺍﺯ ﻣﻘﺎﺩﻳﺮ ﮐﺪ ‪ ASCII‬ﺫﺧﻴﺮﻩ ﻣﯽ ﺷﻮﺩ ‪ .‬ﺍﮔﺮ ﻻﺯﻡ ﺑﺎﺷﺪ ﮐﻪ ﻳﮏ ﻋﺪﺩ ﺩﻭ ﺑﺎﻳﺘﯽ ﺩﺭ‪EEPROM‬‬ ‫ﺫﺧﻴﺮﻩ ﺷﻮﺩ ﺑﺎﻳﺴﺘﯽ ﺍﺯ ﮐﻠﻤﻪ "‪ "WORD‬ﻗﺒﻞ ﺍﺯ ﺛﺎﺑﺖ ﺍﺳﺘﻔﺎﺩﻩ ﮐﺮﺩ ﺩﺭ ﻏﻴﺮ ﺍﻳﻨﺼﻮﺭﺕ ‪ ،‬ﺗﻨﻬـﺎ ﺑﺎﻳـﺖ ﺑـﺎ‬ ‫ﺍﺭﺯﺵ ﮐﻤﺘﺮ ﺫﺧﻴﺮﻩ ﻣﯽ ﺷﻮﺩ‪ .‬ﺩﺳﺘﻮﺭ ‪ DATA‬ﺗﻨﻬﺎ ﺩﺭ ﻣﻴﮑﺮﻭﮐﻨﺘﺮﻟﺮ ﻫﺎﯼ ‪ PIC‬ﮐﻪ ﺩﺍﺭﺍﯼ ‪EEPROM‬‬ ‫ﺩﺍﺧﻠﯽ ﻣﯽ ﺑﺎﺷﺪ ﻣﺎﻧﻨﺪ ‪ PIC16F84‬ﻳﺎ ﺳﺮﯼ ‪ 16F87X‬ﻗﺎﺑﻞ ﺍﺟﺮﺍ ﺍﺳﺖ‪.‬‬ ‫‪ DATA‬ﺗﻨﻬﺎ ﻳﮏ ﻣﺮﺗﺒﻪ ﺩﺭ ﻓﻀﺎﯼ ﺣﺎﻓﻈﻪ ‪ EEPROM‬ﻣﯽ ﺗﻮﺍﻧﺪ ﺫﺧﻴﺮﻩ ﺷﻮﺩ ﻭ ﺁﻥ ﻫﻢ ﺩﺭ ﺯﻣﺎﻥ ﺑﺮﻧﺎﻣﻪ‬ ‫ﺭﻳﺰﯼ ﻣﻴﮑﺮﻭﮐﻨﺘﺮﻟﺮ ﻣﯽ ﺑﺎﺷﺪ ﻭ ﻧﻪ ﻫﺮ ﺯﻣﺎﻧﯽ ﮐﻪ ﺑﺮﻧﺎﻣﻪ ﺍﺟﺮﺍ ﻣﯽ ﺷـﻮﺩ ‪ .‬ﺩﺳـﺘﻮﺭ ‪ WRITE‬ﺑـﺮﺍﯼ ﻗـﺮﺍﺭ‬ ‫ﺩﺍﺩﻥ ﻣﻘﺎﺩﻳﺮ ﺑﺮ ﺭﻭﯼ ‪ EEPROM‬ﺩﺍﺧﻠﯽ ﺩﺭ ﻫﻨﮕﺎﻡ ﺍﺟﺮﺍﯼ ﺑﺮﻧﺎﻣﻪ )‪ ( RUNTIME‬ﻣﯽ ﺗﻮﺍﻧﺪ ﺍﺳـﺘﻔﺎﺩﻩ‬ ‫ﺷﻮﺩ‪.‬‬ ‫ﻣﺜﺎﻝ ‪:‬‬ ‫‪@5,1,2,3‬‬

‫‪data‬‬

‫ﻧﻮﺷﺘﻦ ﻣﻘﺪﺍﺭﻫﺎﯼ ‪ ۲ ، ۱‬ﻭ ‪ ۳‬ﺭﻭﯼ ﻣﻮﻗﻌﻴﺘﻬﺎﯼ ‪ ۶ ، ۵‬ﻭ ‪ ۷‬ﺣﺎﻓﻈﻪ ‪EEPROM‬‬ ‫‪data word $1234‬‬ ‫ﻧﻮﺷﺘﻦ ﻣﻘﺪﺍﺭﻫﺎﯼ ‪ $12‬ﻭ ‪ $34‬ﺩﺭ ﻣﻮﻗﻌﻴﺘﻬﺎﯼ ‪ ۰‬ﻭ ‪ ۱‬ﺣﺎﻓﻈﻪ ‪EEPROM‬‬ ‫)‪Data (4),0(10‬‬ ‫ﭘﺮﻳﺪﻥ ﺑﻪ ﻣﻮﻗﻌﻴﺖ ﭼﻬﺎﺭﻡ ﻭ ﺫﺧﻴﺮﻩ ‪10 0s‬‬

‫‪ : DTMFOUT .۱ -۳-۱۲‬ﺗﻮﻟﻴﺪ ﮐﺮﺩﻥ ﺳﻴﮕﻨﺎﻝ ﺻﺪﺍ )ﺗﻮﻥ( ﺷﻤﺎﺭﮔﻴﺮﯼ ﺭﻭﯼ ﭘﻴﻦ ﺧﺮﻭﺟﯽ‬ ‫ﺗﺮﮐﻴﺐ ‪:‬‬ ‫]}…‪DTMFOUT PIN , {ONMS,OFFMS,}[TONE{,TONE‬‬

‫ﺷﺮﺡ ‪:‬‬ ‫ﺩﺳﺘﻮﺭ ‪ DTMFOUT‬ﺗﻮﻥ ﺷﻤﺎﺭﮔﻴﺮﯼ ﺭﺍ ) ﻣﺜﻼ ﺑﺮﺍﯼ ﺗﻠﻔﻨﻬﺎ ( ﺗﻮﻟﻴـﺪ ﻣـﯽ ﮐﻨـﺪ ‪ .‬ﭘـﺎﺭﺍﻣﺘﺮ ‪ONMS‬‬ ‫ﻣﺪﺕ ﺯﻣﺎﻥ ﻫﺮ ﺷﻤﺎﺭﮔﻴﺮﯼ ﺭﺍ ﻧﺸﺎﻥ ﻣﯽ ﺩﻫﺪ‪ .‬ﻭ ‪ OFFMS‬ﻣﺪﺕ ﻗﻄـﻊ ﺑـﻴﻦ ﺩﻭ ﺻـﺪﺍﯼ ﭘـﯽ ﺩﺭﭘـﯽ ﺭﺍ‬ ‫ﻣﺸﺨﺺ ﻣﯽ ﮐﻨﺪ ‪ .‬ﺍﮔﺮ ﭘﺎﺭﺍﻣﺘﺮﻫﺎﯼ ﻓﻮﻕ ﻣﻘﺪﺍﺭﮔﺬﺍﺭﯼ ﻧﺸﻮﻧﺪ ‪ ۲۰۰ ONMS‬ﻣﻴﻠـﯽ ﺛﺎﻧﻴـﻪ ﻭ ‪OFFMS‬‬ ‫‪ ۵۰‬ﻣﻴﻠﯽ ﺛﺎﻧﻴﻪ ﻣﻘﺪﺍﺭ ﮔﺬﺍﺭﯼ ﻣﯽ ﺷﻮﻧﺪ ‪ .‬ﺍﻳﻦ ﺩﺳﺘﻮﺭ ﺑﺮﺍﯼ ‪ ۱۶‬ﺷﻤﺎﺭﻩ ﺻﺪﺍ ﺗﻮﻟﻴﺪ ﻣـﯽ ﮐﻨـﺪ ﮐـﻪ ﺑـﺮﺍﯼ‬ ‫ﺷﻤﺎﺭﻫﻬﺎﯼ ‪ ۰‬ﺗﺎ ‪ ۹‬ﺻﺪﺍﻳﯽ ﻣﻄﺎﺑﻖ ﺑﺎ ﺻﺪﺍﯼ ﺷﻤﺎﺭﮔﻴﺮ ﺗﻠﻔﻦ ﺗﻮﻟﻴﺪ ﻣﯽ ﮐﻨﺪ ﻭ ﺻﺪﺍﯼ ‪ ۱۰‬ﻫﻤﺎﻥ ﺻـﺪﺍﯼ‬ ‫ﮐﻠﻴﺪ * ﺑﺮ ﺭﻭﯼ ﮐﻴﺒﻮﺭﺩ) ‪ ( key board‬ﺗﻠﻔﻦ ﻣﯽ ﺑﺎﺷﺪ ﻭ ‪ ۱۱‬ﻫﻤﺎﻥ ﺻﺪﺍﯼ ﮐﻠﻴﺪ ‪ #‬ﺭﺍ ﺗﻮﻟﻴﺪ ﻣﯽ ﮐﻨـﺪ‬ ‫ﻭ‪ ۱۲‬ﺗﺎ ‪ ۱۵‬ﺻﺪﺍﯼ ﻣﺸﺎﺑﻪ ﮐﻠﻴﺪﻫﺎﯼ ‪ A‬ﺗﺎ ‪ D‬ﺗﻮﻟﻴﺪ ﻣﯽ ﮐﻨﻨﺪ ‪.‬‬

‫‪۲۲‬‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫ﺷﮑﻞ ‪ (1-3.‬ﻓﻴﻠﺘﺮ ﺑﺮﺍﯼ ﺑﺪﺳﺖ ﺁﻭﺭﺩﻥ ﺷﮑﻞ ﺳﻴﻨﻮﺳﯽ‬

‫ﺑﺮﺍﯼ ﺑﺪﺳﺖ ﺁﻭﺭﺩﻥ ﺷﮑﻞ ﺳﻴﻨﻮﺳﯽ ﺩﺭ ﺧﺮﻭﺟﯽ ﻳﮏ ﻓﻴﻠﺘﺮ ﻣﻨﺎﺳﺐ )ﺗﻄﺒﻴﻘـﯽ( ﺍﺣﺘﻴـﺎﺝ ﻣـﯽ ﺑﺎﺷـﺪ ﺗـﺎ‬ ‫ﺗﻌﺪﺍﺩﯼ ﺍﺯ ﻫﺎﺭﻣﻮﻧﻴﻬﺎ ﺭﺍ ﺍﺯ ﺑﻴﻦ ﺑﺒﺮﺩ ﻭﺳﻴﻨﻮﺳﯽ ﺭﺍ ﺻﺎﻓﺘﺮ ﮐﻨﺪ ‪.‬‬ ‫‪ DTMFOUT‬ﺑﺎ ﺍﺳﻴﻼﺗﻮﺭ ‪ ۲۰‬ﻣﮕﺎﻫﺮﺗﺰ ﺑﻬﺘﺮ ﮐﺎﺭ ﻣﯽ ﮐﻨﺪ ﺍﻟﺒﺘﻪ ﺑﺎ ﺍﺳﻴﻼﺗﻮﺭ ‪ ۴‬ﻣﮕﺎﻫﺮﺗﺰ ﻧﻴـﺰ ﮐـﺎﺭ ﻣـﯽ‬ ‫ﮐﻨﺪ ﻭﻟﯽ ﻓﻴﻠﺘﺮ ﮐﺮﺩﻥ ﺁﻥ ﻭ ﺗﺒـﺪﻳﻞ ﺁﻥ ﺑـﻪ ﺳﻴﻨﻮﺳـﯽ ﺳـﺨﺘﺘﺮ ﺍﺳـﺖ‪ .‬ﺩﺳـﺘﻮﺭ ‪ DTMFOUT‬ﺍﺯ ﺗـﺎﺑﻊ‬ ‫‪ FREQOUT‬ﺑﺮﺍﯼ ﺗﻮﻟﻴﺪ ﺻﺪﺍﯼ ﺷﻤﺎﺭﮔﻴﺮﯼ ﺍﺳﺘﻔﺎﺩﻩ ﻣﯽ ﮐﻨﺪ‪ FREQOUT .‬ﺻـﺪﺍﯼ ﻣـﻮﺭﺩ ﻧﻈـﺮ ﺭﺍ‬ ‫ﺑﺼﻮﺭﺕ ﻣﺪﻭﻻﺳﻴﻮﻥ ﭘﻬﻨﺎﯼ ﭘﺎﻟﺲ ﺗﻮﻟﻴﺪ ﻣﯽ ﮐﻨﺪ‪.‬‬ ‫ﻣﺜﺎﻝ ‪:‬‬ ‫‪TRISB = $FF‬‬ ‫‪Main:‬‬ ‫]‪Dtmfout PORTB.1,[2,1,2‬‬ ‫‪goto Loop‬‬ ‫‪End‬‬

‫‪.۱ -۳-۱۳‬‬ ‫ﺗﺮﮐﻴﺐ‪:‬‬

‫‪Loop:‬‬

‫‪ :EEPROM‬ﻣﺠﻤﻮﻋﻪ ﺛﺎﺑﺘﻬﺎﯼ ﺍﻭﻟﻴﻪ ﺑﺮﺍﯼ ﺑﺮﻧﺎﻣﻪ ﻧﻮﺳﯽ ‪EEPROM‬‬ ‫}‪EEPROM {@location, } constant {, constant‬‬

‫ﺷﺮﺡ ‪:‬‬ ‫ﻣﺠﻤﻮﻋﻪ ﺍﯼ ﺍﺯ ﺛﺎﺑﺘﻬﺎ ﺭﺍ ﺩﺭ ‪ EEPROM‬ﺩﺍﺧﻠﯽ ﻣﻴﮑﺮﻭﮐﻨﺘﺮﻟﺮ ﻗﺮﺍﺭ ﻣﯽ ﺩﻫﺪ ‪ .‬ﺍﻳﻦ ﺩﺳﺘﻮﺭ ﺗﻨﻬﺎ ﺩﺭ ﺍﺑﺘﺪﺍ‬ ‫ﻭ ﻳﺎ ﺍﻧﺘﻬﺎﯼ ﺑﺮﻧﺎﻣﻪ ﻗﺮﺍﺭ ﻣﯽ ﮔﻴﺮﺩ ﻭ ﺑﺮﺍﯼ ﺧﻮﺍﻧﺪﻥ ﻭ ﻧﻮﺷﺘﻦ ﺩﺭ ﻭﺳﻂ ﺑﺮﻧﺎﻣﻪ ﻭ ﺩﺭﺣﺎﻝ ﺍﺟﺮﺍ ﺍﺯ ﺩﺳﺘﻮﺭﺍﺕ‬ ‫‪ WRITE‬ﻭ ‪ READ‬ﺍﺳﺘﻔﺎﺩﻩ ﻣﯽ ﺷﻮﺩ‪.‬‬ ‫ﺍﻳﻦ ﺩﺳﺘﻮﺭ ﺩﺭ ﻣﻴﮑﺮﻭﮐﻨﺘﺮﻟﺮﻫﺎﯼ ﮐﻪ ﺑﺎ ‪ I2C‬ﺑﺎ ‪ EEPROM‬ﺧﺎﺭﺟﯽ ﺍﺭﺗﺒﺎﻁ ﺑﺮﻗﺮﺍﺭ ﻣﯽ ﮐﻨﻨﺪ ﻗﺎﺑﻞ ﺍﺟﺮﺍ‬ ‫ﻧﻴﺴﺖ ‪.‬‬ ‫ﻣﺜﺎﻝ ‪:‬‬

‫‪۲۳‬‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫‪EEPROM @5,1,2,3‬‬

‫ﻣﻘﺎﺩﻳﺮ ‪ ۲ ، ۱‬ﻭ ‪ ۳‬ﺭﺍ ﺩﺭ ﻣﻮﻗﻌﻴﺘﻬﺎﯼ ‪ ۶ ، ۵‬ﻭ ‪ EEPROM ۷‬ﻗﺮﺍﺭ ﻣﯽ ﺩﻫﺪ‪.‬‬ ‫‪EEPROM @5,1,2,3‬‬

‫ﻣﻘﺎﺩﻳﺮ‪ $12‬ﻭ ‪ $34‬ﺭﺍ ﺩﺭ ﻣﻮﻗﻌﻴﺘﻬﺎﯼ ‪ ۰‬ﻭ ‪ EEPROM ۱‬ﻗﺮﺍﺭ ﻣﯽ ﺩﻫﺪ‪.‬‬ ‫‪ : END .۱ -۳-۱۴‬ﻧﺸﺎﻧﻪ ﮔﺬﺍﺭﯼ ﭘﺎﻳﺎﻥ ﺑﺮﻧﺎﻣﻪ‬ ‫ﺗﺮﮐﻴﺐ ‪:‬‬ ‫‪END‬‬

‫ﺷﺮﺡ ‪:‬‬ ‫ﺍﺯ ﺍﺟﺮﺍﯼ ﺑﻴﺸﺘﺮ ﺑﺮﻧﺎﻣﻪ ﺟﻠﻮﮔﻴﺮﯼ ﻣﯽ ﮐﻨﺪ ﻭ ﺑﺮﻧﺎﻣﻪ ﺭﺍ ﺑﻪ ﺣﺎﻟﺖ ﮐﻢ ﻣﺼﺮﻑ ﺩﺭ ﻣﯽ ﺁﻭﺭﺩ ﺷﺒﻴﻪ ﺩﺳـﺘﻮﺭ‬ ‫‪ SLEEP‬ﮐﻪ ﺩﺭ ﻳﮏ ﺣﻠﻘﻪ ﻗﺮﺍﺭ ﮔﺮﻓﺘﻪ ﺍﺳﺖ‪ .‬ﺍﻳﻦ ﺩﺳﺘﻮﺭ ﺩﺭ ﺍﻧﺘﻬﺎﯼ ﺑﺮﻧﺎﻣﻪ ﻧﻮﺷﺘﻪ ﻣﯽ ﺷﻮﺩ‪.‬‬ ‫‪ : FOR … NEXT .۱ -۳-۱۵‬ﺗﮑﺮﺍﺭ ﮐﺮﺩﻥ ﻳﮏ ﻗﺴﻤﺖ ﺍﺯ ﺑﺮﻧﺎﻣﻪ‬ ‫ﺗﺮﮐﻴﺐ ‪:‬‬ ‫} ‪FOR Index = Start TO End {Step {-} Inc‬‬ ‫‪{ instructions,‬‬ ‫} ‪instructions‬‬ ‫}‪NEXT {Index‬‬

‫ﺷﺮﺡ ‪:‬‬

‫"‪ "Index‬ﻣﺘﻐﻴﺮﯼ ﺍﺳﺖ ﮐﻪ ﺑﺮﺍﯼ ﮐﻨﺘﺮﻝ ﭼﮕﻮﻧﮕﯽ ﺗﻌﺪﺍﺩ ﺑﺎﺭﻫﺎﯼ ﮐﻪ ﺣﻠﻘﻪ ﺍﺟﺮﺍ ﻣﯽ ﺷﻮﺩ ﺍﺳﺘﻔﺎﺩﻩ ﻣﯽ‬ ‫ﺷﻮﺩ‪ .‬ﺍﮔﺮ ﭘﺎﺭﺍ ﻣﺘﺮ ‪ step‬ﺍﺳﺘﻔﺎﺩﻩ ﻧﺸﻮﺩ ﻣﺘﻐﻴﺮ ﻳﮑﯽ ﻳﮑﯽ ﺍﻓﺰﺍﻳﺶ ﻣﯽ ﻳﺎﺑﺪ) ‪(index = index + 1‬‬

‫‪ : FREQOUT .۱ -۳-۱۶‬ﺗﻮﻟﻴﺪ ﺳﻴﮕﻨﺎﻝ ﺑﺎ ﻓﺮﮐﺎﻧﺲ ﻣﺸﺨﺺ ﺭﻭﯼ ﭘﻴﻦ ﺧﺮﻭﺟﯽ‬ ‫ﺗﺮﮐﻴﺐ ‪:‬‬ ‫‪FREQOUT Pin, Onms, Freq1, Freq2‬‬

‫ﺷﺮﺡ ‪:‬‬

‫‪ FREQOUT‬ﺳﻴﮕﻨﺎﻝ ‪ PWM‬ﺑﺎ ﺭﻧﺞ ﻓﺮﮐﺎﻧﺴـﯽ ﺍﺯ ‪ ۰‬ﺗـﺎ ‪ ۳۲۷۶۷‬ﻫﺮﺗـﺰ ﺭﻭﯼ ﭘـﻴﻦ ﺗﻌﺮﻳـﻒ ﺷـﺪﻩ ﺩﺭ‬ ‫ﭘﺎﺭﺍﻣﺘﺮ " ‪ " pin‬ﻭ ﺑﺎ ﻣﺪﺕ ﺯﻣﺎﻥ " ‪ " onms‬ﺗﻮﻟﻴﺪ ﻣﯽ ﮐﻨﺪ ‪ FREQOUT .‬ﺑﺎ ﺍﺳـﻴﻼﺗﻮﺭ ‪ 20MHZ‬ﺑﻬﺘـﺮ‬ ‫ﮐﺎﺭ ﻣﯽ ﮐﻨﺪ‪ "onms" .‬ﻣﺪﺕ ﺯﻣﺎﻥ ﺳﻴﮕﻨﺎﻝ ﺑﺮ ﺣﺴﺐ ﻣﻴﻠﯽ ﺛﺎﻧﻴﻪ ﺭﺍ ﻧﺸﺎﻥ ﻣﯽ ﺩﻫﺪ‪.‬‬

‫ﺷﮑﻞ ‪ ( 1-4.‬ﻓﻴﻠﺘﺮ ﺑﺮﺍﯼ ﺑﺪﺳﺖ ﺁﻭﺭﺩﻥ ﺷﮑﻞ ﺳﻴﻨﻮﺳﯽ‬

‫‪۲۴‬‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫ﺑﺮﺍﯼ ﺑﺪﺳﺖ ﺁﻭﺭﺩﻥ ﺳﻴﮕﻨﺎﻝ ﺳﻴﻨﻮﺳﯽ ﻣﻄﻠﻮﺏ ﺩﺭ ﺧﻮﺭﺟﯽ ﻧﺼﺐ ﻳﮏ ﻓﻴﻠﺘﺮ ﻻﺯﻡ ﺍﺳﺖ‪.‬‬ ‫ﻣﺜﺎﻝ ‪:‬‬ ‫‪freqout PORTB.1,2000,1000‬‬ ‫ﺳﻴﮕﻨﺎﻝ ﺑﺎ ﻓﺮﮐﺎﻧﺲ ‪ 1000HZ‬ﺩﺭ ﻣﺪﺕ ‪ ۲‬ﺛﺎﻧﻴﻪ ﺩﺭ ﭘﻴﻦ ‪ 1‬ﭘﻮﺭﺕ ‪ B‬ﺗﻮﻟﻴﺪ ﻣﯽ ﮐﻨﺪ‪.‬‬ ‫‪ : GOSUB .۱ -۳-۱۷‬ﻓﺮﺍﺧﻮﺍﻧﯽ ﺯﻳﺮ ﺑﺮﻧﺎﻣﻪ ﻫﺎﯼ ‪BASIC‬‬

‫ﺗﺮﮐﻴﺐ ‪:‬‬

‫‪GOSUB label‬‬

‫ﺷﺮﺡ ‪:‬‬ ‫ﺑﺎ ﺍﻳﻦ ﺩﺳﺘﻮﺭ ﺑﺮﻧﺎﻣﻪ ﺑﻪ ﺯﻳﺮ ﺑﺮﻧﺎﻣﻪ ﺍﯼ ﮐﻪ ﺑﻴﻦ " ‪ " label‬ﻭ ﺩﺳﺘﻮﺭ ‪ RETURN‬ﻗﺮﺍﺭﺩﺍﺭﺩ ﻣﯽ ﺭﻭﺩ‪ .‬ﺯﻳـﺮ‬ ‫ﺑﺮﻧﺎﻣﻪ ﻫﺎ ﻣﯽ ﺗﻮﺍﻧﻨﺪ ﺗﻮﺩﺭﺗﻮ ﺑﺎﺷﻨﺪ‪ .‬ﺍﻳﻦ ﺣﺎﻟﺖ ﺗﺎ ﭼﻬﺎﺭ ﺳﻄﺢ ﻣﯽ ﺗﻮﺍﻧﺪ ﻋﻤﻖ ﺩﺍﺷـﺘﻪ ﺑﺎﺷـﺪ ﻭ ﺩﻟﻴـﻞ ﺁﻥ‬ ‫ﻣﺤﺪﻭﺩ ﺑﻮﺩﻥ ﭘﺸﺘﻪ ﻣﯽ ﺑﺎﺷﺪ‪.‬‬ ‫ﻣﺜﺎﻝ ‪:‬‬ ‫‪Main :‬‬ ‫ﻓﺮﺍﺧﻮﺍﻧﯽ ﺯﻳﺮ ﺑﺮﻧﺎﻣﻪ ‪' Blink‬‬

‫‪gosub Blink‬‬ ‫‪Loop: goto Loop‬‬

‫ﺯﻳﺮ ﺑﺮﻧﺎﻣﻪ ‪' Blink‬‬

‫‪Blink:‬‬ ‫‪PORTB = $FF‬‬ ‫‪Pause 1000‬‬ ‫‪PORTB = $00‬‬ ‫‪Pause 1000‬‬ ‫‪Return‬‬ ‫‪End‬‬

‫‪ : GOTO .۱ -۳-۱۸‬ﺍﺩﺍﻣﻪ ﺑﺮﻧﺎﻣﻪ ﺍﺯ ﺑﺮﭼﺴﺐ ﻣﺸﺨﺺ ﺷﺪﻩ‬ ‫ﺗﺮﮐﻴﺐ ‪:‬‬ ‫‪GOTO label‬‬

‫ﺷﺮﺡ ‪:‬‬ ‫ﺍﻳﻦ ﺑﺮ ﻧﺎﻣﻪ ﭘﺮﺵ ﺑﻪ ﻫﺮ ﺟﺎﻳﯽ ﺍﺯ ﺑﺮﻧﺎﻣﻪ ﺭﺍ ﻣﻤﮑﻦ ﻣﯽ ﺳﺎﺯﺩ ‪ .‬ﺗﮑﺮﺍﺭ ﺯﻳﺎﺩ ﺍﻳﻦ ﺩﺳﺘﻮﺭ ﺩﺭ ﺑﺮﻧﺎﻣﻪ ﺗﻮﺻﻴﻪ‬ ‫ﻧﻤﯽ ﺷﻮﺩ ﺯﻳﺮﺍ ﻗﺎﺑﻞ ﻓﻬﻢ ﺑﻮﺩﻥ ﺑﺮﻧﺎﻣﻪ ﺭﺍ ﮐﻤﺘﺮ ﻣﯽ ﮐﻨﺪ‪.‬‬ ‫‪ : HIGH .۱ -۳-۱۹‬ﻧﺸﺎﻧﺪﻥ ﻳﮏ ﻣﻨﻄﻘﯽ ﺭﻭﯼ ﭘﻴﻦ ﺧﺮﻭﺟﯽ‬ ‫ﺗﺮﮐﻴﺐ ‪:‬‬ ‫‪HIGH Pin‬‬

‫‪۲۵‬‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫ﺷﺮﺡ ‪:‬‬ ‫ﭘﻴﻦ ﻣﻮﺭﺩ ﻧﻈﺮ ﺭﺍ ﺑﻪ ﺳﻄﺢ ﺑﺎﻻ ﻣﯽ ﺁﻭﺭﺩ‪ .‬ﺍﻳﻦ ﺩﺳﺘﻮﺭ ﺑﻄﻮﺭ ﺧﻮﺩﮐﺎﺭ ﭘﻴﻦ ﺭﺍ ﺩﺭ ﮔﺮﺍﻳﺶ ﺧﺮﻭﺟﯽ ﻗﺮﺍﺭ ﻣﯽ‬ ‫ﺩﻫﺪ‪ .‬ﭘﻴﻦ ﻣﻤﮑﻦ ﺍﺳﺖ ﻳﮏ ﻋﺪﺩ ﺛﺎﺑﺖ ﺑﻴﻦ ‪ ۰‬ﺗﺎ ‪ ۱۵‬ﻳﺎ ﻳﮏ ﻋﺪﺩ ﻣﺘﻐﻴﺮ ﮐﻪ ﻣﺤﺘﻮﺍﯼ ﺁﻥ ﺑﻴﻦ ‪ ۰‬ﺗﺎ ‪ ۱۵‬ﻭ‬ ‫ﻳﺎ ﺍﺳﻢ ﭘﻮﺭﺕ ﺑﺎﺷﺪ‪.‬ﺍﮔﺮ ﭘﻴﻦ ﻣﻮﺭﺩ ﻧﻈﺮ ﺩﺭ ﮔﺮﺍﻳﺶ ﺧﺮﻭﺟﯽ ﺑﺎﺷﺪ ﺍﺳﺘﻔﺎﺩﻩ ﺍﺯ ﻋﺒﺎﺭﺕ ﺯﻳﺮ ﻣﻨﺎﺳﺒﺘﺮ ﺍﺳـﺖ ‪.‬‬ ‫‪PORTB.0 = 1.‬‬ ‫ﻣﺜﺎﻝ ‪:‬‬

‫‪: HESERIN .۱ -۳-۲۰‬‬ ‫ﺳﺨﺖ ﺍﻓﺰﺍﺭ ﻭﺭﻭﺩﯼ ﺁﺳﻨﮑﺮﻭﻥ‬ ‫ﺗﺮﮐﻴﺐ ‪:‬‬ ‫])‪HSERIN {Error,}{Timeout, Label,}[Modifier(,...‬‬

‫ﺷﺮﺡ ‪:‬‬

‫‪ HSERIN‬ﺍﻃﻼﻋﺎﺕ ﺭﺍ ﺑﺼﻮﺭﺕ ﺳﺮﻳﺎﻝ ﺩﺭﻳﺎﻓﺖ ﻣﯽ ﮐﻨﺪ‪ .‬ﺍﻳﻦ ﺩﺳﺘﻮﺭ ﺑـﺎ ﻣﻴﮑﺮﻭﮐﻨﺘﺮﻟﺮﻫـﺎﯼ ﮐـﻪ ﺩﺍﺭﺍﯼ‬ ‫ﻭﺍﺣﺪ ﺳﺨﺖ ﺍﻓﺰﺍﺭﯼ ﺍﺭﺗﺒﺎﻁ ﺳـﺮﻳﺎﻝ ) ﺳـﺨﺖ ﺍﻓـﺰﺍﺭ ‪ ( USART‬ﻣـﯽ ﺑﺎﺷـﻨﺪ ‪ ،‬ﺑﮑـﺎﺭ ﻣـﯽ ﺭﻭﺩ )ﻣﺎﻧﻨـﺪ‬ ‫ﻣﻴﮑﺮﻭﮐﻨﺘﺮﻟﺮ ‪ .( 16F877‬ﭘﺎﺭﺍﻣﺘﺮﻫﺎﯼ ﺍﻧﺘﻘﺎﻝ ﺳﺮﻳﺎﻝ ﺑﺎ ﺩﺳﺘﻮﺭ ‪ DEFINE‬ﺗﻌﻴﻴﻦ ﻣﯽ ﺷﻮﺩ‪.‬‬

‫ﻋﻤﻠﮑﺮﺩ ‪ HSERIN‬ﺑﺎ ﺍﺳﻴﻼﺗﻮﺭ ‪ 4MHZ‬ﺍﺯ ﭘﻴﺶ ﺗﻌﺮﻳﻒ ﺷﺪﻩ ﺍﺳﺖ ﻭﺑﺮﺍﯼ ﮐﺎﺭ ﮐﺮﺩﻥ ﺑﺎ ﺍﺳﻴﻼﺗﻮﺭﻫﺎﯼ‬ ‫ﺩﻳﮕﺮ ﺑﺎﻳﺴﺘﯽ ﺍﺯ ﺩﺳﺘﻮﺭ ﺍﺳﻴﻼﺗﻮﺭ ﻣﻮﺭﺩ ﻧﻈﺮ ﺭﺍ ﺩﺭ ﺍﺑﺘﺪﺍﯼ ﺑﺮﻧﺎﻣﻪ ﺗﻌﺮﻳﻒ ﮐﺮﺩ‪.‬‬ ‫ﺍﺻﻼﺡ ﮐﻨﻨﺪﻩ‬

‫ﭼﮕﻮﻧﮕﯽ ﮐﺎﺭﮐﺮﺩ‬ ‫ﮔﺮﻓﺘﻦ ﺭﻗﻤﻬﺎﯼ ﺑﺎﻳﻨﺮﯼ‬

‫}‪BIN{1..16‬‬

‫ﮔﺮﻓﺘﻦ ﺭﻗﻤﻬﺎﯼ ﺩﺳﻴﻤﺎﻝ‬

‫}‪DEC{1..5‬‬

‫ﮔﺮﻓﺘﻦ ﺭﻗﻤﻬﺎﯼ ﻫﮕﺰﺍ ﺩﺳﻴﻤﺎﻝ‬

‫}‪HEX{1..4‬‬

‫ﻧﮕﺮﻓﺘﻦ ﮐﺮﮐﺘﺮ ﺑﻌﺪ ﺍﺯ ﮐﺮﮐﺘﺮ ‪n‬ﺍﻡ‬

‫‪SKIP n‬‬

‫ﮔﺮﻓﺘﻦ ﻣﺘﻮﺍﻟﯽ ‪ n‬ﮐﺮﮐﺘﺮ ﺗﺎ ﺯﻣﺎﻧﯽ ﮐﻪ ﮐﺮﮐﺘﺮ ‪) c‬ﺍﺧﺘﻴﺎﺭﯼ( ﺑﻴﺎﻳﺪ‬

‫}‪STR ArrayVar\n{\c‬‬

‫ﺍﻧﺘﻈﺎﺭ ﺑﺮﺍﯼ ﮐﺮﮐﺘﺮ ﻫﺎﯼ ﻣﺘﻮﺍﻟﯽ‬

‫) ( ‪WAIT‬‬

‫ﺍﻧﺘﻈﺎﺭ ﺑﺮﺍﯼ ﺭﺷﺘﻪ‬

‫}‪WAITSTR ArrayVar{\n‬‬ ‫ﺗﻌﻴﻴﻦ ﻓﺮﮐﺎﻧﺲ ﻣﻮﺭﺩ ﻧﻈﺮ ‘‬

‫‪DEFINE OSC tact‬‬

‫‪۲۶‬‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫ﭘﺎﺭﺍﻣﺘﺮﻫﺎﯼ " ‪ " Time out‬ﻭ " ‪ " Label‬ﻣﻮﺟﺐ ﻣﯽ ﺷﻮﻧﺪ ﮐﻪ ﺍﮔﺮ ﻫﻴﭻ ﮐﺮﮐﺘﺮﯼ ﺩﺭﻳﺎﻓﺖ ﻧﺸﺪ ﺑﺮﻧﺎﻣـﻪ‬ ‫ﺑﻌﺪ ﺍﺯ ﺯﻣﺎﻥ" ‪ ) " Time out‬ﺑﺮ ﺣﺴﺐ ﻣﻴﻠﯽ ﺛﺎﻧﻴﻪ ( ﺍﺯ ﺑﺮﭼﺴﺐ ‪ Label‬ﺍﺩﺍﻣﻪ ﻣﯽ ﻳﺎﺑـﺪ‪ .‬ﻗﺎﻟـﺐ ﺑﻨـﺪﯼ‬ ‫ﺍﻃﻼﻋﺎﺕ ﺳﺮﻳﺎﻝ ﻣﯽ ﺗﻮﺍﻧﺪ ‪ ۸ ) 8N1‬ﺑﻴﺖ ﺍﻃﻼﻋﺎﺕ ﺑﺪﻭﻥ ﺑﻴﺖ ﺗﻮﺍﺯﻥ ﻭﺑﺎ ﺗﻨﻬﺎ ﻳﮏ ﺑﻴﺖ ﺗﻮﻗﻒ ( ﻭ ‪7E1‬‬ ‫) ‪۷‬ﺑﻴﺖ ﺍﺯ ﺍﻃﻼﻋﺎﺕ ‪ ،‬ﺑﻴﺖ ﺗﻮﺍﺯﻥ ﻭ ﻳﮏ ﺑﻴﺖ ﺗﻮﻗﻒ ( ﺍﺳﺘﻔﺎﺩﻩ ﺷﻮﺩ ﮐﻪ ﺑﺎ ﺩﺳﺘﻮﺭ ‪ DEFINE‬ﺗﻌﻴﻴﻦ ﻣﯽ‬ ‫ﺷﻮﺩ‪.‬‬ ‫ﭼﮏ ﮐﺮﺩﻥ ‪DEFINE HSER_EVEN 1 ‘ parity‬‬ ‫ﭼﮏ ﮐﺮﺩﻥ ‪DEFINE HSER_ODD 1 ‘ Non_parity‬‬

‫ﺑﺮﻧﺎﻣﻪ ﻣﻤﮑﻦ ﺍﺳﺖ ﺩﺍﺭﺍﯼ ﻳﮏ ﺑﺮﭼﺴﺐ "‪ "Error‬ﺑﺎﺷﺪ ﮐﻪ ﺑﺎ ﺗﻮﺟﻪ ﺑﻪ ﺧﻄﺎ ﻭ ﺩﺭﺳﺖ ﻧﺒﻮﺩﻥ ﭘﺮﻳﺘﯽ ﺑـﻪ‬ ‫ﺁﻥ ﺑﺮﭼﺴﺐ ﻣﯽ ﭘﺮﺩ‪ .‬ﺍﺻﻼﺡ ﮐﻨﻨﺪﻩ ﻫﺎ ﺩﺭ ﺟﺪﻭﻝ ﺯﻳﺮ ﺁﻣﺪﻩ ﺍﺳﺖ‪.‬‬ ‫ﻣﺜﺎﻝ‪:‬‬

‫‪ : HPWM .۱ -۳-۲۱‬ﺗﻮﻟﻴﺪ ﮐﺮﺩﻥ ﺳﻴﮕﻨﺎﻝ ‪ PWM‬ﺭﻭﯼ ﭘﻴﻦ ﻣﻴﮑﺮﻭﮐﻨﺘﺮﻟﺮ‬ ‫ﺗﺮﮐﻴﺐ ‪:‬‬ ‫‪HPWM Channel,Relation_on_off, Frequency‬‬

‫ﺷﺮﺡ ‪:‬‬ ‫ﺍﻳﻦ ﻓﺮﻣﺎﻥ ﺍﺯ ﺳﺨﺖ ﺍﻓﺰﺍﺭ ‪ PWM‬ﺭﻭﯼ ﻣﻴﮑﺮﻭﮐﻨﺘﺮﻟﺮ ﻫﺎﯼ ﮐﻪ ﺩﺍﺭﺍﯼ ﺍﻳﻦ ﺍﻣﮑﺎﻥ ﻫﺴﺘﻨﺪ ﺍﺳﺘﻔﺎﺩﻩ ﮐـﺮﺩﻩ‬ ‫ﺍﺳﺖ ﻭ ﺳﻴﮕﻨﺎﻝ ‪ PWM‬ﺭﺍ ﺗﻮﻟﻴﺪ ﻣﯽ ﮐﻨﺪ‪.‬‬ ‫ﭘﺎﺭﺍﻣﺘﺮ "‪ "channel‬ﮐﺎﻧﺎﻝ ‪ PWM‬ﺭﺍ ﺗﻌﺮﻳﻒ ﻣﯽ ﮐﻨﺪ ﺗﻌﺪﺍﺩ ﺍﻳﻦ ﮐﺎﻧﺎﻟﻬﺎ ﺑﺴﺘﮕﯽ ﺑﻪ ﻧـﻮﻉ ﻣﻴﮑﺮﻭﮐﻨﺘﺮﻟـﺮ‬ ‫ﺩﺍﺭﺩ ﻭ ﺑﻴﻦ ‪ ۱‬ﺗﺎ ‪ ۳‬ﮐﺎﻧﺎﻝ ﺍﺳﺖ ‪ .‬ﺑﺮﺍﯼ ﺩﻭ ﮐﺎﻧﺎﻟﻪ ﻫﺎ ﻫﻨﮕﺎﻡ ﺭﺍﻩ ﺍﻧﺪﺍﺯﯼ ﻫﺮ ﺩﻭ ﮐﺎﻧﺎﻝ ﻓﺮﮐﺎﻧﺲ ﺁﻧﻬﺎ ﺑﺎﻳﺴﺘﯽ‬ ‫ﻳﮑﺴﺎﻥ ﺑﺎﺷﺪ‪ Relation_on_off .‬ﻧﺴﺒﺖ ﺑﻴﻦ ﺳﻴﮕﻨﺎﻝ ‪ on‬ﻭ ‪ off‬ﺭﺍ ﻣﺸﺨﺺ ﻣﯽ ﮐﻨﺪ ﻭ ﻣﻘـﺪﺍﺭ ﺻـﻔﺮ‬ ‫ﺳﻴﮕﻨﺎﻝ ﺧﺎﻣﻮﺵ ﺭﺍ ﺭﻭﯼ ﭘﻴﻦ ﻣﯽ ﻓﺮﺳﺘﺪ ﻭ ﻣﻘـﺪﺍﺭ ‪ ۲۵۵‬ﺳـﻴﮕﻨﺎﻝ ﻫﻤﻴﺸـﻪ ﺭﻭﺷـﻦ ﺭﺍ ﺭﻭﯼ ﭘـﻴﻦ ﻣـﯽ‬ ‫ﻓﺮﺳﺘﺪ‪ .‬ﭘﺎﺭﺍﻣﺘﺮ "‪ "Frequency‬ﻓﺮﮐﺎﻧﺲ ﺳﻴﮕﻨﺎﻝ ‪ PWM‬ﺭﺍ ﻣﺸﺨﺺ ﻣﯽ ﮐﻨﺪ‪ ) .‬ﮐﻤﺘﺮﻳﻦ ﻓﺮﮐﺎﻧﺲ ﺩﺭ‬ ‫ﺍﺳــﻴﻼﺗﻮﺭ ‪ 245HZ ، 4MHZ‬ﻭ ﺑـﺎﻻﺗﺮﻳﻦ ﻓﺮﮐــﺎﻧﺲ ﻣﻤﮑــﻦ ﺩﺭ ﺍﺳــﻴﻼﺗﻮﺭ ﺳــﺮﻳﻊ ‪ ۳۲۷۶۷‬ﻫﺮﺗــﺰ ﺍﺳــﺖ (‪.‬‬ ‫‪ HPWM‬ﺑﻄﻮﺭ ﭘﻴﻮﺳﺘﻪ ﺩﺭ ﺯﻣﺎﻥ ﺍﺟﺮﺍﯼ ﺑﺮﻧﺎﻣﻪ ﮐﺎﺭ ﻣﯽ ﮐﻨﺪ‪ .‬ﺗﻌﺪﺍﺩﯼ ﺍﺯ ﻗﻄﻌﺎﺕ ﻣﻤﮑﻦ ﺍﺳـﺖ ﭘﻴﻨﻬـﺎﯼ‬ ‫ﭼﻨﺪ ﮐﺎﺭ ﮐﻪ ‪ HPWM‬ﺭﺍ ﺩﺍﺭﻧﺪ ﺩﺍﺷﺘﻪ ﺑﺎﺷﻨﺪ ‪ DEFINE .‬ﺍﺟﺎﺯﻩ ﺍﺳﺘﻔﺎﺩﻩ ﺍﺯ ﺍﻳﻦ ﭘﻴﻨﻬﺎ ﺭﺍ ﺩﺭ ﺍﻳﻦ ﺭﺍﺳـﺘﺎ‬ ‫ﻣﯽ ﺩﻫﺪ‪.‬‬ ‫‪'Hpwm 1 pin port‬‬ ‫‪'Hpwm 1 pin bit‬‬

‫‪DEFINE CCP1_REG PORTC‬‬ ‫‪DEFINE CCP1_BIT 2‬‬

‫‪۲۷‬‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫‪DEFINE CCP2_REG PORTC‬‬ ‫‪'Hpwm 2 pin port‬‬ ‫‪DEFINE CCP2_BIT 1‬‬ ‫‪'Hpwm 2 pin bit‬‬ ‫ﺗﻌﺮﻳﻔﻬﺎﯼ ﺯﻳﺮ ﻧﺸﺎﻥ ﻣﯽ ﺩﻫﻨﺪ ﮐﻪ ﺗﺎﻳﻤﺮ ‪ ۱‬ﻳﺎ ‪ ۲‬ﺑﺮﺍﯼ ﺗﻮﻟﻴﺪ ‪ PWM‬ﺭﻭﯼ ﮐﺎﻧﺎﻝ ‪ ۲‬ﻳﺎ ‪ ۳‬ﺻﻮﺭﺕ ﺑﮕﻴﺮﺩ‪.‬‬

‫ﺍﻧﺘﺨﺎﺏ ﺗﺎﻳﻤﺮ‬

‫ﻣﺜﺎﻝ ‪:‬‬

‫ﺑﺮﺍﯼ ‪'Hpwm 2‬‬

‫‪DEFINE HPWM2_TIMER 1‬‬

‫‪'Hpwm 3‬‬

‫‪DEFINE HPWM3_TIMER 1‬‬

‫ﺍﻧﺘﺨﺎﺏ ﺗﺎﻳﻤﺮ ﺑﺮﺍﯼ‬

‫ﮐﺎﻧﺎﻝ ﺩﻭﻡ ﺑﺎ ﺍﺳﺘﻔﺎﺩﻩ ﺍﺯ ﺗﺎﻳﻤﺮ‪' ۱‬‬ ‫‪‘ 25% PWM on 1kHz‬‬

‫‪DEFINE HPWM2_TIMER 1‬‬ ‫‪hpwm 2, 64, 1000‬‬

‫‪ : HSEROUT .۱ -۳-۲۲‬ﺳﺨﺖ ﺍﻓﺰﺍﺭ ﺧﺮﻭﺟﯽ ﺁﺳﻨﮑﺮﻭﻥ‬ ‫ﺗﺮﮐﻴﺐ ‪:‬‬ ‫]}‪HSEROUT [Item{,Item...‬‬

‫ﺷﺮﺡ ‪:‬‬

‫‪ HSEROUT‬ﺍﻃﻼﻋﺎﺕ ﺭﺍ ﺍﺯ ﻃﺮﻳﻖ ﺳﺨﺖ ﺍﻓﺰﺍﺭ ‪ USART‬ﺑﻪ ﺻﻮﺭﺕ ﺳﺮﻳﺎﻝ ﻣﯽ ﻓﺮﺳﺘﺪ‪ .‬ﭘﺎﺭﺍﻣﺘﺮﻫﺎﯼ‬ ‫ﺍﻧﺘﻘﺎﻝ ﺑﻮﺳﻴﻠﻪ ‪ DEFINE‬ﺗﻌﺮﻳﻒ ﻣﯽ ﺷﻮﺩ‪.‬‬ ‫ﻗﺮﺍﺭ ﺩﺍﺩﻥ ﻣﻘﺪﺍﺭ ﻣﻨﺎﺳﺐ ﺩﺭ ﺭﺟﻴﺴﺘﺮ ﺩﺭﻳﺎﻓﺖ ‘ ‪DEFINE HSER_RCSTA 90h‬‬ ‫ﻗﺮﺍﺭ ﺩﺍﺩﻥ ﻣﻘﺪﺍﺭ ﻣﻨﺎﺳﺐ ﺩﺭ ﺭﺟﻴﺴﺘﺮ ﺍﻧﺘﺸﺎﺭ ‘ ‪DEFINE HSER_TXSTA 20h‬‬ ‫ﺳﺮﻋﺖ ﺍﻧﺘﻘﺎﻝ)‪DEFINE HSER_BAUD 2400 ‘ (Baud rate‬‬ ‫ﻗﺮﺍﺭ ﺩﺍﺩﻥ ﻣﻘﺪﺍﺭ ﻣﻨﺎﺳﺐ ﺑﻄﻮﺭ ﻣﺴﺘﻘﻴﻢ ﺩﺭ‪DEFINE HSER_SPBRG 25 ‘ SPBRG‬‬

‫ﺍﻳﻦ ﺳﺮﻋﺘﻬﺎﯼ ﺍﻧﺘﻘﺎﻝ ﮐﻪ ﺗﻌﺮﻳﻒ ﺷﺪ ﺑﺮﺍﯼ ﻣﻴﮑﺮﻭﮐﻨﺘﺮﻟﺮﯼ ﺑﺎ ﺍﺳﻴﻼﺗﻮﺭ ‪ 4MHZ‬ﻣـﯽ ﺑﺎﺷـﺪ ﻭﺑـﺮﺍﯼ ﺩﻳﮕـﺮ‬ ‫ﺍﺳﻴﻼﺗﻮﺭﻫﺎ ﺑﺎﻳﺴﺘﯽ ﺗﻌﺮﻳﻒ ﺩﺭﺍﺑﺘﺪﺍﯼ ﺑﺮﻧﺎﻣﻪ ﺻﻮﺭﺕ ﺑﮕﻴﺮﺩ‪ .‬ﻗﺎﻟﺐ ﺑﻨﺪﯼ ﻫـﺎﯼ ﻣﺨﺘﻠـﻒ ﻧﻴـﺰ ﺑـﺎ ﺩﺳـﺘﻮﺭ‬ ‫‪ DEFINE‬ﺗﻌﺮﻳﻒ ﻣﯽ ﺷﻮﺩ‪.‬‬ ‫ﭼﮏ ﮐﺮﺩﻥ ‪DEFINE HSER_EVEN 1 ‘parity‬‬ ‫‪DEFINE HSER_ODD 1‬‬ ‫ﭼﮏ ﮐﺮﺩﻥ ‪‘Non_ parity‬‬ ‫ﻓﺮﺳﺘﺎﺩﻩ ﺷﺪﻩ‬

‫ﺍﺻﻼﺡ ﮐﻨﻨﺪﻩ ﻫﺎ‬

‫ﻣﻘﺪﺍﺭ ‪binary‬‬

‫}‪{I}{S} BIN{1..16‬‬

‫ﻣﻘﺪﺍﺭ ‪decimal‬‬

‫}‪{I}{S} DEC{1..5‬‬

‫ﻣﻘﺪﺍﺭ ‪hexadecimal‬‬

‫}‪{I}{S} HEX{1..4‬‬

‫ﮐﺮﮐﺘﺮ‪ n ،c‬ﺑﺎﺭ ﺗﮑﺮﺍﺭ ﻣﯽ ﺷﻮﺩ‬

‫‪REP c/n‬‬

‫‪ n‬ﮐﺮﮐﺘﺮ ﺭﺷﺘﻪ‬

‫}‪STR ArrayVar {\n‬‬ ‫ﺟﺪﻭﻝ‬

‫ﻣﺜﺎﻝ ‪:‬‬

‫‪۱-۷‬‬ ‫‪B0 var byte‬‬ ‫‪B0 = 4‬‬

‫‪۲۸‬‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫‪Main :‬‬ ‫ﻓﺮﺳﺘﺎﺩﻥ ﻣﻘﺪﺍﺭ ﺩﺳﻴﻤﺎﻝ ﺍﺯ ﻣﺘﻐﻴﺮ ‪ B0‬ﻭ ﻣﻘﺪﺍﺭ ‪‘۱۰‬‬

‫]‪hserout [dec B0, 10‬‬ ‫‪Loop: goto Loop‬‬ ‫‪End‬‬

‫‪ : I2CREAD .۱ -۳-۲۳‬ﺧﻮﺍﻧﺪﻥ ﺍﻃﻼﻋﺎﺕ ﺍﺯ ﻭﺳﺎﻳﻞ ﺟﺎﻧﺒﯽ ‪I2C‬‬

‫ﺗﺮﮐﻴﺐ ‪:‬‬

‫} ‪I2CREAD Data,Frequency,Control_byte,{Address,}[Variable{,Variable...}]{,Label‬‬

‫ﺷﺮﺡ ‪:‬‬ ‫ﺍﻃﻼﻋــﺎﺕ ﺁﺩﺭﺱ ﻭﮐﻨﺘــﺮﻝ ﺍﺭﺳــﺎﻝ ﺷــﺪﻩ ﺍﺯ ﺧــﻂ ‪ I2C‬ﺩﺭ ﻣﺘﻐﻴــﺮ "‪ "Variable‬ﺫﺧﻴــﺮﻩ ﻣــﯽ ﺷـﻮﺩ ‪.‬‬ ‫‪ I2CREAD‬ﻭ‪ I2CWRITE‬ﺑﺮﺍﯼ ﺧﻮﺍﻧﺪﻥ ﻭ ﻧﻮﺷﺘﻦ ﺍﻃﻼﻋﺎﺕ ﺑﺮ ﺭﻭﯼ ﻭﺍﺣﺪﻫﺎﯼ ﺟﺎﻧﺒﯽ ﺍﺳﺘﻔﺎﺩﻩ ﻣـﯽ‬ ‫ﺷﻮﺩ‪ .‬ﺍﻳﻦ ﺩﺳﺘﻮﺭﻫﺎ ﻣﯽ ﺗﻮﺍﻧﻨﺪ ﺍﺭﺗﺒﺎﻁ ﺑﺎ ﻭﺳﺎﻳﻞ ﮐﻪ ﺩﺍﺭﺍﯼ ﺧﻂ ﺍﺭﺗﺒﺎﻃﯽ ‪ I2C‬ﻫﺴﺘﻨﺪ ﺍﺭﺗﺒﺎﻁ ﺑﺮﻗﺮﺍﺭ ﮐﻨﺪ‬ ‫ﺍﺯ ﻗﺒﻴﻞ ﺳﻨﺴﻮﺭﻫﺎﯼ ﺩﻣﺎ ‪A/D ،‬ﻫﺎ ‪EEPROM ،‬ﻫﺎﯼ ﺳﺮﻳﺎﻝ ﻭ ﻏﻴﺮﻩ‪.‬‬ ‫‪ ۷‬ﺑﻴﺖ ﺑﺎﻻﺗﺮ ﮐﺪ ﮐﻨﺘﺮﻟﯽ ﺑﺮﺍﯼ ﺍﻧﺘﺨﺎﺏ ﭼﻴﭗ ﻣﻮﺭﺩ ﻧﻈﺮ ﺑﮑﺎﺭ ﻣﯽ ﺭﻭﺩ ﺑﻴﺖ ﭘﺎﻳﻴﻨﺘﺮ )‪ (LSB‬ﺭﻭﺵ ﺟﺎﺭﯼ‬ ‫) ﺧﻮﺍﻧﺪﻥ ﻳﺎ ﻧﻮﺷﺘﻦ ( ﺭﺍ ﺗﻌﻴﻴﻦ ﻣﯽ ﮐﻨﺪ‪ .‬ﺑﺮﺍﯼ ﻣﺜﺎﻝ ﺑﺮﺍﯼ ﺍﺭﺗﺒﺎﻁ ﺑﺎ ‪ EEPROM‬ﺳﺮﻳﺎﻝ ‪، 24LC01B‬‬ ‫ﺁﺩﺭﺱ ﺩﺭﺧﻮﺍﺳﺘﯽ ‪۸‬ﺑﻴﺖ ﺍﺳﺖ ﮐﻪ ﮐﺪ ﮐﻨﺘﺮﻟﯽ ‪ %1010‬ﺍﺳﺖ ﻭﺍﻧﺘﺨﺎﺏ ﭼﻴﭗ ﺩﺭ ﺍﻳﻨﺠﺎ ﺑﮑﺎﺭ ﻧﻤﯽ ﺁﻳـﺪ‬ ‫ﭘﺲ ﺑﻴﺖ ﮐﻨﺘﺮﻭﻟﯽ ﻣﻤﮑﻦ ﺍﺳﺖ ‪ %10100000‬ﺑﺎﺷﺪ‪.‬‬ ‫ﻗﺎﻟﺐ ﺑﻨﺪﯼ ﭼﻨﺪﻳﻦ ‪ EEPROM‬ﺳﺮﻳﺎﻝ ﺩﺭ ﺯﻳﺮ ﻧﺸﺎﻥ ﺩﺍﺩﻩ ﺷﺪﻩ ﺍﺳﺖ‪.‬‬ ‫ﺍﻧﺪﺍﺯﻩ ﺁﺩﺭﺱ‬

‫ﮐﻠﻤﻪ ﮐﻨﺘﺮﻟﯽ‬

‫ﻇﺮﻓﻴﺖ‬

‫‪1 byte‬‬ ‫‪1 byte‬‬ ‫‪1 byte‬‬ ‫‪1 byte‬‬ ‫‪1 byte‬‬ ‫‪2 bytes‬‬ ‫‪2 bytes‬‬

‫‪%1010xxx0‬‬ ‫‪%1010xxx0‬‬ ‫‪%1010xxb0‬‬ ‫‪%1010xbb0‬‬ ‫‪%1010bbb0‬‬ ‫‪%1010ddd0‬‬ ‫‪%1010ddd0‬‬

‫‪128 bytes‬‬ ‫‪256 bytes‬‬ ‫‪512 bytes‬‬ ‫‪1K bytes‬‬ ‫‪2K bytes‬‬ ‫‪4K bytes‬‬ ‫‪8K bytes‬‬

‫ﺟﺪﻭﻝ ‪۱-۸‬‬

‫‪EEPROM‬‬ ‫‪24LC01B‬‬ ‫‪24LC02B‬‬ ‫‪24LC04B‬‬ ‫‪24LC08B‬‬ ‫‪24LC16B‬‬ ‫‪24LC32B‬‬ ‫‪24LC65‬‬ ‫اﻧﺘﺨﺎب ﺑﻠﻮک = ‪bbb‬‬ ‫ﺑﯿﺘﻬﺎی اﻧﺘﺨﺎب وﺳﯿﻠﻪ = ‪ddd‬‬ ‫ﺑﺪون اﺛﺮ = ‪xxx‬‬

‫ﺍﮔﺮ ﺍﻃﻼﻋﺎﺕ ﺩﻭ ﺑﺎﻳﺘﯽ )‪ (WORD‬ﺩﺭﻳﺎﻓﺖ ﺷﻮﺩ ﺍﺑﺘﺪﺍ ﺑﺎﻳﺖ ﺑﺎﻻﺗﺮ ﺩﺭﻳﺎﻓﺖ ﻣﯽ ﺷﻮﺩ ﻭﺑﻌﺪ ﺑﺎﻳﺖ ﭘﺎﻳﻴﻨﺘﺮ‪.‬‬ ‫ﺑﺮﺍﯼ ﺩﺭﻳﺎﻓﺖ ﺭﺷﺘﻪ ‪ STR ،‬ﺑﻌﺪ ﺍﺳﻢ ﺭﺷﺘﻪ ﻣﯽ ﺁﻳﺪ ﻭﺗﻌﺪﺍﺩ ﮐﺮﮐﺘﺮﻫﺎ ﺑﻌﺪ ﺍﺯ \ ﻣﯽ ﺁﻳﺪ‪.‬‬ ‫]‪a var byte[8‬‬ ‫]‪I2CREAD PORTC.4, PORTC.3, $a0, 0, [STR a\8‬‬

‫ﺍﮔﺮ ﺍﺯ ﺑﺮ ﭼﺴﺐ ﺍﺳﺘﻔﺎﺩﻩ ﺷﻮﺩ ‪ ،‬ﺩﺭﺻﻮﺭﺕ ﺩﺭﻳﺎﻓﺖ ﻧﮑـﺮﺩﻥ ﭼﻴـﺰﯼ ﺑـﺮ ﺭﻭﯼ ﻣـﺪﺍﺭ ﻭﺍﺳـﻂ ‪ I2C‬ﺑـﻪ ﺁﻥ‬ ‫ﺑﺮﭼﺴﺐ ﻣﯽ ﭘﺮﺩ‪ .‬ﺳﺮﻋﺖ ﺍﻧﺘﻘﺎﻝ ﺍﺳﺘﺎﻧﺪﺍﺭﺩ ‪ 100KHZ‬ﻣﯽ ﺑﺎﺷﺪ ﮐﻪ ﺑﺎ ﺍﺳﻴﻼﺗﻮﺭ ‪ 8MHZ‬ﺑﺪﺳﺖ ﻣﯽ ﺁﻳﺪ ﻭ‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫‪۲۹‬‬

‫ﺑﺮﺍﯼ ﺳﺮﻋﺘﻬﺎﯼ ﺑﺎﻻﺗﺮ ) ‪ ( 400KHZ‬ﺍﺯ ﺍﺳﻴﻼﺗﻮﺭ ‪ 20MHZ‬ﺍﺳـﺘﻔﺎﺩﻩ ﻣـﯽ ﺷـﻮﺩ‪ .‬ﺍﮔـﺮ ﺍﺯ ﺍﺳـﻴﻼﺗﻮﺭ ﮐﻨـﺪﺗﺮ‬ ‫ﺍﺳﺘﻔﺎﺩﻩ ﺷﻮﺩ ﺑﺎﻳﺴﺘﯽ ﺩﺳﺘﻮﺭﺍﻟﻌﻤﻞ ﺯﻳﺮ ﺑﺮﺍﯼ ﺗﻌﺮﻳﻒ ﺁﻥ ﺑﮑﺎﺭ ﺭﻭﺩ‪.‬‬ ‫‪DEFINE I2C_SLOW 1‬‬

‫ﻣﺜﺎﻝ ‪:‬‬ ‫‪B0 var byte‬‬ ‫‪addr var byte‬‬ ‫‪cont con %10100000‬‬ ‫ﺁﺩﺭﺱ ﮐﻨﺘﺮﻟﯽ‪‘ EEPROM‬‬ ‫‪addr = 17‬‬ ‫ﺍﻃﻼﻋﺎﺕ ﺍﺯ ﺁﺩﺭﺱ ‪ ۱۷‬ﺧﻮﺍﻧﺪﻩ ﻣﯽ ﺷﻮﺩ ‘‬ ‫‪Main:‬‬ ‫ﻗﺮﺍﺭ ﺩﺍﺩﻥ ﺍﻃﻼﻋﺎﺕ ﺩﺭ ‪I2CREAD PORTA.0, PORTA.1, cont, addr, [B0] ‘B0‬‬ ‫‪Loop: goto Loop‬‬ ‫‪End‬‬ ‫‪ : I2CWRITE .۱ -۳-۲۴‬ﻧﻮﺷﺘﻦ ﺍﻃﻼﻋﺎﺕ ﺑﺮ ﺭﻭﯼ ﻭﺳﺎﻳﻞ ﺟﺎﻧﺒﯽ ‪I2C‬‬

‫ﺗﺮﮐﻴﺐ ‪:‬‬

‫} ‪I2CWRITE Data, Frequency, Control_byte, {Address,} [Vari {, Vari...}]{,Label‬‬

‫ﺷﺮﺡ ‪:‬‬

‫‪ I2CWRITE‬ﺍﻃﻼﻋﺎﺕ ﮐﻨﺘﺮﻝ ﻭ ﺁﺩﺭﺱ ﺭﺍ ﺗﻮﺳﻂ ﻣﺪﺍﺭ ﻭﺍﺳﻂ ‪ I2C‬ﻣﯽ ﻓﺮﺳـﺘﺪ‪ .‬ﺍﮔـﺮ ﻭﺳـﻴﻠﻪ ﺟـﺎﻧﺒﯽ‬ ‫‪ EEPROM‬ﺳﺮﻳﺎﻝ ﺑﺎﺷﺪ ‪ ،‬ﺍﻧﺘﻈﺎﺭ ‪۱۰‬ﻣﻴﻠﯽ ﺛﺎﻧﻴﻪ ﺑﺮﺍﯼ ﭘﺎﻳﺎﻥ ﮔﺮﻓﺘﻦ ﻧﻮﺷﺘﻦ ﻻﺯﻡ ﺍﺳﺖ‪.‬ﺍﮔﺮ ﻗﺒﻞ ﺍﺯ ﺍﻳﻦ‬ ‫ﺍﻧﺘﻈﺎﺭ ﺍﻃﻼﻋﺎﺗﯽ ﺭﺍ ﺑﻔﺮﺳﺘﻴﻢ ﺍﺯ ﻧﻮﺷﺘﻦ ﺁﻥ ﺟﻠﻮﮔﻴﺮﯼ ﻣﯽ ﺷﻮﺩ‪.‬ﺍﻧﺪﺍﺯﻩ ﺁﺩﺭﺱ ‪ ۱‬ﻳﺎ ‪ ۲‬ﺑﺎﻳـﺖ ﻣـﯽ ﺑﺎﺷـﺪ )‬ ‫ﻭﺍﺑﺴﺘﻪ ﺑﻪ ﻭﺳﻴﻠﻪ ﺍﯼ ﮐﻪ ﻣﺘﺼﻞ ﺷﺪﻩ ﺍﺳﺖ ( ‪ .‬ﺍﮔﺮ ﻣﺎ ﺍﺯ ﻭﺳﺎﻳﻞ ﺑﺪﻭﻥ ﺗﺎﺧﻴﺮ ﺍﺳﺘﻔﺎﺩﻩ ﮐﻨﻴﻢ ﻭ ﺩﻭﺑﺎﻳـﺖ )‬ ‫‪ ( WORD‬ﺭﺍ ﺑﻪ ﺳﻮﯼ ﺁﻥ ﺑﻔﺮﺳﺘﻴﻢ ﺍﺑﺘﺪﺍ ﺑﺎﻳﺖ ﺑﺎﻻﺗﺮ ﻭ ﺳﭙﺲ ﺑﺎﻳﺖ ﭘﺎﻳﻴﻨﺘﺮ ﻓﺮﺳﺘﺎﺩﻩ ﻣﯽ ﺷـﻮﺩ‪ .‬ﺑـﺮﺍﯼ‬ ‫ﺍﻧﺘﻘﺎﻝ ﺭﺷﺘﻪ ‪ STR ،‬ﻗﺒﻞ ﺍﺯ ﺍﺳﻢ ﺭﺷﺘﻪ ﻣﯽ ﺁﻳﺪ ﻭ ﺗﻌﺪﺍﺩ ﮐﺮﮐﺘﺮﻫﺎ ﺑﻌﺪ ﺍﺯ "\" ﻣﯽ ﺁﻳﺪ‪.‬‬ ‫]‪a var byte[8‬‬ ‫]‪I2CWRITE PORTC.4, PORTC.3, $a0, 0, [STR a\8‬‬

‫ﺍﮔﺮ ﺳﻴﮕﻨﺎﻝ ﭘﺎﺳﺨﯽ ﺭﻭﯼ ﻣﺪﺍﺭ ﻭﺍﺳﻂ ‪ I2C‬ﻭﺟﻮﺩ ﻧﺪﺍﺷﺘﻪ ﺑﺎﺷﺪ ﺑﺮﻧﺎﻣﻪ ﺑﻪ ﺑﺮﭼﺴـﺐ ﺍﺧﺘﻴـﺎﺭﯼ ﺧﻮﺍﻫـﺪ‬ ‫ﭘﺮﻳﺪ ‪ .‬ﺳﺮﻋﺖ ﺍﻧﺘﻘﺎﻝ ﺍﺳﺘﺎﻧﺪﺍﺭﺩ ‪ 100KHZ‬ﻣﯽ ﺑﺎﺷﺪ ﮐﻪ ﺑـﺎ ﺍﺳـﻴﻼﺗﻮﺭ ‪ 8MHZ‬ﺑﺪﺳـﺖ ﻣـﯽ ﺁﻳـﺪ ﻭ ﺑـﺮﺍﯼ‬ ‫ﺳﺮﻋﺘﻬﺎﯼ ﺑﺎﻻﺗﺮ ) ‪ ( 400KHZ‬ﺍﺯ ﺍﺳﻴﻼﺗﻮﺭ ‪ 20MHZ‬ﺍﺳﺘﻔﺎﺩﻩ ﻣﯽ ﺷﻮﺩ‪ .‬ﺍﮔﺮ ﺍﺯ ﺍﺳـﻴﻼﺗﻮﺭ ﮐﻨـﺪﺗﺮ ﺍﺳـﺘﻔﺎﺩﻩ‬ ‫ﺷﻮﺩ ﺑﺎﻳﺴﺘﯽ ﺩﺳﺘﻮﺭﺍﻟﻌﻤﻞ ﺯﻳﺮ ﺑﺮﺍﯼ ﺗﻌﺮﻳﻒ ﺁﻥ ﺑﮑﺎﺭ ﺭﻭﺩ‪.‬‬ ‫‪DEFINE I2C_SLOW 1‬‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫‪۳۰‬‬

‫ﺑﺮﺍﯼ ﺩﺍﺷﺘﻦ ﮐﻼﮎ ﻣﺪﺍﺭ ﻭﺍﺳﻂ ‪ I2C‬ﺩﻭ ﻗﻄﺒﯽ )‪ (Bipolar‬ﻭ ﻧﻪ ﻳﮏ ‪ open collector‬ﺩﺳﺘﻮﺭ ﺍﻟﻌﻤـﻞ‬ ‫‪ DEFINE‬ﺑﻪ ﺻﻮﺭﺕ ﺯﻳﺮ ﺍﺳﺘﻔﺎﺩﻩ ﺷﻮﺩ‪.‬‬ ‫‪DEFINE I2C_SCLOUT‬‬

‫ﺑﺮﺍﯼ ﻋﻤﻠﮑﺮﺩ ﻭﺍﺣﺪﻫﺎﯼ ﺟﺎﻧﺒﯽ ﺩﺍﺭﺍﯼ ﺍﺭﺗﺒﺎﻁ ‪ I2C‬ﺑﺎﻳﺴﺘﯽ ﺭﺍﻫﻨﻤﺎ ﻭ ﻣﺸﺨﺼﺎﺕ ﺳﺎﺯﻧﺪﻩ ﺧﻮﺍﻧﺪﻩ ﺷﻮﺩ ﺗﺎ‬ ‫ﺑﻴﺘﻬﺎﯼ ﮐﻨﺘﺮﻟﯽ ﻭ ﺗﺎﺧﻴﺮﻫﺎ ﻣﻨﺎﺳﺐ ﺑﺪﺳﺖ ﺁﻳﺪ‪.‬‬ ‫ﻣﺜﺎﻝ ‪:‬‬

‫ﻣﻘﺪﺍﺭ ‪ ۶‬ﺩﺭ ﺁﺩﺭﺱ ‪ ۱۷‬ﻗﺮﺍﺭ ﻣﯽ ﮔﻴﺮﺩ ‘‬

‫ﻣﻘﺪﺍﺭ ‪ B0‬ﺩﺭ ﺁﺩﺭﺱ ‪ ۱‬ﻗﺮﺍﺭ ﻣﯽ ﮔﻴﺮﺩ ‘‬

‫‪B0 var byte‬‬ ‫‪addr var byte‬‬ ‫‪cont con %10100000‬‬ ‫ﺁﺩﺭﺱ ﮐﻨﺘﺮﻟﯽ ‪‘ EEPROM‬‬ ‫‪Main:‬‬ ‫‪addr = 17‬‬ ‫ﺍﻃﻼﻋﺎﺕ ﺩﺭ ﺁﺩﺭﺱ ‪ ۱۷‬ﺭﻳﺨﺘﻪ ﻣﯽ ﺷﻮﺩ ‘‬ ‫]‪i2cwrite PORTA.0, PORTA.1, cont, addr, [6‬‬ ‫‪pause 10‬‬ ‫ﺍﻧﺘﻈﺎﺭ ‪ ۱۰‬ﻣﻴﻠﯽ ﺛﺎﻧﻴﻪ ﺗﺎ ﻧﻮﺷﺘﻦ ﺗﻤﺎﻡ ﺷﻮﺩ ‘‬ ‫‪addr = 1‬‬ ‫ﺍﻃﻼﻋﺎﺕ ﺩﺭ ﺁﺩﺭﺱ ‪ ۱‬ﺭﻳﺨﺘﻪ ﻣﯽ ﺷﻮﺩ ‘‬ ‫‪B0 = 23‬‬ ‫]‪i2cwrite PORTA.0, PORTA.1, cont, addr, [B0‬‬ ‫‪pause 10‬‬ ‫ﺍﻧﺘﻈﺎﺭ ‪ ۱۰‬ﻣﻴﻠﯽ ﺛﺎﻧﻴﻪ ﺗﺎ ﻧﻮﺷﺘﻦ ﺗﻤﺎﻡ ﺷﻮﺩ ‘‬ ‫‪Loop: goto Loop‬‬ ‫‪End‬‬

‫‪ : INPUT .۱ -۳-۲۵‬ﺑﺮﮔﺰﻳﺪﻥ ﭘﻴﻦ ‪ I/O‬ﺩﺭ ﮔﺮﺍﻳﺶ ﻭﺭﻭﺩﯼ‬ ‫ﺗﺮﮐﻴﺐ ‪:‬‬ ‫‪INPUT Pin‬‬

‫ﺷﺮﺡ ‪:‬‬ ‫ﺍﻳﻦ ﺩﺳﺘﻮﺭ ﮔﺮﺍﻳﺶ ﻭﺭﻭﺩﯼ ﻳﮏ ﭘﻴﻦ ﺭﺍ ﺗﻌﻴﻴﻦ ﻣﯽ ﮐﻨﺪ ﻣﺎ ﻣﯽ ﺗﻮﺍﻧﻴﻢ ﻫﻤﻪ ﭘﻴﻨﻬـﺎ ﻭﻳـﺎ ﻳـﮏ ﭘـﻴﻦ ﺭﺍ ﺍﺯ‬ ‫ﻃﺮﻳﻖ ﻣﻘﺪﺍﺭ ﮔﺬﺍﺭﯼ ﺩﺭ ‪ TRIS‬ﺑﺪﺳﺖ ﺁﻭﺭﻳﻢ‬ ‫ﻣﺜﺎﻝ ‪:‬‬ ‫‪TRISB = %11111111‬‬ ‫‪TRISA.1 = 1‬‬

‫‪ : IF … THEN … ELSE .۱ -۳-۲۶‬ﮔﺰﻳﻨﺶ ﻳﮏ ﻗﺴﻤﺖ ﺍﺯ ﺑﺮﻧﺎﻣﻪ‬ ‫ﺗﺮﮐﻴﺐ ‪:‬‬ ‫‪IF Expression1 { AND / OR Expression2} THEN Label‬‬ ‫}‪{instructions‬‬ ‫‪ELSE‬‬ ‫}‪{instructions‬‬ ‫‪ENDIF‬‬

‫‪۳۱‬‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫ﺷﺮﺡ ‪ :‬ﺍﻳﻦ ﺩﺳﺘﻮﺭ ﻳﮑﯽ ﺍﺯ ﺩﻭ ﺍﻣﮑﺎﻥ ﻣﺴﻴﺮ ﺑﺮﻧﺎﻣﻪ ﺭﺍ ﺍﻧﺘﺨﺎﺏ ﻣﯽ ﮐﻨﺪ ‪.‬‬

‫ﺷﮑﻞ‪( 1-5.‬‬

‫ﺩﺳﺘﻮﺭ ‪ IF‬ﺩﺳﺘﻮﺭ ﺍﺻﻠﯽ ﺷﺎﺧﻪ ﮔﺰﻳﻨﯽ ﺩﺭ ‪ PIC BASIC‬ﻭ ﺁﻥ ﻣـﯽ ﺗﻮﺍﻧـﺪ ﺑـﻪ ﭼﻨـﺪﻳﻦ ﻃﺮﻳـﻖ ﺑـﺮﺍﯼ‬ ‫ﺍﻧﻌﻄﺎﻑ ﭘﺬﻳﺮﯼ ﺩﺭ ﻓﻬﻢ ﺳﺎﺧﺖ ﻳﮏ ﺗﺼﻤﻴﻢ ﻣﻨﻄﻘﯽ ﺍﺳﺘﻔﺎﺩﻩ ﻣﯽ ﺷﻮﺩ ‪.‬‬ ‫ﻣﺜﺎﻝ ﺑﺮﺍﯼ ﺷﮑﻞ ﺳﺎﺩﻩ ﺍﻳﻦ ﺩﺳﺘﻮﺭ ‪:‬‬ ‫‪w var byte‬‬ ‫‪Main :‬‬ ‫‪IF PORTB.0=0 THEN Add‬‬ ‫‪goto Main‬‬ ‫‪Add : W=W+1‬‬ ‫‪End‬‬

‫ﺷﮑﻞ ﭘﻴﭽﻴﺪﻩ ﺗﺮ ﺍﻳﻦ ﺩﺳﺘﻮﺭ ﺍﺳﺘﻔﺎﺩﻩ ﺍﺯ ‪ ELSE‬ﻣﯽ ﺑﺎﺷﺪ‪.‬‬

‫ﺷﮑﻞ ‪(1-6.‬‬

‫‪۳۲‬‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫ﻣﺜﺎﻝ ‪:‬‬ ‫‪w var byte‬‬ ‫‪Main :‬‬ ‫‪IF (PORTB = $F0) && (PORTA.0 = 1) THEN Add‬‬ ‫‪ELSE Subtract‬‬ ‫‪ENDIF‬‬ ‫‪goto Main‬‬ ‫‪Add : W=W+1‬‬ ‫‪Subtract : W=W-1‬‬ ‫‪End‬‬

‫ﺑﺮﻧﺎﻣﻪ ﺑﺎﻻ ﺭﺍ ﻣﯽ ﺗﻮﺍﻥ ﺑﺼﻮﺭﺕ ﺯﻳﺮ ﻧﻴﺰ ﻧﻮﺷﺖ ‪:‬‬ ‫‪w var byte‬‬ ‫‪Main :‬‬ ‫‪IF PORTB.0=0 THEN W=W+1‬‬ ‫‪ELSE W=W-1‬‬ ‫‪ENDIF‬‬ ‫‪goto Main‬‬ ‫‪End‬‬

‫‪.۱ -۳-۲۷‬‬ ‫ﺗﺮﮐﻴﺐ ‪:‬‬

‫‪ : LCDOUT‬ﻧﻮﺷﺘﻦ ﺍﻃﻼﻋﺎﺕ ﺑﺮ ﺭﻭﯼ ﻧﻤﺎﻳﺸﮕﺮ ‪LCD‬‬ ‫}‪LCDOUT Data {, Data...‬‬

‫ﺷﺮﺡ ‪:‬‬

‫‪ LCDOUT‬ﺍﻃﻼﻋــﺎﺕ ﺭﺍ ﺑــﻪ ‪ ( Liquid Crystal Display ) LCD‬ﻣــﯽ ﻓﺮﺳــﺘﺪ‪PIC BASIC .‬‬

‫ﻣﺪﻟﻬﺎﯼ ﮔﻮﻧﺎﮔﻮﻥ ‪ LCD‬ﮐﻪ ﮐﻨﺘﺮﻟـﺮ ‪ Hitachi 44780‬ﺭﺍ ﺩﺍﺭﻧـﺪ ﻭ ﻳـﺎ ﺷـﺒﻴﻪ ﺁﻥ ﻋﻤـﻞ ﻣـﯽ ﮐﻨﻨـﺪ ﺭﺍ‬ ‫ﭘﺸﺘﻴﺒﺎﻧﯽ ﻣﯽ ﮐﻨﺪ‪ LCD .‬ﻣﻌﻤﻮﻻ ‪ ۱۴‬ﻳﺎ ‪ ۱۶‬ﭘﺎﻳﻪ ﺩﺍﺭﺩ ﮐﻪ ﺑﻪ ﻣﻴﮑﺮﻭﮐﻨﺘﺮﻟﺮ ﻣﺘﺼﻞ ﻣﯽ ﺷﻮﻧﺪ‪ .‬ﺍﮔﺮ ﮐﺮﮐﺘﺮ‬ ‫" ‪ " #‬ﻗﺒﻞ ﺍﺯ ﺍﻃﻼﻋﺎﺕ ﻓﺮﺳﺘﺎﺩﻩ ﺷﻮﺩ ﻣﻘﺪﺍﺭ ‪ ASCII‬ﻫﺮ ﻳﮏ ﺍﺯ ﺍﻃﻼﻋـﺎﺕ ﺭﺍ ﻣـﯽ ﻓﺮﺳـﺘﺪ‪LCDOUT .‬‬ ‫ﺍﺻﻼﺡ ﮐﻨﻨﺪﻩ ﻫﺎﯼ ﺩﺭ ﺟﺪﻭﻝ ﺯﻳﺮ ﺁﻣﺪﻩ ﺍﺳﺖ ‪.‬‬ ‫ﻓﺮﺳﺘﺎﺩﻩ ﺷﺪﻩ‬

‫ﺍﺻﻼﺡ ﮐﻨﻨﺪﻩ ﻫﺎ‬

‫ﻣﻘﺪﺍﺭ ‪binary‬‬

‫}‪{I}{S} BIN{1..16‬‬

‫ﻣﻘﺪﺍﺭ ‪decimal‬‬

‫}‪{I}{S} DEC{1..5‬‬

‫ﻣﻘﺪﺍﺭ ‪hexadecimal‬‬

‫}‪{I}{S} HEX{1..4‬‬

‫ﮐﺮﮐﺘﺮ‪ n ،c‬ﺑﺎﺭ ﺗﮑﺮﺍﺭ ﻣﯽ ﺷﻮﺩ‬

‫‪REP c/n‬‬

‫‪ n‬ﮐﺮﮐﺘﺮ ﺭﺷﺘﻪ‬

‫}‪STR ArrayVar {\n‬‬

‫ﺟﺪﻭﻝ ‪۱-۹‬‬

‫‪۳۳‬‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫ﻧﻤﺎﻳﺸﮕﺮ ‪ LCD‬ﻣﯽ ﺗﻮﺍﻧﺪ ﺑﺎ ﺑﺎﺱ ‪۴‬ﺑﻴﺘﯽ ﻳﺎ ‪۸‬ﺑﻴﺘﯽ ﺑﻪ ﻳﮏ ﻣﻴﮑﺮﻭﮐﻨﺘﺮﻟﺮ ﻣﺘﺼﻞ ﺷﻮﺩ‪ .‬ﺍﮔﺮ ﺍﺯ ﺑﺎﺱ ‪۸‬ﺑﻴﺘﯽ‬ ‫ﺍﺳﺘﻔﺎﺩﻩ ﺷﻮﺩ ﻫﻤﻪ ‪۸‬ﺑﻴﺖ ﺑﺎﻳﺴﺘﯽ ﺑﻪ ﻳﮏ ﭘﻮﺭﺕ ﻭﺻﻞ ﺷﻮﻧﺪ‪ .‬ﻭﻗﺘﯽ ﺩﺭ ﺣﺎﻟﺖ ﺑﺎﺱ ‪۴‬ﺑﻴﺘﯽ ﻫﺮ ‪۴‬ﺑﻴﺖ ﻣﯽ‬ ‫ﺗﻮﺍﻧﺪ ﻳﺎ ﺑﻪ ‪۴‬ﺑﻴﺖ ﭘﺎﻳﻴﻦ ﻭ ﻳﺎ ﺑﺎﻻﯼ ﭘﻮﺭﺕ ﻣﺘﺼـﻞ ﺷـﻮﺩ ‪ .‬ﺍﮔـﺮ ﺍﺯ ‪ LCD‬ﺗﻨﻬـﺎ ﺑـﺮﺍﯼ ﻧﻤـﺎﻳﺶ ﺍﺳـﺘﻔﺎﺩﻩ‬ ‫ﻣﯽ ﺷﻮﺩ ﺑﺎﻳﺴﺘﯽ ﺧﻂ ‪ R/W‬ﺑﻪ ﺯﻣﻴﻦ ﻣﺘﺼﻞ ﺷﻮﺩ ﺩﺭ ﺣﺎﻟﺖ ﭘﻴﺶ ﻓﺮﺽ ﭘﺎﻳـﻪ ﻫـﺎﯼ ‪ LCD‬ﺩﺭ ﺣﺎﻟـﺖ‬ ‫‪۴‬ﺑﻴﺘﯽ ) ‪ ( DB7 – DB4‬ﺑﻪ ‪ RA0-RA3‬ﻣﺘﺼﻞ ﻣﯽ ﺷﻮﻧﺪ‪ .‬ﺑﻴﺖ ‪ RS‬ﺑـﻪ ‪ RA4‬ﻣﺘﺼـﻞ ﻣـﯽ ﺷـﻮﺩ ﻭ‬ ‫ﭘﻴﻦ ‪ E‬ﺑﻪ ‪ RB3‬ﻭﺻﻞ ﻣﯽ ﺷﻮﺩ ‪ .‬ﺩﺭﺍﻳﻦ ﺣﺎﻟﺖ ‪ ۲ * ۱۶ ، LCD‬ﺩﺭ ﻧﻈﺮ ﮔﺮﻓﺘﻪ ﻣﯽ ﺷﻮﺩ ﺑﺮﺍﯼ ﺗﻐﻴﻴﺮ ﺩﺭ‬ ‫ﻫﺮ ﻳﮏ ﺍﺯ ﻭﺿﻌﻴﺘﻬﺎ ﺑﺎﻻ ﺑﺎﻳﺴﺘﯽ ﺍﺯ ﺩﺳﺘﻮﺭ ‪ DEFINE‬ﺍﺳﺘﻔﺎﺩﻩ ﺷﻮﺩ ‪.‬‬ ‫ﺍﻧﺘﺨﺎﺏ ﭘﻮﺭﺕ‘‬ ‫ﺍﻧﺘﺨﺎﺏ ‪ ۰‬ﻳﺎ ‪ ۴‬ﺩﺭ ﺣﺎﻟﺖ ﺑﺎﺱ ‪ ۴‬ﺑﻴﺘﯽ‘‬

‫ﺍﻧﺘﺨﺎﺏ ﭘﻮﺭﺕ ﺑﺮﺍﯼ ﺍﺗﺼﺎﻝ ﭘﻴﻦ ‪‘RS‬‬ ‫ﺍﻧﺘﺨﺎﺏ ﺑﻴﺖ ﺑﺮﺍﯼ ‪‘RS‬‬ ‫ﺍﻧﺘﺨﺎﺏ ﭘﻮﺭﺕ ﺑﺮﺍﯼ ﺍﺗﺼﺎﻝ ﭘﻴﻦ ‪‘ E‬‬ ‫ﺍﻧﺘﺨﺎﺏ ﺑﻴﺖ ﺑﺮﺍﯼ ‪‘ E‬‬

‫ﺍﻧﺘﺨﺎﺏ ﺑﺎﺱ‪ ۴‬ﺑﻴﺘﯽ ﻳﺎ ‪ ۸‬ﺑﻴﺘﯽ ‘‬ ‫ﺗﻌﻴﻴﻦ ﺗﻌﺪﺍﺩ ﺧﻄﻬﺎﯼ ‪‘LCD‬‬ ‫ﺗﺎﺧﻴﺮ ﺍﺭﺳﺎﻝ ﺩﺳﺘﻮﺭ ﺑﺮﺣﺴﺐ ﻣﻴﮑﺮﻭ ﺛﺎﻧﻴﻪ ‘‬ ‫ﺗﺎﺧﻴﺮ ﺍﺭﺳﺎﻝ ﺍﻃﻼﻋﺎﺕ ﺑﺮﺣﺴﺐ ﻣﻴﮑﺮﻭ ﺛﺎﻧﻴﻪ‘‬

‫‪PORTB‬‬

‫‪DEFINE LCD_DREG‬‬

‫‪DEFINE LCD_DBIT‬‬ ‫‪4‬‬ ‫‪DEFINE LCD_RSREG PORTB‬‬ ‫‪DEFINE LCD_RSBIT 1‬‬ ‫‪DEFINE LCD_EREG PORTB‬‬ ‫‪DEFINE LCD_EBIT‬‬ ‫‪0‬‬ ‫‪DEFINE LCD_BITS‬‬ ‫‪4‬‬ ‫‪DEFINE LCD_LINES 2‬‬ ‫‪DEFINE LCD_COMMANDS 2000‬‬ ‫‪DEFINE LCD_DATAUS 50‬‬

‫ﺗﻌﺮﻳﻔﻬﺎﯼ ﺑﺎﻻ ‪ ،‬ﻣﻌﺮﻓﯽ ﻣﯽ ﮐﻨﻨﺪ ‪۲ LCD‬ﺧﻄﯽ ﺭﺍ ﺑﺎ ﺑﺎﺱ ‪۴‬ﺑﻴﺘﯽ ﮐﻪ ﺑﻪ ‪۴‬ﺑﻴﺖ ﺑﺎﻻﯼ ﭘﻮﺭﺕ ‪ B‬ﻣﺘﺼﻞ‬ ‫ﺍﺳﺖ ﻭ ﭘﺎﻳﻪ ﺍﻧﺘﺨﺎﺏ ﺭﺟﻴﺴﺘﺮ )‪ (RS‬ﺑﻪ ‪ PORTB.1‬ﻭ ﭘﺎﻳﻪ ﻓﻌﺎﻝ ﺳﺎﺯﯼ ﺑﻪ ‪ PORTB.0‬ﻣﺘﺼﻞ ﺍﺳﺖ‪.‬‬ ‫ﻫﺮ ﮐﻨﺘﺮﻟﺮ ‪ LCD‬ﺩﺍﺭﺍﯼ ﺩﺳﺘﻮﺭﺍﺕ ﻣﻌﻴﻨﯽ ﺍﺳﺖ ‪ .‬ﺍﻳﻦ ﺩﺳﺘﻮﺭﺍﺕ ﺑﺼـﻮﺭﺕ ‪LCDOUT $FE, $Kod‬‬ ‫ﻓﺮﺳﺘﺎﺩﻩ ﻣﯽ ﺷﻮﻧﺪ‪ .‬ﺍﻳﻦ ﺩﺳﺘﻮﺭﺍﺕ ﺩﺭ ﺟﺪﻭﻝ ﺯﻳﺮ ﻧﺸﺎﻥ ﺩﺍﺩﻩ ﺷﺪﻩ ﺍﺳﺖ‪.‬‬ ‫ﻋﻤﻠﮑﺮﺩ‬

‫ﺩﺳﺘﻮﺭﺍﺕ‬

‫ﭘﺎﮎ ﮐﺮﺩﻥ ﺻﻔﺤﻪ ﻧﻤﺎﻳﺶ‬

‫‪$FE, 1‬‬

‫ﺷﺮﻭﻉ ﺍﺯ ﺍﺑﺘﺪﺍﯼ ﺧﻂ ﺍﻭﻝ‬

‫‪$FE, 2‬‬

‫ﺧﺎﻣﻮﺵ ﮐﺮﺩﻥ ﻣﮑﺎﻥ ﻧﻤﺎ‬

‫‪$FE, $0C‬‬

‫ﺭﻭﺷﻦ ﮐﺮﺩﻥ ﻣﮑﺎﻥ ﻧﻤﺎﯼ ﺍﺯ ﻧﻮﻉ ﺧﻂ ﺯﻳﺮ) _ (‬

‫‪$FE, $0E‬‬

‫ﺭﻭﺷﻦ ﮐﺮﺩﻥ ﻣﮑﺎﻥ ﻧﻤﺎﯼ ﺍﺯ ﻧﻮﻉ ﺧﺎﻟﯽ‬

‫‪$FE, $0F‬‬

‫ﺷﻴﻔﺖ ﻣﮑﺎﻥ ﻧﻤﺎ ﺑﻪ ﭼﭗ‬

‫‪$FE, $10‬‬

‫ﺷﻴﻔﺖ ﻣﮑﺎﻥ ﻧﻤﺎ ﺑﻪ ﭼﭗ‬

‫‪$FE, $14‬‬

‫ﻗﺮﺍﺭ ﺩﺍﺩﻥ ﻣﮑﺎﻥ ﻧﻤﺎ ﺩﺭ ﺍﺑﺘﺪﺍﯼ ﺧﻂ ﺩﻭﻡ‬

‫‪$FE, $C0‬‬

‫ﻗﺮﺍﺭ ﺩﺍﺩﻥ ﻣﮑﺎﻥ ﻧﻤﺎ ﺩﺭ ﺍﺑﺘﺪﺍﯼ ﺧﻂ ﺳﻮﻡ‬

‫‪$FE, $94‬‬

‫ﻗﺮﺍﺭ ﺩﺍﺩﻥ ﻣﮑﺎﻥ ﻧﻤﺎ ﺩﺭ ﺍﺑﺘﺪﺍﯼ ﺧﻂ ﭼﻬﺎﺭﻡ‬

‫‪$FE, $D4‬‬

‫‪۳۴‬‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫ﻣﺜﺎﻝ ‪:‬‬

‫ﭘﺎﮎ ﮐﺮﺩﻥ ﺻﻔﺤﻪ ﻧﻤﺎﻳﺶ ﻭ ﻧﻮﺷﺘﻦ ”‪‘ “Hello‬‬

‫ﺭﻓﺘﻦ ﺑﻪ ﺧﻂ ﺩﻭﻡ ‘‬ ‫ﻧﻤﻨﺎﻳﺶ ﻣﻘﺪﺍﺭ ‪‘ B0‬‬ ‫ﻧﻤﺎﻳﺶ ﮐﺪ ﺍﺳﮑﯽ ﻣﺘﻐﻴﺮ‪‘ B1‬‬

‫‪B0 var byte‬‬ ‫‪B1 var byte‬‬ ‫‪Main:‬‬ ‫”‪lcdout $FE, 1, “Hello‬‬ ‫‪lcdout $FE, $C0‬‬ ‫‪lcdout B0‬‬ ‫‪lcdout #B1‬‬ ‫‪Loop: goto Loop‬‬ ‫‪End‬‬

‫‪ : LOOKDOWN .۱ -۳-۲۸‬ﺟﺴﺘﺠﻮ ﮐﺮﺩﻥ ﺟﺪﻭﻝ ﺛﺎﺑﺘﻬﺎ‬ ‫ﺗﺮﮐﻴﺐ ‪:‬‬ ‫‪LOOKDOWN Value, [Const {, Const...}], Var‬‬

‫ﺷﺮﺡ ‪:‬‬ ‫ﺩﺳﺘﻮﺭ ‪ LOOKDOWN‬ﻭﺟﻮﺩ ﻣﻘﺪﺍﺭ ﻣﻌﻴﻨﯽ ﺭﺍ ﺩﺭ ﻓﻬﺮﺳﺘﯽ ﺍﺯ ﺛﺎﺑﺘﻬﺎ ﺟﺴﺘﺠﻮ ﻣﯽ ﮐﻨﺪ ﺍﮔﺮ ‪ value‬ﺩﺭ‬ ‫ﻓﻬﺮﺳﺖ ﻭﺟﻮﺩ ﺩﺍﺷﺘﻪ ﺑﺎﺷﺪ ﺷﺎﺧﺺ ﺍﺧﺘﺼﺎﺹ ﺩﺍﺩﻩ ﺷﺪﻩ ﺑﻪ ﺛﺎﺑﺖ ) ﺷﻤﺎﺭﻩ ﺛﺎﺑﺖ ( ﺩﺭ ‪ Var‬ﺫﺧﻴﺮﻩ ﻣـﯽ‬ ‫ﺷﻮﺩ‪ .‬ﺍﮔﺮ ﺛﺎﺑﺖ ﺍﻭﻟﯽ ﺑﺎ ﻣﻘﺪﺍﺭ ‪ value‬ﻳﮑﯽ ﺑﺎﺷﺪ ﻣﻘﺪﺍﺭ ‪ ۰‬ﺩﺭ ‪ Var‬ﺫﺧﻴﺮﻩ ﻣﯽ ﺷﻮﺩ‪ .‬ﻭﺍﮔﺮ ﺛﺎﺑﺖ ﺩﻭﻣﯽ ﺍﺯ‬ ‫ﻓﻬﺮﺳﺖ ﺟﻮﺭ ﺷﻮﺩ ﻣﻘﺪﺍﺭ ‪ ۱‬ﺫﺧﻴﺮﻩ ﻣﯽ ﺷﻮﺩ ﻭ ﻏﻴﺮﻩ ‪ . ...‬ﺍﮔﺮ ﻣﻘﺪﺍﺭ ‪ value‬ﺩﺭ ﻓﻬﺮﺳـﺖ ﻧﺒﺎﺷـﺪ ﻣﻘـﺪﺍﺭ‬ ‫‪ Var‬ﺗﻐﻴﻴﺮ ﻧﻤﯽ ﮐﻨﺪ‪ .‬ﻓﻬﺮﺳﺖ ﺛﺎﺑﺘﻬﺎ ﻣﯽ ﺗﻮﺍﻧﺪ ﻫﻢ ﻋﺪﺩﯼ ﻭ ﻫﻢ ﮐﺎﺭﮐﺘﺮﯼ ﺑﺎﺷﺪ‪ .‬ﻫـﺮ ﮐﺮﮐﺘـﺮ ﺭﺷـﺘﻪ ﺭﺍ‬ ‫ﺑﺼﻮﺭﺕ ﻳﮏ ﻣﻘﺪﺍﺭ ‪ ASCII‬ﺭﻓﺘﺎﺭ ﻣﯽ ﮐﻨﺪ‪ .‬ﺗﻌﺪﺍﺩ ﻣﺠـﺎﺯ ﺛﺎﺑﺘﻬـﺎ ‪ ۲۵۵‬ﺗـﺎ ) ‪ ۲۵۶‬ﺗـﺎ ﺑـﺮﺍﯼ ‪(18CXXX‬‬ ‫ﺛﺎﺑﺖ ﺩﺭ ﻓﻬﺮﺳﺖ ﻣﯽ ﺑﺎﺷﺪ‪.‬‬ ‫ﻣﺜﺎﻝ ‪:‬‬ ‫‪B0 var byte‬‬ ‫‪B1 var byte‬‬ ‫‪B0=$f‬‬ ‫‪Main:‬‬ ‫‪lookdown B0, (“01234567890ABCDEF”), B1‬‬ ‫‪PORTB=B1‬‬ ‫‪loop: goto loop‬‬ ‫‪End‬‬

‫‪ : LOOKUP .۱ -۳-۲۹‬ﺑﺪﺳﺖ ﺁﻭﺭﺩﻥ ﻣﻘﺪﺍﺭﯼ ﺍﺯ ﺟﺪﻭﻝ ﺛﺎﺑﺘﻬﺎ‬ ‫ﺗﺮﮐﻴﺐ ‪:‬‬ ‫‪LOOKUP Index, ( Constant {, Constant}), Var‬‬

‫ﺷﺮﺡ ‪:‬‬

‫‪ LOOKUP‬ﺑﺮﺍﯼ ﺧﻮﺍﻧﺪﻥ ﻣﻘﺪﺍﺭﯼ ﺍﺯ ﺟﺪﻭﻝ ﺛﺎﺑﺘﻬﺎ ﻣﺘﻨﺎﻇﺮ ﺑﺎ ﻣﻘﺪﺍﺭ ‪ Index‬ﺍﺳـﺘﻔﺎﺩﻩ ﻣـﯽ ﺷـﻮﺩ‪ .‬ﺍﮔـﺮ‬ ‫‪ Index‬ﺑﺮﺍﺑﺮ ﺻﻔﺮ ﺑﺎﺷﺪ ‪ ،‬ﺩﺭ ‪ Var‬ﻣﻘﺪﺍﺭ ﺛﺎﺑﺖ ﺍﻭﻟﯽ ﻗﺮﺍﺭ ﻣﯽ ﮔﻴﺮﺩ ﻭ ﺍﮔﺮ ‪ Index‬ﺑﺮﺍﺑﺮ ﻳﮏ ﺑﺎﺷﺪ ‪Var‬‬

‫‪۳۵‬‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫ﻣﻘﺪﺍﺭ ﺛﺎﺑﺖ ﺩﻭﻣﯽ ﺭﺍ ﺩﺭ ﺧﻮﺩ ﺟﺎﯼ ﻣﯽ ﺩﻫﺪ ﻭ ﻏﻴﺮﻩ ‪ .‬ﻭﺍﮔﺮ ﻣﻘﺪﺍﺭ ‪ Index‬ﺍﺯ ﺗﻌﺪﺍﺩ ﺛﺎﺑﺘﻬﺎ ﺑﻴﺸﺘﺮ ﺑﺎﺷـﺪ ‪،‬‬ ‫‪ Var‬ﺑﺪﻭﻥ ﺗﻐﻴﻴﺮ ﻣﯽ ﻣﺎﻧﺪ‪ .‬ﺗﻌﺪﺍﺩ ‪ ۲۵۶ ) ۲۵۵‬ﺗﺎ ﺑﺮﺍﯼ ‪ (18CXXX‬ﺛﺎﺑﺖ ﺩﺭ ﻓﻬﺮﺳﺖ ﻣﯽ ﺗﻮﺍﻧـﺪ ﻗـﺮﺍﺭ‬ ‫ﺑﮕﻴﺮﺩ‪.‬‬ ‫ﻣﺜﺎﻝ ‪:‬‬ ‫ﺑﺮﻧﺎﻣﻪ ﺯﻳﺮ ﺍﺳﺘﻔﺎﺩﻩ ﺍﺯ ‪ lookup‬ﺑﺮﺍﯼ ﺭﻗﻤﻬﺎﯼ ﺭﻭﯼ ﻧﻤﺎﻳﺸﮕﺮ ﺳﻮﻥ ﺳـﮕﻤﻨﺖ )‪ (seven segment‬ﺭﺍ‬ ‫ﻧﺸﺎﻥ ﻣﯽ ﺩﻫﺪ‪.‬‬ ‫‪Digit var byte‬‬ ‫ﻣﺘﻐﻴﺮ ‪ digit‬ﺑﺮﺍﯼ ﺭﻗﻤﻬﺎ‘‬ ‫‪Mask var byte‬‬ ‫ﻣﺘﻐﻴﺮ ‪ Mask‬ﺑﺮﺍﯼ ﺗﺒﺪﻳﻞ ﺷﺪﻩ ﻫﺎ ‘‬ ‫‪Main:‬‬ ‫‪for i=0 to 9‬‬ ‫‪Digit=i‬‬ ‫_‪Lookup Digit, [$3F, $06, $5B, $4F, $66, $6D, $7D, $07,‬‬ ‫‪$7F, $6F], Mask‬‬ ‫ﻓﺮﺳﺘﺎﺩﻥ ﻣﻘﺪﺍﺭ ﺗﺒﺪﻳﻞ ﺷﺪﻩ ﺭﻗﻢ ﺑﻪ ﭘﻮﺭﺕ ‪‘ B‬‬

‫‪PORTB=Mask‬‬

‫ﺗﺎﺧﻴﺮ ﺑﺮﺍﯼ ﺩﻳﺪ ﻥ ﻣﻘﺪﺍﺭ ﺧﺮﻭﺟﯽ ‘‬

‫‪pause 500‬‬ ‫ﺍﻓﺰﺍﻳﺶ ‪‘j‬‬ ‫ﺗﮑﺮﺍﺭ ﺩﻭﺑﺎﺭﻩ ﺑﺮﻧﺎﻣﻪ ‘‬

‫‪next i‬‬ ‫‪goto Main‬‬ ‫‪end‬‬

‫‪ : LOW .۱ -۳-۳۰‬ﻗﺮﺍﺭ ﺩﺍﺩﻥ ﺻﻔﺮ ﻣﻨﻄﻘﯽ ﺩﺭ ﭘﻴﻦ ﺧﺮﻭﺟﯽ‬ ‫ﺗﺮﮐﻴﺐ ‪:‬‬ ‫‪LOW Pin‬‬

‫ﺷﺮﺡ ‪:‬‬ ‫ﺗﻐﻴﻴﺮ ﭘﻴﻦ ﻣﻮﺭﺩ ﻧﻈﺮ ﺑﻪ ﺻﻔﺮ ‪ .‬ﭘﻴﻨﻬﺎ ﺑﺼﻮﺭﺕ ﺧﻮﺩﮐﺎﺭ ﺩﺭ ﮔﺮﺍﻳﺶ ﺧﺮﻭﺟﯽ ﻗﺮﺍﺭ ﻣـﯽ ﮔﻴـﺮﺩ‪ .‬ﻣـﯽ ﺗـﻮﺍﻥ‬ ‫ﻣﻘﺪﺍﺭ ﺭﺍ ﺑﻪ ﺻﻮﺭﺕ ﻣﺴﺘﻘﻴﻢ ﺩﺭ ﺭﺟﻴﺴﺘﺮ ﻗﺮﺍﺭ ﺩﺍﺩ‪ ).‬ﺍﻟﺒﺘﻪ ﺑﺎﻳﺴﺘﯽ ﭘﻮﺭﺕ ﻣﻮﺭﺩ ﻧﻈﺮ ﺩﺭ ﮔﺮﺍﻳﺶ ﺧﺮﻭﺟـﯽ‬ ‫ﻗﺮﺍﺭ ﮔﻴﺮﺩ‪( .‬‬ ‫‪7‬‬

‫‪LOW‬‬

‫ﻭ ﻳﺎ‬ ‫‪TRISB.7 = 0‬‬ ‫‪PORTB.7 = 0‬‬

‫‪ : NAP .۱ -۳-۳۱‬ﺧﺎﻣﻮﺵ ﮐﺮﺩﻥ ﺑﺮﺍﯼ ﻳﮏ ﺩﻭﺭﻩ ﺯﻣﺎﻧﯽ ﮐﻮﺗﺎﻩ‬ ‫ﺗﺮﮐﻴﺐ ‪:‬‬ ‫‪NAP period‬‬

‫‪۳۶‬‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫ﺷﺮﺡ ‪:‬‬ ‫ﺍﻳﻦ ﺩﺳﺘﻮﺭ ﻣﻴﮑﺮﻭﮐﻨﺘﺮﻟﺮ ﺭﺍ ﺑﺮﺍﯼ ﻳﮏ ﺩﻭﺭﻩ ﺯﻣﺎﻧﯽ ﺩﺭ ﺣﺎﻟﺖ ﺗﻮﺍﻥ ﮐﻢ ﻗﺮﺍﺭ ﻣﯽ ﺩﻫﺪ‪ .‬ﺩﺭ ﺍﻳﻦ ﻣﺪﺕ ﺍﻧﺮﮊﯼ‬ ‫ﻣﺼﺮﻓﯽ ﻣﻴﮑﺮﻭﮐﻨﺘﺮﻟـﺮ ﺑـﻪ ﮐﻤﺘـﺮﻳﻦ ﺣﺎﻟـﺖ ﺧـﻮﺩ ﻣـﯽ ﺭﺳـﺪ‪.‬ﺍﻳـﻦ ﺩﻭﺭﻩ ﺯﻣـﺎﻧﯽ ﺑـﺎ ﺍﺳـﺘﻔﺎﺩﻩ ﺍﺯ ﺗـﺎﻳﻤﺮ‬ ‫‪ WatchDog‬ﺗﺎﻣﻴﻦ ﻣﯽ ﺷﻮﺩ ﻭ ﻭﺍﺑﺴﺘﻪ ﺑﻪ ﺗﺮﺍﺷﻪ ﻭ ﺩﻣﺎ ﻣﯽ ﺑﺎﺷﺪ‪.‬‬ ‫‪Period‬‬ ‫‪0‬‬ ‫‪1‬‬ ‫‪2‬‬ ‫‪3‬‬ ‫‪4‬‬ ‫‪5‬‬ ‫‪6‬‬ ‫‪7‬‬

‫]‪Delay [ms‬‬ ‫‪18‬‬ ‫‪36‬‬ ‫‪72‬‬ ‫‪144‬‬ ‫‪288‬‬ ‫‪576‬‬ ‫‪1152‬‬ ‫‪2304‬‬

‫ﺟﺪﻭﻝ ‪۱-۱۰‬‬

‫ﻣﺜﺎﻝ‪:‬‬ ‫‪Main:‬‬ ‫‪‘ take a nap for 2.304 seconds‬‬

‫‪nap 7‬‬ ‫‪Loop: goto Loop‬‬ ‫‪End‬‬

‫‪ : OUTPUT .۱ -۳-۳۲‬ﮔﻤﺎﺷﺘﻦ ﭘﻴﻦ ‪ I/O‬ﺩﺭ ﮔﺮﺍﻳﺶ ﺧﺮﻭﺟﯽ‬ ‫ﺗﺮﮐﻴﺐ ‪:‬‬ ‫‪OUTPUT pin‬‬

‫ﺷﺮﺡ ‪:‬‬ ‫ﭘﻴﻦ ﻣﻮﺭﺩ ﻧﻈﺮ ﺭﺍ ﺑﺼﻮﺭﺕ ﺧﺮﻭﺟﯽ ﭘﻴﮑﺮﺑﻨﺪﯼ ﻣﯽ ﮐﻨﺪ‬ ‫‪OUTPUT PORTB.7‬‬

‫ﺷﺒﻴﻪ ﺑﻪ ‪:‬‬ ‫‪TRISB.7 = 0‬‬

‫‪.۱ -۳-۳۳‬‬ ‫ﺗﺮﮐﻴﺐ ‪:‬‬

‫‪ : OWIN‬ﺩﺭﻳﺎﻓﺖ ﺍﻃﻼﻋﺎﺕ ﺍﺯ ﻃﺮﻳﻖ ﺍﺭﺗﺒﺎﻁ ﻳﮏ ﺳﻴﻢ‬ ‫]‪OWIN Pin, Mode, [Var1, Var2...‬‬

‫ﺷﺮﺡ ‪:‬‬ ‫ﭘﺎﺭﺍﻣﺘﺮ " ‪ " Pin‬ﻧﺸﺎﻥ ﺩﻫﻨﺪﻩ ﭘﻴﻨﯽ ﺍﺳﺖ ﮐﻪ ﺍﺭﺗﺒﺎﻁ ﻳﮏ ﺳﻴﻤﻪ ﺭﺍ ﺑﺎ ﻭﺳﻴﻠﻪ ﺩﻳﮕﺮ ﻣـﯽ ﺧﻮﺍﻫـﺪ ﺑﺮﻗـﺮﺍﺭ‬ ‫ﮐﻨﺪ‪ .‬ﭘﺎﺭﺍﻣﺘﺮ " ‪ " Mode‬ﻣﻘﺪﺍﺭ ﺗﻌﺮﻳﻒ ﺷﺪﻩ ﭘﺎﺭﺍﻣﺘﺮﻫﺎﯼ ﺍﺭﺗﺒﺎﻁ ﺭﺍ ﺩﺭ ﺧﻮﺩ ﻗﺮﺍﺭ ﻣﯽ ﺩﻫﺪ‪.‬‬

‫‪۳۷‬‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫ﺑﻴﺖ "‪"Mode‬‬

‫ﭼﮕﻮﻧﮕﯽ ﻋﻤﻠﮑﺮﺩ‬

‫ﻓﺮﺳﺘﺎﺩﻥ ﺳﻴﮕﻨﺎﻝ ﺭﻳﺴﺖ ﻗﺒﻞ ﺍﺯ ﺍﺭﺳﺎﻝ ﺍﻃﻼﻋﺎﺕ = ‪1‬‬

‫‪0‬‬

‫ﻓﺮﺳﺘﺎﺩﻥ ﺳﻴﮕﻨﺎﻝ ﺭﻳﺴﺖ ﺑﻌﺪ ﺍﺯ ﺍﺭﺳﺎﻝ ﺍﻃﻼﻋﺎﺕ = ‪1‬‬

‫‪1‬‬

‫‪0 = 8-bit data‬‬ ‫‪1= 1-bit data‬‬

‫‪2‬‬

‫ﺟﺪﻭﻝ ‪۱-۱۱‬‬

‫ﭘﺎﺭﺍﻣﺘﺮﻫﺎﯼ "‪ "Var1‬ﻭ "‪ "Var2‬ﻣﺘﻐﻴﺮﻫﺎﯼ ﺷﺎﻣﻞ ﺍﻃﻼﻋﺎﺕ ﺧﻮﺍﻧﺪﻩ ﺷﺪﻩ ﻣﯽ ﺑﺎﺷﻨﺪ‪.‬‬ ‫ﻣﺜﺎﻝ‪:‬‬ ‫ﺧﻮﺍﻧﺪﻥ ﺩﻣﺎ ‘‬ ‫ﻧﺸﺎﻥ ﺩﺍﺩﻥ ﺩﻣﺎﺭﻭﯼ ﭘﻮﺭﺕ‬

‫‪‘B‬‬

‫‪Temperature var byte‬‬ ‫‪Main:‬‬ ‫]‪OWIN PORTC.0, 0, [Temperature‬‬ ‫‪PORTB=Temperature‬‬ ‫‪goto Main‬‬ ‫‪End‬‬

‫‪ : OWOUT .۱ -۳-۳۴‬ﺍﺭﺳﺎﻝ ﺍﻃﻼﻋﺎﺕ ﺍﺯ ﻃﺮﻳﻖ ﻳﮏ ﺳﻴﻢ ) ‪(One_Wire Comunication‬‬ ‫ﺗﺮﮐﻴﺐ ‪:‬‬ ‫]‪OWOUT Pin, Mode, [Var1, Var2...‬‬

‫ﺷﺮﺡ ‪:‬‬ ‫ﭘﺎﺭﺍﻣﺘﺮ " ‪ " Pin‬ﻧﺸﺎﻥ ﺩﻫﻨﺪﻩ ﭘﻴﻨﯽ ﺍﺳﺖ ﮐﻪ ﺍﺭﺗﺒﺎﻁ ﻳﮏ ﺳﻴﻤﻪ ﺭﺍ ﺑﺎ ﻭﺳﻴﻠﻪ ﺩﻳﮕﺮ ﻣـﯽ ﺧﻮﺍﻫـﺪ ﺑﺮﻗـﺮﺍﺭ‬ ‫ﮐﻨﺪ‪ .‬ﭘﺎﺭﺍﻣﺘﺮ " ‪ " Mode‬ﻣﻘﺪﺍﺭ ﺗﻌﺮﻳﻒ ﺷﺪﻩ ﭘﺎﺭﺍﻣﺘﺮﻫﺎﯼ ﺍﺭﺗﺒﺎﻁ ﺭﺍ ﺩﺭ ﺧﻮﺩ ﻗﺮﺍﺭ ﻣﯽ ﺩﻫﺪ‪.‬‬ ‫ﺑﻴﺖ "‪"Mode‬‬

‫ﭼﮕﻮﻧﮕﯽ ﻋﻤﻠﮑﺮﺩ‬

‫ﻓﺮﺳﺘﺎﺩﻥ ﺳﻴﮕﻨﺎﻝ ﺭﻳﺴﺖ ﻗﺒﻞ ﺍﺯ ﺍﺭﺳﺎﻝ ﺍﻃﻼﻋﺎﺕ = ‪1‬‬

‫‪0‬‬

‫ﻓﺮﺳﺘﺎﺩﻥ ﺳﻴﮕﻨﺎﻝ ﺭﻳﺴﺖ ﺑﻌﺪ ﺍﺯ ﺍﺭﺳﺎﻝ ﺍﻃﻼﻋﺎﺕ = ‪1‬‬

‫‪1‬‬

‫‪0 = 8-bit data‬‬ ‫‪1= 1-bit data‬‬

‫‪2‬‬

‫ﺟﺪﻭﻝ ‪۱-۱۲‬‬

‫ﻣﺜﺎﻝ ‪:‬‬ ‫ﻓﺮﺳﺘﺎﺩﻥ ﺳﻴﮕﻨﺎﻝ ﺭﻳﺴﺖ ﺑﻌﺪ ﺍﺯ ﺩﻭ ﻣﻘﺪﺍﺭ ‘‬

‫‪: PAUSE .۱ -۳-۳۵‬‬ ‫ﺗﺮﮐﻴﺐ ‪:‬‬

‫‪Main :‬‬ ‫]‪OWOUT PORTC.0, 1, [$CC, $BE‬‬ ‫‪goto Main‬‬ ‫‪End‬‬

‫ﺗﺎﺧﻴﺮ ﺑﺮﺣﺴﺐ ﻣﻴﻠﯽ ﺛﺎﻧﻴﻪ‬ ‫)‪PAUSE Period (in miliseconds‬‬

‫‪۳۸‬‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫ﺷﺮﺡ ‪:‬‬ ‫ﺍﻳﻦ ﺩﺳﺘﻮﺭ ﺑﻪ ﺍﻧﺪﺍﺯﻩ ‪ Period‬ﻣﻴﻠﯽ ﺛﺎﻧﻴﻪ ﺗﺎﺧﻴﺮ ﺍﻳﺠﺎﺩ ﻣﯽ ﮐﻨﺪ‪ Period .‬ﻳﮏ ﻣﻘﺪﺍﺭ ‪ ۱۶‬ﺑﻴﺘﯽ ﺍﺳـﺖ ﻭ‬ ‫ﺣﺪﺍﮐﺜﺮ ﺗﺎﺧﻴﺮ ‪ ۶۵۵۳۵‬ﻣﻴﻠـﯽ ﺛﺎﻧﻴـﻪ ﻣـﯽ ﺑﺎﺷـﺪ‪ .‬ﺑـﺮﺧﻼﻑ ﺩﺳـﺘﻮﺭﻫﺎﯼ ‪ NAP‬ﻭ ‪ ، SLEEP‬ﺩﺳـﺘﻮﺭ‬ ‫‪ PAUSE‬ﻣﻴﮑﺮﻭﮐﻨﺘﺮﻟﺮ ﺭﺍ ﺩﺭ ﺣﺎﻟﺖ ﺗﻮﺍﻥ ﮐﻢ ﻗﺮﺍﺭ ﻧﻤﯽ ﺩﻫﺪ‪ .‬ﺑﻨﺎﺑﺮﺍﻳﻦ ﺍﻳـﻦ ﺩﺳـﺘﻮﺭ ﺗـﻮﺍﻥ ﺑﻴﺸـﺘﺮﯼ ﺭﺍ‬ ‫ﻣﺼﺮﻑ ﻣﯽ ﮐﻨﺪ ﻭﻟﯽ ﺯﻣﺎﻥ ﺩﻗﻴﻘﺘﺮﯼ ﺭﺍ ﺑﻪ ﻣﺎ ﻣﯽ ﺩﻫﺪ‪ ).‬ﺩﻗﺖ ﺁﻥ ﺑﻪ ﮐﻼﮎ ﺍﺳﻴﻼﺗﻮﺭ ﺑﺴﺘﮕﯽ ﺩﺍﺭﺩ ( ﺍﻳﻦ‬ ‫ﺩﺳﺘﻮﺭ ﺑﺎ ﺍﺳﻴﻼﺗﻮﺭ ﺍﺯ ﭘﻴﺶ ﺗﻌﺮﻳﻒ ﺷﺪﻩ ‪ 4MHZ‬ﮐﺎﺭ ﻣﯽ ﮐﻨﺪ ﻭ ﺍﺳﻴﻼﺗﻮﺭﻫﺎﯼ ﺩﻳﮕﺮ ﺑﺎ ﺩﺳﺘﻮﺭ ‪DEFINE‬‬ ‫ﺑﺎﻳﺴﺘﯽ ﺗﻌﺮﻳﻒ ﺑﺸﻮﻧﺪ‪.‬‬ ‫ﻣﺜﺎﻝ ‪:‬‬ ‫‪TRISB = 0‬‬ ‫‪Main:‬‬ ‫‪PORTB = 255‬‬ ‫ﺗﺎﺧﻴﺮ ‪ ۱‬ﺛﺎﻧﻴﻪ ﺍﯼ ‘ ‪pause 1000‬‬ ‫‪PORTB = 0‬‬ ‫ﺗﺎﺧﻴﺮ‪ ۲‬ﺛﺎﻧﻴﻪ ﺍﯼ ‘ ‪pause 2000‬‬ ‫‪goto Main‬‬ ‫‪End‬‬

‫‪ : PAUSEUS .۱ -۳-۳۶‬ﺗﺎﺧﻴﺮ ﺑﺮﺣﺴﺐ ﻣﻴﮑﺮﻭﺛﺎﻧﻴﻪ‬ ‫ﺗﺮﮐﻴﺐ ‪:‬‬ ‫)‪PAUSEUS Period (in miliseconds‬‬

‫ﺷﺮﺡ ‪:‬‬

‫‪ PAUSEUS‬ﺑﺮﻧﺎﻣﻪ ﺭﺍ ﺑﺮﺍﯼ ‪ Period‬ﻣﻴﮑﺮﻭﺛﺎﻧﻴﻪ ﻣﺘﻮﻗﻒ ﻣـﯽ ﮐﻨـﺪ‪۱۶ Period .‬ﺑﻴﺘـﯽ ) ‪( WORD‬‬ ‫ﻣﯽ ﺑﺎﺷﺪ ﻭ ﺑﻴﺸﺘﺮﻳﻦ ﺗﺎﺧﻴﺮ ‪ 65535μs‬ﺍﺳﺖ‪ .‬ﺍﻳﻦ ﺩﺳﺘﻮﺭ ﺑﺎ ﺍﺳﻴﻼﺗﻮﺭ ﺍﺯ ﭘﻴﺶ ﺗﻌﺮﻳﻒ ﺷـﺪﻩ ‪ 4MHZ‬ﮐـﺎﺭ‬ ‫ﻣﯽ ﮐﻨﺪ ﻭ ﺍﺳﻴﻼﺗﻮﺭﻫﺎﯼ ﺩﻳﮕﺮ ﺑﺎ ﺩﺳﺘﻮﺭ ‪ DEFINE‬ﺑﺎﻳﺴﺘﯽ ﺗﻌﺮﻳﻒ ﺑﺸﻮﻧﺪ‪ .‬ﺍﻳﻦ ﺩﺳﺘﻮﺭ ﺑﺎ ﺻﺮﻑ ﺍﻧـﺮﮊﯼ‬ ‫ﺑﻴﺸﺘﺮ ﺯﻣﺎﻥ ﺩﻗﻴﻘﺘﺮﯼ ﺭﺍ ﻣﯽ ﺩﻫﺪ‪ .‬ﮐﻤﺘﺮﻳﻦ ﺗﺎﺧﻴﺮ ﺑﺎ ﺍﻳﻦ ﺩﺳﺘﻮﺭ ﺑﻪ ﻓﺮﮐﺎﻧﺲ ﺍﺳﻴﻼﺗﻮﺭ ﺑﺴﺘﮕﯽ ﺩﺍﺭﺩ‪.‬‬ ‫‪Minimal delay‬‬ ‫‪20 us‬‬ ‫‪24 us‬‬ ‫‪12 us‬‬ ‫‪8 us‬‬ ‫‪7 us‬‬ ‫‪5 us‬‬ ‫‪3 us‬‬ ‫ﺟﺪﻭﻝ ‪۱ -۱۳‬‬

‫ﻣﺜﺎﻝ ‪:‬‬

‫‪OSC‬‬ ‫)‪3 (3.58‬‬ ‫‪4‬‬ ‫‪8‬‬ ‫‪10‬‬ ‫‪12‬‬ ‫‪16‬‬ ‫‪20‬‬

‫‪۳۹‬‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫‪TRISB = 0‬‬ ‫‪Main:‬‬ ‫‪PORTB = 255‬‬ ‫‪pauseus 100‬‬ ‫‪PORTB = 0‬‬ ‫‪goto Main‬‬

‫‪pauseus 3450‬‬ ‫‪End‬‬

‫‪ : POT .۱ -۳-۳۷‬ﺑﺮﮔﺮﺩﺍﻧﺪﻥ ﻣﻘﺪﺍﺭ ﻣﻘﺎﻭﻣﺖ ﻣﺘﺼﻞ ﺑﻪ ﭘﻴﻦ‬ ‫ﺗﺮﮐﻴﺐ ‪:‬‬ ‫‪POT Pin, Scale, Var‬‬

‫ﺷﺮﺡ ‪:‬‬ ‫ﺩﺳﺘﻮﺭ ‪ POT‬ﻣﻘﺪﺍﺭ ﭘﺘﺎﻧﺴﻴﻮﻣﺘﺮﯼ ﺭﺍ ﮐﻪ ﺭﻭﯼ ﭘﻴﻦ ﻣﻮﺭﺩﻧﻈﺮ ﻗﺮﺍﺭ ﮔﺮﻓﺘـﻪ ﻣﺤﺎﺳـﺒﻪ ﻣـﯽ ﮐﻨـﺪ‪ .‬ﻣﻘـﺪﺍﺭ‬ ‫ﻣﻘﺎﻭﻣﺖ ﻣﯽ ﺗﻮﺍﻧﺪ ﺑﺎ ‪ RC‬ﻫﺎﯼ ﻣﺨﺘﻠﻒ ﭘﺎﻳﺪﺍﺭ ﻣﺤﺎﺳﺒﻪ ﺷﻮﺩ‪ .‬ﻣﻘﺎﻭﻣﺖ ﺑﺎ ﺯﻣﺎﻥ ﺗﺨﻠﻴﻪ ﺧﺎﺯﻥ ﺩﺭ ﻣﻘﺎﻭﻣﺖ‬ ‫ﻣﺤﺎﺳﺒﻪ ﻣﯽ ﺷﻮﺩ‪.‬‬ ‫‪ Scale‬ﺑﺮﺍﯼ ﺗﻨﻈﻴﻢ ﺗﻐﻴﻴﺮﺍﺕ ﺿﺮﻳﺐ ﺛﺎﺑﺖ ﺷﺒﮑﻪ ‪ RC‬ﺑﻪ ﮐﺎﺭ ﻣﯽ ﺭﻭﺩ ﺑﺮﺍﯼ ﺿﺮﺍﻳﺐ ﺛﺎﺑﺖ ﺑﺰﺭﮒ ‪، RC‬‬ ‫ﻣﻘﺪﺍﺭ ‪ Scale‬ﺭﺍ ‪ 1‬ﺍﻧﺘﺨﺎﺏ ﻣﯽ ﮐﻨﻴﻢ ﻭ ﺑﺮﺍﯼ ﺿﺮﺍﻳﺐ ﺛﺎﺑـﺖ ﮐﻮﭼـﮏ ‪ Scale‬ﺭﺍ ﺭﻭﯼ ﺣـﺪﺍﮐﺜﺮ ﻣﻘـﺪﺍﺭ‬ ‫ﺧﻮﺩ ‪ ۲۵۵‬ﻗﺮﺍﺭ ﻣﯽ ﺩﻫﻴﻢ‪ .‬ﺍﮔﺮ ﻣﻘﺪﺍﺭ ‪ Scale‬ﺩﺭﺳﺖ ﺍﻧﺘﺨﺎﺏ ﺷﺪﻩ ﺑﺎﺷﺪ ﻣﻘﺪﺍﺭ ﻣﺘﻐﻴـﺮ ‪ Var‬ﺩﺭ ﺣـﺎﻟﺘﯽ‬ ‫ﮐﻪ ﻣﻘﺪﺍﺭ ﻣﻘﺎﻭﻣﺖ ﺣﺪﺍﻗﻞ ﺍﺳﺖ ﺻﻔﺮ ﻣﯽ ﺷﻮﺩ ﻭ ﻫﻨﮕﺎﻣﯽ ﮐﻪ ﺣﺪﺍﮐﺜﺮ ﻣﻘﺎﻭﻣﺖ ﺭﺍ ﺩﺍﺭﻳﻢ ‪ ۲۵۵‬ﻣﯽ ﺷﻮﺩ‪.‬‬ ‫) ﻣﺘﺎﺳﻔﺎﻧﻪ ‪ Scale‬ﺑﺎﻳﺴﺘﯽ ﺑﺼﻮﺭﺕ ﺗﺠﺮﺑﯽ ﺑﺪﺳﺖ ﺁﻳﺪ (‬ ‫ﺍﻧﻮﺍﻉ ﻣﺒﺪﻟﻬﺎﯼ ﻣﻘﺎﻭﻣﺘﯽ ﻭﺟﻮﺩ ﺩﺍﺭﻧﺪ ﮐﻪ ﻣﯽ ﺗﻮﺍﻧﻨﺪ ﺗﻮﺳﻂ ﺩﺳﺘﻮﺭ ‪ POT‬ﺁﻧﻬﺎ ﺭﺍ ﺧﻮﺍﻧﺪ‪ .‬ﺍﻳﻦ ﻣﺒﺪﻟﻬﺎ ﻭﻟﺘﺎﮊ‬ ‫ﺭﺍ ﺍﻧﺪﺍﺯﻩ ﻧﻤﯽ ﮔﻴﺮﻧﺪ ﺑﻠﮑﻪ ﻣﻘﺎﻭﻣﺖ ﺭﺍ ﺍﻧﺪﺍﺯﻩ ﻣﯽ ﮔﻴﺮﻧﺪ‪.‬‬ ‫ﻣﺜﺎﻝ ‪:‬‬ ‫ﺑﺮﺍﯼ ﺗﻨﻈﻴﻢ ‪ Scale‬ﻣﯽ ﺗﻮﺍﻥ ﺍﺯ ﺑﺮﻧﺎﻣﻪ ﺯﻳﺮ ﺍﺳﺘﻔﺎﺩﻩ ﮐﺮﺩ‪:‬‬

‫ﺧﻮﺍﻧﺪﻥ ﻣﻘﺪﺍﺭ ﭘﺘﺎﻧﺴﻴﻮﻣﺘﺮ ﺭﻭﯼ ﭘﻴﻦ ‪‘ RA0‬‬ ‫ﻧﺸﺎﻥ ﺩﺍﺩﻥ ﻣﻘﺪﺍﺭ ﻣﻘﻴﺎﺱ ﻳﺮﻭﯼ ﭘﻮﺭﺕ‪‘ B‬‬

‫‪B0 var byte‬‬ ‫‪skala var byte‬‬ ‫‪Main :‬‬ ‫‪FOR skala=1 TO 255‬‬ ‫‪pot PORTA.0, scale, B0‬‬ ‫‪IF B0>253 Then Over‬‬ ‫‪NEXT skala‬‬ ‫‪Over : PORTB=scale‬‬ ‫‪goto Main‬‬ ‫‪End‬‬

‫‪ : PULSIN .۱ -۳-۳۸‬ﻣﺤﺎﺳﺒﻪ ﻋﺮﺽ ﭘﺎﻟﺲ ﺭﻭﯼ ﭘﺎﻳﻪ ﻭﺭﻭﺩﯼ‬ ‫ﺗﺮﮐﻴﺐ ‪:‬‬ ‫‪PULSIN Pin, Level, Var‬‬

‫‪۴۰‬‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫ﺷﺮﺡ ‪:‬‬ ‫ﺍﻳﻦ ﺩﺳﺘﻮﺭ ﻋﺮﺽ ﭘﺎﻟﺲ ﺭﺍ ﺑﺎ ﺩﻗﺖ ‪ ) 10μS‬ﻭﻗﺘﯽ ﺑﺎ ﺍﺳﻴﻼﺗﻮﺭ ‪ 4MHZ‬ﮐﺎﺭ ﻣﯽ ﮐﻨﺪ( ﺭﻭﯼ ﭘﻴﻦ ﻣﻮﺭﺩ ﻧﻈﺮ‬ ‫ﻣﺤﺎﺳﺒﻪ ﻣﯽ ﮐﻨﺪ ﻭ ﺍﮔﺮ ﻣﺘﻐﻴﺮ ‪ ، Level‬ﺻﻔﺮ ﺑﺎﺷﺪ ﻗﺴﻤﺖ ﭘﺎﻳﻴﻦ ﻋﺮﺽ ﭘﺎﻟﺲ ﺍﻧﺪﺍﺯﻩ ﮔﻴﺮﯼ ﻣﯽ ﺷﻮﺩ ﻭ‬ ‫ﺍﮔﺮ ﻳﮏ ﺑﺎﺷﺪ ﻗﺴﻤﺖ ﺑﺎﻻﯼ ﭘﺎﻟﺲ ﺍﻧﺪﺍﺯﻩ ﮔﻴﺮﯼ ﻣﯽ ﺷـﻮﺩ‪.‬ﻣﻘـﺪﺍﺭ ﺍﻧـﺪﺍﺯﻩ ﮔﻴـﺮﯼ ﺷـﺪﻩ ﺩﺭ ﻣﺘﻐﻴـﺮ ‪Var‬‬ ‫ﺫﺧﻴﺮﻩ ﻣﯽ ﺷﻮﺩ‪ .‬ﺯﻣﺎﻥ ﺍﻧﺪﺍﺯﻩ ﮔﻴﺮﯼ ﻣﯽ ﺗﻮﺍﻧﺪ ﺍﺯ ‪ ۱۰‬ﺗﺎ ‪ ۶۵۵۳۵‬ﻣﻴﮑﺮﻭ ﺛﺎﻧﻴـﻪ ﻃـﻮﻝ ﺑﮑﺸـﺪ‪ ) .‬ﻣﺘﻐﻴـﺮ‬ ‫‪۱۶‬ﺑﻴﺘﯽ ﺍﺳﺖ ( ﺍﮔﺮ ﻣﺘﻐﻴﺮ ‪۸‬ﺑﻴﺘـﯽ ﺑﺎﺷـﺪ ‪ ۸‬ﺑﻴـﺖ ﭘـﺎﻳﻴﻦ ﺍﺯ ﻣﺘﻐﻴـﺮ ‪۱۶‬ﺑﻴﺘـﯽ ‪ WORD‬ﺍﺳـﺘﻔﺎﺩﻩ ﻣـﯽ‬ ‫ﺷﻮﺩ‪.‬ﻗﺪﺭﺕ ﺗﻔﮑﻴﮏ ﺑﻪ ﻓﺮﮐﺎﻧﺲ ﺍﺳﻴﻼﺗﻮﺭ ﺑﺴﺘﮕﯽ ﺩﺍﺭﺩ ﻭﺑﺮﺍﯼ ﺍﺳﻴﻼﺗﻮﺭ ‪ 4MHZ‬ﺣـﺪ ﺗﻔﮑﻴـﮏ ‪ 10μS‬ﻣـﯽ‬ ‫ﺑﺎﺷﺪ‪ .‬ﻭﻗﺘﯽ ﺍﺯ ﺍﺳﻴﻼﺗﻮﺭ ‪ 20 MHZ‬ﺍﺳﺘﻔﺎﺩﻩ ﻣﯽ ﺷﻮﺩ ‪ ،‬ﺣﺪ ﺗﻔﮑﻴﮏ ‪ 2μS‬ﻣﯽ ﺷﻮﺩ‪.‬‬ ‫ﻣﺜﺎﻝ ‪:‬‬ ‫ﻣﺤﺎﺳﺒﻪ ﺍﻳﻤﭙﺎﻟﺴﻬﺎﯼ ﻳﮏ ﺭﻭﯼ ﭘﻴﻦ‬

‫‪‘RB0‬‬

‫‪W0 var word‬‬ ‫‪Main :‬‬ ‫‪pulsin PORTB.0, 1, W0‬‬ ‫‪goto Main‬‬ ‫‪End‬‬

‫‪ : PULSOUT .۱ -۳-۳۹‬ﺗﻮﻟﻴﺪ ﮐﺮﺩﻥ ﭘﺎﻟﺲ ﺩﺭ ﭘﻴﻦ ﺧﺮﻭﺟﯽ‬ ‫ﺗﺮﮐﻴﺐ ‪:‬‬ ‫‪PULSOUT Pin, Period‬‬

‫ﺷﺮﺡ ‪:‬‬ ‫ﺍﻳﻦ ﺩﺳﺘﻮﺭ ﭘﺎﻟﺲ ﺑﺎ ﺣﺪ ﺗﻔﮑﻴﮏ ‪ ۱۰‬ﻣﻴﮑﺮﻭﺛﺎﻧﻴﻪ ﺭﺍ ﺗﻮﻟﻴﺪ ﻣﯽ ﮐﻨﺪ‪ .‬ﭘﺎﻟﺲ ﺑﺎ ﺗﻐﻴﻴﺮ ﻭﺿﻌﻴﺖ ﻳﮏ ﭘﻴﻦ ﺑﻪ‬ ‫ﺣﺎﻟﺖ ﺩﻳﮕﺮ ﺗﻮﻟﻴﺪ ﻣﯽ ﺷﻮﺩ ‪ .‬ﭘﻴﻦ ﺑﺼﻮﺭﺕ ﺧﻮﺩﮐﺎﺭ ﺩﺭ ﮔﺮﺍﻳﺶ ﻭﺭﻭﺩﯼ ﻗﺮﺍﺭ ﻣﯽ ﮔﻴﺮﺩ‪.‬‬ ‫ﻣﺜﺎﻝ ‪:‬‬ ‫‪Main :‬‬ ‫ﺗﻮﻟﻴﺪ ﺍﻳﻤﭙﺎﻟﺴﻬﺎ ﺭﻭﯼ ﭘﻴﻦ ‪‘ RB7‬‬

‫‪pulsout PORTB.7, 100‬‬ ‫‪goto Main‬‬ ‫‪End‬‬

‫‪ : PWM .۱ -۳-۴۰‬ﺗﻮﻟﻴﺪ ﺳﻴﮕﻨﺎﻝ ‪ PWM‬ﺭﻭﯼ ﭘﻴﻦ‬ ‫ﺗﺮﮐﻴﺐ ‪:‬‬ ‫‪PWM Pin, Ratio, Cycle‬‬

‫ﺷﺮﺡ ‪:‬‬ ‫ﺍﻳﻦ ﺩﺳﺘﻮﺭ ﭘﺎﻟﺴﻬﺎﯼ ‪ ( Pulse_width Modulation ) PWM‬ﺑﺮﺍﯼ ﭘﻴﻦ ﻣﺸﺨﺺ ﺷﺪﻩ ﻣﯽ ﻓﺮﺳﺘﺪ ‪.‬‬ ‫ﺍﻳﻦ ﺳﻴﮑﻞ ﺑﺮﺍﯼ ﺗﻌﺪﺍﺩ ﺑﺎﺭﻫﺎﯼ ﮐﻪ ﺗﻌﺮﻳﻒ ﺷﺪﻩ ﺑﺎ ﭘﺎﺭﺍﻣﺘﺮ ‪ Cycle‬ﺧﻮﺩﺵ ﺭﺍ ﺗﮑﺮﺍﺭ ﻣﯽ ﮐﻨﺪ‪ .‬ﻣﺪﺕ ﺩﻭﺭﻩ‬

‫ﺷﮑﻞ ‪( 1-7.‬‬

‫‪PWM‬‬

‫‪۴۱‬‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫ﺑﻪ ﺍﺳﻴﻼﺗﻮﺭ ﺑﺴﺘﮕﯽ ﺩﺍﺭﺩ‪ .‬ﺩﺭ ﺣﺎﻟﺘﯽ ﮐﻪ ﺍﺳﻴﻼﺗﻮﺭ ‪ 4MHZ‬ﺍﺳﺖ ﻣـﺪﺕ ﺩﻭﺭﻩ ﺗﻨـﺎﻭﺏ ‪ 5mS‬ﺍﺳـﺖ‪ .‬ﻭﻗﺘـﯽ‬ ‫ﺍﺳﻴﻼﺗﻮﺭ ‪ 8MHZ‬ﺑﺎﺷﺪ ﺍﻳﻦ ﺩﻭﺭﻩ ﺗﻨﺎﻭﺏ ﺑﻪ ‪ 1mS‬ﻣﯽ ﺭﺳﺪ‪ .‬ﺑﺎ ﺩﺳﺘﻮﺭ ‪ PWM‬ﺑﻪ ﺳﺎﺩﮔﯽ ﺑﺎ ﻳﮏ ﻣﺪﺍﺭ ‪RC‬‬ ‫ﻣﯽ ﺗﻮﺍﻥ ﻭﻟﺘﺎﮊ ‪ DC‬ﺗﻮﻟﻴﺪ ﮐﺮﺩ ﻭ ﺩﺭ ﻭﺍﻗﻊ ﻳﮏ ﻣﺒﺪﻝ ‪ D/A‬ﺳﺎﺩﻩ ﺳﺎﺧﺘﻪ ﻣﯽ ﺷﻮﺩ‪.‬‬ ‫ﻣﺜﺎﻝ ‪:‬‬ ‫‪Main :‬‬ ‫ﻓﺮﺳﺘﺎﺩﻥ ﺳﻴﮕﻨﺎﻝ ‪ %۵۰ PWM‬ﺭﻭﯼ ﭘﻴﻦ‪pwm PORTB.7, 127, 100 ‘ RB7‬‬ ‫‪goto Main‬‬ ‫‪End‬‬

‫‪ : RANDOM .۱ -۳-۴۱‬ﺗﻮﻟﻴﺪ ﻋﺪﺩ ﺗﺼﺎﺩﻓﯽ‬ ‫ﺗﺮﮐﻴﺐ ‪:‬‬ ‫‪RANDOM Variable‬‬

‫ﺷﺮﺡ ‪:‬‬ ‫ﺍﻳﻦ ﺩﺳﺘﻮﺭ ﻋﺪﺩ ﺗﺼﺎﺩﻓﯽ ﺭﺍ ﺩﺭ ﻳﮏ ﻣﺘﻐﻴﺮ ‪ ۱۶‬ﺑﻴﺘﯽ ﺫﺧﻴﺮﻩ ﻣﯽ ﮐﻨﺪ‪).‬ﺗﻨﻬﺎ ﺻﻔﺮ ﺭﺍ ﺗﻮﻟﻴﺪ ﻧﻤﯽ ﮐﻨﺪ(‬ ‫ﻣﺜﺎﻝ ‪:‬‬ ‫ﻗﺮﺍﺭ ﺩﺍﺩﻥ ﻣﻘﺪﺍﺭ ﺭﺍﻧﺪﻡ ﺩﺭ ﻣﺘﻐﻴﺮ ‪‘ W0‬‬ ‫ﻧﻤﺎﻳﺶ ﻣﻘﺪﺍﺭ ﺭﺍﻧﺪﻡ ﺩﺭ ‪‘ LCD‬‬

‫‪W0 var word‬‬ ‫‪Main :‬‬ ‫‪random W0‬‬ ‫‪lcdoout #W0‬‬ ‫‪goto Main‬‬ ‫‪End‬‬

‫‪ : RCTIME .۱ -۳-۴۲‬ﻣﺤﺎﺳﺒﻪ ﭘﺎﻟﺲ ﺭﻭﯼ ﭘﻴﻦ ) ﻣﺸﺎﺑﻪ ‪(PULSIN‬‬ ‫ﺗﺮﮐﻴﺐ ‪:‬‬ ‫‪RCTIME Pin, State, Variable‬‬

‫ﺷﺮﺡ ‪:‬‬ ‫ﺍﻳﻦ ﺩﺳﺘﻮﺭ ﻣﺪﺕ ﺯﻣﺎﻥ ﺭﺍ ﮐﻪ ﭘﻴﻦ ﺩﺭ ﻳﮏ ﺣﺎﻟﺖ ﻣﻌﻴﻨﯽ ﻗﺮﺍﺭ ﻣﯽ ﮔﻴﺮﺩ ‪ ،‬ﺍﻧـﺪﺍﺯﻩ ﻣـﯽ ﮔﻴـﺮﺩ‪ .‬ﺍﮔـﺮ ﭘـﻴﻦ‬ ‫ﺑﺪﻭﻥ ﺗﻐﻴﻴﺮ ﺑﻤﺎﻧﺪ ﻣﺘﻐﻴﺮ ‪ Variable‬ﺻﻔﺮ ﻣﯽ ﺷﻮﺩ‪ RCTIME .‬ﺑـﺮﺍﯼ ﺧﻮﺍﻧـﺪﻥ ﭘﺘﺎﻧﺴـﻴﻤﺮ ﺑـﺎ ﻋﻨﺎﺻـﺮ‬ ‫ﻣﻘﺎﻭﻣﺘﯽ ﺩﻳﮕﺮ ﺍﺳﺘﻔﺎﺩﻩ ﻣﯽ ﺷﻮﺩ‪ .‬ﺣﺪ ﺗﻔﮑﻴﮏ ﺑﻪ ﻓﺮﮐﺎﻧﺲ ﺍﺳﻴﻼﺗﻮﺭ ﺑﺴﺘﮕﯽ ﺩﺍﺭﺩ‪ .‬ﻭﺑﺮﺍﯼ ﺍﺳﻴﻼﺗﻮﺭ ‪4MHZ‬‬ ‫ﺣﺪ ﺗﻔﮑﻴﮏ ‪ 10μS‬ﻣﯽ ﺑﺎﺷﺪ‪ .‬ﻭﻗﺘﯽ ﺍﺯ ﺍﺳﻴﻼﺗﻮﺭ ‪ 20 MHZ‬ﺍﺳﺘﻔﺎﺩﻩ ﻣﯽ ﺷﻮﺩ ‪ ،‬ﺣﺪ ﺗﻔﮑﻴﮏ ‪ 2μS‬ﻣﯽ ﺷﻮﺩ‬ ‫ﻣﺜﺎﻝ ‪:‬‬ ‫ﺗﺨﻠﻴﻪ ﺧﺎﺯﻥ ‘‬ ‫ﺗﺨﻠﻴﻪ ﺑﻪ ﺍﻧﺪﺍﺯﻩ ‪ ۱۰‬ﻣﻴﻠﯽ ﺛﺎﻧﻴﻪ ‘‬ ‫ﻣﺤﺎﺳﺒﻪ ﻣﺪﺕ ﺷﺎﺭﮊ ﺷﺪﻥ ‘‬ ‫ﻧﻤﺎﻳﺶ ﻣﻘﺪﺍﺭ ‪ W0‬ﺭﻭﯼ ‪‘ LCD‬‬

‫‪W0 var word‬‬ ‫‪Main :‬‬ ‫‪low PORTA.0‬‬ ‫‪pause 10‬‬ ‫‪rctime PORTA.0, 0, W0‬‬ ‫‪lcdout #W0‬‬ ‫‪goto Main‬‬ ‫‪End‬‬

‫‪۴۲‬‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫‪ : READ .۱ -۳-۴۳‬ﺧﻮﺍﻧﺪﻥ ﻳﮏ ﺑﺎﻳﺖ ﺍﺯ ﺍﻃﻼﻋﺎﺕ ‪EEPROM‬‬

‫ﺗﺮﮐﻴﺐ ‪:‬‬

‫‪READ Address, Variable‬‬

‫ﺷﺮﺡ ‪:‬‬ ‫ﺍﻳﻦ ﺩﺳﺘﻮﺭ ﺍﻃﻼﻋﺎﺕ ﺭﺍ ﺍﺯ ﺣﺎﻓﻈﻪ ‪ EEPROM‬ﺩﺍﺧﻠﯽ ﺍﺯ ﺁﺩﺭﺱ ﻣﺸﺨﺺ ﺷﺪﻩ ﻣﯽ ﺧﻮﺍﻧﺪ ﻭ ﻧﺘﺎﻳﺞ ﺭﺍ ﺩﺭ‬ ‫‪ Variable‬ﺫﺧﻴﺮﻩ ﻣﯽ ﮐﻨﺪ‪ .‬ﺍﻳﻦ ﺩﺳﺘﻮﺭ ﺗﻨﻬﺎ ﺑﺎ ﻣﻴﮑﺮﻭﮐﻨﺘﺮﻟﺮﻫﺎﯼ ﮐﻪ ﺩﺍﺭﺍﯼ ‪ EEPROM‬ﺩﺍﺧﻠﯽ ﺍﺳﺖ‬ ‫ﺍﺟﺮﺍ ﻣﯽ ﺷﻮﻧﺪ‪ .‬ﺍﺯ ﺩﺳﺘﻮﺭ ‪ I2CREAD‬ﺑﺮﺍﯼ ‪ EEPROM‬ﻫﺎﯼ ﺧﺎﺭﺟﯽ ﺍﺳﺘﻔﺎﺩﻩ ﻣﯽ ﺷﻮﺩ‪.‬‬ ‫‪B0 var byte‬‬ ‫‪W var word‬‬ ‫‪Main :‬‬ ‫‪READ 5, B0‬‬ ‫ﺧﻮﺍﻧﺪﻥ ﻣﻘﺪﺍﺭ ﺁﺩﺭﺱ ‪ ۵‬ﻭ ﺭﻳﺨﺘﻦ ﺩﺭ ﻣﺘﻐﻴﺮ ‪‘B0‬‬ ‫ﺧﻮﺍﻧﺪﻥ ﻳﮏ ﻣﻘﺪﺍﺭ ‪ ۱۶‬ﺑﻴﺘﯽ ﺍﺯ ﺁﺩﺭﺱ ‪ ۶‬ﻭ ‪READ 6, W.BYTE0 ‘ ۷‬‬ ‫‪READ 7, W.BYTE1‬‬ ‫‪Loop: goto Loop‬‬ ‫‪End‬‬

‫‪ : READCODE .۱ -۳-۴۴‬ﺧﻮﺍﻧﺪﻥ ‪ ۲‬ﺑﺎﻳﺖ ) ‪ ( WORD‬ﺍﺯ ﮐﺪ ﺑﺮﻧﺎﻣﻪ‬ ‫ﺗﺮﮐﻴﺐ ‪:‬‬ ‫‪READ Address, Variable‬‬

‫ﺷﺮﺡ ‪ :‬ﺍﻳﻦ ﺩﺳﺘﻮﺭ ﮐﺪ ﺑﺮﻧﺎﻣﻪ ﺭﺍ ﺍﺯ ﺁﺩﺭﺱ ﺩﺍﺩﻩ ﺷﺪﻩ ﻣﯽ ﺧﻮﺍﻧـﺪ ﻭ ﻧﺘﻴﺠـﻪ ﺭﺍ ﺩﺭ ﻣﺘﻐﻴـﺮ ‪ ۱۶‬ﺑﻴﺘـﯽ ﻣـﯽ‬ ‫ﮔﺬﺍﺭﺩ‪ .‬ﻣﻴﮑﺮﻭﮐﻨﺘﺮﻟﺮ ﻫﺎﯼ ‪ PIC16F87X‬ﺧﻮﺍﻧﺪﻥ ﻭ ﻧﻮﺷﺘﻦ ﮐﺪ ﺑﺮﻧﺎﻣـﻪ ﺭﺍ ﺩﺭ ﺣـﺎﻝ ﺍﺟـﺮﺍ ﺍﺟـﺎﺯﻩ ﻣـﯽ‬ ‫ﺩﻫﻨﺪ‪.‬‬ ‫ﻣﺜﺎﻝ ‪:‬‬ ‫ﺧﻮﺍﻧﺪﻥ ﺍﻃﻼﻋﺎﺕ ﺍﺯ ﺣﺎﻓﻈﻪ ﻓﻠﺶ ﺩﺭ ﺁﺩﺭﺱ ‪ ۱۰۰‬ﻭ ﺭﻳﺨﺘﻦ ﺩﺭﻣﺘﻐﻴﺮ‬

‫‪‘ W0‬‬

‫‪Wo var word‬‬ ‫‪Main :‬‬ ‫‪readcode 100, W0‬‬ ‫‪Loop : goto Loop‬‬ ‫‪End‬‬

‫‪ : REVERSE .۱ -۳-۴۵‬ﺗﻐﻴﺮ ﮔﺮﺍﻳﺶ ﭘﻴﻦ‬ ‫ﺗﺮﮐﻴﺐ ‪:‬‬ ‫‪REVERSE Pin‬‬

‫ﺷﺮﺡ ‪:‬‬ ‫ﺍﻳﻦ ﺩﺳﺘﻮﺭ ﮔﺮﺍﻳﺶ ﭘﻴﻦ ﻣﻮﺭﺩ ﻧﻈﺮ ﺭﺍ ﻭﺍﺭﻭﻧﻪ ﻣﯽ ﮐﻨﺪ‪ .‬ﺍﮔﺮ ﭘﻴﻨﯽ ﺩﺭ ﮔﺮﺍﻳﺶ ﻭﺭﻭﺩﯼ ﺑﺎﺷﺪ ﺑﺎ ﺍﻳﻦ ﺩﺳـﺘﻮﺭ‬ ‫ﺩﺭ ﮔﺮﺍﻳﺶ ﺧﺮﻭﺟﯽ ﻗﺮﺍﺭ ﻣﯽ ﮔﻴﺮﺩ‪.‬‬

‫‪۴۳‬‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫‪ : SERIN .۱ -۳-۴۶‬ﻭﺭﻭﺩﯼ ﺳﺮﻳﺎﻝ ﺁﺳﻨﮑﺮﻭﻥ‬ ‫ﺗﺮﮐﻴﺐ ‪:‬‬ ‫}‪SERIN Pin, Mode, {Timeout, Label}, {[Qual...], }{Item...‬‬

‫ﺷﺮﺡ ‪:‬‬

‫‪ SERIN‬ﻣﻘﺎﺩﻳﺮﯼ ﺭﺍ ﺑﺎ ﻗﺎﻟﺐ ﺑﻨﺪﯼ ﺁﺳﻨﮑﺮﻭﻥ ) ‪۸‬ﺑﻴﺖ ﺑﺪﻭﻥ ﺑﻴﺖ ﺗﻮﺍﺯﻥ ﻭﻳـﮏ ﺑﻴـﺖ ﺗﻮﻗـﻒ ( ﺍﺯ ﭘـﻴﻦ‬ ‫ﻣﺸﺨﺺ ﺷﺪﻩ ﺩﺭﻳﺎﻓﺖ ﻭ ﺩﺭ ﻣﺘﻐﻴﺮ ﺫﺧﻴﺮﻩ ﻣﯽ ﮐﻨﺪ‪ .‬ﺑﺠﺎﯼ ﻣﻘﺪﺍﺭ ﻋﺪﺩﯼ ﺗﻨﻈﻴﻤﯽ ‪ ۰‬ﺗـﺎ ‪( Mode ) ۱۵‬‬ ‫ﻣﯽ ﺗﻮﺍﻥ ﻳﮏ ﺍﺳﻢ ﺍﺯ ﮐﺘﺎﺑﺨﺎﻧﻪ "‪ "modedefs.inc‬ﺭﺍ ﻗﺮﺍﺭ ﺩﺍﺩ‪ ) .‬ﺟﺪﻭﻝ ‪( ۲-۱۴‬‬ ‫ﺩﺳﺘﻮﺭ ‪ SERIN‬ﻣﯽ ﺗﻮﺍﻧﺪ ﺩﺍﺭﺍﯼ ﺑﺮﭼﺴﺐ ) ﭘﺎﺭﺍﻣﺘﺮ ‪ ( Label‬ﻧﻴﺰ ﺑﺎﺷﺪ ﮐﻪ ﺩﺭ ﺻﻮﺭﺕ ﺩﺭﻳﺎﻓﺖ ﻧﮑـﺮﺩﻥ‬ ‫ﺍﻃﻼﻋﺎﺗﯽ ﺩﺭ ﺯﻣﺎﻥ ﻣﻌﻴﻦ ﺑﺮﻧﺎﻣﻪ ﺑـﻪ ﺁﻥ ﺑﺮﭼﺴـﺐ ﻣـﯽ ﭘـﺮﺩ‪ ) .‬ﺣﺎﻟـﺖ ﺍﺯ ﭘـﻴﺶ ﺗﻌﺮﻳـﻒ ﺷـﺪﻩ ﭘـﺎﺭﺍﻣﺘﺮ‬ ‫‪ 1mS ، Timeout‬ﺍﺳﺖ(‬ ‫ﺍﮔﺮ ﻣﻘﺪﺍﺭﯼ ﻳﺎ ﮐﺮﮐﺘﺮﯼ ﺩﺍﺧﻞ ﺑﺮﺍﮐﺖ " ] [ " ﻗﺮﺍﺭ ﺑﮕﻴﺮﺩ ﻣﻴﮑﺮﻭﮐﻨﺘﺮﻟﺮ ﻗﺒﻞ ﺍﺯ ﺩﺭﻳﺎﻓﺖ ﺍﻃﻼﻋـﺎﺕ ﺍﺻـﻠﯽ‬ ‫ﺑﺎﻳﺴﺘﯽ ﻣﻘﺪﺍﺭ ﻗﻴﺪﮔﺬﺍﺭﯼ ﺷﺪﻩ ﺭﺍ ﺩﺭﻳﺎﻓﺖ ﮐﻨﺪ‪ .‬ﻗﻴﺪﮔﺬﺍﺭ ﻣﯽ ﺗﻮﺍﻧﺪ ﻳﮏ ﻣﻘﺪﺍﺭ ﺛﺎﺑﺖ ﻳﺎ ﻳﮏ ﻣﺘﻐﻴـﺮ ﻭ ﻳـﺎ‬ ‫ﻳﮏ ﺭﺷﺘﻪ ﺑﺎﺷﺪ‪ .‬ﺍﮔﺮ ﻋﻼﻣﺖ "‪ "#‬ﻗﺒﻞ ﺍﺯ ﻣﺘﻐﻴﺮ ﻗﺮﺍﺭ ﮔﻴﺮﺩ ﻣﻘﺪﺍﺭ ﺩﺳﻴﻤﺎﻝ ﺩﺭﻳﺎﻓﺘﯽ ﺑـﻪ ‪ ASCII‬ﺗﺒـﺪﻳﻞ‬ ‫ﻣﯽ ﺷﻮﺩ ﻭﻧﺘﻴﺠﻪ ﺭﺍ ﺩﺭ ﻣﺘﻐﻴﺮ ﺫﺧﻴﺮﻩ ﻣﯽ ﮐﻨﺪ‪.‬‬

‫‪State‬‬

‫‪True‬‬

‫‪Inverted‬‬

‫‪Baud rate‬‬

‫‪Mode number‬‬

‫‪Mode‬‬

‫‪2400‬‬

‫‪0‬‬

‫‪T2400‬‬

‫‪1200‬‬

‫‪1‬‬

‫‪T1200‬‬

‫‪9600‬‬

‫‪2‬‬

‫‪T9600‬‬

‫‪300‬‬

‫‪3‬‬

‫‪T300‬‬

‫‪2400‬‬

‫‪4‬‬

‫‪N2400‬‬

‫‪1200‬‬

‫‪5‬‬

‫‪N1200‬‬

‫‪9600‬‬

‫‪6‬‬

‫‪N9600‬‬

‫‪300‬‬

‫‪7‬‬

‫‪N300‬‬

‫ﺟﺪﻭﻝ ‪۱-۱۴‬‬

‫ﺍﻳﻦ ﺩﺳﺘﻮﺭ ﺑﺎ ﺍﺳﻴﻼﺗﻮﺭ ‪ 4MHZ‬ﺩﺭﺳﺖ ﮐﺎﺭ ﻣﯽ ﮐﻨﺪ ﻭﺑﺮﺍﯼ ﺍﻳﻨﮑﻪ ﺑﺎ ﺍﺳﻴﻼﺗﻮﺭﻫﺎﯼ ﺩﻳﮕﺮ ﺩﺭﺳﺖ ﮐﺎﺭ ﮐﻨـﺪ‬ ‫ﺑﺎﻳﺴﺘﯽ ﻓﺮﮐﺎﻧﺲ ﺍﺳﻴﻼﺗﻮﺭ ﺑﺎ ﺩﺳﺘﻮﺭ ‪ DEFINE‬ﺗﻌﺮﻳﻒ ﺷﻮﺩ‪.‬‬ ‫ﻣﺜﺎﻝ ‪:‬‬ ‫" ‪Include " modedefs.inc‬‬ ‫‪B0 var byte‬‬ ‫‪Main :‬‬ ‫ﺍﻧﺘﻈﺎﺭ ﺑﺮﺍﯼ ﺭﺳﻴﺪﻥ ﮐﺮﮐﺘﺮ "‪ "A‬ﺭﻭﯼ ﭘﻴﻦ ‪ RB0‬ﻭ ﺳﭙﺲ ﺩﺭﻳﺎﻓﺖ ﮐﺮﮐﺘﺮﻫﺎﯼ ﺑﻌﺪﯼ‘‬

‫‪serin PORTB.0, N2400, ["A"], B0‬‬

‫‪۴۴‬‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫‪variable B0‬‬ ‫ﻧﻤﺎﻳﺶ ﻣﺤﺘﻮﺍﯼ ‪ B0‬ﺭﻭﯼ ‪lcdout B0 ‘ LCD‬‬ ‫‪Loop : goto Loop‬‬ ‫‪End‬‬

‫‪.۱ -۳-۴۷‬‬ ‫ﺗﺮﮐﻴﺐ ‪:‬‬

‫‪ : SEROUT‬ﺧﺮﻭﺟﯽ ﺳﺮﻳﺎﻝ ﺁﺳﻨﮑﺮﻭﻥ‬ ‫]}‪SEROUT Pin, Mode, [Item{, Item...‬‬

‫ﺷﺮﺡ ‪:‬‬ ‫ﺍﻃﻼﻋﺎﺕ ﺭﺍ ﺑﺎ ﻗﺎﻟﺐ ﺑﻨﺪﯼ ﺁﺳﻨﮑﺮﻭﻥ ﺍﺳﺘﺎﻧﺪﺍﺭﺩ ‪ 8N1‬ﺍﺯﻃﺮﻳﻖ ﭘﻴﻦ ﻣﺸﺨﺺ ﺷﺪﻩ ﻣﯽ ﻓﺮﺳﺘﺪ ‪ .‬ﻣـﺪﻫﺎﯼ‬ ‫ﺍﻧﺘﻘﺎﻝ ) "‪ ( "Mode‬ﺑﻪ ﺍﻳﻦ ﺷﺮﺡ ﻣﯽ ﺑﺎﺷﻨﺪ‪.‬‬ ‫ﺑﺠﺎﯼ ﻣﻘﺪﺍﺭ ﻋﺪﺩﯼ ﺗﻨﻈﻴﻤﯽ ‪ ۰‬ﺗﺎ ‪ ( Mode ) ۱۵‬ﻣﯽ ﺗﻮﺍﻥ ﻳﮏ ﺍﺳﻢ ﺍﺯ ﮐﺘﺎﺑﺨﺎﻧﻪ "‪"modedefs.inc‬‬ ‫ﺭﺍ ﻗﺮﺍﺭ ﺩﺍﺩ‪.‬‬ ‫‪State‬‬

‫‪Driven True‬‬

‫‪Driven Inverted‬‬

‫‪Open True‬‬

‫‪Open Inverted‬‬

‫‪Baud Rate‬‬ ‫‪2400‬‬

‫‪Mode number‬‬ ‫‪0‬‬

‫‪Mode‬‬ ‫‪T2400‬‬

‫‪1200‬‬

‫‪1‬‬

‫‪T1200‬‬

‫‪9600‬‬

‫‪2‬‬

‫‪T9600‬‬

‫‪300‬‬

‫‪3‬‬

‫‪T300‬‬

‫‪2400‬‬

‫‪4‬‬

‫‪N2400‬‬

‫‪1200‬‬

‫‪5‬‬

‫‪N1200‬‬

‫‪9600‬‬

‫‪6‬‬

‫‪N9600‬‬

‫‪300‬‬

‫‪7‬‬

‫‪N300‬‬

‫‪2400‬‬

‫‪8‬‬

‫‪OT2400‬‬

‫‪1200‬‬

‫‪9‬‬

‫‪OT1200‬‬

‫‪9600‬‬

‫‪10‬‬

‫‪OT9600‬‬

‫‪300‬‬

‫‪11‬‬

‫‪OT300‬‬

‫‪2400‬‬

‫‪12‬‬

‫‪ON2400‬‬

‫‪1200‬‬

‫‪13‬‬

‫‪ON1200‬‬

‫‪9600‬‬

‫‪14‬‬

‫‪ON9600‬‬

‫‪300‬‬

‫‪15‬‬

‫‪ON300‬‬

‫ﺟﺪﻭﻝ ‪۱-۱۵‬‬

‫ﺍﮔﺮ ﻋﻼﻣﺖ "‪ "#‬ﻗﺒﻞ ﺍﺯ ﻣﺘﻐﻴﺮ ‪ SEROUT‬ﻗﺮﺍﺭ ﮔﻴﺮﺩ ﻣﻘﺪﺍﺭ ﺩﺳﻴﻤﺎﻝ ﺑﻪ ﮐﺪ ‪ ASCII‬ﺗﺒﺪﻳﻞ ﻣﯽ ﺷـﻮﺩ‬ ‫ﻣﺜﻼ ﺍﮔﺮ ‪ B‬ﺑﺮﺍﺑﺮ ‪ ۳۴‬ﺑﺎﺷﺪ ﺁﻧﮕﺎﻩ ‪ #B‬ﺩﺭ ﺍﻳﻦ ﺩﺳﺘﻮﺭ "‪ "۳‬ﻭ "‪ " ۴‬ﺭﺍ ﻣﯽ ﻓﺮﺳﺘﺪ‪ .‬ﺍﻳﻦ ﺩﺳﺘﻮﺭ ﺑـﺎ ﺍﺳـﻴﻼﺗﻮﺭ‬ ‫‪ 4MHZ‬ﺩﺭﺳﺖ ﮐﺎﺭ ﻣﯽ ﮐﻨﺪ ﻭﺑﺮﺍﯼ ﺍﻳﻨﮑﻪ ﺑﺎ ﺍﺳﻴﻼﺗﻮﺭﻫﺎﯼ ﺩﻳﮕـﺮ ﺩﺭﺳـﺖ ﮐـﺎﺭ ﮐﻨـﺪ ﺑﺎﻳﺴـﺘﯽ ﻓﺮﮐـﺎﻧﺲ‬ ‫ﺍﺳﻴﻼﺗﻮﺭ ﺑﺎ ﺩﺳﺘﻮﺭ ‪ DEFINE‬ﺗﻌﺮﻳﻒ ﺷﻮﺩ‪.‬ﺗﺎﺧﻴﺮ ﺑﻌﺪ ﺍﺯ ﻓﺮﺳﺘﺎﺩﻥ ﻫﺮ ﻣﻘﺪﺍﺭ ﺑﺎ ‪ DEFINE‬ﺗﻌﺮﻳﻒ ﻣـﯽ‬ ‫ﺷﻮﺩ ﮐﻪ ﺯﻣﺎﻥ ‪ ۱‬ﺗﺎ ‪ ۶۵۵۳۵‬ﻣﻴﮑﺮﻭ ﺛﺎﻧﻴﻪ ﺭﺍ ﺩﺭ ﺑﺮ ﻣﯽ ﮔﻴﺮﺩ‪.‬‬ ‫‪ ۱‬ﻣﻴﻠﯽ ﺛﺎﻧﻴﻪ ﺗﺎﺧﻴﺮ ﺑﻴﻦ ﺩﻭ ﮐﺮﮐﺘﺮ ‘ ‪DEFINE CHAR_PACING 1000‬‬

‫ﻣﺜﺎﻝ ‪:‬‬

‫‪۴۵‬‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫ﻓﺮﺳﺘﺎﺩﻥ ﻣﻘﺪﺍﺭ ﮐﺪ ﺍﺳﮑﯽ ‪ B0‬ﻭ ﻋﺪﺩ ﺛﺎﺑﺖ ‪ ۱۳‬ﺑﺎ‬

‫‪‘RA0‬‬

‫‪B0 var byte‬‬ ‫‪Main:‬‬ ‫‪B0 = 25‬‬ ‫]‪serout PORTA.3, N2400, [#B0, 13‬‬ ‫‪Loop : goto Loop‬‬ ‫‪End‬‬

‫‪ : SHIFTIN .۱ -۳-۴۸‬ﻭﺭﻭﺩﯼ ﺳﺮﻳﺎﻝ ﺳﻨﮑﺮﻭﻥ‬ ‫ﺗﺮﮐﻴﺐ ‪:‬‬ ‫]‪SHIFTIN DataPin, ClockPin, Mode, [Var{\Bits}...‬‬

‫ﺷﺮﺡ ‪:‬‬ ‫ﺍﻳﻦ ﺩﺳﺘﻮﺭ ﺑﻴﺘﻬﺎﯼ ﺩﺭﻳﺎﻓﺘﯽ ﺍﺯ ﭘﻴﻦ ﻣﺸﺨﺼﯽ ﺭﺍ ﺑﺼﻮﺭﺕ ﺳﻨﮑﺮﻭﻥ ﺑﺎ ﺳﻴﮕﻨﺎﻝ ﻓﺮﮐﺎﻧﺴﯽ‬ ‫"‪ "ClockPin‬ﺩﺭﻳﺎﻓﺖ ﻣﯽ ﮐﻨﺪ ﻭ ﺁﻧﻬﺎ ﺭﺍ ﺩﺭ ﻣﺘﻐﻴﺮﯼ ﺫﺧﻴﺮﻩ ﻣﯽ ﮐﻨﺪ‪ "Var\Bits" .‬ﻣﻘﺪﺍﺭ ﺑﻴﺘﻬﺎ ﺷﻴﻔﺖ‬ ‫ﺩﺍﺩﻩ ﺷﺪﻩ ﺭﺍ ﺑﺼﻮﺭﺕ ﺩﻟﺨﻮﺍﻩ ﺗﻌﻴﻴﻦ ﻣﯽ ﮐﻨﺪ ﻣﻘﺪﺍﺭ ﭘﻴﺶ ﻓﺮﺽ ﺁﻥ ‪ ۸‬ﻣﯽ ﺑﺎﺷﺪ‪ .‬ﺑـﺎ ﺗﻮﺟـﻪ ﺑـﻪ ﺷـﻴﻔﺖ‬ ‫ﺩﺍﺩﻥ ﻣﺴﺘﻘﻴﻢ ) ﺍﺯ ‪ MSB‬ﺑﻪ ‪ ( LSB‬ﻣﺪﻫﺎﯼ ﺍﻧﺘﻘﺎﻝ ﮔﻮﻧﺎﮔﻮﻥ ﻣﯽ ﺗﻮﺍﻧﺪ ﺗﻌﺮﻳﻒ ﺷﻮﺩ‪ .‬ﺑﺮﺍﯼ ﺍﺳـﺘﻔﺎﺩﻩ ﺍﺯ‬ ‫ﺍﻳﻦ ﻣﺪﻫﺎ ﺑﺎﻳﺴﺘﯽ ﮐﺘﺎﺑﺨﺎﻧﻪ "‪ "modedefs.BAS‬ﺑﻪ ﺑﺮﻧﺎﻣﻪ ﺍﻟﺤﺎﻕ ﮐﻨﻴﺪ‪.‬‬ ‫ﻋﻤﻠﮑﺮﺩ‬

‫‪Mode‬‬ ‫‪number‬‬

‫"‪"Mode‬‬

‫ﺍﺑﺘﺪﺍ ﺑﻴﺖ ﺑﺎﻻﺗﺮ ﺷﻴﻔﺖ ﺩﺍﺩﻩ ﻣﯽ ﺷﻮﺩ ﺍﻃﻼﻋﺎﺕ ﭘﻴﺶ ﺍﺯ ﮐﻼﮎ ﻓﺮﺳﺘﺎﺩﻩ ﺷﺪﻩ ﺧﻮﺍﻧﺪﻩ ﻣﯽ ﺷﻮﺩ‪ .‬ﮐﻼﮎ ﺭﻭﯼ‬ ‫ﺻﻔﺮ ﻣﻨﻄﻘﯽ ﻏﻴﺮ ﻓﻌﺎﻝ ﻣﯽ ﺷﻮﺩ‪.‬‬

‫‪0‬‬

‫‪MSBPRE‬‬

‫ﺍﺑﺘﺪﺍ ﺑﻴﺖ ﭘﺎﻳﻴﻨﺘﺮ ﺷﻴﻔﺖ ﺩﺍﺩﻩ ﻣﯽ ﺷﻮﺩ ﺍﻃﻼﻋﺎﺕ ﭘﻴﺶ ﺍﺯ ﮐﻼﮎ ﻓﺮﺳﺘﺎﺩﻩ ﺷﺪﻩ ﺧﻮﺍﻧﺪﻩ ﻣﯽ ﺷﻮﺩ‪ .‬ﮐﻼﮎ ﺭﻭﯼ‬ ‫ﺻﻔﺮ ﻣﻨﻄﻘﯽ ﻏﻴﺮ ﻓﻌﺎﻝ ﻣﯽ ﺷﻮﺩ‪.‬‬

‫‪1‬‬

‫‪LSBPRE‬‬

‫ﺍﺑﺘﺪﺍ ﺑﻴﺖ ﺑﺎﻻﺗﺮ ﺷﻴﻔﺖ ﺩﺍﺩﻩ ﻣﯽ ﺷﻮﺩ ﺍﻃﻼﻋﺎﺕ ﺑﻌﺪ ﺍﺯ ﮐﻼﮎ ﻓﺮﺳﺘﺎﺩﻩ ﺷﺪﻩ ﺧﻮﺍﻧﺪﻩ ﻣﯽ ﺷﻮﺩ‪ .‬ﮐﻼﮎ ﺭﻭﯼ‬ ‫ﺻﻔﺮ ﻣﻨﻄﻘﯽ ﻏﻴﺮ ﻓﻌﺎﻝ ﻣﯽ ﺷﻮﺩ‪.‬‬

‫‪2‬‬

‫‪MSBPOST‬‬

‫ﺍﺑﺘﺪﺍ ﺑﻴﺖ ﭘﺎﻳﻴﻨﺘﺮ ﺷﻴﻔﺖ ﺩﺍﺩﻩ ﻣﯽ ﺷﻮﺩ ﺍﻃﻼﻋﺎﺕ ﺑﻌﺪ ﺍﺯ ﮐﻼﮎ ﻓﺮﺳﺘﺎﺩﻩ ﺷﺪﻩ ﺧﻮﺍﻧﺪﻩ ﻣﯽ ﺷﻮﺩ‪ .‬ﮐﻼﮎ ﺭﻭﯼ‬ ‫ﺻﻔﺮ ﻣﻨﻄﻘﯽ ﻏﻴﺮ ﻓﻌﺎﻝ ﻣﯽ ﺷﻮﺩ‬

‫‪3‬‬

‫‪LSBPOST‬‬

‫ﺍﺑﺘﺪﺍ ﺑﻴﺖ ﺑﺎﻻﺗﺮ ﺷﻴﻔﺖ ﺩﺍﺩﻩ ﻣﯽ ﺷﻮﺩ ﺍﻃﻼﻋﺎﺕ ﭘﻴﺶ ﺍﺯ ﮐﻼﮎ ﻓﺮﺳﺘﺎﺩﻩ ﺷﺪﻩ ﺧﻮﺍﻧﺪﻩ ﻣﯽ ﺷﻮﺩ‪ .‬ﮐﻼﮎ ﺭﻭﯼ‬ ‫ﻳﮏ ﻣﻨﻄﻘﯽ ﻏﻴﺮ ﻓﻌﺎﻝ ﻣﯽ ﺷﻮﺩ‪.‬‬

‫‪4‬‬

‫ﺍﺑﺘﺪﺍ ﺑﻴﺖ ﭘﺎﻳﻴﻨﺘﺮ ﺷﻴﻔﺖ ﺩﺍﺩﻩ ﻣﯽ ﺷﻮﺩ ﺍﻃﻼﻋﺎﺕ ﭘﻴﺶ ﺍﺯ ﮐﻼﮎ ﻓﺮﺳﺘﺎﺩﻩ ﺷﺪﻩ ﺧﻮﺍﻧﺪﻩ ﻣﯽ ﺷﻮﺩ‪ .‬ﮐﻼﮎ ﺭﻭﯼ‬ ‫ﻳﮏ ﻣﻨﻄﻘﯽ ﻏﻴﺮ ﻓﻌﺎﻝ ﻣﯽ ﺷﻮﺩ‪.‬‬

‫‪5‬‬

‫ﺍﺑﺘﺪﺍ ﺑﻴﺖ ﺑﺎﻻﺗﺮ ﺷﻴﻔﺖ ﺩﺍﺩﻩ ﻣﯽ ﺷﻮﺩ ﺍﻃﻼﻋﺎﺕ ﺑﻌﺪ ﺍﺯ ﮐﻼﮎ ﻓﺮﺳﺘﺎﺩﻩ ﺷﺪﻩ ﺧﻮﺍﻧﺪﻩ ﻣﯽ ﺷﻮﺩ‪ .‬ﮐﻼﮎ ﺭﻭﯼ ﻳﮏ‬ ‫ﻣﻨﻄﻘﯽ ﻏﻴﺮ ﻓﻌﺎﻝ ﻣﯽ ﺷﻮﺩ‪.‬‬

‫‪6‬‬

‫ﺍﺑﺘﺪﺍ ﺑﻴﺖ ﭘﺎﻳﻴﻨﺘﺮ ﺷﻴﻔﺖ ﺩﺍﺩﻩ ﻣﯽ ﺷﻮﺩ ﺍﻃﻼﻋﺎﺕ ﺑﻌﺪ ﺍﺯ ﮐﻼﮎ ﻓﺮﺳﺘﺎﺩﻩ ﺷﺪﻩ ﺧﻮﺍﻧﺪﻩ ﻣﯽ ﺷﻮﺩ‪ .‬ﮐﻼﮎ ﺭﻭﯼ‬ ‫ﻳﮏ ﻣﻨﻄﻘﯽ ﻏﻴﺮ ﻓﻌﺎﻝ ﻣﯽ ﺷﻮﺩ‪.‬‬

‫‪7‬‬

‫ﺟﺪﻭﻝ ‪1-16‬‬

‫ﻓﺮﮐﺎﻧﺲ ﺷﻴﻔﺖ ﺣﺪﻭﺩ‬ ‫ﺗﺎﺧﻴﺮ ﺍﺿﺎﻓﯽ ﺭﺍ ﺑﺮﺍﯼ ﺁﻫﺴﺘﻪ ﮐﺮﺩﻥ ﮐﻼﮎ ﺗﻌﺮﻳﻒ ﻣﯽ ﮐﻨﻴﻢ‪.‬‬ ‫‪KHZ‬‬

‫‪ 50‬ﺍﺳﺖ ﮐﻪ ﻭﺍﺑﺴﺘﻪ ﺑﻪ ﺍﺳـﻴﻼﺗﻮﺭ ﻣـﯽ ﺑﺎﺷـﺪ‪ .‬ﺑـﺎ ﺍﺳـﺘﻔﺎﺩﻩ ﺍﺯ ‪DEFINE‬‬

‫‪DEFINE SHIFT_PAUSEUS 100 ‘ Slowing down the clock for additional 100ms‬‬

‫‪۴۶‬‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫ﻣﺜﺎﻝ ‪:‬‬ ‫]‪shiftin Data, Clock, MSBPRE, [RxData‬‬

‫‪ : SHIFTOUT .۱ -۳-۴۹‬ﺧﺮﻭﺟﯽ ﺳﺮﻳﺎﻝ ﺳﻨﮑﺮﻭﻥ‬ ‫ﺗﺮﮐﻴﺐ ‪:‬‬ ‫]‪SHIFTOUT DataPin, ClockPin, Mode, [Var{\Bits}...‬‬

‫ﺷﺮﺡ ‪:‬‬ ‫ﺍﻳﻦ ﺩﺳﺘﻮﺭ ﺑﻴﺘﻬﺎ ﺭﺍ ﺍﺯ ﻃﺮﻳﻖ ﭘﻴﻦ ﻣﺸﺨﺼﯽ ﺑﺼـﻮﺭﺕ ﺳـﻨﮑﺮﻭﻥ ﺑـﺎ ﺳـﻴﮕﻨﺎﻝ ﻓﺮﮐﺎﻧﺴـﯽ "‪"ClockPin‬‬ ‫ﺍﺭﺳﺎﻝ ﻣﯽ ﮐﻨﺪ‪ "Var\Bits" .‬ﻣﻘﺪﺍﺭ ﺑﻴﺘﻬﺎ ﺷﻴﻔﺖ ﺩﺍﺩﻩ ﺷﺪﻩ ﺭﺍ ﺗﻌﻴﻴﻦ ﻣﯽ ﮐﻨﺪ‪.‬‬ ‫ﺑﺎ ﺗﻮﺟﻪ ﺑﻪ ﺷﻴﻔﺖ ﺩﺍﺩﻥ ﻣﺴﺘﻘﻴﻢ ) ﺍﺯ ‪ MSB‬ﺑﻪ ‪ ( LSB‬ﻣﺪﻫﺎﯼ ﺍﻧﺘﻘﺎﻝ ﮔﻮﻧﺎﮔﻮﻥ ﻣﯽ ﺗﻮﺍﻧﺪ ﺗﻌﺮﻳﻒ ﺷﻮﺩ‪.‬‬ ‫ﺑﺮﺍﯼ ﺍﺳﺘﻔﺎﺩﻩ ﺍﺯ ﺍﻳﻦ ﻣﺪﻫﺎ ﺑﺎﻳﺴﺘﯽ ﮐﺘﺎﺑﺨﺎﻧﻪ "‪ "modedefs.BAS‬ﺭﺍ ﺑﻪ ﺑﺮﻧﺎﻣﻪ ﺍﻟﺤﺎﻕ ﮐﻨﻴﺪ‬ ‫ﻋﻤﻠﮑﺮد‬

‫‪Mode‬‬ ‫‪number‬‬

‫"‪"Mode‬‬

‫ﺍﺑﺘﺪﺍ ﺑﻴﺖ ﺑﺎﻻﺗﺮ ﺷﻴﻔﺖ ﺩﺍﺩﻩ ﻣﯽ ﺷﻮﺩ ﺍﻃﻼﻋﺎﺕ ﭘﻴﺶ ﺍﺯ ﮐﻼﮎ ﻓﺮﺳﺘﺎﺩﻩ ﺷﺪﻩ ﺧﻮﺍﻧﺪﻩ ﻣﯽ ﺷﻮﺩ‪ .‬ﮐﻼﮎ ﺭﻭﯼ ﺻﻔﺮ‬ ‫ﻣﻨﻄﻘﯽ ﻏﻴﺮ ﻓﻌﺎﻝ ﻣﯽ ﺷﻮﺩ‪.‬‬

‫‪0‬‬

‫‪LSBFIRST‬‬

‫ﺍﺑﺘﺪﺍ ﺑﻴﺖ ﭘﺎﻳﻴﻨﺘﺮ ﺷﻴﻔﺖ ﺩﺍﺩﻩ ﻣﯽ ﺷﻮﺩ ﺍﻃﻼﻋﺎﺕ ﭘﻴﺶ ﺍﺯ ﮐﻼﮎ ﻓﺮﺳﺘﺎﺩﻩ ﺷﺪﻩ ﺧﻮﺍﻧﺪﻩ ﻣﯽ ﺷﻮﺩ‪ .‬ﮐﻼﮎ ﺭﻭﯼ ﺻﻔﺮ‬ ‫ﻣﻨﻄﻘﯽ ﻏﻴﺮ ﻓﻌﺎﻝ ﻣﯽ ﺷﻮﺩ‪.‬‬

‫‪1‬‬

‫‪MSBFIRST‬‬

‫ﺍﺑﺘﺪﺍ ﺑﻴﺖ ﺑﺎﻻﺗﺮ ﺷﻴﻔﺖ ﺩﺍﺩﻩ ﻣﯽ ﺷﻮﺩ ﺍﻃﻼﻋﺎﺕ ﭘﻴﺶ ﺍﺯ ﮐﻼﮎ ﻓﺮﺳﺘﺎﺩﻩ ﺷﺪﻩ ﺧﻮﺍﻧﺪﻩ ﻣﯽ ﺷﻮﺩ‪ .‬ﮐﻼﮎ ﺭﻭﯼ ﻳﮏ‬ ‫ﻣﻨﻄﻘﯽ ﻏﻴﺮ ﻓﻌﺎﻝ ﻣﯽ ﺷﻮﺩ‪.‬‬

‫‪4‬‬

‫ﺍﺑﺘﺪﺍ ﺑﻴﺖ ﭘﺎﻳﻴﻨﺘﺮ ﺷﻴﻔﺖ ﺩﺍﺩﻩ ﻣﯽ ﺷﻮﺩ ﺍﻃﻼﻋﺎﺕ ﭘﻴﺶ ﺍﺯ ﮐﻼﮎ ﻓﺮﺳﺘﺎﺩﻩ ﺷﺪﻩ ﺧﻮﺍﻧﺪﻩ ﻣﯽ ﺷﻮﺩ‪ .‬ﮐﻼﮎ ﺭﻭﯼ ﻳﮏ‬ ‫ﻣﻨﻄﻘﯽ ﻏﻴﺮ ﻓﻌﺎﻝ ﻣﯽ ﺷﻮﺩ‪.‬‬

‫‪5‬‬

‫ﺟﺪﻭﻝ‬

‫ﻣﺜﺎﻝ ‪:‬‬

‫‪۱-۱۷‬‬

‫‪B0 var byte‬‬ ‫‪B1 var byte‬‬ ‫‪W0 var byte‬‬ ‫‪Main :‬‬ ‫]‪shiftout PORTA.0, PORTA.1, MSBFIRST, [B0, B1‬‬ ‫ﻓﺮﺳﺘﺎﺩﻥ ﻣﺤﺘﻮﺍﯼ ‪ B0‬ﻭ ‪ B1‬ﺑﺼﻮﺭﺕ ﺷﻴﻔﺖ ﺩﺍﺩﻥ ﺑﻪ ﺧﺮﻭﺟﯽ ﺑﻄﻮﺭﯼ ﮐﻪ ﺍﻭﻟﻴﻦ ﺑﻴﺖ ﺷﻴﻔﺖ ﺩﺍﺩﻩ ﺷﺪﻩ ﺑﻴﺖ ‪ MSB‬ﻣﯽ ﺑﺎﺷﺪ‘‬

‫]‪shiftout PORTA.0, PORTA.1, MSBFIRST, [W0\4‬‬ ‫ﻓﺮﺳﺘﺎﺩﻥ ﭼﻬﺎﺭ ﺑﻴﺖ ﺍﺯ ﻣﺘﻐﻴﺮ ‪ W0‬ﺑﻄﻮﺭﻳﮑﻪ ﺍﻭﻟﻴﻦ ﺑﻴﺖ ﺍﻧﺘﻘﺎﻝ ﻳﺎﻓﺘﻪ ﺑﻴﺖ ‪ MSB‬ﻣﯽ ﺑﺎﺷﺪ‪‘.‬‬

‫‪Loop : goto Loop‬‬ ‫‪End‬‬

‫‪ : SLEEP .۱ -۳-۵۰‬ﺧﺎﻣﻮﺵ ﮐﺮﺩﻥ ﭘﺮﺩﺍﺯﻧﺪﻩ ﺑﺮﺍﯼ ﻳﮏ ﭘﺮﻳﻮﺩ ﺯﻣﺎﻧﯽ ﻣﻌﻴﻦ‬ ‫ﺗﺮﮐﻴﺐ ‪:‬‬ ‫‪SLEEP Period‬‬

‫‪۴۷‬‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫ﺷﺮﺡ ‪:‬‬ ‫ﺍﻳﻦ ﺩﺳﺘﻮﺭ ﻣﻴﮑﺮﻭﮐﻨﺘﺮﻟﺮ ﺭﺍ ﺑﻪ ﺣﺎﻟﺖ ﮐﻢ ﻣﺼﺮﻑ ﺑﺮﺍﯼ ‪ Period‬ﺛﺎﻧﻴﻪ ﻗـﺮﺍﺭ ﻣـﯽ ﺩﻫﻨـﺪ‪ Period .‬ﻳـﮏ‬ ‫ﻣﻘﺪﺍﺭ ‪۱۶‬ﺑﻴﺘﯽ ﻣﯽ ﺑﺎﺷﺪ ﮐﻪ ﺣﺪﺍﮐﺜﺮ ‪ ۶۵۵۳۵‬ﺛﺎﻧﻴﻪ ) ﺣﺪﻭﺩ ‪ ۱۸‬ﺳـﺎﻋﺖ ( ﺗـﺎﺧﻴﺮ ﺭﺍ ﺍﻳﺠـﺎﺩ ﻣـﯽ ﮐﻨـﺪ‪.‬‬ ‫ﺩﺳﺘﻮﺭ ‪ SLEEP‬ﺍﺯ ﺗﺎﻳﻤﺮ ‪ WDT‬ﺍﺳﺘﻔﺎﺩﻩ ﻣﯽ ﮐﻨﺪ ﮐﻪ ﺑﻌﻠـﺖ ﺍﺳـﺘﻔﺎﺩﻩ ﮐـﺮﺩﻥ ﺍﺯ ‪ RC‬ﺩﺍﺧﻠـﯽ ﺩﻗـﺖ‬ ‫ﮐﻤﺘﺮﯼ ﻧﺴﺒﺖ ﺑﻪ ﮐﻼﮎ ﺍﺳﻴﻼﺗﻮﺭ ﺩﺍﺭﺩ‪.‬‬ ‫‪ : SOUND .۱ -۳-۵۱‬ﺗﻮﻟﻴﺪ ﮐﺮﺩﻥ ﺻﺪﺍ ﻳﺎ ﻧﻮﻳﺰ ﺳﻔﻴﺪ ﺭﻭﯼ ﻳﮏ ﭘﻴﻦ ﻣﺸﺨﺺ‬ ‫ﺗﺮﮐﻴﺐ ‪:‬‬ ‫)}‪SOUND Pin, (Note, Duration{, Note, Duration‬‬

‫ﺷﺮﺡ ‪:‬‬ ‫ﺍﻳﻦ ﺩﺳﺘﻮﺭ ﺻﺪﺍ ﻭ ﻧﻮﻳﺰ ﺭﻭﯼ ﭘﻴﻦ ﻣﺸﺨﺼﯽ ﺗﻮﻟﻴﺪ ﻣﯽ ﮐﻨﺪ‪ .‬ﺑﺮﺍﯼ ‪ Note = 0‬ﺻﺪﺍﯼ ﻭﺟﻮﺩ ﻧـﺪﺍﺭﺩ‪ .‬ﺍﮔـﺮ‬ ‫‪ Note‬ﻣﻘﺪﺍﺭﯼ ﺑﻴﻦ ‪ ۱‬ﺗﺎ ‪ ۱۲۷‬ﺑﺎﺷﺪ ﺻﺪﺍ ﺗﻮﻟﻴﺪ ﻣﯽ ﮐﻨﺪ ﻭ ﺍﮔﺮ ﺑﻴﻦ ‪ ۱۲۸‬ﺗﺎ ‪ ۲۵۵‬ﺑﺎﺷﺪ ﻧﻮﻳﺰ ﺗﻮﻟﻴﺪ ﻣﯽ‬ ‫ﮐﻨـﺪ‪ Note = 1 .‬ﺩﺍﺭﺍﯼ ﻓﺮﮐـﺎﻧﺲ ‪ 78.74HZ‬ﻭ ‪ Note = 127‬ﺩﺍﺭﺍﯼ ﻓﺮﮐـﺎﻧﺲ ‪ 10KHZ‬ﻣـﯽ ﺑﺎﺷـﺪ‪.‬‬ ‫‪ Duration‬ﻣﻘﺪﺍﺭﯼ ﺑﻴﻦ ‪۰‬ﺗﺎ ‪ ۲۵۵‬ﻣﻴﺒﺎﺷﺪ ﮐﻪ ﻣﺪﺕ ﺯﻣﺎﻥ ﺗﻮﻟﻴﺪ ﺻﺪﺍ ﺭﺍ ﺗﻌﻴﻴﻦ ﻣﯽ ﮐﻨﺪ ‪ .‬ﻫﺮﻳﮏ ﻭﺍﺣﺪ‬ ‫ﺍﻓﺰﺍﻳﺶ ﺍﻳﻦ ﻣﺘﻐﻴﺮ ﺗﻘﺮﻳﺒﺎ ﻣﻌﺎﺩﻝ ‪ 12mS‬ﻣﯽ ﺑﺎﺷﺪ‪.‬‬ ‫ﺳﻴﮕﻨﺎﻝ ﺧﺮﻭﺟﯽ ‪ ،‬ﻳﮏ ﻣﻮﺝ ﻣﺮﺑﻌﯽ ﺑﺎ ﺳﻄﺢ ﻭﻟﺘﺎﮊ ‪ TTL‬ﻣﯽ ﺑﺎﺷﺪ‪ .‬ﻳﮏ ﺑﻠﻨﺪﮔﻮ ﮐﻮﭼﮏ ﺑﻪ ﻫﻤﺮﺍﻩ ﺧﺎﺯﻥ‬ ‫ﻣﺴﺘﻘﻴﻤﺎ ﻣﯽ ﺗﻮﺍﻧﺪ ﺗﻮﺳﻂ ﭘﺎﻳﻪ ﺗﻮﻟﻴﺪ ﺳﻴﮕﻨﺎﻝ ﺭﺍﻩ ﺍﻧﺪﺍﺯﯼ ﺷﻮﺩ‪ .‬ﺑﻠﻨﺪﮔﻮﻫﺎﯼ ﮐﺮﻳﺴﺘﺎﻟﯽ )‪ (Piezo‬ﺑﻪ ﻃﻮﺭ‬ ‫ﻣﺴﺘﻘﻴﻢ ﺭﺍﻩ ﺍﻧﺪﺍﺯﯼ ﻣﯽ ﺷﻮﻧﺪ‪.‬‬ ‫ﻣﺜﺎﻝ ‪:‬‬ ‫ﻓﺮﺳﺘﺎﺩﻥ ‪ ۲‬ﺻﺪﺍﯼ ﻣﺘﻮﺍﻟﯽ ﺑﻪ ﺧﺮﻭﺟﯽ ‘ )‪sound PORTB.7, (100, 10, 50, 10‬‬

‫‪ : STOP .۱ -۳-۵۲‬ﺗﻮﻗﻒ ﺑﺮﻧﺎﻣﻪ ﺩﺭ ﺣﺎﻝ ﺍﺟﺮﺍ‬ ‫ﺷﺮﺡ ‪:‬‬ ‫ﺍﻳﻦ ﺩﺳﺘﻮﺭ ﺑﺮﻧﺎﻣﻪ ﺍﺟﺮﺍﯼ ﺭﺍ ﺑﻮﺳﻴﻠﻪ ﻗﺮﺍﺭ ﺩﺍﺩﻥ ﺩﺭ ﺣﻠﻘﻪ ﺑـﯽ ﻧﻬﺎﻳـﺖ ﻣﺘﻮﻗـﻒ ﻣـﯽ ﮐﻨـﺪ‪ .‬ﺍﻳـﻦ ﺩﺳـﺘﻮﺭ‬ ‫ﻣﻴﮑﺮﻭﮐﻨﺘﺮﻟﺮ ﺭﺍ ﺑﻪ ﺣﺎﻟﺖ ﺗﻮﺍﻥ ﮐﻢ ﻧﻤﯽ ﺑﺮﺩ‪.‬‬ ‫‪ : SWAP .۱ -۳-۵۳‬ﻣﺒﺎﺩﻟﻪ ﻣﻘﺎﺩﻳﺮ ﺩﻭ ﻣﺘﻐﻴﺮ‬ ‫ﺗﺮﮐﻴﺐ ‪:‬‬ ‫‪SWAP Variable1, Variable1‬‬

‫‪۴۸‬‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫ﺷﺮﺡ ‪:‬‬ ‫ﺍﻳﻦ ﺩﺳﺘﻮﺭ ﺑﺎ ﺍﻧﻮﺍﻉ ﻣﺘﻐﻴﺮﻫﺎ ) ‪ ( word ، byte ، bit‬ﺍﺳـﺘﻔﺎﺩﻩ ﻣـﯽ ﺷـﻮﺩ‪ SWAP .‬ﺑـﺎ ﺭﺷـﺘﻪ ﻫـﺎ ﻧﻴـﺰ‬ ‫ﺍﺳﺘﻔﺎﺩﻩ ﻣﯽ ﺷﻮﺩ ﻭﻟﯽ ﺑﺎﻳﺴﺘﯽ ﺷﺎﺧﺺ ﺁﻧﻬﺎ ﻳﮑﺴﺎﻥ ﺑﺎﺷﺪ‪.‬‬ ‫ﻣﺜﺎﻝ ‪:‬‬ ‫‪B0 var byte‬‬ ‫‪B1 var byte‬‬ ‫‪temp var byte‬‬ ‫‪Main :‬‬ ‫‪temp = B0‬‬ ‫‪B0 = B1‬‬ ‫‪B1 = temp‬‬ ‫ﺭﺍﻩ ﻗﺪﻳﻤﯽ ﺍﻧﺠﺎﻡ ﺁﻥ ‘‬ ‫‪...‬ﻭ ﺭﺍﻩ ﺁﺳﺎﻧﺘﺮ ﺁﻥ ‘ ‪swap B0, B1‬‬ ‫‪Loop : goto Loop‬‬ ‫‪End‬‬

‫‪ : TOGGLE .۱ -۳-۵۴‬ﻭﺍﺭﻭﻥ ﮐﺮﺩﻥ ﻭﺿﻌﻴﺖ ﭘﻴﻦ‬ ‫ﺗﺮﮐﻴﺐ ‪:‬‬ ‫‪TOGGLE Pin‬‬

‫ﺷﺮﺡ ‪:‬‬ ‫ﺍﻳﻦ ﺩﺳﺘﻮﺭ ﻭﺿﻌﻴﺖ ﭘﻴﻦ ﺭﺍ ﻭﺍﺭﻭﻥ ﻣﯽ ﮐﻨﺪ ‪ .‬ﺩﺭ ﺍﻳﻦ ﺩﺳﺘﻮﺭ ﭘﻴﻦ ﺑﺼﻮﺭﺕ ﺧﻮﺩﮐﺎﺭ ﺩﺭ ﮔﺮﺍﻳﺶ ﺧﺮﻭﺟـﯽ‬ ‫ﻗﺮﺍﺭ ﻣﯽ ﮔﻴﺮﺩ‪.‬‬ ‫ﻣﺜﺎﻝ ‪:‬‬ ‫‪Main :‬‬ ‫‪low PORTB.0‬‬ ‫‪toggle PORTB.0‬‬ ‫‪Loop : goto Loop‬‬ ‫‪End‬‬

‫‪ : WRITE .۱ -۳-۵۵‬ﻧﻮﺷﺘﻦ ﺍﻃﻼﻋﺎﺕ ﺩﺭ ‪ EEPROM‬ﺩﺍﺧﻠﯽ‬ ‫ﺗﺮﮐﻴﺐ ‪:‬‬ ‫‪WRITE Address, Value‬‬

‫ﺷﺮﺡ ‪:‬‬ ‫ﺍﻳﻦ ﺩﺳﺘﻮﺭ ‪ Value‬ﺭﺍ ﺩﺭ ﺁﺩﺭﺱ ﺗﻌﻴﻴﻦ ﺷﺪﻩ ﺩﺭ ‪ EEPROM‬ﺩﺍﺧﻠﯽ ﻣﯽ ﺭﻳﺰﺩ ‪ .‬ﺍﮔﺮ ﻣﺘﻐﻴﺮ ﺩﻭ ﺑﺎﻳﺘﯽ ﺭﺍ‬ ‫ﺧﻮﺍﺳﺘﻪ ﺑﺎﺷﻴﻢ ﺫﺧﻴﺮﻩ ﮐﻨﻴﻢ ﺑﺎﻳﺴﺘﯽ ﻫﺮ ﺑﺎﻳﺖ ﺭﺍ ﺟﺪﺍ ﮔﺎﻧﻪ ﺫﺧﻴﺮﻩ ﮐﺮﺩ‪.‬‬ ‫‪WRITE Address, Variable.BYTE0‬‬ ‫‪WRITE Address, Variable.BYTE1‬‬

‫‪۴۹‬‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫ﺍﮔﺮ ﺩﺭ ﺑﺮﻧﺎﻣﻪ ﺍﺯ ﻭﻗﻔﻪ ﺍﺳﺘﻔﺎﺩﻩ ﻣﯽ ﺷﻮﺩ ﻗﺒﻞ ﺍﺯ ﺍﻳﻦ ﺩﺳﺘﻮﺭ ﮐﻠﻴﻪ ﻭﻗﻔﻪ ﻫـﺎ ) ﺑـﺎ ﺩﺳـﺘﻮﺭ ‪( DISABLE‬‬ ‫ﻏﻴﺮ ﻓﻌﺎﻝ ﺷﻮﻧﺪ‪.‬‬ ‫ﻣﺜﺎﻝ ‪:‬‬ ‫‪B0 var byte‬‬ ‫‪Main :‬‬ ‫‪B0 = $EA‬‬ ‫ﻧﻮﺷﺘﻦ ﻣﻘﺪﺍﺭ ‪ $EA‬ﺩﺭ ﻣﻮﻗﻌﻴﺖ ‪ ۵‬ﺣﺎﻓﻈﻪ ‪write 5, B0 ‘EEPROM‬‬ ‫‪Loop : goto Loop‬‬ ‫‪End‬‬

‫‪ : WRITECODE .۱ -۳-۵۶‬ﻧﻮﺷﺘﻦ ﺩﻭﺑﺎﻳﺖ ﺍﺯ ﺍﻃﻼﻋﺎﺕ ﺑﺮ ﺭﻭﯼ ﺣﺎﻓﻈﻪ ﺑﺮﻧﺎﻣﻪ‬ ‫ﺗﺮﮐﻴﺐ ‪:‬‬ ‫‪WRITECODE Address, Value‬‬

‫ﺷﺮﺡ ‪:‬‬ ‫ﺍﻳﻦ ﺩﺳﺘﻮﺭ " ‪ " Value‬ﺭﺍ ﺩﺭ ﺁﺩﺭﺱ ﻣﻌﻴﻨﯽ ﺑﻪ ﺣﺎﻓﻈﻪ ﺑﺮﻧﺎﻣﻪ ﺍﺿﺎﻓﻪ ﻣـﯽ ﮐﻨـﺪ‪ .‬ﺍﻳـﻦ ﺩﺳـﺘﻮﺭ ﺗﻨﻬـﺎ ﺑـﺎ‬ ‫ﻣﻴﮑﺮﻭﮐﻨﺘﺮﻟﺮﻫﺎﯼ ‪ PIC‬ﮐﻪ ﺩﺍﺭﺍﯼ ﺣﺎﻓﻈﻪ ‪ FLASH‬ﻣﯽ ﺑﺎﺷﻨﺪ ) ﻣﺎﻧﻨﺪ ‪ ،( PIC16F87X‬ﺑﮑﺎﺭ ﻣﯽ ﺭﻭﺩ‪.‬‬ ‫ﻭﻗﻔﻪ ﻫﺎ ﻣﻮﻗﻊ ﺑﮑﺎﺭﮔﻴﺮﯼ ﺍﻳﻦ ﺩﺳﺘﻮﺭ ﺑﺎﻳﺴﺘﯽ ﻏﻴﺮ ﻓﻌﺎﻝ ﺑﺎﺷﻨﺪ‪.‬‬ ‫ﻣﺜﺎﻝ ‪:‬‬ ‫‪W0 var byte‬‬ ‫‪Main :‬‬ ‫‪W0 = $12FE‬‬ ‫ﻧﻮﺷﺘﻦ ﻣﻘﺪﺍﺭ ‪ $12FE‬ﺩﺭ ﻣﻮﻗﻌﻴﺖ ‪ ۱۰۰‬ﺣﺎﻓﻈﻪ ‪ FLASH‬ﺑﺮﻧﺎﻣﻪ‘ ‪writecode 100, W0‬‬ ‫‪Loop : goto Loop‬‬ ‫‪End‬‬

‫‪ : WHILE – WEND .۱ -۳-۵۷‬ﺍﺟﺮﺍﯼ ﻗﺴﻤﺘﯽ ﺍﺯ ﺑﺮﻧﺎﻣﻪ ﺗﺎ ﻭﻗﺘﯽ ﮐﻪ ﺷﺮﻁ ﺑﺮﻗﺮﺍﺭ ﺍﺳﺖ‬ ‫ﺗﺮﮐﻴﺐ ‪:‬‬ ‫‪WHILE Condition‬‬ ‫‪Instructions...‬‬ ‫‪WEND‬‬

‫ﺷﺮﺡ ‪:‬‬ ‫ﻫﺪﻑ ﺍﺯ ﺍﻳﻦ ﺩﺳﺘﻮﺭ ﻗﺮﺍﺭ ﺩﺍﺩﻥ ﻗﺴﻤﺘﯽ ﺍﺯ ﺑﺮﻧﺎﻣﻪ ﺑﻴﻦ ‪ WHILE‬ﻭ ‪ WEND‬ﺗﺎ ﻣﻮﻗﻌﯽ ﮐﻪ ﺷﺮﻁ ﺑﺮﻗـﺮﺍﺭ‬ ‫ﺍﺳﺖ ﻭﺑﻌﺪ ﺍﺯ ﺁﻥ ﺍﺯ ﺣﻠﻘﻪ ﺧﺎﺭﺝ ﻣﯽ ﺷﻮﺩ‪.‬‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫‪۵۰‬‬

‫ﻣﺜﺎﻝ ‪:‬‬ ‫‪i Var byte‬‬ ‫‪Main :‬‬ ‫‪i=1‬‬ ‫‪WHILE i< 10‬‬ ‫ﺩﺭ ﺩﻫﻤﻴﻦ ﺗﮑﺮﺍﺭ ﺑﺮﻧﺎﻣﻪ ﻣﺘﻮﻗﻒ ﻣﯽ ﺷﻮﺩ ﻭ ﭘﻮﺭﺕ ‪ B‬ﻣﻘﺪﺍﺭ ‪ ۹‬ﺭﺍ ﻧﺸﺎﻥ ﻣﯽ ﺩﻩﺩ‘‬ ‫‪i=i+1‬‬ ‫‪PORTB = i‬‬ ‫‪Pause 1000‬‬ ‫‪WEND‬‬ ‫‪goto Main‬‬ ‫‪End‬‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫ﻓﺼﻞ‬

‫ﺩﻭﻡ ‪:‬‬

‫‪۵۱‬‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫ﻣﺪﺍﺭ ﺭﺍﻩ ﺍﻧﺪﺍﺯ ﻣﻴﮑﺮﻭﮐﻨﺘﺮﻟﺮﻫﺎﯼ ‪ ) PIC‬ﺑﺮﺍﯼ ﻧﻤﻮﻧﻪ ‪( PIC 16F877‬‬

‫‪۵۲‬‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫ﻣﺜﺎﻝ‪ : ۱‬ﺭﺍﻩ ﺍﻧﺪﺍﺯﯼ ‪LCD‬‬

‫‪۵۳‬‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫‪۵۴‬‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫ﻣﺜﺎﻝ‪ : ۲‬ﺍﺭﺗﺒﺎﻁ ﺳﺮﻳﺎﻝ ﺑﺎ ﮐﺎﻣﭙﻴﻮﺗﺮ‬

‫‪۵۵‬‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫‪۵۶‬‬

۵۷

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫ ﺑﻌﻨﻮﺍﻥ ﻭﺭﻭﺩﯼ ﺁﻧﺎﻟﻮﮒ ﻭ‬A ‫ ﺍﺳﺘﻔﺎﺩﻩ ﺍﺯ ﭘﻮﺭﺕ‬:۳ ‫ﻣﺜﺎﻝ‬ ‫ﻧﺸﺎﻥ ﺩﺍﺩﻥ ﻣﻘﺎﺩﻳﺮ ﺗﺒﺪﻳﻞ ﺷﺪﻩ ﺍﺯ ﺁﻧﺎﻟﻮﮒ ﺑﻪ ﺩﻳﺠﻴﺘﺎﻝ‬

'================== Define LCD pins ================ Define LCD_DREG Define LCD_DBIT

PORTD 4

Define LCD_RSREG

PORTE

Define LCD_RSBIT

0

Define LCD_EREG

PORTE

Define LCD_EBIT

1

'================== Allocate variables =============== x

var

byte

y

var

byte

z

var

byte

ADCON1 = 4

' Set PortA 0, 1, 3 to A/D inputs

Low PORTE.2

' LCD R/W line low (W)

Pause 100

' Wait for LCD to start

Goto

' Skip subroutines

mainloop

' =============Subroutine to read a/d convertor ========== getad: Pauseus 50

ADCON0.2 = 1

' Wait for channel to setup

' Start conversion

۵۸

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

Pauseus 50

' Wait for conversion

Return

'============== Subroutine to get pot x value =========== getx: ADCON0 = $41

' Set A/D to Fosc/8, Channel 0, On

Gosub getad x = ADRESH Return '=============== Subroutine to get pot y value ============= gety: ADCON0 = $49

' Set A/D to Fosc/8, Channel 1, On

Gosub getad y = ADRESH Return '================ Subroutine to get pot z value ============ getz: ADCON0 = $59

' Set A/D to Fosc/8, Channel 3, On

Gosub getad z = ADRESH Return ' ================Main program ===================== mainloop: Gosub getx

' Get x value

Gosub gety

' Get y value

Gosub getz

' Get z value

Lcdout $fe, 1, "x=", #x, " y=", #y, " z=", #z ' Send to LCD Pause 100

Goto

End

mainloop

' Do it about 10 times a second

' Do it forever

۵۹

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫ ﺳﺎﺧﺖ ﮐﻴﺒﻮﺭﺩ ﺳﺮﻳﺎﻝ‬: ۴‫ﻣﺜﺎﻝ‬

INCLUDE "modedefs.bas"

col

VAR

BYTE

' Keypad column

row

VAR

BYTE

' Keypad row

key

VAR

BYTE

' Key value

baud

VAR

PortA.0

' Baud select pin

serpin

VAR

PortA.1

' Serial output pin

CMCON

=

7

' PortA = digital I/O

VRCON

=

0

' Voltage reference disabled

TRISA

=

%00000001' PortA.0 = baud select pin

OPTION_REG.7 =

0

' Enable PORTB pull-ups

loop: GOSUB getkey

'Get key from keypad

send: IF baud = 1 THEN fast'If baud = 1 then N9600,else N2400 SEROUT serpin,N2400,[key]'Send key value out PortA.1 GOTO loop

۶۰

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

fast: SEROUT serpin,N9600,[key] GOTO loop

'Do it forever

PAUSE 50

'Debounce key-input

getkey:

getkeyu:' Wait for all keys up PORTB = 0

' All output-pins low

TRISB = $f0

' Bottom 4-pins out, top 4-pins in

IF ((PORTB >> 4) != $f) THEN getkeyu 'If keys down, loop PAUSE 50

' Debounce key-input

getkeyp:' Wait for keypress FOR row = 0 TO 3 PORTB = 0

' 4 rows in keypad ' All output-pins low

TRISB = (DCD row) ^ $ff ' Set one row pin to output col = PORTB >> 4

' Read columns

IF col != $f THEN gotkey' If any keydown, exit NEXT row GOTO getkeyp

' No keys down, go look again

gotkey: ' Change row and column to key number 1 - 16 key = (row * 4) + (NCD (col ^ $f)) 'NOTE: for 12-key keypad, change to key = (row * 3) RETURN

END

' Subroutine over

۶۱

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

MicriCode Studio ‫ ﺍﻧﺪﺍﺯﻩ ﮔﻴﺮﯼ ﺩﻣﺎ ﻭ ﻧﻤﺎﻳﺶ ﺁﻥ ﺩﺭ ﭘﻨﺠﺮﻩ ﺍﺭﺗﺒﺎﻁ ﺳﺮﻳﺎﻝ‬: ۵ ‫ﻣﺜﺎﻝ‬

DEFINE DEFINE DEFINE DEFINE DEFINE DEFINE

loader_used 1 debug_mode 0 debug_reg portc debug_bit 6 debug_baud 9600 osc 4

' ' ' ' ' '

Boot loader is being used Debug sending True serial data Debug Port = PortC Debug.bit = PortC.6 Default baud rate = 9600 We're using a 4 MHz oscillator

۶۲

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

DEFINE ADC_BITS 8 ' Set A/D for 8-bit operation DEFINE ADC_CLOCK 1 ' Set A/D clock Fosc/8 DEFINE ADC_SAMPLEUS 50 ' Set A/D sampling time @ 50 uS samples VAR WORD ' Multiple A/D sample accumulator sample VAR BYTE ' Holds number of samples to take temp VAR BYTE ' Temperature storage samples = 0 ' Clear samples accumulator on power-up TRISA = %11111111 ' Set PORTA to all input ADCON1 = %00000011 ' Set PORTA.0,1,2,5 = A/D, PortA.3 = +Vref PAUSE 500 ' Wait .5 second loop: FOR sample = 1 TO 20 ' Take 20 samples ADCIN 0, temp ' Read channel 0 into temp variable samples = samples + temp ' Accumulate 20 samples PAUSE 250 ' Wait approximately 1/4 seconds per loop NEXT sample temp = samples/20 DEBUG "Temperature is: ",DEC temp," Deg F",10,13 samples = 0 ' Clear old sample accumulator GOTO loop ' Do it forever

END

‫ﻧﻤﺎﻳﺶ ﻧﺘﺎﻳﺞ ﺣﺎﺻﻞ ﺍﺭﺳﺎﻝ ﺷﺪﻩ ﺍﺯ ﻣﻴﮑﺮﻭﮐﻨﺘﺮﻟﺮ ﺑﻪ ﮐﺎﻣﭙﻴﻮﺗﺮ ﺍﺯ ﻃﺮﻳﻖ ﭘﻨﺠﺮﻩ ﺍﺭﺗﺒﺎﻁ ﺳﺮﻳﺎﻝ ﻧﺮﻡ ﺍﻓﺰﺍﺭ‬ MicroCode Stodio

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫ﺿﻤﻴﻤﻪ ‪:‬‬

‫ﻣﺸﺨﺼﺎﺕ ﻭ ﻗﺎﺑﻠﻴﺘﻬﺎﯼ ﻣﻴﮑﺮﻭﮐﻨﺘﺮﻟﺮ ‪PIC16F877‬‬

‫ﺍﻳﻦ ﻣﻴﮑﺮﻭﮐﻨﺘﺮﻟﺮ ﺩﺍﺭﺍ ‪ ۴۰‬ﭘﺎﻳﻪ ﻣﯽ ﺑﺎﺷﺪ ﮐﻪ ﺩﺭ ﺷﮑﻞ ﺯﻳﺮ ﻧﺸﺎﻥ ﺩﺍﺩﻩ ﺷﺪﻩ ﺍﺳﺖ‪.‬‬ ‫ﻣﺸﺨﺼﺎﺕ ﺩﺍﺧﻠﯽ ﻣﻴﮑﺮﻭﮐﻨﺘﺮﻟﺮ ‪:‬‬ ‫‪ o‬ﻋﻤﻠﮑﺮﺩ ﺑﺎﻻﯼ ‪CPU ، RISC‬‬

‫‪ o‬ﺗﻨﻬﺎ ‪ ۳۵‬ﺩﺳﺘﻮﺭ ﺑﺮﺍﯼ ﻳﺎﺩﮔﻴﺮﯼ ﺩﺍﺭﺩ‬ ‫‪ o‬ﻫﻤﻪ ﺩﺳﺘﻮﺭﺍﺕ ﺩﺭ ﻳﮏ ﺳﻴﮑﻞ ﺍﺟﺮﺍ ﻣﯽ ﺷﻮﻧﺪ ﺑﺠﺰ ﺩﺳﺘﻮﺭﺍﺕ ﮔﺰﻳﻨﺸﯽ‬ ‫‪ o‬ﺳﺮﻋﺖ ﻋﻤﻠﮑﺮﺩ ﺁﻥ ﺍﺯ ‪ DC‬ﺗﺎ ‪ 20MHZ‬ﻣﯽ ﺑﺎﺷﺪ‬ ‫‪ o‬ﺣﺎﻓﻈﻪ ﺑﺮﻧﺎﻣﻪ ﻧﻮﻳﺴﯽ ﺁﻥ ﺍﺯ ﻧﻮﻉ ‪ FLASH‬ﺍﺳﺖ ) ‪ ۸ K * ۱۴‬ﮐﻠﻤﻪ (‬ ‫ﺣﺎﻓﻈﻪ ‪ ۳۶۸ * ۸ RAM‬ﺑﺎﻳﺖ‬ ‫ﺣﺎﻓﻈﻪ ‪ ۲۵۶ * ۸ EEPROM‬ﺑﺎﻳﺖ‬ ‫‪ o‬ﻗﺎﺑﻠﻴﺖ ﻭﻗﻔﻪ ) ‪ ۱۴‬ﻣﻨﺒﻊ (‬ ‫‪ o‬ﻫﺸﺖ ﺳﻄﺢ ﺑﺮﺍﯼ ﭘﺸﺘﻪ‬ ‫‪ o‬ﻣﺪﻫﺎﯼ ﺁﺩﺭﺱ ﺩﻫﯽ ﻣﺴﺘﻘﻴﻢ ‪ ،‬ﻏﻴﺮ ﻣﺴﺘﻘﻴﻢ ﻭ ﻧﺴﺒﯽ‬ ‫‪ o‬ﺭﻳﺴﺖ ﺷﺪﻥ ﺩﺭ ﻫﻨﮕﺎﻡ ﻭﺻﻞ ﺷﺪﻥ ﻣﻨﺒﻊ ﺗﻐﺬﻳﻪ ) ‪( POR‬‬ ‫‪ o‬ﺗﺎﻳﻤﺮ ﺭﻭﺷﻦ ﻧﮕﻬﺪﺍﺭ ) ‪ ( PWRT‬ﻭ ﺗﺎﻳﻤﺮ ﺷﺮﻭﻉ ﺑﻪ ﮐﺎﺭ ﺍﺳﻴﻼﺗﻮﺭ ) ‪( OSC‬‬ ‫‪ o‬ﺗﺎﻳﻤﺮ ‪ ( WDT ) Watchdog‬ﺑﺎ ﺍﺳﻴﻼﺗﻮﺭ ‪ RC‬ﻣﺠﺰﺍ ﺑﺮ ﺭﻭﯼ ﺗﺮﺍﺷﻪ‬ ‫‪ o‬ﻣﺪ ‪ SLEEP‬ﺑﺮﺍﯼ ﮐﻢ ﻣﺼﺮﻑ ﮐﺮﺩﻥ ﺍﻧﺮﮊﯼ‬ ‫‪ o‬ﻗﺎﺑﻞ ﺍﻧﺘﺨﺎﺏ ﺑﻮﺩﻥ ﺍﺳﻴﻼﺗﻮﺭ‬ ‫‪ o‬ﻗﺎﺑﻠﻴﺖ ﺑﺮﻧﺎﻣﻪ ﺭﻳﺰﯼ ﺩﺭﻭﻥ ﻣﺪﺍﺭ ﺑﺎ ﺍﺳﺘﻔﺎﺩﻩ ﺍﺯ ﺩﻭ ﭘﺎﻳﻪ ) ‪( ICSP‬‬

‫‪۶۳‬‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫‪۶۴‬‬

‫‪ o‬ﻗﺎﺑﻠﻴﺖ ﺑﺮﻧﺎﻣﻪ ﺭﻳﺰﯼ ﺩﺭﻭﻥ ﻣﺪﺍﺭ ﺑﺎ ﻭﻟﺘﺎﮊ ‪ ۵‬ﻭﻟﺖ‬ ‫‪ o‬ﺧﻮﺍﻧﺪﻥ ﻭﻧﻮﺷﺘﻦ ﺣﺎﻓﻈﻪ ﺑﺮﻧﺎﻣﻪ ﺭﻳﺰﯼ‬ ‫‪ o‬ﻋﻤﻠﮑﺮﺩ ﺩﺭ ﻭﻟﺘﺎﮊﻫﺎﯼ ﺑﻴﻦ ‪ ۲‬ﺗﺎ ‪ ۵,۵‬ﻭﻟﺖ‬ ‫‪ o‬ﺟﺮﻳﺎﻥ ‪ Sink‬ﻭ ‪ ۲۵ Source‬ﻣﻴﻠﯽ ﺁﻣﭙﺮ‬ ‫‪ o‬ﻣﺼﺮﻑ ﺗﻮﺍﻥ ﮐﻢ‬ ‫ ‪<2mA typical @ 5V, 4 MHz‬‬‫ ‪20mA typical @ 3V, 32 kHz‬‬‫‪<1mA typical standby current -‬‬

‫ﻣﺸﺨﺼﺎﺕ ﺟﺎﻧﺒﯽ‬ ‫‪ o‬ﺗﺎﻳﻤﺮ ‪ : ۰‬ﺗﺎﻳﻤﺮ ﻭ ﻳﺎ ﺷﻤﺎﺭﻧﺪﻩ ‪۸‬ﺑﻴﺘﯽ ﺑﺎ ‪ ۸‬ﺑﻴﺖ ‪prescaler‬‬

‫‪ o‬ﺗﺎﻳﻤﺮ ‪ : ۱‬ﺗﺎﻳﻤﺮ ﻭ ﻳﺎ ﺷﻤﺎﺭﻧﺪﻩ ‪ ۱۶‬ﺑﻴﺘﯽ ﺑﺎ ‪ prescaler‬ﻣﯽ ﺗﻮﺍﻧـﺪ ﺩﺭ ﺣﺎﻟـﺖ ‪ sleep‬ﺑـﺎ ﮐـﻼﮎ ﻳـﺎ‬ ‫ﮐﺮﻳﺴﺘﺎﻝ ﺧﺎﺭﺟﯽ ﮐﺎﺭ ﮐﻨﺪ‬ ‫‪ o‬ﺗﺎﻳﻤﺮ ‪ : ۲‬ﺗﺎﻳﻤﺮ ﻭ ﻳﺎ ﺷﻤﺎﺭﻧﺪﻩ ‪۸‬ﺑﻴﺘﯽ ﺑﺎ ﺭﺟﻴﺴﺘﺮ ‪ ۸‬ﺑﻴﺘﯽ ‪ prescaler‬ﻭ ‪postscaler‬‬

‫‪ o‬ﺩﻭ ‪ Capture‬ﻭ ﻣﻘﺎﻳﺴﻪ ﮐﻨﻨﺪﻩ ﻭ ﻣﻮﻟﺪ ‪( CCP ) PWM‬‬ ‫‪ ۱۶ Capture‬ﺑﻴﺘﯽ ﺍﺳﺖ ﺑﺎ ﺣﺪ ﺗﻔﮑﻴﮏ ‪ ۱۲,۵‬ﻧﺎﻧﻮﺛﺎﻧﻴﻪ‬ ‫ﻣﻘﺎﻳﺴﻪ ﮐﻨﻨﺪﻩ ‪ ۱۶‬ﺑﻴﺘﯽ ﺍﺳﺖ ﺑﺎ ﺣﺪ ﺗﻔﮑﻴﮏ ‪ ۲۰۰‬ﻧﺎﻧﻮﺛﺎﻧﻴﻪ‬ ‫‪ PWM‬ﺑﺎ ﺣﺪﺗﻔﮑﻴﮏ ‪ ۱۰‬ﺑﻴﺖ‬ ‫‪ o‬ﻣﺒﺪﻝ ‪ A/D‬ﭼﻨﺪ ﮐﺎﻧﺎﻟﻪ ﺑﺎ ﺩﻗﺖ ‪ ۱۰‬ﺑﻴﺖ‬ ‫‪ o‬ﭘﻮﺭﺕ ‪ Slave‬ﻣﻮﺍﺯﯼ ) ‪ ( PSP‬ﺑﺎ ‪۸‬ﺑﻴﺖ ﭘﻬﻨﺎ ﺑﺎ ﭘﺎﻳﻪ ﻫﺎﯼ ﮐﻨﺘﺮﻟﯽ ‪ WR ، RD‬ﻭ ‪ CS‬ﺧﺎﺭﺟﯽ‬ ‫‪ o‬ﺁﺷﮑﺎﺭ ﺳﺎﺯﯼ ﮐﺎﻫﺶ ﻭﻟﺘﺎﮊ ﻣﻨﺒﻊ ﺑﺮﺍﯼ ﺭﻳﺴﺖ ﮐﺮﺩﻥ ) ‪( BOR‬‬

‫‪۶۵‬‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫ﭘﺎﻳﻪ ﻫﺎﯼ ﭼﻨﺪ ﻣﻴﮑﺮﻭﮐﻨﺘﺮﻟﺮ‪PIC‬‬

‫ﺷﮑﻞ‪ (1-1‬ﻣﻴﮑﺮﻭﮐﻨﺘﺮﻟﺮ‬

‫‪PIC16F877‬‬

‫‪۶۶‬‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫ﺷﮑﻞ‪ (2-2‬ﻣﻴﮑﺮﻭﮐﻨﺘﺮﻟﺮ‬

‫‪PIC16F876 / 873‬‬

‫ﺷﮑﻞ‪ (3-3‬ﻣﻴﮑﺮﻭﮐﻨﺘﺮﻟﺮ‬

‫‪PIC16F62X‬‬

‫‪۶۷‬‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫ﺟﺪﻭﻝ ﺩﺳﺘﻮﺭﺍﺕ ﺑﻴﺴﻴﮏ ‪:‬‬ ‫ﺭﺩﻳﻒ‬

‫ﺩﺳﺘﻮﺭ‬

‫ﺗﺸﺮﻳﺢ‬

‫‪۱‬‬

‫@‬

‫ﻭﺍﺭﺩ ﮐﺮﺩﻥ ﻳﮏ ﺧﻂ ﺑﺮﻧﺎﻣﻪ ﺑﺎ ﮐﺪ ﺍﺳﻤﺒﻠﯽ‬

‫‪۲‬‬

‫… ‪ASM‬‬ ‫‪ENDASM‬‬ ‫‪ADCIN‬‬

‫ﻭﺍﺭﺩ ﮐﺮﺩﻥ ﻳﮏ ﺑﻠﻮﮎ ﺍﺯ ﺩﺳﺘﻮﺭﺍﺕ ﺍﺳﻤﺒﻠﯽ‬

‫‪۴‬‬

‫‪BRANCH‬‬

‫ﭘﺮﻳﺪﻥ ﺑﻪ ﺑﺮﭼﺴﺐ ﻣﺸﺨﺺ ﺷﺪﻩ ﺗﻮﺳﻂ ﺷﺎﺧﺺ‬

‫‪۵‬‬

‫‪BRANCHL‬‬

‫ﭘﺮﺷﯽ ﺑﻠﻨﺪ ﺑﻪ ﺑﺮﭼﺴﺐ ﻧﻈﻴﺮ ﺷﺎﺧﺺ‬

‫‪۶‬‬

‫‪BUTTON‬‬

‫ﺧﻮﺍﻧﺪﻥ ﺣﺎﻟﺖ ﺩﮐﻤﻪ ﺭﻭﯼ ﭘﻴﻦ ﻭﺭﻭﺩﯼ‬

‫‪۷‬‬

‫‪CALL‬‬

‫ﻓﺮﺍﺧﻮﺍﻧﯽ ﺯﻳﺮ ﺑﺮﻧﺎﻣﻪ ﻫﺎﯼ ﺍﺳﻤﺒﻠﯽ‬

‫‪۸‬‬

‫‪CLEAR‬‬

‫ﻣﻘﺪﺍﺭ ﻫﻤﻪ ﻣﺘﻐﻴﺮﻫﺎ ﺭﺍ ﺑﻪ ﺻﻔﺮ ﺗﻐﻴﻴﺮ ﺩﺍﺩﻥ‬

‫‪۹‬‬

‫‪CLEARWDT‬‬

‫ﺑﺎﺯ ﻧﺸﺎﻧﺪﻥ ﺗﺎﻳﻤﺮ ‪Watchdog‬‬

‫‪۱۰‬‬

‫‪COUNT‬‬

‫ﺷﻤﺮﺩﻥ ﭘﺎﻟﺴﻬﺎﯼ ﺭﻭﯼ ﭘﻴﻦ ﻭﺭﻭﺩﯼ‬

‫‪۱۱‬‬

‫‪DATA‬‬

‫ﻧﻮﺷﺘﻦ ﺩﺭ ‪ EEPROM‬ﺩﺍﺧﻠﯽ ﺩﺭ ﺍﺑﺘﺪﺍﯼ ﺑﺮﻧﺎﻣﻪ‬

‫‪۱۲‬‬

‫‪DTMFOUT‬‬

‫ﺗﻮﻟﻴﺪ ﮐﺮﺩﻥ ﺳﻴﮕﻨﺎﻝ ﺻﺪﺍ )ﺗﻮﻥ( ﺷﻤﺎﺭﮔﻴﺮﯼ ﺭﻭﯼ ﭘﻴﻦ ﺧﺮﻭﺟﯽ‬

‫‪۱۳‬‬

‫‪EEPROM‬‬

‫ﻣﺠﻤﻮﻋﻪ ﺛﺎﺑﺘﻬﺎﯼ ﺍﻭﻟﻴﻪ ﺑﺮﺍﯼ ﺑﺮﻧﺎﻣﻪ ﻧﻮﺳﯽ ‪EEPROM‬‬

‫‪۱۴‬‬

‫‪END‬‬

‫ﻧﺸﺎﻧﻪ ﮔﺬﺍﺭﯼ ﭘﺎﻳﺎﻥ ﺑﺮﻧﺎﻣﻪ‬

‫‪۱۵‬‬

‫‪FOR … NEXT‬‬

‫ﺗﮑﺮﺍﺭ ﮐﺮﺩﻥ ﻳﮏ ﻗﺴﻤﺖ ﺍﺯ ﺑﺮﻧﺎﻣﻪ‬

‫‪۱۶‬‬

‫‪FREQOUT‬‬

‫ﺗﻮﻟﻴﺪ ﺳﻴﮕﻨﺎﻝ ﺑﺎ ﻓﺮﮐﺎﻧﺲ ﻣﺸﺨﺺ ﺭﻭﯼ ﭘﻴﻦ ﺧﺮﻭﺟﯽ‬

‫‪۱۷‬‬

‫‪GOSUB‬‬

‫ﻓﺮﺍﺧﻮﺍﻧﯽ ﺯﻳﺮ ﺑﺮﻧﺎﻣﻪ ﻫﺎﯼ ‪BASIC‬‬

‫‪۱۸‬‬

‫‪GOTO‬‬

‫ﺍﺩﺍﻣﻪ ﺑﺮﻧﺎﻣﻪ ﺍﺯ ﺑﺮﭼﺴﺐ ﻣﺸﺨﺺ ﺷﺪﻩ‬

‫‪۱۹‬‬

‫‪HIGH‬‬

‫ﻧﺸﺎﻧﺪﻥ ﻳﮏ ﻣﻨﻄﻘﯽ ﺭﻭﯼ ﭘﻴﻦ ﺧﺮﻭﺟﯽ‬

‫‪۲۰‬‬

‫‪HESERIN‬‬

‫ﺳﺨﺖ ﺍﻓﺰﺍﺭ ﻭﺭﻭﺩﯼ ﺁﺳﻨﮑﺮﻭﻥ‬

‫‪۲۱‬‬

‫‪HPWM‬‬

‫ﺗﻮﻟﻴﺪ ﮐﺮﺩﻥ ﺳﻴﮕﻨﺎﻝ ‪ PWM‬ﺭﻭﯼ ﭘﻴﻦ ﻣﻴﮑﺮﻭﮐﻨﺘﺮﻟﺮ‬

‫‪۲۲‬‬

‫‪HSEROUT‬‬

‫ﺳﺨﺖ ﺍﻓﺰﺍﺭ ﺧﺮﻭﺟﯽ ﺁﺳﻨﮑﺮﻭﻥ‬

‫‪۲۳‬‬

‫‪I2CREAD‬‬

‫ﺧﻮﺍﻧﺪﻥ ﺍﻃﻼﻋﺎﺕ ﺍﺯ ﻭﺳﺎﻳﻞ ﺟﺎﻧﺒﯽ ‪I2C‬‬

‫‪۲۴‬‬

‫‪I2CWRITE‬‬

‫ﻧﻮﺷﺘﻦ ﺍﻃﻼﻋﺎﺕ ﺑﺮ ﺭﻭﯼ ﻭﺳﺎﻳﻞ ﺟﺎﻧﺒﯽ ‪I2C‬‬

‫‪۲۵‬‬

‫‪INPUT‬‬

‫ﺑﺮﮔﺰﻳﺪﻥ ﭘﻴﻦ ‪ I/O‬ﺩﺭ ﮔﺮﺍﻳﺶ ﻭﺭﻭﺩﯼ‬

‫‪۲۶‬‬ ‫‪۲۷‬‬

‫‪IF … THEN‬‬ ‫‪… ELSE‬‬ ‫‪LCDOUT‬‬

‫ﮔﺰﻳﻨﺶ ﻳﮏ ﻗﺴﻤﺖ ﺍﺯ ﺑﺮﻧﺎﻣﻪ‬ ‫ﻧﻮﺷﺘﻦ ﺍﻃﻼﻋﺎﺕ ﺑﺮ ﺭﻭﯼ ﻧﻤﺎﻳﺸﮕﺮ ‪LCD‬‬

‫‪۲۸‬‬

‫‪LOOKDOWN‬‬

‫ﺟﺴﺘﺠﻮ ﮐﺮﺩﻥ ﺟﺪﻭﻝ ﺛﺎﺑﺘﻬﺎ‬

‫‪۳‬‬

‫ﺩﺭﻳﺎﻓﺖ ﻣﻘﺎﺩﻳﺮ ﺍﺯ ﻭﺭﻭﺩﯼ ﻣﺒﺪﻝ ‪A/D‬‬

‫‪۶۸‬‬

‫ﮔﺮﻭﻩ ﻣﻬﻨﺪﺳﯽ ﺍﻟﮑﺘﺮﻭﻧﻴﮏ ﻭ ﮐﺎﻣﭙﻴﻮﺗﺮ ﮊﻭﭘﻴﻦ‬

‫ﺭﺩﻳﻒ‬

‫ﺩﺳﺘﻮﺭ‬ ‫‪LOOKUP‬‬

‫ﺁﻭﺭﺩﻥ ﻣﻘﺪﺍﺭﯼ ﺍﺯ ﺟﺪﻭﻝ ﺛﺎﺑﺘﻬﺎ‬

‫‪۳۰‬‬

‫‪LOW‬‬

‫ﻗﺮﺍﺭ ﺩﺍﺩﻥ ﺻﻔﺮ ﻣﻨﻄﻘﯽ ﺩﺭ ﭘﻴﻦ ﺧﺮﻭﺟﯽ‬

‫‪۳۱‬‬

‫‪NAP‬‬

‫ﺧﺎﻣﻮﺵ ﮐﺮﺩﻥ ﺑﺮﺍﯼ ﻳﮏ ﺩﻭﺭﻩ ﺯﻣﺎﻧﯽ ﮐﻮﺗﺎﻩ‬

‫‪۳۲‬‬

‫‪OUTPUT‬‬

‫ﮔﻤﺎﺷﺘﻦ ﭘﻴﻦ ‪ I/O‬ﺩﺭ ﮔﺮﺍﻳﺶ ﺧﺮﻭﺟﯽ‬

‫‪۳۳‬‬

‫‪OWIN‬‬

‫ﺩﺭﻳﺎﻓﺖ ﺍﻃﻼﻋﺎﺕ ﺍﺯ ﻃﺮﻳﻖ ﺍﺭﺗﺒﺎﻁ ﻳﮏ ﺳﻴﻢ‬

‫‪۳۴‬‬

‫‪OWOUT‬‬

‫ﺍﺭﺳﺎﻝ ﺍﻃﻼﻋﺎﺕ ﺍﺯ ﻃﺮﻳﻖ ﻳﮏ ﺳﻴﻢ‬

‫‪۳۵‬‬

‫‪PAUSE‬‬

‫ﺗﺎﺧﻴﺮ ﺑﺮﺣﺴﺐ ﻣﻴﻠﯽ ﺛﺎﻧﻴﻪ‬

‫‪۳۶‬‬

‫‪PAUSEUS‬‬

‫ﺗﺎﺧﻴﺮ ﺑﺮﺣﺴﺐ ﻣﻴﮑﺮﻭﺛﺎﻧﻴﻪ‬

‫‪۳۷‬‬

‫‪POT‬‬

‫ﺑﺮﮔﺮﺩﺍﻧﺪﻥ ﻣﻘﺪﺍﺭ ﻣﻘﺎﻭﻣﺖ ﻣﺘﺼﻞ ﺑﻪ ﭘﻴﻦ‬

‫‪۳۸‬‬

‫‪PULSIN‬‬

‫ﻣﺤﺎﺳﺒﻪ ﻋﺮﺽ ﭘﺎﻟﺲ ﺭﻭﯼ ﭘﺎﻳﻪ ﻭﺭﻭﺩﯼ‬

‫‪۳۹‬‬

‫‪PULSOUT‬‬

‫ﺗﻮﻟﻴﺪ ﮐﺮﺩﻥ ﭘﺎﻟﺲ ﺩﺭ ﭘﻴﻦ ﺧﺮﻭﺟﯽ‬

‫‪۴۰‬‬

‫‪PWM‬‬

‫ﺗﻮﻟﻴﺪ ﺳﻴﮕﻨﺎﻝ ‪ PWM‬ﺭﻭﯼ ﭘﻴﻦ‬

‫‪۴۱‬‬

‫‪RANDOM‬‬

‫ﺗﻮﻟﻴﺪ ﻋﺪﺩ ﺗﺼﺎﺩﻓﯽ‬

‫‪۴۲‬‬

‫‪RCTIME‬‬

‫ﻣﺤﺎﺳﺒﻪ ﭘﺎﻟﺲ ﺭﻭﯼ ﭘﻴﻦ‬

‫‪۴۳‬‬

‫‪READ‬‬

‫ﺧﻮﺍﻧﺪﻥ ﻳﮏ ﺑﺎﻳﺖ ﺍﺯ ﺍﻃﻼﻋﺎﺕ ‪EEPROM‬‬

‫‪۴۴‬‬

‫‪READCODE‬‬

‫ﺧﻮﺍﻧﺪﻥ ‪ ۲‬ﺑﺎﻳﺖ ) ‪ ( WORD‬ﺍﺯ ﮐﺪ ﺑﺮﻧﺎﻣﻪ‬

‫‪۴۵‬‬

‫‪REVERSE‬‬

‫ﺗﻐﻴﺮ ﮔﺮﺍﻳﺶ ﭘﻴﻦ‬

‫‪۴۶‬‬

‫‪SERIN‬‬

‫ﻭﺭﻭﺩﯼ ﺳﺮﻳﺎﻝ ﺁﺳﻨﮑﺮﻭﻥ‬

‫‪۴۷‬‬

‫‪SEROUT‬‬

‫ﺧﺮﻭﺟﯽ ﺳﺮﻳﺎﻝ ﺁﺳﻨﮑﺮﻭﻥ‬

‫‪۴۸‬‬

‫‪SHIFTIN‬‬

‫ﻭﺭﻭﺩﯼ ﺳﺮﻳﺎﻝ ﺳﻨﮑﺮﻭﻥ‬

‫‪۴۹‬‬

‫‪SHIFTOUT‬‬

‫ﺧﺮﻭﺟﯽ ﺳﺮﻳﺎﻝ ﺳﻨﮑﺮﻭﻥ‬

‫‪۵۰‬‬

‫‪SLEEP‬‬

‫ﺧﺎﻣﻮﺵ ﮐﺮﺩﻥ ﭘﺮﺩﺍﺯﻧﺪﻩ ﺑﺮﺍﯼ ﻳﮏ ﭘﺮﻳﻮﺩ ﺯﻣﺎﻧﯽ ﻣﻌﻴﻦ‬

‫‪۵۱‬‬

‫‪SOUND‬‬

‫ﺗﻮﻟﻴﺪ ﮐﺮﺩﻥ ﺻﺪﺍ ﻳﺎ ﻧﻮﻳﺰ ﺳﻔﻴﺪ ﺭﻭﯼ ﻳﮏ ﭘﻴﻦ ﻣﺸﺨﺺ‬

‫‪۵۲‬‬

‫‪STOP‬‬

‫ﺗﻮﻗﻒ ﺑﺮﻧﺎﻣﻪ ﺩﺭ ﺣﺎﻝ ﺍﺟﺮﺍ‬

‫‪۵۳‬‬

‫‪SWAP‬‬

‫ﻣﺒﺎﺩﻟﻪ ﻣﻘﺎﺩﻳﺮ ﺩﻭ ﻣﺘﻐﻴﺮ‬

‫‪۵۴‬‬

‫‪TOGGLE‬‬

‫ﻭﺍﺭﻭﻥ ﮐﺮﺩﻥ ﻭﺿﻌﻴﺖ ﭘﻴﻦ‬

‫‪۵۵‬‬

‫‪WRITE‬‬

‫ﻧﻮﺷﺘﻦ ﺍﻃﻼﻋﺎﺕ ﺩﺭ ‪ EEPROM‬ﺩﺍﺧﻠﯽ‬

‫‪۵۶‬‬

‫‪WRITECODE‬‬

‫ﻧﻮﺷﺘﻦ ﺩﻭﺑﺎﻳﺖ ﺍﺯ ﺍﻃﻼﻋﺎﺕ ﺑﺮ ﺭﻭﯼ ﺣﺎﻓﻈﻪ ﺑﺮﻧﺎﻣﻪ‬

‫‪۵۷‬‬

‫– ‪WHILE‬‬ ‫‪WEND‬‬

‫ﺍﺟﺮﺍﯼ ﻗﺴﻤﺘﯽ ﺍﺯ ﺑﺮﻧﺎﻣﻪ ﺗﺎ ﻭﻗﺘﯽ ﮐﻪ ﺷﺮﻁ ﺑﺮﻗﺮﺍﺭ ﺍﺳﺖ‬

‫‪۲۹‬‬

‫ﺗﺸﺮﻳﺢ‬

Related Documents

Picbasic Farsi
November 2019 11
Farsi Quran
November 2019 7
Learn Farsi
June 2020 4
Genetic Farsi
October 2019 16
Farsi Bible
November 2019 5
Gsm Farsi
November 2019 17