I am doing a project, 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:
Expand|Select|Wrap|Line Numbers
- #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!