Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

pleaaaase help me to make comments on the code.

Status
Not open for further replies.

1050744

Newbie level 3
Joined
Jan 22, 2010
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
palestine
Activity points
1,341
hi all
I need ur service to make comments on the following code (explain each line in the code). and please send the comments on the following mail:
abu_alrub1987@yahoo.com
thnx alot
the code is for ISD4003:


ISD4003 Code:


/* PREPROCESSOR STUFF */
#case
#include <16F877a.H>
/* clk is 20MHz */
#use Delay(Clock=20000000)
/* no watchdog timer, no code protect, yes power up timer */
#fuses HS, NOWDT, NOPROTECT, PUT
/* set port directions manually */
#use fast_io(A)
#use fast_io(B)

#define LED_1 PIN_B6
#define LED_2 PIN_B7
#define VOICE_SS PIN_B3
#define PUSH_REC PIN_A1
#define PUSH_PLAY PIN_A4
#define PUSH_STOP PIN_A5

#define T_PUD 25 /* Power Up Delay Time to wait ( miliseconds ) */
#define POWER_UP_CMD 0b00100000
#define POWER_DN_CMD 0b00010000
#define STRT_RECORD_CMD 0b10110000
#define STOP_RECORD_CMD 0b00110000
#define STRT_PLAY_CMD 0b11110000
#define STOP_PLAY_CMD 0b00110000
#define INIT_MSG_CUE_CMD 0b11101000
#define STRT_MSG_CUE_CMD 0b11111000


void power_up_voice() { /*this function is used to
give power to PIC*/



output_low(VOICE_SS); /*let pin B3 of the PIC low*/
spi_write( 0x00 ); /*blank address*/
spi_write( POWER_UP_CMD); /* Send data via SPI*/
output_high( VOICE_SS ); /*let pin B3 of the PIC high*/
delay_ms( T_PUD * 4 ); /* give some extra time to power up operation */
}

void power_down_voice() { /* this function is used to
decrease power of PIC*/


output_low( VOICE_SS ); /*let pin B3 of the PIC low*/
spi_write( 0x00 ); /*blank address*/
spi_write( POWER_DN_CMD ); /* Send data via SPI*/
output_high( VOICE_SS ); /*let pin B3 of the PIC high*/
}


/* Function will record at the current address
messages should be cued to the last one before initiating a new record operation
*/

void start_record_voice() { /* to start recording your message*/

output_low( VOICE_SS ); /*let pin B3 of the PIC low*/
spi_write( 0x00 ); /*bLANK ADDRESS */
spi_write( STRT_RECORD_CMD ); /* send data via spi*/
output_high( VOICE_SS ); /*let pin B3 of the PIC high*/
}

void stop_record_voice() { /* for stopping recording messages*/

output_low( VOICE_SS ); /*let pin B3 of the PIC low*/
spi_write( 0x00 ); /*bLANK ADDRESS */
spi_write( STOP_RECORD_CMD ); /* send data via spi*/
output_high( VOICE_SS ); /*let pin B3 of the PIC high*/
delay_ms(100); /* actual time is 50ms. used 100 just in case */
}

void start_play_voice() { /*to start playing message*/

int i;
output_low( VOICE_SS ); /*let pin B3 of the PIC low*/
spi_write( 0x00 ); /*bLANK ADDRESS */
spi_write( STRT_PLAY_CMD ); /* send data via spi*/
delay_ms(10);
output_high( VOICE_SS ); /*let pin B3 of the PIC high*/


/* need to monitor for end of message interruption not done yet
will just wait for now

for (i=0;i<10;i++)
delay_ms( 1000 );
*/
}

void stop_play_voice() { /*to stop playing the message*/

output_low( VOICE_SS ); /*let pin B3 of the PIC low*/
spi_write( 0x00 ); /*bLANK ADDRESS */
spi_write( STOP_PLAY_CMD ); /* send data via spi*/
output_high( VOICE_SS ); /*let pin B3 of the PIC high*/
delay_ms(100); /* actual time is 50ms. used 100 just in case */
}

/* fUNCTION that initializes cueing mode.
Jumps to the beggining of the messages.
*/

void init_message_cue_voice() {

output_low( VOICE_SS );
spi_write( 0x00 );
spi_write( INIT_MSG_CUE_CMD);
output_high( VOICE_SS );
delay_ms(20);
}


/* Function that starts message cueing.
Will play from last message
init_message_cue_voice() has to be invoqued first to play first message
*/

void start_message_cue_voice() {

output_low( VOICE_SS );
spi_write( 0x00 );
spi_write( STRT_MSG_CUE_CMD);
output_high( VOICE_SS );
delay_ms(20);
}


test_LED() {
output_high(LED_1); /*pin B6 of the pic will be high*/
output_low(LED_1); /* pin B6 of the pic will be low*/
delay_ms(200); /* wait for 200ms*/
output_high(LED_1); /*pin B6 of the pic will be high*/
delay_ms(200); /* wait for 200ms*/
}


void record_addr_test() {
output_low( VOICE_SS );
delay_us(25);
spi_write( 0x00 );
spi_write( 0x05 ); /*inv 00000101 */
delay_us(25);
output_high( VOICE_SS );
delay_us(50);
}


void stop_test() {
output_low( VOICE_SS );
delay_us(25);
spi_write( 0x00 );
spi_write( 0x0C ); /*inv 00001100 */
delay_us(25);
output_high( VOICE_SS );
delay_us(25);
}

void play_addr_test() {
output_low( VOICE_SS );
delay_us(25);
spi_write( 0x00 );
spi_write( 0x07 ); /* 00000111 */
delay_us(25);
output_high( VOICE_SS );
delay_ms(25);
}


void power_up_voice_test() {

/*#define POWER_UP_CMD 0b0010 0000
0000 0100 */
output_low(VOICE_SS);
delay_us(25);
spi_write( 0x00 );
spi_write( 0x04 );
delay_us(25);
output_high( VOICE_SS );
delay_ms( T_PUD * 4 ); /* give some extra time to power up operation */
}


main()
{

int i;
/* INIT SEQUENCE */
/* enable timer interrupt
counter incr happens every 8M/4/128
interrupt is every 256 counts, 61 interrupts/sec */
set_rtcc(0);
setup_counters(RTCC_INTERNAL, RTCC_DIV_128);
/*
enable_interrupts(RTCC_ZERO);
enable_interrupts(GLOBAL);
*/

/* set direction of ports*/
set_tris_a(0b00110010);
set_tris_b(0x00);
set_tris_c(0b00010000);

output_high( VOICE_SS );
setup_spi(SPI_MASTER | SPI_L_TO_H | SPI_CLK_DIV_16 ); /*SPI mode 1*/
delay_ms(400);
output_low( VOICE_SS );
output_high( VOICE_SS );
delay_ms(400);
for(i=0;i<4;i++) test_LED();
for(i=0;i<250;i++) {
output_high(VOICE_SS);
delay_us(25);
output_low(VOICE_SS);
delay_us(25);}
output_high(VOICE_SS);
output_high(VOICE_SS);

/* power_up_voice(); */



power_up_voice_test();
delay_ms(100);
power_up_voice_test();
delay_ms(400);

do{


if( input( PUSH_REC ) == 0 ) {
delay_ms(400);
/* start_record_voice(); */

record_addr_test();
output_low(LED_2);
}
else if ( input( PUSH_PLAY ) == 0 ) {
/*
stop_play_voice();
init_message_cue_voice();
start_play_voice();
start_message_cue_voice();
start_play_voice();
*/
delay_ms(400);
output_low( LED_2);
play_addr_test();
delay_ms(5000);


}
else if ( input( PUSH_STOP ) == 0 ) {
delay_ms(10);
stop_test();
output_high(LED_2);
}

test_LED();
}while(1);

}
 

ohhhhhh:D:D:D:D:D
Sorry man,
Just ask ur doubt:!::!::!::!:
 

anandpv2009 is right and you have already add comments on your code.
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top