#line 1 "E:/PROGRAMY INSTALOVANE/FED/PIXIE/PreProc.C"
#line 3 "E:/PROGRAMY INSTALOVANE/FED/PIXIE/Libs/ProcIncs/P16F628.h"
typedef unsigned char BYTE;
typedef unsigned char FileReg;
typedef unsigned int WORD;
typedef unsigned long ulong;
#line 79
extern FileReg INDF ;
extern FileReg TMR0 ;
extern FileReg PCL ;
extern FileReg STATUS ;
extern FileReg FSR ;
extern FileReg PORTA ;
extern FileReg PORTB ;
extern FileReg PCLATH ;
extern FileReg INTCON ;
extern FileReg PIR1 ;
extern FileReg TMR1L ;
extern FileReg TMR1H ;
extern FileReg T1CON ;
extern FileReg TMR2 ;
extern FileReg T2CON ;
extern FileReg CCPR1L ;
extern FileReg CCPR1H ;
extern FileReg CCP1CON ;
extern FileReg RCSTA ;
extern FileReg TXREG ;
extern FileReg RCREG ;
extern FileReg CMCON ;
extern FileReg OPTION_REG ;
extern FileReg TRISA ;
extern FileReg TRISB ;
extern FileReg PIE1 ;
extern FileReg PCON ;
extern FileReg PR2 ;
extern FileReg TXSTA ;
extern FileReg SPBRG ;
extern FileReg EEDATA ;
extern FileReg EEADR ;
extern FileReg EECON1 ;
extern FileReg EECON2 ;
extern FileReg VRCON ;

#pragma locate INDF 0x0000
#pragma locate TMR0 0x0001
#pragma locate PCL 0x0002
#pragma locate STATUS 0x0003
#pragma locate FSR 0x0004
#pragma locate PORTA 0x0005
#pragma locate PORTB 0x0006
#pragma locate PCLATH 0x000A
#pragma locate INTCON 0x000B
#pragma locate PIR1 0x000C
#pragma locate TMR1L 0x000E
#pragma locate TMR1H 0x000F
#pragma locate T1CON 0x0010
#pragma locate TMR2 0x0011
#pragma locate T2CON 0x0012
#pragma locate CCPR1L 0x0015
#pragma locate CCPR1H 0x0016
#pragma locate CCP1CON 0x0017
#pragma locate RCSTA 0x0018
#pragma locate TXREG 0x0019
#pragma locate RCREG 0x001A
#pragma locate CMCON 0x001F
#pragma locate OPTION_REG 0x0081
#pragma locate TRISA 0x0085
#pragma locate TRISB 0x0086
#pragma locate PIE1 0x008C
#pragma locate PCON 0x008E
#pragma locate PR2 0x0092
#pragma locate TXSTA 0x0098
#pragma locate SPBRG 0x0099
#pragma locate EEDATA 0x009A
#pragma locate EEADR 0x009B
#pragma locate EECON1 0x009C
#pragma locate EECON2 0x009D
#pragma locate VRCON 0x009F
#line 152
enum T_STATUS {
IRP =0x0007,RP1 =0x0006,RP0 =0x0005,NOT_TO =0x0004,NOT_PD =0x0003,Z =0x0002,DC =0x0001,C =0x0000
};

enum T_INTCON {
GIE =0x0007,PEIE =0x0006,T0IE =0x0005,INTE =0x0004,RBIE =0x0003,T0IF =0x0002,INTF =0x0001,RBIF =0x0000
};

enum T_PIR1 {
EEIF=7,CMIF =0x0006,RCIF=5,TXIF=4,CCP1IF=2,TMR2IF=1,TMR1IF=0
};

enum T_T1CON {
T1CKPS1 =0x0005,T1CKPS0 =0x0004,T1OSCEN =0x0003,NOT_T1SYNC =0x0002,TMR1CS =0x0001,TMR1ON =0x0000
};

enum T_T2CON {
TOUTPS3 =0x0006,TOUTPS2 =0x0005,TOUTPS1 =0x0004,TOUTPS0 =0x0003,TMR2ON =0x0002,T2CKPS1 =0x0001,T2CKPS0 =0x0000
};

enum T_CCP1CON {
CCP1X =0x0005,CCP1Y =0x0004,CCP1M3 =0x0003,CCP1M2 =0x0002,CCP1M1 =0x0001,CCP1M0 =0x0000
};

enum T_RCSTA {
SPEN =0x0007,RX9 =0x0006,SREN =0x0005,CREN =0x0004,ADDEN =0x0003,FERR =0x0002,OERR =0x0001,RX9D =0x0000
};

enum T_CMCON {
C2OUT=0x0007,C1OUT=0x0006,C2INV=0x0005,C1INV=0x0004,
CIS=0x0003,CM2=0x0002,CM1=0x0001,CM0=0x0000
};

enum T_OPTION {
NOT_RBPU =0x0007,INTEDG =0x0006,T0CS =0x0005,T0SE =0x0004,PSA =0x0003,PS2 =0x0002,PS1 =0x0001,PS0 =0x0000
};

enum T_PIE1 {
EEIE =0x0007,CMIE =0x0006,RCIE =0x0005,TXIE =0x0004,CCP1IE =0x0002,
TMR2IE =0x0001,TMR1IE =0x0000
};

enum T_PCON {
OSCF=0x0003,NOT_POR =0x0001,NOT_BO =0x0000
};

enum T_TXSTA {
CSRC =0x0007,TX9 =0x0006,TXEN =0x0005,SYNC =0x0004,BRGH =0x0002,TRMT =0x0001,TX9D =0x0000
};

enum T_EECON1 {
WRERR =0x0003,WREN =0x0002,WR =0x0001,RD =0x0000
};

enum T_VRCON {

VREN=7,VROE=6,VRR=5,VR3=0x3,VR2=0x2,VR1=0x1,VR0=0
};
#line 214
struct sPort
{
unsigned char B0:1;
unsigned char B1:1;
unsigned char B2:1;
unsigned char B3:1;
unsigned char B4:1;
unsigned char B5:1;
unsigned char B6:1;
unsigned char B7:1;
};

extern sPort PA;
#pragma locate PA 5
extern sPort PB;
#pragma locate PB 6
extern sPort PC;
#pragma locate PC 7
extern sPort PD;
#pragma locate PD 8
extern sPort PE;
#pragma locate PE 9
#line 5 "E:/PROGRAMY INSTALOVANE/FED/PIXIE/Libs/ProcIncs/P16F628_bits.h"
extern bit bC;
#pragma locate bC &STATUS,0x00
extern bit bDC;
#pragma locate bDC &STATUS,0x01
extern bit bIRP;
#pragma locate bIRP &STATUS,0x07
extern bit bNOT_PD;
#pragma locate bNOT_PD &STATUS,0x03
extern bit bNOT_TO;
#pragma locate bNOT_TO &STATUS,0x04
extern bit bRP0;
#pragma locate bRP0 &STATUS,0x05
extern bit bRP1;
#pragma locate bRP1 &STATUS,0x06
extern bit bZ;
#pragma locate bZ &STATUS,0x02

extern bit bGIE;
#pragma locate bGIE &INTCON,0x07
extern bit bINTE;
#pragma locate bINTE &INTCON,0x04
extern bit bINTF;
#pragma locate bINTF &INTCON,0x01
extern bit bPEIE;
#pragma locate bPEIE &INTCON,0x06
extern bit bRBIE;
#pragma locate bRBIE &INTCON,0x03
extern bit bRBIF;
#pragma locate bRBIF &INTCON,0x00
extern bit bT0IE;
#pragma locate bT0IE &INTCON,0x05
extern bit bT0IF;
#pragma locate bT0IF &INTCON,0x02

extern bit bCCP1IF;
#pragma locate bCCP1IF &PIR1,0x02
extern bit bCMIF;
#pragma locate bCMIF &PIR1,0x06
extern bit bEEIF;
#pragma locate bEEIF &PIR1,0x07
extern bit bRCIF;
#pragma locate bRCIF &PIR1,0x05
extern bit bTMR1IF;
#pragma locate bTMR1IF &PIR1,0x00
extern bit bTMR2IF;
#pragma locate bTMR2IF &PIR1,0x01
extern bit bTXIF;
#pragma locate bTXIF &PIR1,0x04

extern bit bNOT_T1SYNC;
#pragma locate bNOT_T1SYNC &T1CON,0x02
extern bit bT1CKPS0;
#pragma locate bT1CKPS0 &T1CON,0x04
extern bit bT1CKPS1;
#pragma locate bT1CKPS1 &T1CON,0x05
extern bit bT1OSCEN;
#pragma locate bT1OSCEN &T1CON,0x03
extern bit bTMR1CS;
#pragma locate bTMR1CS &T1CON,0x01
extern bit bTMR1ON;
#pragma locate bTMR1ON &T1CON,0x00

extern bit bT2CKPS0;
#pragma locate bT2CKPS0 &T2CON,0x00
extern bit bT2CKPS1;
#pragma locate bT2CKPS1 &T2CON,0x01
extern bit bTMR2ON;
#pragma locate bTMR2ON &T2CON,0x02
extern bit bTOUTPS0;
#pragma locate bTOUTPS0 &T2CON,0x03
extern bit bTOUTPS1;
#pragma locate bTOUTPS1 &T2CON,0x04
extern bit bTOUTPS2;
#pragma locate bTOUTPS2 &T2CON,0x05
extern bit bTOUTPS3;
#pragma locate bTOUTPS3 &T2CON,0x06

extern bit bCCP1M0;
#pragma locate bCCP1M0 &CCP1CON,0x00
extern bit bCCP1M1;
#pragma locate bCCP1M1 &CCP1CON,0x01
extern bit bCCP1M2;
#pragma locate bCCP1M2 &CCP1CON,0x02
extern bit bCCP1M3;
#pragma locate bCCP1M3 &CCP1CON,0x03
extern bit bCCP1X;
#pragma locate bCCP1X &CCP1CON,0x05
extern bit bCCP1Y;
#pragma locate bCCP1Y &CCP1CON,0x04

extern bit bADEN;
#pragma locate bADEN &RCSTA,0x03
extern bit bCREN;
#pragma locate bCREN &RCSTA,0x04
extern bit bFERR;
#pragma locate bFERR &RCSTA,0x02
extern bit bOERR;
#pragma locate bOERR &RCSTA,0x01
extern bit bRX9;
#pragma locate bRX9 &RCSTA,0x06
extern bit bRX9D;
#pragma locate bRX9D &RCSTA,0x00
extern bit bSPEN;
#pragma locate bSPEN &RCSTA,0x07
extern bit bSREN;
#pragma locate bSREN &RCSTA,0x05

extern bit bC1INV;
#pragma locate bC1INV &CMCON,0x04
extern bit bC1OUT;
#pragma locate bC1OUT &CMCON,0x06
extern bit bC2INV;
#pragma locate bC2INV &CMCON,0x05
extern bit bC2OUT;
#pragma locate bC2OUT &CMCON,0x07
extern bit bCIS;
#pragma locate bCIS &CMCON,0x03
extern bit bCM0;
#pragma locate bCM0 &CMCON,0x00
extern bit bCM1;
#pragma locate bCM1 &CMCON,0x01
extern bit bCM2;
#pragma locate bCM2 &CMCON,0x02

extern bit bINTEDG;
#pragma locate bINTEDG &OPTION_REG,0x06
extern bit bNOT_RBPU;
#pragma locate bNOT_RBPU &OPTION_REG,0x07
extern bit bPS0;
#pragma locate bPS0 &OPTION_REG,0x00
extern bit bPS1;
#pragma locate bPS1 &OPTION_REG,0x01
extern bit bPS2;
#pragma locate bPS2 &OPTION_REG,0x02
extern bit bPSA;
#pragma locate bPSA &OPTION_REG,0x03
extern bit bT0CS;
#pragma locate bT0CS &OPTION_REG,0x05
extern bit bT0SE;
#pragma locate bT0SE &OPTION_REG,0x04

extern bit bCCP1IE;
#pragma locate bCCP1IE &PIE1,0x02
extern bit bCMIE;
#pragma locate bCMIE &PIE1,0x06
extern bit bEEIE;
#pragma locate bEEIE &PIE1,0x07
extern bit bRCIE;
#pragma locate bRCIE &PIE1,0x05
extern bit bTMR1IE;
#pragma locate bTMR1IE &PIE1,0x00
extern bit bTMR2IE;
#pragma locate bTMR2IE &PIE1,0x01
extern bit bTXIE;
#pragma locate bTXIE &PIE1,0x04

extern bit bNOT_BO;
#pragma locate bNOT_BO &PCON,0x00
extern bit bNOT_BOR;
#pragma locate bNOT_BOR &PCON,0x00
extern bit bNOT_POR;
#pragma locate bNOT_POR &PCON,0x01
extern bit bOSCF;
#pragma locate bOSCF &PCON,0x03

extern bit bBRGH;
#pragma locate bBRGH &TXSTA,0x02
extern bit bCSRC;
#pragma locate bCSRC &TXSTA,0x07
extern bit bSYNC;
#pragma locate bSYNC &TXSTA,0x04
extern bit bTRMT;
#pragma locate bTRMT &TXSTA,0x01
extern bit bTX9;
#pragma locate bTX9 &TXSTA,0x06
extern bit bTX9D;
#pragma locate bTX9D &TXSTA,0x00
extern bit bTXEN;
#pragma locate bTXEN &TXSTA,0x05

extern bit bRD;
#pragma locate bRD &EECON1,0x00
extern bit bWR;
#pragma locate bWR &EECON1,0x01
extern bit bWREN;
#pragma locate bWREN &EECON1,0x02
extern bit bWRERR;
#pragma locate bWRERR &EECON1,0x03

extern bit bVR0;
#pragma locate bVR0 &VRCON,0x00
extern bit bVR1;
#pragma locate bVR1 &VRCON,0x01
extern bit bVR2;
#pragma locate bVR2 &VRCON,0x02
extern bit bVR3;
#pragma locate bVR3 &VRCON,0x03
extern bit bVREN;
#pragma locate bVREN &VRCON,0x07
extern bit bVROE;
#pragma locate bVROE &VRCON,0x06
extern bit bVRR;
#pragma locate bVRR &VRCON,0x05
#line 9 "E:/PROGRAMY INSTALOVANE/FED/PIXIE/Libs/PortBits.h"
extern bit bRA0,bRA1,bRA2,bRA3,bRA4,bRA5,bRA6,bRA7;
extern bit bTRA0,bTRA1,bTRA2,bTRA3,bTRA4,bTRA5,bTRA6,bTRA7;
extern bit bRB0,bRB1,bRB2,bRB3,bRB4,bRB5,bRB6,bRB7;
extern bit bTRB0,bTRB1,bTRB2,bTRB3,bTRB4,bTRB5,bTRB6,bTRB7;
extern bit bRC0,bRC1,bRC2,bRC3,bRC4,bRC5,bRC6,bRC7;
extern bit bTRC0,bTRC1,bTRC2,bTRC3,bTRC4,bTRC5,bTRC6,bTRC7;
extern bit bRD0,bRD1,bRD2,bRD3,bRD4,bRD5,bRD6,bRD7;
extern bit bTRD0,bTRD1,bTRD2,bTRD3,bTRD4,bTRD5,bTRD6,bTRD7;
extern bit bRE0,bRE1,bRE2,bRE3,bRE4,bRE5,bRE6,bRE7;
extern bit bTRE0,bTRE1,bTRE2,bTRE3,bTRE4,bTRE5,bTRE6,bTRE7;
#line 21
#pragma locate bRA0 5,0
#pragma locate bRA1 5,1
#pragma locate bRA2 5,2
#pragma locate bRA3 5,3
#pragma locate bRA4 5,4
#pragma locate bRA5 5,5
#pragma locate bRA6 5,6
#pragma locate bRA7 5,7
#pragma locate bRB0 6,0
#pragma locate bRB1 6,1
#pragma locate bRB2 6,2
#pragma locate bRB3 6,3
#pragma locate bRB4 6,4
#pragma locate bRB5 6,5
#pragma locate bRB6 6,6
#pragma locate bRB7 6,7
#pragma locate bRC0 7,0
#pragma locate bRC1 7,1
#pragma locate bRC2 7,2
#pragma locate bRC3 7,3
#pragma locate bRC4 7,4
#pragma locate bRC5 7,5
#pragma locate bRC6 7,6
#pragma locate bRC7 7,7
#pragma locate bRD0 8,0
#pragma locate bRD1 8,1
#pragma locate bRD2 8,2
#pragma locate bRD3 8,3
#pragma locate bRD4 8,4
#pragma locate bRD5 8,5
#pragma locate bRD6 8,6
#pragma locate bRD7 8,7
#pragma locate bRE0 9,0
#pragma locate bRE1 9,1
#pragma locate bRE2 9,2
#pragma locate bRE3 9,3
#pragma locate bRE4 9,4
#pragma locate bRE5 9,5
#pragma locate bRE6 9,6
#pragma locate bRE7 9,7
#pragma locate bTRA0 0x85,0
#pragma locate bTRA1 0x85,1
#pragma locate bTRA2 0x85,2
#pragma locate bTRA3 0x85,3
#pragma locate bTRA4 0x85,4
#pragma locate bTRA5 0x85,5
#pragma locate bTRA6 0x85,6
#pragma locate bTRA7 0x85,7
#pragma locate bTRB0 0x86,0
#pragma locate bTRB1 0x86,1
#pragma locate bTRB2 0x86,2
#pragma locate bTRB3 0x86,3
#pragma locate bTRB4 0x86,4
#pragma locate bTRB5 0x86,5
#pragma locate bTRB6 0x86,6
#pragma locate bTRB7 0x86,7
#pragma locate bTRC0 0x87,0
#pragma locate bTRC1 0x87,1
#pragma locate bTRC2 0x87,2
#pragma locate bTRC3 0x87,3
#pragma locate bTRC4 0x87,4
#pragma locate bTRC5 0x87,5
#pragma locate bTRC6 0x87,6
#pragma locate bTRC7 0x87,7
#pragma locate bTRD0 0x88,0
#pragma locate bTRD1 0x88,1
#pragma locate bTRD2 0x88,2
#pragma locate bTRD3 0x88,3
#pragma locate bTRD4 0x88,4
#pragma locate bTRD5 0x88,5
#pragma locate bTRD6 0x88,6
#pragma locate bTRD7 0x88,7
#pragma locate bTRE0 0x89,0
#pragma locate bTRE1 0x89,1
#pragma locate bTRE2 0x89,2
#pragma locate bTRE3 0x89,3
#pragma locate bTRE4 0x89,4
#pragma locate bTRE5 0x89,5
#pragma locate bTRE6 0x89,6
#pragma locate bTRE7 0x89,7
#line 22 "C:/Documents and Settings/Marek/Desktop/Bakalarka 2009/PIC628A program/StpDrvPic628/StepperDriverPic628_Auto.h"
void UserInitialise();
void UserInterrupt();
void UserLoop();
#line 28
#pragma asmline _PortInnCopy=1
#line 36
#pragma asmline _PortInUsed=1

#pragma asmline _PortIn0Used=1
#line 46
#pragma asmline _In0Port=PORTB
#pragma asmline _In0Bit=1
#pragma asmline _RXPort=PORTB
#pragma asmline _RXBit=1
#line 17 "C:/DOCUMENTS AND SETTINGS/Marek/Desktop/BAKALARKA 2009/PIC628A PROGRAM/STPDRVPIC628/STEPPERDRIVERPIC628_USER.C"
bool stop = 1;
unsigned char steps = 0;
unsigned char goalstep = 0;
char lastchar = "*";
bool freeride;
unsigned char ledCounter = 0;
#line 35
void SendChar(char send)
{
#pragma asmline bsf STATUS,RP0
#pragma asmline btfss TXSTA,TRMT
#pragma asmline goto $-1
#pragma asmline bcf STATUS,RP0
TXREG = send;
}

void SendCommand(char *command, char length)
{
int i;
SendChar(0x0D);
SendChar(0x0A);
for(i = 0; i < length; i++)
{
SendChar(*command);
command++;
}
SendChar(0x0D);
SendChar(0x0A);
}

void UserInterrupt()
{

if(PIR1 & (1 << TMR2IF))
{
ledCounter++;
if(ledCounter == 50)
{

bRB3 = !bRB3;
ledCounter = 0;
}
PIR1 &= ~(1 << TMR2IF);
}
if(PIR1 & (1 << TMR1IF))
{
if(!stop)
{
bRA2 = 0;
bRB4 = 0;
bRB0 = !bRB0;
bRB6 = !bRB6;
if((bRB0 == 1)||(bRB6 == 1)) steps++;

if((steps == 10)&&(goalstep >= 10)&&(freeride == 0))
{
SendChar(10);
goalstep -= 10;
steps = 0;
}
if((steps == 10)&&(freeride == 1))
{
SendChar(10);
goalstep = 0;
steps = 0;
}
if((steps == goalstep)&&(freeride == 0))
{
SendChar(steps);
steps = 0;
goalstep = 0;
stop = 1;
bRA2 = 1;
bRB4 = 1;
}

}
TMR1H = 0x90;
PIR1 &= ~(1 << TMR1IF);
}

if(PIR1 & (1 << RCIF))
if((RCSTA & (1 << OERR))||(RCSTA & (1 << FERR)))
{

RCSTA &= ~(1 << CREN);
RCSTA |= (1 << CREN);
}
else
{
char Recchar = RCREG;
if(lastchar == '*')
lastchar = Recchar;
else
{
switch(lastchar)
{
case('F'):
{
bRA1 = 0;
bRB7 = 1;
goalstep = Recchar;
if(goalstep == 0) freeride = 1; else freeride = 0;
SendChar(steps);
steps = 0;
stop = 0;
break;
}
case('B'):
{
bRA1 = 1;
bRB7 = 0;
goalstep = Recchar;
if(goalstep == 0) freeride = 1; else freeride = 0;
SendChar(steps);
steps = 0;
stop = 0;
break;
}
case('L'):
{
bRA1 = 0;
bRB7 = 0;
goalstep = Recchar;
if(goalstep == 0) freeride = 1; else freeride = 0;
SendChar(steps);
steps = 0;
stop = 0;
break;
}
case('R'):
{
bRA1 = 1;
bRB7 = 1;
goalstep = Recchar;
if(goalstep == 0) freeride = 1; else freeride = 0;
SendChar(steps);
steps = 0;
stop = 0;
break;
}
case('S'):
{
bRA1 = 0;
bRB7 = 0;
SendChar(steps);
steps = 0;
bRA2 = 1;
bRB4 = 1;
stop = 1;
break;
}
case('+'):
{
SendCommand("Hello",5);
break;
}
}
lastchar = '*';
}
}
#pragma asmline SETPCLATH UserIntReturn,-1
#pragma asmline goto UserIntReturn
}
#line 201
void UserInitialise()
{
#line 207
TXSTA=(1<<BRGH)|(1<<TXEN);
SPBRG=20000000/16/9600-1;

RCSTA=(1<<SPEN)|(1<<CREN);
INTCON|=(1<<PEIE);
PIE1|=(1<<TMR1IE);
PIE1|=(1<<TMR2IE);
PIE1|=(1<<RCIE);
CMCON = 0x07;
bRA2 = 1;
bRB4 = 1;
bRA3 = 1;
bRB5 = 1;

}
#line 229
void UserLoop()
{
}
