180 likes | 420 Views
嵌入式系統概論 Lab3. 鍵盤掃描與七段顯示器. 實驗目的. 實作一個利用鍵盤掃描方式來取得 keyboard 上正確的位置 , 並顯示結果於 LED 上。 練習 GPIO 設定與使用以及鍵盤掃描. 4*4 鍵盤介面. 0000. Output. 110 1. 1111. Input. No kb press.
E N D
嵌入式系統概論Lab3 鍵盤掃描與七段顯示器
實驗目的 • 實作一個利用鍵盤掃描方式來取得keyboard上正確的位置,並顯示結果於LED上。 • 練習GPIO設定與使用以及鍵盤掃描
0000 Output 110 1 1111 Input No kb press
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
晶片接腳圖示 • 晶片原廠說明書p.6
Port 設定 (p.229 晶片手冊) Port F Port G
暫存器初始設定 • 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
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
控制暫存器的存取 • 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
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)
Shift operation • Be careful not to modify the bits which are unwanted to be affected • E.g., GPIO Data Port
暫存器初始化設定 • Port F 設定 (p.229) • rPCONF= rPCONF & 0x2F; • Port G 設定 (p.230) • rPCONG = rPCONG & 0xFF; • rPCONG = rPCONG | 0x5500;