max5483单独控制正确,和max5481合在一起控制也正确,但是当我把这些程序移到我的主程序中后只有max5481正确,而max5481 、max5483他们的控制程序是一样的,为什么max5481正确,max5483就不正确呢? #include <reg52.h> #include <intrins.h> #include <absacc.h> #define uchar unsigned char #define uint unsigned int sbit MAX5481_CS18 = P1^5; sbit MAX5481_CS5 = P1^4; sbit MAX5481_SCLK = P1^6; sbit MAX5481_DIN = P1^7;
//max5481 void max5481write(uchar direct,uchar data1,uchar data2); void max5483write(uchar direct,uchar data1,uchar data2); void main() { while(1) { max5481write(0x00,0x56,0x00); max5483write(0x00,0x65,0xc0); } }
//max5483 void max5483write(uchar direct,uchar data1,uchar data2) { uchar i; MAX5481_SCLK = 0; MAX5481_CS18=0; for (i=0;i<8;i++) //上升沿写入命令 { MAX5481_SCLK =0; MAX5481_DIN = (bit)(direct&0x80); direct = direct<<1; MAX5481_SCLK =1; _nop_(); _nop_(); } for (i=0;i<8;i++) //上升沿写入数据 { MAX5481_SCLK =0; MAX5481_DIN = (bit)(data1&0x80); data1 = data1<<1; MAX5481_SCLK =1; _nop_(); _nop_(); } //_nop_(); _nop_(); for (i=0;i<8;i++) //上升沿写入数据 { MAX5481_SCLK =0; MAX5481_DIN = (bit)(data2&0x80); data2 = data2<<1; MAX5481_SCLK =1; _nop_(); _nop_(); // } MAX5481_CS18=1; } //max5481 void max5481write(uchar direct,uchar data1,uchar data2) { uchar i; MAX5481_SCLK = 0; MAX5481_CS5=0; for (i=0;i<8;i++) //上升沿写入命令 { MAX5481_SCLK =0; MAX5481_DIN = (bit)(direct&0x80); direct = direct<<1; MAX5481_SCLK =1; _nop_(); } _nop_(); for (i=0;i<8;i++) //上升沿写入数据 { MAX5481_SCLK =0; MAX5481_DIN = (bit)(data1&0x80); data1 = data1<<1; MAX5481_SCLK =1; _nop_(); } _nop_(); for (i=0;i<8;i++) //上升沿写入数据 { MAX5481_SCLK =0; MAX5481_DIN = (bit)(data2&0x80); data2 = data2<<1; MAX5481_SCLK =1; _nop_(); } MAX5481_CS5=1; }
|