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.

programming a PIC using c language

Status
Not open for further replies.

weird86

Newbie level 1
Joined
Jan 26, 2010
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Malaysia
Activity points
1,299
hai i am very new to pic programming using c language.... i got a few set of lines from the web and am finding it hard to understand them..... i am hoping that someone can explain to me this lines..... i am trying to built a elevator system using pic16f877....

// the push-buttons that request the elevator target floor
// we map BUTTON_0=RA4 etc. to keep the schematics simple..
//
#define BUTTON_0 RA4
#define BUTTON_1 RA3
#define BUTTON_2 RA2
#define BUTTON_3 RA1
#define BUTTON_4 RA0

// the sensors that indicate which floor the elevator car
// has reached. Again we map 0-4 1-3 etc. to avoid signal
// crossing in the schematics.
//
#define SENSOR_0 RB4
#define SENSOR_1 RB3
#define SENSOR_2 RB2
#define SENSOR_3 RB1
#define SENSOR_4 RB0

// two output ports used to control the elevator motor
// (on/off) and motor direction (up/ndown).
//
#define MOTOR_ON RB6
#define UP_NDOWN RB7

// the elevator states: parked means waiting (at floor < i >),
// up_to and down_to imply moving to the corresponding floor.
// We force an encoding that allows you to watch the state
// during the simulation (upper nibble=1/2/4: parked/up/down),
// lower nibble=floor index, 0xff=error
//

//I DONT UNDERSTAND FROM THIS LINE

enum elevator_state {
PARKED_0 = 0x10,
PARKED_1 = 0x11,
PARKED_2 = 0x12,
PARKED_3 = 0x13,
PARKED_4 = 0x14,

UP_TO_1 = 0x21,
UP_TO_2 = 0x22,
UP_TO_3 = 0x23,
UP_TO_4 = 0x24,

DOWN_TO_3 = 0x43,
DOWN_TO_2 = 0x42,
DOWN_TO_1 = 0x41,
DOWN_TO_0 = 0x40,

UNKNOWN = 0xff,
};

enum motor_state {
STOP = 0x00,
MOVE_UP = 0xc0,
MOVE_DOWN = 0x80,
};


// global variables for state-machine state and motor control
//
unsigned char state = PARKED_0;
unsigned char motor = STOP;



// inidicate an error by lighting the LED on port B.5
// (note that RB5 is also used to reset the SR-flipflops,
// but the short strobes should not be visible on a real LED.
void
error(void)
{
motor = STOP;
for(;;) {
RB5 = 1;
}
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top