Download presentation
Presentation is loading. Please wait.
Published byCharleen Blankenship Modified over 9 years ago
1
Microprocessor and Microcontroller Based Systems Instructor: Eng.Moayed N. EL Mobaied The Islamic University of Gaza Faculty of Engineering Electrical Engineering Department بسم الله الرحمن الرحيم EELE 4315 — Fall 2010 Lecture 6
2
Programming methods What options do we have for programming a microcontroller? The Problem of Programming, and Programming Options Use Machine Code Use High Level Language Use Assembler
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
10
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.
11
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.
12
Writing in Assembler label instruction operand(s) ;comment Assembler format: ;now switch on red led Start bsf status,5 ;select memory bank 1 addwf counter For example: labelcomment operands commentLeft-most space optional instruction
13
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. Assembler DirectiveSummary of Action listimplement a listing option* #includeinclude additional source file orgset program origin equdefine an assembly constant; this allows us to assign a value to a label endend program block Example MPASM Directives
14
Representing Numbers RadixExample Representation Decimal D ‘ 255 ’ Hexadecimal H ‘ 8d ’ or Ox8d Octal O ‘ 574 ’ Binary B ‘ 01011100 ’ ASCII ‘ G ’ or A ‘ G ’
15
Assembler File Structure (Simple Form) For us, this will be MPLAB Written by you, as a text file, in Assembler format Files that the Assembler (e.g. MPLAB) generates Source File Assembler Executable File List File Error File.asm.hex.lst.err
16
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 startbsfstatus,5 ;select memory bank 1 movlwB'00011000' movwftrisa;port A according to above pattern movlw00 movwftrisb;all port B bits output bcfstatus,5 ;select bank 0 ; ;The “main” program starts here clrf porta;clear all bits in ports A loopmovfporta,0;move port A to W register movwfportb;move W register to port B gotoloop end Opening explanatory comments SFR locations specified, by equating labels to numbers, taken directly from RAM memory map Initialisation Actual Program Program start address specified Directive specifying processor
17
Software MPLAB v8.00 “ASSEMBLER+ SIMULTATOR”
18
Software IC-Prog1.05” programmer software
19
Software Pic simulator
20
Software Proteus V7.1 “simulator for circuits”
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.