13.07.2015 Views

Microchip 16 Microchip 16-bit MCU 內建周邊模組Parallel Master Port

Microchip 16 Microchip 16-bit MCU 內建周邊模組Parallel Master Port

Microchip 16 Microchip 16-bit MCU 內建周邊模組Parallel Master Port

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Microchip</strong> <strong>16</strong>-<strong>bit</strong> <strong>MCU</strong>內 建 周 邊 模 組Parallel <strong>Master</strong><strong>Port</strong>(PMP)© 2006 <strong>Microchip</strong> Technology Incorporated. All Rights Reserved. Slide 1


Parallel <strong>Master</strong> <strong>Port</strong> – PMPRead, Write, EnableLCD DisplayPIC24J128GA010Up to 2 Chip SelectUp to <strong>16</strong>-<strong>bit</strong> AddressParallelPeripherals8- or <strong>16</strong>-<strong>bit</strong> DATA© 2006 <strong>Microchip</strong> Technology Incorporated. All Rights Reserved. 204 ADV Slide 2


Example : LCD Write TimingWrite is active low.But remember! PMP signal we are using is PMRD/PMWR,so the pin needs to be configured as active high.Enable is active High.© 2006 <strong>Microchip</strong> Technology Incorporated. All Rights Reserved. 204 ADV Slide 3


Example : LCD Read Timing© 2006 <strong>Microchip</strong> Technology Incorporated. All Rights Reserved. 204 ADV Slide 4


PMP Configuration:Control SignalsPICPMBEPMRD orPMRD/PMWRPMWR orPMENBUp to 2 PMCSThe Signal can be individuallyEnabled or DisabledPMCON: PTBEEN, PTWREN,PTRDEN PMPEN: CS2, CS1The Signal polarity can beindividually selectedPMCON: ALP, CS2P, CS1P,BEP, WRSP, RDSPPMMODEUp to <strong>16</strong>-<strong>bit</strong>The Address pins can beAddressindividually Enabled or DisabledPMAEN: Reg8-<strong>bit</strong> DataPMCONChip SelectFunction00 CS1, CS2, A15, A1401 CS1, CS2, A15, A1410 CS1, CS2, A15, A14© 2006 <strong>Microchip</strong> Technology Incorporated. All Rights Reserved. 204 ADV Slide 5


PMP Configuration:Multiplexed Data BusPMBEPIC(100-pin)PMRD or PMRD/PMWRPMWR or PMENBPMCS1 & PMCS2PMALLUp to 8-<strong>bit</strong> Address High8-<strong>bit</strong> Address Low/8-<strong>bit</strong> DataPMCON = 01© 2006 <strong>Microchip</strong> Technology Incorporated. All Rights Reserved. 204 ADV Slide 6


PMP Configuration:Multiplexed Data BusPMBEPIC(100-pin)PMRD or PMRD/PMWRPMWR or PMENBPMCS1 & PMCS2PMMODE MODE<strong>16</strong>PMALLPMALHPMCON = 108-<strong>bit</strong> Address Low/8-<strong>bit</strong> Address High/8/<strong>16</strong>-<strong>bit</strong> Data© 2006 <strong>Microchip</strong> Technology Incorporated. All Rights Reserved. 204 ADV Slide 7


PMP Configuration:Standard PeripheralsPIC(100-pin)PMBEPMRD/PMWRPMWRPMENBUp to 2 PMCSParallelPeripheralsLCD DisplayUp to <strong>16</strong>-<strong>bit</strong> addressPMADDR8/<strong>16</strong>-<strong>bit</strong> DataPMDIN2:PMDIN1PMDIN1PMMODEPMMODE MODE1 MODE0> = 1011PMMODEPMMODE© 2006 <strong>Microchip</strong> Technology Incorporated. All Rights Reserved. 204 ADV Slide 8


PMP 對 低 速 周 邊 的 時 序 調 整● PMMODE Register© 2006 <strong>Microchip</strong> Technology Incorporated. All Rights Reserved. 204 ADV Slide 9


PMP 時 序 範 例© 2006 <strong>Microchip</strong> Technology Incorporated. All Rights Reserved. 204 ADV Slide 10


PMP Configuration:Slave ModePIC(100-pin)PMRDPMWRPMDIN2:PMDIN1PMDOUT2:PMDOUT1PMMODE = 11FourLevelBufferPMCSPMA0PMA18/<strong>16</strong>-<strong>bit</strong> DataPMMODE = 01 00© 2006 <strong>Microchip</strong> Technology Incorporated. All Rights Reserved. 204 ADV Slide 11


Legacy PSP Mode●●與 傳 統 的 <strong>16</strong> & 18 系 列 相 容只 有 一 層 Buffer● 設 定 方 式 PMMODE = 00© 2006 <strong>Microchip</strong> Technology Incorporated. All Rights Reserved. 204 ADV Slide 12


Buffered PSP Mode●●●與 傳 統 <strong>16</strong> & 18 系 列 的 PSP 大 至 相 同Read/Write Buffer 為 四 層設 定 方 式− PMMODE = 00 & PMMODE = 11© 2006 <strong>Microchip</strong> Technology Incorporated. All Rights Reserved. 204 ADV Slide 13


Addressed Buffer Mode●使 用 PMA0 & PMA1 來 指 向 四 個 Buffer 的 其 中 一 個● 設 定 方 式 PMMODE = 01© 2006 <strong>Microchip</strong> Technology Incorporated. All Rights Reserved. 204 ADV Slide 14


Let’s go Hands on&Case Study first !!© 2006 <strong>Microchip</strong> Technology Incorporated. All Rights Reserved. Slide 15


練 習 一使 用 PMP 來 控 制 LCD● 使 用 範 本 程 式 來 開 始 程 式 的 開 發− C30_Template.c● 使 用 PIC24FJ128GA006 的 PMP− 完 成 LCD 的 初 始 化− 完 成 要 求 的 lcd.c 各 個 副 程 式− 將 自 己 的 英 文 姓 名 寫 至 LCD© 2006 <strong>Microchip</strong> Technology Incorporated. All Rights Reserved. 204 ADV Slide <strong>16</strong>


LCD Module 的 接 腳LMC-SSC2A<strong>16</strong>© 2006 <strong>Microchip</strong> Technology Incorporated. All Rights Reserved. 204 ADV Slide 17


LCD W/R Timing© 2006 <strong>Microchip</strong> Technology Incorporated. All Rights Reserved. 204 ADV Slide 18


LCD Commands [1]© 2006 <strong>Microchip</strong> Technology Incorporated. All Rights Reserved. 204 ADV Slide 19


LCD Commands [2]© 2006 <strong>Microchip</strong> Technology Incorporated. All Rights Reserved. 204 ADV Slide 20


LCD 命 令 的 確 認● 雖 然 LCD 的 每 一 command 都 有 確 定 的 執 行 時 間 ,但 檢 查 Busy Flag 是 較 有 效 率 的 方 法 ? Why ?© 2006 <strong>Microchip</strong> Technology Incorporated. All Rights Reserved. 204 ADV Slide 21


LCD 與 PMP 的 可 用 連 接 方 式PIC24J128GA010Parallel<strong>Master</strong><strong>Port</strong>PMRD/PMWRPMENBPMA0PMDR/WERSDB7 – DB0LCD© 2006 <strong>Microchip</strong> Technology Incorporated. All Rights Reserved. 204 ADV Slide 22


以 PMP 連 接 LCD 時 信 號 的 考 量● Setup PMP for an LCD, thinkabout:− Signals – 所 需 信 號− Polarity – 各 信 號 Ati Active 的 極 性− LCD interface– 使 用 的 界 面 型 式− Addressing – 如 何 對 LCD 定 址− Timing – 時 序 的 相 容 性© 2006 <strong>Microchip</strong> Technology Incorporated. All Rights Reserved. 204 ADV Slide 23


LCD 操 作 於 8-<strong>bit</strong> 模 式 的 初 始 流 程© 2006 <strong>Microchip</strong> Technology Incorporated. All Rights Reserved. 204 ADV Slide 24


Declaration in C30●Declare the array with initial values− Examples :− const unsigned char my_name[] = "CalvinHo"; o;●宣 告 一 個 存 於 Program Memory 的 字 串my_name , 內 容 為 : 你 的 英 文 姓 名− const unsigned char * ptrname;●宣 告 一 指 標 來 操 作 字 串© 2006 <strong>Microchip</strong> Technology Incorporated. All Rights Reserved. 204 ADV Slide 25


PMP Data Write & Read●●●決 定 要 寫 入 的 位 址− PMPADDR = ????將 資 料 寫 入 PMPIN1 – 將 資 料 輸 出− PMPIN1 = ????由 PMP data bus 讀 取 資 料− Var1 = PMPIN1● Wait State ?− PIC24 的 執 行 速 度 與 LCD 的 Timing 是 否須 Wait State 配 合 ?© 2006 <strong>Microchip</strong> Technology Incorporated. All Rights Reserved. 204 ADV Slide 26


APP026-3 的 硬 體 接 法●●參 考 24FJ128FA006 的 接 腳 圖 , 將 LCD 信 號 接 至 正 確 腳 位新 版 本 (V4.0) 的 LCD 已 經 由 CON4 的 11 個 Jumper 接 至CPU 的 PMP <strong>Port</strong>© 2006 <strong>Microchip</strong> Technology Incorporated. All Rights Reserved. 204 ADV Slide 27


PIC24FJ128GA006 腳 位 圖© 2006 <strong>Microchip</strong> Technology Incorporated. All Rights Reserved. 204 ADV Slide 28


硬 體 連 接 之 注 意 事 項● LCD Module 的 注 意 事 項− LCD Module 的 VDD 接 到 5V− LCD Module 的 VO ( Pin 3 ) 接 至 電阻 R2 & R3 構 成 的 分 壓− LCD Module 的 RS , RW , E 腳 分 別接 至 CPU 的 PMA0 , PMRD ,PMWR/PMENB© 2006 <strong>Microchip</strong> Technology Incorporated. All Rights Reserved. 204 ADV Slide 29


●●●Step by Step to finish PMPExercise !!Write code to initial PMP− In PMP_main.cWrite code to initial LCD− In lcd.c請 做 另 一 標 頭 檔 lcd.h , 放 置 下 一 頁 中 各LCD 相 關 副 程 式 的 原 型 宣 告● LCD Operation Mode :●2 lins , 8-<strong>bit</strong> bus , 5X7 character© 2006 <strong>Microchip</strong> Technology Incorporated. All Rights Reserved. 204 ADV Slide 30


必 備 的 LCD Functions (lcd.c)●●void LCD_Initial()−將 LCD 規 劃 於 指 定 模 式int LCD_IsBusy()−讀 取 LCD 的 BUSY Flag 並 傳 回 狀 態●1 = Busy 0 = Not Busy● void LCD_PutChar( char )−將 傳 入 的 指 定 字 元 輸 出 至 LCD● Void LCD_SerCursor( char X , char Y )−將 LCD 的 游 標 重 新 設 定 於 (X,Y)© 2006 <strong>Microchip</strong> Technology Incorporated. All Rights Reserved. 204 ADV Slide 31


必 備 的 LCD Functions (lcd.c)●●●putsLCD( *string)− 將 至 於 data memory 的 字 串 由 LCD 印 出putrsLCD(*string)− 將 至 於 const data memory 的 字 串 由 LCD 印 出你 可 能 須 要 其 它 的 functions 來 輔 助 以 上 功 能 , 這些 function 可 自 行 命 名© 2006 <strong>Microchip</strong> Technology Incorporated. All Rights Reserved. 204 ADV Slide 32


LCD_IsBusy() 的 參 考 寫 法int LCD_IsBusy(void){int BusyLoop ;int LCDStatus ;for (BusyLoop = 0 ; BusyLoop < FCY*4 ; BusyLoop++) ;// FCY 為 LCD.C 中 定 義 的 參 數 !!PMADDR = 0x0000;LCDStatus = PMDIN1;for (BusyLoop = 0 ; BusyLoop < FCY*4 ; BusyLoop++) ;}return ((LCDStatus>>7) & 0x0001) ;© 2006 <strong>Microchip</strong> Technology Incorporated. All Rights Reserved. 204 ADV Slide 33


D2A_main.c 的 重 點●●●●●宣 告 儲 存 姓 名 的 字 串− MyName[]=“Your Name” ;− 可 放 置 於 Program or Data Memory !完 成 PMP_Initial() 做 為 規 劃 PMP Module 的 副 程式在 main() 中 呼 叫 PMP_Initial() 初 始 PMP Module在 main() 起 始 時 呼 叫 LCD_Initial() 來 對 LCD 做 初始 化在 main() 中 呼 叫 lcd.c 中 的 副 程 式 來 顯 示 字 串−−−−−LCD_PutChar()LCD_IsBusy()LCD_SetCursor()putsLCD()putrsLCD()© 2006 <strong>Microchip</strong> Technology Incorporated. All Rights Reserved. 204 ADV Slide 34


main() 的 參 考 寫 法 (1)int main(void){const unsigned char *pName; // 宣 告 與 MyName型 別 相 等 的 指 標……..}pName = MyName ; // 指 標 對 應while (*pName != 0x00){if ( ! LCD_IsBusy())LCD_PutChar(*pName++) ;}while(1) ; // Wait here !!© 2006 <strong>Microchip</strong> Technology Incorporated. All Rights Reserved. 204 ADV Slide 35


main() 的 參 考 寫 法 (2)int main(void){const unsigned char *pName; // 宣 告 與 MyName型 別 相 等 的 指 標……..// 直 接 使 用 putrsLCD () 將 字 串 直 接 印 出putrsLCD(MyName) ;}while(1) ; // Wait here !!© 2006 <strong>Microchip</strong> Technology Incorporated. All Rights Reserved. 204 ADV Slide 36


Clock Exercise●●●練 習 使 用 C30 Library 來 規 劃 Timer1練 習 使 用 較 小 時 間 的 Timer 計 時 來 做 成較 長 時 間 的 Timer− 此 練 習 要 求 使 用 10 ms 的 Timer 中 斷 配 合累 積 用 的 變 數 來 做 成 1 Second 的 計 時− 加 入 CPU 的 Fosc 被 設 定 為 8MhMhz使 用 已 完 成 的 範 例 專 案 Clock_Exercise© 2006 <strong>Microchip</strong> Technology Incorporated. All Rights Reserved. 204 ADV Slide 37


Clock Exercise● Step-1 : 完 成 在 Timer1_Initial 中 的 ToDo 1− Timer1 將 於 每 10 ms 中 斷 CPU 一 次void Timer1_Initial(void){// ToDo 1// 使 用 C30 Library 的 Timer 函 式 來 規 劃 Timer1 每 10 ms 中 斷 一 次// 使 用 OpenTimer1() & ConfigIntTimer1()// To make a 10 ms Timer @ Fosc = 8 Mhz -> Fcy = 4Mhz// Select 1:8 prescaler , Freq to Timer1 = 500 K -> >2us// 10ms = 10000 us , 10000 us / 2 us = 5000// So, PR1 = 4999 for a 10 ms Timer// OpenTimer1(); // 去 掉 此 行 註 解 將 OpenTimer1() 的 參 數 補 齊}// ConfigIntTimer1() ; // 去 掉 此 行 註 解 將 ConfigIntTimer1() 的 參 數 補 齊© 2006 <strong>Microchip</strong> Technology Incorporated. All Rights Reserved. 204 ADV Slide 38


Clock Exercise● Timer1 的 中 斷 服 務 程 式 內 容void _ISR _T1Interrupt(void){IFS0<strong>bit</strong>s.T1IF = 0 ;}Timer1Tick = 1 ;● 中 斷 旗 號 要 軟 體 清 除● 在 中 斷 中 僅 設 定 一 個 旗 標 變 數− Timer1Tick© 2006 <strong>Microchip</strong> Technology Incorporated. All Rights Reserved. 204 ADV Slide 39


Clock Exercise● Step-2 : 完 成 在 main() 中 的 ToDo 2while(1){// ToDo 2// 檢 查 TimerTick 是 否 為 1 , 若 是 則 10 ms 已 到// 累 積 10ms 的 事 件 至 Timer1Count 變 數 , 若 到 達 100 次 則 為 1 秒// 1 second 到 了 就 update Sec 及 Min 兩 個 變 數// 呼 叫 Update_Time() 將 MM:SS 印 出Update_Time() ;●}請 利 用 中 斷 服 務 程 式 設 定 的 TimerTick 旗 標 變 數 來組 合 成 1 Second 的 計 時 並 update Sec 及 Min 兩變 數© 2006 <strong>Microchip</strong> Technology Incorporated. All Rights Reserved. 204 ADV Slide 40


LCD on the PMP● Goals− Learn about the Parallel <strong>Master</strong> <strong>Port</strong>(PMP)− Refresh knowledge of the common LCDinterface− Do some coding for PIC24© 2006 <strong>Microchip</strong> Technology Incorporated. All Rights Reserved. 204 ADV Slide 41

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!