By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,853 Members | 992 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,853 IT Pros & Developers. It's quick & easy.

Can anyone help me with my source code?

P: 26
Hello everyone! I'm new here.

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
  1. #include <p18f4620.h> //for special function register declarations
  2. #include <portb.h>   //for the RB0/INT0 interrupt
  3. //#include<adc.h>
  4. //#include<stdlib.h>
  5. #include <delays.h>
  6. #define PR PORTCbits.RC2   //name PORTCbits.RC2 as PR
  7. #define PD PORTDbits.RD7  //name PORTDbits.RD7 as PD
  8. #define CE_ PORTDbits.RD6  //name PORTDbits.RD6 as CE_
  9. #define EOM_ PORTCbits.RC3      //#define EOM_ PORTCbits.RC3
  10.  
  11. void Init(void)     //re-initialize the PORTs 
  12. {
  13.  PD=1;
  14.  CE_=1;
  15.  PR=1;
  16.  PORTCbits.RC4 = 0;
  17.  PORTBbits.RB5 = 0;
  18.  PORTBbits.RB4 = 0;
  19.  PORTBbits.RB3 = 0;
  20.  PORTAbits.RA5 = 0;
  21.  PORTAbits.RA4 = 1;
  22.  PORTEbits.RE2 = 0;
  23.  PORTEbits.RE1 = 0;
  24.  PORTEbits.RE0 = 0;
  25. }
  26. void Mode(void)
  27. {
  28.   CE_=0; //to start record/playback
  29.  Delay10KTCYx (25);
  30.  CE_=1; //take CE back to high to stop record/playback
  31. }
  32. void AddressNorth (void)   //address code for North
  33. {
  34.  PORTCbits.RC4 = 0;
  35.  PORTBbits.RB5 = 0;
  36.  PORTBbits.RB4 = 0;
  37.  PORTBbits.RB3 = 1;
  38.  PORTAbits.RA5 = 1;
  39.  PORTAbits.RA4 = 0;
  40.  PORTEbits.RE2 = 0;
  41.  PORTEbits.RE1 = 1;
  42.  PORTEbits.RE0 = 0;
  43. }
  44. void AddressEast (void)   //address code for East
  45. {
  46.  PORTCbits.RC4 = 0;
  47.  PORTBbits.RB5 = 0;
  48.  PORTBbits.RB4 = 1;
  49.  PORTBbits.RB3 = 1;
  50.  PORTAbits.RA5 = 0;
  51.  PORTAbits.RA4 = 0;
  52.  PORTEbits.RE2 = 1;
  53.  PORTEbits.RE1 = 0;
  54.  PORTEbits.RE0 = 0;
  55. }
  56. void AddressSouth (void)  //address code for South
  57. {
  58.  PORTCbits.RC4 = 0;
  59.  PORTBbits.RB5 = 1;
  60.  PORTBbits.RB4 = 0;
  61.  PORTBbits.RB3 = 0;
  62.  PORTAbits.RA5 = 1;
  63.  PORTAbits.RA4 = 0;
  64.  PORTEbits.RE2 = 1;
  65.  PORTEbits.RE1 = 1;
  66.  PORTEbits.RE0 = 0;
  67. }
  68. void AddressWest (void)   //address code for West
  69. {
  70.  PORTCbits.RC4 = 0;
  71.  PORTBbits.RB5 = 1;
  72.  PORTBbits.RB4 = 1;
  73.  PORTBbits.RB3 = 0;
  74.  PORTAbits.RA5 = 0;
  75.  PORTAbits.RA4 = 1;
  76.  PORTEbits.RE2 = 0;
  77.  PORTEbits.RE1 = 0;
  78.  PORTEbits.RE0 = 0;
  79. }
  80.  
  81. void Record (void);
  82. void Playback (void);
  83. #pragma code HIGH_INTERRUPT_VECTOR = 0x8 
  84. void high_ISR(void)
  85. {
  86.  if(INTCONbits.INT0IF)  //to set the interrupt routines
  87.  {
  88.  _asm
  89.    goto Record
  90.  _endasm 
  91.  }
  92.  if(INTCON3bits.INT1IF)  //to set the interrupt routines
  93.  {
  94.  _asm
  95.   goto Playback
  96.  _endasm
  97.  }
  98. }
  99. #pragma code //allow the linker to locate the remaining code
  100. #pragma interrupt Record
  101. void Record(void)
  102. {
  103.  PD=0;     //take PD to low state 
  104.  Delay10KTCYx(30);
  105.  PR=0;     //take PR to low state
  106.  
  107. // Delay10KTCYx (25);
  108.  if(PORTA ==0x16)    //to set the address memory
  109.  {
  110.   AddressNorth();
  111.  }
  112.  if(PORTA ==0x1C)    //to set the address memory
  113.  {
  114.   AddressEast();
  115.  }
  116.  if(PORTA ==0x19)    //to set the address memory
  117.  {
  118.   AddressSouth();
  119.  }
  120.  if(PORTA ==0x13)    //to set the address memory
  121.  {
  122.   AddressWest();
  123.  }
  124.  PR=0;       //take PR pin to low
  125.  CE_=0;  //take CE_ pin to low
  126.  Mode();  //to define the mode
  127.  EOM_=1;  //to define the mode
  128.  Delay10KTCYx (13);
  129.  while(!PORTBbits.RB0)
  130.  {
  131.   INTCONbits.INT0IF=0; //clear flag to avoid another interrupt
  132.   Init();     // call Init routine (to initialize)
  133.  } 
  134. }
  135. #pragma interrupt Playback
  136. void Playback(void)
  137. {
  138.  PD=0;       //take PD to low state
  139.  PR=1;       //take PR to high state
  140.  if(PORTA ==0x16)                //to set the address memory
  141.  {
  142.   AddressNorth();
  143.  }
  144.  if(PORTA ==0x1C)    //to set the address memory
  145.  {
  146.   AddressEast();
  147.  }
  148.  if(PORTA ==0x19)    //to set the address memory
  149.  {
  150.   AddressSouth();
  151.  }
  152.  if(PORTA ==0x13)    //to set the address memory
  153.  {
  154.   AddressWest();
  155.  }
  156. // PD=0;  //set PD to low
  157. // PR=1;  //take PR to high
  158. // Delay10KTCYx (300);
  159.  CE_=1; 
  160. // CE_=0;
  161. // Delay10KTCYx (30);
  162. // CE_=1;
  163.  Mode();     //to define the mode
  164.  
  165.  while(!PORTBbits.RB1)           
  166.  {
  167.   INTCON3bits.INT1IF=0; //clear flag to avoid another interrupt
  168.   Init(); //call Init routine (to initialize)
  169.  }
  170. }
  171.  
  172. void EnableHighInterrupts(void)
  173. {
  174.  RCONbits.IPEN =1; //enable interrupt priority levels
  175.  INTCONbits.GIEH=1; //enable all high priority interrupts
  176.     //INTCON3bits.INT2IP=1;
  177. }
  178. void WaitForButton(void)
  179.  {
  180.   INTCONbits.RBIF=0; //set INTCONbits.RBIF back to low
  181.   Init(); //call Init routine (to initialize)      
  182.         while(1); //wait for the SW3 button to be pressed
  183.  }  
  184.  
  185. void main(void)
  186. {
  187.  /*Initializing PORTA*/
  188.  LATA = 0x00;   //Initialize PortA by clearing output data latches
  189.   PORTA = 0x00;
  190.  ADCON1 = 0x0F;   //Configure A/D for digital inputs 
  191.  TRISA = 0x0F;    //RA<3:0> as inputs, RA<4:5> as outputs
  192.      //RA<6:7> as "0" when not used as port pins    
  193.  CMCON = 0x07;   //Configure comparators for digital inputs
  194.  /*Initializing PORTB*/    
  195.  LATB = 0x00;   //Initialize PortB by clearing output data latches
  196.  TRISB = 0xC7;    //RB<2:0> & RB<7:6> as input, RB<5:3> as outputs
  197.  
  198.  
  199.  /*Initializing PORTC*/
  200.  LATC = 0x00;   //Initialize PortC by clearing output data latches
  201.  TRISC = 0x20;    //RC5 as inputs, RC<7:6> & RC<4:0> as outputs
  202.  
  203.  /*Initializing PORTD*/
  204.  //PORTD = 0x00;
  205.  LATD = 0x00;   //Initialize PortD by clearing output data latches
  206.  TRISD = 0x00;    //RD<7:0> as outputs
  207.  
  208.  
  209.  /*Initializing PORTE*/
  210.  LATE = 0x00;   //Initialize PortE by clearing output data latches
  211.  TRISE = 0x00;    //RE<7:0> as outputs */
  212.  
  213.  EnableHighInterrupts();
  214.  OpenRB0INT(PORTB_CHANGE_INT_ON & //enable the RB0/INT0 interrupt
  215.       PORTB_PULLUPS_ON & //configure the RB0 pin for input
  216.       FALLING_EDGE_INT); //trigger interrupt upon SW3 button 
  217.           //depression
  218.  OpenRB1INT(PORTB_CHANGE_INT_ON & //enable the RB1/INT0 interrupt
  219.       PORTB_PULLUPS_ON & //configure the RB1 pin for input
  220.       FALLING_EDGE_INT); //trigger interrupt upon SW3 button depression            
  221.  
  222.  
  223.  WaitForButton();
  224.  
  225. }
Sorry for my untidiness.
Please correct my source code.
Million Thanks!
Jun 2 '07 #1
Share this Question
Share on Google+
4 Replies


AdrianH
Expert 100+
P: 1,251
So what, you want us to do your project for you? If you want to hire me, I am a contractor. But nobody is going to look though all of that code for you for free.

If you have specific smaller problems, try posting them instead.


Adrian
Jun 2 '07 #2

Expert 10K+
P: 11,448
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.
Working with those devices takes an intimate knowledge of those devices; I've
been there done that (using those darn Atmel microcontrollers). I know nothing
of the chips set(s) you mentioned though and I doubt you'll find anyone on this
general C/C++ forum who does know anything about it. I recognize the register
fiddling gibberish though and I was wondering whether or not you treat that PR
bit right: you set it to low before recording and set it to low again after the deed.

This is just a guess though; like I wrote: one needs detailed knowledge of the
used chip set(s). Aren't there dedicated forums for them?

kind regards,

Jos
Jun 2 '07 #3

P: 26
Thanks Jos for your reply. I agree that working with those devices takes an intimate knowledge of those devices. I'm in the middle of learning C language and those chips are still new to me. So there's more for me to learn.

As for my project, I hope i can help the blind more as the market has very few deice that can help the blind to find their direction.

Anyone here knows any interrupts rountine code for ISD2560 (voicerecord/playback chip)?

Your help will be very much appreciated.
Thanks
Jun 3 '07 #4

Banfa
Expert Mod 5K+
P: 8,916
I know nothing
of the chips set(s) you mentioned though and I doubt you'll find anyone on this
general C/C++ forum who does know anything about it. I recognize the register
fiddling gibberish though and I was wondering whether or not you treat that PR
bit right: you set it to low before recording and set it to low again after the deed.
It just so happens Jos that the project I am working on at this minute is based on PIC18F2620 micro-controllers, which is the same processor in a different package.

However the problem here is not with the micro-processor but with driving the other devices about which I know nothing.

This function

Expand|Select|Wrap|Line Numbers
  1. void Mode(void)
  2. {
  3.   CE_=0; //to start record/playback
  4.  Delay10KTCYx (25);
  5.  CE_=1; //take CE back to high to stop record/playback
  6. }
Looks suspect, it starts record/playback, waits 250,000 seconds and then stops it again. If you are using a high speed clock you would be pausing for

250,000 / 4,000,000 = 63 milliseconds, not enough time to record or playback anything

at the slow clock speed it would be

250,000 / 32768 = 7.5 seconds, which may be ok

You are leaving yourself open to a maintenance issue if the clock gets changed.

However additionally you are doing this from a high priority interrupt. Pausing in an interrupt is a bad idea, you are preventing your processor doing or responding to anything else at all.

If you need to using timings of this length you should consider switching on timer1 which interrupts at 1/2 second intervals.
Jun 3 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.