Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

i need a help in this code for playing musical note using pic16F877A ,, there is

ID: 3841629 • Letter: I

Question

i need a help in this code for playing musical note using pic16F877A ,, there is a small error which says the ((Error at file ../main.c line 1 column 17: (141) can't open include file ""xc.h"": Invalid argument )). this is the code witch i entered

#include <"xc.h">

void Sound_Play(unsigned freq_in_hz, unsigned duration_ms);
void Tone1()
{
Sound_Play(659, 250); // Frequency = 659Hz, duration = 250ms
}
void Tone2() {
Sound_Play(698, 250); // Frequency = 698Hz, duration = 250ms
}
void Tone3() {
Sound_Play(784, 250); // Frequency = 784Hz, duration = 250ms
}
void Melody() { // Plays the melody "Yellow house"
Tone1(); Tone2(); Tone3(); Tone3();
Tone1(); Tone2(); Tone3(); Tone3();
Tone1(); Tone2(); Tone3();
Tone1(); Tone2(); Tone3(); Tone3();
Tone1(); Tone2(); Tone3();
Tone3(); Tone3(); Tone2(); Tone2(); Tone1();
}
void ToneA() {
Sound_Play( 880, 50);
}
void ToneC() {
Sound_Play(1046, 50);
}
void ToneE() {
Sound_Play(1318, 50);
}

void Melody2() {
unsigned short i;
for (i = 9; i > 0; i--) {
ToneA(); ToneC(); ToneE();
}
}

void main() {

TRISB = 0xF8; // Configure RB7..RB3 as input

Sound_Init(&PORTC, 3);
Sound_Play(880, 1000); // Play sound at 880Hz for 1 second

while (1) {
if (Button(&PORTB,7,1,1)) // RB7 plays Tone1
Tone1();
while (RB7_bit) ; // Wait for button to be released

if (Button(&PORTB,6,1,1)) // RB6 plays Tone2
Tone2();
while (RB6_bit) ; // Wait for button to be released

if (Button(&PORTB,5,1,1)) // RB5 plays Tone3
Tone3();
while (RB5_bit) ; // Wait for button to be released

if (Button(&PORTB,4,1,1)) // RB4 plays Melody2
Melody2();
while (RB4_bit) ; // Wait for button to be released

if (Button(&PORTB,3,1,1)) // RB3 plays Melody
Melody();
while (RB3_bit) ; // Wait for button to be released
}
}

Explanation / Answer

Hi,

Your code seems to be correct to me. The error could be due to below reasons-

1. Use the below syntax to include user defined header files-

#include "xc.h" (Remove the brackets <>)

2. Keep the xc.h file in the same path where you have kept the main driver program.

Please check with above points. If the issue still exists, please revert back.

Regards,

Vinay Singh