Sign in to follow this  
Help_Me

Anyone can help me with my source code?

Recommended Posts

Hello everyone! I am doing Digital Compass Navigation Aids. It consists of the 1490 Digital Compass, a P18F4620 Microcontroller, ISD2560 voice record/playback chip LM4808M amplifier, 5volts and 3.3volts voltage regulators and three switches, the recording switch, the playback switch. First, i should record north, south, east and west into the chip by pressing SW3. Then by pressing SW4, it should playback my voice. My objectives are to create a portable device that can be used by the blind to keep track of their direction of travels. Eg. When the blind man is facing north, the device should playback "north". Using MPLAB IDE v7.40 - C Language. My problem: When the record button is pressed, voice is not recorded in the chip. The code for the playback button is also not working. Here is my code: #include <p18f4620.h> //for special function register declarations #include <portb.h> //for the RB0/INT0 interrupt //#include<adc.h> //#include<stdlib.h> #include <delays.h> #define PR PORTCbits.RC2 //name PORTCbits.RC2 as PR #define PD PORTDbits.RD7 //name PORTDbits.RD7 as PD #define CE_ PORTDbits.RD6 //name PORTDbits.RD6 as CE_ #define EOM_ PORTCbits.RC3 //#define EOM_ PORTCbits.RC3 void Init(void) //re-initialize the PORTs { PD=1; CE_=1; PR=1; PORTCbits.RC4 = 0; PORTBbits.RB5 = 0; PORTBbits.RB4 = 0; PORTBbits.RB3 = 0; PORTAbits.RA5 = 0; PORTAbits.RA4 = 1; PORTEbits.RE2 = 0; PORTEbits.RE1 = 0; PORTEbits.RE0 = 0; } void Mode(void) { CE_=0; //to start record/playback Delay10KTCYx (25); CE_=1; //take CE back to high to stop record/playback } void AddressNorth (void) //address code for North { PORTCbits.RC4 = 0; PORTBbits.RB5 = 0; PORTBbits.RB4 = 0; PORTBbits.RB3 = 1; PORTAbits.RA5 = 1; PORTAbits.RA4 = 0; PORTEbits.RE2 = 0; PORTEbits.RE1 = 1; PORTEbits.RE0 = 0; } void AddressEast (void) //address code for East { PORTCbits.RC4 = 0; PORTBbits.RB5 = 0; PORTBbits.RB4 = 1; PORTBbits.RB3 = 1; PORTAbits.RA5 = 0; PORTAbits.RA4 = 0; PORTEbits.RE2 = 1; PORTEbits.RE1 = 0; PORTEbits.RE0 = 0; } void AddressSouth (void) //address code for South { PORTCbits.RC4 = 0; PORTBbits.RB5 = 1; PORTBbits.RB4 = 0; PORTBbits.RB3 = 0; PORTAbits.RA5 = 1; PORTAbits.RA4 = 0; PORTEbits.RE2 = 1; PORTEbits.RE1 = 1; PORTEbits.RE0 = 0; } void AddressWest (void) //address code for West { PORTCbits.RC4 = 0; PORTBbits.RB5 = 1; PORTBbits.RB4 = 1; PORTBbits.RB3 = 0; PORTAbits.RA5 = 0; PORTAbits.RA4 = 1; PORTEbits.RE2 = 0; PORTEbits.RE1 = 0; PORTEbits.RE0 = 0; } void Record (void); void Playback (void); #pragma code HIGH_INTERRUPT_VECTOR = 0x8 void high_ISR(void) { if(INTCONbits.INT0IF) //to set the interrupt routines { _asm goto Record _endasm } if(INTCON3bits.INT1IF) //to set the interrupt routines { _asm goto Playback _endasm } } #pragma code //allow the linker to locate the remaining code #pragma interrupt Record void Record(void) { PD=0; //take PD to low state Delay10KTCYx(30); PR=0; //take PR to low state // Delay10KTCYx (25); if(PORTA ==0x16) //to set the address memory { AddressNorth(); } if(PORTA ==0x1C) //to set the address memory { AddressEast(); } if(PORTA ==0x19) //to set the address memory { AddressSouth(); } if(PORTA ==0x13) //to set the address memory { AddressWest(); } PR=0; //take PR pin to low CE_=0; //take CE_ pin to low Mode(); //to define the mode EOM_=1; //to define the mode Delay10KTCYx (13); while(!PORTBbits.RB0) { INTCONbits.INT0IF=0; //clear flag to avoid another interrupt Init(); // call Init routine (to initialize) } } #pragma interrupt Playback void Playback(void) { PD=0; //take PD to low state PR=1; //take PR to high state if(PORTA ==0x16) //to set the address memory { AddressNorth(); } if(PORTA ==0x1C) //to set the address memory { AddressEast(); } if(PORTA ==0x19) //to set the address memory { AddressSouth(); } if(PORTA ==0x13) //to set the address memory { AddressWest(); } // PD=0; //set PD to low // PR=1; //take PR to high // Delay10KTCYx (300); CE_=1; // CE_=0; // Delay10KTCYx (30); // CE_=1; Mode(); //to define the mode while(!PORTBbits.RB1) { INTCON3bits.INT1IF=0; //clear flag to avoid another interrupt Init(); //call Init routine (to initialize) } } void EnableHighInterrupts(void) { RCONbits.IPEN =1; //enable interrupt priority levels INTCONbits.GIEH=1; //enable all high priority interrupts //INTCON3bits.INT2IP=1; } void WaitForButton(void) { INTCONbits.RBIF=0; //set INTCONbits.RBIF back to low Init(); //call Init routine (to initialize) while(1); //wait for the SW3 button to be pressed } void main(void) { /*Initializing PORTA*/ LATA = 0x00; //Initialize PortA by clearing output data latches PORTA = 0x00; ADCON1 = 0x0F; //Configure A/D for digital inputs TRISA = 0x0F; //RA<3:0> as inputs, RA<4:5> as outputs //RA<6:7> as "0" when not used as port pins CMCON = 0x07; //Configure comparators for digital inputs /*Initializing PORTB*/ LATB = 0x00; //Initialize PortB by clearing output data latches TRISB = 0xC7; //RB<2:0> & RB<7:6> as input, RB<5:3> as outputs /*Initializing PORTC*/ LATC = 0x00; //Initialize PortC by clearing output data latches TRISC = 0x20; //RC5 as inputs, RC<7:6> & RC<4:0> as outputs /*Initializing PORTD*/ //PORTD = 0x00; LATD = 0x00; //Initialize PortD by clearing output data latches TRISD = 0x00; //RD<7:0> as outputs /*Initializing PORTE*/ LATE = 0x00; //Initialize PortE by clearing output data latches TRISE = 0x00; //RE<7:0> as outputs */ EnableHighInterrupts(); OpenRB0INT(PORTB_CHANGE_INT_ON & //enable the RB0/INT0 interrupt PORTB_PULLUPS_ON & //configure the RB0 pin for input FALLING_EDGE_INT); //trigger interrupt upon SW3 button //depression OpenRB1INT(PORTB_CHANGE_INT_ON & //enable the RB1/INT0 interrupt PORTB_PULLUPS_ON & //configure the RB1 pin for input FALLING_EDGE_INT); //trigger interrupt upon SW3 button depression WaitForButton(); } Please correct my source code. Million Thanks

Share this post


Link to post
Share on other sites
Quote:

Please correct my source code.

Sorry, no.

First of all, we don't help directly with homework, and that's what this sounds like. Second of all, your source code is poorly formatted (use the "source" and "/source" tags, replacing quotes with square brackets). Thirdly, your problem is poorly documented (what does "doesn't work" mean; what did you expect to see, and at what point during execution, and what did you see instead? In the case of a compiler error, what was the error and where was it?)

Provide more specific information and somebody might be able to give you some guidance, but it's highly unlikely that anybody is going to come along and correct your code wholesale for you. That's your job.

Share this post


Link to post
Share on other sites
Nobody can help you with hardware issues.

The code you posted is some low-level driver code which most likely doesn't work because of some detail - interrupt not firing, data getting garbled, constants set incorrectly, or something else.

There is simply no way to know why it doesn't work. Unless someone happened to have used the same hardware before, but given the rarity of the chipset I somehow doubt it.

Also, MPLAB is a staple tool frequently used in schools, so the chance of this being homework related is incredibly high.

Share this post


Link to post
Share on other sites
You realize there are forums from Microchip specifically for your choice of micro controller, right? That said, I doubt even they will take the time to figure out what's going on without you doing a little bit more work on narrowing the problem down.

Share this post


Link to post
Share on other sites
Thanks for replying.

As for the hardware, it is working. I am only having problems with the software.
Regarding my project, they are not my homework. I hope i can help the blind more as the market has very few deice that can help the blind to find their direction. So this is my project work.

I am looking for help here because i don't know much about C language and i still trying to learn more about it.

Anyone here knows any interrupt routine in C code for ISD2560 (voicerecord/playback chip)?

Your help will be very much appreciated.
Thanks

Share this post


Link to post
Share on other sites
Finding the correcting the faults in your code isn't as simple as reading it over and easily finding it. Depending on the fault you'd probably need to read the datasheets for the digital compass and the voice record/playback chip and look at the circuit diagram (to see how the PIC is actually connected to everything else).

Personally I suggest getting an oscilloscope or logic analyser hooking it up to your circuit and seeing if the various pins are outputting what you think they're outputting (i.e. to start recording on your voice chip, you might hold some pin high and put an address to record the voice to on some other pins, so when you press the record button see if this happens, and if not work out why not). You can also run your code in the MPLab emulator, of course it won't emulate the stuff external to the PIC but you should be able to at least see if it's doing the correct things with the pins. You can also get in-circuit debuggers which can help a lot.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this