Top Banner
Ch. 2- Assembly Lang - PIC The PIC Microcontroller and Embedded Systems: Using Assembly and C for PIC18 By Muhammad Ali Mazidi, Rolin McKinlay, Danny Causey
24

Ch. 2- Assembly Lang - PIC The PIC Microcontroller and Embedded Systems: Using Assembly and C for PIC18 By Muhammad Ali Mazidi, Rolin McKinlay, Danny Causey.

Dec 17, 2015

Download

Documents

Jocelin Green
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Ch. 2- Assembly Lang - PIC The PIC Microcontroller and Embedded Systems: Using Assembly and C for PIC18 By Muhammad Ali Mazidi, Rolin McKinlay, Danny Causey.

Ch. 2- Assembly Lang - PIC

The PIC Microcontroller and Embedded Systems: Using Assembly and C for PIC18By Muhammad Ali Mazidi, Rolin McKinlay, Danny Causey

Page 2: Ch. 2- Assembly Lang - PIC The PIC Microcontroller and Embedded Systems: Using Assembly and C for PIC18 By Muhammad Ali Mazidi, Rolin McKinlay, Danny Causey.

• http://microdigitaled.com/PIC/Software/PIC_tools.htm– Install MPLAB– Install C18

– Read tutorials from - http://microdigitaled.com/PIC/PIC_books.htm

Page 3: Ch. 2- Assembly Lang - PIC The PIC Microcontroller and Embedded Systems: Using Assembly and C for PIC18 By Muhammad Ali Mazidi, Rolin McKinlay, Danny Causey.

Finish!!!?

Now work at home n learn –

based on the concepts of Intel 8086’s Assembly Language

=======

Page 4: Ch. 2- Assembly Lang - PIC The PIC Microcontroller and Embedded Systems: Using Assembly and C for PIC18 By Muhammad Ali Mazidi, Rolin McKinlay, Danny Causey.

Working Register

Page 5: Ch. 2- Assembly Lang - PIC The PIC Microcontroller and Embedded Systems: Using Assembly and C for PIC18 By Muhammad Ali Mazidi, Rolin McKinlay, Danny Causey.

Only one!

• WREG – Working REGister is same as Accumulator in other microprocessors

• WREG us used for all arithmetic and logic instructions

Page 6: Ch. 2- Assembly Lang - PIC The PIC Microcontroller and Embedded Systems: Using Assembly and C for PIC18 By Muhammad Ali Mazidi, Rolin McKinlay, Danny Causey.

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

languageMOVLW 25H Move value 25H into WREG

Page 7: Ch. 2- Assembly Lang - PIC The PIC Microcontroller and Embedded Systems: Using Assembly and C for PIC18 By Muhammad Ali Mazidi, Rolin McKinlay, Danny Causey.

MOVLW

• ‘L’ stands for literal • Immediate value concept of other

microprocessor

• ‘W’ for WREG• MOVLW move a literal value to WREG reg.

Page 8: Ch. 2- Assembly Lang - PIC The PIC Microcontroller and Embedded Systems: Using Assembly and C for PIC18 By Muhammad Ali Mazidi, Rolin McKinlay, Danny Causey.

ADDLW

Page 9: Ch. 2- Assembly Lang - PIC The PIC Microcontroller and Embedded Systems: Using Assembly and C for PIC18 By Muhammad Ali Mazidi, Rolin McKinlay, Danny Causey.

ADDLW

• Add ‘k’ to register WREG• Put the result back in the WREG

Page 10: Ch. 2- Assembly Lang - PIC The PIC Microcontroller and Embedded Systems: Using Assembly and C for PIC18 By Muhammad Ali Mazidi, Rolin McKinlay, Danny Causey.

WREG & ALU using literal value

Page 11: Ch. 2- Assembly Lang - PIC The PIC Microcontroller and Embedded Systems: Using Assembly and C for PIC18 By Muhammad Ali Mazidi, Rolin McKinlay, Danny Causey.

• MOVLW 5h• MOVLW 05h• MOVLW 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

Page 12: Ch. 2- Assembly Lang - PIC The PIC Microcontroller and Embedded Systems: Using Assembly and C for PIC18 By Muhammad Ali Mazidi, Rolin McKinlay, Danny Causey.

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

Page 13: Ch. 2- Assembly Lang - PIC The PIC Microcontroller and Embedded Systems: Using Assembly and C for PIC18 By Muhammad Ali Mazidi, Rolin McKinlay, Danny Causey.

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.

Page 14: Ch. 2- Assembly Lang - PIC The PIC Microcontroller and Embedded Systems: Using Assembly and C for PIC18 By Muhammad Ali Mazidi, Rolin McKinlay, Danny Causey.

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 hundredmore timers in a PIC, the more SFR reg. it has

Page 15: Ch. 2- Assembly Lang - PIC The PIC Microcontroller and Embedded Systems: Using Assembly and C for PIC18 By Muhammad Ali Mazidi, Rolin McKinlay, Danny Causey.

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

Page 16: Ch. 2- Assembly Lang - PIC The PIC Microcontroller and Embedded Systems: Using Assembly and C for PIC18 By Muhammad Ali Mazidi, Rolin McKinlay, Danny Causey.

File reg. size [in bytes]

PIC File register = SFR + GPR• PIC12F508 32 bytes 7 25• PIC16… 80 12 68• PIC18F452 1792 256 1536

Page 17: Ch. 2- Assembly Lang - PIC The PIC Microcontroller and Embedded Systems: Using Assembly and C for PIC18 By Muhammad Ali Mazidi, Rolin McKinlay, Danny Causey.

GPR RAM vs. EEPROM

• GPR – internal data storage, used by the CPU

• EEPROM – as an add-on memory, can add externally to the chip

Page 18: Ch. 2- Assembly Lang - PIC The PIC Microcontroller and Embedded Systems: Using Assembly and C for PIC18 By Muhammad Ali Mazidi, Rolin McKinlay, Danny Causey.

File register & access bank in PIC18

• PIC18 family can have a max of 4096 (4k = 212) bytes

• So, address range of the file reg. = 000h ~ 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

Page 19: Ch. 2- Assembly Lang - PIC The PIC Microcontroller and Embedded Systems: Using Assembly and C for PIC18 By Muhammad Ali Mazidi, Rolin McKinlay, Danny Causey.

• 256-byte access bank two 128 bytes sections = GPR & SFR

• The 128 bytes – from locations 00H to 7FH – as General-purpose reg. – used for read/write storage – Scratch pad– For storing data & parameters by PIC18 programmers &

C compilers • The other 128 bytes – from locations F80H to FFFH

– as special-function reg.

Page 20: Ch. 2- Assembly Lang - PIC The PIC Microcontroller and Embedded Systems: Using Assembly and C for PIC18 By Muhammad Ali Mazidi, Rolin McKinlay, Danny Causey.

So far for PIC

• MOVLW• ADDLW

– Literal – WREG

Page 21: Ch. 2- Assembly Lang - PIC The PIC Microcontroller and Embedded Systems: Using Assembly and C for PIC18 By Muhammad Ali Mazidi, Rolin McKinlay, Danny Causey.

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

Page 22: Ch. 2- Assembly Lang - PIC The PIC Microcontroller and Embedded Systems: Using Assembly and C for PIC18 By Muhammad Ali Mazidi, Rolin McKinlay, Danny Causey.

Move to SFR

• MOVWF PORTA; move the contents of WREG into SFR reg. called PORTA

MOVLW 55H ;WREG = 55H

MOVWF PORTB ;copy WREG to Port-B

MOVWF PORTC ;copy WREG to Port-C..

PortB, PortC, and PortD are part of the special function reg.They can be connected to the I/O pins of the PIC mic.

Page 23: Ch. 2- Assembly Lang - PIC The PIC Microcontroller and Embedded Systems: Using Assembly and C for PIC18 By Muhammad Ali Mazidi, Rolin McKinlay, Danny Causey.

Move to GPR

• Move [copy] contents of WREG GPR/RAM

MOVLW 99H ;WREG=99HMOVWF 0H;move [copy] WREG contents to location 0h…- Cant move literal [immediate] values directly into the general-

purpose RAM locations in the PIC18.- They must be moved there via WREG.

Q: Can literal values directly into SFR?

Page 24: Ch. 2- Assembly Lang - PIC The PIC Microcontroller and Embedded Systems: Using Assembly and C for PIC18 By Muhammad Ali Mazidi, Rolin McKinlay, Danny Causey.

ADDWF• ADDLW 15H ; =15h + [WREG]

• ADDWF fileReg, D ; =[WREG] + [fileReg]

• Sources: • Content of WREG• fileReg: 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