Arduino Projects    |   Raspberry Pi  |     Electronic Circuits   |   Electronics Reference Design Library  |   AVR    |    PIC    |    8051    |    Electronic Projects

combine two codes

3 posts / 0 new
Last post
erik
erikb1984's picture
Offline
Joined: 07/05/2012
Posts: 1
Points: 0
combine two codes

howdy yall

 

im using a p18.8680 mirocontroller chip in my embedded systems class. we are conducting our final project and my lab partner and i decided to create a toy car for our project. it will actually be a model car with a siren and flashing lights. an emergency police car. we have done a couple of labs already that we are planning on using. my questions is: how can we combine the two codes?

 

we have already tried but we get a couple of errors and are having trouble with it. i am asking yall because if we ask the professor, he will deduct points. :)

 

our "mock" led code:

 

 

#include<p18F8680.h>

#include<delays.h>

char led_tab [8] ={0x7E,0xBD,0xDB,0xE7,

                                                                                0xE7,0xDB,0xBD,0x7E};

void main (void)

{

                                                                unsigned char i;

                                                                TRISD = 0x00;

                                                                while(1){

                                                                                                for (i = 0; i < 8; i++){

                                                                                                                                                                PORTD = led_tab[i];

                                                                                                                                                                Delay10KTCYx(300);

                                                                                                                }

                                                                                }

return;}

#include<p18F8680.h>

#include<delays.h>

char led_tab [8] ={0x7E,0xBD,0xDB,0xE7,

                                                                                0xE7,0xDB,0xBD,0x7E};

void main (void)

{

                                                                unsigned char i;

                                                                TRISD = 0x00;

                                                                while(1){

                                                                                                for (i = 0; i < 8; i++){

                                                                                                                                                                PORTD = led_tab[i];

                                                                                                                                                                Delay10KTCYx(300);

                                                                                                                }

                                                                                }

return;}

 

 

our "mock" siren code, this code is the one from our actual lab:

 

#include    <P18F8680.h>

#define           G3          2551

#define           B3          2025

#define           C4          1911

#define           C4S         1804

#define           D4          1703

#define           E4          1517

#define           F4          1432

#define           F4S         1351

#define           G4          1276

#define           A4          1136

#define           B4F         1073

#define           B4          1012

#define           C5          956

#define           C5S         902

#define           D5          851

#define           E5          758

#define           F5          716

#define           F5S         676

#define           G5          638

#define           SS          60000

 

unsignedint delayCNT;

voiddelayby10ms(unsigned char n);

voidhigh_ISR(void);

voidlow_ISR(void);

#pragmacode high_vector = 0x08 // force the following statement to

voidhigh_interrupt (void)          // start at 0x08

{

      _asm

      goto high_ISR

      _endasm

}

#pragmacode low_vector = 0x18      // force the following statement to

voidlow_interrupt (void)           // start at 0x18

{

      _asm

      goto low_ISR

      _endasm

}

#pragmacode                              // return to the default code section

#pragmainterrupt high_ISR

voidhigh_ISR (void)

{

      if(PIR1bits.CCP1IF){

      PIR1bits.CCP1IF=0;

      CCPR1 +=delayCNT;

      }

}

#pragmacode

#pragmainterrupt low_ISR

voidlow_ISR (void)

{

      _asm

      retfie 0

      _endasm

}

unsignedrom int score[102]= {D4,B3,G3,B3,D4,G4,B4,A4,G4,B3,C4S,

                                    D4,D4,D4,B4,A4,G4,F4S,E4,F4S,G4,G4,D4,B3,G3,

                                    D4,B3,G3,B3,D4,G4,B4,A4,G4,B3,C4S,D4,D4,D4,

                                    B4,A4,G4,F4S,E4,F4S,G4,G4,D4,B3,G3,B4,B4,

                                    B4,C5,D5,D5,C5,B4,A4,B4,C5,C5,C5,B4,A4,G4,

                                    F4S,E4,F4S,G4,B3,C4S,D4,D4,G4,G4,G4,F4S,

                                    E4,E4,E4,A4,C5,B4,A4,G4,G4,F4S,D4,D4,

                                    G4,A4,B4,C5,D5,G4,A4,B4,C5,A4,G4,0};

unsignedrom int dur[101]= {30,10,40,40,40,80,30,10,40,40,40,

                                    80,20,20,60,20,40,80,20,20,40,40,40,40,40,

                                    30,10,40,40,40,80,30,10,40,40,40,80,20,20,

                                    60,20,40,80,20,20,40,40,40,40,40,20,20,

                                    40,40,40,80,20,20,40,40,40,80,40,60,20,40,

                                    80,20,20,40,40,40,80,40,40,40,20,20,

                                    40,40,40,40,20,20,20,20,40,40,20,20,

                                    60,20,20,20,80,20,20,60,20,40,80};

voidmain (void)

{

      unsigned int i;

      unsigned char temp1, temp2;

      INTCONbits.GIE                =0;

      RCONbits.IPEN                 =1;

      IPR1bits.CCP1IP               =1;

      TRISCbits.TRISC2        =0;

      T1CON                         =0xB1;

      T3CON                         =0x81;

      PIE1bits.CCP1IE               =1;

      PIR1bits.CCP1IF               =0;

      INTCON                              =0xC0;

      CCP1CON                             =0x02;

      i                                   =0;

while(score[i]){

      delayCNT    =score[i];

      CCPR1       =(unsigned int)TMR1L + (unsigned int)TMR1H * 256 +

      delayCNT;

      delayby10ms(dur[i]);

      i++;

      }

      CCP1CON                             =0;

      while(1);

}

voiddelayby10ms(unsigned char n)

{

      unsigned char i;

      T0CON                         =0x80;

      for(i=0;i<n;i++){

                        TMR0H       =0x63;

                        TMR0L       =0xC0;

                        INTCONbits.TMR0IF=0;

                        while(!(INTCONbits.TMR0IF));

            }

}

 

Amrith
amrith's picture
Offline
Joined: 23/04/2012
Posts: 224
Points: 1000

Hi Erik,

 

Can you explain the flow of your project through good description or flow chart. It would be easy to understand exact application of you project & to combine your codes.

AJISH ALFRED
ajishalfred's picture
Offline
Joined: 10/01/2012
Posts: 1490
Points: 7085

 

Hi Erik,

               Whatever code you write, make it a habit to comment it properly. It will help others to understand your logic. Try commenting line by line, atleast block by block.

                You will surely get help from this forum. All the best.

Login or register to post comments

APPLICATIONS & TECHNOLOGIES

Learn about the latest applications and industry trends with tutorials and white paper design resources on vertical markets.

Automotive
Energy Harvesting
MEMS Technology
OpenSource Hardware
RFID & NFC
RF Wireless
Sensor
Solar
Touch
Wireless Charging

 

You are here