Chapter 9 PIC18F Interrupt I/O, LCD, and Keyboard Interfacing
Basics of Polled I/O vs. Interrupt I/O
unconditional , conditional I/O
- 有 unconditional I/O , conditional I/O 這兩種I/O。
- 微算機可以隨時用 unconditional I/O 傳資料給外部裝置。
- conditional I/O 會先做 handshaking ( 交握 ) 才可以開始傳資料。
handshaking 的概念是微算機先聯絡外部裝置,外部裝置說 OK 並且微算機接收到了,然後才會開始傳送資料。
8 bit A/D converter
- Start 接收到一個脈衝時,會做好初始化準備轉換,把 Busy bit 設置成 LOW 。
- Busy bit HIGH 的時候轉換結束。
- 結束後 Output 會變 LOW 然後把 A/D 轉換的東西輸出。
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
A/D converter to microcontroller
- 程式呼叫 A/D converter,PortA 的 bit 2 傳一個脈衝給 A/D Start bit。
- 直到程式傳輸完了,Busy 會改成 HIGH,左邊接收到之後 PortA bit 0 會傳 LOW 把 Output enable 改成 LOW,然後把資料轉成數位資料放在 Digital output。
Port B 接收 digital output。
- 程式一直跑 loop 等 Busy 改成 HIGH,被稱為 Conditional or Polled I/O。
- 因為怕等太久影響到其他程序,所以用 interrupt 比較好,出現的時候再來處理。
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
A/D and microcontroller via interrupt
- 跟上面很像,只是把 Busy 指向 interrupt bit。 ( 不確定為啥 start 跑到bit 7 )。
- interrupt 會把程式中斷,先來接收 A/D 資料 ( 看怎麼寫 )。
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
課本說 interrupt RETURN 完了之後會 enable interrupt bit,但我們平常寫的時候還是要自己調回來。
- p.19 - p.23 有 example 根據電壓調整LED是否開啟的 asm 和 C code。
INTCON registers for exteranl interrupt
- 有三個 registers 分別為 INTCON , INTCON2 , INTCON3 ( 小心沒有INTCON1 )
- INTCON 裡面有 INT0IE , INT0IF 去控制 external interrupt。
- INTCON3 裡面有 INT1IE , INT1IF , INT2IE , INT2IF 去控制兩個的 external interrupt。
- 要用 external interrupt 的時候要設置 IE IF,所以需要兩個 instruction cycles。 ( 預設 1M 的情況下就是 2 * 4 微秒 )。
Programming the PIC18F Ext. Interrupts。
- ⭐RETFIE 是 ISR 最後會執行的指令,作用是會把 GIE set 成 1 然後讀取 PC 原本要執行的指令。
- high priority interrupt 從 0x000008開始到 0x000017 結束,之後是 low priority interrupt,所以如果要寫大東西要直接寫 goto 在外面做。
- IPEN = 1 ( 讓 interrupt 有 priority 順序,位在 RCON )
- GIE / GIEH (在同一個 bit )。根據 IPEN 來決定代表哪種意思。
如果 IPEN = 0,一定要開啟 GIE ( global interrupt enable bit 位在 INTCON ),所有 interrupt 才可以跑。
如果 IPEN = 1,開啟來代表允許 high priority interrupt。
- PEIE / GIEL ( 在同一個bit )
如果 IPEN = 0 ( 控制外部裝置的interrupt,peripheral Interrupt Enable bit )
如果 IPEN = 1,開啟來代表允許 low priority interrupt。
Interrupt enable 圖
- 要用哪一個 interrupt,要把要用的 IE 設成 1 , IF 設成 0。 這張應該是 IPEN = 0 的圖。
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- INT2 <=> AN8
INT1 <=> AN10
INT0 <=> AN12
要把對應的 AN channel 設成 digital。
- ISR ( interrupt function ) 結束前要把 INTXIF 歸零。
Interrupt priority
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- INT0 沒有 IP。
- INT1IP , INT2IP 都位在 INTCON3,設 1 代表 high priority , 0 low priority。
interrupt triggered edge
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- INTEDGX 可以用來決定這個 interrupt 要用 rising edge 還是 falling edge。
- INTEDG 位在 INTCON2。
interrupt by PORTB
- RBIE = 1 代表允許 PORT B 去改變 interrupt ( RBIE 位在 INTCON bit 3 )。
- RBIP = 1 代表 RB PORT 改變 interrupt priority ( 位在 INTCON bit 0 )。
Accessing On-chip peripheral devices
peripheral device interrupt
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- ADIE = 1 允許 A/D 的 interrupt ( 在 PIE1 bit 6 )。
- ADIF 是 A / D converter 的 flag,即用完要記得歸零。 ( 在 PIR1 bit 6 )
- 因為是外部裝置,所以 PEIE 要設成 1 。
LCD 顯示器
- 從 p.86 ~ p.111 都是在講 LCD 顯示器,希望不會考我先跳過。
- 這邊應該也不會考 1/4 (剛剛去看紀錄檔)
Basics of Keyboard and Display Interface
水啦 老師說這邊不會考