I'm not quite sure if this is the right place for this or if it is where many people know about C Programming, but here goes.
For the engineering module on my Uni course, we are in groups and have to produce a working prototype based around a microcontroller and C Programming. It just so happens that the other two people in the group cannot do it even though they are engineering students so it has been left to me, a design student, to produce the code for the model. I know very little if any so any help in writing the code would be greatly appreciated.
Our model is of one of those remote control cars which had the controller attached by a wire. A motor is used to drive the wheels and another motor is used for the steering in a rack and pinion type of arrangement, which I have been assured by the 2 engineers will work, but I'm sceptical about it. There are 4 buttons. One for forward, one for back, left and right. There are also 4 LEDs for headlights.
To go forward, the forward button must be pressed. To go back, the back button is pressed. To go forward and left, both forward and left must be pressed and so on for the remaining directions. If the left button is pressed on its own, nothing will happen. If the left and right buttons are pressed simultaneously, the LEDs will light, and press again to turn them off.
Here is the code so far and initial tests have shown it sort of works for forward and back but I don't know what to do to it now.
I can include a schematic of the circuit if that is helpful or more information on the microcontroller that we are using, but any help at all would be extremely helpful and appreciated.
For the engineering module on my Uni course, we are in groups and have to produce a working prototype based around a microcontroller and C Programming. It just so happens that the other two people in the group cannot do it even though they are engineering students so it has been left to me, a design student, to produce the code for the model. I know very little if any so any help in writing the code would be greatly appreciated.
Our model is of one of those remote control cars which had the controller attached by a wire. A motor is used to drive the wheels and another motor is used for the steering in a rack and pinion type of arrangement, which I have been assured by the 2 engineers will work, but I'm sceptical about it. There are 4 buttons. One for forward, one for back, left and right. There are also 4 LEDs for headlights.
To go forward, the forward button must be pressed. To go back, the back button is pressed. To go forward and left, both forward and left must be pressed and so on for the remaining directions. If the left button is pressed on its own, nothing will happen. If the left and right buttons are pressed simultaneously, the LEDs will light, and press again to turn them off.
Here is the code so far and initial tests have shown it sort of works for forward and back but I don't know what to do to it now.
PHP:
//V1.0
#include <16f877a.h>
#device ICD=TRUE
#fuses HS,NOLVP,NOWDT,PUT
#use delay (clock=200000000)
#define LEFT PIN_B6 //input button
#define RIGHT PIN_B4 //input button
#define FORWARD PIN_B2 //input button
#define BACK PIN_B0 //input button
#define MOTORFWD PIN_D6 //output drive forward
#define MOTORBCK PIN_D4 //output drive backward
#define MOTORLEFT PIN_D2 //output steer left
#define MOTORRIGHT PIN_D0 //output steer right
#define LIGHTS PIN_C4 //output headlights
void main()
{
if (FORWARD,0)
output_low (MOTORFWD);
if (BACK,0)
output_low (MOTORBCK);
if (FORWARD,0, LEFT,0)
output_low (MOTORFWD);
output_low (MOTORLEFT);
if (FORWARD,0, RIGHT,0)
output_low (MOTORFWD);
output_low (MOTORRIGHT);
if (BACK,0, LEFT,0)
output_low (MOTORBCK);
output_low (MOTORLEFT);
if (BACK,0, RIGHT,0)
output_low (MOTORBCK);
output_low (MOTORRIGHT);
}
void headlights()
{
while(input(LIGHTS));
while(input(!LIGHTS));
while(true)
{
HEADLIGHTS light_one_led();
wait_for_one_press();
}
}
I can include a schematic of the circuit if that is helpful or more information on the microcontroller that we are using, but any help at all would be extremely helpful and appreciated.