1 / 18

嵌入式系統概論 Lab3

嵌入式系統概論 Lab3. 鍵盤掃描與七段顯示器. 實驗目的. 實作一個利用鍵盤掃描方式來取得 keyboard 上正確的位置 , 並顯示結果於 LED 上。 練習 GPIO 設定與使用以及鍵盤掃描. 4*4 鍵盤介面. 0000. Output. 110 1. 1111. Input. No kb press.

astrid
Download Presentation

嵌入式系統概論 Lab3

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 嵌入式系統概論Lab3 鍵盤掃描與七段顯示器

  2. 實驗目的 • 實作一個利用鍵盤掃描方式來取得keyboard上正確的位置,並顯示結果於LED上。 • 練習GPIO設定與使用以及鍵盤掃描

  3. 4*4鍵盤介面

  4. 0000 Output 110 1 1111 Input No kb press

  5. Time4 1 1 1 0掃描週期 Time3 1 1 0 1 Time2 1 0 1 1 Time1 0 1 1 1 GPG7 GPG6 GPG5 GPG4 0111 1011 1101 1110 Output 1101 1111 1111 Input No kb press

  6. LED電路圖

  7. 晶片接腳圖示 • 晶片原廠說明書p.6

  8. Port 設定 (p.229 晶片手冊) Port F Port G

  9. 暫存器初始設定 • Port F • #define rPCONF (*(volatile unsigned *)0x01D20034) • #define rPDATF (*(volatile unsigned *)0x01D20038) • #define rPUPF (*(volatile unsigned *)0x01D2003C) • Port G • #define rPCONG (*(volatile unsigned *)0x01D20040) • #define rPDATG (*(volatile unsigned *)0x01D20044) • #define rPUPG (*(volatile unsigned *)0x01D20048) Volatile: 因是Memory map I/O, 避免這些位址被Cache

  10. I/O Addressing (I/O定址) • Right ping connection and bus width setting • I/O memory location • control/status/data registers, FIFO/buffer • I/O address declaration • #define rPCONC (*(volatile unsigned *)0x01d20010) • Volatile • I/O memory location content could be changed automatically • Prevent compiler from allocating I/O memory in CPU register

  11. 控制暫存器的存取 • Bit-based accesses • One control register could include both Read/Write, Read-Only, Write-Only bits • Even the same bit could have different Read and Write meaning • Status bits is usually read-only • Read the data sheet carefully

  12. Control register is usually accessed in the unit of bit(s). • Set bit(s) • Bit 0: reg = reg | 0x01; • Bit in set_bits: reg = reg | set_bits; • Clear bit(s) • Bit 0: reg = reg & ( ~0x01 ); • Bit in clear_bits: reg = reg & (~clear_bits); • Note: ~0x01 v.s. 0xFE (or 0xFFFE, 0xFFFFFFFE)

  13. Shift operation • Be careful not to modify the bits which are unwanted to be affected • E.g., GPIO Data Port

  14. 暫存器初始化設定 • Port F 設定 (p.229) • rPCONF= rPCONF & 0x2F; • Port G 設定 (p.230) • rPCONG = rPCONG & 0xFF; • rPCONG = rPCONG | 0x5500;

  15. Port F 暫存器初始化設定

  16. Port G 暫存器初始化設定

More Related