// control.c // // needs: // ax_0.c // ax_1.c // cx_0.c // cx_1.c // dy.c // def.h #include <16f877.h> #device ADC=10 #fuses HS, NOWDT, PUT, NOPROTECT #use delay(CLOCK = 20000000) #use fast_io(C) #use fast_io(D) #include "def.h" static int icount; int i, u_data; unsigned int8 a,b,c,d,e; signed int16 x[N]; signed int16 y, u, sum, p; signed int16 tmp, x_tmp; #int_timer0 void intval() { set_timer0(0x16); // 0.75msec icount++; } void calc_ax_0() { #include "ax_0.c" } void calc_ax_1() { #include "ax_1.c" } void main() { setup_adc_ports(ALL_ANALOG); setup_adc(ADC_CLOCK_DIV_32); for(i = 0; i < N; i++){ x[i] = 0; } u = 0; a = b = e = 0x7a; set_tris_c(0x00); //port C;output set_tris_d(0x03); //port D0, D1;input D2-D7;output icount = 0; setup_timer_0(RTCC_INTERNAL | RTCC_DIV_16); set_timer0(0x16); // 0.75msec enable_interrupts(INT_TIMER0); enable_interrupts(GLOBAL); while(1){ if(icount >=1){ icount = 0; set_adc_channel(0); #include "cx_1.c" // y = S/8*(read_adc() - 511); // y = (read_adc() - 511) << 1; // S = 16 // y = (read_adc() - 511) << 2; // S = 32 y = (read_adc() - 511) << 3; // S = 64 // y = (read_adc() - 511) << 4; // #include "dy.c" // u_data = (u + 1024) >> 3; u_data = (u + 2048) >> 4; // S = 64 の場合 // u_data = (u + 4096) >> 5; // 0.75msec if(input(PIN_D0)){ output_high(PIN_D5); // LED off }else{ output_low(PIN_D5); // LED on output_c(u_data); } calc_ax_0(); calc_ax_1(); #include "cx_0.c" e = a; a >>= 2; a &= 0x01; b >>= 7; b &= 0x01; d = a^b; e <<= 1; e += d; a = e; b = e; e &= 0x80; if(input(PIN_D1)){ output_high(PIN_D4); // LED off }else{ output_low(PIN_D4); // LED on if( e == 0x80 ){ output_high(PIN_D2); }else{ output_low(PIN_D2); } } } } }