EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Topics / combine two codes

combine two codes

|

Microcontroller › PIC › combine two codes

  • This topic has 2 replies, 3 voices, and was last updated 13 years, 1 month ago by AJISH ALFRED.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • May 16, 2012 at 10:53 pm #1805
    erik
    Participant

    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;

                                                                                                                                                                    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;

                                                                                                                                                                    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){

          delayCNT    =score;

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

          delayCNT;

          delayby10ms(dur);

          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));

                }

    }

     

    May 17, 2012 at 11:28 am #7846
    Amrith
    Participant

    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.

    May 17, 2012 at 5:43 pm #7848
    AJISH ALFRED
    Participant

     

    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.

  • Author
    Posts
Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • Curved lines in PCB design June 15, 2025
  • Wideband matching an electrically short bowtie antenna; 50 ohm, 434 MHz June 15, 2025
  • using a RTC in SF basic June 15, 2025
  • PIC KIT 3 not able to program dsPIC June 15, 2025
  • Siemens large industrial PLC parts June 15, 2025

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise