473,385 Members | 2,015 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Can anyone help me with my source code?

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
4 2690
AdrianH
1,251 Expert 1GB
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
JosAH
11,448 Expert 8TB
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
Polar
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
9,065 Expert Mod 8TB
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

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

Similar topics

0
by: Jim Kerr | last post by:
I am trying to reconstruct Python source files from an application I generated from py2exe. I accidentally deleted the sources for the app, but the py2exe-generated executable contains .pyc files...
0
by: Carlo Chung | last post by:
I urgently require the source code of xp_gettable_dblib, which is a sample program under the path of SQL installation. When I was going to locate it, I discovered that I haven't installed it during...
1
by: RC | last post by:
It would be nice to have an editor or "source safe" that tracks changes and shows relationships between things like "If" and "End If". Anyone know of any other possibilities? I found one but I...
0
by: ColinWard | last post by:
the title is self explanatory. However although I have figured out how to implement the add-in from code, it consistently fails with the message. "There is no active worksheet". I tried opening...
1
by: Diffident | last post by:
Hello All, I am encountering a strange behavior which I want the MSDN stalwarts to explain me in detail and your explanation is highly appreciated. I have a User Control which is dynamically...
7
by: changs | last post by:
Hi, all I have a asm code, I suspect it sort of socket programming. Can anyone here give some instructions on how to determine the function or give the psudo-code in C? Thanks in advance! ...
4
by: Podi | last post by:
Hi, I am trying to copy all files under a directory tree to a single directory (in Windows). I can well write the script myself, but was wonder if anyone has done it so I won't be reinventing...
66
by: QuantumG | last post by:
Decompilation is the process of recovering human readable source code from a program executable. Many decompilers exist for Java and .NET as the program executables (class files) maintain much of...
6
by: dr | last post by:
does anyone see what is wrong with my .gif download logic? no matter what image url i try it downloads a junk file that can't be opened in any paint program. System.Net.WebRequest myRequest =...
12
by: Philip | last post by:
Does anyone know any commercial C++/CLI GUI library with source code? Thank you very much.
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.