Documentation Podstawy techniki mikroprocesowej ETEW6 Architektura wybranych mikrokontrolerów Andrzej Stępień / Janusz Janiczek Katedra Metrologii Elektronicznej i Fotonicznej. C5. Architecture and Instruction Set. User s MANUAL. Infineon, July 2, p.4-2. RS5L3xxx High-Perfmance 85 MCU + F-. Datasheet. Ramtron, Rev 2. 3. ST7 FAMILY PROGMING MANUAL. STMicroelectronics, November 25 4. MSP43xxx Family User s Guide. Texas Instruments, SLAU49F, 26 5. 8-bit AR Instruction Set. Atmel, Rev. 856G AR 7/8 6. ARM Architecture Reference Manual. ARM DDI E, June 2 RS5L3xxx High-Perfmance 85 MCU + F-. Datasheet. Ramtron, Rev 2. RS5L374 F--enhanced high perfmance Mult/Div/Accu 85 Ce 32-Bit Barrel Single Cycle JTAG On-Chip Shifter 4MHz Emulation Flash 64K Bytes Pts(7/5), S I/Os (56/4) 4352 Bytes F 892/248 Bytes 85-based microcontroller (/3) 85 High Perfmance Single Cycle Process (Operation up to 4 MIPS) 64KB Flash Program Memy (In-System/ln-Application Programmable) 4352 Bytes of S (4KB + 256) (Ext. 4KB can be used f program data memy) 892 / 248 Bytes of on-chip F- memy JTAG Interface f Flash Programming and Non-Intrusive Debugging/In-Circuit Emulation MULT/DI/ACCU Unit including Barrel Shifter 56 / 4 General Purpose I/Os (64/44-pin version) RS5L3xxx High-Perfmance 85 MCU + F-. Datasheet. Ramtron, Rev 2. RS5L374 F--enhanced high perfmance 85-based microcontroller (2/3) SPI I 2 C UARTs Baud Rate Generats Interrupt Controller PWMs/ Timers (8) Pulse Width Counters (2) Timer Capture Inputs (3) 2 Serial UARTs/2 Baud Rate Generats (2-bit) Enhanced SPI Interface (fully configurable wd size) Fully Configurable I2C Interface (Master/Slave) 6 External Interrupt Pins/Interrupt On Pt Pin Change 6-bit General Purpose Timer/Counters 2 Pulse Width Counter Modules 8 PWM Controller Outputs with Individual Timers PWMs can be used as General Purpose Timers RS5L3xxx High-Perfmance 85 MCU + F-. Datasheet. Ramtron, Rev 2. RS5L374 F--enhanced high perfmance 85-based microcontroller (3/3) : Typy pamięci On-Board Oscillat Cristal Oscillat Inputs Dynamic Clock Control Watch Dog Timer Power-On Reset Internal Oscillat (startup < 2 µs), oscillat temperature stability: +/ 2 % in to +7ºC +/ 3.25 % in 4 to +85ºC Dynamic System Clock Frequency Adjustment Power Saving Features Power-On Reset/Brown-Out Detect Watchdog Timer Operating voltage: 3. to 3.6 Operating Temperature -4 C to +85 C zewnętrzna kodu programu CODE wewnętrzna kodu programu SFR 7Fh rejestry X FFh 8h zewnętrzna danych wewnętrzna danych
: Adresowanie pamięci i SFR : - segment bitowy i SFR FFh adresowanie bitu: CLR 2Dh.3 CLR 6Bh adresowanie bezpośrednie (addr) adresowanie rejestrowe (Rn) rejestry 7Fh 8h segment bitowy adresowanie pośrednie (@Ri) adresowanie bitu CY w rejestrze PSW ( adres Dh ): CLR Dh.7 CLR D7h CLR PSW.7 CLR C : Rejestry specjalne (SFR), 5, 7A Rejestry specjalne (SFR), 5, 7A, ST7: CPU Architecture Memy Data Bus MDB Memy Address Bus MAB Memy Address Register MA MSP43 CPU Architecture ROM RBn DPTR B PSW internal registers SP SFR ROM A temp ALU X Y CC ST72334 SP Periph A temp ALU Register R (PC) Increment logic Register R (SP) Register R2 (SR/CG) Register R3 (CG2) Register R4... Register R5 Temp Register Instruction Fetch Register Sequencer PC PC C (Carry) Z (Zero) N (Negative) (oerflow) ALU + Shifter Cin 2
MSP43 R - Program Counter PC R - Stack Pointer SP MSP43x4xx Family User s Guide. Texas Instruments, SLAU56G, 27, p.4-9 MSP43 Constant Generat MSP43x4xx Family User s Guide. Texas Instruments, SLAU56G, 27, p.4-6... R2 - SR / Constant Generat CG (+4, +8) R3 - Constant Generat CG2 (, +, +2, FFh, FFFFh): CLR* Clear destination: MO #, dst ; dst *): MO #, dst R2 - SR / Constant Generat CG (+4, +8) RESERED OSC CPU Off Off R3 - Constant Generat CG2 (, +, +2, ) R4.. R5 - User wking Registers GIE N Z C most used constant: +8 +4 +2 + CLRC* Clear Carry bit: BIC #, SR ; C *): BIC #, SR CLRZ* Clear Zero bit: BIC #2, SR ; Z *): BIC #2, SR SETN* Clear Negative bit: BIS #4, SR ; N *): BIS #4, SR EINT* Disable general BIS #8, SR ; GIE *): BIS #8, SR interrupts: IN* Invert destination: IN.W dst ; *): XOR #FFFFh, dst *) Emulation ARM7: CPU Architecture Privileged Modes Exception Modes User System Supervis Abt Undefined Interrupt Saved Program R3 (Stack Pointer) R4 (Link Register) Current Program CPSR CPSR R R R2 R3 R4 R5 R6 R7 R8 R9 R R R2 R3_svc R3_abt R3_und R4_svc R4_abt R4_und PC (Program Counter) CPSR_svc SPSR_svc CPSR_abt SPSR_abt CPSR_und SPSR_und R3_irq R4_irq CPSR_irq SPSR_irq Fast Interrupt R8_fiq R9_fiq R_fiq R_fiq R2_fiq R3_fiq R4_fiq CPSR_fiq SPSR _fiq Program Program Status Wd (PSW) Register: addr in SFR = Dh Carry flag Auxiliary Carry flag Register bank select control bits General purpose user flag CY AC F RS RS O F P Overflow flag Parity flag Conditional Branch Register bank select control bits Overflow flag Carry flag AC F RS RS CY O F P Parity flag Auxiliary Carry flag General purpose user flag Test Mnemonic Operation A = JZ rel jump if Acc = A JNZ rel jump if Acc C = JNC rel jump if C = C = JC rel jump if C = F8h Fh E8h Eh D8h Dh C8h Ch B8h Bh A8h Ah 98h 9h 88h 8h bit = JNB bit, rel jump if bit = bit = JB bit, rel jump if bit = bit = JBC bit, rel jump if bit = & clear bit B ACC PSW IE P3 IE P2 SCON P TCON P SFR SBUF TMOD SP Bit addressing ST7 Condition Code Register Condition Code (CC) Register H I N Z C Half Carry flag Carry flag Zero flag Negative flag General Interrupt flag 3
ST7 Conditional Test Mnemonic Operation bit = BTJF dst, #pos jump if bit is false () bit = BTJT dst, #pos jump if bit is true () xx JRxx jump if condition is true Branch xx Condition Comment NC C = Not Carry Carry flag H I N Z C Half Carry flag Zero flag Negative flag General Interrupt flag UGE C = Unsigned Greater Equal (>=) C C = Carry ULT C = Unsigned Lower Than (<) NE Z = Not Equal EQ Z = Equal UGT (C OR Z) = Unsigned Greater Then (>) ULE (C OR Z) = Unsigned Lower Equal (<=) T True () RF False () NH H = Not Half-Carry RH H = Half-Carry IL Interrupt Line is Low IH Interrupt Line is High NM I = Not Interrupt Mask M I = Interrupt Mask PL N = Plus MI N = Minus MSP43 (R2) RESERED OSC Off CPU Off GIE N Z C most used constant: +8 +4 +2 + Overflow bit. System clock generat System clock generat OSC Off CPU Off GIE N Z C Oscillat Off CPU Off General interrupt enable Negative bit Zero bit Carry bit f Entering Low-Power Modes MSP43 Contitional and unconditional Jumps JMP JC / JHS JEQ / JZ JGE JL JN JNC / JLO JNE / JNZ RESERED 5 3 2 jump width -bit signed offset ; jump 9 8 OP - Code S OP-Code: operand code field (6 bit) OSC Off CPU Off GIE N Z C Offset S: sign ( bit sign offset) ; jump if carry set / higher same (C=) ; jump if equal / zero set (Z=) ; jump if greater equal (N.x. =) ; jump if less (N.x. =) ; jump if negative (N=) ; jump if carry not set / lower (C=) ; jump if not equal / zero not set (Z=) ARM7 Current/Saved Program Condition code flags: Negative less than Zero Carry brow extend Overflow 27 26 25 24 N Z C I F T M4 M3 M2 M M 3 3 29 28 access only in Privileged Modes IRQ (Interrupt Request) disable FIQ (Fast Interrupt Request) disable Current / Saved Program 8 7 6 State bit: T=, Thumb state, 6-bit Thumb instruction set 4 3 2 User FIQ IRQ Supervis Abt Undefined System ARM7 Instruction Set All ARM instruction can be conditionally executed EQ NE CS / HS CC / LO equal Z set not equal Z clear unsigned higher same C set unsigned lower C clear AL MI PL S C N Z C 3 3 29 28 always negative N set positive zero N clear overflow set no overflow clear I F T M4 M3 M2 M M 7 ARM Architecture Reference Manual. ARM DDI E. ARM DDI 27D, June 2, p.a3-6 HI LS GE LT unsigned higher C set and Z clear unsigned lower same C clear Z set signed greater than equal N set and set, N clear and clear (N == ) signed less than N set and clear, N clear and set (N!= ) signed greater than Z clear, and either GT N set and set, N clear & clear (Z ==,N == ) LE signed less than equal Z set, N set and clear, N clear and set (Z == N!= ) Znaczniki C, H,, S, N, Z (AR - /2) Rd Rr bez znaku C H N S Z x7f + = b 27 + = 28 b +27 + = 28! C= b ze znakiem H R C =, Rd 7 =, Rr 7 =, R 7 = H =, Rd 3 =, Rr 3 =, R 3 = =, Rd 7 =, Rr 7 =, R 7 = N =, R 7 = S = Z =, all R n = : O = C x A 7 6 P = dla parzystej liczby w Acc 8-bit AR Instruction Set. Atmel, Rev. 856G AR 7/8, doc856, p.5 C = Rd 7 Rr 7 + Rr 7 R 7 + R 7 Rd 7 H = Rd 3 Rr 3 + Rr 3 R 3 + R 3 Rd 3 = Rd 7 Rr 7 R 7 + Rd 7 Rr 7 R 7 N=R 7 S = N Z = R 7 R 6 R 5 R4 R 3 R 2 R R 4
Znaczniki C, H,, S, N, Z (AR - 2/2) Rd Rr bez znaku C H N S Z xff + = b 255 + = 256! b + = C= b ze znakiem H R C =, Rd 7 =, Rr 7 =, R 7 = H =, Rd 3 =, Rr 3 =, R 3 = =, Rd 7 =, Rr 7 =, R 7 = N =, R 7 = S = Z =, all R n = : O = C x A 7 6 P = dla parzystej liczby w Acc C = Rd 7 Rr 7 + Rr 7 R 7 + R 7 Rd 7 H = Rd 3 Rr 3 + Rr 3 R 3 + R 3 Rd 3 = Rd 7 Rr 7 R 7 + Rd 7 Rr 7 R 7 N=R 7 S = N Z = R 7 R 6 R 5 R4 R 3 R 2 R R source file.asm.a5 Absolute / Relocatable listing file.lst Linker source file.c.c5 Source file.asm.a5.src Absolute / Relocatable on some compilers listing file.lst Absolute / Relocatable object file object file Library file.lib Linker [Converter] Absolute file..abs.hex Symbol file.sym Map file.map. m5 Arytmetyka BCD kekcja dziesiętna Arytmetyka BCD DEC_8 Dod_BCD: MO A, #95h ADD A, #85h DA Dodać dwie liczby zapisane w kodzie BCD: 95h i 85h. Wynik dodawania w rejestrach: R7 (h) i R6 (8h). MO CLR MO MO A R6, A A Acc., C R7, A ; A 95h, 95h = b ; A A + 85h, 85h = b ; C=, AC=, A = Ah = b ; A A + 6 ponieważ A 3.. > 9 ; +6 = b ; C=, A = 2h = b ; A A + 6h ponieważ C= ; +6h = b ; C=, A = 8h = b ; R6 A ; A ; A C, A = b ; R7 A DEC-rementacja 8-bitowej zmiennej zapisanej w kodzie BCD, np. = 99 DEC_arg8: MO A, Arg8 ; (Arg8) = BCD = b ADD A, #99h ; 99h = b ; A = b, AC =, A 3.. A 9 ; C =, A 7.. A 4 9 ; przy odejmowaniu: przekroczenie ; zakresu liczb BCD (. 99) DA A ; brak kekcji MO Arg8, A ; (Arg8) 99 5
MSP43 DADD scr, dst The source operand and the destination operand are treated as four binary coded decimals (BCD) with positive signs. The source operand and the carry C are added decimally to the destination operand: scr + dst + C dst decimally The result is not defined f non-bcd numbers Status bits: N=MSB C= if the result > 9999 WORD 99 BYTE Z= if result is zero =undefined Example: The 8-digit-BCD number contained in R4 and R5 is added decimally to a 8- digit_bcd number contained in R6 and R7 (R4 and R6 contain the MSDs) CLRC ; C= DADD R5, R7 ; (R5 + C + R7) BCD R7, add LSDs DADD R4, R6 ; (R4 + C + R6) BCD R6, add MSDs with carry JC Overflow ; if carry occurs go to err handling routine C39 - Maxim / Dallas Semiconducts arithmetic accelerat (DS8c39.pdf, 8c39_userguide.pdf) 5 dodatkowych rejestrów: MCNT, MCNT, MA, MB, MC, D8h Dh PSW MCNT MCNT MD2 MA MB MC C8h wykonywane operacje arytmetyczne: 32/6 bitowe dzielenie (9 t CY ): 32-bitowy ilaz, 6-bitowa reszta, 6/6 bitowe dzielenie (6 t CY ): 6-bitowy ilaz, 6-bitowa reszta, 6 6 bitowe mnożenie (6 t CY ): 32-bitowy iloczyn, 32-bitowe przesunięcie (9 t CY ): 32-bitowy wynik, 32-bitowa nmalizacja (9 t CY ): 32-bitowa mantysa, 5-bitowa potęga, szybkość taktowania: t CY = 4 / f OSC C39 - Maxim / Dallas Semiconducts - operacje kolejność wykonywania operacji: C39 - Maxim / Dallas Semiconducts - typy operacji typ dzielenie dzielenie operacji 32 bity / 6 bitów 6 bitów / 6 bitów pierwszy wpis do MA lub MB ostatni wpis do MA, MB lub MCNT MST= ostatni odczyt pierwszy odczyt z MA, MB z MA lub MCNT początek MA dzielna (LSB) MA dzielna (LSB) w MA dzielna (LSB+) MA dzielna (MSB) p MA dzielna (LSB+2) i MA dzielna (MSB) s MB dzielnik (LSB) MB dzielnik (LSB) koniec MB dzielnik (MSB) MB dzielnik (MSB) faza faza 2 faza 3 wpis do rejestrów obliczenia odczyt z rejestrów czas czekaj aż MST= czekaj aż MST= początek o MA ilaz (MSB) MA ilaz (MSB) d MA ilaz (LSB+2) MA ilaz (LSB) c MA ilaz (LSB+) z MA ilaz (MSB) y MB reszta (MSB) MB reszta (MSB) koniec t MB reszta (LSB) MB reszta (LSB) Kod ASCII Kod ASCII (American Standard Code f Infmation Interchange): 7-bitowy kod konwersji cyfr, liter, znaków interpunkcyjnych i kodów sterujących; 8-bitowy rozszerzony kod ASCII zawierający znaki narodowe znak LF CR space! / 3h+ 9 : ASCII 3 32 33 47 48 49 57 58 Ah Dh 2h 2h 2Fh 3h 3h 39h 3Ah znak @ A F G Y Z [ ^ _ ASCII 64 65 7 7 89 9 9 94 95 4h 4h 46h 47h 59h 5Ah 5Bh 5Eh 5Fh +2h 2h znak ` a f g y z { ~ DEL ASCII 96 97 2 3 2 22 23 26 27 6h 6h 66h 67h 79h 7Ah 7Bh 7Eh 7Fh Zamiana Hex ASCII Przedstawić zawartość rejestru R7 w postaci znaków w kodzie ASCII Addr + A = 4h R = Addr = 3h R7 R A h pozostawienie 4 mniej znaczących bitów dodanie 3 h wynik > 39 h TAK litery dodanie 7 przesłanie wyniku do koniec NIE cyfry 6
: Hex ASCII - obliczenia pobieranie danych z pamięci kodu MO R, #Addr ; R adresuje wyników SWAP A ; A 7..4 A 3.. CALL Hex_ASCII ; wywołanie podprogramu zamiany CALL Hex_ASCII ; wywołanie podprogramu zamiany Hex_ASCII: ANL A, #Fh ; wydzielenie 4 mniej znaczących bitów ADD A, #3h ; A A + 3h CJNE A, #39h+, Hex_ASCII_ ; jeśli A = 3h.. 39h (cyfry) to C = Hex_ASCII_: ; jeśli A > 39h (litery) to C = JC Hex_ASCII_2 ADD A, #7 ; kekcja 7 znaków : ; < = >? @ Hex_ASCII_2: MO @R, A ; przesłanie wyniku do pamięci INC R ; przygotowanie do kolejnego przesłania Addr_2 = Addr_ + A MO DPTR, #data_6 ; DPTR data_6 MOC A, Addr_ = DPTR h @A+DPTR @A+PC CODE wart_ ; A (A + DPTR) CODE ; A (A + PC) CODE ; A jest 8-bitową liczbą ; liczbą całkowitą bez znaku ; PC wskazuje adres ; pierwszego bajtu następnej ; instrukcji Hex ASCII - tablica (/2) MO R, #Addr ; R adresuje wyników MO DPTR, #Tab_ASCII ; DPTR adresuje tablicę kodów ASCII SWAP A ; A 7..4 A 3.. Hex_ASCII_Tab: ANL A, #Fh ; wydzielenie 4 mniej znaczących bitów MOC A, @A+DPTR ; pobranie kodu ASCII z tablicy kodów MO @R, A ; przesłanie wyniku do pamięci INC R ; przygotowanie do kolejnego przesłania Tab_ASCII: DB 3h, 3h, 32h, 33h, 34h, 35h, 36h, 37h, 38h, 39h ; cyfry DB 4h, 42h, 43h, 44h, 45h, 46h ; litery Hex ASCII - tablica (2/2) MO R, #Addr ; R adresuje wyników MO DPTR, #Tab_ASCII ; DPTR adresuje tablicę kodów ASCII SWAP A ; A 7..4 A 3.. Hex_ASCII_Tab: ANL A, #Fh ; wydzielenie 4 mniej znaczących bitów MOC A, @A+DPTR ; pobranie kodu ASCII z tablicy kodów MO @R, A ; przesłanie wyniku do pamięci INC R ; przygotowanie do kolejnego przesłania Tab_ASCII: DB 23456789 ; cyfry DB ABCDEF ; litery Hex 7-segment - tablica (/2) Problem jak przedstawić zawartość rejestru R7 w postaci znaków w kodzie 7-segmentowym? rozmieszczenie segmentów we wskaźniku 7-segmentowym i sterowania segmentów w bajcie: a f e g d b c h h g f e d c b a włączenie cyfry 3 wymaga wpisania wartości 4Fh: a f e g d b c h Hex 7-segment - tablica (2/2) MO R, #Addr ; R adresuje wyników MO DPTR, #Tab_ 7_Segment ; DPTR adresuje tablicę kodów SWAP A ; A 7..4 A 3.. CALL Hex_7_Segment_Tab ; wywołanie podprogramu zamiany CALL Hex_7_Segment_Tab ; wywołanie podprogramu zamiany Hex_7_Segment_Tab: ANL A, #Fh ; wydzielenie 4 mniej znaczących bitów MOC A, @A+DPTR ; pobranie nowego kodu z tablicy kodów MO @R, A ; przesłanie wyniku do pamięci INC R ; przygotowanie do kolejnego przesłania Tab_7_Segment: DB 3Fh, 6h, 5Bh, 4Fh, 66h, 6Dh, 7Dh, 7h, 7Fh, 6Fh ; cyfry DB 77h, 7Ch, 39h, 5Eh, 79h, 7h ; litery 7