TunghaiFSM
  • NEW!
    NEW!  Connect Ideas Across Notes
    Save time and share insights. With Paragraph Citation, you can quote others’ work with source info built in. If someone cites your note, you’ll see a card showing where it’s used—bringing notes closer together.
    Got it
        • Sharing URL Link copied
        • /edit
        • View mode
          • Edit mode
          • View mode
          • Book mode
          • Slide mode
          Edit mode View mode Book mode Slide mode
        • Customize slides
        • Note Permission
        • Read
          • Owners
          • Signed-in users
          • Everyone
          Owners Signed-in users Everyone
        • Write
          • Owners
          • Signed-in users
          • Everyone
          Owners Signed-in users Everyone
        • Engagement control Commenting, Suggest edit, Emoji Reply
      • Invite by email
        Invitee

        This note has no invitees

      • Publish Note

        Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

        Your note will be visible on your profile and discoverable by anyone.
        Your note is now live.
        This note is visible on your profile and discoverable online.
        Everyone on the web can find and read all notes of this public team.

        Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

        Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

        Explore these features while you wait
        Complete general settings
        Bookmark and like published notes
        Write a few more notes
        Complete general settings
        Write a few more notes
        See published notes
        Unpublish note
        Please check the box to agree to the Community Guidelines.
        View profile
      • Commenting
        Permission
        Disabled Forbidden Owners Signed-in users Everyone
      • Enable
      • Permission
        • Forbidden
        • Owners
        • Signed-in users
        • Everyone
      • Suggest edit
        Permission
        Disabled Forbidden Owners Signed-in users Everyone
      • Enable
      • Permission
        • Forbidden
        • Owners
        • Signed-in users
      • Emoji Reply
      • Enable
      • Versions and GitHub Sync
      • Note settings
      • Note Insights New
      • Engagement control
      • Make a copy
      • Transfer ownership
      • Delete this note
      • Insert from template
      • Import from
        • Dropbox
        • Google Drive
        • Gist
        • Clipboard
      • Export to
        • Dropbox
        • Google Drive
        • Gist
      • Download
        • Markdown
        • HTML
        • Raw HTML
    Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Help
    Menu
    Options
    Engagement control Make a copy Transfer ownership Delete this note
    Import from
    Dropbox Google Drive Gist Clipboard
    Export to
    Dropbox Google Drive Gist
    Download
    Markdown HTML Raw HTML
    Back
    Sharing URL Link copied
    /edit
    View mode
    • Edit mode
    • View mode
    • Book mode
    • Slide mode
    Edit mode View mode Book mode Slide mode
    Customize slides
    Note Permission
    Read
    Owners
    • Owners
    • Signed-in users
    • Everyone
    Owners Signed-in users Everyone
    Write
    Owners
    • Owners
    • Signed-in users
    • Everyone
    Owners Signed-in users Everyone
    Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # 2nd小考 ###### tags: `microcomputer` `note` `thu` {%hackmd theme-dark %} ## ***CH7*** ## MCS-51內部功能 ![](https://i.imgur.com/kf9AU4I.png) ### 外部程式記憶器與外部RAM 使用程式位址暫存器作為記憶器位址暫存器(RAM) I/O埠0與2作為位址與資料匯流排 ### 使用PSEN、RD、WR控制線 區分目前存取的記憶器為程式記憶器((PSEN啟動)或是資料記憶器((RD)或(WR)啟動) ## CPU時序 ### 機器週期 一個機器週期(machine cycle)=12個時脈週期(clock cycle) =>分為6個狀態,稱為S1~S6 =>每個狀態由2個clock cycle組成,稱為phase 1 (P1)與phase 2 (P2) P1:算術與邏輯運算動作,P2:內部暫存器的轉移 ALE(Address Latch Enable): 位址栓鎖訊號,用於外部記憶體讀寫。 CPU在每一個機器週期的S1(S1 P2)與S4(S4 P2)狀態時 產生2個時脈週期的ALE訊號。 ### 指令長度 1位元組(INC A) 2位元組(ADD A,#data) 3位元組(CJNE A,direct,disp8) 指令執行時間為1到2個機器週期 MUL與DIV為4個機器週期 ![](https://i.imgur.com/d5iXUbK.png) ## 硬體介面 ![](https://i.imgur.com/wL0gbn5.png) ### 支援接腳: Vcc與GND(電源)、XTAL1、XTAL2(時脈輸入)、RST(reset) ### 4個並列I/O埠 ***I/O埠0(P0.7~P0.0,雙向,8位元):*** 輸出埠時,每一個接腳可以吸取8個TTL的輸入電流 輸入埠時,每一個接腳可當作高阻抗輸入端使用 存取外部程式或資料記憶器時,多工的低序位元組的位址匯流排與資料匯流排,且具有內部提升電路,將其提升到高電位 ***I/O埠1(P1.7~P1.0,雙向,8位元):*** 輸入埠,寫入1於I/O埠1接腳的門閂電路後,每一個I/O接腳均由內部的提升電阻器提升到高電位 輸出埠,每一個I/O接腳可以吸取或供給4個TTL的輸入電流 ***I/O埠2(P2.7~P2.0,雙向,8位元):*** 輸入埠,每一個I/O接腳在外部電路為低電位時,輸出𝐼_𝐼𝐿(內部有提升電路連接到電源) 輸出埠,每一個I/O接腳可以吸取或供給4個TTL的輸入電流 ***I/O埠2(P2.7~P2.0,雙向,8位元):*** 存取外部程式記憶器或是使用16位元的位址(MOVX @DPTR)存取外部RAM時,為高序位元組的位址匯流排 ***I/O埠3(P3.7~P3.0,雙向,8位元):*** 輸出埠,每一個I/O接腳可以吸取或供給4個TTL的輸入電流 輸入埠,每一個I/O接腳在外部電路為低電位時,輸出𝐼_𝐼𝐿(內部有提升電路連接到電源) 具備另一組副功能:規劃(寫入資料於程式記憶器或快閃記憶器)內部程式記憶器時,也當作某些控制信號的輸入端 I/O埠3的副功能 : ![](https://i.imgur.com/lKoCCPk.png) ## 記憶器介面 ### 可使用$\overline{(RD)}$與$\overline{(WR)}$直接存取64k($2^{16}$)位元組的外部RAM及使用$\overline{(PSEN)}$存取到64k($2^{16}$)位元組的程式記憶器 ### MCS-51為一個8位元系統,當其存取記憶器的資料時,每次均為一個位元組 * 位址匯流排為16位元(A15~A0) * 資料匯流排為8位元(D7~D0) 為將所有位址匯流排信號接腳、資料匯流排信號接腳、控制信號包裝在標準的PDIP內 低序的8條位址匯流排與資料匯流排以多工方式輸出 位址匯流排與資料匯流排與I/O port 0 和 2重疊使用相同的接腳 ***($\overline{EA}$)(External access,輸入)(低電位啟動):*** 只使用外部的程式記憶器,提供0000H~0FFFFH空間,接到低電位 接高電位時,同時使用內部與外部程式記憶器 ***($\overline{RD}$)(Read,輸出)(低電位啟動):*** 啟動時,表示MCS-51欲自資料匯流排(即記憶器或IO裝置中)中,讀取資料 ***($\overline{WR}$)(Write,輸出)(低電位啟動):*** 啟動時,寫入資料於資料匯流排中。當為低電位時,CPU的資料匯流排中含有正確的資料 ***($\overline{PSEN}$)(program store enable,輸出)(低電位啟動):*** 啟動時,指示正在讀取外部程式記憶器中的資料 每一個機器週期中均啟動兩次 ***若維持在不啟動的狀態*** 讀取內部程式記憶器中的資料 ***ALE(address latch enable,輸出):*** 指示MCS-51的位址/資料匯流排上的資料為成立的位址資料。 ### ALE相關: #### 正常指令執行期間(不存取外部RAM時),持續輸出一個頻率為1/6系統時脈的脈波(可當作外部的時序信號或是時脈) #### MOVX存取外部RAM時,第2個機器週期中,ALE只輸出一個脈波 #### 若不希望ALE持續輸出脈波 * 設定SFR中的8EH位置的位元0之值為1 * 只在MOVX或是MOVC執行時,才啟動而輸出適當的脈波 * 從高阻抗電路提升為高電位 ### 中斷控制 #### 包含一個兩層次導向性優先權中斷系統 位於程式記憶器最底端的48個位元組$\overline{(INT0)}$、 $\overline{(INT1)}$ #### $\overline{(INT0)}$ (P3.2)與$\overline{(INT0)}$ (P3.3)(低電位啟動,輸入):可抑制式中斷輸入線 當兩信號為低電位時,且IE暫存器中對應的位元與EA位元值均為1時 CPU完成目前的指令執行後,將認知此中斷,並產生一個中斷程序 ### 內部記憶體規劃 #### 內部含有0k~64k位元組的快閃記憶器或是EEPROM 包含規劃內部程式記憶器的相關控制信號與電路 ALE/$\overline{PROG}$ 與 ($\overline{EA}$)/$V_{pp}$ ALE/$\overline{PROG}$ (Program,輸入) :規劃內部程式記憶器時,由此接腳加入規劃脈波 $\overline{EA}$/$V_{pp}$(Program,輸入) :規劃內部程式記憶器時,此信號必須接於$V_{pp}$ ## 晶片模組 ### 單一模組 ![](https://i.imgur.com/QIIjvlN.png) ### 擴充(多重) ![](https://i.imgur.com/wxV6raE.png) ## 記憶器類型 ### 提供獨立的資料記憶器與程式記憶器位址空間,各為64k位元組 * **內部程式記憶器與內部RAM** 用於需要小容量的資料記憶器之系統中,容量由8k到64k位元組不等 * **內部程式記憶器與外部RAM** 需要大容量的資料記憶器中,程式記憶器8k~64k位元組不等,容量最多為64k位元組 * **外部程式記憶器與外部RAM** 外部程式記憶器通常使用EEPROM或是快閃記憶器。有時也使用SRAM,以方便程式的下載與測試。外部RAM與程式記憶器容量最多個為64k位元組 * **內部程式記憶器與外部RAM及外部程式記憶器** 內部的程式記憶器儲存監督程式,而外部的程式記憶器儲存應用程式。外部RAM與程式記憶器可合併成一個SRAM ### RAM SRAM(6264: 8k* 8;62256: 32k* 8) 於SRAM中,若只有一條讀取與寫入控制輸入線時,標示為R/$\overline{W}$ 若被選取($\overline{CE}$為低電位) : R/$\overline{W}$ =1,讀取,R/$\overline{W}$ =0,寫入 讀取與寫入控制信號各別使用一條輸入線,標示為$\overline{OE}$ 與 $\overline{WE}$ ### SRAM元件被選取時 $\overline{(OE)}$ =0,讀取, $\overline{(WE)}$ = 0,寫入 兩者皆為1時,沒有任何動作 資料輸出端為高阻抗狀態 6246具有兩條晶片選擇輸入線($\overline{CE1}$ 與CE2)、各自的讀取與寫入控制輸入線($\overline{(OE)}$、$\overline{(WE)}$) 62256只有一條晶片選擇輸入線($\overline{(CE)}$ 與 $\overline{(OE)}$,$\overline{(WE)}$ ### SRAM記憶器接腳分佈: ![](https://i.imgur.com/aAsxisB.png) #### MCS-51的低序位元組與資料匯流排,是由I/O埠0以多工的方式依序輸出,必須使用門閂電路(74LS373),藉著ALE控制信號鎖住低序位元組的位址 ### 外部資料記憶器: ![](https://i.imgur.com/pPiOMn3.png) 讀取週期中,由於$\overline{(WE)}$均保持在高電位,記憶器元件的$\overline{(WE)}$輸入端為高電位 * $\overline{(OE)}$輸入端由於$\overline{(RD)}$信號的加入而為低電位 * 若其$\overline{(CE1)}$輸入端也為低電位,該記憶器元件被致能,而輸出由位址線定址的記憶器位元組資料於資料匯流排上 寫入週期中,由於$\overline{(RD)}$信號均保持在高電位,記憶器元件的$\overline{(OE)}$輸入端為高電位,其輸出緩衝器處於關閉狀態 $\overline{WE}$輸入端由於$\overline{(WR)}$信號的加入而為低電位 * 若$\overline{(CE)}$輸入端也為低電位,該記憶器元件的寫入電路被致能 * 寫入資料匯流排上的資料於由位址線指定的記憶器元件位致中 ### 快閃記憶器 ![](https://i.imgur.com/ROCdnAj.png) #### 快閃記憶器接腳分布 ![](https://i.imgur.com/bLZx2Ak.png) #### SRAM 記憶器組織 ![](https://i.imgur.com/fGT9I9a.png) ### 外部程式記憶器 ![](https://i.imgur.com/7Kngto9.png) --- ## ***CH8*** ## **中斷與處理** ## 主要應用 * 協調I/O動作與處理 * 偵測軟體程式執行時,可能產生的意外情況 * 偵測硬體電路的意外狀況 * 提供使用者存取系統資源的管道 * 提供危機性事件的處理 * 提醒CPU定時的處理某些例行性程式 ## 中斷類型 ### 內部中斷(internal interrupt, TRAP) 1. CPU內部的硬體電路產生的中斷 1. 大部分16或32位元的微處理器中,當CPU內部發生異常的事件(除以0或執行一個不合法的指令),都會產生一個硬體中斷 1. CPU轉移控制權到一個預定的ISR,做一些應急的處理 1. 例外(exception)或是TRAP * MCS-51並未提供,只有ARM或x86/x64 #### 軟體中斷(software interrupt) 1. CPU執行一個軟體中斷指令產生的中斷 1. 大部分16或32位元的微處理器,通常提供一種特殊的軟體指令 1. 程式的控制權轉移之用 1. 指令執行後,CPU即產生一個中斷程序,而執行相關的ISR * MCS-51並未提供,只有ARM或x86/x64 ### 外部中斷(external interrupt) #### 可抑制式中斷(maskable interrupt) 中斷信號可以被擋住(抑制),令CPU不對其採取任何行動 * MCS-51與x86/x64 #### 不可抑制式中斷(nonmaskable interrupt) 中斷信號產生後,CPU必然會對其採取因應措施(行動) * x86/x64中的NMI (non maskable interrupt) **CPU在認知一個中斷後,即暫時中止目前正在執行的程式,而進入中斷服務程式繼續執行指令,以處理中斷需求的動作。** #### 導向性中斷(vectored interrupt) 一個中斷的中斷服務程式(ISR)的起始位址,需要由產生該中斷的來源I/O裝置,提供一些(位址)資料 * x86/x64微處理器中的INTR #### 非導向性中斷(nonvectored interrupt) 1. 一個中斷的中斷服務程式(ISR)的起始位址,只由CPU內部自行決定時 1. 每一個中斷的中斷服務程式的起始位址,在設計CPU時已經事先設定為固定的位址。 * MCS-51中的所有中斷和x86/x64中的NMI ## CPU對中斷的反應 ### 中斷輸入控制線的輸入信號是否會被CPU認知 * 中斷致能旗號IE(interrupt enable flag)(EA, enable all) * IE=0,不管該中斷輸入線是否有中斷信號產生,CPU皆不會認知此中斷 * IE=1,CPU才會認知該中斷 ### 為了簡化CPU內部的硬體設計與指令執行的完整性, * 目前指令執行週期結束,才會認知一個中斷 ### CPU對中斷的反應 * 目前指令執行週期結束 * IE=1(對可抑制式中斷而言) * 有中斷信號發生 #### 導向性中斷: ![](https://i.imgur.com/Jpc15nD.png) 1. ***導向性中斷*中,當CPU認知一個中斷及送出中斷認知信號後,即自動地由資料匯流排中,讀取一個位元組的資訊** * 中斷向量(interrupt vector)或中斷類型(interrupt type) * 決定ISR的起始位址 2. **中斷向量內容可以為** * 單位元組的指令(Z80中的RST) * 中斷向量表的指標(x86/x64) * 由微處理器的類型與工作模式而定 3. ***非導向性中斷*** * CPU認知一個中斷後,自動由內部硬體取得對應的中斷向量 * 決定ISR的起始位址 * MCS-51中的所有中斷均屬於此類型 4. **任何一個微處理器通常擁有多條中斷輸入線** * 處理每一條中斷輸入線,皆有不同的優先順序 * 中斷優先權(interrupt priority) * 每一條輸入線相當於一個優先權層次(interrupt level) 5. **每一條輸入線皆可被外部I/O裝置用來要求中斷服務** * 較低層次的中斷服務程式可以被另外一個較高層次的中斷所中斷 * 多層次(multilevel)中斷系統 6. **x86/x64,有兩條中斷輸入線(NMI與INTR)** * NMI有較高的優先權 7. **MCS-51中,一共有5個中斷來源** * 由中斷優先權(IP)暫存器動態地分成高、低兩種不同的優先權層次 * 相同優先權群中的中斷不能被另外一個中斷所中斷 ### MCS-51中斷結構 #### MCS-51在取樣中斷後 * CPU檢查高、低兩個優先權中斷群中的中斷 * 事先設定好的輪呼次序,決定目前可以被服務的中斷,提供服務 * 輪呼次序是固定的,但優先權可以選擇為高或低 * 優先權由IP暫存器與輪呼共同決定 ![](https://i.imgur.com/jN9aHy7.png) ### 中斷來源控制 #### 外部中斷輸入線可由定時器控制暫存器(time control register) 中的位元IT0與IT1規劃成位準偵測(Level sensitive) 或負緣偵測(negavite edge sensitive) #### ITx(x=1/0)為0時,$\overline{INTx}$為低位準偵測,ITx為1時,為負緣偵測 #### 負緣偵測時,外部中斷$\overline{INTx}$的信號上升為高電位的一個週期,然後下降為低電位的一個機器週期 * TCON暫存器中的中斷旗號位元IEx為1,產生中斷 * IEx在CPU進入對應中斷服務程式後,即自動被清除為0 #### 位準偵測時,$\overline{INTx}$的信號必須持續啟動(維持在低電位)直到該中斷被認知為止 * 恢復為不起動狀態,否則將再度產生中斷 * 中斷旗號位元的值與$\overline{INTx}$的反向值相同 #### 當定時器/計數器0與1(定時器0模式3除外)計時終了或計數溢位時 * 對應的中斷旗號位元TFx即設定為1,因而產生中斷 * CPU進入對應中斷服務程式後,即清除該中斷旗號位元TFx為0 #### 在串列埠中,TI(transmit interrupt)與RI(receive interrupt)共用一個中斷。 * 進入中斷服務程式後,必須判別是TI或RI產生的中斷,以提供適當的服務 * TI與RI必須由中斷服務程式清除 #### MCS-52,定時器2的中斷由TF2或EXF2產生 * 判別是TF2或EXF2產生的中斷 * 由中斷服務程式清除 #### 均可由軟體設定為1,以產生中斷,或是清除為0,清除任何懸置尚未服務的中斷 ![](https://i.imgur.com/RELEFdE.png) ### 中斷智能暫存器 * 全體致能(Enable all, EA)位元控制所有中斷的產生與否 * EA為一般微處理器中的中斷致能(IE) * 當EA為0,所有中斷均不被接受 * EA為1,一個中斷的接受與否,尤其各別的控制位元決定 #### 暫存器控制功能 1. ES (enable serial port) >> 串列通訊埠 1. ET1 (enable timer 1) >> 定時器1 1. EX1 (enable external interrupt 1) >> 外部中斷輸入$\overline{INT1}$ 1. ET0 (enable timer 0) >> 定時器 0 1. EX0 (enable external interrupt 0) >> 外部中斷輸入$\overline{INT0}$ #### 其值為0:抑制中斷 ; 其值為1:致能中斷 #### ET2(enable timer 2)為MCS-52的定時器2的中斷控制位元 ![](https://i.imgur.com/Wm8oIGM.png) ### 中斷優先權暫存器 #### MCS-51中的每一個中斷來源,均可以依據IP的內容,規畫為高優先權中斷群或是低優先權中斷群 #### 中斷優先權暫存器中的每一個位元對應一個中斷來源 * PT2(MCS-52的定時器2) * PS(串列通訊埠) * PT1(定時器1) * PX1(外部中斷輸入$\overline{INT1}$) * PT0(定時器0) * PX0(外部中斷輸入$\overline{INT0}$) **當其值為0,對應來源歸入低優先權;其值為1,對應來源歸入高優先權** #### 低優先權中斷群中的中斷 * 可被高優先權中斷群中的中斷所中斷 * 不會被另一個低優先權中斷群的中斷所中斷 #### 高優先權中斷群中的中斷,則不會被任何其他的中斷所中斷。當有2個或多個中斷來源同時產生 -> 高優先權的中斷將被認知(依據事先設定好的輪呼次序) #### 輪呼次序為$\overline{INT0}$(優先權最高)->定時器0->$\overline{INT1}$->定時器1->串列通訊埠->定時器2->(優先權最低) #### MCS-51/52提供2個層次的中斷優先控制 1. 中斷優先權暫存器決定 1. 輪呼次序 ![](https://i.imgur.com/4lW4fLa.png) ## 中斷處理 ### 中斷處理程序 #### 於每一個機器週期的S5P2時 * 取樣中斷旗號位元 * 其次的機器週期執行輪呼動作,選取一個中斷提供服務 * MCS-52的定時器2的TF2在S2P2設定,並且在產生設定時器溢位的同一個機器週期中,執行輪呼動作 #### 認知一個中斷後,若無下列一個狀況發生時,CPU即執行一個硬體的LCALL副程式呼叫動作,跳到ISR中執行,並抑制相同優先權層次的其他中斷產生中斷,稱為 ***中斷處理程序(中斷程序)*** * 已經有一個較高或是相同優先權層次的中斷服務程式正在執行 * 目前的輪呼動作不是在一個執行中的指令的最後一個週期 * 目前正在執行中的指令為RETI指令或是任何寫入IE或是IP暫存器的指令 #### 三條件中任一情況發生時: 暫停產生硬體的LCALL副程式呼叫動作 #### 狀況2: 確保在進入一個中斷服務程式之前,已經完成目前正在進行中的指令之動作 #### 狀況3: 確保在進入一個ISR之前,若目前正在進行中的指令為RETI或是任何寫入IE或IP暫存器的指令時,至少能在繼續執行一個指令。 * **輪呼動作** -> 每一個機器週期均重複一次 * 一個中斷旗號啟動後,因上述狀況而其ISR無法被執行,並且在狀況解除之後,該中斷旗號也不再啟動時,該中斷將不被服務。 * 每一個中斷向量皆**配置8個位元組** -> 較複雜的應用中,ISR多於8個位元組,可以在此位置上置放一個LJMP指令 ![](https://i.imgur.com/SXAIPO5.png) ### 中斷遲滯時間 * 中斷的需求產生到進入ISR,開始執行指令的時間 * 關鍵的因素 ![](https://i.imgur.com/hY436Nh.png) #### 當進入一個ISR後,除非被中斷的程式至少執行一個指令,否則將不再進入該ISR * 利用此一特性,MCS-51可以單步執行指令,其做法為設定$\overline{INT0}$為位準啟動方式,並設定該ISR為: ![](https://i.imgur.com/n5NhwsE.png) #### 若$\overline{INT0}$(P3.2)正常為低電位 * CPU 進入$\overline{INT0}$ISR,等待$\overline{INT0}$上升為高電位,然後下降為低電位 * 接著執行RET1指令,回到程式中執行一個指令,再進入$\overline{INT0}$ISR,重複上述動作。 #### 每一個$\overline{INT0}$的高電位脈波將促使程式執行一個指令 ### 中斷服務程式 #### ISR的結構與副程式的結構類似 * 運用CALL呼叫副程式,RET則由副程式回到主程式 #### CPU認知一個中斷後,呼叫該中斷的ISR * ISR欲回到主程式,使用RET ![](https://i.imgur.com/uCK6VIQ.png) #### 設計一個ISR,需遵守下列三步驟: ***撰寫ISR*** 1. 在中斷向量表中的適當位置內填入ISR,或是在該位置中填入LJMP指令,使其跳到ISR中執行 1. 若需要,設定IP暫存器 1. 設定適當的中斷致能位元 ![](https://i.imgur.com/zBTTzdP.png) ### 巢路中斷 ![](https://i.imgur.com/ju6pmuT.png) $\overline{INT1}$產生中斷,中斷向量為13H ### 系統重置 #### 系統重製為讓CPU回到一個已知的初始狀態 * 恢復內部的SFR內容為預先設定的值,然後重新執行開機程式 #### 功率控制為適當管理功率消耗(Power consumption) * 在一特定的應用中,僅需最小的功率消耗 #### 如何重置MCS-51系統? * 啟動RST信號完成 * 時脈信號啟動後,RST設為高電位,且延續兩個機器週期以上時,即系統重置。 #### SFR的初值 * PC、ACC、暫存器B、DPTR & PSW均清除為0。(CPU由0000H位址開始執行指令) * SP設為07H * I/O port設為0FFH * IP為xxx00000B,IE為0xx00000B (MCS-51) * IP為xx000000B,IE為0X000000B (MCS-52) * 定時器暫存器與SCON均清除為0,SBUF則為未定值(xxH) * PCON為0xxx0000B ### 電源控制 ![](https://i.imgur.com/wWhsVIm.png) ![](https://i.imgur.com/NYf16TV.png) ![](https://i.imgur.com/jVEmfmB.png) ### ***Author: TMWF***

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Google Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully