#ifndef _int_c_ #define _int_c_ #include "int.h" #pragma SRC unsigned char bdata ENC_FLAGS; sbit ENCHO_USE = ENC_FLAGS^0; sbit ENCVE_USE = ENC_FLAGS^1; sbit ENCHO_COR = ENC_FLAGS^2; sbit ENCVE_COR = ENC_FLAGS^3; sbit ENCHO_DIR = ENC_FLAGS^4; sbit ENCVE_DIR = ENC_FLAGS^5; sbit ENCHO_CORUSE = ENC_FLAGS^6; sbit ENCVE_CORUSE = ENC_FLAGS^7; unsigned char bdata MOT_FLAGS; sbit MOTHO_RUN = MOT_FLAGS^0; sbit MOTVE_RUN = MOT_FLAGS^1; sbit MOTFR_USE = MOT_FLAGS^2; sbit MOTHO_DIR = MOT_FLAGS^3; sbit MOTVE_DIR = MOT_FLAGS^4; sbit MOTFR_DIR = MOT_FLAGS^5; sbit MOT_GOTO = MOT_FLAGS^6; sbit MOT_CORRECTION = MOT_FLAGS^7; volatile int idata YEAR; volatile int idata MONTH; volatile int idata DAY; volatile int idata HOUR; volatile int idata MINUTE; volatile int idata SECOND; volatile int idata MSECOND; volatile int idata TIMER10; volatile int idata THISMDAYS; volatile int idata CFG_ENC_HO; volatile int idata CFG_ENC_VE; volatile int idata ARC10PERENCHO; volatile int idata ARC10PERENCVE; volatile long idata ENC_ARC10_HO; volatile long idata ENC_ARC10_VE; volatile long idata HSTEPSHO090; volatile long idata HSTEPSHO180; volatile long idata HSTEPSHO270; volatile long idata HSTEPSHO359; volatile long idata CUR_HSTEPS_HO; volatile long idata CUR_HSTEPS_VE; volatile long idata TRG_HSTEPS_HO; volatile long idata TRG_HSTEPS_VE; volatile long idata CUR_ARC10_HO; volatile long idata CUR_ARC10_VE; volatile int idata SPEED_HO; volatile int idata SPEED_VE; volatile int idata SPEED_FR; volatile int idata SPEED_HO_CT; volatile int idata SPEED_VE_CT; volatile int idata SPEED_FR_CT; volatile unsigned char idata hsteps[8] = { HSTEP1, HSTEP2, HSTEP3, HSTEP4, HSTEP5, HSTEP6, HSTEP7, HSTEP8 }; volatile int idata HSTEP_HO; volatile int idata HSTEP_VE; volatile int idata HSTEP_FR; volatile double idata CFG_HSTS_HO; volatile double idata CFG_HSTS_VE; volatile double idata CFG_HSTS_FR; volatile double idata DITMP1; volatile double idata DITMP2; void initTimerInt( void ) { T3IC = TIMERINTOFF; T3CON = TIMERSTOP; T4CON = TIMERSET; T4 = TIMERRELOAD; T3 = TIMERRELOAD; } void startTimerInt( void ) { TIMER10 = 0; T3 = TIMERRELOAD; T4 = TIMERRELOAD; T3CON = TIMERSTART; T3IC = TIMERINTON; } void stopTimerInt( void ) { T3IC = TIMERINTOFF; T3CON = TIMERSTOP; } #pragma ASM ;P2 DEFR 0FFC0H P7 DEFR 0FFD0H P8 DEFR 0FFD4H #pragma ENDASM //interrupt every 1/10000 second void timer_int (void) interrupt TIMER_INT = 0x23 using TIMER_BANK { TIMER10++; if( TIMER10 >= 10 ){ TIMER10 = 0; MSECOND++; if( MSECOND >= 1000 ){ MSECOND = 0; SECOND++; if( SECOND >= 60 ){ SECOND = 0; MINUTE++; if( MINUTE >= 60 ){ MINUTE = 0; HOUR++; if( HOUR >= 24 ){ HOUR = 0; DAY++; if( DAY > THISMDAYS ) { DAY = 1; MONTH++; if( MONTH > 12 ){ MONTH = 1; YEAR++; } } } } } } } /// so updating of date/time is down /// here we do the work for motors /// /// if( ENCHO_COR == ON ) { if( ENCHO_CORUSE == ON ) { DITMP1 = (double)ENC_ARC10_HO / (double)10; DITMP1 = (double)DITMP1 / (double)CFG_HSTS_HO; modf( DITMP1, &DITMP2); CUR_HSTEPS_HO = ( long )DITMP2; } ENCHO_COR = OFF; } if( ENCVE_COR == ON ) { if( ENCVE_CORUSE == ON ) { DITMP1 = (double)ENC_ARC10_VE / (double)10; DITMP1 = (double)DITMP1 / (double)CFG_HSTS_VE; modf( DITMP1, &DITMP2); CUR_HSTEPS_VE = ( long )DITMP2; } ENCVE_COR = OFF; } if( MOT_GOTO == ON ) { if( MOTHO_RUN == ON ) { if( (long)CUR_HSTEPS_HO == (long)TRG_HSTEPS_HO ){ MOTHO_RUN = OFF; } } if( MOTVE_RUN == ON ) { if( (long)CUR_HSTEPS_VE == (long)TRG_HSTEPS_VE ){ MOTVE_RUN = OFF; } } } if( ( MOT_GOTO == ON ) || ( MOT_CORRECTION == ON ) ) { if( MOTHO_RUN == ON ) { SPEED_HO_CT++; if( SPEED_HO_CT >= SPEED_HO ){ SPEED_HO_CT = 0; if( MOTHO_DIR == LEFT ) { HSTEP_HO--; if( HSTEP_HO < 0 ){ HSTEP_HO = 7; } CUR_HSTEPS_HO = (long)CUR_HSTEPS_HO - (long)1; if( CUR_HSTEPS_HO < (long)0 ){ CUR_HSTEPS_HO = (long)HSTEPSHO359; } } else { HSTEP_HO++; if( HSTEP_HO > 7 ){ HSTEP_HO = 0; } CUR_HSTEPS_HO = (long)CUR_HSTEPS_HO + (long)1; if( CUR_HSTEPS_HO > (long)HSTEPSHO359 ){ CUR_HSTEPS_HO = (long)0; } } #pragma ASM MOV R7,#hsteps ADD R7,HSTEP_HO MOVB RL6,[R7] ANDB RL6,#15 MOVB RL5,P7 ANDB RL5,#240 ORB RL6,RL5 MOVB P7,RL6 #pragma ENDASM } } if( MOTVE_RUN == ON ) { SPEED_VE_CT++; if( SPEED_VE_CT >= SPEED_VE ){ SPEED_VE_CT = 0; if( MOTVE_DIR == DOWN ) { HSTEP_VE--; if( HSTEP_VE < 0 ){ HSTEP_VE = 7; } CUR_HSTEPS_VE = (long)CUR_HSTEPS_VE - (long)1; } else { HSTEP_VE++; if( HSTEP_VE > 7 ){ HSTEP_VE = 0; } CUR_HSTEPS_VE = (long)CUR_HSTEPS_VE + (long)1; } #pragma ASM MOV R7,#hsteps ADD R7,HSTEP_VE MOVB RL6,[R7] ANDB RL6,#240 MOVB RL5,P7 ANDB RL5,#15 ORB RL6,RL5 MOVB P7,RL6 #pragma ENDASM } } if( ( MOTFR_USE == ON ) && ( MOT_GOTO == ON ) ){ SPEED_FR_CT++; if( SPEED_FR_CT >= SPEED_FR ){ SPEED_FR_CT = 0; if( MOTFR_DIR == LEFT ) { HSTEP_FR--; if( HSTEP_FR < 0 ){ HSTEP_FR = 7; } } else { HSTEP_FR++; if( HSTEP_FR > 7 ){ HSTEP_FR = 0; } } #pragma ASM MOV R7,#hsteps ADD R7,HSTEP_FR MOVB RL6,[R7] ANDB RL6,#15 MOVB RL5,P8 ANDB RL5,#240 ORB RL6,RL5 MOVB P8,RL6 #pragma ENDASM } } } } void initEncoderInts(void) { DP2_8 = INPUT; DP2_9 = INPUT; DP2_10 = INPUT; DP2_11 = INPUT; CC8IC = ENC1_0INTOFF; CC9IC = ENC1_1INTOFF; CC10IC = ENC2_0INTOFF; CC11IC = ENC2_1INTOFF; EXICON = 0x00ff; } void startEncoderIntsHo(void) { ENCHO_COR = OFF; ENCHO_DIR = RIGHT; CC8IC = ENC1_0INTON; CC9IC = ENC1_1INTON; } void startEncoderIntsVe(void) { ENCVE_COR = OFF; ENCVE_DIR = UP; CC10IC = ENC2_0INTON; CC11IC = ENC2_1INTON; } void stopEncoderInts(void) { CC8IC = ENC1_0INTOFF; CC9IC = ENC1_1INTOFF; CC10IC = ENC2_0INTOFF; CC11IC = ENC2_1INTOFF; ENCHO_COR = OFF; ENCVE_COR = OFF; } void encoder1_0_int (void) interrupt ENCODER1_0_INT = 0x18 using ENCODER10_BANK { #pragma ASM jb P2.8,LENC10HIGH jnb P2.9,LENC10RIGHT JMPR cc_UC,LENC10LEFT LENC10HIGH: jb P2.9,LENC10RIGHT LENC10LEFT: BSET ENC_FLAGS.4 #pragma ENDASM ENC_ARC10_HO = (long)ENC_ARC10_HO - (long)ARC10PERENCHO; if( ENC_ARC10_HO < (long)0){ ENC_ARC10_HO = (long)12960000 + (long)ENC_ARC10_HO; // ENC_ARC10_HO = (long)12959999 + (long)ENC_ARC10_HO; } #pragma ASM jmpr cc_UC,LENC10END LENC10RIGHT: BCLR ENC_FLAGS.4 #pragma ENDASM ENC_ARC10_HO = (long)ENC_ARC10_HO + (long)ARC10PERENCHO; if( ENC_ARC10_HO > (long)12959999 ){ ENC_ARC10_HO = (long)ENC_ARC10_HO - (long)12960000; // ENC_ARC10_HO = (long)ENC_ARC10_HO - (long)12959999; } #pragma ASM LENC10END: BSET ENC_FLAGS.2 #pragma ENDASM // max ~4us } void encoder1_1_int (void) interrupt ENCODER1_1_INT = 0x19 using ENCODER11_BANK { #pragma ASM jb P2.9,LENC11HIGH jb P2.8,LENC11RIGHT JMPR cc_UC,LENC11LEFT LENC11HIGH: jnb P2.8,LENC11RIGHT LENC11LEFT: BSET ENC_FLAGS.4 #pragma ENDASM ENC_ARC10_HO = (long)ENC_ARC10_HO - (long)ARC10PERENCHO; if( ENC_ARC10_HO < (long)0){ ENC_ARC10_HO = (long)12960000 + (long)ENC_ARC10_HO; // ENC_ARC10_HO = (long)12959999 + (long)ENC_ARC10_HO; } #pragma ASM jmpr cc_UC,LENC11END LENC11RIGHT: BCLR ENC_FLAGS.4 #pragma ENDASM ENC_ARC10_HO = (long)ENC_ARC10_HO + (long)ARC10PERENCHO; if( ENC_ARC10_HO > (long)12959999 ){ ENC_ARC10_HO = (long)ENC_ARC10_HO - (long)12960000; // ENC_ARC10_HO = (long)ENC_ARC10_HO - (long)12959999; } #pragma ASM LENC11END: BSET ENC_FLAGS.2 #pragma ENDASM } void encoder2_0_int (void) interrupt ENCODER2_0_INT = 0x1A using ENCODER20_BANK { #pragma ASM jb P2.10,LENC20HIGH jb P2.11,LENC20RIGHT JMPR cc_UC,LENC20LEFT LENC20HIGH: jnb P2.11,LENC20RIGHT LENC20LEFT: BSET ENC_FLAGS.5 #pragma ENDASM ENC_ARC10_VE = (long)ENC_ARC10_VE - (long)ARC10PERENCVE; #pragma ASM jmpr cc_UC,LENC20END LENC20RIGHT: BCLR ENC_FLAGS.5 #pragma ENDASM ENC_ARC10_VE = (long)ENC_ARC10_VE + (long)ARC10PERENCVE; #pragma ASM LENC20END: BSET ENC_FLAGS.3 #pragma ENDASM //max 3.2 us } void encoder2_1_int (void) interrupt ENCODER2_1_INT = 0x1B using ENCODER21_BANK { #pragma ASM jb P2.11,LENC21HIGH jnb P2.10,LENC21RIGHT JMPR cc_UC,LENC21LEFT LENC21HIGH: jb P2.10,LENC21RIGHT LENC21LEFT: BSET ENC_FLAGS.5 #pragma ENDASM ENC_ARC10_VE = (long)ENC_ARC10_VE - (long)ARC10PERENCVE; #pragma ASM jmpr cc_UC,LENC21END LENC21RIGHT: BCLR ENC_FLAGS.5 #pragma ENDASM ENC_ARC10_VE = (long)ENC_ARC10_VE + (long)ARC10PERENCVE; #pragma ASM LENC21END: BSET ENC_FLAGS.3 #pragma ENDASM } #endif