Write the assembly instructions / functions for the following operations. Note y
ID: 3550330 • Letter: W
Question
Write the assembly instructions / functions for the following operations. Note you do not have to write a working program. For example, part (a) can be just an instruction and you do not have to include ORG, EQU etc.
Turn on bit 3 of PORTC.
Turn off bit 3 of PORTC.
Have a delay of between 1 ms and 2 ms (it can be anything like a 4 digits 1xxx ?s).
Add up three integers a, b, and c each between decimal 15 and 30 (you specify a, b and c yourself, in hex or in decimal as you like).
Write the C instructions / functions for the following operations. Note you do not have to write a working program. For example, part (a) can be a #define instruction and an instruction to set a variable to 1 in C language. You do not need to include the instruction #include <PIC18F458.h>
Turn on bit 3 of PORTC.
Turn off bit 3 of PORTC.
Have a delay of between 100 ms and 200 ms (it can be anything like a 3 digits 1xx ?s).
Add up three integers a, b, and c each between decimal 15 and 30 (you specify a, b and c yourself, in hex or in decimal as you like).
Toggling data in PORTB
The book had shown how PORTB data can be toggled between 0x55 and 0xAA (which is one
Explanation / Answer
1) 1)Turning portC on:
movlw B'00001000'
movwf PORTC
2)Turning portC off:
movlw B'00000000'
movwf PORTC
3) For 1ms delay
Delay:movlw .048 ; outer counter value
movwf K ; store it in the "K" register
clrf J
delay1: nop
decfsz J,f
goto delay1
delay2: nop
decfsz J,f
goto delay2
decfsz K,f
goto delay1
For 2ms delay
Delay:movlw .097 ; outer counter value
movwf K ; store it in the "K" register
clrf J
delay1: nop
decfsz J,f
goto delay1
delay2: nop
decfsz J,f
goto delay2
decfsz K,f
goto delay1
4) Adding a,b,c. adding 20+21+22
declaring them:
a equ 0x73
b equ 0x74
c equ 0x75
main: movlw d'20'
movwf a
movlw d'21'
addwf a,1 ; storing value in a again
movlw d'22'
addwf a,1
2) C instructions:
5) PortC on:
PORTC=0x08;
6) PORTC off:
PORTC=0x00;
7) delay_ms(100);
delay_ms(200);
8)
int a = 20;
int b = 21;
int c = 22;
int y=0;
y = a+b+c;
4) first method:
PORTB EQU 0x0F8
ORG 0
BACK MOVLW 0x57
MOVWF PORTB
MOVLW 0xAA
MOVWF PORTB
GOTO BACK
END
Second method:
PORTB EQU 0x0F8
PORTC EQU 0x0F9
ORG 0
MOVLW 0x57
BACK MOVWF PORTB
COMF PORTB
MOVF PORTB,0
GOTO BACK
END
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.