/* ============================================================== */ /* HS303_2.C */ /* ============================================================== */ /* Description : Control HS-303 SM by external Potentiometer. AD Converting is performed by 8 bit A/D pollling. PS-303 RC Servo Motor : 0.7ms(-90 deg) бн 1.5ms(0 deg) бн 2.3ms(90 deg) Let Period = 5.0ms (= 6250 state) -90 = 0.7ms (= 875 state) 0 = 1.5ms (= 1875 state) +90 = 2.3ms (= 2875 state) */ #pragma dn(0) #pragma code #pragma pagelength(32767) #pragma model(kc) #include <80c196.h> #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 main(void) { BYTE ad_lo; char ad_hex; hso1_reset_time = 0; /* Initial degree is 0 deg */ 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; lcd_print("SM Ctrl with ADC", LINE1); lcd_print(" 0 mV 0 deg", LINE2); fpinit(); /* Floating Point Init. */ /* 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; int_mask = 0x00; imask1= 0x00; disable(); /* Disable whole INT. */ while(1) { ad_command=0x18; /* ACH0, Immediate, 8BIT */ asm nop; asm nop; do{ ad_lo = ad_result_lo; /* ad_result_lo.3 = 1 : Doing */ }while(ad_lo&0x08); /* ad_result_lo.3 = 0 : Done */ ad_hex=ad_result_hi; /* 8 bit result */ hso1_reset_time = 7.8125*((WORD)ad_hex&0x0ff) + 875; 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; lcd_put4dec(ad_hex*20, LINE2, 0); lcd_put3dec((WORD)((ad_hex&0x0ff)*0.703125), LINE2, 9); } }