1 / 23

微算機原理與應用實習 Holtek 48R70A

微算機原理與應用實習 Holtek 48R70A. HT48R70A 記憶體. 8192*16 ROM( 唯讀記憶體 ) 程式記憶體,存於程式指令的地方 256×8-bit SRAM( 可讀 / 寫記憶體 ) 32×8-bit 特殊功能暫存器 (Special function registers) 當 一般暫存器 與週邊之 控制暫存器 224×8-bit 資料記憶體 (General purpose data memory) 用來存放程式執行過程中所需之 變數內容 或 暫存之資料值. delay: mov a,07fh mov [61h],a

orsen
Download Presentation

微算機原理與應用實習 Holtek 48R70A

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. 微算機原理與應用實習Holtek 48R70A

  2. HT48R70A 記憶體 • 8192*16 ROM(唯讀記憶體) • 程式記憶體,存於程式指令的地方 • 256×8-bit SRAM(可讀/寫記憶體 ) • 32×8-bit特殊功能暫存器(Special function registers) • 當一般暫存器與週邊之控制暫存器 • 224×8-bit資料記憶體(General purpose data memory) • 用來存放程式執行過程中所需之變數內容或暫存之資料值 delay: mov a,07fh mov [61h],a wait_1: mov a,0ffh mov [60h],a wait_2: sdz [60h] jmp wait_2 sdz [61h] jmp wait_1 ret pa equ [12h] pac equ [13h] org 0h jmp reset reset: mov a,00h mov pac,a start: clr pa.0 call delay set pa.0 call delay jmp start 數值 label 指令 一般暫存器 資料記憶體 控制暫存器

  3. 256*8 RAM記憶體 • Data memory – RAM • 特殊暫存器 (位址00~1FH) • 資料記憶體 (位址20H~FFH) • 每一個記憶體皆可獨立拿來運算 • 記憶體的每一位元(Bit)可單獨設定 • SET [m].i (將位址m之記憶體的第i bit 設為1 • CLR [m].i (將位址m之記憶體的第i bit 設為0 7 i 0 Mem[m] 1 7 i 0 Mem[m] 0

  4. 控制單顆LED閃爍 • LED是二極體的一種,具有正負極性 • 使用時將其長腳接正電源,短腳接地時即可讓LED發亮 • 順向電壓降的範圍值由1.2 ~ 3.0伏特不等 • 為了延長其使用壽命,通常會利用一限流電阻串接LED,將其工作電流限制在10 mA ~ 20 mA之間 = 250 (歐姆)

  5. 為要讓LED點亮與熄滅交替進行,所輸入的「1」、「0」信號圖形為要讓LED點亮與熄滅交替進行,所輸入的「1」、「0」信號圖形 這信號就是方波訊號,但其工作週期則不限定是50%的duty cycle。 若要讓LED產生閃爍感,則輸入之方波控制信號須為極低頻,其頻率要小於16Hz,否則人眼將就看不到閃爍現象,主要是因人的眼睛視覺暫留現象,一般而言,視覺暫留約在1/16秒到1/24秒之間,所以方波信的週期必須大於1/16秒,實際上最好取0.25秒以上,閃爍的感覺才會更真實 如何讓LED閃爍

  6. 電路與程式 pa equ [12h] pac equ [13h] org 0h jmp reset reset: mov a,00h mov pac,a start: clr pa.0 call delay set pa.0 call delay jmp start delay: mov a,07fh mov [61h],a wait_1: mov a,0ffh mov [60h],a wait_2: sdz [60h] jmp wait_2 sdz [61h] jmp wait_1 ret vcc vcc output PA0 200 HT48R70A Internal Pull-high

  7. 微控制器之計時方式 • 使用軟體延遲迴圈:利用微控制器執行一軟體延遲迴圈,利用執行此迴圈所需的指令週期數,配合供給之工作產率,即可產生所要的時間延遲。 • 使用硬體計時器:借助外部硬體計時器(Timer),將欲延遲的時間設定給硬體計時器,當延遲時間到達時,硬體計時器會對微控制器產生硬體中斷,以告知延遲時間已到達。

  8. 系統頻率 指令週期(system clock) 工作頻率 48R70A Crystal Oscillator (Max 8MHz) ROM Code Option CPU 指令執行 Instruction Cycle ÷4 fs, System Clock External RC Oscillator Internal RC oscillator Pipeline 執行指令 Instruction cycle 在Instruction Fetch (IR)階段, 程式計數器操作方式如下: 執行指令<= ROM[PC] PC <= PC + 1 (下一指令執行位址)

  9. 指令執行週期之計算原則 • Holtek的所有指令大都是1個指令週期,除了該指令的執行會破壞執行順序 ,則為2個指令週期 • 所謂 破壞執行順序 是指:他的下一個執行之指令不是PC+1 • 即程式分支指令: • JMP, SZ [m], SZA [m], SZ [m].i, SNZ [m].i, SIZ [m], SDZ [m], SIZA [m], SDZA [m], Call addr, RET, RET A, x, RETI

  10. 指令週期計算 指令週期 pa equ [12h] 0 pac equ [13h] 0 org 0h 0 jmp reset 2 reset: mov a,00h 1 mov pac,a 1 start: clr pa.0 1 call delay 2 set pa.0 1 call delay 2 jmp start 2 delay: mov a,07fh 1 mov [61h],a 1 wait_1: mov a,0ffh 1 mov [60h],a 1 wait_2: sdz [60h] 1 or 2 jmp wait_2 2 sdz [61h] 1 or 2 jmp wait_1 2 ret 2 Delay= 1+1+Y+2 Y= (7F-1)*(1+1+X+1+2)+2 or 7F*(1+1+X+1+2)-1 X= (FF-1)*3 + 2 or FF*3 -1

  11. indirect address register (IAR) RAM記憶體的位址00H (IAR0)與02H(IAR1)為間接定址暫存器,但實際上並無此真實暫存器,而是分別與位址01H、03H之記憶體指標(RAM Pointer, MP0、MP1)做間接定址 MOV A, [00H] or MOV A, IAR0 後 ,A的值為37H , 即 A <= M[MP0] ex MOV A, 60H MOV MP0, A MOV A, 31H MOV IAR0, A  Mem[60H] = 31H RAM – 特殊暫存器 00H IAR0 30H 01H (MP0) 02H IAR1 03H(MP1) MP1 30H 37H A RAM

  12. Accumulator (累加器) 兩個記憶體要傳輸資料, 需先經由ACC 暫存器 mov a, [60H] mov [61H], a Program Counter – PC 決定指令執行之位址 為13-Bit (因為ROM是8K*16) ,分成兩部分 PCL-低位元組,為可被讀/寫的暫存器 (06H) 當將資料寫入PCL時,即表示執行短程跳躍 (一個 page範圍內的跳躍,256的位址空間) RAM – 特殊暫存器

  13. RAM – 特殊暫存器 • 10001000 • + 10000100 • (1)00001100 • 進位 C = 1 Status register – STATUS • C bit (carry flag):當加法運算結果有進位或減法運算結果沒有借位,則此bit設為1,其餘則設為0; • AC bit (輔助進位旗標):當加法運算時,第4-bit (low nibble)有半進位或減法運算第4-bit沒有半借位,則此bit設為1,其餘則設為0; • 10001000 • - 10000100 • (0)00000100 • 不借位 C = 1 • 10001000 • + 10001000 • (1)00010000 • 進位 AC = 1 • 10001000 • - 00001000 • 10000000 • 不借位 AC = 1

  14. Z bit (零值旗標):當算術或邏輯運算結果為0時,Z=1,其餘則設為0; EX: MOV A, 10H AND A, 20H  因ACC = 0, Z=1 • OV bit (溢位旗標):在有號數運算時, 若 (正) + (正) = (負) 或 (負) + (負) = (正) 或 (負) - (正) = (正), 則溢位旗標OV=1,其餘則設為0; • PDF bit (省電旗標):當執行HALT指令時,此位元設為1; • TO bit (當watchdog timer timeout時,此位元設為1。 • 01010000 (+81) • + 01000100 (+70) • 10010101 (-21) • 溢位旗標 OV = 1

  15. HT48R70A之I/O port • 56 雙向 input/output 腳 (PA ~ PG) • 相對之記憶體位址為 [12h][14h][16h][18h][1Ah][1Ch], and [1Eh] • 每一個I/O Port有自己相對之控制暫存器 • PAC[13h], PBC[15h], PCC[17h], PDC[19h], PEC[1Bh], PFC[1Dh], and PGC[1Fh] • 若要將I/O Port的接腳設為輸入埠,則相對的控制暫存器需設為 “1” • 如 mov a,01h mov PAC,a • MOV A, [PA], 讀取PA之內容 • MOV [PA], A 或SET [PA].i, 設定PA之內容或PA之第i腳之內容 • 所有的I/O 腳皆可利用ROM option 設為 pull-high 7 i 0 PAC 0 0 0 0 0 0 0 1 PA.0 為Input,PA.1 ~ PA.7為Output

  16. 8K*16程式記憶體ROM • Program Memory – ROM • 用來存放程式之指令 • 可用來存放固定之資料/表格 • 特殊之位址 • Location 000H • After chip reset, PC = 000H • Location 004H • External interrupt subroutine • Location 008H • Timer/Event 0 ISR • Location 00CH • Timer/Event 1 ISR • Table location (0x0010~1FFFH)

  17. Program Counter, PC

  18. Oscillator configuration • 3 oscillator circuit in the microcontroller for system clocks • External RC oscillator • External crystal oscillator • Internal RC oscillator • The HALT mode stops the system clock • If the internal RC oscillator is used, the OSC1 and OSC2 can be selected as 32768Hz crystal oscillator (RTC OSC) • This is call internal RC + RTC mode

  19. 系統頻率來源(system clock) ROM Code Option Crystal Oscillator (Max 8MHz) ÷4 fs, System Clock Instruction Cycle External RC Oscillator Internal RC oscillator

  20. Watchdog Timer, WDT System clock may be disabled by HALT 72 us/256 = 18.6 ms • WDT clock source has (which is determined by ROM code option) • Dedicated internal RC oscillator (WDT oscillator, about 72us/clock) • RTC clock • Instruction clock • Use to prevent a software malfunction or jump to an unknown location • The watchdog timer can be disabled by ROM code option • The RTC clock only is enabled in the internal RC+RTC mode 72 us

  21. 有三種情況可將看門看計數器的內容清除: • 外部reset (external reset ) • software instruction • CLR WDT • Or “CLR WDT1” and “CLR WDT2” • HALT instruction • If WDT overflow • Under normal operation the “chip reset” is executed • In HALT mode, a “warm reset” is executed. (only PC and SP are reset to zero)

  22. Power down operation - HALT • entered by the “HALT” instruction • System clock is turn off • The contents of the on chip RAM and registers remain unchanged • WDT and WDT prescaler will be cleared and recounted again • All of the I/O ports maintain their original status • The PD flag is set and the TO flag is cleared • How to leave the HALT mode • External reset • An interrupt • External falling edge signal on port A (the input pins of port A are selected to wake-up the device by option) • Wake-up in the next instruction • WDT overflow

  23. ROM Code option • All of the ROM code options must be defined to ensure proper system functioning

More Related