0% found this document useful (0 votes)
8 views9 pages

Assignment 3

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views9 pages

Assignment 3

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

University of Science and technology

Biomedical engineering
Embedded Systems

Assignment - 3

Supervisor : Eng. Ammar Kord


By Students :

- Abdullah AL-Qahtani

- Hasan Ali Mohammed

- 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)

2. Observe the functions of the MOVLW and MOVWF using the


debugger .

(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

The schematic capture:

(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.

7. Write a similar code using C, (use MikroC pro).

#include <16F877A.h> // Include the PIC16F877A header file


#fuses HS, NOWDT, NOPROTECT // Set the necessary fuses
#use delay(clock=20000000) // Set clock frequency
int COUNT1 = 0; // Variable to simulate COUNT1
int COUNT2 = 0; // Variable to simulate COUNT2
void delay3)({
for (COUNT1 = 0; COUNT1 < 31; COUNT1++); // Simple delay loop
for (COUNT2 = 0; COUNT2 < 31; COUNT2++); // Simple delay loop}
void main )({
// Configure PORTB and PORTD
TRISBbits.TRISB0 = 0; // Set RB0 as output
TRISBbits.TRISB1 = 0; // Set RB1 as output
TRISDbits.TRISD0 = 1; // Set RD0 as input
while (1) { // Main loop
PORTBbits.RB0 = 0; // Clear RB0
if (PORTDbits.RD0 == 1) { // If RD0 is high
blink;)(
} else { // If RD0 is low
change_count_value;)(
}
}
}

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
}

void change_count_value )({


COUNT2 = 0x1F; // Set COUNT2 to 0x1F
blink(); // Call blink function
}

You might also like