/********************************************************************************
Copyright (C), Sinowealth Electronic. Ltd.
Author: Sino
Version: V0.0
Date: 2014/05/30
History:
V0.0 2014/05/30 Preliminary
********************************************************************************/
#include "system.h"
#include "Uart.h"
#include "TwiIO.h"
#include "TwiModule.h"
#include "McuFlash.h"
/*******************************************************************************
Function: Page1WrRdFuncTable()
Description:
Input: NULL
Output: NULL
Others: NULL
*******************************************************************************/
U16 code Page1WrRdFuncTable[18]=
{
SYS_PARA_MAP_ADDR, //SubClassID 0x00
SYSINFO_MAP_ADDR, //0x01
CHG_PARA_MAP_ADDR, //0x02
DSG_PARA_MAP_ADDR, //0x03
DSG_PWM_PARA_MAP_ADDR, //0x04
CHG_TEMP_PARA_MAP_ADDR, //0x05
DSG_TEMP_PARA_MAP_ADDR, //0x06
0x00, //0x07
BAL_PARA_MAP_ADDR, //0x08
0x00, //0x09
AFE_PARA_MAP_ADDR, //0x0A
CALI_PARA_MAP_ADDR, //0x0B
0x00, //0x0C 已被RTC读取占用
0x00, //0x0D
0x00, //0x0E
0x00, //0x0F
0x00, //0x10
0x00, //0x11
};
/*******************************************************************************
Function: Page2WrRdFuncTable()
Description:
Input: NULL
Output: NULL
Others: NULL
*******************************************************************************/
U16 code Page2WrRdFuncTable[18]=
{
SYS_PARA_MAP_ADDR+32, //SubClassID 0x00
SYSINFO_MAP_ADDR+32, //0x01
CHG_PARA_MAP_ADDR+32, //0x02
DSG_PARA_MAP_ADDR+32, //0x03
DSG_PWM_PARA_MAP_ADDR+32, //0x04
CHG_TEMP_PARA_MAP_ADDR+32, //0x05
DSG_TEMP_PARA_MAP_ADDR+32, //0x06
0x00, //0x07
BAL_PARA_MAP_ADDR+32, //0x08
0x00, //0x09
AFE_PARA_MAP_ADDR+32, //0x0A
CALI_PARA_MAP_ADDR+32, //0x0B
0x00, //0x0C 已被RTC读取占用
0x00, //0x0D
0x00, //0x0E
0x00, //0x0F
0x00, //0x10
0x00, //0x11
};
/*******************************************************************************
Function: InitUART0()
Description: Init UART0
Input: NULL
Output: NULL
Others:
*******************************************************************************/
void InitUART0(void)
{
UART0CR = 0x32; //TXD:P0.7, RXD:P0.6(默认)
PCON = 0x00;
SCON = 0x50; //配置Uart工作在模式1
SBRTH = 0xff; //配置波特率参数,波特率9600
SBRTL = 0x64; //计算公式:(int)X=FSY/(16*波特率) ; SBRT=32768-X ; SFINE=(FSY/波特率)-16*X FSY=24M
SFINE = 0x04;
SADDR = 0x0A;
SADEN = 0xFF;
ucUartBufPT = 0;
ucUartTimeoutCnt = 0;
}
/*******************************************************************************
Function:ISPHandshake()
Description: Processing ISP Handshake
Input: NULL
Output: NULL
Others:
*******************************************************************************/
U8 code ISPCODE[10] = {0,7,0x05,0x0a,0x09,0x06,'I','S','P'};
void ISPHandshake(void)
{
U8 i;
for(i=0; i<9; i++)
{
if(ucUartBuf[2+i] != ISPCODE[i])
{
UART_SEND_NACK;
return;
}
}
bISPFlg = 1;
bUartSndAckFlg = 0;
UART_SEND_ACK;
}
/*******************************************************************************
Function:UartHandshake()
Description: PC and slave handshake
Input: NULL
Output: NULL
Others:
*******************************************************************************/
void UartHandshake(void)
{
if(ucUartBuf[2] == 0x00) //Testing equipment is properly
{
UART_SEND_ACK;
}
else
{
UART_SEND_NACK;
}
}
/*******************************************************************************
Function:UartWriteInfo()
Description: write the information: MCU Info
Input: *prt---Data storage address
Output: NULL
Others:
*******************************************************************************/
void UartWriteInfo(U8 xdata *ptr) //PC write to MCU
{
U8 i;
if(ucUartBuf[3+ucUartBuf[UART_LENGTH]] == CRC8cal(&ucUartBuf, ucUartBuf[UART_LENGTH]+3))
{
for(i=0; i<ucUartBuf[UART_LENGTH]; i++)
{
*ptr = ucUartBuf[3+i];
ptr++;
}
bWrFlashFlg = 1; //Updated parameters, and written to the flash
UpEepromWithDelay();
UART_SEND_ACK;
}
else
{
UART_SEND_NACK;
}
}
/*******************************************************************************
Function:UartReadInfo()
Description: Read the information: Battery Info, MCU Info, MTP Info
Input: *prt---Data storage address
Output: NULL
Others:
*******************************************************************************/
void UartReadInfo(U8 xdata *ptr)
{
U8 i;
if(ucUartBuf[UART_LENGTH] > 140)
{
ucUartBuf[UART_LENGTH] = 0;
}
for(i=0; i<ucUartBuf[UART_LENGTH]; i++)
{
ucUartBuf[3+i] = *ptr;
ptr++;
}
ucUartBuf[3+ucUartBuf[UART_LENGTH]] = CRC8cal(&ucUartBuf,ucUartBuf[UART_LENGTH]+3);
UART_SEND_DATA; //Start Send Data; Set UART REG
}
/*******************************************************************************
Function:WriteManufacture()
Description: write the information: User-defined, For example, a software reset and forced into sleep
Input: *prt---Data storage address
Output: NULL
Others:
*******************************************************************************/
void WriteManufacture(void)
{
if(ucUartBuf[3+ucUartBuf[UART_LENGTH]] == CRC8cal(&ucUartBuf, ucUartBuf[UART_LENGTH]+3))
{
if(ucUartBuf[4] == 0x41) //0x0041: Reset system
{
ucResetFlag = 0x12;
}
else if(ucUartBuf[4] == 0x05) //0x0005: Enter sleep mode
{
bPCSleepFlg = 1;
}
bUartSndAckFlg = 0;
UART_SEND_ACK;
}
else
{
UART_SEND_NACK;
}
}
void ReadSubClassID(void)
{
if(ucUartBuf[3+ucUartBuf[UART_LENGTH]] == CRC8cal(&ucUartBuf, ucUartBuf[UART_LENGTH]+3))
{
ucSubClassID=ucUartBuf[3];
bUartSndAckFlg = 0;
UART_SEND_ACK;
}
else
{
UART_SEND_NACK;
}
}
/*******************************************************************************
Function:UartRdCmdProcess()
Description: Processing Uart read command
Input: NULL
Output: NULL
Others:
*******************************************************************************/
void UartRdCmdProcess(void)
{
U8 xdata *rdaddr;
switch(ucUartBuf[UART_CMD_NO])
{
case 0xA0:
UartHandshake();
break;
case CELL1:
case CELL2:
case CELL3:
case CELL4:
case CELL5:
case CELL6:
case CELL7:
case CELL8:
case CELL9:
case CELL10:
case CELL11:
case CELL12:
case CELL13:
case CELL14:
case CELL15:
case CELL16:
// UartReadInfo((U8 xdata *)&Info.VCell[UART_CMD_NO-1]);
UartReadInfo((U8 xdata *)&Info.VCell[ucUartBuf[UART_CMD_NO]-1]);
break;
case TOTAL_VOLTAGE:
UartReadInfo((U8 xdata *)&Info.Voltage);
break;
case CADC_CURRENT:
UartReadInfo((U8 xdata *)&Info.CurCadc);
break;
case EXT_TEMPE1:
UartReadInfo((U8 xdata *)&Info.Temperature1);
break;
case EXT_TEMPE2:
UartReadI
没有合适的资源?快使用搜索试试~ 我知道了~
SH367309+SH79F6441_DemoCode_V3.1_191108.zip
共117个文件
lst:23个
obj:23个
c:22个
1星 需积分: 50 95 下载量 125 浏览量
2021-03-31
20:28:09
上传
评论 2
收藏 566KB ZIP 举报
温馨提示
SH367309+SH79F6441_DemoCode_V3.1_191108.zip
资源详情
资源评论
资源推荐
收起资源包目录
SH367309+SH79F6441_DemoCode_V3.1_191108.zip (117个子文件)
TwiModule.__i 141B
ExtE2PRom.__i 141B
GasGauge.__i 138B
McuFlash.__i 138B
AfeMtp.__i 132B
Common.__i 132B
TwiIO.__i 129B
RTC.__i 123B
ISP.__i 123B
STARTUP._ia 104B
STARTUP.A51 506B
MCUCore.uvgui.andyliu 164KB
MCUCore_uvopt.bak 83KB
MCUCore.uvgui_sinouser.bak 77KB
MCUCore_uvproj.bak 53KB
Uart.c 17KB
DataFlash.c 15KB
Initial.c 10KB
TwiIO.c 10KB
Memory.c 9KB
TwiModule.c 8KB
AfeMtp.c 8KB
ExtE2PRom.c 8KB
McuFlash.c 7KB
Calculate.c 7KB
ISP.c 7KB
ShutDown.c 6KB
Calibrate.c 5KB
GasGauge.c 5KB
AfeProcess.c 4KB
Interrupt.c 4KB
RTC.c 4KB
Common.c 4KB
Main.c 3KB
Balance.c 2KB
Led.c 2KB
BlueTooth.c 2KB
Sino.cfg 34B
Eeprom 2KB
SH79F6441.h 10KB
Memory.h 9KB
McuFlash.h 3KB
Uart.h 2KB
AfeMtp.h 1KB
Led.h 1KB
Main.h 1KB
ISP.h 944B
System.h 793B
TwiIO.h 787B
ExtE2PRomRTC.h 733B
Common.h 377B
TwiModule.h 370B
c51_type.h 243B
GasGauge.h 206B
Calibrate.h 142B
MCUCore.hex 52KB
Eeprom.hex 3KB
Eeprom.build_log.htm 1KB
MCUCore.build_log.htm 1KB
MCUCore.lnp 709B
Eeprom.lnp 171B
Uart.lst 33KB
DataFlash.lst 26KB
Initial.lst 22KB
TwiIO.lst 21KB
TwiModule.lst 20KB
ISP.lst 19KB
Memory.lst 18KB
ShutDown.lst 17KB
ExtE2PRom.lst 17KB
Calculate.lst 15KB
AfeMtp.lst 15KB
GasGauge.lst 14KB
McuFlash.lst 14KB
AfeProcess.lst 12KB
Calibrate.lst 11KB
Interrupt.lst 10KB
RTC.lst 9KB
Main.lst 8KB
Common.lst 7KB
Led.lst 6KB
Balance.lst 5KB
BlueTooth.lst 4KB
STARTUP.lst 3KB
MCUCore.m51 202KB
Eeprom.m51 1KB
MCUCore 644KB
Uart.obj 54KB
Initial.obj 46KB
ExtE2PRom.obj 41KB
Memory.obj 40KB
Calibrate.obj 38KB
Calculate.obj 37KB
ShutDown.obj 37KB
AfeMtp.obj 36KB
ISP.obj 34KB
GasGauge.obj 33KB
AfeProcess.obj 32KB
TwiModule.obj 31KB
McuFlash.obj 30KB
共 117 条
- 1
- 2
joey打字机
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论1