📄 debug.c
字号:
//;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
// ;;
#include <reg51.h>
#include <absacc.h>
#include <stdio.h>
#include <string.h>
#include "define.h"
#include "main.h"
#include "i2c.h"
//#include "config.h"
//#include "mcu.h"
//#include "scaler.h"
//#include "eeprom.h"
//#include "misc.h"
//#include "main.h"
//#include "ext_var.h"
//#include "tuner.h"
//#include "modeset.h"
//#include "isr.h"
#define bWrite 0
#define bRead 1
#define bWrite1 2
#define bRead1 3
#define bList 4
#define bList1 5
#define bRead2 6
#define bRead3 7
BYTE code cWrite[] = "w";
BYTE code cRead[] = "r";
BYTE code cWrite1[] = "W";
BYTE code cRead1[] = "R";
BYTE code cList[] = "l";
BYTE code cList1[] = "L";
BYTE code cRead2[] = "lr";
BYTE code cRead3[] = "LR";
P_CBYTE code cCmdTable[] = {cWrite, cRead, cWrite1, cRead1,cList,cList1,cRead2,cRead3};
static BYTE idata cRxBuf[5];
static BYTE cRxIndex;
static BYTE cArgIndex;
static BYTE cCommand;
static BYTE cDevice;
static BYTE cAddress;
static BYTE cValue;
//#define Version 002
void init_debug( void ) {
cRxIndex = 0;
cArgIndex = 0;
printf( "The I2C debug program is begin!!!!\n");
}
BYTE atoh( BYTE ch ) {
if ( ch >= '0' && ch <= '9' ) return ( ch - '0' );
else if ( ch >= 'A' && ch <= 'F' ) return ( ch - 'A' + 10 );
else if ( ch >= 'a' && ch <= 'f' ) return ( ch - 'a' + 10 );
else return 0xff;
}
void kick_debug_interface() {
BYTE ch;
BYTE tempByte,i; // TestCode
if ( !RI ) return;
ch = getchar();
if ( ch != ' ' ) {
cRxBuf[cRxIndex] = ch;
if ( ++cRxIndex >= 5 ) cRxIndex = 4;
return;
}
else cRxBuf[cRxIndex] = 0x00;
cRxIndex = 0;
switch (cArgIndex++) {
// user command processing........................................
case 0:
for (ch = 0; ch < (sizeof(cCmdTable) / sizeof(P_CBYTE)); ch++)
if (!strcmp(cRxBuf, cCmdTable[ch])) break;
if (ch != sizeof(cCmdTable) / sizeof(P_CBYTE)) cCommand = ch;
else {cArgIndex = 0; printf( "Error : unknown command\n" );}
break;
// 1st command dependent parameter processing.....................
case 1:
if (cRxBuf[1]) cDevice = atoh(cRxBuf[0]) * 16 + atoh(cRxBuf[1]); // 2-digital length
else cDevice = atoh(cRxBuf[0]); // 1-digital length
if (cCommand == bList || cCommand == bList1)
{
printf("List All Regs:\n");
for(i=0;i<=0xff;i++)
{
tempByte = ReadI2CData(cDevice,i,1);
printf("%x ", (WORD)tempByte);
if ((i & 0x0f) == 0x0f)
printf("\n");
if(i == 0xff)
break;
}
cArgIndex = 0;
break;
}
break;
case 2:
if (cRxBuf[1]) cAddress = atoh(cRxBuf[0]) * 16 + atoh(cRxBuf[1]); // 2-digital length
else cAddress = atoh(cRxBuf[0]); // 1-digital length
if (cCommand == bRead || cCommand == bRead1)
{
tempByte = ReadI2CData(cDevice,cAddress,1);
printf("REG%x = %x\n", (WORD)cAddress, (WORD)tempByte);
cArgIndex = 0;
break;
}
break;
// 2nd command dependent parameter processing.....................
case 3:
if (cRxBuf[1]) cValue = atoh(cRxBuf[0]) * 16 + atoh(cRxBuf[1]);
else cValue = atoh(cRxBuf[0]);
if (cCommand == bWrite || cCommand == bWrite1)
{
WriteI2CData(cDevice,cAddress,cValue);
tempByte = ReadI2CData(cDevice,cAddress,1);
printf("REG%x = %x\n", (WORD)cAddress, (WORD)tempByte);
cArgIndex = 0;
break;
}
if (cCommand == bRead2 || cCommand == bRead3)
{
printf("\n");
printf("%bd,",cValue);
printf("0x%bx,", cDevice);
printf("0x%bx,", cAddress);
for(i=0;i<cValue;i++)
{
tempByte = ReadI2CData(cDevice,cAddress,1);
if(tempByte == 0)
printf("0x00,");
else if((tempByte & 0xf0) == 0x00)
{
printf("0x0%bx,", tempByte);
}
else
{
printf("0x%bx,", tempByte);
}
if ((i & 0x0f) == 0x0f)
printf("\n");
cAddress ++;
}
printf("\n");
cArgIndex = 0;
break;
}
break;
default:
printf("\n");
cArgIndex = 0;
break;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -