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. "
I think there is something in MPlab that can make the easy transition but I cant find it.
Rich (BB code):
#include <18f452.h>
#use delay(clock=10000000)
#fuses HS,WDT
#byte PORTD = 0x08 /* output port D definition */
#bit EW_RED_LITE = PORTD.5 /* definitions to actual outputs */
#bit EW_YEL_LITE = PORTD.6 /* used to control the lights */
#bit EW_GRN_LITE = PORTD.7
#bit NS_RED_LITE = PORTD.1
#bit NS_YEL_LITE = PORTD.2
#bit NS_GRN_LITE = PORTD.3
#byte PINB = 0x06 /* input port B definition */
#bit PED_XING_EW = PINB.0 /* pedestrian crossing push button */
#bit PED_XING_NS = PINB.1 /* pedestrian crossing push button */
#bit FOUR_WAY_STOP = PINB.3 /* switch input for 4-Way Stop */
char time_left; // time in seconds spent in each state
int current_state; // current state of the lights
char flash_toggle; // toggle used for FLASHER state
// This enumeration creates a simple way to add states to the machine // by name. Enumerations generate an integer value for each name
// automatically, making the code easier to maintain.
enum { EW_MOVING , EW_WARNING , NS_MOVING , NS_WARNING , FLASHER };
// The actual state machine is here..
void Do_States(void)
{
switch(current_state)
{
case EW_MOVING: // east-west has the green!!
EW_GRN_LITE = 0;
NS_GRN_LITE = 1;
NS_RED_LITE = 0; // north-south has the red!!
EW_RED_LITE = 1;
EW_YEL_LITE = 1;
NS_YEL_LITE = 1;
if(PED_XING_EW || FOUR_WAY_STOP)
{ // pedestrian wishes to cross, or
// a 4-way stop is required
if(time_left > 10)
time_left = 10; // shorten the time
}
if(time_left != 0) // count down the time
{
--time_left;
return; // return to main
} // time expired, so..
time_left = 5; // give 5 seconds to WARNING
current_state = EW_WARNING;
// time expired, move
break; // to the next state
case EW_WARNING:
EW_GRN_LITE = 1;
NS_GRN_LITE = 1;
NS_RED_LITE = 0; // north-south has the red..
EW_RED_LITE = 1;
EW_YEL_LITE = 0; // and east-west has the yellow
NS_YEL_LITE = 1;
if(time_left != 0) // count down the time
{
--time_left;
return; // return to main
} // time expired, so..
if(FOUR_WAY_STOP) // if 4-way requested then start
current_state = FLASHER; // the flasher
else
{ // otherwise..
time_left = 30; // give 30 seconds to MOVING
current_state = NS_MOVING;
} // time expired, move
break; // to the next state
case NS_MOVING:
EW_GRN_LITE = 1;
NS_GRN_LITE = 0;
NS_RED_LITE = 1; // north-south has the green!!
EW_RED_LITE = 0; // east-west has the red!!
EW_YEL_LITE = 1;
NS_YEL_LITE = 1;
if(PED_XING_NS || FOUR_WAY_STOP)
{ // if a pedestrian wishes to cross, or
// a 4-way stop is required..
if(time_left > 10)
time_left = 10; // shorten the time
}
if(time_left != 0) // count down the time
{
--time_left;
return; // return to main
} // time expired, so..
time_left = 5; // give 5 seconds to WARNING
current_state = NS_WARNING; // time expired, move
break; // to the next state
case NS_WARNING:
EW_GRN_LITE = 1;
NS_GRN_LITE = 1;
NS_RED_LITE = 1; // north-south has the yellow..
EW_RED_LITE = 0;
EW_YEL_LITE = 1; // and east-west has the red..
NS_YEL_LITE = 0;
if(time_left != 0) // count down the time
{
--time_left;
return; // return to main
} // time expired, so..
if(FOUR_WAY_STOP) // if 4-way requested then start
current_state = FLASHER; // the flasher
else
{ // otherwise..
time_left = 30; // give 30 seconds to MOVING
current_state = EW_MOVING;
} // time expired, move
break; // to the next state
case FLASHER:
EW_GRN_LITE = 1; // all yellow and
NS_GRN_LITE = 1; // green lites off
EW_YEL_LITE = 1;
NS_YEL_LITE = 1;
flash_toggle ^= 1; // toggle LSB..
if(flash_toggle & 1)
{
NS_RED_LITE = 0; // blink red lights
EW_RED_LITE = 1;
}
else
{
NS_RED_LITE = 1; // alternately
EW_RED_LITE = 0;
}
if(!FOUR_WAY_STOP) // if no longer a 4-way stop
current_state = EW_WARNING;
break; // then return to normal
default:
current_state = NS_WARNING;
break; // set any unknown state to a good one!!
}
}
void main(void)
{
port_b_pullups(TRUE);
set_tris_b(0xFF); // port B is all input
set_tris_d(0x00); // port D is all output
current_state = NS_WARNING; // initialize to a good starting
// state (as safe as possible)
while(1)
{
delay_ms(250); // 1 second delay.. this time could
delay_ms(250);
delay_ms(250);
delay_ms(250);
// be used for other needed processes
Do_States(); // call the state machine, it knows
// where it is and what to do next
}
}