C8051f系列开发之keil c单步调试
来源:互联网 发布:文本加密软件 编辑:程序博客网 时间:2024/05/23 18:40
C8051f系列单片机是一种高速,集成度很高的单片机,功能还是蛮强大的。我在用此款单片机读取ST 公司的三轴加速度计的时候发现输出总是全1。于是,我用keil c的单步调试功能。一步一步调试,于是我发现执行到一条把某一管脚置1的语句之后,watch窗口显示的相应管教状态仍是0.
于是我觉得可能是硬件的问题,引脚一直接地被拉低。果然,我在查看电路板的线路时发现sdi和sdo两根线与另外两个引脚相连,而这个连接是我修改版图时无意连接上的。而且一个引脚被配置成高电平,另外一个被配置成低电平。所以sdi和sdo都一直保持低电平和高电平。所以不能对传感器进行正常的配置和读取数据。
另附lis3lv02dq读取程序,采用的是虚拟spi总线。
#include "main.H"unsigned char spi_comm(unsigned char outgoing_byte){ uchar incoming_byte, x; acc_spc = 1; //Pull SPI clock high for(x = 0 ; x < 8 ; x++) { if(outgoing_byte&0x80) acc_sdi =1; //Put bit on SPI data bus else acc_sdi = 0; outgoing_byte <<= 1; //Rotate byte 1 to the left acc_spc = 0; //Toggle the SPI clock acc_spc = 1; incoming_byte <<= 1; //Rotate byte 1 to the leftif(acc_sdo) //Read bit on SPI data bus incoming_byte += 0x01; } return(incoming_byte);}unsigned char read_register(unsigned char register_name){ uchar in_byte; register_name |= 0x80; //Set D7 to 1 for read mode acc_cs = 0; //Select LIS in_byte = spi_comm(register_name); //SPI read 6-bit register from LIS //printf("In1 = %h ", in_byte); //in_byte is nothing, we need to clock in another 8 bits in_byte = spi_comm(0x00); //Send nothing, but we should get back the register value acc_cs = 1; return(in_byte);}//Sends a write command to LISvoid write_register(unsigned char register_name, unsigned char register_value){ unsigned char in_byte; register_name &= 0x7f; //Clear D7 to 0 for write mode acc_cs = 0; //Select LIS in_byte = spi_comm(register_name); //SPI read 6-bit register from LIS //printf("In1 = %h ", in_byte); //in_byte is nothing, we need to clock in the value to write in_byte = spi_comm(register_value); //Send nothing, but we should get back the register value acc_cs = 1; //Return nothing} void acc_spi(void) { acc_cs = 1; //Unselect LIS // CK = 0; // acc[0] = read_register(0x0F); //Read register WHO_AM_I write_register(0x20,0xc7); //Power on device, enable all axis, and turn off self test - CTRL_REG1 delay(5); write_register(0x21,0x44);while(!acc_rdy); acc[1] = read_register(0x28); //Read outx_l acc[0] = read_register(0x29); //Read outx_hacc[3] = read_register(0x2a);acc[2] = read_register(0x2b);acc[5] = read_register(0x2c);acc[4] = read_register(0x2d); }
0 0
- C8051f系列开发之keil c单步调试
- Eclipse 单步调试系列
- Android开发之设置断点单步调试
- ddms之单步调试
- windows程序员进阶系列:《软件调试》之四:断点和单步调试
- windows程序员进阶系列:《软件调试》之四:断点和单步调试
- windows程序员进阶系列:《软件调试》之四:断点和单步调试
- gdb调试C语言--单步调试、断点调试
- gdb调试C语言--单步调试、断点调试
- android NDK开发在本地C/C++源代码中设置断点单步调试详细教程
- android NDK开发在本地C/C++源代码中设置断点单步调试详细教程
- 展讯开发环境 之 VC6单步调试卡死的问题
- Linux内核驱动开发之KGDB单步调试内核(kgdboc方式)
- Linux内核驱动开发之KGDB单步调试内核(kgdboc方式)
- Linux内核驱动开发之KGDB单步调试内核(kgdboc方式)
- Linux内核驱动开发之KGDB单步调试内核(kgdboc方式)
- Visual Studio调试之避免单步跟踪调试模式
- C#编程利器之调试篇--单步调试、单元测试
- 阿萨德发的发生大发师傅公司发给
- 阿萨德发的发生大发师傅公司发给
- 测试bracketStatckMine
- 测试NumberRepalce
- [ACM] POJ 3071 Football (概率DP)
- C8051f系列开发之keil c单步调试
- Makefile学习
- 十分钟使用ionic Framework开发一个跨平台移动应用
- Spring Security初探
- TestRightArray
- memcache的一致性hash算法使用
- MySQL主键外键设定方法
- pvfs2 集群安装配置
- MAC 上搭建lua