210 likes | 499 Vues
MicroChip. UNCA ECE 406 April 11, 2007. MicroChip processors. Very popular in embedded systems Small instruction set About 35 instructions Many with built-in A-to-D MPLAB IDE Used in the Boe-Bot Cheap. Some processors. PIC10F200 8-bit microcontroller PIC24FJ128GA
E N D
MicroChip UNCA ECE 406 April 11, 2007
MicroChip processors • Very popular in embedded systems • Small instruction set • About 35 instructions • Many with built-in A-to-D • MPLAB IDE • Used in the Boe-Bot • Cheap
Some processors • PIC10F200 • 8-bit microcontroller • PIC24FJ128GA • 16-bit microcontroller • dsPIC30 • 16-bit Digital Signal Controllers • Serial EEPROM • In many protocols
Harvard architecture • Program memory • Holds instructions • Vector table • Data memory • Register file • Access to I/O • Some special purpose registers • Two for indirect access
Data memory • General purpose registers • May be as small as 8 bytes • May be in “banks” • May be “unimplemented” • CPU control registers • For I/O, etc. • Operation status (Z and C bits) • Accumulator and W registers • May be used to store arithmetic results
W register • Heavily used in smaller processors • To add 33h and 34h and store in 37h MOVE 33h, W ADDF 34h, W MOVWF 37h • Larger processors • Arrays of W registers • Accumulators for fixed point operators
ALU ops on low-end processors • Three categories, according to destination • Always in W register • Always in a file register • Could be either a file register or W register • Generally a single bit specifies which one
Common operands • Assuming a low-end chip • Possible operands • k, a constant (literal) – probably 0 to 255 • f, a file register – limit depends on the chip • d, chooses between W and the file register • Either W or F • b, a bit index – 0 to 7
Destination is either -- 1 d can be either F or W All set Z bit
Destination is either -- 2 All these involve the C bit There is also a DC (digit carry) bit for add and subtract d can be either F or W All set Z bit
Destination is either -- 3 d can be either F or W All set Z bit
Unconditional branches • Build an infinite loop with the GOTO loop ADDLW 20h,F ADDLW 2 GOTO loop • Generally you’ll need a GOTO in the reset vector ORF 0h reset GOTO start
Skipping for a conditional Sometimes you can skip the next instruction The Z, C, and DC bits are stored in the STATUS register
An ordinary C program tot = 0 ; for (i=25; i != 0; --i) tot = tot + i ;
A PIC program I EQU 30h ; define I to be file register 30h TOT EQU 31h ; define TOT to be register 31h CLRF TOT ; TOT = 0 MOVLW 25 ; W = 25 MOVWF I ; I = W = 25 FORL MOVF I,W ; W = I ADDF TOT,W ; TOT = TOT + W = TOT + I DECFZ I ; I = I – 1 GOTO FORL ; skip if I is 0 FORE: .... ; out of the loop
Special file registers • File registers may be used for • Input and output pins • Program counter • Status bits • Analog-to-digital converters • Timers • “Memory” mapping • Examples are from PIC10F200
Status register • Register 03h • Time-out • Wake-up • Z bit -- 2 • DC bit – 1 • C bit -- 0
To test if equal • C code if (F20 == F21) F25 = 7 • PIC code MOVWF 20h ; W = F20 SUBWF 21h,W ; W = F20-F21 BTFSS STATUS,Z GOTO labelX ; skip if Z bit set MOVLW 7 ; W = 7 MOVWF 25h ; F25 = 7 labelX ...
To test if less than • C code if (F20 < F21) F25 = 7 • PIC code MOVWF 20h ; W = F20 SUBWF 21h,W ; W = F20-F21 BTFSS STATUS,C GOTO labelX ; skip if C bit set MOVLW 7 ; W = 7 MOVWF 25h ; F25 = 7 labelX ...