I’m trying out the C18 compiler for the first time. I’m just trying to turn on two LEDs, the one in digital output 5, and in output 1, however, the digital output 5 and 4 are the only ones that turn on. Here’s the code:
This code looks like it ought to work. I notice that you are zeroing out RA4 & RA6, which are not used for I/O ports. I don’t know what they might be wired to inside the Vex microcontroller, so perhaps this is causing some problems? You could try just zeroing the bits you need and leave the rest alone.
Personally, I always use the defines from ifi_aliases.h because they make the code much easier to understand with no performance penalty. I’d write this program like so:
It still didn’t work. The LEDs didn’t turn on. The LEDs only turn on when I clear PORTA, and only outputs 4 and 5 would turn on, when I actually wanted 1 and 5 to turn on.
You turn the LEDs on by writing a 0 to the port and turn them off by writing a 1 to the port. The reason for this is that the LEDs are wired between +5V (center pin) and the signal pin. To get them to light, the signal pin has to go low and sink some current (about 4mA) to light the LED.
I was able to get the LEDs work and everything though I’m having problems using PWM outputs and inputs. I believe pwm0X sets a motor to the specified value and PWM_inX are the channels of the Vex controller. Putdata is required to give information of the motor ports and Getdata is used to recieve information from the Vex controller. I tried to make a program used to control my robot, but the following error occurs:
Error - could not find definition of symbol ‘Putdata’ in file ‘./main.o’.
This error also appears for Getdata.
My program works fine with the Vex Starter code, however, I would to make a program more from scratch. Here’s the program I made:
#include "ifi_aliases.h"
#include "ifi_default.h"
tx_data_record txdata;
rx_data_record rxdata;
void main()
{
IO1 = 0; // Set the LED ports to outputs.
IO5 = 0;
while (1)
{
Getdata(&rxdata);
pwm02 = PWM_in3; // Assign motors to RC reciever.
pwm03 = PWM_in4;
/* LED code */
if ( PWM_in3 > 127 + 27 )
rc_dig_in05 = 0;
else
rc_dig_in05 = 1;
if ( PWM_in4 > 127 + 27 || PWM_in4 < 100 )
rc_dig_in01 = 0;
else
rc_dig_in01 = 1;
Putdata(&txdata);
}
}
I believe you need to link against one of the Vex_* libraries provided with the VexCode project. There is a brief note about this in the README included with VexCode.
You should also make sure you are using the 18f8520user.lkr script, to make sure everything gets located correctly.
Try adding Vex_Library to the solution (or Vex_AllTimers)
Note: Do not add the *_wauton libraries as these are used to trigger autonomous mode!
You’re also missing the Vex initialisation line which I believe is quite important. Download the sample code from the wiki and then have a look at the main.c file (Ignore the rest of the files for what you are doing!)