小弟 用89c2051驱动3972电机芯片 用ME-52硬件仿真给出汇编小弟对汇编不了解 代码如下: #include <reg51.h> #define uchar unsigned char
#define drv_ref 0 #define drv_rng 1 #define drv_mod 0 #define drv_word0 0 #define drv_word1 1
sbit clockp=P1^7; sbit datap=P1^6; sbit strobp=P1^5; sbit clockt=P1^4; sbit datat=P1^3; sbit strobt=P1^2;
uchar pan_dac1; uchar pan_dac2; uchar tilt_dac1; uchar tilt_dac2; uchar pan_phs; uchar pan_mode; uchar num_step; long pan_word0; long pan_word1; long tilt_word0; long tilt_word1;
void wrtwords(long bits) { uchar word; long select; strobp=1; strobp=0;
select=0x00040000; for(word=0,clockp=1;word<19;word++) { clockp=0; if((bits&select)>0)datap=1; else datap=0; select=select>>1; clockp=1; } strobp=1; }
void write_word0(uchar xx) { pan_dac1=(xx&0x1f)<<1; pan_dac2=((31-xx)&0x1f)<<1; pan_phs=xx>>5; if(pan_phs==0) pan_phs++; if(pan_phs==3) pan_phs--; pan_word0=pan_phs; pan_word0=pan_word0<<13; pan_word0|=pan_dac2<<7; pan_word0|=pan_dac1<<1; wrtwords(pan_word0); }
void write_word1() { pan_word1=0x00040667; wrtwords(pan_word1); }
void delay(int xx) { for(;xx>0;xx--); }
void main() { write_word1(); for(;;) { delay(30000); write_word0(num_step); if(num_step++>126) num_step=0; } }
|