Ch 2 Assembly Lang PIC The PIC Microcontroller
Ch. 2 - Assembly Lang - PIC The PIC Microcontroller and Embedded Systems: Using Assembly and C for PIC 18 By Muhammad Ali Mazidi, Rolin Mc. Kinlay, Danny Causey
• http: //microdigitaled. com/PIC/Software/PIC_t ools. htm – Install MPLAB – Install C 18 – Read tutorials from http: //microdigitaled. com/PIC_books. htm
Finish!!!? Now work at home n learn – based on the concepts of Intel 8086’s Assembly Language =======
Working Register
Only one! • WREG – Working REGister is same as Accumulator in other microprocessors • WREG us used for all arithmetic and logic instructions
MOVLW instruction • MOVLW move 8 -bit data into the WREG reg. MOVLW k Move literal value of k into WREG • L Literally – a number must be used • Similar to immediate value of 8086’s assembly language MOVLW 25 H Move value 25 H into WREG
MOVLW • ‘L’ stands for literal • Immediate value concept of other microprocessor • ‘W’ for WREG • MOVLW move a literal value to WREG reg.
ADDLW L
ADDLW • Add ‘k’ to register WREG • Put the result back in the WREG
WREG & ALU using literal value
• MOVLW 5 h 00000101 ; in binary • Moving a value larger than 255 (FF in hex) into the WREG register will truncate the upper byte and cause a warning in the. err file
2. 2: File Register • • File register == data RAM == data memory == (general-purpose-reg. + special-function-reg. ) • Data memory space is different from program (code) memory
Data RAM == special-function-reg + general-purpose-reg • Special-fn. reg. [SFR] for specific functions, e. g. , – ALU status – Timers – Serial communications – I/O ports – ADC – Etc.
SFR… • Function of each SFR is fixed by the CPU designer at the time of the design – as it is used for control of the microcontroller or peripheral • 8 -bit registers • No. of locations in the file reg. ? 7 to over a hundred more timers in a PIC, the more SFR reg. it has
Data RAM == special-function-reg + general-purpose-reg • • GPR / RAM Used for data storage and scratch pad 8 bits wide The space that is not allocated for SFRs – typically is sued for GPR
File reg. size [in bytes] PIC File register = SFR • PIC 12 F 508 • PIC 16… • PIC 18 F 452 32 bytes 80 1792 7 12 256 + GPR 25 68 1536
GPR RAM vs. EEPROM • GPR – internal data storage, used by the CPU • EEPROM – as an add-on memory, can add externally to the chip
File register & access bank in PIC 18 • PIC 18 family can have a max of 4096 (4 k = 212) bytes • So, address range of the file reg. = 000 h ~ FFFh • File reg. is divided into 256 -byte banks • So, 4069/256 = 16 banks • At least one bank for the file reg. – called access bank
• 256 -byte access bank two 128 bytes sections = GPR & SFR • The 128 bytes – from locations 00 H to 7 FH – as General-purpose reg. – used for read/write storage – Scratch pad – For storing data & parameters by PIC 18 programmers & C compilers • The other 128 bytes – from locations F 80 H to FFFH – as special-function reg.
So far for PIC • MOVLW • ADDLW – Literal – WREG
2. 3: Using instructions with the default access bank • MOVWF it tells the CPU to move (in reality, copy) the source reg. of WREG – to a destination in the file reg. (F) • So, the location (new) in file reg. will have the same value as reg. WREG. • F – file reg. – stands for a location in the file reg. • W – WREG
Move to SFR • MOVWF PORTA ; move the contents of WREG into SFR reg. called PORTA MOVLW MOVWF 55 H PORTB PORTC ; WREG = 55 H ; copy WREG to Port-B ; copy WREG to Port-C . . Port. B, Port. C, and Port. D are part of the special function reg. They can be connected to the I/O pins of the PIC mic.
Move to GPR • Move [copy] contents of WREG GPR/RAM MOVLW 99 H ; WREG=99 H MOVWF 0 H ; move [copy] WREG contents to location 0 h … - Cant move literal [immediate] values directly into the general-purpose RAM locations in the PIC 18. - They must be moved there via WREG. Q: Can literal values directly into SFR?
ADDWF • ADDLW 15 H ; =15 h + [WREG] • ADDWF file. Reg, D ; =[WREG] + [file. Reg] • Sources: • Content of WREG • file. Reg: Content of file register (special or general) • Destination: D indicates destination bit • If D = 0, destination of the result is WREG, or • If D = 1, destination is file register
- Slides: 24