1 / 20

Microprocessor and Microcontroller Based Systems

بسم الله الرحمن الرحيم. The Islamic University of Gaza Faculty of Engineering Electrical Engineering Department. Microprocessor and Microcontroller Based Systems. EELE 4315 — Fall 2010. Instructor: Eng.Moayed N. EL Mobaied. Lecture 6. Use Assembler.

zuriel
Download Presentation

Microprocessor and Microcontroller Based Systems

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. بسم الله الرحمن الرحيم The Islamic University of Gaza Faculty of Engineering Electrical Engineering Department Microprocessor and Microcontroller Based Systems EELE 4315 — Fall 2010 Instructor: Eng.Moayed N. EL Mobaied Lecture 6

  2. Use Assembler Use Machine Code Use High Level Language Programming methods The Problem of Programming , and Programming Options What options do we have for programming a microcontroller?

  3. Assembler option The Assembler Option

  4. Developing a Simple Project Write/modify Source Code Assemble/Compile (Simulate) Download Test in Hardware

  5. Instruction set for PIC 16 series what does each column represent?

  6. PIC 16XXX Instruction Set Operand Codes. f for file (i.e. memory location in RAM), a 7-bit number; b for bit, to be found within a file also specified, a 3-bit number; d for destination, as described above, a single bit; k for literal, an 8-bit number if data, or 11-bit if address

  7. Status register The STATUS register contains the arithmetic status of the ALU, the RESET status and the bank select bit for data memory. As with any register, the STATUS register can be the destination for any instruction. If the STATUS register is the destination for an instruction that affects the Z, DC or C bits, then the write to these three bits is disabled. These bits are set or cleared according to device logic. Furthermore, the TO and PD bits are not writable. Therefore, the result of an instruction with the STATUS register as destination may be different than intended. For example, CLRF STATUS will clear the upper three bits and set the Z bit. This leaves the STATUS register as 000u u1uu (where u = unchanged). Only the BCF, BSF, SWAPF and MOVWF instructions should be used to alter the STATUS register, because these instructions do not affect any status bit.

  8. Status Register

  9. Some Example Instructions clrw This clears the value in the W register to zero. There are no operands to specify. Column 5 tells us that the Status Register Z bit is affected by the instruction. As the result of this instruction is always zero, the bit is always set to 1. No other status register bits are affected. clrf f This clears the value of a memory location, symbolised as f. It is up to the programmer to specify a value for f. Again, because the result is zero, the Status Register Z bit is affected. addwf f,d This adds the contents of the W register to the contents of a memory location symbolised by f. It is up to the programmer to specify a value for f. There is a choice of where the result is placed, as discussed above. This is determined by the value of the operand bit d. Because of the different values that the result can take, all three condition code bits, i.e. Z, the Carry bit C, and the Digit Carry bit DC are affected by the instruction.

  10. Some Example Instructions bcf f,b This instruction clears a single bit in a memory location. Both the bit and the location must be specified by the programmer. The bit number b will take a value from 0 to 7, to identify any one of the 8 bits in a memory location. No Status Register flags are affected, even though it is possible to imagine that the result of the instruction could be to set a memory location to zero. addlw k This instruction adds the value of a literal, whose value k must be specified by the programmer, to the value held in the W register. The result is stored in the W register; there is no choice. Like addwf, all condition code bits can be affected by this instruction.

  11. Left-most space optional label comment instruction comment operands Writing in Assembler Assembler format: label instruction operand(s) ;comment For example: ;now switch on red led Start bsf status,5 ;select memory bank 1 addwf counter

  12. Assembler Directives These look like Assembler mnemonics, but are instructions to the (Cross-) Assembler program itself. They differ from one Assembler to the other, though there does tend to be some similarity. Example MPASM Directives

  13. Representing Numbers

  14. Assembler File Structure (Simple Form) Files that the Assembler (e.g. MPLAB) generates For us, this will be MPLAB Executable File .hex List File Source File Assembler .asm .lst Written by you, as a text file, in Assembler format Error File .err

  15. Opening explanatory comments Directive specifying processor SFR locations specified, by equating labels to numbers, taken directly from RAM memory map Program start address specified Initialisation Actual Program A Complete 16 Series Assembler Program ;This program moves push button switch values from Port A to the ;leds on Port B ;************************************************************** ; ;Configuration Word: WDT off, power-up timer on, code protect off, RC oscillator ; list p=16F84A ;specify SFRs status equ 03 porta equ 05 trisa equ 05 portb equ 06 trisb equ 06 ; org 00 ;Initialise start bsf status,5 ;select memory bank 1 movlw B'00011000' movwf trisa ;port A according to above pattern movlw 00 movwf trisb ;all port B bits output bcf status,5 ;select bank 0 ; ;The “main” program starts here clrf porta ;clear all bits in ports A loop movf porta,0 ;move port A to W register movwf portb ;move W register to port B goto loop end

  16. Software MPLAB v8.00 “ASSEMBLER+ SIMULTATOR”

  17. Software IC-Prog1.05” programmer software

  18. Software Pic simulator

  19. Software Proteus V7.1 “simulator for circuits”

More Related