Crimson C-language program examples

ceilingwalker

Lifetime Supporting Member
Join Date
Mar 2010
Location
Phoenix, AZ
Posts
1,586
Hello all and Merry Christmas. Would like to know if anyone here might have some Crimson V3 C-language examples they wouldn't mind sharing with me. I have limited experience with C to begin with however, some of what I know won't work when creating routines in the Crimson environment, the compiler doesn't recognize some keywords, for example. The more complex the program you might be able to share with me, the better. Thanks much.
 
Here is a very simple one:

///When Welder.ARC_ON is true move Welder.Volts_G03 into Welder.Volts
///When Welder.ARC_ON is False move 0 into Welder.Volts

if(Welder.ARC_ON)
{
Welder.Volts = Welder.Volts_GO3;
}
else Welder.Volts = 0;
 
Here is a very simple one:

///When Welder.ARC_ON is true move Welder.Volts_G03 into Welder.Volts
///When Welder.ARC_ON is False move 0 into Welder.Volts

if(Welder.ARC_ON)
{
Welder.Volts = Welder.Volts_GO3;
}
else Welder.Volts = 0;

(y) Thank you, this is exactly the kind of thing I was looking for.
 
I could share some C programs, however they are ones written in Codewarrior not in Crimson
 
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
#include "stdio.h"

//from the lcd display program
char Esc_seq[2]={
0x1b,'[' };
int dummy;
char sendtime[9];
unsigned int temptime;
short hr, min, sec, incsec, startupdate;
long time;
//when connecting to PMODRS232, TXD1 (from HC12) connects to
//RXD on PMOD and RXD1 (from HC12) connects to TXD on PMOD


//void MCU_init(void); /* Device initialization function declaration */
void TERMIO_PutChar(char ch); // send character to serial port
char TERMIO_GetChar(void); // get character from serial port
void serial_port_sel(char sel);
void send_nibble(short hr);

char sel,temp[20];//temp;
int dummy;
//setup generic serial port register definitions
unsigned char *SCI_SR1,*SCI_DRL; //* tells to get the value out of the location that is stored in variable

void MCU_init(void); /* Device initialization function declaration */

void main(void) {
MCU_init(); /* call Device Initialization */
/* put your own code here */
startupdate=0;
// code from the long int example
sel = 1; serial_port_sel(sel);
dummy = printf("%s1e",Esc_seq);//turn on display,no back light
dummy = printf("%s2c",Esc_seq);//cursor on blinking
dummy = printf("%s0h",Esc_seq);//wrap around after 16 chars
dummy = printf("%sj",Esc_seq); //clear screen and home cursor
dummy = printf("Waiting");//send chars
sel = 0; serial_port_sel(sel);
dummy=printf("\n\rPlease enter the time (HMS),no leading 0: ");
dummy=scanf("%li", &time); /*use %li (long int) to input a long*/

/*break long into hr,min,sec */
temptime= (char)(time/10000); /*isolate hr*/
hr=temptime;
hr=(temptime/10)*16+temptime%10; /*change hr into BCD number*/

temptime= (char)((time/100)%100); /*isolate min*/
min=temptime;
min=(temptime/10)*16+temptime%10; /*change min into BCD number*/

temptime= (char)(time%100); /*isolate sec*/
sec=temptime;
sec=(temptime/10)*16+temptime%10; /*change sec into BCD number*/
send_nibble(hr); //lcd print function
//dummy = printf("%i:%i:%i",hr,min,sec);
startupdate=1;
while(1)
{
if (incsec) //bcd clock section
{
incsec=0;
if ((sec & 0b00001001) == 0b00001001) //checks to make sure lower nibble is less than A
{
sec = sec + 0b0111; //if lower is nine adds one to upper nible
}
else
{
sec = sec + 1; //incrememnts seconds
}
if (sec == 0b01100000)//checks to see if counter is at 60
{
sec = 0b00000000; //clears seconds
min = min + 1; //increment minutes
if ((min & 0b00001010) == 0b00001010) //this section does same as seconds, but with minutes
{
min = min + 0b0110; //adds 6 instead of eight becaus checking for 0xA instead of 9 due to the way C goes linearly
}
if (min == 0b01100000) ///checks for 60 minutes
{
min = 0b00000000; //clears minutes
hr = hr + 1; //increments hours
if ((hr & 0b00001010) == 0b00001010) //this section does same as seconds, but with hours and 24 not 60
{
hr = hr +0b0110;
}
if (hr == 0b00100100) //checks for 24 bcd
{
hr = 0b00000000; //clears hours, all values are 0 at this point
}
}
}
send_nibble(hr); //lcd print function

}
}//ends while loop


for(;;) {
/* _FEED_COP(); by default, COP is disabled with device init. When enabling, also reset the watchdog. */
} /* loop forever */
/* please make sure that you never leave main */
}
void serial_port_sel(char sel)
{
if (sel) //selects the second serial port
{
SCI_SR1 = &SCI1SR1; //& means wants the address, not the content
SCI_DRL = &SCI1DRL;
}
else ////selects the primary serial port
{
SCI_SR1 = &SCI0SR1;
SCI_DRL = &SCI0DRL;
}
}

//redefine functions used by scanf and printf
void TERMIO_PutChar(char ch)
{
while ((*SCI_SR1 & 0x80) == 0)//reads the transmit buffer empty status flag
;
*SCI_DRL = ch; // * is a pointer in this case its placing data to send

}

char TERMIO_GetChar(void)
{


while ((*SCI_SR1 & 0x20) == 0); ///reads the recieve buffer full bit

return *SCI_DRL;
}
void send_nibble(short hr)

{
sendtime[0] = (char)((hr / 16)+ 0b00110000); // shifts upper bits right four places the adds a "3" on for ascii
sendtime[1] = (char)((hr & 0b00001111) + 0b00110000); // clears upper bits adds a "3" on for ascii
sendtime[2] = 0x3a; // colon
sendtime[3] = (char)((min / 16)+ 0b00110000); // shifts upper bits right four places the adds a "3" on for ascii
sendtime[4] = (char)((min & 0b00001111) + 0b00110000); // clears upper bits adds a "3" on for ascii
sendtime[5] = 0x3a; // colon
sendtime[6] = (char)((sec / 16)+ 0b00110000); // shifts upper bits right four places the adds a "3" on for ascii
sendtime[7] = (char)((sec & 0b00001111) + 0b00110000); // clears upper bits adds a "3" on for ascii
sendtime[8] = (char)(00); // tells printf done

sel = 1; serial_port_sel(sel);
dummy = printf("%sj",Esc_seq); //clear screen and home cursor
dummy = printf("%s",sendtime); //sends array

}
 
That is a clock program written to display in hyperterminal my spacing and tabs did not transfer so it looks wholly disorganized
 
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
#include <math.h>

#define numberOfPoints 100 //sets number of times through and samples

double x[numberOfPoints] = 0;
int i;
double c1,c2,c3,c4,c5,c6,c7,c8;
double P1,P2,P3,P4,P5,P6,P7,P8;

double Goertzel(double c);

void MCU_init(void); /* Device initialization function declaration */
void main(void) {
MCU_init(); /* call Device Initialization */
/* put your own code here */

c1 = 1.996053457; //500hz
c2 = 1.937166322; //2khz
c3 = 1.809654105; //3.5khz
c4 = 1.618033989; //5khz
c5 = 1.369094212; //6.5khz
c6 = 1.07165359; //8khz
c7 = 0.736249105; //9.5khz
c8 = 0.374762629; //11khz

while (1){



for ( i = 0; i < numberOfPoints; i++) // loop loads numberOfPoints samples into memory
{
while(!(ATD0STAT0 & 0x80)); //waits for the A to D to be ready to give a value
x = (double)ATD0DR0 - 511; //assigns A to D holding register subtracting out the dc offset
}

P1 = Goertzel(c1);
if (P1>1500){PTT&=0xFE;}else{PTT|=0x01;}
P2 = Goertzel(c2);
if (P2>500){PTT&=0xFD;}else{PTT|=0x02;}
P3 = Goertzel(c3);
if (P3>350){PTT&=0xFB;}else{PTT|=0x04;}
P4 = Goertzel(c4);
if (P4>200){PTT&=0xF7;}else{PTT|=0x08;}
P5 = Goertzel(c5);
if (P5>150){PTT&=0xEF;}else{PTT|=0x10;}
P6 = Goertzel(c6);
if (P6>100){PTT&=0xDF;}else{PTT|=0x20;}
P7 = Goertzel(c7);
if (P7>100){PTT&=0xBF;}else{PTT|=0x40;}
P8 = Goertzel(c8);
if (P8>75){PTT&=0x7F;}else{PTT|=0x80;}

}

for(;;) {
/* _FEED_COP(); by default, COP is disabled with device init. When enabling, also reset the watchdog. */
} /* loop forever */
/* please make sure that you never leave main */
}

double Goertzel(double c)
{

double s0,s1,s2;
int n;
double power,powerreal,powerimaj;

s0=0;s1=0;s2=0; //resets "s" variables to 0 for new set of computations

for ( n = 0; n < numberOfPoints; n++) //loop performs computation numberOfPoints times
{
s2 = s1; //shifts "s" variables
s1 = s0;
s0 = x[n] + (c * s1) - s2; //computation to be performed numberOfPoints of times
}

powerreal = s0 - (c/2) * s1;
powerimaj = (-1 * (sqrt(1 - ((c/2)*(c/2)))) * s1);
power = sqrt(powerreal * powerreal + powerimaj * powerimaj);

return power;
}
 
These programs were written for a microprocessor not an HMI so there is much that may not apply to you
 
Here is a very simple one:

///When Welder.ARC_ON is true move Welder.Volts_G03 into Welder.Volts
///When Welder.ARC_ON is False move 0 into Welder.Volts

if(Welder.ARC_ON)
{
Welder.Volts = Welder.Volts_GO3;
}
else Welder.Volts = 0;

This can be simplified to a simple one line expression instead of using a complex code block by using the ternary IF form.

Welder.Volts = Welder.ARC_ON? Welder.Volts_GO3:0;
 

Similar Topics

Hey guys, hoping someone here could give me a little advice. I'm working with a CR1000-04000 in Crimson 3.1 and I was interested in adding the...
Replies
4
Views
114
Hi, I'm having an issue in crimson 3.0 when I create a programme using a case statement referencing a fault word that each bit needs to change the...
Replies
4
Views
170
How do you install update on Red Lion Crimson ver 3.1. Do I just need to run the exe file on the host server?
Replies
1
Views
105
Has anyone found a way to convert/replace/update the firmware on old Parker TS80xx series HMIs (i.e. TS8010, TS8006, etc) to accept Crimson...
Replies
0
Views
89
Has anyone setup communications with Red Lion 3.0 MODBUS to Baker Hughes Centrilift GCS VFD? Thanks
Replies
0
Views
89
Back
Top Bottom