1 / 24

Ch. 2- Assembly Lang - PIC

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

vina
Télécharger la présentation

Ch. 2- Assembly Lang - PIC

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. Ch. 2- Assembly Lang - PIC The PIC Microcontroller and Embedded Systems:  Using Assembly and C for PIC18 By Muhammad Ali Mazidi, RolinMcKinlay, Danny Causey

  2. http://microdigitaled.com/PIC/Software/PIC_tools.htm • Install MPLAB • Install C18 • Read tutorials from - http://microdigitaled.com/PIC/PIC_books.htm

  3. Finish!!!? Now work at home n learn – based on the concepts of Intel 8086’s Assembly Language =======

  4. Working Register

  5. Only one! • WREG – Working REGister is same as Accumulator in other microprocessors • WREG us used for all arithmetic and logic instructions

  6. 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 25H  Move value 25H into WREG

  7. MOVLW • ‘L’ stands for literal • Immediate value concept of other microprocessor • ‘W’ for WREG • MOVLW  move a literal value to WREG reg.

  8. ADDLW

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

  10. WREG & ALU using literal value

  11. 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

  12. 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

  13. 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.

  14. 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

  15. 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

  16. File reg. size [in bytes] PIC File register = SFR + GPR • PIC12F508 32 bytes 7 25 • PIC16… 80 12 68 • PIC18F452 1792 256 1536

  17. GPR RAM vs. EEPROM • GPR – internal data storage, used by the CPU • EEPROM – as an add-on memory, can add externally to the chip

  18. 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

  19. 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.

  20. So far for PIC • MOVLW • ADDLW • Literal • WREG

  21. 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

  22. 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.

  23. Move to GPR • Move [copy] contents of WREG GPR/RAM MOVLW 99H ;WREG=99H MOVWF 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?

  24. 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

More Related