No.93093 作者:funv 邮件:funv@163.com ID:53453 登陆:1次 文章数:1篇 最后登陆IP:59.36.213.85 最后登陆:2006/5/24 8:50:10 注册:2006/5/20 8:34:33 财富:105 发帖时间:2006/5/20 8:56:02 发贴者IP:59.36.210.115 标题:funv:实际使用SPI写/读MC33984内的寄存器没有响应,请高手帮我看看,附有原程序 摘要:No.93093实际使用SPI写/读MC33984内的寄存器没有响应,请高手帮我看看,附有原程序 实际使用SPI写/读MC33984内的寄存器没有响应,请高手帮我看看 #include "stc12c5410ad.h" #include "BIN2HEX.h" #include <intrins.h> #include "MC33984.h" #include <stdio.h> // 连接脚定义 sbit MC33984_WAKE = P1^6; // D 唤醒 sbit MC33984_CSNS = P1^7; // 电流采样信号(外下拉) sbit MC33984_FS_ = P1^4; // # 故障状态报告(外上拉) sbit MC33984_RST_ = P1^5; // D # 复位 低电平有效 sbit MC33984_CS_ = P1^3; // U # 片选 低电平有效 sbit MC33984_SCLK = P1^2; // D SPI 时钟 sbit MC33984_SO = P3^7; // SPI 输出 sbit MC33984_SI = P1^0; // D SPI 输入 #define P1_PUSH_PULL B0110_1101 /* 1:表示推挽式输出的脚(P1) */ #define P3_PUSH_PULL B0000_0000 /* 1:表示推挽式输出的脚(P3) */ #define P1_INPUT B1000_0000 /* 1:表示只用于输入的脚(P1) */ #define P3_INPUT B0000_0000 /* 1:表示只用于输入的脚(P3) */ //////////////////////// 输出脉冲时钟 /////////////////////////////////// #pragma disable void spi_puls(){ _nop_(); MC33984_SCLK = 1; _nop_(); _nop_(); _nop_(); MC33984_SCLK = 0; _nop_(); _nop_(); } //////////////////////// 输出命令 /////////////////////////////////////// #pragma disable void spi_write( unsigned char v ){ unsigned char i; printf( "W=%BX\n", v ); //debug MC33984_CS_ = 0; for(i=0; i <8;i++){ if( v & 0x80 ) MC33984_SI = 1; else MC33984_SI = 0; spi_puls(); v = v < <1; } MC33984_SI = 0; MC33984_CS_ = 1; } //////////////////////// 取内容 //////////////////////////////////////// #pragma disable unsigned char spi_read( ){ unsigned char temp; unsigned char i; temp = 0; MC33984_CS_ = 0; for(i=0;i <8;i++){ temp = temp < <1; spi_puls(); if( MC33984_SO ){ temp |= 0x01; } } printf( "R=%BX\n", temp ); //debug return( temp ); } ////////////////////////// 命令字格式化 ///////////////////////////////// void MC33984_setup( unsigned char set, unsigned char value ){ set |= (value & 0x0f); spi_write( set ); } ////////////////////////// 命令字格式化 ///////////////////////////////// unsigned char MC33984_stat( unsigned char stat ){ unsigned char temp; temp = 0x0; temp |= (stat> > 4) & 0x07; temp |= stat & 0x80; spi_write( temp ); temp = spi_read( ); return( temp ); } ////////////////////////// 初始化 ////////////////////////////////////// void MC33984_init(){ //推挽输出脚 P1M0 &= ~P1_PUSH_PULL; // M1=0, M0=0 标准 P1M1 |= P1_PUSH_PULL; // M1=0, M0=1 输入 P3M0 &= ~P3_PUSH_PULL; // M1=1, M0=0 推挽 P3M1 |= P3 ......
>>返回讨论的主题
|