/* ========================================================================== */ /* HS303_1.C */ /* ========================================================================== */ /* Description : Control RC Servo-motor by two external pin interrupts. */ /* ========================================================================== */ /* HS-303 RC Servo Motor : 0.7ms(-90) бн 1.5ms(0) бн 2.3ms(90) Let Period = 5.0ms (= 6250 state) -90 = 0.7ms (= 875 state) 0 = 1.5ms (= 1875 state) +90 = 2.3ms (= 2875 state) */ #pragma dn(0) /* Error diagnostic level = 0 */ #pragma code /* Attach ASM code to .lst file */ #pragma pagelength(32767) /* Let the page length maximum */ #pragma model(kc) /* cpu model = 80C196KC */ #include <80c196.h> /* Standard header for 80C196 */ #define INT13 /* For pin 9 */ #define INT07 /* For pin 15 */ #include /* Definition of ISR and BYTE, WORD */ #include <196io.h> /* My header for additional I/Os */ #include /* For floating-point arithmetics */ const WORD period = 6250; /* 5.0ms */ const WORD hso1_set_time = 0; /* set time and reset time */ int hso1_reset_time; void INT13(void); /* No.15: External pin Interrupt : UP button */ void INT07(void); /* No. 9: External pin Interrupt : DOWN button */ void main(void) { hso1_reset_time = 0; /* Initial degree is 0 deg */ lcd_print(" PWM with HSO.1 ", LINE1); /* display title */ lcd_print(" Degree is 0 D", LINE2); timer2 = 0; /* timer 2 initial value */ ioc2 = 0xC0; /* clear HSO CAM and enable locking */ wsr = 1; t2control = 0x01; /* timer 2 internal clock source */ wsr = 0; fpinit(); /* For floating Point Arithmetic */ ioc1 = 0x02; /* Select pin no. 9 for external Interrupt */ int_mask = 0x80; /* Enable No.9 INT. */ imask1 = 0x20; /* Enable No.15 INT. */ enable(); /* Enable Global INT. */ /* HSO.1 */ /* Set Period */ while((ios0 & 0x40) == 0x40); hso_command = 0xCE; /* 11001110 ||||++++- timer2 reset |||+----- HSO Interrupt Disable ||+------ Set the selected pin to 0!!!!!!!!! |+------- Select timer2 +-------- CAM Lock */ hso_time = period; /* Set Time */ while((ios0 & 0x40) == 0x40); hso_command = 0xE1; /* 11100001 ||||++++- Select HSO.1 |||+----- HSO Interrupt Disable ||+------ Set the selected pin to 1!!!!!!!!! |+------- Select timer2 +-------- CAM Lock */ hso_time = hso1_set_time; /* Reset Time */ do{ while((ios0 & 0x40) == 0x40); hso_command = 0x41; /* 01000001 ||||++++- Select HSO.1 |||+----- HSO Interrupt Disable ||+------ Set the selected pin to 0!!!!!!!!! |+------- Select timer2 +-------- CAM UnLock */ hso_time = hso1_reset_time; }while(1); } void INT13(void) { asm pushf; hso1_reset_time += 100; if(hso1_reset_time > 2875) hso1_reset_time = 2875; lcd_put3dec((WORD)((hso1_reset_time-875)*0.09), LINE2, 11); asm popf; return; } void INT07(void) { asm pushf; hso1_reset_time -= 100; if(hso1_reset_time < 875) hso1_reset_time = 875; lcd_put3dec((WORD)((hso1_reset_time-875)*0.09), LINE2, 11); asm popf; return; }