dev c++ error/programming

Discussion in 'Programmer's Corner' started by skuzzie, Apr 6, 2009.

  1. skuzzie

    Thread Starter Member

    Feb 11, 2009
    10
    0
    Ok, I am using dev c++ and I have code for a PIC 16f circuit. I am trying to take that code and put it onto a PIC18f425. When I put the code in and try to compile it the first line is an error "1 C:\Dev-Cpp\main.cpp 18f452.h: No such file or directory. "

    Code ( (Unknown Language)):
    1. #include <18f452.h>
    2. #use delay(clock=10000000)
    3. #fuses HS,WDT
    4.  
    5. #byte    PORTD = 0x08            /* output port D definition */
    6. #bit       EW_RED_LITE    = PORTD.5    /* definitions to actual outputs */
    7. #bit       EW_YEL_LITE    = PORTD.6    /* used to control the lights */
    8. #bit       EW_GRN_LITE    = PORTD.7
    9. #bit       NS_RED_LITE    = PORTD.1
    10. #bit       NS_YEL_LITE    = PORTD.2
    11. #bit       NS_GRN_LITE    = PORTD.3
    12.  
    13. #byte    PINB  = 0x06             /* input port B definition */
    14. #bit       PED_XING_EW    = PINB.0     /* pedestrian crossing push button */
    15. #bit       PED_XING_NS    = PINB.1     /* pedestrian crossing push button */
    16. #bit       FOUR_WAY_STOP = PINB.3     /* switch input for 4-Way Stop */
    17.  
    18. char time_left;        // time in seconds spent in each state
    19. int current_state;    // current state of the lights
    20. char flash_toggle;    // toggle used for FLASHER state
    21.  
    22. // This enumeration creates a simple way to add states to the machine // by name. Enumerations generate an integer value for each name
    23. // automatically, making the code easier to maintain.
    24.  
    25. enum { EW_MOVING , EW_WARNING , NS_MOVING , NS_WARNING , FLASHER };
    26.  
    27. // The actual state machine is here..
    28. void Do_States(void)
    29. {
    30.     switch(current_state)
    31.     {
    32.         case    EW_MOVING:        // east-west has the green!!
    33.             EW_GRN_LITE = 0;
    34.             NS_GRN_LITE = 1;    
    35.             NS_RED_LITE = 0;    // north-south has the red!!
    36.             EW_RED_LITE    = 1;
    37.             EW_YEL_LITE = 1;
    38.             NS_YEL_LITE = 1;
    39.            
    40.             if(PED_XING_EW || FOUR_WAY_STOP)    
    41.             {    // pedestrian wishes to cross, or
    42.                 // a 4-way stop is required
    43.                 if(time_left > 10)
    44.                     time_left = 10;    // shorten the time
    45.             }
    46.             if(time_left != 0)        // count down the time
    47.             {
    48.                 --time_left;
    49.                 return;            // return to main
    50.             }                     // time expired, so..
    51.             time_left = 5;       // give 5 seconds to WARNING
    52.             current_state = EW_WARNING;    
    53.                         // time expired, move
    54.             break;            // to the next state
    55.  
    56.         case    EW_WARNING:
    57.             EW_GRN_LITE = 1;
    58.             NS_GRN_LITE = 1;
    59.             NS_RED_LITE = 0;    // north-south has the red..
    60.             EW_RED_LITE    = 1;
    61.             EW_YEL_LITE = 0;    // and east-west has the yellow
    62.             NS_YEL_LITE = 1;
    63.            
    64.             if(time_left != 0)        // count down the time
    65.             {
    66.                 --time_left;
    67.                 return;            // return to main
    68.             }            // time expired, so..
    69.             if(FOUR_WAY_STOP)    // if 4-way requested then start
    70.                current_state = FLASHER; // the flasher
    71.             else
    72.             {                // otherwise..
    73.                time_left = 30;    // give 30 seconds to MOVING
    74.                 current_state = NS_MOVING;    
    75. }                // time expired, move
    76.             break;            // to the next state
    77.  
    78.         case    NS_MOVING:
    79.             EW_GRN_LITE = 1;
    80.             NS_GRN_LITE = 0;    
    81.             NS_RED_LITE = 1;    // north-south has the green!!
    82.             EW_RED_LITE    = 0;    // east-west has the red!!
    83.             EW_YEL_LITE = 1;
    84.             NS_YEL_LITE = 1;
    85.            
    86.             if(PED_XING_NS || FOUR_WAY_STOP)    
    87.             {    // if a pedestrian wishes to cross, or
    88.                 // a 4-way stop is required..
    89.                 if(time_left > 10)
    90.                     time_left = 10;    // shorten the time
    91.             }
    92.             if(time_left != 0)        // count down the time
    93.             {
    94.                 --time_left;
    95.                 return;            // return to main
    96.             }            // time expired, so..
    97.             time_left = 5;    // give 5 seconds to WARNING
    98.             current_state = NS_WARNING;    // time expired, move
    99.             break;                // to the next state
    100.  
    101.         case    NS_WARNING:
    102.             EW_GRN_LITE = 1;
    103.             NS_GRN_LITE = 1;
    104.             NS_RED_LITE = 1;    // north-south has the yellow..
    105.             EW_RED_LITE    = 0;
    106.             EW_YEL_LITE = 1;    // and east-west has the red..
    107.             NS_YEL_LITE = 0;
    108.            
    109.             if(time_left != 0)        // count down the time
    110.             {
    111.                 --time_left;
    112.                 return;            // return to main
    113.             }            // time expired, so..
    114.             if(FOUR_WAY_STOP)    // if 4-way requested then start
    115.             current_state = FLASHER; // the flasher
    116.             else
    117.             {                // otherwise..
    118.                time_left = 30;    // give 30 seconds to MOVING
    119.                 current_state = EW_MOVING;    
    120.       }                // time expired, move
    121.         break;            // to the next state
    122.  
    123.         case    FLASHER:
    124.            EW_GRN_LITE = 1;    // all yellow and
    125.             NS_GRN_LITE = 1;    // green lites off
    126.             EW_YEL_LITE = 1;    
    127.             NS_YEL_LITE = 1;
    128.  
    129.             flash_toggle ^= 1;    // toggle LSB..
    130.             if(flash_toggle & 1)
    131.             {
    132.                 NS_RED_LITE = 0;    // blink red lights
    133.                EW_RED_LITE    = 1;
    134.             }
    135.             else
    136.             {
    137.                 NS_RED_LITE = 1;    // alternately
    138.                  EW_RED_LITE    = 0;
    139.             }
    140.             if(!FOUR_WAY_STOP)    // if no longer a 4-way stop
    141.                 current_state = EW_WARNING;
    142.             break;            // then return to normal
    143.  
    144.         default:
    145.           current_state = NS_WARNING;    
    146.          break;    // set any unknown state to a good one!!
    147.     }
    148. }
    149.  
    150. void main(void)
    151. {
    152.    port_b_pullups(TRUE);
    153.    set_tris_b(0xFF); // port B is all input
    154.    set_tris_d(0x00); // port D is all output
    155.    
    156.     current_state = NS_WARNING;    // initialize to a good starting
    157.                         // state (as safe as possible)
    158.     while(1)
    159.    {
    160.       delay_ms(250);    // 1 second delay.. this time could
    161.       delay_ms(250);
    162.       delay_ms(250);
    163.       delay_ms(250);
    164.                 // be used for other needed processes
    165.  
    166.       Do_States();    // call the state machine, it knows
    167.                 // where it is and what to do next
    168.     }
    169. }
    170.  
    I think there is something in MPlab that can make the easy transition but I cant find it.
     
  2. Mark44

    Well-Known Member

    Nov 26, 2007
    626
    1
    Apparently the compiler can't find your header file, 18f452.h. Your preprocessor line, "#include <18f452.h>" indicates to the compiler that it should be able to find this header in the usual place, the directory that contains stdio.h and so on.

    Change the # line to something like this: #include "<path>\18f452.h", where <path> is the directory path to where the head is.
     
Loading...