SSU ES 310 - Directives, Memory, and Stack

Unformatted text preview:

Directives, Memory, and StackDirectivesData DirectivesData Directives - ExampleList DirectivesObject File DirectivesControl DirectivesASCII TABLEPIC18 Memory SpaceInternal PIC18 ArchitectureProgram MemorySlide 12Data MemorySlide 14Slide 15Using BSR – Writing into file registersA Typical Instruction showing the a-bitSlide 18Slide 19Slide 20Slide 21Initializing the RAM – indirect addressingProgram Stack MemoryDirectives, Memory, and StackDirectivesSpecial commands to the assembler May or may not generate machine code Categories by their function Programming directivesObject file directivesControl DirectivesList Directives Data DirectivesData DirectivesDescribe data ASCII data can be stored in memory using declare byte (DB) or DATAData Directives - ExampleDE "Test Data"List DirectivesControl listing processExample: LIST P=18F4520, F=INHX32 ;directive to define processor and file format#include <P18F4520.INC> ;processor specific variable definitionsObject File DirectivesHow to generate code in the object fileExample: RESET_VECTOR CODE Ox0000Example:Control DirectivesControl the assembly at the time of link processASCII TABLEPIC18 Memory Space8-bit CPUProgramMemoryData MemoryClock GenerationI/O PortsTimersAnalog to Digital ConverterSerialPortsOtherPeripherals16 wires8 wiresDataEEPROM31 x 21Stack Memory21 wires8 wires8 wiresInternal PIC18 ArchitectureProgram MemoryProgram memory addresses are 21-bit address starting at location 0x000000.Program memory is either PROM or EEPROM. The PROM version is called OTP (one-time programmable) The EEPROM version is called Flash memory.If it has flash it will have 256 bytes or 1024 bytes of data EEPROMThe data EEPROM memory is indirectly addressed through the special function registerProgram MemoryThere are three important memory locations in the program memory. 0x0000, 0x0008, and 0x0018 called vectors. Generally the GOTO instruction in assembly language is placed at a vector location. A vector is an address that is accessed when the reset or interrupt occurs.The reset vector is 0x0000, the high priority interrupt vector is 0x0008, and the low priority interrupt vector is 0x0018.Data MemoryData memory is either SRAM or EEPROM.SRAM data memory begins at 12-bit address 0x000 and ends at 12-bit address 0xFFF. Not all PIC18 versions contain 4K or data memory space.Various PIC18 versions contain between 256 and 3968 bytes of data memory.Data MemoryThere are two types of registers: general-purpose registers (GPRs) special-function registers (SFRs)GPRs are used to hold dynamic data when the PIC18 CPU is executing a program.SFRs are registers used by the CPU and peripheral modules for controlling the desired operation of the MCU.The upper 128 bytes of the data memory are used for special function registers (SFR) at addresses 0xF80 through 0xFFF. Some versions of the PIC18 have additional SFRs at locations below 0xF80.Data MemoryUsing BSR – Writing into file registers0x120x2F0x3a=1; bank selectiona=0; access bankA Typical Instruction showing the a-bit15 109870Op-code8-bit data memory addressa-bita = 0 access banka = 1 use BSRd-bitd = 0 WREGd = 1 data memory addressMOVLW 0x06 ;place a 0x06 into WADDLW 0x02 ;add a 0x02 to WMOVWF 0x00, 0 ;copy W to access bank register 0x00; OR another version using the ACCESS keywordMOVLW 0x06 ;place a 0x06 into WADDLW 0x02 ;add a 0x02 to WMOVWF 0x00, ACCESS ;copy W to access bank register 0x00MOVLW 0x06 ;place a 0x06 into WADDLW 0x02 ;add a 0x02 to WMOVLB 2 ;load BSR with bank 2MOVWF 0x00, 1 ;copy W to data register 0x00;of bank 2 or address 0x200; OR using the BANKED keywordMOVLW 0x06 ;place a 0x06 into WADDLW 0x02 ;add a 0x02 to WMOVLB 2 ;load BSR with 2MOVLF 0x00, BANKED ;copy W to data register 0x00;of bank 2 or address 0x200; OR without any bank indicationMOVLW 0x06 ;place a 0x06 into WADDLW 0x02 ;add a 0x02 to WMOVLB 2 ;load BSR with bank 2MOVWF 0x00 ;copy W to data register 0x00;of bank 2 or address 0x200MOVLW 0x7FMOVWF ADCON1 ;select all digital pins for portsMOVLW 0x00 ;place 0x00 in Port A direction registerMOVWF TRISA ;to select output operationMOVLW 0x03MOVWF PORTA ;place 0x03 on Port AData Memory0x0000x0010x0020x0030x004Register File (Data Memory)0xF7F0xF7E0xF7DBank Select Register (BSR)-4 bitAccumulator (WREG)Product High (PRODH)Product Low (PRODL)0xFE80xFE0Major Special Function Registers0xFF30xFF4File Select Register 0 High (FSR0H)File Select Register 0 Low (FSR0L)File Select Register 1 High (FSR1H)File Select Register 1 Low (FSR1L)File Select Register 2 High (FSR2H)File Select Register 2 Low (FSR2L)0xFEA0xFE90xFE20xFE10xFD90xFDAStatus Register (SR)0xFD88-BitsProgram Counter (PC)8-BitsNote: - The program counter is an internal 21-bit physical register - The program counter is modified by the GOTO, CALL, RETURN, and branch instructions. The program counter is not directly addressable.Initializing the RAM – indirect addressingWhat is this doing?Program Stack MemoryThe PIC18 contains a program stack that stores up to 31 return addresses from functions. The program stack is 21 bits in width as is the program address.When a function is called, the return address (location of the next step in a program) is pushed onto the stack. When the return occurs within the function, the return address is retrieved from the stack and placed into the program


View Full Document

SSU ES 310 - Directives, Memory, and Stack

Download Directives, Memory, and Stack
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Directives, Memory, and Stack and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Directives, Memory, and Stack 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?