📄 wnt10.c
字号:
/////////////////////////////////////////////
/*** Author: lilixue ***/
/*** Date: 2004.02.27 ***/
/*** Version: Simple 1.0 ***/
/*** User SRAM: ExSRAM Page 0 ***/
/*** VocRecCH0 SRAM: ExSRAM Page 1~2 ***/
/*** VocRecCH1 SRAM: ExSRAM Page 3~4 ***/
/*** VocRecCH2 SRAM: ExSRAM Page 5~6 ***/
/*** VoiceSample SRAM: ExSRAM Page 7 ***/
/////////////////////////////////////////////
/*
1, Changed Comment: when 386Ex have sended the command to shut down all the mobile phones,firstly MCU stop charging
the cell phones,and after 30 seconds MCU shut down the 386Ex system.
2, Battary charging protect, 120k resister.
3, Vref_1: 2.408V; Vref_2: 2.435V; Vref_3: 2.410V;
4, ExVolt_1: 1.208V; ExVolt_2: 1.188V; ExVolt_3: 1.229V;
5, DAC Output.
*/
#include <c8051f040.h> // SFR declarations.
#include "Timer.h" // Timer Operation Function.
#include "UART.h" // UART Operation Function.
#include "ExSRAM.h" // ExSRAM Operation Function.
#include "AdcDac.h" // ADC and DAC Operation Function.
#include "WNT10.h" // General Operation Function.
#define DEBUG 0 // Debug Mode.
#define VOLT_REF 2.410 // ADC and DAC Reference Voltage.
#define TEMP_REF (int)( ( -50 * 0.00286 + 0.776 ) / VOLT_REF * 1024 ) // Temperature Reference: -50 degree.
#define TEMP_MAX (int)( ( 70 * 0.00286 + 0.776 ) / VOLT_REF * 1024 ) - TEMP_REF // OverHigh Temperature Threshold: 60 degree.
#define TEMP_MIN (int)( ( -20 * 0.00286 + 0.776 ) / VOLT_REF * 1024 ) - TEMP_REF // OverLow Temperature Threshold: -10 degree;
#define TEMP_FAN_OPEN (int)( ( 40 * 0.00286 + 0.776 ) / VOLT_REF * 1024 ) - TEMP_REF // Enable Fans: 35 degree(0x68);
#define TEMP_FAN_STOP (int)( ( 35 * 0.00286 + 0.776 ) / VOLT_REF * 1024 ) - TEMP_REF // Disable Fans: 30 degree(0x62);
#define BATT_MAX (int)( 7.3 / 4 / VOLT_REF * 255 ) // High Battary Voltage;
#define BATT_MID (int)( 6.8 / 4 / VOLT_REF * 255 ) // Normal Battary Voltage;
#define BATT_MIN (int)( 6.2 / 4 / VOLT_REF * 255 ) // Low Battary Voltage;
#define BATT_ERR (int)( 1.2 / 4 / VOLT_REF * 255 ) // Error Battary Voltage;
#define BATT_CHG_IVL 5 // Battary Charge Interval: 5S Charge and 5S STOP.
#define BattAlmVldTim 5 // Battary Alarm Valid Times Define.
#define BattNrlVldTim 180 // Battary Normal Valid Times Define.
#define LowBattShutDown 65 // Low Battary to Shutdown 386Ex: 1min;
#define TempAlmVldTim 5 // Temp Alarm Valid Times Define.
#define TempNrlVldTim 180 // Temp Normal Valid Times Define.
#define OverTempShutDown 65 // Over Temp to Shutdown 386Ex: 1min;
#define ExPwrAlmVldTim 30 // ExPwr Alarm Valid Times Define.
#define ExPwrNrlVldTim 30 // ExPwr Normal Valid Times Define.
#define ExPwrOffShutDown 930 // ExPwrOff to Shutdown 386Ex: 15min;
#define Ex386ReadyToPDN 30 // Ex386 Ready to Power Down: 30S;
#define FraSAT0 0x55 // Frame Start Flag 0.
#define FraSAT1 0xAA // Frame Start Flag 1.
#define FraEND 0x88 // Frame End Flag.
#define AlmFraCTL 0x04 // AlarmInfo frame head.
#define GpsFraCTL 0x05 // GpsInfo frame head.
#define StaFraCTL 0x06 // MCU STATUS Changed frame head.
#define SysFraCTL 0x07 // System STATUS data frame head.
#define RecFraCTL 0x01 // Record data frame head: 0x01/0x020x03.
#define AlmFraLeng 1 // AlarmInfo valid data: 1 bytes.
#define GpsFraLeng 37 // GpsInfo valid data: 39 bytes.
#define StaFraLeng 1 // MCU STATUS Changed valid data: 1 bytes.
#define SysFraLeng 9 // System STATUS valid data: 9 bytes.
#define RecFraLeng 200 // Voice Record valid data: 200 bytes.
#define AlmTX_NUM 9; // Alarm Frame: 9 bytes.
#define GpsTX_NUM 45; // GPS Frame: 47 bytes.
#define StaTX_NUM 9; // MCU STATUS Changed Frame: 9 bytes.
#define SysTX_NUM 17; // System STATUS Frame: 17 bytes.
#define RecTX_NUM 208; // Record Frame: 208 bytes.
#define AckTX_NUM 4; // ACK Frame: 4 bytes.
#define RvrTX_NUM 8; // Error Recover Frame: 8 bytes.
unsigned char code VocCh0RecEndPag = 1; // Voice Record Length: 1 Pages = 8sec.
unsigned char code VocCh1RecEndPag = 3; //
unsigned char code VocCh2RecEndPag = 5; //
unsigned int code VocRecFrameIdxMax = 320; // .
unsigned char code VocRecDatTxTimMax = 240; // Voice Record DATA UpLoad Max Time: 240sec.
unsigned int code VocRecDatLength = 64000; // Voice Record Length / Page( 8S max );
unsigned int code VocSamPlyLength = 64000; // Voice Sample Length ( 8S max );
unsigned char code VocSamRePlayTim = 3; // Voice Replay Times;
unsigned char code RecChnTxDlyMax = 10; // Voice Record TX to Next Channal Delay: 10S.
unsigned char code TX_RE_TIM = 10; // TX Pause to Resume Time.
unsigned char code RE_TX_TIM = 2; // Error ReTransmit MAX Times. ???????
unsigned char code RvrTimOutMin = 4; // Rvr Time Out Begin: 40mS.
unsigned char code RvrTimOutMax = 6; // Rvr Time Out End : 60mS.
typedef union INTUC
{
unsigned int uiVAR;
unsigned char ucVAR[2];
} INTUC;
void RstSTATUS(void);
void TstLED(void);
void Blink(unsigned char OnTime,unsigned char OffTime,unsigned char Num);
void PwrCtrl(unsigned char ucMode);
void FraFormat(void);
void WriteDacBuffTstDat(void);
sbit SW0 = P2^0; // Backup Battary Switch Enabled; "Low" is Active;(0)
sbit SW1 = P2^1; // Digital Power Enabled(VCC), "Low" is Active;(0)
sbit SW2 = P2^2; // GPS Power Enabled(TPS76350), "High" is Active;(1)
sbit SW3 = P2^3; // Analog Power Enabled(TPS76350),"High" is Active;(1)
sbit SW4 = P2^4; // OT160 Charging Enabled(MTD2955),"Low" is Active;(0)
sbit SW5 = P2^5; // OT190 Charging Enabled(MTD2955),"Low" is Active;(0)
sbit SW6 = P2^6; // CDMA Charging Enabled(MTD2955),"Low" is Active;(0)
sbit SW7 = P2^7; // Battary Charge Enabled(MTD2955),"Low" is Active;(0)
sbit SW8 = P1^0; // Fans' Power Enabled, "Low" is Active;(0)
sbit nPDN = P1^1; // MobilePhone Battary Enabled,"High" is Active; (1)
sbit LED0 = P1^2; // System Power's STADUS (0)
sbit LED1 = P1^3; // Communicating with the Control Centerl (1)
sbit LED2 = P1^4; // GPS's STADUS (1)
sbit LED3 = P1^5; // MobilePhone 1's STADUS (1)
sbit LED4 = P1^6; // MobilePhone 2's STADUS (1)
sbit LED5 = P1^7; // MobilePhone 3's STADUS (1)
sbit nRST386 = P3^7; // Reset the Ex386,"Low" is active(1);
sbit GpsPPS = P0^4; // Interrupt Source,PPS Signal of the GPS.
sbit CarON = P0^5; // Interrupt Source,Car is PowerOn('0' means Off_to_On).
sbit CarOFF = P0^6; // Query,Car is PowerOff('0' means NO ExPower).
unsigned int uiTimCNT = 0; // 125uS Counting, 1S = 8000 * 125uS.
unsigned int VocCh0RecDatWrPtr = 0; // Voice CH0 Record Write Address Pointer.
unsigned char VocCh0RecDatWrPag = 1; // Voice CH0 Record Write Initial SRAM Page 1.
unsigned int VocCh1RecDatWrPtr = 0; // Voice CH1 Record Write Address Pointer.
unsigned char VocCh1RecDatWrPag = 3; // Voice CH1 Record Write Initial SRAM Page 3.
unsigned int VocCh2RecDatWrPtr = 0; // Voice CH2 Record Write Address Pointer.
unsigned char VocCh2RecDatWrPag = 5; // Voice CH2 Record Write Initial SRAM Page 5.
unsigned int VocSamDatWrPtr = 0; // Voice Sample Write Address Pointer.
unsigned char CurrTxVocChNum = 255; // Current TX Voice Channal No Data.
unsigned int VocRecDatRdPtr = 0; // Voice Record Read Address Pointer.
unsigned char VocRecDatRdPag = 1; // Voice Record Read Initial SRAM Page 1.
unsigned int VocSamDatRdPtr = 0; // Voice Sample Read Address Pointer.
unsigned char VocRePlyTimCNT = 0; // Voice Replay Times Counting.
unsigned char xdata GpsDATA[45]; // GpsInfo Data,39 Valid bytes.
unsigned char xdata AlmDATA[9]; // AlarmInfo Data,1 Valid byte.
unsigned char xdata StaDATA[9]; // MCU Status Changed Data,1 Valid byte.
unsigned char xdata SysDATA[17]; // SystemInfo Data, 9 Valid bytes.
unsigned char xdata RecDATA[208]; // Voice Record Data, 200 valid bytes MAX.
unsigned char xdata AckDATA[4]; // ACK Frame.
unsigned char xdata Ex386Sta1DATA; // 386Ex STATUS Buff 1.
unsigned char xdata Ex386Sta0DATA; // 386Ex STATUS Buff 0.
unsigned char xdata Ex386Cmd1DATA; // 386Ex Command Buff 1.
unsigned char xdata Ex386Cmd0DATA; // 386Ex Command Buff 0.
unsigned char xdata VocSam1DATA[200]; // Voice Sample Buff 1.
unsigned char xdata VocSam0DATA[200]; // Voice Sample Buff 0.
#ifdef DEBUG
INTUC AdcDatBuff _at_ 0x50; // DATA Buffer for ADC.
#else
INTUC AdcDatBuff; // DATA Buffer for ADC.
#endif
INTUC DacDatBuff; // DATA Buffer for DAC.
unsigned char xdata *ExSramWrRdAdr; // DATA Buffer Pointer for ADC and DAC.
////////////////////////////////////////
/* UART0 TX/RX */
////////////////////////////////////////
unsigned char xdata *TxDATA; // UART0 TX Buffer Pointer.
unsigned char xdata *TxBUFF; // UART0 TX Middle Buffer Pointer.
unsigned char UART0_TX_TASK; // UART0 TX Task No.
unsigned char UART0_TX_NUM; // UART0 TX Total Number.
unsigned char TX_NUM_Buff; //
unsigned char UART0_TX_CNT; // UART0 TX Counter.
unsigned char AckTimOutCNT; // ACK Wait Time Counter.
unsigned char UART0_ReTx_CNT; // ReTransmit Time Counter.
unsigned char UART0_RX_DTYPE; // Current RX DATA Type.
unsigned char UART0_RX_CNT; // UART0 RX Byte Counter.
unsigned char idata XOR; //
unsigned char idata Ex386STATUS; // 386Ex Operating Status.
INTUC RxCurrFraIdx; // Current Frame Index.
INTUC RxLastFraIdx; // Last Frame Index.
INTUC TxRecFraIdx; // UpLoad Frame Index.
unsigned char bdata UART0_RX_STATUS = 0;
sbit RxBuff0Busy = UART0_RX_STATUS^7; // RX Buffer 0 Busy.
sbit RxBuff1Busy = UART0_RX_STATUS^6; // RX Buffer 1 Busy.
sbit UART0_RX_Vos1 = UART0_RX_STATUS^5; // 386Ex VoS Buff 1 Valid flag.
sbit UART0_RX_Vos0 = UART0_RX_STATUS^4; // 386Ex VoS Buff 0 Valid flag.
sbit UART0_RX_Cmd1 = UART0_RX_STATUS^3; // 386Ex COMMAND Buff 1 Valid flag.
sbit UART0_RX_Cmd0 = UART0_RX_STATUS^2; // 386Ex COMMAND Buff 0 Valid flag.
sbit UART0_RX_Sta1 = UART0_RX_STATUS^1; // 386Ex STATUS Buff 1 Valid flag.
sbit UART0_RX_Sta0 = UART0_RX_STATUS^0; // 386Ex STATUS Buff 0 Valid flag.
unsigned char bdata UART0_TX_STATUS = 0;
sbit AlmStaVld = UART0_TX_STATUS^7; // Alarm Status Valid.
sbit UART0_TX_Wait = UART0_TX_STATUS^6; // UART0 Wait ACK.
sbit UART0_TX_ReTx = UART0_TX_STATUS^5; // Transmit Last Frame Again.
sbit UART0_TX_Paus = UART0_TX_STATUS^4; // TX Pause.
sbit UART0_TX_Busy = UART0_TX_STATUS^3; // UART0 TX Status.
unsigned char bdata UART0_TX_TSK = 0;
sbit AckDatReady = UART0_TX_TSK^6; // ACK Frame Ready.
sbit RecDatReady = UART0_TX_TSK^5; // Record DATA Frame Ready.
sbit SysDatReady = UART0_TX_TSK^4; // System Status Info Frame Ready.
sbit StaDatReady = UART0_TX_TSK^3; // MCU Status Changed Frame Ready.
sbit ReTxReady = UART0_TX_TSK^2; // ReTX Frame Ready.
sbit GpsDatReady = UART0_TX_TSK^1; // GPS Frame Ready.
sbit AlmDatReady = UART0_TX_TSK^0; // Alarm Frame Ready.
unsigned char bdata UART0_RxFORMAT_MATCH = 0;
sbit UART0_FraHEAD_OK = UART0_RxFORMAT_MATCH^6;
sbit UART0_FraHEAD_END = UART0_RxFORMAT_MATCH^5;
sbit UART0_FraHEAD_LENG = UART0_RxFORMAT_MATCH^4;
sbit UART0_FraHEAD_IDX = UART0_RxFORMAT_MATCH^3;
sbit UART0_FraHEAD_CTRL = UART0_RxFORMAT_MATCH^2;
sbit UART0_FraHEAD_SAT1 = UART0_RxFORMAT_MATCH^1;
sbit UART0_FraHEAD_SAT0 = UART0_RxFORMAT_MATCH^0;
////////////////////////////////////////
/* GPS DATA Decoding */
////////////////////////////////////////
unsigned char bdata GPS_HEAD_MATCH = 0;
sbit GPS_HEAD_OK = GPS_HEAD_MATCH^6;
sbit GPS_HEAD_C = GPS_HEAD_MATCH^5;
sbit GPS_HEAD_M = GPS_HEAD_MATCH^4;
sbit GPS_HEAD_R = GPS_HEAD_MATCH^3;
sbit GPS_HEAD_P = GPS_HEAD_MATCH^2;
sbit GPS_HEAD_G = GPS_HEAD_MATCH^1;
sbit GPS_HEAD_S = GPS_HEAD_MATCH^0;
unsigned char GpsFlaCNT = 1; //
unsigned char GpsDatPtr = 7;
////////////////////////////////////////
/* System Information Frame */
////////////////////////////////////////
unsigned char bdata MCU_Ex386_STATUS = 0; // MCU & 386Ex RST Status Info.
sbit VocCh2RecEvt = MCU_Ex386_STATUS^7; // Voice CH2 Record Event Flag.
sbit VocCh1RecEvt = MCU_Ex386_STATUS^6; // Voice CH1 Record Event Flag.
sbit VocCh0RecEvt = MCU_Ex386_STATUS^5; // Voice CH0 Record Event Flag.
sbit Ex386RST = MCU_Ex386_STATUS^4; // 386Ex Reset Flag.
sbit McuWdtRST = MCU_Ex386_STATUS^3; // MCU WDT Time Out Reset Flag.
sbit McuMisClkRST = MCU_Ex386_STATUS^2; // MCU Miss Clock Reset Flag.
sbit McuPwrOnRST = MCU_Ex386_STATUS^1; // MCU Power On Reset Flag.
sbit McuExRST = MCU_Ex386_STATUS^0; // MCU External Reset Flag.
unsigned char idata McuTxCNT = 0; // MCU TX Frame Counting every minute.
unsigned char idata RxAckCNT = 0; // 386Ex Ack Counting every minute.
unsigned char idata VocCh0RecTimCNT = 0; // Voice CH0 Record & TX Times Counting.
unsigned char idata VocCh1RecTimCNT = 0; // Voice CH1 Record & TX Times Counting.
unsigned char idata VocCh2RecTimCNT = 0; // Voice CH2 Record & TX Times Counting.
///////////////////////
/* MCU Alarm Frame */
///////////////////////
unsigned char bdata MCU_ALARM = 0; // MCU Alarm Information.
sbit BattSamEvt = MCU_ALARM^7; // Battary Voltage Sampling Event Flag.
sbit TempSamEvt = MCU_ALARM^6; // Temperature Sampling Event Flag.
sbit ExPwrOffAlmEvt = MCU_ALARM^5; // External Power Off Alarm Event Flag.
sbit LowBattAlmEvt = MCU_ALARM^4; // Battary Low Voltage Alarm Event Flag.
sbit OverTempAlmEvt = MCU_ALARM^3; // Over Temp Alarm Event Flag.
sbit ExPwrOffAlm = MCU_ALARM^2; // External Power Off Alarm.
sbit LowBattAlm = MCU_ALARM^1; // Low Battary Alarm.
sbit OverTempAlm = MCU_ALARM^0; // Over Temperature Alarm.
////////////////////////
/* MCU Status Changed */
////////////////////////
unsigned char bdata MCU_STATUS = 0x70; // MCU Status Changed Information.
sbit BattChgSTA = MCU_STATUS^7; // 1/0: Battary Charging/Non-Charging.
sbit MP2PwrOn = MCU_STATUS^6; // Mobile Phone 2 PwrOff Flag.
sbit MP1PwrOn = MCU_STATUS^5; // Mobile Phone 1 PwrOff Flag.
sbit MP0PwrOn = MCU_STATUS^4; // Mobile Phone 0 PwrOff Flag.
sbit VocPlaySTA = MCU_STATUS^3; // Play Voice Samples STATUS.
sbit VocCh2RecSTA = MCU_STATUS^2; // Voice CH2 Record STATUS.
sbit VocCh1RecSTA = MCU_STATUS^1; // Voice CH1 Record STATUS.
sbit VocCh0RecSTA = MCU_STATUS^0; // Voice CH0 Record STATUS.
unsigned char MCULastSTA = 0x70; // MCU Last STATUS.
unsigned char bdata SYS_RUN_FLAG = 0; //
sbit SysStandby = SYS_RUN_FLAG^7; // System Standby.
sbit Ex386StaChg = SYS_RUN_FLAG^6; // Ex386 STATUS Changed.
sbit ExPwrStaChg = SYS_RUN_FLAG^5; // ExPwr STATUS Changed.
sbit TempStaChg = SYS_RUN_FLAG^4; // Temp STATUS Changed.
sbit BattStaChg = SYS_RUN_FLAG^3; // Battary STATUS Changed.
sbit MinFlag = SYS_RUN_FLAG^2; // Minute Flag.
sbit SecFlag = SYS_RUN_FLAG^1; // Second Flag.
sbit mSecFlag = SYS_RUN_FLAG^0; // mSecond Flag.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -