Microsoft PowerPoint - 1_PIC18F4550簡介與實作 [相容模式]

Similar documents
ICD ICD ICD ICD ICD

ARM Cortex-M3 (STM32F) STMicroelectronics ( ST) STM32F103 Core: ARM 32-bit Cortex -M3 CPU 72 MHz, 90 DMIPS with 1.25 DMIPS/MHz Single-cycle multiplica

USB解决方案.ppt

untitled

2 PIC PIC 1 / CPU PIC MCU PIC RC

FM1935X智能非接触读写器芯片

Cube20S small, speedy, safe Eextremely modular Up to 64 modules per bus node Quick reaction time: up to 20 µs Cube20S A new Member of the Cube Family

PROTEUS VSM

1-1 SH79F6431 A. 2( ) 9~15V ( 12V) U2 U3 3.3V SH79F B. 1(VCC/GND) SH79F6431 C. VDDIO SH79F6431 P4 P5 P0.6 P0.7 VDDIO VDDIO=5V D. 2 V 1.0

邏輯分析儀的概念與原理-展示版

(Load Project) (Save Project) (OffLine Mode) (Help) Intel Hex Motor

PIC16F F MPLAB 08 16F LED 15 LED

Chroma 61500/ bit / RMS RMS VA ()61500 DSP THD /61508/61507/61609/61608/ (61500 ) Chroma STEP PULSE : LISTLIST 100 AC DC

目录

SPHE8202R Design Guide Important Notice SUNPLUS TECHNOLOGY CO. reserves the right to change this documentation without prior notice. Information provi

2 Keil µ vision 2.1 1) Keil µ vision2 V2.34 µ vision3 2) Sino_Keil.exe Keil c:\keil\ 3) JET51 USB PC C:\Keil\ USB PC 4) S-L

33023A.book(31001A_cn.fm)


投影片 1

P4V88+_BIOS_CN.p65

51 C 51 isp 10 C PCB C C C C KEIL

JLX

Tel:

P4VM800_BIOS_CN.p65

MODEL 62000H SERIES 5KW / 10KW / 15KW 0 ~ 375A 0 ~ 1000V/2000V( ) : 200/220Vac, 380/400Vac, 440/480Vac 3U/15KW / & 150KW / ( 10 ms ~ 99 hours)

Bus Hound 5

ATMEL AT90S8515 AVR CPU AVR AVR AVR ATMEL RISC 32 8 r0 r X Y Z R0 R1 R2 R13 R14 R15 R16 R17 R26 R27 R28 R29 R30 R31 0x00 0x

User ID 150 Password - User ID 150 Password Mon- Cam-- Invalid Terminal Mode No User Terminal Mode No User Mon- Cam-- 2

AN INTRODUCTION TO PHYSICAL COMPUTING USING ARDUINO, GRASSHOPPER, AND FIREFLY (CHINESE EDITION ) INTERACTIVE PROTOTYPING

Microsoft PowerPoint - ATF2015.ppt [相容模式]

12232A LED LED LED EL EL CCFL EL CCF

untitled

逢 甲 大 學

1.1 ML_ONOFF = 1 Q 3 Q 8 C 0.3V M 2 L 1 ML_ONOFF = 0 Q 3 Q 8 C 1. + R31 VCC R21 10K ML_ONOFF R15 0:off 1:on 1K Green Light VCC=5V L1 Q VDD=12V C

行业

Section1_16bit Arc.ppt

1 TPIS TPIS 2 2

audiogram3 Owners Manual

1 Project New Project 1 2 Windows 1 3 N C test Windows uv2 KEIL uvision2 1 2 New Project Ateml AT89C AT89C51 3 KEIL Demo C C File

1 CPU

Microsoft Word - MSP430 Launchpad 指导书.docx

行业

untitled

MCU DSP MSO MCU DSP MSO MSO MSO MCU/DSP I/O MSO 16 Microchip IC18 turn-on MSO chirp MCU I/O I 2 C

untitled

!!

STM32 for sensorless vector control

Pin Configurations Figure2. Pin Configuration of FS2012 (Top View) Table 1 Pin Description Pin Number Pin Name Description 1 GND 2 FB 3 SW Ground Pin.

INCF SEC1,F ; 將 SEC1+1 作查表取回對應數字 MOVF SEC1,W banksel STRING1 banksel PORTB RETFIE run_sec2: MOVF SEC2,W SUBLW.5 GOTO run_min ; 將秒個位數歸 0 CLRF SEC1 MOVL

(02) (02) (02) (02) (02

第10章:CCP捕捉/比较/脉宽调制

untitled

BC04 Module_antenna__ doc

目 录

iml v C / 4W Down-Light EVM - pplication Notes. IC Description The iml8683 is a Three Terminal Current Controller (TTCC) for regulating the cur

68369 (ppp quickstart guide)

iml v C / 0W EVM - pplication Notes. IC Description The iml8683 is a Three Terminal Current Controller (TTCC) for regulating the current flowin

T stg -40 to 125 C V cc 3.8V V dc RH 0 to 100 %RH T a -40 to +125 C -0.3 to 3.6V V -0.3 to VDD+0.3 V -10 to +10 ma = 25 = 3V) VDD

52C

KT-SOPCx开发套件简明教程

行业

Ác Åé å Serial ATA ( Sil3132) S A T A (1) SATA (2) BIOS SATA (3)* RAID BIOS RAID (4) SATA (5) SATA (a) S A T A ( S A T A R A I D ) (b) (c) Windows XP

General Description: Preliminary TTP916 Consumer IC VCD/DVD LCD Green mode Stand-by mode( 1W ) Features: 2.2V-5.5V LCD RAM read condition 2.6V-5.5V RC

Microsoft Word - LR1122B-B.doc

行业

专业主干课程与主要专业课程教学大纲(2009年、2011年).doc

2/80 2

2 14 PORTC.1 PORTB.3 PORTA.2/T0 GND PORTB.2 PORTA.0 PORTC.3 PORB.0/OSCO PORTB.1/OSCI PORTC.0 PORTC.2 SH69P21 /SOP PORTA

1.ai

iml88-0v C / 8W T Tube EVM - pplication Notes. IC Description The iml88 is a Three Terminal Current Controller (TTCC) for regulating the current flowi

热设计网

STK2139 Datasheet

untitled

行业

ARM JTAG实时仿真器安装使用指南

r_09hr_practical_guide_kor.pdf

SST SPAC SST SoftICE SST89C5x/SST89x554RC /564RD /SST89x516/5xRD / SoftICE SoftICE MCU SoftICE SS

P3V4X JumperFree TM

Outline USB Application Requirements Variable Definition Communications Code for VB Code for Keil C Practice

untitled

Microsoft Word - ISSFA-0109_B_SM59264_WDT_ APN_TC_.doc

bingdian001.com

P3B-F Pentium III/II/Celeron TM

Microsoft PowerPoint - CA_03 Chapter5 Part-II_multi _V1.ppt

untitled

使用手冊

時脈樹設計原則

Microsoft Word - LD5515_5V1.5A-DB-01 Demo Board Manual

untitled

大学计算机基础B.doc

System Design and Setup of a Robot to Pass over Steps Abstract In the research, one special type of robots that can pass over steps is designed and se

<4D F736F F D FB971BEF7BB50B971A46CB8735FB773A55FA5ABA5DFB7E7AADAB0AAAFC5A475B77EC2BEB77EBEC7AED55FA97EAE61C0F4B9D2B4BCBC7AB1B1A8EEA874B2CE2E646F63>

IP TCP/IP PC OS µclinux MPEG4 Blackfin DSP MPEG4 IP UDP Winsock I/O DirectShow Filter DirectShow MPEG4 µclinux TCP/IP IP COM, DirectShow I

<4D F736F F D20B5E7D7D3D0C5CFA2C0E0D7A8D2B5C5E0D1F8B7BDB0B8D0DEB6C1D6B8C4CF2E646F63>

Microsoft PowerPoint - STU_EC_Ch08.ppt

CC213

AL-M200 Series

Transcription:

PIC18F4520/50 單晶片實務研習 使用僑高公司 S-500 實驗器 講師 : 杜勇進 1 研習大綱 壹 PIC18F4520/50 單晶片實務實驗 貳 103 年電腦硬體裝修乙級檢定講解與實作參 102 年工科技藝競賽電腦修護題目講解與實作肆 Arduino 簡介與實作 2 1

單元壹 : 大綱 PIC18F4520/4550 簡介 環境建置 基礎實驗 PIC 中斷架構 PIC 計時器架構 ADC 架構 繪圖型 LCD VB6 與 4550 溝通與實作 UART 3 CH-S500 (89S51/52 & PIC18F4520/50) CHIRKAL4 2

4550 VS 4520 CHIRKAL5 PIC18F4520 主要特性 1/2 Flash Memory : 32K Bytes (10 萬次的重寫次數 ) Data RAM : 1536 Bytes EEPROM : 256 Bytes (100 萬次重寫能耐 ) Timer : 4 組 CCP Module : x 1 Enhanced CCP : x 1 串列通訊 : EUSART,IIC (I2C),SPI 電壓比較器 : x 2 AD 轉換器 : 10-bit / 13CH Reset : POR,BOR,WDT,MCLR,Stack,Reset 指令 I/O : 最多 36 6 3

PIC18F4520 主要特性 2/2 振盪模式 HS XT LP HSPLL EC 及 External RC 內建 RC 震盪 31KHz ~ 8MHz ( 具 8 種頻率選擇 ) 可使用 x4 PLL Clock Failure Monitoring Extended WDT : 4ms ~131Sec. Programmable BOR (Software Enable) Power Done Mode Run Idle Sleep Mode 7 28/40/44-Pin, PIC18F4550 主要特性 High-Performance, Enhanced Flash, USB Microcontrollers with nanowatt Technology 8 4

Universal Serial Bus Features USB V2.0 Compliant Low Speed (1.5 Mb/s) and Full Speed (12 Mb/s) Supports Control, Interrupt, Isochronous( 同步 ) and Bulk( 大批 ) Transfers Supports up to 32 Endpoints (16 bidirectional) 1-Kbyte Dual Access RAM for USB On-Chip USB Transceiver with On-Chip Voltage Regulator Interface for Off-Chip USB Transceiver Streaming Parallel Port (SPP) for USB streaming transfers (40/44-pin devices only):: 9 Power-Managed Modes Run: CPU on, peripherals on Idle : CPU off, peripherals on Sleep : CPU off, peripherals off Idle mode currents down to 5.8 μa typical Sleep mode currents down to 0.1 μa typical Timer1 Oscillator : 1.1 μa typical, 32 khz, 2V Watchdog Timer : 2.1 μa typical Two-Speed Oscillator Start-up 10 5

Flexible Oscillator Structure Four Crystal modes, including High Precision PLL for USB Two External Clock modes, up to 48 MHz Internal Oscillator Block: - 8 user-selectable frequencies, from 31 khz to 8 MHz - User-tunable to compensate for frequency drift Secondary Oscillator using Timer1 @ 32 khz Dual Oscillator options allow microcontroller and USB module to run at different clock speeds Fail-Safe Clock Monitor: - Allows for safe shutdown if any clock stops 11 Peripheral Highlights1/2 High-Current Sink/Source: 25 ma/25 ma Three External Interrupts Four Timer modules (Timer0 to Timer3) Up to 2 Capture/Compare/PWM (CCP) modules: - Capture is 16-bit, max. resolution 5.2 ns (TCY/16) - Compare is 16-bit, max. resolution 83.3 ns (TCY) - PWM output: PWM resolution is 1 to 10-bit Enhanced Capture/Compare/PWM p (ECCP) module: - Multiple output modes - Selectable polarity - Programmable dead time - Auto-shutdown and auto-restart 12 6

Peripheral Highlights2/2 Enhanced USART module: - LIN bus support Master Synchronous Serial Port (MSSP) module supporting 3-wire SPI (all 4 modes) and I2C Master and Slave modes 10-bit, up to 13-channel Analog-to-Digital Converter module (A/D) with Programmable Acquisition Time Dual Analog Comparators with Input Multiplexing 13 Special Microcontroller Features1/2 C Compiler Optimized Architecture with optional Extended Instruction Set 100,000 Erase/Write Cycle Enhanced Flash Program Memory typical 1,000,000 Erase/Write Cycle Data EEPROM Memory typical Flash/Data EEPROM Retention: ti > 40 years Self-Programmable under Software Control Priority Levels for Interrupts 14 7

Special Microcontroller Features2/2 8 x 8 Single-Cycle Hardware Multiplier Extended Watchdog Timer (WDT): - Programmable period from 41 ms to 131s Programmable Code Protection Single-Supply 5V In-Circuit Serial Programming (ICSP) via two pins In-Circuit Debug (ICD) via two pins Optional dedicated ICD/ICSP port (44-pin devices only) Wide Operating Voltage Range (2.0V to 5.5V) 15 相關系列差別 CHIRKAL16 8

PIC18F4550 架構圖 ( 一 ) CHIRKAL17 PIC18F4550 架構圖 ( 二 ) CHIRKAL 18 9

接腳圖 PA: 0 ~ 6 PB: 0 ~ 7 PC: 0 ~ 6 PD: 0 ~ 7 PE: 0 ~ 3 32+4=36 IO 腳 Vdd 2, Vss 2 CHIRKAL19 4550 VS 4520 CHIRKAL20 10

PIC18F4520 程式位置配置 CHIRKAL 21 IO Port 規劃 建議使用 LATx 暫存器進行位元運算的操作 CHIRKAL 22 11

為何要加入 LATx 的暫存器 消除 Read-Modify-Write 動作的風險 23 Oscillator Types CHIRKAL24 12

大綱 PIC18F4520/4550 簡介 環境建置 基礎實驗 PIC 中斷架構 PIC 計時器架構 ADC 架構 繪圖型 LCD VB6 與 4550 溝通與實作 UART 25 軟體 MPLAB_IDE_8_92 環境建置 mplabc18-v3.46-windows-lite-installer.exe 硬體 PICkit2( 燒錄 ) PICkit3 ICD2( 除錯 單步執行 ) ICD3 26 13

CH-S500 (89S51/52 & PIC18F4520/50) CHIRKAL 27 建專案 : 選元件 上機步驟 28 14

選 C18 編譯器 CHIRKAL 29 選擇專案位置及專案名稱 假設目錄為 MyPIC\Lab1, 專案名稱 Hello 30 15

編輯原始程式 CHIRKAL31 建置 (Build) CHIRKAL 32 16

設定燒錄器 1/2 33 設定燒錄器 2/2 CHIRKAL34 17

燒錄與執行 拿一條 8 Pin 排線,RD(Port D) 接至 LED 35 OSCCON: OSCILLATOR CONTROL REGISTER CHIRKAL36 18

ADCON1: A/D CONTROL REGISTER 1 CHIRKAL37 大綱 PIC18F4520/4550 簡介 環境建置 基礎實驗 PIC18F 中斷架構 PIC18F 計時器架構 ADC 架構 繪圖型 LCD VB6 與 4550 溝通與實作 UART 38 19

基礎實驗 Lab1 :LED 閃爍 Lab2 : 按鍵控制 LED 花樣變化 Lab3 : 七段顯示器 Lab4 : 文字型 LCD Lab5 :LCD + 鍵盤 Lab6 :8*8 點矩陣 Lab7 : 步進馬達 39 組態位元 CHIRKAL 40 20

大綱 PIC18F4520/4550 簡介 環境建置 基礎實驗 PIC18F 中斷架構 PIC18F 計時器架構 ADC 架構 繪圖型 LCD VB6 與 4550 溝通與實作 UART 41 PIC18F 中斷架構 18F4520/50 有兩個中斷向量點 高優先權 ==> 中斷向量位址 0x0008 低優先權 ==> 中斷向量位址 0x0018 每個中斷源均可選擇其中斷優先權 ( 二選一 ) 每個中斷源均有獨立的中斷旗標 (Flag) 中斷旗標的清除 ==> 自行用軟體清除 每個中斷源均可 Enable 或 Disable 當然 PIC18 系列也可設定與 PIC16Fxxx 系列的中斷相容 ( 關掉優先權的設定 ) 42 21

中斷優先權示意圖 CHIRKAL43 High Priority Interrupt Generation 44 22

Low Priority Interrupt Generation 45 中斷事件訊號 外部中斷 :INT0,INT1,INT2 PORT B 改變 TIMER 0 週邊裝置 : PSP(Parallel Slave Port) AD(A/D Conversion) RC(USART Receive) TX(USART Transmit) SSP(Master Synchronous Serial Port) CCP1(Capture Compare PWM 1) OSC(OScillator) CM(Comparator) EE(Data EEPROM/Flash Write Operation) BCL(Bus Collision) HLVD(High/LowVoltage Detect) TMR3(Timer3) CCP2(Capture Compare PWM 2) USB 46 23

相關暫存器 RCON: 重置控制暫存器 INTCON: 中斷控制暫存器 1 INTCON2: 中斷控制暫存器 2 INTCON3: 中斷控制暫存器 3 PIR1,PIR2: 週邊裝置中斷旗號暫存器 PIE1,PIE2: 週邊裝置中斷致能暫存器 IPR1,IPR2: 中斷優先設定暫存器 47 interrupt source control bits Each interrupt source has three bits to control its operation. The functions of these bits are: Flag bit to indicate that an interrupt event occurred Enable bit that allows program execution to branch to the interrupt vector address when the flag bit is set Priority bit to select high priority or low priority 48 24

高優先中斷及其 ISR 的設定範例 CHIRKAL49 中斷的前置設定 CHIRKAL 50 25

中斷處理程式 (ISR) 注意事項 中斷函數無法傳遞參數 中斷所使用到的變數需加入 volatile 的宣告 中斷函數儘量不要使用 Local 變數, 影響中斷響應時間 ISR 應越短越好, 不要做太多的處理, 可以設定 Flag 後交給主程式處理 許多運算都會用到 tmpdata 節區, 若 ISR 中有複雜的計算 ( 乘 除 比較的運算 ), 就必須要 save tmpdata 這個節區, 避免與主程式的暫存資料相衝突 新版的 C18, 會自動儲存 tempdata 51 中斷實驗 Lab1 :INT0 中斷 Lab2 :INT1 中斷 Lab3 : 巢狀中斷 Lab4 : 多個同層中斷 INT1_INT2 52 26

大綱 PIC18F4520/4550 簡介 環境建置 基礎實驗 PIC 中斷架構 PIC 計時器架構 ADC 架構 繪圖型 LCD VB6 與 4550 溝通與實作 UART 53 PIC18F 計時器架構 Timer0:8/16 bit Counter Timer1:16 bit Counter Timer2:8 bit Counter 及 8 bit 週期暫存器 Timer3 :16 bit Counter( 同 Timer1) 54 27

Timer0 8/16 bit Counter (16-bit mode 時, TMR0H 會在讀寫 TMR0L 時才真正的被讀出或寫入 Timer0) 3 bit Prescaler( 最大預除 256) 外部 / 內部來源 溢位產生中斷 正緣 / 負緣 55 TIMER0 BLOCK DIAGRAM (8-BIT MODE) CHIRKAL56 28

TIMER0 BLOCK DIAGRAM(16-BIT MODE) CHIRKAL 57 Timer0 相關暫存器 CHIRKAL58 29

Timer1 16 bit Counter( 由兩個可讀 / 寫的 8-bit 計數器串聯而成 ) 2 bit Prescaler ( 預除器有四種選擇 :1, 2,4,or 8 最大預除 8) 外部 / 內部來源 正緣 / 負緣 可由 CCP 模組重置的特殊事件觸發 16-bit 模式的計數器或計時器三種功能 : 計時器, 同步模式計數器, 非同步模式計數器 ( 睡眠模式下使用非同步時序喚醒 ) 專用石英振盪電路可作為外部計數時序或第二系統時序 ( System Clock ) 選擇 當計數器或計時器產生溢位時 FFFFh to 0000h, 即產生中斷 59 TIMER1 BLOCK DIAGRAM CHIRKAL 60 30

Timer1 相關暫存器 CHIRKAL 61 Timer 2 8 bit Counter 8bit 週期暫存器 2 bit Prescaler ( 最大預除 16) 4 bitpostscaler ( 最大預除 16) 外部 / 內部來源 溢位產生中斷 當 PR2 符合 TMR2 內容產生中斷信號 MSSP(SPI) 模組可選擇使用 TMR2 輸出產生時序移位脈波 62 31

Timer 2 8-bit 採比較模式的計時器 有預除器及後除器之功能 TMR2 為一可讀 寫並具有自動載入功能 計時器 (TMR2) 會自動加一並與設定的值 (PR2) 相比 ; 若相等則送出訊號至後除器或產生中斷, 並自動將計時器 (TMR2) 清除為零, 重新計時 PWM 模式下是 Period & Duty 的基本頻率 也可以當成 MSSP(SPI) 傳送速率的設定 63 TIMER2 BLOCK DIAGRAM CHIRKAL64 32

Timer2 相關暫存器 CHIRKAL65 Timer3 16 bit Counter 2 bit Prescaler ( 最大預除 8) 外部 / 內部來源 溢位產生中斷 正緣 / 負緣 可由 CCP 模組重置的特殊事件觸發 66 33

TIMER3 BLOCK DIAGRAM CHIRKAL67 Timer3 相關暫存器 CHIRKAL 68 34

CCP MODE TIMER RESOURCE 69 Timer 實驗 Lab1:Timer0 計時 (0.524ms) Lab2:Timer0 計時 (0.5sec) Lab3:Timer1 計時 0.5sec Lab4: 利用 C18 函數庫 Lab5:Timer0 與 INT0 中斷 Lab6:Timer0 計數中斷 Lab7: 四位數七段多工掃描 Lab8: 鍵盤掃描與四位數七段 Lab9:PWM 70 35

大綱 PIC18F4520/4550 簡介 環境建置 基礎實驗 PIC 中斷架構 PIC 計時器架構 ADC 架構 繪圖型 LCD VB6 與 4550 溝通與實作 UART 71 ADC 使用 SAR 的轉換方式 ( 須設定 TAD ) 13 組類比轉換多工輸入選擇,10 bits 解析度 類比輸入取樣時間 :2.4 µs ( 信號源阻抗 <10K) 類比輸入轉換時間 : 11 ~ 12 個 TAD 8.4 µs (12 TAD, TAD 的最小時間為 0.7uS) 10-bit 解析度時, 只有一位元的誤差 允許使用外部參考電壓 : VREF+ & VREF- 轉換的結果允許被設定為向左 向右對齊修正 72 36

ADC 相關暫存器 A/D Result High Register (ADRESH) A/D Result Low Register (ADRESL) A/D Control Register 0 (ADCON0) A/D Control Register 1 (ADCON1) A/D Control Register 2 (ADCON2) 73 ADCON0: A/D CONTROL REGISTER 0 74 37

ADCON1: A/D CONTROL REGISTER 1 CHIRKAL 75 PIC18F4520 ADC 方塊圖 CHIRKAL 76 38

C18--ADC 函數 OpenADC SetChanADC SelChanConvADC ConvertADC BusyADC ReadADC CloseADC 77 OpenADC config1 = ADC_FOSC_32 ADC_RIGHT_JUST ADC_2_TAD ; config2 = ADC_CH0 ADC_INT_OFF ADC_REF_VDD_VSS ; portconfig = ADC_2ANA ; // analog: AN0->1 and remaining channels are digital OpenADC(config1, config2, portconfig); 78 39

ADC 實驗 Lab1: 光敏電阻的電壓顯示在 LCD Lab2: 光線控制步進馬達轉動 79 大綱 PIC18F4520/4550 簡介 環境建置 基礎實驗 PIC 中斷架構 PIC 計時器架構 ADC 架構 繪圖型 LCD VB6 與 4550 溝通與實作 UART 80 40

JXD12864-13A LCM 內部方塊圖 CHIRKAL 81 並列時序圖 CHIRKAL82 41

CHIRKAL84 串列時序圖 83 Reset Timing 42

模組內部架構圖 85 命令解釋 Display ON/OFF CHIRKAL 86 43

Display Start line Set CHIRKAL 87 Page Address Set CHIRKAL 88 44

Column Address Set CHIRKAL89 Display Data Write /Read CHIRKAL90 45

CHIRKAL 92 接腳介面說明 CHIRKAL91 硬體連接方式 ( 並列方式 ) 46

CHIRKAL93 硬體連接方式 ( 串列方式 ) 串列模式發送資料 CHIRKAL 94 47

95 相關副程式 void delay1ms(int count); void GLCD_DataSend(unsigned char ByteData); void GLCD_init_so64128(void); void GLCD_wbyte(unsigned char ByteData); // 寫入 1 個 BYTE void GLCD_clear_screen(); // 清除繪圖型 LCD // 在某位置顯示一 16*16 字型 void GLCD_display_chinese_position(unsigned char *p, unsigned char page_no, unsigned char y); // 在某位置清除一 16*16 字型 void GLCD_clear_chinese_position(unsigned char page_no, unsigned char y); // 在某位置顯示一 5*7 字型 void GLCD_display_number_position(unsigned char *p, unsigned char page_no, unsigned char y); // 在某位置清除一 5*7 字型 void GLCD_clear_number_position(unsigned char *p, unsigned char page_no, unsigned char y); 96 48

編碼方式 配合 Sunpls DM 字型轉碼器可將圖形文字轉為數位編碼, 其編碼方式可分為 Up to down,left to Right( 由上至下, 由左至右 ) 以及 Down to up,left to Right ( 由下至上, 由左至右 ) 兩種編碼方式, 在以下的範例中將介紹 Up to Down,Left to Right 以及 Down to Up,Left to Right 的編碼方式 97 up to down left to right 編碼方式 1byte 1byte 1 3 5 7 2 46 LSB0 HSB0 LSB1 HSB1 up to down left to right 編碼方式 : 由上至下由左至右, 因此第 1 個 byte 先被編碼出來, 接下來為 2 3 4 接著編碼, 若把 16*16 點矩陣由中間切開我們便能發現上排圖形由字碼 1 3 5 7 所構成, 下排則由 2 4 6 8 所構成 98 49

down to up left to right 編碼方式 1byte 2 46 1byte 1 3 57 LSB1 HSB1 LSB0 HSB0 down to up left to right 編碼方式 : 由下至上由左至右, 因此第 1 個 byte 先被編碼出來, 接下來為 2 3 4 接著編碼, 若把 16*16 點矩陣由中間切開我們便能發現上排圖形由字碼 2 4 6 8 所構成, 下排則由 1 3 5 7 所構成 99 編碼差異 Up to down,left to Right( 由上至下, 由左至右 ) 以及 Down to up,left to Right ( 由下至上, 由左至右 ) 兩種編碼方式的差異在於起始編碼位置不同, 由此可知 Up to down,left to Right 的編碼方式其位置 1 3 5 7 可構成上半截圖型,2 4 6 8 則構成下半截圖形 ;Down to up,left to Right 則反之其位置 2 4 6 8 可構成上半截圖型,1 3 5 7 則構成下半截圖形 PS: 我們所使用編碼方式為 Down to Up,Left to Right 100 50

128*64 繪圖型 LCD ¼ 圖形解析 X 軸由第 0bit 64 bit 一 16*16 文字圖形所佔面積 Y 軸 page0 page1 page2 page3 16 bit 16 bit 1 2 3 4 5 6 7 8 1byte 1byte 由上圖得知我們若欲寫入一 16*16 文字則起始位置由 Y 軸 page0 開始, X 軸由第 0bit 開始, 寫完 1 若欲寫 2 則 X 軸由第 16bit 接續寫入 101 山 - 文字圖形編碼 文字圖形編碼格式介紹 LSB1 後 left to right 先 HSB1 LSB0 down to up 綠色為 0 白色為 1 以第二行 0x7f 為例 HSB0 0111 1111 0x7f,0xf0 編碼方式以 down to up left to right 所編出的字碼為 : 0x00,0x00,0x7f,0xf0,0x40,0x00,0x40,0x00, 0x40,0x00,0x40,0x00,0x40,0x00,0x7f,0xfe, 0x40,0x00,0x40,0x00,0x40,0x00,0x40,0x00, 102 0x40,0x00,0x7f,0xf0,0x00,0x00,0x00,0x00 51

山 - 文字圖形編碼 文字圖形編碼格式介紹 LSB0 後 left to right 先 HSB0 LSB1 up to down 綠色為 0 白色為 1 以第二行 0x7f 為例 HSB1 0111 1111 0x0f,0xfe 編碼方式以 up to down left to right 所編出的字碼為 : 0x00,0x00,0x0f,0xfe,0x00,0x02,0x00,0x02, 0x00,0x02,0x00,0x02,0x00,0x02,0x7f,0xfe, 0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02, 103 0x00,0x02,0x0f,0xfe,0x00,0x00,0x00,0x00 CHIRKAL104 52

圖形編碼方式 CHIRKAL105 tu.c CHIRKAL106 53

繪圖型 LCD 實驗 Lab1: 一個中文字 Lab2: 四個中文字 Lab3: 阿拉伯數字及英文 107 大綱 PIC18F4550 簡介 環境建置 基礎實驗 VB6 與 PIC18F4550 USB 溝通與實作 108 54

大綱 PIC18F4520/4550 簡介 環境建置 基礎實驗 PIC 中斷架構 PIC 計時器架構 ADC 架構 繪圖型 LCD VB6 與 4550 溝通與實作 UART 109 VB 初始畫面 偵測到 USB 110 55

VB PIC CHIRKAL111 HardwareProfile.h CHIRKAL112 56

PIC 端的 main CHIRKAL113 PIC 要處理部份 CHIRKAL114 57

VB 輸出 輸出入緩衝區 OutputReportData(128) SendBuffer() VB 輸入 ReadBuffer() 115 VB 要處理部份 CHIRKAL116 58

大綱 PIC18F4520/4550 簡介 環境建置 基礎實驗 PIC 中斷架構 PIC 計時器架構 ADC 架構 繪圖型 LCD VB6 與 4550 溝通與實作 UART 117 PortC.6 for Tx PortC.7 for Rx 相關暫存器 UART 簡介 TXSTA, RCSTA, BAUDCON Baud rate 計算 TXREG 傳送暫存器 RCREG 接收暫存器 118 59

UART 實驗 Lab1: 輪詢式傳送 -- 利用 C18 函數 Lab2: 中斷式接收 -- 低優先權中斷 Lab3:PC 端控制 LED 花樣變化 119 參考資料 Microchip RTC 講義 CCOM3101T v1.1.pdf http://www.waitingforfriday.com/index.php/ Building_a_PIC18F_USB_device http://www.rakeshmondal.info/ MPLAB C18 Compiler User s Guide & Library Microchip RTC 講義 TLS2118_TW.pdf http://120.114.77.133/notes/ch-s500/index.htm 120 60

謝謝聆聽, 敬請指教!! 121 61