Some of the comments are not right(as I still developing it ), but I am using code warrior along with c.
[code]#include <hidef.h> /* for EnableInterrupts macro /
#include “derivative.h” / include peripheral declarations */
// DEFINE General
#define ON 0 // LED ON
#define OFF 1 // LED OFF
#define UP 1 // Switch off
#define DOWN 0 // Switch on
// DEFINE LED’s
#define LED1 PTFD_PTFD0 // LED1
#define LED1_DDR PTFDD_PTFDD0 // DATA DIRECTION FOR LED1
// vars
int i = 0; // this is for the for loop
int j = 0;
int xposition;
int leastxposition = 1100;
int maxxposition = 2000;
char temp[4];
/*
char PinNumber[3];
char Position[5];
char Time[6];
*/
byte EndCommand = 0x0d; // Carriage Return
// wait loop that lets you wait between the commands
void waitloop(int seconds){
// 25 = 1 second
for ( j = 0; j < seconds; j++ ) {
// 29000 = 40 ms
for (i = 0; i < 29000; i++ ) {
__RESET_WATCHDOG();
}
}
}
void SetRobotNumber(char *PinNumber, char *Position ) {
__RESET_WATCHDOG();
while(SCI2S1_TDRE == 0);
SCI2D = '#';
while(SCI2S1_TDRE == 0);
SCI2D = *PinNumber;
while(SCI2S1_TDRE == 0);
SCI2D = *(PinNumber+1);
while(SCI2S1_TDRE == 0);
SCI2D = 'P';
while(SCI2S1_TDRE == 0);
SCI2D = *Position;
while(SCI2S1_TDRE == 0);
SCI2D = *(Position+1);
while(SCI2S1_TDRE == 0);
SCI2D = *(Position+2);
while(SCI2S1_TDRE == 0);
SCI2D = *(Position+3);
}
// #0P1600T1000 1000 = 1 second
void MoveX(char* Time) {
__RESET_WATCHDOG();
while(SCI2S1_TDRE == 0);
SCI2D = 'T';
while(SCI2S1_TDRE == 0);
SCI2D = *(Time);
while(SCI2S1_TDRE == 0);
SCI2D = *(Time+1);
while(SCI2S1_TDRE == 0);
SCI2D = *(Time+2);
while(SCI2S1_TDRE == 0);
SCI2D = *(Time+3);
while(SCI2S1_TDRE == 0);
SCI2D = *(Time+4);
}
int SetArmDefault(){
SetRobotNumber("00","1500");
SetRobotNumber("01","1500");
SetRobotNumber("02","1500");
SetRobotNumber("16","1890");
SetRobotNumber("17","2100");
SetRobotNumber("18","1500");
SetRobotNumber("19","1500");
while(SCI2S1_TDRE == 0);
SCI2D = EndCommand;
return 1500;
}
int MoveArmx(){
SetRobotNumber("00","2250");
MoveX ("1000"); // move x in 10 seconds
while(SCI2S1_TDRE == 0);
SCI2D = EndCommand;
return 2250;
}
void main(void) { // main
EnableInterrupts; // enable interrupts
LED1_DDR = 1; // sets up led1 as the output
// DEFINE SCI2
// BAUD RATE MODULO
SCI2BDH = 0; // SCIBDH DOESN’T CHANGE UNTILL SCIBDL IS WRITTEN
SCI2BDL = 28; // 4 MHZ /(16 * 26) = 9600 baud rate 00001101 BAUDRATE = BUSRATE / (SCI2BDL X 16 ) 29 = 9600 116 =2400
SCI2C2_TE = 1; // TRANSMITTER IS ENABLED
for(;
{
__RESET_WATCHDOG();
xposition = SetArmDefault();
waitloop(25); // waits for one second
xposition = MoveArmx();
waitloop(100); // waits for 4 seconds
}
// Loop forever
}[/code]