Assignment 3
Assignment 3
Biomedical engineering
Embedded Systems
Assignment - 3
- Abdullah AL-Qahtani
- Khaled Nabil
- Waleed Nasser
2024 – 2025
1
1. Refer to the datasheet and find out what are the functions of
each new instruction in this code.
- MOVWF: Move W to F
- MOVLW: Move L to W
- BTFSC: Test a bit in F and Skip next instruction if it is clear (=0)
- BTFSS: Test a bit in F and Skip next instruction if it is set (=1)
(Figure 1)
2
(Figure 2)
3
3. Change the input from pin 0 in PORTD to pin 1 in PORTA.
The code:
CBLOCK h'20'
COUNT1
COUNT2
ENDC
ORG 0x00
MAIN:
BANKSEL TRISB
BCF TRISB,0
BCF TRISB,1
BANKSEL TRISA
BSF TRISA,1
BANKSEL PORTB
MainLoop:
BCF PORTB, 0
BANKSEL PORTA
BTFSC PORTA,1
GOTO Blink
BTFSS PORTA,1
GOTO CHANGE_COUNT_VALUE
GOTO MainLoop ; Do it again...
Blink:
BANKSEL PORTB
BCF PORTB,0
BSF PORTB,1
CALL DELAY3
BSF PORTB,0
BCF PORTB,1
CALL DELAY3
GOTO MainLoop
CHANGE_COUNT_VALUE:
MOVLW 0X1F
MOVWF COUNT2
GOTO Blink
DELAY3:
DECFSZ COUNT1,1
GOTO DELAY3
DECFSZ COUNT2,1
GOTO DELAY3
RETURN
END
4
The schematic capture:
(Figure 3)
5
4. Change the output pins from PORTB to PORTD.
THE CODE :
#include p16f877a.inc ; Include register definition file
CBLOCK h'20'
COUNT1
COUNT2
ENDC
ORG 0x00
MAIN:
BANKSEL TRISD
BCF TRISD,0
BCF TRISD,1
BANKSEL TRISA
BSF TRISA,1
BANKSEL PORTD
MainLoop:
BCF PORTD, 0
BANKSEL PORTA
BTFSC PORTA,1
GOTO Blink
BTFSS PORTA,1
GOTO CHANGE_COUNT_VALUE
GOTO MainLoop ; Do it again...
Blink:
BANKSEL PORTD
BCF PORTD,0
BSF PORTD,1
CALL DELAY3
BSF PORTD,0
BCF PORTD,1
CALL DELAY3
GOTO MainLoop
CHANGE_COUNT_VALUE:
6
MOVLW 0X1F
MOVWF COUNT2
GOTO Blink
DELAY3:
DECFSZ COUNT1,1
GOTO DELAY3
DECFSZ COUNT2,1
GOTO DELAY3
RETURN
END
(Figure 4)
5. Add a third speed to the mixer, you can use three buttons or
two buttons.
7
6. Use the debugger to find out if you can exit from the delay
subroutine (function) when the button is pressed .
You cannot exit the delay even if you press the button. It keeps
counting and you keep pressing and pressing the button until you
complete the delay.
void blink)({
PORTBbits.RB0 = 0; // Clear RB0
8
PORTBbits.RB1 = 1; // Set RB1
delay3(); // Call delay
PORTBbits.RB0 = 1; // Set RB0
PORTBbits.RB1 = 0; // Clear RB1
delay3(); // Call delay
}