# 微算機 Chaper3 Microcontroller Memory and I/O ###### tags: `microcontroller` ## Main Memory - 儲存instruction和data。對於8bit的微算機,memory也會被切成8-bit units,稱為memory words。 - PIC18F最多能有 $2^{21}bytes$ 的program memory。 - data memory address長度是12-bit。所以PIC18F最多能存 $2^{12}bytes$ ,ranging from 000 to FFF。 - PIC18F分割memory space into 16 contiguous banks of 256 byte。每個location可以以12 bits表示,可以是12-bit的address或者是8-bit low-order address加上4-bit Bank Pointer。 - Main memory分兩類: 1. Read-Only Memory(ROM) 2. Random-Access Memory(RAM) ### Read-Only Memory(ROM) - 使用CMOS技術去製造。 - 分以下幾個區塊: 1. **Mask ROMs**:裡面的內容完全無法被使用者更動。 2. **EPROMs**:可以被編程,能使用特殊的工具去修改裡面的東西。 3. **EEPROMs**:可以不把 ROM 拔掉就修改裡面的東西,也被稱為 read-mostly memories ( RMMs )。 4. **Flash Memory**:以EPROM和E2PROM的技術去設計,與EPROMs不一樣是,可以在板子上去改裡面的內容。<font color = "#F00"> PIC18F 用這個當 program memory </font>。 ### Random-Access Memory - 分兩類: 1. **static RAM(SRAM)**: - 用flip-flops去儲存資料。 - <font color = "#F00"> PIC18F 用這個去當 data memory </font>。 2. **dynamic RAM(DRAM)** - 用電容器去儲存資料。 - 在RAM中,儲存單元密度:DRAM > SRAM。 --- ## Timing Diagrams ### READ diagrams - CPU 執行 instruction fetch 去讀取 op-code。 - CPU 把 op-code 轉換成讀取記憶體的操作。 - 當 clock 在 HIGH pin 時拿到 address 。 - 把 READ pin 也調高成 HIGH。 - MAR 把 RAM , ROM 的資料放到 data bus 然後 CPU 在把資料從data bus 的 pin D0~7 讀取。 -  - ( 待確認補充 ch3 p.22 ) ### write diagrams - 一樣先抓取 op-code - 把 op-code 轉換成 WRITE 指令,然後執行DATA STORE cycle。 - 一樣 clock 在 HIGH pin時拿到資料 ( 從A0~15 )。 - 同時CPU把 WRITE pin 也調到 HIGH。 - 把資料放到 pin D0~7。 - 然後從暫存器存到RAM。 -  ### Instruction fetch(IF) - 抓取指令的操作,會根據時脈,一高一低過一個周期之後,把新的指令放到PC。 --- ## Microcontroller Input/Output(I/O) - microcontroller和I/O有兩種傳遞資料的方式: 1. **programmed I/O**:由CPU執行的program發起要使用外部裝置。 2. **interrupt I/O**:由外部裝置強制CPU暫停手上的作業,然後去滿足外部裝置的需求。 ### Programmed I/O - microcontroller和external device藉由一或多個registers called **I/O ports**,每一個port可以被 **Data Direction Register(DDR)** 這個register去分配是input or output port。 - PIC18F在I/O port上,若對應DDR的bit為 1 則是 input;若對應bit為 0 則是 output。 - 當這個bit被分到output port但接收到input,此bit會被視為don't care項。 - I/O port are addressed using these two: 1. **standard I/O(port I/O)**:執行IN,OUT instruction時會讓 $M/\overline{IO}$ 為 **LOW**,而執行memory operation時 ( 例如 move ) $M/\overline{IO}$ 為 **HIGH**。 2. **memory-mapped I/O**:CPU使用一部分的memory addresses去表示I/O ports來操作並產生必要的control signals去執行I/O。<font color = "#F00">PIC18F用這種</font>。 :::danger standard I/O和memory-mapped I/O我不是很確定喔 ::: - 有兩種方式可以使用I/O: 1. **unconditional I/O**:microcontroller可以在任何時間去使用external device。 2. **conditional I/O**:microcontroller必須要等特定的時間狀況發生,才能output data到external device。也被稱為**Polled I/O**。 - 若不想依照condition,當然也可以使用**Interrupt I/O**: - 因為如果一直在等condition的迴圈裡面跑會占用CPU資源。 - 如果要使用interrupt I/O,external device會連接到一個pin叫**interrupt pin (INT)**。 - 當CPU被interrupt時,會儲存現在的program counter和status register進入stack。 - 當最後interrupt service routine 回傳時,會把之前存的東西用回來繼續執行。 - interrupt也有分兩種: 1. **external interrupt**:由external device觸發,又分為兩種: 1. **maskable**:可以被instruction去控制要不要被interrupt。 2. **nonmaskable**:擁有比maskable更高的權限,不被instruction影響。多被用於發生電源問題時所執行的interrupt。PIC18F沒有這個東西。 2. **internal interrupt**:都是maskable的,可以被instruction禁止。由內部condition所觸發。 - **Interrupt Address Vector**:用來找到starting address of the service routine(常為interrupt address vector) ( vector 裡面每格存此 interrupt 要如何處理的函式位置 ) - **Saving the Microcontroller Registers**:當interrupt發生時,把program counter(PC)和status register(SR)的內容丟入stack裡的地方。
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up