260 likes | 627 Views
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
E N D
Ch. 2- Assembly Lang - PIC The PIC Microcontroller and Embedded Systems: Using Assembly and C for PIC18 By Muhammad Ali Mazidi, RolinMcKinlay, Danny Causey
http://microdigitaled.com/PIC/Software/PIC_tools.htm • Install MPLAB • Install C18 • Read tutorials from - http://microdigitaled.com/PIC/PIC_books.htm
Finish!!!? Now work at home n learn – based on the concepts of Intel 8086’s Assembly Language =======
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 25H Move value 25H 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 • Add ‘k’ to register WREG • Put the result back in the WREG
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
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 + GPR • PIC12F508 32 bytes 7 25 • PIC16… 80 12 68 • PIC18F452 1792 256 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 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
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.
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 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.
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?
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