The answers for questions 1 to 7 inclusive are contained within the course notes.
What is the purpose of:
What are the stages in developing an assembly language program?
What is the purpose of the EQU directive?
What is the purpose of the ORG directive?
What is the purpose of the Status register?
Why is a reset vector necessary in a microprocessor/microcontroller system and how does it work in the case of the PIC16F84?
What is the purpose of a stack in a microcontroller?
Explain the function (and outcome) of the following PIC instructions:
BSF porta,3
sets bit 3 of portA (XXXX 1XXX) - where 'X' remains unchanged
BCF porta,5
Clears bit 5 of portA (XX0X XXXX) - where 'X' remains unchanged
GOTO 0004
Transfers program control to the instruction at address 0004.
BTSS portb,7
Test bit 7 of portB and skip the next instruction if bit 7 is set
BTSC portb,0
Test bit 0 of portB and skip the next instruction if bit 0 is clear
MOVLW 56h
Place the literal 56h (0101 0110) into the W register
MOVWF option
Move the contents of the W register into the option register
CLRW
Clear (set to zero) all bits of the W register
CLRF porta
Clear the contents of the Port A (assumed to be configured as an output port).
ANDLW FEh
Logically AND the contents of the W register with the literal FEh.
IORLW 01h
Logically OR the contents of the W register with the literal 01h
XORWF porta
Exclusive Or the contents of the W register with portA (assumed to be an input port).
INCF W,0
Add one to the W register.
DECF portb,1
Subtract one from portB (assumed to be configured as an output port).
NOP
No Operation instruction. Used during program development or to pad out a program for specific execution time.
RETURN
Return from the sub program. The last instruction of a sub program should be this instruction (or the RETFIE instruction).
SUBLW 09h
Subtract W register from the literal 09h. i.e., 09h - W.
RRF reg1,0
Rotate contents of reg1 right by one bit into the carry and place the result into the W register (because d=0).
RLF reg1,1
Rotate the contents of reg1 left by one bit into the carry and place the result into reg1 (because d=1).
SWAPF option,0
Exchange upper and lower four bits (nibbles) of the option register and place the result into the W register.
DECFSZ count,1
Subtract one from the counter register and place the result of the subtraction into the count register.
DECFSZ count,0
Subtract one from the counter register and place the result of the subtraction into the W register.
INCFSZ count,1
Add one to the count register and place the result into the count register.
Consider the following segments of PIC assembly language program and determine what they are doing:
| BSF MOVLW MOVWF BCF |
STATUS,5 5Ah TRISB STATUS,5 |
5Ah = 0101 1010 in binary
This code sets up portB so that bits 7, 5, 2, and 0 are output bits. The rest are input bits
| MOVLW ANDLW |
EEh 75h |
Logically AND the literal value 75h with the contents of W register (EEh) giving
1110 1110 (EEh) = W 0111 0101 (75h) = Literal 0110 0100 (64h) = Result in the w register.
| MOVF IORLW MOVF |
porta,0 81h porta |
Logically OR the data of port A (moved into the W register for the operation) with the literal value 81h, giving:-
XXXX XXXX W 1000 0001 literal 81h 1XXX XXX1 The result is to set bits 7 and 0. The rest remains unchanged.
nxt |
MOVLW MOVWF DECFSZ GOTO BSF |
FFh count count nxt portb,7 |
FFh (1111 1111) is loaded into the register named 'count'. This value is then decremented until it reaches zero via the 'nxt' loop.
Program completes the loop 255 times before setting bit 7 of portB.
Convert the program fragment of question 9d into a sub-program.
| delay | MOVLW | FFh |
| MOVWF | count | |
| nxt | DECFSZ | count |
| GOTO | nxt | |
| BSF | portb,7 | |
| RETURN |
Show how the sub-program of question 9e could be used in a main program.
CALL delay
Updated 20.06.07 ML
Powered by Google
Site Map