0% found this document useful (0 votes)
63 views12 pages

Program Master Avr Atmega 32A: Deklasrasi Library Program Komunikasi Serial (Penerimaan Data Dari LABVIEW)

The document summarizes an Arduino program for controlling a 3D printer. It includes sections for declaring libraries and variables, serial communication to receive data from a computer program, an emergency stop routine, functions for timer delays and controlling the individual axes (X, Y, Z), and linear interpolation for moving the axes. The main sections are for serial receive, emergency stop, timer delays, axis control including moving individually on the Z-axis and linear interpolation for combined X and Y axis movement.

Uploaded by

Atep Puja T
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views12 pages

Program Master Avr Atmega 32A: Deklasrasi Library Program Komunikasi Serial (Penerimaan Data Dari LABVIEW)

The document summarizes an Arduino program for controlling a 3D printer. It includes sections for declaring libraries and variables, serial communication to receive data from a computer program, an emergency stop routine, functions for timer delays and controlling the individual axes (X, Y, Z), and linear interpolation for moving the axes. The main sections are for serial receive, emergency stop, timer delays, axis control including moving individually on the Z-axis and linear interpolation for combined X and Y axis movement.

Uploaded by

Atep Puja T
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

PROGRAM MASTER AVR ATMEGA 32A

Deklasrasi Library #endif Program komunikasi


serial ( Penerimaan data
#include <mega32a.h> #ifndef DOR dari LABVIEW)

#include <mega32a.h> #define DOR 3 // USART Receiver buffer


#include <delay.h> #endif #define RX_BUFFER_SIZE 1200
#include <stdio.h> #ifndef FE char gcode[1200];
#include <math.h> #define FE 4 unsigned int rx_wr_index = 0;
#include <stdlib.h> #endif // This flag is set on USART Receiver
buffer overflow
#include <string.h> #ifndef UDRE
bit charReceived;
Deklarasi varibel #define UDRE 5
(mengatur tipe data // USART Receiver interrupt service
variable tersebut) #endif
routine

long int #ifndef RXC


interrupt [USART_RXC] void
startx,starty,akhirx,akhiry,pkx,pky,qk usart_rx_isr(void)
#define RXC 7
x,qky,dpx,dpy,iterasi_linear,iterasi_ci
rcular,MaxRegister,p1=0,p2=0,p3=0,p #endif {
4,p5,p6,p7,p8,p9=0,p10,p11,p12;
char status,data;
unsigned long int stepZ = 0,x,z, mode,
uu, vv, ww, xx, XTotal, YTotal, #define FRAMING_ERROR (1<<FE) status=UCSRA;
ZTotal,Aktif,NonAktif,XNewABS = 0,
#define PARITY_ERROR (1<<UPE) data=UDR;
YNewABS = 0, ZNewABS = 0,
kuadranlinier; if ((status & (FRAMING_ERROR |
#define DATA_OVERRUN (1<<DOR)
PARITY_ERROR |
#define DATA_REGISTER_EMPTY DATA_OVERRUN))==0)
char GMode[5], GX[5], GY[5], GZ[5], (1<<UDRE)
{
GR[5], GF[5], MMode[5], SMode[5];
#define RX_COMPLETE (1<<RXC)
gcode[rx_wr_index]=data;
unsigned int a,b,i, j, k, GSelect, p,v,b ;
#define PulseX PORTA.0 //C
rx_wr_index++;
unsigned long RADIUS = 0, GNum,
#define PulseY PORTA.1 //C
GFeed=0, MNum=0; charReceived = 1;
#define PulseZ PORTB.0 //C
long XNew = 0, YNew = 0, ZNew = 0, if (rx_wr_index == RX_BUFFER_SIZE)
XOld = 0, YOld = 0, ZOld = 0, SNum; #define DirectionX PORTA.2 //C rx_wr_index=0;
unsigned int tot_overflow, #define DirectionY PORTA.3 //C }}
Zmaju,ulang, milih, s, m;
#define DirectionZ PORTB.1 //C Program Emergency
int xtot,ytot,EMG,ztot;
#define EnableX PORTA.4 //C void emergencyloop()
#define frekuensiManual 1500
#define EnableY PORTA.5 //C {
#ifndef RXB8
#define EnableZ PORTB.2 //C PORTC.1 = 0;
#define RXB8 1
#define A PORTB.3 PORTC.0 = 0;
#endif
#define B PORTB.6 PORTC.2 = 1; //LAMPU EMG
#ifndef TXB8
#define C PORTB.7 while (PINC.5 != 1) //RESET
#define TXB8 0
#define DIRECTION PORTC.7 {
#endif
#define LAMPU_EMG PORTC.2 PulseX = 0;
#ifndef UPE
EnableX = 0;
#define UPE 2
PulseY = 0; putsf("XF0YF0ZF1"); if ( kuadranlinier == 1)

EnableY = 0; delay_us(2000); {

PulseZ = 0; PulseZ =0; DirectionX=0; //CW X

EnableZ = 0; delay_us(2000); DirectionY=1; //CW Y

} } }

EMG =1; } else if ( kuadranlinier == 2)

} else if(Zdir == 0) {

Program Timer { DirectionX=1; //CCW X

void DelayCustom(unsigned long int DirectionZ =1; DirectionY=1; //CW Y


frekuensi){
stepZ= d_z * 50; }
unsigned int timerCount;
for(ulang=0; ulang<stepZ; ulang++) else if ( kuadranlinier == 3)
float cpuClockPeriod = 9.042245,
requiredDelay { {

requiredDelay = (1.2 / frekuensi) * if (PINC.3==1) DirectionX=1; //CCW X


100000000;
{emergencyloop();} DirectionY=0; //CCW Y
timerCount = (requiredDelay /
if (EMG==1){return;} }
cpuClockPeriod) - 1;
EnableZ = 1; else if ( kuadranlinier == 4)
while(TCNT1 <= timerCount){};
PulseZ =1; {
TCNT1 = 0;
putsf("XF0YF0ZB1"); DirectionX=0; //CW X
}
delay_us(2000); DirectionY=0; //CCW Y
Program Sumbu Z
PulseZ =0; }
void putarZ(unsigned long d_z,
unsigned int Zdir ) delay_us(2000); }

{ } else if(milih == 2) // inkriment

if(Zdir ==1) } {

{ else if(pkx < 0){DirectionX=1;} //CCW


X
PulseZ =0; {
else {DirectionX=0;} //CW X
DirectionZ = 0; //DIRZ EnableZ = 0;
if(pky < 0){DirectionY=0;} //CCW Y
stepZ= d_z / 0.02; PulseZ =0;
else {DirectionY=1;} //CW Y
for(ulang=0;ulang<stepZ;ulang++) }
}
{ }
while(x < iterasi_linear)
if (PINC.3==1) Program Linier Sumbu X
dan Y {skips:
{
void LinearInterpolation(unsigned x++;
emergencyloop();}
long int feedrate)
qkx = qkx + abs(pkx);
if (EMG==1){return;}
{ x=0;
qky = qky + abs(pky);
EnableZ = 1;
if (milih == 1) //abs
PulseZ =1;
{
if (qkx >= MaxRegister) if(DirectionY==0 && PulseY==1 {
&&
{ EnableX = 1; PulseX==0){DelayCustom(feedrate); pkx = pkx - dpy;
p8=p8+1;} //ccw
PulseX = 1; pky = pky + dpx;
Program mengirim String
qkx = qkx - MaxRegister; } }
if (p5==50) //X-
else { PulseX = 0; } if (mode == 4)
{putsf("XB50YF0ZF0");
if (qky >= MaxRegister) {
p5=0; }
{ EnableY = 1; pkx = pkx - dpy;
if (p6==50)
PulseY = 1; pky = pky + dpx;
{ putsf("XF50YF0ZF0"); // X+
qky = qky - MaxRegister; } }
p6=0; }
else{PulseY = 0 } qkx = qkx + abs(pkx) ;
if (p7==50) //Y+
if (PINC.3==1) qky = qky + abs(pky) ;
{ putsf("XF0YF50ZF0");
{ emergencyloop(); } if (qkx >= MaxRegister)
p7=0; }
if (EMG==1){return;} {
if (p8==50) //Y-
if (PulseX == 0 && PulseY==0 ) EnableX = 1;
{ putsf("XF0YB50ZF0");
{goto skips;} PulseX = 1;
p8=0; }
if(DirectionY==1 && PulseY==1 && dpx = 1;
DirectionX==1 && }}
PulseX==1){DelayCustom(feedrate); qkx = qkx - MaxRegister;
p1=p1+1;} //cw Program Interpolasi
}
Sirkular
if(DirectionY==0 && PulseY==1
else
&& DirectionX==0 && void CircularInterpolation(unsigned
PulseX==1){DelayCustom(feedrate); long int feedrate) {
p2=p2+1;} //ccw
{ x=0; dpx = 0;
if(DirectionY==1 && PulseY==1
&& DirectionX==0 && while(x <= iterasi_circular) PulseX = 0;
PulseX==1){DelayCustom(feedrate);
{skips2: }
p3=p3+1;} //cw
x++;
if(DirectionY==0 && PulseY==1
&& DirectionX==1 && if (mode == 1) if (qky >= MaxRegister)
PulseX==1){DelayCustom(feedrate);
p4=p4+1;} //ccw { {
if(DirectionX==1 && PulseX==1 pkx = pkx + dpy; EnableY = 1;
&&
PulseY==0){DelayCustom(feedrate); pky = pky - dpx; PulseY = 1;
p5=p5+1;} //ccw
} dpy = 1;
if(DirectionX==0 && PulseX==1
&& if (mode == 3) qky = qky - MaxRegister;
PulseY==0){DelayCustom(feedrate);
{ }
p6=p6+1;} //cw
pkx = pkx + dpy; else
if(DirectionY==1 && PulseY==1
&& pky = pky - dpx; {
PulseX==0){DelayCustom(feedrate);
p7=p7+1;} //cw } dpy = 0;

if (mode == 2) PulseY = 0;
} if (p6==50) DDRB.4 = 0;

if (PINC.3==1) { DDRB.5 = 0;

{emergencyloop();} putsf("XF50YF0ZF0"); // X+ DDRB.6 = 1; //STANDBY

if (EMG==1){return;} p6=0; DDRB.7 = 1;

} PORTC=0x00;

if (PulseX == 0 && PulseY==0) if (p7==50) //Y+ DDRC.0 = 1;

{goto skips2;} { DDRC.1 = 1;

if(DirectionY==1 && PulseY==1 putsf("XF0YF50ZF0"); DDRC.2 = 1;


&& DirectionX==1 &&
PulseX==1){DelayCustom(feedrate); p7=0; DDRC.3 = 0;
p1=p1+1;} //cw
} DDRC.4 = 0;
if(DirectionY==0 && PulseY==1
if (p8==50) //Y- DDRC.5 = 0;
&& DirectionX==0 &&
PulseX==1){DelayCustom(feedrate); { DDRC.6 = 0;
p2=p2+1;} //ccw
putsf("XF0YB50ZF0"); DDRC.7 = 1;
if(DirectionY==1 && PulseY==1
&& DirectionX==0 && p8=0;
PulseX==1){DelayCustom(feedrate);
p3=p3+1;} //cw } PORTD=0x00;

if(DirectionY==0 && PulseY==1 } PORTD.1 = 0;


&& DirectionX==1 &&
} DDRD.0 = 0;
PulseX==1){DelayCustom(feedrate);
p4=p4+1;} //ccw void main(void) DDRD.1 = 0;
if(DirectionX==1 && PulseX==1 { DDRD.2 = 0;
&&
PulseY==0){DelayCustom(feedrate); Pin Input/Output DDRD.3 = 0;
p5=p5+1;} //ccw
PORTA=0x00; DDRD.4 = 0;
if(DirectionX==0 && PulseX==1
&& DDRA.0 = 1; DDRD.5 = 0;
PulseY==0){DelayCustom(feedrate);
DDRA.1 = 1; DDRD.6 = 0;
p6=p6+1;} //cw
DDRA.2 = 1; DDRD.7 = 0;
if(DirectionY==1 && PulseY==1
&& /*TCCR0=0x00;
DDRA.3 = 1;
PulseX==0){DelayCustom(feedrate);
p7=p7+1;} //cw DDRA.4 = 1; //TCNT0=0x00;

if(DirectionY==0 && PulseY==1 DDRA.5 = 1; OCR0=0x00;


&&
PulseX==0){DelayCustom(feedrate); DDRA.6 = 0; Konfigurasi Komunikasi
p8=p8+1;} //ccw Serial (USART)
DDRA.7 = 0;
// USART initialization
PORTB=0x00;
if (p5==50) //X- // Communication Parameters: 8
DDRB=0x00; Data, 1 Stop, No Parity
{
DDRB.0 = 1; // USART Receiver: On
putsf("XB50YF0ZF0");
DDRB.1 = 1; // USART Transmitter: On
p5=0;
DDRB.2 = 1; // USART Mode: Asynchronous
}
DDRB.3 = 1; // USART Baud Rate: 19200
UCSRA=0x00; while(j < rx_wr_index) case 'M':

UCSRB=0x98; { GSelect = 7;

UCSRC=0x06; switch(gcode[j]) k = j + 1;

UBRRH=0x00; { delay_ms(50);

UBRRL=0x23; case 'G': break;

Konfigurasi penggunaan GSelect = 1; case 'S':


Timer
k = j + 1; GSelect = 8;
TCCR1B |= (1 << CS10);
delay_ms(50); k = j + 1;
TCNT1 = 0;
break; s = 1;
// enable overflow interrupt
case 'X': delay_ms(50);
TIMSK |= (1 << TOIE1);
GSelect = 2; break;
//initialize overflow counter variable
k = j + 1; case ';':
tot_overflow = 0;
delay_ms(50); #asm("cli")

break; charReceived = 0;
a=b=i=j=k=uu=vv=ww=xx=0;
case 'Y': Konversi data ke integer
GSelect=0;
GSelect = 3; GNum = atoi(GMode); //atoi adalah
x=XTotal=YTotal=ZTotal=0; array to integer, nilai array diubah ke
k = j + 1; integer
z = 0;
delay_ms(50); MNum = atoi(MMode);
Aktif =1;
break; XNew = atoi(GX);
NonAktif=0;
case 'Z': YNew = atoi(GY);
MaxRegister = 65536;
GSelect = 4; ZNew = atoi(GZ);
iterasi_linear = MaxRegister;
k = j + 1; RADIUS = atoi(GR);
iterasi_circular = 1.57 * MaxRegister;
delay_ms(50); GFeed = atoi(GF);
#asm("sei")
break; SNum = atoi(SMode);
i=0;
\
Program Parsing
case 'R': XTotal=XTotal+XNew;
while (1)
GSelect = 5; YTotal=YTotal+YNew;
{
k = j + 1; ZNewABS = abs(ZNew - ZOld);
i=j=k=GSelect=0;
delay_ms(50); Program Sumbu Z
XNew = YNew = XOld = YOld = ZNew
= ZOld= 0; break; if(ZNew > 0) Zmaju = 1;

if(charReceived == 1) case 'F': else if(ZNew < 0) Zmaju = 0;

{ GSelect = 6; if(ZNewABS != 0 )

PORTC.1 = 0; //LAMPU STANDBY k = j + 1; {


KUNING
delay_ms(50); if(EMG==1){goto skipfinish;}
PORTC.0 = 1; //LAMPU RUN HIJAU
break; putarZ(ZNewABS, Zmaju);
ZNewABS = 0; { }

delay_ms(100); A = 0; }

goto getout; B = 0; if(MNum == 4) //


SPINDLE CCW
} C = 1;
{
goto getout;
if(EMG==1){goto
Program M-Code } skipfinish;}

if(MNum == 3) // spindle CW if(SNum <=4749 && SNum >= DIRECTION = 1;


4550)
{ if(SNum >=5250)
{
if(EMG==1){goto {
skipfinish;} A = 1;
A = 1;
PORTD.7 = 1; B = 1;
B = 1;
DIRECTION = 0; C = 0;
C = 1;
if(SNum >=5250) goto getout;
goto getout;
{ }
}
A = 1; if(SNum <=4549 && SNum >=
4100) if(SNum <=5249 && SNum
B = 1; >=5200)
{
C = 1; {
A = 0;
goto getout; A = 0;
B = 1;
} B = 1;
C = 0;
if(SNum <=5249 && SNum C = 1;
>=5200) goto getout;
goto getout;
{ }
}
A = 0; if(SNum <=4099 && SNum
>= 0) if(SNum <=5199 && SNum >=
B = 1; 4900)
{
C = 1; {
A = 0;
goto getout; A = 1;
B = 0;
} B = 0;
C = 1;
if(SNum <=5199 && SNum >= C = 1;
4900) goto getout;
goto getout;
{ }
}
A = 1; if(SNum == 0)
if(SNum <=4899 && SNum >=
B = 0; { 4750)

C = 1; A = 0; {

goto getout; B = 0; A = 0;

} C = 0; B = 0;

if(SNum <=4899 && SNum >= goto getout; C = 1;


4750)
goto getout; { else if(XNew > XOld && YNew < YOld)
kuadranlinier = 4; // X+ Y-
} A=0;B=0;C=0;
else if(XNew > XOld && YNew ==
if(SNum <=4749 && SNum >= PORTD.7 = 0; YOld) kuadranlinier = 1; // X+
4550)
if(EMG==1){goto else if(XNew < XOld &&
{ skipfinish;} YNew == YOld) kuadranlinier = 3; //
X-
A = 1; goto getout;
else if(XNew == XOld && YNew <
B = 1; }
YOld) kuadranlinier = 3; // Y-
C = 0; Program Absolut /
else if(XNew == XOld && YNew >
Inkrimen
goto getout; YOld) kuadranlinier = 1; // Y+
if (GNum == 90) //abs
} else if(XNew == XOld && YNew ==
{ YOld) kuadranlinier = 1;// DIAM
if(SNum <=4549 && SNum >=
4100) if(EMG==1){goto XNewABS = abs(XNew - XOld);
skipfinish;}
{ YNewABS = abs(YNew - YOld);
p = 1;
A = 0; ZNewABS = abs(ZNew - ZOld);
milih = 1;
B = 1; pkx = XNewABS /0.02 ;
goto getout;
C = 0; pky = YNewABS /0.02 ;
}
goto getout; if(EMG==1){goto skipfinish;}
else if (GNum == 91) //
} LinearInterpolation(500);
inkriment
if(SNum <=4099 && SNum if(EMG==1){goto skipfinish;}
{
>= 0)
XOld = XNew;
if(EMG==1){goto
{ skipfinish;} YOld = YNew;
A = 0; p = 2; delay_ms(100);
B = 0; milih = 2; pkx=pky=qkx=qky=dpy=dpx=0;
C = 1; goto getout; }
goto getout; } if(GNum == 1)
} Program G-Code Absolut {
if(SNum == 0) if ( p == 1) if(EMG==1){goto skipfinish;}
{ { if(XNew > XOld && YNew > YOld)
A = 0; kuadranlinier = 1; // X+ Y+
if(GNum == 0)
B = 0; else if(XNew < XOld && YNew > YOld)
{
kuadranlinier = 2; // X- Y+
C = 0; if(EMG==1){goto skipfinish;}
else if(XNew < XOld && YNew < YOld)
goto getout; if(XNew > XOld && YNew > YOld) kuadranlinier = 3; // X- Y-
kuadranlinier = 1; // X+ Y+
} else if(XNew > XOld && YNew < YOld)
else if(XNew < XOld && YNew > YOld) kuadranlinier = 4; // X+ Y-
}
kuadranlinier = 2; // X- Y+
else if(XNew > XOld && YNew ==
else if(XNew < XOld && YNew < YOld) YOld) kuadranlinier = 1; // X+

if(MNum == 5) //SPINDLE kuadranlinier = 3; // X- Y-


else if(XNew < XOld && YNew ==
STOP YOld) kuadranlinier = 3; // X-
else if(XNew == XOld && YNew < mode = 1 ; XTotal=0;
YOld) kuadranlinier = 3; // Y-
DirectionX=0; //cw YTotal=0;
else if(XNew == XOld && YNew >
YOld) kuadranlinier = 1; // Y+ DirectionY=1; //cw delay_ms(100);

else if(XNew == XOld && YNew == } } }} }


YOld) kuadranlinier = 1;// DIAM
if(XNew < XOld && YNew < YOld) // if(GNum == 3) //Circular CCW
XNewABS = abs(XNew - XOld); x- y-
{
YNewABS = abs(YNew - YOld); {
if(EMG==1){goto skipfinish;}
if(EMG==1){goto skipfinish;} pkx = 0;
if(XNew != XOld && YNew != YOld){
pkx = XNewABS /0.02 ; pky = RADIUS/0.02;
XNewABS = abs(XNew - XOld);
pky = YNewABS /0.02 ; mode = 1 ;
YNewABS = abs(YNew - YOld);
if(EMG==1){goto skipfinish;} DirectionX=1; //ccw
if(XNewABS == YNewABS)
LinearInterpolation(GFeed); DirectionY=0; //ccw
{
if(EMG==1){goto skipfinish;} }
if(XNewABS == RADIUS && YNewABS
XOld = XNew; if(XNew < XOld && YNew > YOld) // == RADIUS)
x- y+
YOld = YNew; {
{
delay_ms(100); if(XNew < XOld && YNew > YOld) //
pkx = RADIUS/0.02; x- y+
pkx=pky=qkx=qky=dpy=dpx=0;
pky = 0; {
XTotal=0;
mode = 2 ; pkx = 0;
YTotal=0;
DirectionX=1; // pky = RADIUS/0.02;
}
DirectionY=1; mode = 3 ;
if(GNum == 2) //Circular CW
} DirectionX=1;
{
if(XNew > XOld && YNew < YOld) // DirectionY=1;
if(EMG==1){goto skipfinish;} x+ y-
if(XNew != XOld && YNew != YOld) if(EMG==1){goto skipfinish;}
{ CircularInterpolation(GFeed);
{
pkx = RADIUS/0.02; if(EMG==1){goto skipfinish;}
XNewABS = abs(XNew - XOld); pkx=pky=qkx=qky=dpy=dpx=0;
pky = 0;
YNewABS = abs(YNew - YOld); }
mode = 2 ;
if(XNewABS == YNewABS) else if(XNew > XOld && YNew < YOld)
DirectionX=0; // x+ y-
{
DirectionY=0; {
if(XNewABS == RADIUS && YNewABS
== RADIUS) } pkx = 0;

{ if(EMG==1){goto skipfinish;} pky = RADIUS/0.02;


CircularInterpolation(GFeed);
if(XNew > XOld && YNew > YOld) mode = 3 ;
// x+ y+ if(EMG==1){goto skipfinish;}
pkx=pky=qkx=qky=dpy=dpx=0; DirectionX=0;
{
XOld = XNew; DirectionY=0;
pkx = 0;
YOld = YNew; if(EMG==1){goto skipfinish;}
pky = RADIUS/0.02;
CircularInterpolation(GFeed); Program G-Code Inkrimen {

if(EMG==1){goto skipfinish;} else if ( p == 2) if(EMG==1){goto skipfinish;}

{ startx =0 ;
pkx=pky=qkx=qky=dpy=dpx=0;
if(GNum == 0) starty =0;
}
{ akhirx= XNew/0.02;
else if(XNew > XOld && YNew > YOld)
// x+ y+ if(EMG==1){goto skipfinish;} akhiry= YNew/0.02;

{ startx =0 ; pkx = akhirx - startx ;

pkx = RADIUS/0.02; starty =0; pky = akhiry - starty ;

pky = 0; akhirx= XNew/0.02; if ( akhirx > 0 && akhiry > 0 ) //


Kuadran1 X+Y+
mode = 4 ; akhiry= YNew/0.02;
{ pkx = 0;
DirectionX=0; pkx = akhirx - startx ;
pky = RADIUS/0.02;
DirectionY=1; pky = akhiry - starty ;
mode = 1 ;
if(EMG==1){goto skipfinish;} if(EMG==1){goto skipfinish;}
DirectionX=0; //cw
CircularInterpolation(GFeed); LinearInterpolation(1000);
DirectionY=1;} //cw
if(EMG==1){goto skipfinish;} if(EMG==1){goto skipfinish;}
if ( akhirx < 0 && akhiry < 0 ) //
pkx=pky=qkx=qky=dpy=dpx=0; XNew = YNew = 0; Kuadran3 X-Y-

} pkx=pky=qkx=qky=dpy=dpx=0; { pkx = 0;

else if(XNew < XOld && YNew < YOld) } pky = RADIUS/0.02;
// x- y-
if(GNum == 1) mode = 1 ;
{
{ DirectionX=1; //ccw
pkx = RADIUS/0.02;
if(EMG==1){goto skipfinish;} DirectionY=0; } //ccw
pky = 0;
startx =0 ; if ( akhirx < 0 && akhiry > 0 ) //
mode = 4 ; Kuadran2 X-Y+
starty =0;
DirectionX=1; { pkx = RADIUS/0.02;
akhirx= XNew/0.02;
DirectionY=0; pky = 0;
akhiry= YNew/0.02;
if(EMG==1){goto skipfinish;} mode = 2 ;
pkx = akhirx - startx ;
CircularInterpolation(GFeed);
DirectionX=1; //
pky = akhiry - starty ;
if(EMG==1){goto skipfinish;}
DirectionY=1;}
pkx=pky=qkx=qky=dpy=dpx=0;
if ( akhirx > 0 && akhiry < 0 ) //
if(EMG==1){goto skipfinish;}
} Kuadran4 X+Y-
LinearInterpolation(GFeed);
XOld = XNew; { pkx = RADIUS/0.02;
if(EMG==1){goto skipfinish;}
YOld = YNew; pky = 0;
XNew = YNew = 0;
XTotal=0; mode = 2 ;
pkx=pky=qkx=qky=dpy=dpx=0;
YTotal=0; DirectionX=0;
}
delay_ms(100); DirectionY=0;}
if(GNum == 2) //Circular CW
} } } } }
if(EMG==1){goto skipfinish;} DirectionY=1; } else if(GSelect == 6) GF[j - k] =
gcode[j];
CircularInterpolation(GFeed); =if (akhirx < 0 && akhiry < 0 ) //
Kuadran4 X-Y- else if(GSelect == 7) MMode[j - k] =
if(EMG==1){goto skipfinish;} gcode[j];
{ pkx = RADIUS/0.02;
XNew = YNew = 0; else if(GSelect == 8) SMode[j - k] =
pky = 0; gcode[j];
RADIUS = 0;
mode = 4 ; break;
pkx=pky=qkx=qky=dpy=dpx=0;
DirectionX=1; }
}
DirectionY=0;} j++;
if(GNum == 3) //Circular CCW
if(EMG==1){goto skipfinish;} }
{
CircularInterpolation(GFeed); skipfinish:
if(EMG==1){goto skipfinish;}
if(EMG==1){goto skipfinish;} if (EMG==1)
startx =0 ;
XNew = YNew = 0; {charReceived = 1;
starty =0;
RADIUS = 0; #asm("sei") }
akhirx= XNew/0.02;
pkx=pky=qkx=qky=dpy=dpx=0;
akhiry= YNew/0.02;
PulseX=PulseY=PulseZ=EnableX=Enab
} }
pkx = akhirx - startx ; leY=EnableZ=0;
getout:
pky = akhiry - starty ; s = 0;
memset(GMode, 0, sizeof(GMode));
if ( akhirx < 0 && akhiry > 0) // m = 0;
Kuadran2 X-Y+ memset(GX, 0, sizeof(GX));
rx_wr_index = 0;
{ pkx = 0; memset(GY, 0, sizeof(GY));
//tx_wr_index=0;
pky = RADIUS/0.02; memset(GZ, 0, sizeof(GZ));
memset(gcode, 0, sizeof(gcode));
mode = 3 ; memset(GR, 0, sizeof(GR));
memset(MMode, 0, sizeof(MMode));
DirectionX=1; memset(MMode, 0, sizeof(MMode));
memset(SMode, 0, sizeof(SMode));
DirectionY=1;} delay_ms(100);
charReceived = 0;
if ( akhirx > 0 && akhiry < 0 ) // charReceived = 1;
XNew = YNew = XOld = YOld = 0;
Kuadran4 X+Y-
#asm("sei")
EMG=0;
{ pkx = 0;
break;
delay_ms(200);
pky = RADIUS/0.02;
default:
}
mode = 3 ;
if(GSelect == 1)GMode[j - k] =
else if(charReceived == 0)
DirectionX=0; gcode[j];
{
DirectionY=0;} else if(GSelect == 2) GX[j - k] =
gcode[j]; PORTC.1 = 1; // LAMPU STANDBY
if ( akhirx > 0 && akhiry > 0) //
KUNING
Kuadran1 X+Y+ else if(GSelect == 3) GY[j - k] =
gcode[j]; PORTC.0 = 0; //LAMPU RUN HIJAU
{ pkx = RADIUS/0.02;
else if(GSelect == 4) GZ[j - k] = PORTC.2 = 0; //LAMPU EMG
pky = 0; gcode[j];
memset(gcode, 0, sizeof(gcode));
mode = 4 ; else if(GSelect == 5) GR[j - k] =
gcode[j]; memset(MMode, 0, sizeof(MMode));
DirectionX=0;
memset(SMode, 0, sizeof(SMode));
} putarZ(ztot, 1); if(p10 == 50)

Program HomePost {

if (PINC.4==1) //HOMEPOST } XTotal = XTotal - 1;

{ pkx = xtot/0.02; }

PORTC.1 = 0; // LAMPU STANDBY pky = ytot/0.02; delay_us(500);


KUNING
LinearInterpolation(1000); PulseX = 0;
PORTC.0 = 1; //LAMPU RUN HIJAU
ztot = 0; delay_us(500);
if (p == 1)
XTotal=xtot=YTotal = ytot = pkx }
{ =pky =0;
else if(PIND.7==1) //z+
if (XNewABS != 0 || YNewABS !=0) } } }
{
{ Program Tombol Manual
memset(gcode, 0, sizeof(gcode));
XNew = 0; else if (PIND.5==1) //X+
DirectionZ=1;
YNew = 0; {
EnableZ = 1;
if(XNew < YNewABS && YNew < memset(gcode, 0, sizeof(gcode));
YNewABS) kuadranlinier = 3; // X- Y- PulseZ = 1;
DirectionX=0;
pkx = XNewABS /0.02 ; putsf("XB0YF0ZF1");
EnableX = 1;
pky = YNewABS /0.02 ; delay_us(500);
PulseX = 1;
PulseZ = 0;
putsf("XF1YF0ZF0");
LinearInterpolation(1000); delay_us(500);
p9=p9+1;
XNewABS=YNewABS= 0; }
if(p9 == 50)
XTotal=xtot=YTotal = ytot = pkx else if(PIND.4==1 ) //z-
=pky =0; {
{
} XTotal = XTotal + 1;
memset(gcode, 0, sizeof(gcode));
} }
DirectionZ=0;
else delay_us(500);
EnableZ = 1;
{ PulseX = 0;
PulseZ = 1;
if (XTotal != 0 || YTotal !=0) delay_us(500);
putsf("XB0YF0ZB1");
{ }
delay_us(500);
PORTB.3 = 0; else if (PIND.6==1) //x-
PulseZ = 0;
PORTB.6 = 0; {
delay_us(500);
PORTB.7 = 0; memset(gcode, 0, sizeof(gcode));
}
xtot = -1 * XTotal ; DirectionX=1;
else if(PINA.6==1) //y+ //C
ytot = -1 * YTotal ; EnableX = 1;
{
ztot = 5; PulseX = 1;
memset(gcode, 0, sizeof(gcode));
if(ztot > 0 ) p10=p10+1;
DirectionY=1;
{ putsf("XB1YF0ZF0");
EnableY = 1;
PulseY = 1;

p11=p11+1;

putsf("XB0YF1ZF0");

if(p11 == 50)

YTotal = YTotal + 1;

delay_us(500);

PulseY = 0;

delay_us(500);

else if(PINA.7==1) //y- //C

memset(gcode, 0, sizeof(gcode));

DirectionY=0;

EnableY = 1;

PulseY = 1;

p11=p11+1;

putsf("XB0YB1ZF0");

if(p12 == 50)

YTotal = YTotal - 1;

delay_us(500);

PulseY = 0;

delay_us(500);

PulseX = 0;

PulseY = 0;

PulseZ = 0;

EnableX = 0;

EnableY = 0;

EnableZ = 0;

You might also like