/* ========================================================================== */ /* PS348_1.C : PWM Control by HSO.1 */ /* ========================================================================== */ /* Description : Control RC Servo-motor by two external pin interrupts. */ /* ========================================================================== */ /* PS-348 RC Servo Motor : 2.3ms(-90) бн 1.5ms(0) бн 0.7ms(90) Let Period = 5.0ms (= 6250 state) -90 = 2.3ms (= 2875 state) 0 = 1.5ms (= 1875 state) +90 = 0.7ms (= 875 state) */ #pragma dn(0) #pragma code #pragma pagelength(32767) #pragma model(kc) #include <80c196.h> #define INT13 #define INT07 #include #include <196io.h> #include const WORD period = 6250; /* 5.0ms */ const WORD hso1_set_time = 0; /* set time and reset time */ int hso1_reset_time; void INT13(void); void INT07(void); 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; imask1 = 0x20; enable(); /* 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; /* 10 */ /* 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 < 875) hso1_reset_time = 875; lcd_put3dec((WORD)(-0.09*hso1_reset_time+258.75), LINE2, 11); asm popf; return; } void INT07(void) { asm pushf; hso1_reset_time += 100; if(hso1_reset_time > 2875) hso1_reset_time = 2875; lcd_put3dec((WORD)(-0.09*hso1_reset_time+258.75), LINE2, 11); asm popf; return; }