commit
543b4f2ff5
48 changed files with 8203 additions and 0 deletions
@ -0,0 +1,33 @@ |
|||
### vim |
|||
*.swp |
|||
*.swo |
|||
*~ |
|||
|
|||
### Keil5 |
|||
/keil/* |
|||
/keilp/* |
|||
!*.sct |
|||
!*.uvprojx |
|||
|
|||
### Source Insight |
|||
*.IAB |
|||
*.IAD |
|||
*.IMB |
|||
*.IMD |
|||
*.PFI |
|||
*.PO |
|||
*.PR |
|||
*.PRI |
|||
*.PS |
|||
*.WK3 |
|||
*.SearchResults |
|||
*.bookmarks.xml |
|||
*.snippets.xml |
|||
si/**/cache/ |
|||
si/**/Backup/ |
|||
si4/**/cache/ |
|||
si4/**/Backup/ |
|||
|
|||
### Source file |
|||
source/bak/ |
|||
/out/ |
Binary file not shown.
Binary file not shown.
@ -0,0 +1,427 @@ |
|||
<?xml version="1.0" encoding="UTF-8" standalone="no" ?> |
|||
<Project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="project_projx.xsd"> |
|||
|
|||
<SchemaVersion>2.1</SchemaVersion> |
|||
|
|||
<Header>### uVision Project, (C) Keil Software</Header> |
|||
|
|||
<Targets> |
|||
<Target> |
|||
<TargetName>STC8F2K16S2</TargetName> |
|||
<ToolsetNumber>0x0</ToolsetNumber> |
|||
<ToolsetName>MCS-51</ToolsetName> |
|||
<uAC6>0</uAC6> |
|||
<TargetOption> |
|||
<TargetCommonOption> |
|||
<Device>STC8F2K64S4</Device> |
|||
<Vendor>STC</Vendor> |
|||
<Cpu>IRAM(0-0xFF) XRAM(0-0x07FF) IROM(0-0xFFF8) CLOCK(35000000) MODP2</Cpu> |
|||
<FlashUtilSpec></FlashUtilSpec> |
|||
<StartupFile>"LIB\STARTUP.A51" ("Standard 8051 Startup Code")</StartupFile> |
|||
<FlashDriverDll></FlashDriverDll> |
|||
<DeviceId>63032</DeviceId> |
|||
<RegisterFile>STC8.H</RegisterFile> |
|||
<MemoryEnv></MemoryEnv> |
|||
<Cmp></Cmp> |
|||
<Asm></Asm> |
|||
<Linker></Linker> |
|||
<OHString></OHString> |
|||
<InfinionOptionDll></InfinionOptionDll> |
|||
<SLE66CMisc></SLE66CMisc> |
|||
<SLE66AMisc></SLE66AMisc> |
|||
<SLE66LinkerMisc></SLE66LinkerMisc> |
|||
<SFDFile></SFDFile> |
|||
<bCustSvd>0</bCustSvd> |
|||
<UseEnv>0</UseEnv> |
|||
<BinPath>d:\Keil\C51\BIN\</BinPath> |
|||
<IncludePath></IncludePath> |
|||
<LibPath></LibPath> |
|||
<RegisterFilePath>STC\</RegisterFilePath> |
|||
<DBRegisterFilePath>STC\</DBRegisterFilePath> |
|||
<TargetStatus> |
|||
<Error>0</Error> |
|||
<ExitCodeStop>0</ExitCodeStop> |
|||
<ButtonStop>0</ButtonStop> |
|||
<NotGenerated>0</NotGenerated> |
|||
<InvalidFlash>1</InvalidFlash> |
|||
</TargetStatus> |
|||
<OutputDirectory>..\out\</OutputDirectory> |
|||
<OutputName>cc_stc02_ps5ws</OutputName> |
|||
<CreateExecutable>1</CreateExecutable> |
|||
<CreateLib>0</CreateLib> |
|||
<CreateHexFile>1</CreateHexFile> |
|||
<DebugInformation>1</DebugInformation> |
|||
<BrowseInformation>1</BrowseInformation> |
|||
<ListingPath>..\out\</ListingPath> |
|||
<HexFormatSelection>0</HexFormatSelection> |
|||
<Merge32K>0</Merge32K> |
|||
<CreateBatchFile>0</CreateBatchFile> |
|||
<BeforeCompile> |
|||
<RunUserProg1>0</RunUserProg1> |
|||
<RunUserProg2>0</RunUserProg2> |
|||
<UserProg1Name></UserProg1Name> |
|||
<UserProg2Name></UserProg2Name> |
|||
<UserProg1Dos16Mode>0</UserProg1Dos16Mode> |
|||
<UserProg2Dos16Mode>0</UserProg2Dos16Mode> |
|||
<nStopU1X>0</nStopU1X> |
|||
<nStopU2X>0</nStopU2X> |
|||
</BeforeCompile> |
|||
<BeforeMake> |
|||
<RunUserProg1>0</RunUserProg1> |
|||
<RunUserProg2>0</RunUserProg2> |
|||
<UserProg1Name></UserProg1Name> |
|||
<UserProg2Name></UserProg2Name> |
|||
<UserProg1Dos16Mode>0</UserProg1Dos16Mode> |
|||
<UserProg2Dos16Mode>0</UserProg2Dos16Mode> |
|||
<nStopB1X>0</nStopB1X> |
|||
<nStopB2X>0</nStopB2X> |
|||
</BeforeMake> |
|||
<AfterMake> |
|||
<RunUserProg1>0</RunUserProg1> |
|||
<RunUserProg2>0</RunUserProg2> |
|||
<UserProg1Name></UserProg1Name> |
|||
<UserProg2Name></UserProg2Name> |
|||
<UserProg1Dos16Mode>0</UserProg1Dos16Mode> |
|||
<UserProg2Dos16Mode>0</UserProg2Dos16Mode> |
|||
<nStopA1X>0</nStopA1X> |
|||
<nStopA2X>0</nStopA2X> |
|||
</AfterMake> |
|||
<SelectedForBatchBuild>0</SelectedForBatchBuild> |
|||
<SVCSIdString></SVCSIdString> |
|||
</TargetCommonOption> |
|||
<CommonProperty> |
|||
<UseCPPCompiler>0</UseCPPCompiler> |
|||
<RVCTCodeConst>0</RVCTCodeConst> |
|||
<RVCTZI>0</RVCTZI> |
|||
<RVCTOtherData>0</RVCTOtherData> |
|||
<ModuleSelection>0</ModuleSelection> |
|||
<IncludeInBuild>1</IncludeInBuild> |
|||
<AlwaysBuild>0</AlwaysBuild> |
|||
<GenerateAssemblyFile>0</GenerateAssemblyFile> |
|||
<AssembleAssemblyFile>0</AssembleAssemblyFile> |
|||
<PublicsOnly>0</PublicsOnly> |
|||
<StopOnExitCode>3</StopOnExitCode> |
|||
<CustomArgument></CustomArgument> |
|||
<IncludeLibraryModules></IncludeLibraryModules> |
|||
<ComprImg>1</ComprImg> |
|||
<BankNo>65535</BankNo> |
|||
</CommonProperty> |
|||
<DllOption> |
|||
<SimDllName>S8051.DLL</SimDllName> |
|||
<SimDllArguments></SimDllArguments> |
|||
<SimDlgDll>DP51.DLL</SimDlgDll> |
|||
<SimDlgDllArguments>-pDP8051</SimDlgDllArguments> |
|||
<TargetDllName>S8051.DLL</TargetDllName> |
|||
<TargetDllArguments></TargetDllArguments> |
|||
<TargetDlgDll>TP51.DLL</TargetDlgDll> |
|||
<TargetDlgDllArguments>-p51</TargetDlgDllArguments> |
|||
</DllOption> |
|||
<DebugOption> |
|||
<OPTHX> |
|||
<HexSelection>0</HexSelection> |
|||
<HexRangeLowAddress>0</HexRangeLowAddress> |
|||
<HexRangeHighAddress>0</HexRangeHighAddress> |
|||
<HexOffset>0</HexOffset> |
|||
<Oh166RecLen>16</Oh166RecLen> |
|||
</OPTHX> |
|||
</DebugOption> |
|||
<Utilities> |
|||
<Flash1> |
|||
<UseTargetDll>0</UseTargetDll> |
|||
<UseExternalTool>0</UseExternalTool> |
|||
<RunIndependent>0</RunIndependent> |
|||
<UpdateFlashBeforeDebugging>0</UpdateFlashBeforeDebugging> |
|||
<Capability>0</Capability> |
|||
<DriverSelection>-1</DriverSelection> |
|||
</Flash1> |
|||
<bUseTDR>0</bUseTDR> |
|||
<Flash2></Flash2> |
|||
<Flash3>"" ()</Flash3> |
|||
<Flash4></Flash4> |
|||
<pFcarmOut></pFcarmOut> |
|||
<pFcarmGrp></pFcarmGrp> |
|||
<pFcArmRoot></pFcArmRoot> |
|||
<FcArmLst>0</FcArmLst> |
|||
</Utilities> |
|||
<Target51> |
|||
<Target51Misc> |
|||
<MemoryModel>2</MemoryModel> |
|||
<RTOS>0</RTOS> |
|||
<RomSize>2</RomSize> |
|||
<DataHold>0</DataHold> |
|||
<XDataHold>0</XDataHold> |
|||
<UseOnchipRom>0</UseOnchipRom> |
|||
<UseOnchipArithmetic>0</UseOnchipArithmetic> |
|||
<UseMultipleDPTR>0</UseMultipleDPTR> |
|||
<UseOnchipXram>0</UseOnchipXram> |
|||
<HadIRAM>1</HadIRAM> |
|||
<HadXRAM>1</HadXRAM> |
|||
<HadIROM>1</HadIROM> |
|||
<Moda2>0</Moda2> |
|||
<Moddp2>0</Moddp2> |
|||
<Modp2>1</Modp2> |
|||
<Mod517dp>0</Mod517dp> |
|||
<Mod517au>0</Mod517au> |
|||
<Mode2>0</Mode2> |
|||
<useCB>0</useCB> |
|||
<useXB>0</useXB> |
|||
<useL251>1</useL251> |
|||
<useA251>0</useA251> |
|||
<Mx51>0</Mx51> |
|||
<ModC812>0</ModC812> |
|||
<ModCont>0</ModCont> |
|||
<Lp51>0</Lp51> |
|||
<useXBS>0</useXBS> |
|||
<ModDA>0</ModDA> |
|||
<ModAB2>0</ModAB2> |
|||
<Mx51P>0</Mx51P> |
|||
<hadXRAM2>0</hadXRAM2> |
|||
<uocXram2>0</uocXram2> |
|||
<hadXRAM3>0</hadXRAM3> |
|||
<ModC2>0</ModC2> |
|||
<ModH2>0</ModH2> |
|||
<Mdu_R515>0</Mdu_R515> |
|||
<Mdu_F120>0</Mdu_F120> |
|||
<Psoc>0</Psoc> |
|||
<hadIROM2>0</hadIROM2> |
|||
<hadIROM3>0</hadIROM3> |
|||
<ModSmx2>0</ModSmx2> |
|||
<cBanks>0</cBanks> |
|||
<xBanks>0</xBanks> |
|||
<OnChipMemories> |
|||
<RCB> |
|||
<Type>0</Type> |
|||
<StartAddress>0x0</StartAddress> |
|||
<Size>0xffff</Size> |
|||
</RCB> |
|||
<RXB> |
|||
<Type>0</Type> |
|||
<StartAddress>0x0</StartAddress> |
|||
<Size>0x0</Size> |
|||
</RXB> |
|||
<Ocm1> |
|||
<Type>0</Type> |
|||
<StartAddress>0x0</StartAddress> |
|||
<Size>0x0</Size> |
|||
</Ocm1> |
|||
<Ocm2> |
|||
<Type>0</Type> |
|||
<StartAddress>0x0</StartAddress> |
|||
<Size>0x0</Size> |
|||
</Ocm2> |
|||
<Ocm3> |
|||
<Type>0</Type> |
|||
<StartAddress>0x0</StartAddress> |
|||
<Size>0x0</Size> |
|||
</Ocm3> |
|||
<Ocr1> |
|||
<Type>0</Type> |
|||
<StartAddress>0x0</StartAddress> |
|||
<Size>0x0</Size> |
|||
</Ocr1> |
|||
<Ocr2> |
|||
<Type>0</Type> |
|||
<StartAddress>0x0</StartAddress> |
|||
<Size>0x0</Size> |
|||
</Ocr2> |
|||
<Ocr3> |
|||
<Type>0</Type> |
|||
<StartAddress>0x0</StartAddress> |
|||
<Size>0x0</Size> |
|||
</Ocr3> |
|||
<IRO> |
|||
<Type>1</Type> |
|||
<StartAddress>0x0</StartAddress> |
|||
<Size>0xfff9</Size> |
|||
</IRO> |
|||
<IRA> |
|||
<Type>0</Type> |
|||
<StartAddress>0x0</StartAddress> |
|||
<Size>0x100</Size> |
|||
</IRA> |
|||
<XRA> |
|||
<Type>0</Type> |
|||
<StartAddress>0x0</StartAddress> |
|||
<Size>0x800</Size> |
|||
</XRA> |
|||
<XRA512> |
|||
<Type>0</Type> |
|||
<StartAddress>0x0</StartAddress> |
|||
<Size>0x0</Size> |
|||
</XRA512> |
|||
<IROM512> |
|||
<Type>0</Type> |
|||
<StartAddress>0x0</StartAddress> |
|||
<Size>0x0</Size> |
|||
</IROM512> |
|||
<XRA513> |
|||
<Type>0</Type> |
|||
<StartAddress>0x0</StartAddress> |
|||
<Size>0x0</Size> |
|||
</XRA513> |
|||
<IROM513> |
|||
<Type>0</Type> |
|||
<StartAddress>0x0</StartAddress> |
|||
<Size>0x0</Size> |
|||
</IROM513> |
|||
</OnChipMemories> |
|||
</Target51Misc> |
|||
<C51> |
|||
<RegisterColoring>0</RegisterColoring> |
|||
<VariablesInOrder>0</VariablesInOrder> |
|||
<IntegerPromotion>0</IntegerPromotion> |
|||
<uAregs>0</uAregs> |
|||
<UseInterruptVector>1</UseInterruptVector> |
|||
<Fuzzy>3</Fuzzy> |
|||
<Optimize>2</Optimize> |
|||
<WarningLevel>2</WarningLevel> |
|||
<SizeSpeed>0</SizeSpeed> |
|||
<ObjectExtend>1</ObjectExtend> |
|||
<ACallAJmp>0</ACallAJmp> |
|||
<InterruptVectorAddress>0</InterruptVectorAddress> |
|||
<VariousControls> |
|||
<MiscControls></MiscControls> |
|||
<Define></Define> |
|||
<Undefine></Undefine> |
|||
<IncludePath></IncludePath> |
|||
</VariousControls> |
|||
</C51> |
|||
<Ax51> |
|||
<UseMpl>0</UseMpl> |
|||
<UseStandard>1</UseStandard> |
|||
<UseCase>0</UseCase> |
|||
<UseMod51>0</UseMod51> |
|||
<VariousControls> |
|||
<MiscControls></MiscControls> |
|||
<Define></Define> |
|||
<Undefine></Undefine> |
|||
<IncludePath></IncludePath> |
|||
</VariousControls> |
|||
</Ax51> |
|||
<Lx51> |
|||
<useFile>0</useFile> |
|||
<linkonly>0</linkonly> |
|||
<UseMemoryFromTarget>1</UseMemoryFromTarget> |
|||
<CaseSensitiveSymbols>0</CaseSensitiveSymbols> |
|||
<WarningLevel>2</WarningLevel> |
|||
<DataOverlaying>1</DataOverlaying> |
|||
<OverlayString></OverlayString> |
|||
<MiscControls>REMOVEUNUSED</MiscControls> |
|||
<DisableWarningNumbers></DisableWarningNumbers> |
|||
<LinkerCmdFile></LinkerCmdFile> |
|||
<Assign></Assign> |
|||
<ReserveString></ReserveString> |
|||
<CClasses></CClasses> |
|||
<UserClasses></UserClasses> |
|||
<CSection></CSection> |
|||
<UserSection></UserSection> |
|||
<CodeBaseAddress></CodeBaseAddress> |
|||
<XDataBaseAddress></XDataBaseAddress> |
|||
<PDataBaseAddress></PDataBaseAddress> |
|||
<BitBaseAddress></BitBaseAddress> |
|||
<DataBaseAddress></DataBaseAddress> |
|||
<IDataBaseAddress></IDataBaseAddress> |
|||
<Precede></Precede> |
|||
<Stack></Stack> |
|||
<CodeSegmentName></CodeSegmentName> |
|||
<XDataSegmentName></XDataSegmentName> |
|||
<BitSegmentName></BitSegmentName> |
|||
<DataSegmentName></DataSegmentName> |
|||
<IDataSegmentName></IDataSegmentName> |
|||
</Lx51> |
|||
</Target51> |
|||
</TargetOption> |
|||
<Groups> |
|||
<Group> |
|||
<GroupName>app</GroupName> |
|||
<Files> |
|||
<File> |
|||
<FileName>main.c</FileName> |
|||
<FileType>1</FileType> |
|||
<FilePath>..\source\app\main.c</FilePath> |
|||
</File> |
|||
<File> |
|||
<FileName>common.c</FileName> |
|||
<FileType>1</FileType> |
|||
<FilePath>..\source\app\common.c</FilePath> |
|||
</File> |
|||
</Files> |
|||
</Group> |
|||
<Group> |
|||
<GroupName>cpu</GroupName> |
|||
<Files> |
|||
<File> |
|||
<FileName>STARTUP.A51</FileName> |
|||
<FileType>2</FileType> |
|||
<FilePath>..\source\cpu\STARTUP.A51</FilePath> |
|||
</File> |
|||
</Files> |
|||
</Group> |
|||
<Group> |
|||
<GroupName>msp</GroupName> |
|||
<Files> |
|||
<File> |
|||
<FileName>time.c</FileName> |
|||
<FileType>1</FileType> |
|||
<FilePath>..\source\msp\time.c</FilePath> |
|||
</File> |
|||
<File> |
|||
<FileName>UART0.C</FileName> |
|||
<FileType>1</FileType> |
|||
<FilePath>..\source\msp\UART0.C</FilePath> |
|||
</File> |
|||
<File> |
|||
<FileName>msp_eeprom.c</FileName> |
|||
<FileType>1</FileType> |
|||
<FilePath>..\source\msp\msp_eeprom.c</FilePath> |
|||
</File> |
|||
<File> |
|||
<FileName>msp_id.c</FileName> |
|||
<FileType>1</FileType> |
|||
<FilePath>..\source\msp\msp_id.c</FilePath> |
|||
</File> |
|||
</Files> |
|||
</Group> |
|||
<Group> |
|||
<GroupName>bsp</GroupName> |
|||
</Group> |
|||
<Group> |
|||
<GroupName>ctask</GroupName> |
|||
<Files> |
|||
<File> |
|||
<FileName>task.c</FileName> |
|||
<FileType>1</FileType> |
|||
<FilePath>..\source\ctask\task.c</FilePath> |
|||
</File> |
|||
<File> |
|||
<FileName>tick.c</FileName> |
|||
<FileType>1</FileType> |
|||
<FilePath>..\source\ctask\tick.c</FilePath> |
|||
</File> |
|||
</Files> |
|||
</Group> |
|||
<Group> |
|||
<GroupName>tpc</GroupName> |
|||
<Files> |
|||
<File> |
|||
<FileName>tpc_modbus.c</FileName> |
|||
<FileType>1</FileType> |
|||
<FilePath>..\source\tpc\tpc_modbus.c</FilePath> |
|||
</File> |
|||
</Files> |
|||
</Group> |
|||
<Group> |
|||
<GroupName>clib</GroupName> |
|||
<Files> |
|||
<File> |
|||
<FileName>clib.c</FileName> |
|||
<FileType>1</FileType> |
|||
<FilePath>..\source\clib\clib.c</FilePath> |
|||
</File> |
|||
</Files> |
|||
</Group> |
|||
</Groups> |
|||
</Target> |
|||
</Targets> |
|||
|
|||
</Project> |
@ -0,0 +1,152 @@ |
|||
#define, Keyword |
|||
#elif, Directive |
|||
#else, Directive |
|||
#endif, Directive |
|||
#if, Directive |
|||
#ifdef, Directive |
|||
#ifndef, Directive |
|||
#include, Keyword |
|||
#pragma, Keyword |
|||
#undef, Keyword |
|||
(, Delimiter |
|||
), Delimiter |
|||
",", Delimiter |
|||
;, Delimiter |
|||
abstract, Keyword |
|||
__abstract, Keyword |
|||
alignas, Keyword |
|||
alignof, Keyword |
|||
asm, Keyword |
|||
__asm, Keyword |
|||
assert, Debug |
|||
Assert, Debug |
|||
async, Keyword |
|||
auto, Keyword |
|||
bool, Keyword |
|||
break, Control |
|||
case, Control |
|||
catch, Control |
|||
cdecl, Keyword |
|||
__cdecl, Keyword |
|||
char, Keyword |
|||
class, Control |
|||
coclass, Control |
|||
const, Keyword |
|||
constexpr, Keyword |
|||
const_cast, Keyword |
|||
continue, Control |
|||
cout, Keyword |
|||
decltype, Keyword |
|||
default, Control |
|||
__delegate, Keyword |
|||
delete, Control |
|||
do, Control |
|||
double, Keyword |
|||
DWORD, Keyword |
|||
dynamic_cast, Keyword |
|||
each, Control |
|||
else, Control |
|||
enum, Control |
|||
__event, Keyword |
|||
except, Control |
|||
__except, Control |
|||
exception, Keyword |
|||
explicit, Keyword |
|||
export, Keyword |
|||
extern, Keyword |
|||
FALSE, Boolean |
|||
false, Boolean |
|||
FAR, Keyword |
|||
far, Keyword |
|||
final, Keyword |
|||
__finally, Control |
|||
float, Keyword |
|||
for, Control |
|||
fortran, Keyword |
|||
for_each, Control |
|||
friend, Keyword |
|||
__gc, Keyword |
|||
goto, Control |
|||
HUGE, Keyword |
|||
huge, Keyword |
|||
if, Control |
|||
inline, Keyword |
|||
INT, Keyword |
|||
int, Keyword |
|||
int16_t, Keyword |
|||
int32_t, Keyword |
|||
int64_t, Keyword |
|||
int8_t, Keyword |
|||
interface, Control |
|||
LONG, Keyword |
|||
long, Keyword |
|||
mutable, Keyword |
|||
namespace, Control |
|||
near, Keyword |
|||
NEAR, Keyword |
|||
new, Control |
|||
noexcept, Keyword |
|||
NULL, Null Value |
|||
nullptr, Null Value |
|||
__nullptr, Null Value |
|||
operator, Keyword |
|||
override, Keyword |
|||
pascal, Keyword |
|||
PASCAL, Keyword |
|||
private, Keyword |
|||
__property, Keyword |
|||
protected, Keyword |
|||
public, Keyword |
|||
ref, Keyword |
|||
REGISTER, Keyword |
|||
register, Keyword |
|||
reinterpret_cast, Keyword |
|||
return, Control |
|||
sealed, Keyword |
|||
short, Keyword |
|||
SHORT, Keyword |
|||
signed, Keyword |
|||
sizeof, Keyword |
|||
static, Keyword |
|||
static_cast, Keyword |
|||
struct, Control |
|||
__super, Keyword |
|||
switch, Control |
|||
template, Control |
|||
this, Keyword |
|||
thread_local, Keyword |
|||
throw, Control |
|||
TRUE, Boolean |
|||
true, Boolean |
|||
try, Control |
|||
__try, Control |
|||
TTSS_step01, Highlight |
|||
TTSS_Task_end, Highlight |
|||
TTSS_Task_init, Highlight |
|||
TTSS_Task_step, Highlight |
|||
TTSS_step01, Highlight |
|||
TTSS_step02,Highlight |
|||
TTSS_step03,Highlight |
|||
TTSS_step04,Highlight |
|||
TTSS_step05,Highlight |
|||
TTSS_step06,Highlight |
|||
TTSS_step07,Highlight |
|||
TTSS_Task_step, Highlight |
|||
typedef, Control |
|||
typeid, Keyword |
|||
typename, Keyword |
|||
UINT, Keyword |
|||
union, Control |
|||
unsigned, Keyword |
|||
using, Keyword |
|||
virtual, Keyword |
|||
VOID, Keyword |
|||
void, Keyword |
|||
volatile, Keyword |
|||
wchar_t, Keyword |
|||
while, Control |
|||
WORD, Keyword |
|||
{, Delimiter |
|||
[, Delimiter |
|||
], Delimiter |
|||
}, Delimiter |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,22 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<ProjectSettings |
|||
AppVer="4.00.0093" |
|||
AppVerMinReader="4.00.0034" |
|||
GlobalConfiguration="1" |
|||
GlobalWorkspace="0" |
|||
LocalsInDb="0" |
|||
IndexMembers="0" |
|||
IndexFragments="1" |
|||
UseMasterFileList="0" |
|||
SourceDir="." |
|||
BackupDir="%PROJECT_DATA_DIR%\Backup" |
|||
MasterFileList="%PROJECT_SOURCE_DIR%\%PROJECT_NAME%_filelist.txt" |
|||
IsImportProject="0" |
|||
> |
|||
<Imports> |
|||
<ImportedLibs/> |
|||
</Imports> |
|||
<ParseConditions> |
|||
<Defines/> |
|||
</ParseConditions> |
|||
</ProjectSettings> |
Binary file not shown.
@ -0,0 +1,141 @@ |
|||
#define, Keyword |
|||
#elif, Directive |
|||
#else, Directive |
|||
#endif, Directive |
|||
#if, Directive |
|||
#ifdef, Directive |
|||
#ifndef, Directive |
|||
#include, Keyword |
|||
#pragma, Keyword |
|||
#undef, Keyword |
|||
(, Delimiter |
|||
), Delimiter |
|||
",", Delimiter |
|||
;, Delimiter |
|||
abstract, Keyword |
|||
__abstract, Keyword |
|||
alignas, Keyword |
|||
alignof, Keyword |
|||
asm, Keyword |
|||
__asm, Keyword |
|||
assert, Debug |
|||
Assert, Debug |
|||
async, Keyword |
|||
auto, Keyword |
|||
bool, Keyword |
|||
break, Control |
|||
case, Control |
|||
catch, Control |
|||
cdecl, Keyword |
|||
__cdecl, Keyword |
|||
char, Keyword |
|||
class, Control |
|||
coclass, Control |
|||
const, Keyword |
|||
constexpr, Keyword |
|||
const_cast, Keyword |
|||
continue, Control |
|||
cout, Keyword |
|||
decltype, Keyword |
|||
default, Control |
|||
__delegate, Keyword |
|||
delete, Control |
|||
do, Control |
|||
double, Keyword |
|||
DWORD, Keyword |
|||
dynamic_cast, Keyword |
|||
each, Control |
|||
else, Control |
|||
enum, Control |
|||
__event, Keyword |
|||
except, Control |
|||
__except, Control |
|||
exception, Keyword |
|||
explicit, Keyword |
|||
export, Keyword |
|||
extern, Keyword |
|||
FALSE, Boolean |
|||
false, Boolean |
|||
FAR, Keyword |
|||
far, Keyword |
|||
final, Keyword |
|||
__finally, Control |
|||
float, Keyword |
|||
for, Control |
|||
fortran, Keyword |
|||
for_each, Control |
|||
friend, Keyword |
|||
__gc, Keyword |
|||
goto, Control |
|||
huge, Keyword |
|||
HUGE, Keyword |
|||
if, Control |
|||
inline, Keyword |
|||
INT, Keyword |
|||
int, Keyword |
|||
int16_t, Keyword |
|||
int32_t, Keyword |
|||
int64_t, Keyword |
|||
int8_t, Keyword |
|||
interface, Control |
|||
long, Keyword |
|||
LONG, Keyword |
|||
mutable, Keyword |
|||
namespace, Control |
|||
near, Keyword |
|||
NEAR, Keyword |
|||
new, Control |
|||
NULL, Null Value |
|||
nullptr, Null Value |
|||
__nullptr, Null Value |
|||
operator, Keyword |
|||
override, Keyword |
|||
PASCAL, Keyword |
|||
pascal, Keyword |
|||
private, Keyword |
|||
__property, Keyword |
|||
protected, Keyword |
|||
public, Keyword |
|||
ref, Keyword |
|||
register, Keyword |
|||
REGISTER, Keyword |
|||
reinterpret_cast, Keyword |
|||
return, Control |
|||
sealed, Keyword |
|||
short, Keyword |
|||
SHORT, Keyword |
|||
signed, Keyword |
|||
sizeof, Keyword |
|||
static, Keyword |
|||
static_cast, Keyword |
|||
struct, Control |
|||
__super, Keyword |
|||
switch, Control |
|||
template, Control |
|||
this, Keyword |
|||
thread_local, Keyword |
|||
throw, Control |
|||
TRUE, Boolean |
|||
true, Boolean |
|||
try, Control |
|||
__try, Control |
|||
ttss_task_init, Highlight |
|||
typedef, Control |
|||
typeid, Keyword |
|||
typename, Keyword |
|||
UINT, Keyword |
|||
union, Control |
|||
unsigned, Keyword |
|||
using, Keyword |
|||
value, Keyword |
|||
virtual, Keyword |
|||
VOID, Keyword |
|||
void, Keyword |
|||
volatile, Keyword |
|||
wchar_t, Keyword |
|||
while, Control |
|||
WORD, Keyword |
|||
[, Delimiter |
|||
{, Delimiter |
|||
], Delimiter |
|||
}, Delimiter |
@ -0,0 +1,75 @@ |
|||
#include "common.h" |
|||
//#include "../tpc/tpc_uart.h"
|
|||
#include "../msp/msp_eeprom.h" |
|||
#include "../msp/msp_id.h" |
|||
|
|||
struct global_param G; |
|||
struct ts_eeprom_param eep_param; |
|||
|
|||
#define EEP_SECTOR_SIZE 0x200 |
|||
#define EEP_PARAM_ADDR (EEP_SECTOR_SIZE * 0) |
|||
#define ENC_KEY 0x01010101 |
|||
|
|||
#if 0 |
|||
void L3_eeprom_read(void) |
|||
{ |
|||
U8 dlen = 0; |
|||
L0_Iap_Read_array(EEP_PARAM_ADDR, (U8*)&eep_param, 2 + EEPROM_PARAM_DATA_MAX + 2); |
|||
if(eep_param.filter == EEPROM_PARAM_FILTER) |
|||
{ |
|||
dlen = eep_param.len - 2; |
|||
crc16(eep_param.crc,(U8*)&eep_param,2+dlen); |
|||
if(eep_param.crc[0] == eep_param.buf[dlen] && eep_param.crc[1] == eep_param.buf[dlen+1]) |
|||
{ |
|||
L0_uart0_uc('#'); |
|||
Lc_buf_copy_uc((U8*)&G.p,(U8*)eep_param.buf,dlen); |
|||
} |
|||
} |
|||
} |
|||
#endif |
|||
|
|||
void L3_eeprom_persist(void) |
|||
{ |
|||
U8 dlen = MCU_ID_KEY_LEN + MCU_ID_LEN; |
|||
eep_param.filter = EEPROM_PARAM_FILTER; |
|||
eep_param.len = dlen + 2; |
|||
Lc_buf_copy_uc((U8*)eep_param.enc_key,(U8*)&G.enc_key,MCU_ID_KEY_LEN); |
|||
Lc_buf_copy_uc((U8*)eep_param.enc_val,(U8*)&G.mcu_enc_id,MCU_ID_LEN); |
|||
crc16(eep_param.crc, &eep_param, 2+dlen); |
|||
|
|||
L0_Iap_Erase(EEP_PARAM_ADDR); |
|||
L0_Iap_Program_array(EEP_PARAM_ADDR, (U8*)&eep_param, 2 + dlen + 2); |
|||
} |
|||
|
|||
|
|||
void L3_chip_encrypt_main(void) |
|||
{ |
|||
U8 i = 0; |
|||
|
|||
//1.获取MCU_ID
|
|||
L0_id_get_rom(G.mcu_id); |
|||
|
|||
for(i=0;i<MCU_ID_LEN;i++) |
|||
{ |
|||
L0_uart0_uchex(G.mcu_id[i]); |
|||
} |
|||
|
|||
//2.ID加密
|
|||
Lc_encrypt_id(G.mcu_enc_id,G.mcu_id, ENC_KEY, MCU_ID_LEN); |
|||
|
|||
//3.写入EEPROM
|
|||
L3_eeprom_persist(); |
|||
|
|||
L0_uart0_uc('Y'); |
|||
} |
|||
|
|||
void L3_reg_init(void) |
|||
{ |
|||
G.enc_key[0] = ENC_KEY >> 24 & 0xFF; |
|||
G.enc_key[1] = ENC_KEY >> 16 & 0xFF; |
|||
G.enc_key[2] = ENC_KEY >> 8 & 0xFF; |
|||
G.enc_key[3] = ENC_KEY >> 0 & 0xFF; |
|||
//eeprom中读取持久化的值
|
|||
//L3_eeprom_read();
|
|||
} |
|||
|
@ -0,0 +1,78 @@ |
|||
#ifndef APP_COMMON_H |
|||
#define APP_COMMON_H |
|||
|
|||
#include "../clib/type.h" |
|||
|
|||
#define APP_VERSION 0x10 |
|||
#define P485_SLAVER_ID 0x01 |
|||
#define D_ADC_CHANNEL_MAX 4 |
|||
|
|||
#define D_MCU_BIGENDIAN 1 |
|||
// #define D_MCU_LITTLEENDIAN 1
|
|||
|
|||
#define D_COUNT_WEIGHT(adc,zadc) ((S32)((1.0 * G.p.ratio * G.p.weight_max * (adc - zadc)) / (2 * 0x7FFFFF / 1000 * D_ADS1213_GAIN_VAL * G.p.lmd))) |
|||
//#define D_COUNT_WEIGHT(adc,zWeight) ((S32)((1.0 * G.p.ratio * G.p.weight_max * (adc)) / (2 * 0x7FFFFF / 1000 * D_ADS1213_GAIN_VAL * G.p.lmd)) - zWeight)
|
|||
|
|||
#define MCU_ID_LEN 7 |
|||
#define MCU_ID_KEY_LEN 4 |
|||
|
|||
enum tp_handle |
|||
{ |
|||
TP_HANDLED, |
|||
TP_UNHANDLE |
|||
}; |
|||
|
|||
/**
|
|||
* EEPROM 存储结构 |
|||
*/ |
|||
#define EEPROM_PARAM_DATA_MAX 64 |
|||
#define EEPROM_PARAM_FILTER 0xAA |
|||
typedef struct ts_eeprom_param |
|||
{ |
|||
U8 filter; |
|||
U8 len; |
|||
U8 enc_key[MCU_ID_KEY_LEN]; |
|||
U8 enc_val[MCU_ID_LEN]; |
|||
U8 crc[2]; |
|||
}EEPROM_PARAM; |
|||
|
|||
/**
|
|||
* 用户协议 |
|||
*/ |
|||
|
|||
|
|||
//协议类型: MODBUS RTU模式
|
|||
#define D_s_PH4_modbus_max (12) |
|||
typedef struct ts_ph4_modbus |
|||
{ |
|||
U8 salver; //从机地址
|
|||
U8 oper; //功能码
|
|||
U8 buf[D_s_PH4_modbus_max]; |
|||
U8 crc[2]; |
|||
U8 num; |
|||
}TS_PH4_modbus; |
|||
|
|||
/**
|
|||
* Register Map |
|||
*/ |
|||
typedef struct global_param |
|||
{ |
|||
U16 reserved; |
|||
U8 enc_key[MCU_ID_KEY_LEN]; |
|||
U8 mcu_id[MCU_ID_LEN]; |
|||
U8 mcu_enc_id[MCU_ID_LEN]; |
|||
}GlobalParam; |
|||
|
|||
extern struct global_param G; |
|||
extern void L3_reg_init(void); |
|||
extern void L3_chip_encrypt_main(void); |
|||
|
|||
//寄存器内存基地址
|
|||
#define REG_MEM_BASE ((U16*)(&G)) //寄存器基础地址(本文件外部不应该使用该宏定义)
|
|||
//变量地址转寄存器
|
|||
#define MEM_2_REG(mem) (((U16*)(mem) - REG_MEM_BASE) + 1) |
|||
//寄存器转变量地址
|
|||
#define REG_2_MEM(reg) (REG_MEM_BASE + (U16)((reg) - 1)) |
|||
|
|||
#endif |
|||
|
@ -0,0 +1,153 @@ |
|||
//////////////////////////////////////////////////////////////////////////
|
|||
/// COPYRIGHT NOTICE
|
|||
/// Copyright (c) 2015, 传控科技
|
|||
/// All rights reserved.
|
|||
///
|
|||
/// @file main.c
|
|||
/// @brief main app
|
|||
///
|
|||
///(本文件实现的功能的详述)
|
|||
///
|
|||
/// @version 1.1 CCsens technology
|
|||
/// @author CC
|
|||
/// @date 20150102
|
|||
/// @note
|
|||
///
|
|||
/// @version 1.2 CCsens technology
|
|||
/// @author CC
|
|||
/// @date 20180903
|
|||
/// @note cc_gsm_PD03SM_vh03_m10_debug01
|
|||
//20160413 CC-ACC-VH02
|
|||
//20170111 CC-ls_02
|
|||
//
|
|||
//20170608 cc_as_stc01_main
|
|||
//
|
|||
//20180903 cc_gsm_PD03SM_vh03_m10_debug01
|
|||
//
|
|||
//
|
|||
/// @version 1.3 CCsens technology
|
|||
/// @author CC
|
|||
/// @date 20180903
|
|||
/// @note add calibrationg function
|
|||
/// @version 1.4 CCsens technology
|
|||
/// @author CC
|
|||
/// @date 20190101
|
|||
/// @note add calibrationg function
|
|||
|
|||
//////////////////////////////////////////////////////////////////////////
|
|||
|
|||
|
|||
/// 下面是一个含有两个参数的函数的注释说明(简述)
|
|||
///
|
|||
/// 这里写该函数的详述信息
|
|||
/// @param a 被测试的变量(param描述参数)
|
|||
/// @param s 指向描述测试信息的字符串
|
|||
/// @return 测试结果(return描述返回值)
|
|||
/// @see Test() (本函数参考其它的相关的函数,这里作一个链接)
|
|||
/// @note (note描述需要注意的问题)
|
|||
/************************************************
|
|||
stc5ac32s |
|||
程序结构 |
|||
|
|||
|
|||
有动静 |
|||
并且采集的值小于c200 设置采集间隔缩短 |
|||
采集值 在 c200<val<cff 设置采集时间间隔 |
|||
采集值大于cff 进入校准模式 ,采集5次求平均 写入曲线中 |
|||
、、、、、、、、、、 |
|||
应用: 定期采集cam 参数:间隔时间 采集方式(热采集还是冷采集,也就是是否对cam |
|||
重新上电) |
|||
驱动: cam 参数设置及中断 |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
************************************************/ |
|||
//===============================================
|
|||
//寄存器头文件
|
|||
//===============================================
|
|||
|
|||
#include "main.h" |
|||
|
|||
|
|||
/// main init
|
|||
/// @param a 被测试的变量(param描述参数)
|
|||
/// @param s 指向描述测试信息的字符串
|
|||
/// @return 测试结果(return描述返回值)
|
|||
/// @see Test() (本函数参考其它的相关的函数,这里作一个链接)
|
|||
/// @note (note描述需要注意的问题)
|
|||
|
|||
void L0_main_init(void) |
|||
{ |
|||
Lc_delay_ms(200); |
|||
//L0_I2C_INIT(1);
|
|||
//L1_app_POWER_init();
|
|||
L1_uart0_buf_init();//串口初始化
|
|||
EA = 1; |
|||
Lc_delay_ms(100); |
|||
|
|||
L1_tick_init(); |
|||
L0_timer0_Init(); |
|||
L0_timer1_Init(); |
|||
//L0_I2C_INIT(1);
|
|||
//L2_task_ALGO_init();
|
|||
} |
|||
|
|||
//===============================================
|
|||
//主函数
|
|||
//===============================================
|
|||
void main(void) |
|||
{ |
|||
//-----------------------------------------------
|
|||
//系统初始化
|
|||
//----------------------------------------------
|
|||
L0_main_init(); |
|||
//L2_task_FLOW_init();
|
|||
|
|||
//while(1);
|
|||
L3_reg_init(); |
|||
//L2_485_init();
|
|||
//L0_ADS1213_INIT();
|
|||
//L1_s2b_PH4_init(&s_uart0_rec,G.p.slaver_id);
|
|||
//L3_task_adc_init();
|
|||
|
|||
L0_uart0_sendArray("v1.0",4); |
|||
|
|||
|
|||
//-----------------------------------------------
|
|||
//系统主循环
|
|||
//-----------------------------------------------
|
|||
//L0_id_main();
|
|||
L3_chip_encrypt_main(); |
|||
//L1_Iap_main();
|
|||
while(1) |
|||
{ |
|||
if(1 == s_nos_tick.t1s_heatbeart) |
|||
{ |
|||
s_nos_tick.t1s_heatbeart = 0; |
|||
L0_uart0_uc('.'); |
|||
P10 ^= 1; |
|||
} |
|||
} |
|||
} |
|||
//end main
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
@ -0,0 +1,82 @@ |
|||
//////////////////////////////////////////////////////////////////////////
|
|||
/// COPYRIGHT NOTICE
|
|||
/// Copyright (c) 2017, 传控科技
|
|||
/// All rights reserved.
|
|||
///
|
|||
/// @file main.c
|
|||
/// @brief main app
|
|||
///
|
|||
///(本文件实现的功能的详述)
|
|||
///
|
|||
/// @version 1.1 CCsens technology
|
|||
/// @author CC
|
|||
/// @date 20150102
|
|||
///
|
|||
///
|
|||
/// 修订说明:最初版本
|
|||
/// Modified by:
|
|||
/// Modified date:
|
|||
/// Version:
|
|||
/// Descriptions:
|
|||
///
|
|||
///
|
|||
///
|
|||
///
|
|||
///
|
|||
///
|
|||
///
|
|||
/// msp: humtemp flow
|
|||
/// bsp: i2c adc
|
|||
///
|
|||
///
|
|||
///
|
|||
///
|
|||
///
|
|||
//////////////////////////////////////////////////////////////////////////
|
|||
|
|||
#ifndef _MAIN_H |
|||
#define _MAIN_H |
|||
#include "../bsp/bsp_config.h" |
|||
//#include "../bsp/adxl362.h"
|
|||
|
|||
//#include "../msp/stc_adc.h"
|
|||
#include "../msp/uart0.h" |
|||
//#include "../msp/uart2.h"
|
|||
//#include "../msp/uart4.h"
|
|||
//#include "../msp/uart3.h"
|
|||
//#include "../msp/time.h"
|
|||
//#include "../msp/msp_buzz.h"
|
|||
//#include "../msp/msp_rtc.h"
|
|||
//#include "../msp/msp_plcd.h"
|
|||
#include "../msp/msp_eeprom.h" |
|||
#include "../msp/msp_id.h" |
|||
|
|||
|
|||
#include "../clib/Clib.h" |
|||
#include "../clib/bit.h" |
|||
|
|||
//#include "../debug/debug_drv.h"
|
|||
//#include "../uartcom/uprotocol.h"
|
|||
//#include "../uartcom/Uartcom0.h"
|
|||
#include "../ctask/task.h" |
|||
#include "../ctask/tick.h" |
|||
|
|||
//#include "../bsp/bsp_led.h"
|
|||
|
|||
|
|||
//#include "../bsp/Bsp_debug.h"
|
|||
|
|||
|
|||
//#include "app_yeelink.h"
|
|||
//#include "app_Gsensor.h"
|
|||
//#include "app_io.h"
|
|||
#include "../tpc/tpc_uart.h" |
|||
#include "stdio.h" |
|||
|
|||
|
|||
//////////////////////////////////////////////////////////////////
|
|||
|
|||
|
|||
#endif //#ifndef _MAIN_H
|
|||
|
|||
|
Binary file not shown.
@ -0,0 +1,343 @@ |
|||
////////////////////////////////////////////////////////////////////////////
|
|||
///@copyright Copyright (c) 2017, 传控科技 All rights reserved.
|
|||
///-------------------------------------------------------------------------
|
|||
/// @file hard_config.h
|
|||
/// @brief hard config include
|
|||
/// @info FILE FOR HARDWARE SETUP AND SOFTWARE SETUP///FOR EXAMPLE: BAORD ,MCU,IDE
|
|||
/// @info YOU CAN CHANGE OR ADD THE DEFINE IF YOU NEED
|
|||
/// @info 整个嵌入式项目的入口 首先是确认电路板 然后确认cpu 芯片型号 然后确认编译器 之后是软件框架 最后是应用程序
|
|||
/// @info bsp_CONFIG 为其他头文件的始祖 TYPE_BOARD_xx
|
|||
///-------------------------------------------------------------------------
|
|||
/// @version 1.1
|
|||
/// @author CC
|
|||
/// @date 20180308
|
|||
/// @note
|
|||
//////////////////////////////////////////////////////////////////////////////
|
|||
/// @version 5.1
|
|||
/// @author CC
|
|||
/// @date 20200301
|
|||
/// @note
|
|||
//////////////////////////////////////////////////////////////////////////////
|
|||
|
|||
|
|||
//////////////////////////////////////////////////////////////////////////
|
|||
#ifndef _BSP_CONFIG_H |
|||
#define _BSP_CONFIG_H |
|||
#include <INTRINS.H> |
|||
|
|||
|
|||
#include "bsp_config0.h" |
|||
|
|||
#define D_version_v 'L' |
|||
|
|||
|
|||
#if 0 |
|||
|
|||
#define D_leda_OFF(); D_P35_OFF(); |
|||
#define D_leda_ON(); D_P35_ON(); |
|||
#define D_leda_REV(); D_P35_REV(); |
|||
#define D_ledb_OFF(); D_P34_OFF(); |
|||
#define D_ledb_ON(); D_P34_ON(); |
|||
#define D_ledb_REV(); D_P34_REV(); |
|||
|
|||
#else |
|||
#define D_leda_OFF(); ///D_P35_OFF();
|
|||
#define D_leda_ON(); ///D_P35_ON();
|
|||
#define D_leda_REV(); ///D_P35_REV();
|
|||
#define D_ledb_OFF(); ///D_P34_OFF();
|
|||
#define D_ledb_ON(); ///D_P34_ON();
|
|||
#define D_ledb_REV(); ///D_P34_REV();
|
|||
|
|||
#endif |
|||
|
|||
|
|||
#if 0 |
|||
#define D_debug_sim |
|||
#endif |
|||
//#define D_iic_inspect
|
|||
#define D_open_save_f |
|||
|
|||
#define TYPE_UASER_BOARD ccSensor_WS_ps5ws //CC_SE_paper_main_m10_smt01.sch
|
|||
|
|||
//STEP 2 TYPE_UASER_BOARD CONFIG >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|||
|
|||
#if(TYPE_UASER_BOARD == ccSensor_WS_ps5ws)///-------TYPE_UASER_BOARD----------------TYPE_UASER_BOARD----------
|
|||
//2.0-5.5 8K 2kram 4k eeprom spi iic 2uart tssop20 stc8f2k08s2 1.2yuan
|
|||
//2.0-5.5 16K 2kram 4k eeprom spi iic 2uart tssop20 stc8f2k16s2 1.4yuan
|
|||
|
|||
|
|||
//1.7-5.5 8K 1kram 3k eeprom spi iic 2uart tssop20 stc8f2k16s2 1.1yuan
|
|||
|
|||
|
|||
|
|||
#define D_version_h 0x37 |
|||
#define D_version_L 0x38 |
|||
|
|||
|
|||
#define TYPE_MCU TYPE_MCU_STC |
|||
#define TYPE_IDE TYPE_IDE_KEIL |
|||
|
|||
#include <stdio.h> |
|||
#include <string.h> |
|||
#include <intrins.h> |
|||
|
|||
#include "../cpu/STC_stc8a8k.h" |
|||
|
|||
#if 0//// 烧写配置
|
|||
. 内部IRC振荡器的频率: 22.128MHz |
|||
. 掉电唤醒定时器的频率: 35.575KHz |
|||
. 振荡器放大增益使能 |
|||
. P3.2和P3.3与下次下载无关 |
|||
. 上电复位时增加额外的复位延时 |
|||
. 复位引脚用作普通I/O口 |
|||
. 检测到低压时不复位,而产生低压中断 |
|||
. 低压检测门槛电压 : 2.20 V |
|||
. 上电复位时,硬件不启动内部看门狗 |
|||
. 上电自动启动内部看门狗时的预分频数为 : 256 |
|||
. 空闲状态时看门狗定时器停止计数 |
|||
. 启动看门狗后,软件可以修改分频数,但不能关闭看门狗 |
|||
. 下次下载用户程序时,将用户EEPROM区一并擦除 |
|||
. 下次下载用户程序时,没有相关的端口控制485 |
|||
. 下次下载时不需要校验下载口令 |
|||
. TXD脚直通输出RXD脚的电平 |
|||
. 芯片复位后,TXD脚为强推挽输出 |
|||
. 芯片复位后,P2.0输出高电平 |
|||
. 内部参考电压: 1341 mV (参考范围: 1270~1410mV) |
|||
. 内部安排测试时间: 2018年1月13日 |
|||
|
|||
. 芯片出厂序列号 : F64181C6219784 |
|||
单片机型号: STC8F2K08S2 |
|||
固件版本号: 7.3.10U |
|||
|
|||
. 用户设定频率: 22.118MHz |
|||
. 调节后的频率: 22.128MHz |
|||
. 频率调节误差: 0.043% |
|||
|
|||
|
|||
操作成功 !(2019-02-24 18:16:24) |
|||
|
|||
该单片机的功能: 2.0-5v 8kflash 2kram DPTR EEPROM 4K |
|||
SPI IIC T0-T4 5个定时器 掉电唤醒专用定时器 比较器 内部电压检测中断 看门狗 tssop20 1.2元人民币 |
|||
#endif |
|||
|
|||
#include "../cpu/c51_macro.h" |
|||
#define D_MCLKO_DIV2 2 |
|||
#define D_MCLKO_DIV4 4 |
|||
#define D_MCLKO_DIV8 6 |
|||
#define D_MCLKO_DIV16 8 |
|||
#define D_MCLKO_DIV32 10 |
|||
#define D_MCLKO_DIV64 12 |
|||
|
|||
#define D_CPUfamily_type D_CPUfamily_8bits |
|||
|
|||
#define D_uart0_BRT BRT_115200 |
|||
#define D_uart0_SBIT SBIT_1 |
|||
#ifdef D_debug115200 |
|||
#if 0 |
|||
#define L2_task_L0_uart0_uc(X) L0_uart0_uc(X)///
|
|||
#define GC032a_L0_uart0_uc(x) L0_uart0_uc(x)//
|
|||
#else |
|||
|
|||
#define L2_task_L0_uart0_uc(X) L0_uart0_uc(X)//
|
|||
#define GC032a_L0_uart0_uc(x) L0_uart0_uc(x)//
|
|||
#endif |
|||
|
|||
#else |
|||
#define L2_task_L0_uart0_uc(x) //L0_uart0_uc_debug(x)///////
|
|||
#define L2_task_L0_uart0_uchex(x) // L0_uart0_uchex(x)/////
|
|||
|
|||
|
|||
#define GC032a_L0_uart0_uc(x) //L0_uart0_uc_debug(x)/////
|
|||
#define GC032a_L0_uart0_uchex(x) //L0_uart0_uchex(x)////
|
|||
|
|||
|
|||
#define GC032a_L0_uart0_sendArray(x,Y) //L0_uart0_uchex(Y)//
|
|||
#define GC032a_L0_uart0_us(x) //L0_uart0_us(x)*/
|
|||
|
|||
#endif |
|||
///#define D_sys_MainFre MainFre_16M2
|
|||
#define D_sys_MainFre MainFre_11M |
|||
///#define D_sys_MainFre MainFre_22M
|
|||
|
|||
#if(MainFre_5M == D_sys_MainFre) |
|||
|
|||
#define D_Cdelay_200us 20 |
|||
#define D_Cdelay_1us 1 ////while p21翻转时测定 500k 2us 一个指令
|
|||
#elif(MainFre_22M == D_sys_MainFre) |
|||
|
|||
#define D_Cdelay_200us 10 |
|||
#define D_Cdelay_1us 10 ////while p21翻转时测定 500k 2us 一个指令
|
|||
#define D_Cdelay_1ms 36// 500 14ms 360--10ms
|
|||
#define D_Cdelay_5ms 180// 500 14ms 360--10ms
|
|||
#define D_Cdelay_15ms 900 |
|||
#define D_Cdelay_30ms 2400 |
|||
|
|||
#define L0_delay_1us() Lc_delay_nop(2) // 5个nop() 100ns 50个nop() 1us (20)=10us (2)1.5us
|
|||
#define L0_delay_10us() Lc_delay_nop(20) // 5个nop() 100ns 50个nop() 1us (20)=10us (2)1.5us
|
|||
|
|||
|
|||
|
|||
// 0x01/#define D_MCLKO_set D_MCLKO_DIV16 //1.389MHz/800ns@MCU.22MHz-
|
|||
#define D_MCLKO_set D_MCLKO_DIV8 ////2.778MHz/400ns@MCU.22MHz-
|
|||
///#define D_MCLKO_set D_MCLKO_DIV4 ////5.556MHz/ @MCU.22MHz-
|
|||
///#define D_MCLKO_set D_MCLKO_DIV2 ////5.556MHz/ @MCU.22MHz-
|
|||
#define D_0xfa 0x33 |
|||
//#define D_0xfa 0x11
|
|||
|
|||
/*******************
|
|||
#define D_0xf7 0x01 |
|||
#define D_0xf8 0x02 |
|||
|
|||
#define D_P00x46 0x26////pclk /////cccc201805 hs low polarity
|
|||
#define D_P00x4c 0x00 |
|||
#define D_P00x4d 0x04 |
|||
#define D_P00x43 0x10 ///EABLE CrCb fixed en 02
|
|||
#define D_P00x4a 0x83 ///div_gate+clk_en 82
|
|||
|
|||
#define D_P00xda 0xff /// Cr fixed
|
|||
#define D_P00xdb 0xff /// Cb fixed
|
|||
|
|||
#define D_0xfa 0x22 //00000000000000
|
|||
|
|||
|
|||
P0:0x4d Debug_mode3 8 0x04 RW |
|||
[7:4] test_image_fix_value |
|||
|
|||
[3] fix_value_mode |
|||
[2] remove_ff_mode |
|||
[1] subsample extend opclk disable when SPI |
|||
[0] clk2x_bypass |
|||
*******************/ |
|||
|
|||
#elif(MainFre_27M == D_sys_MainFre) |
|||
|
|||
#define D_Cdelay_200us 20 |
|||
#define D_Cdelay_1us 1 ////while p21翻转时测定 500k 2us 一个指令
|
|||
|
|||
#else ///MainFre_11M
|
|||
|
|||
#define D_Cdelay_200us 20 |
|||
#define D_Cdelay_1us 1 |
|||
|
|||
#define D_Cdelay_1ms 36//
|
|||
#define D_Cdelay_5ms 180//
|
|||
#define D_Cdelay_15ms 900 |
|||
#define D_Cdelay_30ms 2400 |
|||
#if 0 |
|||
#define L0_delay_1us() Lc_delay_nop(5) // 5个nop() 100ns 50个nop() 1us (20)=10us (2)1.5us
|
|||
#define L0_delay_10us() Lc_delay_nop(40) // 5个nop() 100ns 50个nop() 1us (20)=10us (2)1.5us
|
|||
#define L0_delay_40us() Lc_delay_nop(150) // 5个nop() 100ns 50个nop() 1us (20)=10us (2)1.5us
|
|||
#else |
|||
#define L0_delay_1us() Lc_delay_nop(0) // 5个nop() 100ns 50个nop() 1us (20)=10us (2)1.5us
|
|||
#define L0_delay_10us() Lc_delay_nop(4) // 5个nop() 100ns 50个nop() 1us (20)=10us (2)1.5us //绀烘尝鍣ㄦ祴璇曠粨鏋�
|
|||
#define L0_delay_40us() Lc_delay_nop(18) // 5个nop() 100ns 50个nop() 1us (20)=10us (2)1.5us
|
|||
#endif |
|||
|
|||
#endif//D_sys_MainFre)
|
|||
/*******>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|||
1, |
|||
串口1选择定时器2为波特率发生器 |
|||
AUXR &= 0xFB; //定时器2时钟为Fosc/12,即12T,
|
|||
2, timer0 为task使用 |
|||
L1_tick_tick |
|||
3, |
|||
|
|||
///<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<****/
|
|||
|
|||
#define D_IO_LED1_OFF() D_P35_OFF() |
|||
#define D_IO_LED2_OFF() D_P34_OFF() |
|||
#define D_IO_485_RE_OFF() D_P33_OFF() |
|||
#define D_IO_485_DE_OFF() D_P32_OFF() |
|||
#define D_IO_LED1_INIT() ///D_P35_INIT()
|
|||
#define D_IO_LED2_INIT() ///D_P34_INIT()
|
|||
#define D_IO_485_RE_INIT() ///D_P33_INIT()
|
|||
#define D_IO_485_DE_INIT() ///D_P32_INIT()
|
|||
#define D_IO_LED1_ON() D_P35_ON() |
|||
#define D_IO_LED2_ON() D_P34_ON() |
|||
#define D_IO_485_RE_ON() D_P33_ON() |
|||
#define D_IO_485_DE_ON() D_P32_ON() |
|||
|
|||
|
|||
////////////////////////////////sim iic config
|
|||
//根据sch的定义
|
|||
#define L0_IIC_SIM_INIT() BITN_0(P3M1,5);BITN_0(P3M0,5);\ |
|||
BITN_0(P3M1,4);BITN_0(P3M0,4); |
|||
///stc独有10 高阻
|
|||
#define L0_IIC_SIM_close() BITN_1(P3M1,5);BITN_0(P3M0,5);\ |
|||
BITN_1(P3M1,4);BITN_0(P3M0,4); |
|||
|
|||
#if 10 |
|||
#define L0_SDA_ON() D_P34_ON() |
|||
#define L0_SDA_OFF() D_P34_OFF() |
|||
#define L0_SDA_AT() D_P34_AT() |
|||
#define L0_SCL_ON() D_P35_ON() |
|||
#define L0_SCL_OFF() D_P35_OFF() |
|||
#else |
|||
|
|||
#define L0_SDA_ON() //D_P34_ON()
|
|||
#define L0_SDA_OFF() //D_P34_OFF()
|
|||
#define L0_SDA_AT() //D_P34_AT()
|
|||
#define L0_SCL_ON() //D_P35_ON()
|
|||
#define L0_SCL_OFF() //D_P35_OFF()
|
|||
|
|||
#endif |
|||
|
|||
|
|||
#if(BRT_4800 == D_uart0_BRT) |
|||
#define D_txd4_wakeup() P31 = 1 // >750us
|
|||
#define D_txd4_low() P31 = 0 |
|||
////为适应433 模块的功耗问题
|
|||
////debug的时候切记 此处会对串口造成影响 low有效的情况下其他的发送不会好使,除非事先wakeup
|
|||
|
|||
|
|||
#else |
|||
#define D_txd4_wakeup() //P31 = 1 // >750us
|
|||
#define D_txd4_low() //P31 = 0
|
|||
|
|||
|
|||
#endif |
|||
|
|||
|
|||
#define DR_who_wakeup22 i2ctxd |
|||
|
|||
|
|||
///// DR: Define Register DRB:bit of Define Register
|
|||
#define DR_isr_times SADDR |
|||
|
|||
#define DR_who_wakeup SADEN |
|||
#define DRB_who_wakeup_timer0 BITN0 |
|||
#define DRB_who_wakeup_action BITN1 |
|||
#define DRB_who_wakeup_voice BITN2 |
|||
#ifdef doc342343 |
|||
BITN_1(DR_who_wakeup, DRB_who_wakeup_timer0); |
|||
BITN_0(DR_who_wakeup, DRB_who_wakeup_timer0); |
|||
|
|||
if(BITN_G(DR_who_wakeup, DRB_who_wakeup_timer0)) |
|||
{ |
|||
|
|||
} |
|||
#endif |
|||
|
|||
|
|||
|
|||
|
|||
#elif(TYPE_UASER_BOARD == TYPE_BOARD_TI26_MT01_M178)///-------TYPE_UASER_BOARD----------------TYPE_UASER_BOARD----------
|
|||
#define TYPE_MCU TYPE_MCU_STC |
|||
#define TYPE_IDE TYPE_IDE_KEIL |
|||
|
|||
#include <stdio.h> |
|||
#include <string.h> |
|||
#include <intrins.h> |
|||
|
|||
#include "../cpu/STC_stc8a8k.h" |
|||
|
|||
#define D_CPUfamily_type D_CPUfamily_8bits |
|||
|
|||
#elif(TYPE_UASER_BOARD == TYPE_BOARD_SMMM_MB_VH032_0E) |
|||
|
|||
#endif |
|||
|
|||
#endif//_BSP_CONFIG_H
|
|||
/*********************************end file*********************************************/ |
|||
|
|||
|
@ -0,0 +1,202 @@ |
|||
////////////////////////////////////////////////////////////////////////////
|
|||
///@copyright Copyright (c) 2017, 传控科技 All rights reserved.
|
|||
///-------------------------------------------------------------------------
|
|||
/// @file hard_config.h
|
|||
/// @brief hard config include
|
|||
/// @info FILE FOR HARDWARE SETUP AND SOFTWARE SETUP///FOR EXAMPLE: BAORD ,MCU,IDE
|
|||
/// @info YOU CAN CHANGE OR ADD THE DEFINE IF YOU NEED
|
|||
/// @info 整个嵌入式项目的入口 首先是确认电路板 然后确认cpu 芯片型号 然后确认编译器 之后是软件框架 最后是应用程序
|
|||
/// @info bsp_CONFIG 为其他头文件的始祖 TYPE_BOARD_xx
|
|||
///-------------------------------------------------------------------------
|
|||
/// @version 1.1
|
|||
/// @author CC
|
|||
/// @date 20180308
|
|||
/// @note
|
|||
/// @version 1.6
|
|||
/// @author CC
|
|||
/// @date 20190714
|
|||
/// @note add TTSS_tick TYPE
|
|||
/// @version 1.7
|
|||
/// @author CC
|
|||
/// @date 20191226
|
|||
/// @note gsensor + 485
|
|||
|
|||
|
|||
//////////////////////////////////////////////////////////////////////////////
|
|||
|
|||
|
|||
//////////////////////////////////////////////////////////////////////////
|
|||
#ifndef _BSP_CONFIG0_H |
|||
#define _BSP_CONFIG0_H |
|||
#include <INTRINS.H> |
|||
|
|||
#include "../clib/Type.h" |
|||
#include "../clib/bit.h" |
|||
#include "../ctask/task.h" |
|||
|
|||
#include "../clib/clib.h" |
|||
////#define D_debug115200///
|
|||
|
|||
|
|||
//#define D_cameralIndex 0
|
|||
//#define D_cameralIndex 1
|
|||
//#define D_cameralIndex 2
|
|||
#define D_cameralIndex 3 |
|||
//#define D_cameralIndex 4
|
|||
//#define D_cameralIndex 5
|
|||
|
|||
|
|||
#define SBIT_1 1 //1 stop bit
|
|||
#define SBIT_2 2 //2 stop bit
|
|||
|
|||
|
|||
#define BRT_115200 115200 |
|||
#define BRT_19200 19200 |
|||
#define BRT_9600 9600 |
|||
#define BRT_4800 4800 |
|||
#define BRT_SIM 900 |
|||
#define MainFre_5M 0 |
|||
#define MainFre_11M 1 |
|||
#define MainFre_22M 2 |
|||
#define MainFre_27M 3 |
|||
#define MainFre_24M 4 |
|||
#define MainFre_33M 5 |
|||
#if 0 |
|||
|
|||
#define D_leda_OFF(); D_P35_OFF(); |
|||
#define D_leda_ON(); D_P35_ON(); |
|||
#define D_leda_REV(); D_P35_REV(); |
|||
#define D_ledb_OFF(); D_P34_OFF(); |
|||
#define D_ledb_ON(); D_P34_ON(); |
|||
#define D_ledb_REV(); D_P34_REV(); |
|||
|
|||
#else |
|||
#define D_leda_OFF(); ///D_P35_OFF();
|
|||
#define D_leda_ON(); ///D_P35_ON();
|
|||
#define D_leda_REV(); ///D_P35_REV();
|
|||
#define D_ledb_OFF(); ///D_P34_OFF();
|
|||
#define D_ledb_ON(); ///D_P34_ON();
|
|||
#define D_ledb_REV(); ///D_P34_REV();
|
|||
|
|||
#endif |
|||
|
|||
|
|||
|
|||
#if 0 |
|||
#define D_debug_sim |
|||
#endif |
|||
//#define D_iic_inspect
|
|||
#define D_open_save_f |
|||
|
|||
//>>>>>>>>>>>>>>>>>>>>>>.BORAD TYPE
|
|||
#define TYPE_BOARD_hhnew 16 |
|||
#define TYPE_BOARD_st_sleep04_01 4 |
|||
#define TYPE_BOARD_st_sleep03 5 |
|||
#define TYPE_BOARD_SMMM_MB_VH032_0E 6 |
|||
#define TYPE_BOARD_LPC17xx_ 8 |
|||
#define TYPE_BOARD_STM32F_103ZET6_READBULL 1036 |
|||
#define TYPE_BOARD_hh_CC_MD_VH05_anyriny_simple_m51 0x0551 |
|||
#define TYPE_BOARD_hh_CC_MD_VH06_asMain_m6a7 0x6a7 |
|||
#define TYPE_BOARD_TI26_MT01_M178 0x178 //会议计时器版v TI26_MT01-M178
|
|||
#define TYPE_BOARD_stc5as32_WIFIBV01 532 |
|||
#define TYPE_BOARD_SHC16LAXXQN32 1632 //SHC16LAXXQN32
|
|||
|
|||
#define TYPE_BOARD_paper6133_m0a6 0xa6 //纸张传感器
|
|||
#define TYPE_BOARD_paper_main_m10 0x10 //纸张传感器2 CC_SE_paper_main_m10_smt01.sch
|
|||
#define ccSensor_CG_V02_m08_debug 0x0208 //CG传感器2
|
|||
#define TYPE_BOARD_cc_Light_Speed0B 0x11b //LR光电感器2
|
|||
|
|||
#define TYPE_BOARD_cc_G0A03 0x123 //倾角感器2
|
|||
#define ccSensor_WS_ps5ws 0x0258 ///称重传感器
|
|||
|
|||
|
|||
/*************************************
|
|||
芯片型号 : IRC15W207S |
|||
HSY037.XA |
|||
关于此芯片的重要说明: |
|||
有定时器0和定时器2 (注意:无定时器1) |
|||
有比较器 (可当作一路ADC使用) |
|||
************************/ |
|||
///cc_gsm_paper6133_m0a6_debug01
|
|||
//STEP 1 <<<<<<<<<<<<<<<<<<<<<<<<<<<.BORAD TYPE
|
|||
|
|||
|
|||
// BORAD,
|
|||
// MCU:SHC6601
|
|||
// IDE :KEIL
|
|||
//>>>>>>>>>>>>>>>>>>>>>>mcu TYPE
|
|||
#define TYPE_MCU_SHC6601 66 |
|||
#define TYPE_MCU_STC 51 |
|||
#define TYPE_MCU_LPC17xx 3217 |
|||
#define TYPE_MCU_STM32 3232 |
|||
|
|||
#define D_CPUfamily_8bits 8 |
|||
#define D_CPUfamily_16bits 16 |
|||
#define D_CPUfamily_32bits 32 |
|||
//<<<<<<<<<<<<<<<<<<<<<<mcu TYPE
|
|||
#define TYPE_MCU_STC_stc15x201 201 |
|||
#define TYPE_MCU_STC_stc8f1k 1 |
|||
|
|||
|
|||
#define TYPE_MCU_stc_io TYPE_MCU_STC_stc15x201 |
|||
|
|||
|
|||
|
|||
//>>>>>>>>>>>>>>>>>>>>>>IDE TYPE
|
|||
|
|||
#define TYPE_IDE_KEIL 1 |
|||
#define TYPE_IDE_MDK 2 |
|||
#define TYPE_IDE_IAR 3 |
|||
|
|||
//<<<<<<<<<<<<<<<<<<<<<<IDE TYPE
|
|||
|
|||
//>>>>>>>>>>>>>>>>>>>>>>G-SENSOR TYPE
|
|||
|
|||
#define TYPE_ASENSOR_ADXL362 362 |
|||
#define TYPE_ASENSOR_MSA300 362 |
|||
#define TYPE_ASENSOR TYPE_ASENSOR_MSA300 |
|||
//<<<<<<<<<<<<<<<<<<<<<<G-SENSOR TYPE
|
|||
|
|||
//>>>>>>>>>>>>>>>>>>>>>>TTSS_tick TYPE
|
|||
|
|||
#define D_TTSS_tick_5ms 5 |
|||
#define D_TTSS_tick_10ms 10 |
|||
#define D_TTSS_tick_25ms 25 |
|||
|
|||
|
|||
//<<<<<<<<<<<<<<<<<<<<<<TTSS_tick TYPE
|
|||
|
|||
|
|||
//STEP 1 TYPE_UASER_BOARD SELECT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|||
|
|||
|
|||
//#define TYPE_UASER_BOARD TYPE_BOARD_SMMM_MB_VH032_0E
|
|||
//#define TYPE_UASER_BOARD TYPE_BOARD_stc90c516rd
|
|||
//#define TYPE_UASER_BOARD TYPE_BOARD_hh_CC_MD_VH06_asMain_m6a7
|
|||
//#define TYPE_UASER_BOARD TYPE_BOARD_stc5as32_WIFIBV01
|
|||
//#define TYPE_UASER_BOARD TYPE_BOARD_hhnew
|
|||
//STEP 1 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
|||
//>>>>>>>>>>>>>>>>>>>>>>TTSS_tick TYPE
|
|||
|
|||
#define D_TTSS_tick_5ms 5 |
|||
#define D_TTSS_tick_10ms 10 |
|||
#define D_TTSS_tick_25ms 25 |
|||
|
|||
|
|||
//<<<<<<<<<<<<<<<<<<<<<<TTSS_tick TYPE
|
|||
//// 485 等多机通讯使用
|
|||
#define ADD_Master 0 |
|||
#define ADD_slave1 1 |
|||
#define ADD_slave2 2 |
|||
#define ADD_slave3 3 |
|||
#define ADD_slave4 4 |
|||
#define ADD_slave5 5 |
|||
#define ADD_slave6 6 |
|||
|
|||
#define ADD_slaveN 0xee ///结束
|
|||
|
|||
|
|||
#endif//_BSP_CONFIG0_H
|
|||
/*********************************end file*********************************************/ |
|||
|
|||
|
@ -0,0 +1,405 @@ |
|||
//////////////////////////////////////////////////////////////////////////
|
|||
/// COPYRIGHT NOTICE
|
|||
/// Copyright (c) 2015, 传控科技
|
|||
/// All rights reserved.
|
|||
///
|
|||
/// @file main.c
|
|||
/// @brief main app
|
|||
///
|
|||
///(本文件实现的功能的详述)
|
|||
///
|
|||
/// @version 1.1 CCsens technology
|
|||
/// @author CC
|
|||
/// @date 20150102
|
|||
///
|
|||
///
|
|||
/// 修订说明:最初版本
|
|||
/// Modified by:
|
|||
/// Modified date:
|
|||
/// Version:
|
|||
/// Descriptions:
|
|||
//////////////////////////////////////////////////////////////////////////
|
|||
|
|||
|
|||
#ifndef __BIT_H__ |
|||
#define __BIT_H__ |
|||
|
|||
#define cSetb0 0x01 |
|||
#define cSetb1 0x02 |
|||
#define cSetb2 0x04 |
|||
#define cSetb3 0x08 |
|||
#define cSetb4 0x10 |
|||
#define cSetb5 0x20 |
|||
#define cSetb6 0x40 |
|||
#define cSetb7 0x80 |
|||
|
|||
#define cClrb0 0xfe |
|||
#define cClrb1 0xfd |
|||
#define cClrb2 0xfb |
|||
#define cClrb3 0xf7 |
|||
#define cClrb4 0xef |
|||
#define cClrb5 0xdf |
|||
#define cClrb6 0xbf |
|||
#define cClrb7 0x7f |
|||
|
|||
#define cTestb0 0x01 |
|||
#define cTestb1 0x02 |
|||
#define cTestb2 0x04 |
|||
#define cTestb3 0x08 |
|||
#define cTestb4 0x10 |
|||
#define cTestb5 0x20 |
|||
#define cTestb6 0x40 |
|||
#define cTestb7 0x80 |
|||
|
|||
#define true 1 |
|||
#define false 0 |
|||
|
|||
#define B0000_0000 0x00 |
|||
#define B0000_0001 0x01 |
|||
#define B0000_0010 0x02 |
|||
#define B0000_0011 0x03 |
|||
#define B0000_0100 0x04 |
|||
#define B0000_0101 0x05 |
|||
#define B0000_0110 0x06 |
|||
#define B0000_0111 0x07 |
|||
#define B0000_1000 0x08 |
|||
#define B0000_1001 0x09 |
|||
#define B0000_1010 0x0A |
|||
#define B0000_1011 0x0B |
|||
#define B0000_1100 0x0C |
|||
#define B0000_1101 0x0D |
|||
#define B0000_1110 0x0E |
|||
#define B0000_1111 0x0F |
|||
|
|||
#define B0001_0000 0x10 |
|||
#define B0001_0001 0x11 |
|||
#define B0001_0010 0x12 |
|||
#define B0001_0011 0x13 |
|||
#define B0001_0100 0x14 |
|||
#define B0001_0101 0x15 |
|||
#define B0001_0110 0x16 |
|||
#define B0001_0111 0x17 |
|||
#define B0001_1000 0x18 |
|||
#define B0001_1001 0x19 |
|||
#define B0001_1010 0x1A |
|||
#define B0001_1011 0x1B |
|||
#define B0001_1100 0x1C |
|||
#define B0001_1101 0x1D |
|||
#define B0001_1110 0x1E |
|||
#define B0001_1111 0x1F |
|||
|
|||
#define B0010_0000 0x20 |
|||
#define B0010_0001 0x21 |
|||
#define B0010_0010 0x22 |
|||
#define B0010_0011 0x23 |
|||
#define B0010_0100 0x24 |
|||
#define B0010_0101 0x25 |
|||
#define B0010_0110 0x26 |
|||
#define B0010_0111 0x27 |
|||
#define B0010_1000 0x28 |
|||
#define B0010_1001 0x29 |
|||
#define B0010_1010 0x2A |
|||
#define B0010_1011 0x2B |
|||
#define B0010_1100 0x2C |
|||
#define B0010_1101 0x2D |
|||
#define B0010_1110 0x2E |
|||
#define B0010_1111 0x2F |
|||
|
|||
#define B0011_0000 0x30 |
|||
#define B0011_0001 0x31 |
|||
#define B0011_0010 0x32 |
|||
#define B0011_0011 0x33 |
|||
#define B0011_0100 0x34 |
|||
#define B0011_0101 0x35 |
|||
#define B0011_0110 0x36 |
|||
#define B0011_0111 0x37 |
|||
#define B0011_1000 0x38 |
|||
#define B0011_1001 0x39 |
|||
#define B0011_1010 0x3A |
|||
#define B0011_1011 0x3B |
|||
#define B0011_1100 0x3C |
|||
#define B0011_1101 0x3D |
|||
#define B0011_1110 0x3E |
|||
#define B0011_1111 0x3F |
|||
|
|||
#define B0100_0000 0x40 |
|||
#define B0100_0001 0x41 |
|||
#define B0100_0010 0x42 |
|||
#define B0100_0011 0x43 |
|||
#define B0100_0100 0x44 |
|||
#define B0100_0101 0x45 |
|||
#define B0100_0110 0x46 |
|||
#define B0100_0111 0x47 |
|||
#define B0100_1000 0x48 |
|||
#define B0100_1001 0x49 |
|||
#define B0100_1010 0x4A |
|||
#define B0100_1011 0x4B |
|||
#define B0100_1100 0x4C |
|||
#define B0100_1101 0x4D |
|||
#define B0100_1110 0x4E |
|||
#define B0100_1111 0x4F |
|||
|
|||
#define B0101_0000 0x50 |
|||
#define B0101_0001 0x51 |
|||
#define B0101_0010 0x52 |
|||
#define B0101_0011 0x53 |
|||
#define B0101_0100 0x54 |
|||
#define B0101_0101 0x55 |
|||
#define B0101_0110 0x56 |
|||
#define B0101_0111 0x57 |
|||
#define B0101_1000 0x58 |
|||
#define B0101_1001 0x59 |
|||
#define B0101_1010 0x5A |
|||
#define B0101_1011 0x5B |
|||
#define B0101_1100 0x5C |
|||
#define B0101_1101 0x5D |
|||
#define B0101_1110 0x5E |
|||
#define B0101_1111 0x5F |
|||
|
|||
#define B0110_0000 0x60 |
|||
#define B0110_0001 0x61 |
|||
#define B0110_0010 0x62 |
|||
#define B0110_0011 0x63 |
|||
#define B0110_0100 0x64 |
|||
#define B0110_0101 0x65 |
|||
#define B0110_0110 0x66 |
|||
#define B0110_0111 0x67 |
|||
#define B0110_1000 0x68 |
|||
#define B0110_1001 0x69 |
|||
#define B0110_1010 0x6A |
|||
#define B0110_1011 0x6B |
|||
#define B0110_1100 0x6C |
|||
#define B0110_1101 0x6D |
|||
#define B0110_1110 0x6E |
|||
#define B0110_1111 0x6F |
|||
|
|||
#define B0111_0000 0x70 |
|||
#define B0111_0001 0x71 |
|||
#define B0111_0010 0x72 |
|||
#define B0111_0011 0x73 |
|||
#define B0111_0100 0x74 |
|||
#define B0111_0101 0x75 |
|||
#define B0111_0110 0x76 |
|||
#define B0111_0111 0x77 |
|||
#define B0111_1000 0x78 |
|||
#define B0111_1001 0x79 |
|||
#define B0111_1010 0x7A |
|||
#define B0111_1011 0x7B |
|||
#define B0111_1100 0x7C |
|||
#define B0111_1101 0x7D |
|||
#define B0111_1110 0x7E |
|||
#define B0111_1111 0x7F |
|||
|
|||
#define B1000_0000 0x80 |
|||
#define B1000_0001 0x81 |
|||
#define B1000_0010 0x82 |
|||
#define B1000_0011 0x83 |
|||
#define B1000_0100 0x84 |
|||
#define B1000_0101 0x85 |
|||
#define B1000_0110 0x86 |
|||
#define B1000_0111 0x87 |
|||
#define B1000_1000 0x88 |
|||
#define B1000_1001 0x89 |
|||
#define B1000_1010 0x8A |
|||
#define B1000_1011 0x8B |
|||
#define B1000_1100 0x8C |
|||
#define B1000_1101 0x8D |
|||
#define B1000_1110 0x8E |
|||
#define B1000_1111 0x8F |
|||
|
|||
#define B1001_0000 0x90 |
|||
#define B1001_0001 0x91 |
|||
#define B1001_0010 0x92 |
|||
#define B1001_0011 0x93 |
|||
#define B1001_0100 0x94 |
|||
#define B1001_0101 0x95 |
|||
#define B1001_0110 0x96 |
|||
#define B1001_0111 0x97 |
|||
#define B1001_1000 0x98 |
|||
#define B1001_1001 0x99 |
|||
#define B1001_1010 0x9A |
|||
#define B1001_1011 0x9B |
|||
#define B1001_1100 0x9C |
|||
#define B1001_1101 0x9D |
|||
#define B1001_1110 0x9E |
|||
#define B1001_1111 0x9F |
|||
|
|||
#define B1010_0000 0xA0 |
|||
#define B1010_0001 0xA1 |
|||
#define B1010_0010 0xA2 |
|||
#define B1010_0011 0xA3 |
|||
#define B1010_0100 0xA4 |
|||
#define B1010_0101 0xA5 |
|||
#define B1010_0110 0xA6 |
|||
#define B1010_0111 0xA7 |
|||
#define B1010_1000 0xA8 |
|||
#define B1010_1001 0xA9 |
|||
#define B1010_1010 0xAA |
|||
#define B1010_1011 0xAB |
|||
#define B1010_1100 0xAC |
|||
#define B1010_1101 0xAD |
|||
#define B1010_1110 0xAE |
|||
#define B1010_1111 0xAF |
|||
|
|||
#define B1011_0000 0xB0 |
|||
#define B1011_0001 0xB1 |
|||
#define B1011_0010 0xB2 |
|||
#define B1011_0011 0xB3 |
|||
#define B1011_0100 0xB4 |
|||
#define B1011_0101 0xB5 |
|||
#define B1011_0110 0xB6 |
|||
#define B1011_0111 0xB7 |
|||
#define B1011_1000 0xB8 |
|||
#define B1011_1001 0xB9 |
|||
#define B1011_1010 0xBA |
|||
#define B1011_1011 0xBB |
|||
#define B1011_1100 0xBC |
|||
#define B1011_1101 0xBD |
|||
#define B1011_1110 0xBE |
|||
#define B1011_1111 0xBF |
|||
|
|||
#define B1100_0000 0xC0 |
|||
#define B1100_0001 0xC1 |
|||
#define B1100_0010 0xC2 |
|||
#define B1100_0011 0xC3 |
|||
#define B1100_0100 0xC4 |
|||
#define B1100_0101 0xC5 |
|||
#define B1100_0110 0xC6 |
|||
#define B1100_0111 0xC7 |
|||
#define B1100_1000 0xC8 |
|||
#define B1100_1001 0xC9 |
|||
#define B1100_1010 0xCA |
|||
#define B1100_1011 0xCB |
|||
#define B1100_1100 0xCC |
|||
#define B1100_1101 0xCD |
|||
#define B1100_1110 0xCE |
|||
#define B1100_1111 0xCF |
|||
|
|||
#define B1101_0000 0xD0 |
|||
#define B1101_0001 0xD1 |
|||
#define B1101_0010 0xD2 |
|||
#define B1101_0011 0xD3 |
|||
#define B1101_0100 0xD4 |
|||
#define B1101_0101 0xD5 |
|||
#define B1101_0110 0xD6 |
|||
#define B1101_0111 0xD7 |
|||
#define B1101_1000 0xD8 |
|||
#define B1101_1001 0xD9 |
|||
#define B1101_1010 0xDA |
|||
#define B1101_1011 0xDB |
|||
#define B1101_1100 0xDC |
|||
#define B1101_1101 0xDD |
|||
#define B1101_1110 0xDE |
|||
#define B1101_1111 0xDF |
|||
|
|||
#define B1110_0000 0xE0 |
|||
#define B1110_0001 0xE1 |
|||
#define B1110_0010 0xE2 |
|||
#define B1110_0011 0xE3 |
|||
#define B1110_0100 0xE4 |
|||
#define B1110_0101 0xE5 |
|||
#define B1110_0110 0xE6 |
|||
#define B1110_0111 0xE7 |
|||
#define B1110_1000 0xE8 |
|||
#define B1110_1001 0xE9 |
|||
#define B1110_1010 0xEA |
|||
#define B1110_1011 0xEB |
|||
#define B1110_1100 0xEC |
|||
#define B1110_1101 0xED |
|||
#define B1110_1110 0xEE |
|||
#define B1110_1111 0xEF |
|||
|
|||
#define B1111_0000 0xF0 |
|||
#define B1111_0001 0xF1 |
|||
#define B1111_0010 0xF2 |
|||
#define B1111_0011 0xF3 |
|||
#define B1111_0100 0xF4 |
|||
#define B1111_0101 0xF5 |
|||
#define B1111_0110 0xF6 |
|||
#define B1111_0111 0xF7 |
|||
#define B1111_1000 0xF8 |
|||
#define B1111_1001 0xF9 |
|||
#define B1111_1010 0xFA |
|||
#define B1111_1011 0xFB |
|||
#define B1111_1100 0xFC |
|||
#define B1111_1101 0xFD |
|||
#define B1111_1110 0xFE |
|||
#define B1111_1111 0xFF |
|||
/*************************************************
|
|||
标准位定义 |
|||
*************************************************/ |
|||
#define BIT0 0 |
|||
#define BIT1 1 |
|||
#define BIT2 2 |
|||
#define BIT3 3 |
|||
#define BIT4 4 |
|||
#define BIT5 5 |
|||
#define BIT6 6 |
|||
#define BIT7 7 |
|||
|
|||
///--------------------------------------
|
|||
#define BITN0 0X01 |
|||
#define BITN1 0X02 |
|||
#define BITN2 0X04 |
|||
#define BITN3 0X08 |
|||
#define BITN4 0X10 |
|||
#define BITN5 0X20 |
|||
#define BITN6 0X40 |
|||
#define BITN7 0X80 |
|||
|
|||
/// BITNx = { 0x40 0x80}
|
|||
#define BITN_1(X,BITNx) (X)|= (BITNx) |
|||
#define BITN_0(X,BITNx) (X)&=~(BITNx) |
|||
#define BITN_G(X,BITNx) ((X)&(BITNx)) |
|||
//BITN_1(reg,BITN0)
|
|||
#define BITS_1(X,BITx) (X)|= (BITx) |
|||
#define BITS_0(X,BITx) (X)&=~(BITx) |
|||
|
|||
|
|||
|
|||
#define BITC_1 0X01 |
|||
#define BITC_2 0X03 |
|||
#define BITC_3 0X07 |
|||
#define BITC_4 0X0F |
|||
#define BITC_5 0X1F |
|||
#define BITC_6 0X3F |
|||
#define BITC_7 0X7F |
|||
#define BITC_8 0XFF |
|||
|
|||
//// 多位配置,一定要配对使用,先清除再设置。
|
|||
/// 对REG的 从BITx开始 清除 N位
|
|||
#define BITS_CLR(REG,BITC_N,BITx) (REG)&= ~((BITC_N)<<(BITx)) |
|||
////对REG的 从BITx开始 放入值,小心溢出 一定要配对使用,先清除再设置。
|
|||
#define BITS_SET(REG,VAL) (REG) |= (VAL) //直接操作 之前必须清零
|
|||
///BITS_CLR(REG,BITC_2,BIT0)/// reg.0 reg.1 两位被清零
|
|||
///BITS_CLR(REG,BITC_3,BIT5)/// reg.5 reg.6 reg.7 3位被清零
|
|||
|
|||
|
|||
#define BITS_SET_SHIFT(REG,VAL,BITx) (REG)|= ((VAL)<<(BITx))///需要移位 兼容一部分程序
|
|||
|
|||
|
|||
|
|||
#if 0 |
|||
|
|||
/// b = {0,1,2,3,4,5,6,7}
|
|||
#define BIT_1(X,b) (X)|= (1<<(b)) |
|||
#define BIT_0(X,b) (X)&=~(1<<(b)) |
|||
#define BIT_G(X,b) ((X)&(1<<(b))) |
|||
#define SETBIT(regVal, bitN) ((regVal) |= (1<<(bitN))) // 置位
|
|||
#define CLRBIT(regVal, bitN) ((regVal) &= ~(1<<(bitN))) // 清位
|
|||
#define GETBIT(regVal, bitN) ((regVal) & (1<<(bitN)) ) // 取位值
|
|||
|
|||
|
|||
// 原来的意思是双位进行移位和赋值 0b0000 0011 // fixme
|
|||
#define BITD_CLR(regVal,D,bitN) (regVal)&=~((D)<<(bitN)) |
|||
#define BITD_SET(regVal,D,bitN) BITD_CLR((regVal),3,(bitN));(regVal)|= ((D)<<(bitN)) |
|||
|
|||
///-----------------------------------
|
|||
|
|||
|
|||
#define IO_OUT_HIGH(PORT, PIN) SETBIT(PORT, PIN) |
|||
#define IO_OUT_LOW(PORT, PIN) CLRBIT(PORT, PIN) |
|||
|
|||
|
|||
#endif |
|||
#endif /* __BIT_H__ */ |
File diff suppressed because it is too large
@ -0,0 +1,112 @@ |
|||
/*****************************************************************************
|
|||
* uart.h: Header file for NXP LPC17xx Family Microprocessors |
|||
* |
|||
* Copyright(C) 2009, NXP Semiconductor |
|||
* All rights reserved. |
|||
* |
|||
* History |
|||
* 2009.05.27 ver 1.00 Prelimnary version, first Release |
|||
* |
|||
******************************************************************************/ |
|||
#ifndef _CLIB_H_ |
|||
#define _CLIB_H_ |
|||
|
|||
|
|||
#include <stdarg.h> |
|||
#include <stdlib.h> |
|||
#include "../clib/type.h" |
|||
//#include "../clib/Clib.h"
|
|||
//#include "../debug/debug_drv.h"
|
|||
//extern char guc_send[128];
|
|||
extern unsigned char code cguHex2Char[16][2]; |
|||
typedef struct |
|||
{ |
|||
vU16 up_point; |
|||
vU16 down_point; |
|||
|
|||
|
|||
}TS_up_down_p_; |
|||
|
|||
extern U8 Lc_Hex2Char(U8 CharStr); |
|||
//extern void Lc_int2str(U32 ui_in,UN_TYPE len,UN_TYPE point,char *d);
|
|||
// input: 123456d
|
|||
// output: '1' '2' '3'....
|
|||
//对应的点阵 为 0123456789. ,最后为空格,专为显示点阵类的数值使用
|
|||
//extern void Lc_int2number(U32 ui_in,UN_TYPE len,UN_TYPE point,char *d);
|
|||
//extern U32 L2_fun_number_show(int i,char str[4]);
|
|||
#if 0 |
|||
|
|||
struct _s_temp_ |
|||
{ |
|||
U8 d[16]; |
|||
|
|||
}; |
|||
|
|||
extern struct _s_temp_ s_temp22; |
|||
extern U8 s_temp[16]; |
|||
|
|||
extern U32 ul2fun2[10]; |
|||
extern void Lc_Byte_cp(BYTE *src,BYTE *dis, int len); |
|||
|
|||
extern void L1_buf22ui(volatile BYTE in[],vU32 *ui_t2,vU32 *ui_t3); |
|||
|
|||
extern void Lc_2ui2buf(vU32 ui_t2,vU32 ui_t3,volatile BYTE out[]); |
|||
extern void Lc_int2str_3(U32 ui_in,char *d); |
|||
extern U32 Lc_abs(vU32 a,vU32 b,vU32 *diff); |
|||
extern void Lc_int2str_4(U32 ui_in,char *d); |
|||
|
|||
extern void Lc_sint2str_3(int i_in,char *d); |
|||
#define Lc_WEI(WEIx,WEIn) (U8)((WEIx/ul2fun2[WEIn])%10); |
|||
#define Lc_eee(WEIn) ul2fun2[WEIn] |
|||
|
|||
|
|||
#endif |
|||
|
|||
extern char *Lc_int2a(vS32 value, char *string, UN_TYPE radix); |
|||
|
|||
extern void Lc_int2D(vS16 value, char *string,char bits); |
|||
|
|||
extern char *strstr(const char *str1, const char *str2); |
|||
extern unsigned char catch_protocol (const char d_src[],char d_protocol[]) ; |
|||
#define Lc_delay_1us() L0_delay_1us() |
|||
|
|||
|
|||
extern void Lc_delay_us(vU16 i); |
|||
extern void Lc_delay_ms(vU16 i); |
|||
extern void Lc_delay_nop(U8 i); |
|||
|
|||
////////////////
|
|||
|
|||
extern void Lc_uc_hex(char ww); |
|||
extern void Lc_us_hex(U16 ww); |
|||
//extern void Lc_print(void (*L0pf_send_uc)(char ww), char *dat,...);
|
|||
extern void Lc_print(char *dat4,...); |
|||
extern void Lc_print_NC(char *dat,...); |
|||
extern void Lc_print_buf(char *dat4,...); |
|||
|
|||
|
|||
extern void L3_us_big(U16 *d); |
|||
extern void L3_ui_big(vU32 *d); |
|||
extern void Lc_buf_copy_uc(U8 *d,const U8 *s,U16 num); |
|||
|
|||
///void L2_line_algo_media(U8 *buf,vU16 len);
|
|||
extern vU8 Lc_U8_media3(vU8 a,vU8 b,vU8 c); |
|||
extern vS32 Lc_S32_media3(vS32 a,vS32 b,vS32 c); |
|||
extern vS32 Lc_S32_media(vS32 val[],S16 num); |
|||
extern void Lc_array_sort(S32 arr[],int n); |
|||
|
|||
/// 0x11 0x22 ---> 0x31 0x31 0x32 0x32 '1' '1' '2' '2'
|
|||
extern void Lc_hex2ascii(U8 *buf,U16 len,U8 *ascii); |
|||
extern void crc16(unsigned char *CRC,void *dat,unsigned int len); |
|||
extern int isBigEndianOrder(void); |
|||
extern U32 ntohl(U32 dat); |
|||
extern U32 htonl(U32 dat); |
|||
extern U16 ntohs(U16 dat); |
|||
extern U16 htons(U16 dat); |
|||
extern U32 Lc_abs(vS32 a,vS32 b); |
|||
extern void Lc_encrypt_id(U8 *enc_dst, U8 *enc_src, U32 enc_key, U8 src_len); |
|||
|
|||
#endif /* end __UART_H */ |
|||
/*****************************************************************************
|
|||
** End Of File |
|||
******************************************************************************/ |
@ -0,0 +1,316 @@ |
|||
//////////////////////////////////////////////////////////////////////////
|
|||
/// COPYRIGHT NOTICE
|
|||
/// Copyright (c) 2020, 传控科技
|
|||
/// All rights reserved.
|
|||
///
|
|||
/// @file main.c
|
|||
/// @brief main app
|
|||
///
|
|||
///(本文件实现的功能的详述)
|
|||
///
|
|||
/// @version 1.1 CCsens technology
|
|||
/// @author CC
|
|||
/// @date 20150102
|
|||
///
|
|||
///
|
|||
/// 修订说明:最初版本
|
|||
/// Modified by: cc
|
|||
/// Modified date: 20200531
|
|||
/// Version:
|
|||
/// Descriptions: add u8
|
|||
//////////////////////////////////////////////////////////////////////////
|
|||
|
|||
|
|||
//#include <stdint.h>
|
|||
|
|||
#ifndef __TYPE_H__ |
|||
#define __TYPE_H__ |
|||
|
|||
#ifndef NULL |
|||
#define NULL ((void *)0) |
|||
#endif |
|||
|
|||
#ifndef FALSE |
|||
#define FALSE (0) |
|||
#endif |
|||
|
|||
#ifndef D_stop |
|||
#define D_stop (1) |
|||
#endif |
|||
|
|||
#ifndef D_run |
|||
#define D_run (0) |
|||
#endif |
|||
|
|||
#ifndef D_ready |
|||
#define D_ready (1) |
|||
#endif |
|||
|
|||
#ifndef D_ready2 |
|||
#define D_ready2 (2) |
|||
#endif |
|||
|
|||
|
|||
#ifndef D_max |
|||
#define D_max (3) |
|||
#endif |
|||
|
|||
|
|||
|
|||
#ifndef D_diff |
|||
#define D_diff (4) |
|||
#endif |
|||
|
|||
#ifndef D_set |
|||
#define D_set (1) |
|||
#endif |
|||
|
|||
|
|||
|
|||
#ifndef D_clear |
|||
#define D_clear (0) |
|||
#endif |
|||
#define D_ON 1 |
|||
#define D_OFF 0 |
|||
|
|||
#define D_sleep_wakeup 3 |
|||
#define D_sleep 1 |
|||
#define D_wakeup 0 |
|||
|
|||
#ifndef TRUE |
|||
#define TRUE (1) |
|||
#endif |
|||
/*********************************************************************************************************
|
|||
定义与编译器无关的数据类型 |
|||
*********************************************************************************************************/ |
|||
|
|||
typedef unsigned char U8; |
|||
typedef unsigned char u8; |
|||
typedef volatile U8 vU8; |
|||
|
|||
|
|||
|
|||
typedef U8 BOOLEAN; /* 布尔变量 */ |
|||
typedef U8 *PU8; |
|||
typedef U8 BYTE; |
|||
typedef signed char S8; |
|||
typedef signed char *PS8; |
|||
|
|||
|
|||
|
|||
#define bit char |
|||
//#define code
|
|||
|
|||
typedef unsigned short u16; |
|||
typedef unsigned short U16; /* 无符号16位整型变量 */ |
|||
typedef volatile U16 vU16; /* 无符号16位整型变量 */ |
|||
typedef signed short S16; |
|||
typedef volatile S16 vS16; /* 有符号16位整型变量 */ |
|||
|
|||
typedef signed long S32; |
|||
typedef unsigned long U32; /* 无符号32位整型变量 */ |
|||
typedef volatile U32 vU32; /* 有符号32位整型变量 */ |
|||
typedef volatile signed long vS32; |
|||
|
|||
typedef float FP32; /* 单精度浮点数(32位长度) */ |
|||
typedef double FP64; /* 双精度浮点数(64位长度) */ |
|||
|
|||
|
|||
//typedef unsigned char BOOLEAN; // 布尔变量
|
|||
typedef unsigned char INT8U; // 无符号8位整型变量
|
|||
typedef signed char INT8S; // 有符号8位整型变量
|
|||
typedef unsigned short INT16U; // 无符号16位整型变量
|
|||
typedef signed short INT16S; // 有符号16位整型变量
|
|||
typedef unsigned long INT32U; // 无符号32位整型变量
|
|||
|
|||
typedef signed long INT32S; // 有符号32位整型变量
|
|||
//typedef float FP32; // 单精度浮点数(32位长度)
|
|||
//typedef double FP64; // 双精度浮点数(64位长度)
|
|||
|
|||
typedef unsigned int FLAG_P; // 标准类变量
|
|||
//typedef unsigned char INTU; // 标准类变量8BIT MCU
|
|||
typedef unsigned int INTU; // 标准类变量32BIT MCU
|
|||
/******************
|
|||
**************************/ |
|||
|
|||
|
|||
|
|||
/*********************************************************************************************************
|
|||
返回值定义 |
|||
*********************************************************************************************************/ |
|||
#define ZY_OK 0 /* 操作成功 */ |
|||
#define ZY_NOT_OK 1 /* 操作失败 */ |
|||
#define ZY_PARAMETER_ERR 2 /* 参数错误 */ |
|||
#define ZY_NO_FIND_FUNCTION 6 /* 没有发现指定函数 */ |
|||
#define ZY_NO_MEMORY 12 /* 内存不足 */ |
|||
#define ZY_TIME_OUT 13 /* 超时 */ |
|||
#define ZY_NO_FIND_OBJECT 16 /* 没有发现对象 */ |
|||
|
|||
/*********************************************************************************************************
|
|||
realView编译器需要添加的头文件 |
|||
*********************************************************************************************************/ |
|||
#include <ctype.h> |
|||
#include <stdlib.h> |
|||
#include <setjmp.h> |
|||
//#include <rt_misc.h>
|
|||
#define D_flag_lock 2 |
|||
#define D_flag_clear 0 |
|||
#define D_flag_CanUse 1 |
|||
|
|||
|
|||
typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus; |
|||
typedef enum {DISABLE = 0, ENABLE = !DISABLE} FunctionalState; |
|||
|
|||
typedef U8 UN_TYPE; |
|||
typedef U8 vtype; |
|||
|
|||
|
|||
|
|||
/*************
|
|||
|
|||
******************/ |
|||
|
|||
//>>>>>
|
|||
|
|||
|
|||
typedef union |
|||
{ |
|||
vU32 ui; |
|||
vU16 s[2]; |
|||
vU8 d[4]; |
|||
}tu_ui4uc; |
|||
|
|||
typedef union |
|||
{ |
|||
vU16 word; |
|||
struct |
|||
{ |
|||
vU8 h; |
|||
vU8 l; |
|||
}BYTE2; |
|||
}U_U16; |
|||
|
|||
typedef union |
|||
{ |
|||
vU32 dWord; |
|||
///High 0123 Low
|
|||
struct |
|||
{ |
|||
vU8 byte0; |
|||
vU8 byte1; |
|||
vU8 byte2; |
|||
vU8 byte3; |
|||
}BYTE4; |
|||
}U_U32; |
|||
typedef union |
|||
{ |
|||
vU16 us; |
|||
vU8 uc[2]; |
|||
struct |
|||
{ |
|||
vU8 H; |
|||
vU8 L; |
|||
}BYTE2; |
|||
}U_F16; |
|||
/**********
|
|||
k.us = 0x1234 |
|||
uc |
|||
[0]=0x12 |
|||
[1]=0x34 |
|||
byte2 |
|||
H=0x12 |
|||
L=0x34 |
|||
|
|||
**********/ |
|||
|
|||
|
|||
|
|||
typedef union |
|||
{ |
|||
float fl; |
|||
vU8 uc[4]; |
|||
|
|||
}U_F32; |
|||
|
|||
typedef struct |
|||
{ |
|||
vU8 *buffer; |
|||
vU8 wpt; |
|||
vU8 rpt; |
|||
vU8 cnt; |
|||
}byte_len_fifo_struct; |
|||
|
|||
typedef struct |
|||
{ |
|||
vU16 *buffer; |
|||
vU16 wpt; |
|||
vU16 rpt; |
|||
vU16 cnt; |
|||
}word_len_fifo_struct; |
|||
|
|||
typedef struct |
|||
{ |
|||
vU16 x; |
|||
vU16 y; |
|||
}point_struct; |
|||
|
|||
|
|||
typedef struct |
|||
{ |
|||
vU16 x; |
|||
vU16 y; |
|||
vU16 width; |
|||
vU16 height; |
|||
}rect_struct; |
|||
|
|||
|
|||
#define HIGHT 1 |
|||
#define LOW 0 |
|||
|
|||
#ifndef MIN |
|||
#define MIN(a,b) (((a) < (b)) ? (a) : (b)) |
|||
#endif |
|||
|
|||
#ifndef MAX |
|||
#define MAX(a, b) (((a) > (b)) ? (a) : (b)) |
|||
#endif |
|||
|
|||
#ifndef ABS |
|||
#define ABS(a, b) (((a) > (b)) ? ((a) - (b)) : ((b) - (a))) |
|||
#endif |
|||
|
|||
|
|||
#define F_FINSIH 1 |
|||
#define F_WORKING 0 |
|||
#define F_WAITINGKEY 2 |
|||
|
|||
|
|||
#define DF_var_up(v,step,max,init) (v) += (step);if((v) > (max)) (v) = (init); |
|||
//if step > 1 bug warning!!
|
|||
#define DF_var_down(v,step,min,init) \ |
|||
if((v) < ((min) + (step))) \ |
|||
{ \ |
|||
(v) = (init); \ |
|||
}else \ |
|||
{ \ |
|||
(v) -= (step); \ |
|||
} |
|||
|
|||
#define D_us2uc_H(x) (U8)(0x00ff&((x)>>8)) |
|||
#define D_us2uc_L(x) (U8)(0x00ff&(x)) |
|||
|
|||
|
|||
#define D_ul2uc_0(xx) (U8)(0x000000ff&(xx)) |
|||
#define D_uc_high(ww) ((ww)>>4) |
|||
#define D_uc_low(ww) ((ww)&0x0f) |
|||
|
|||
#define L0_type_byte(x) ((U8 *) &(x)) |
|||
|
|||
|
|||
//#define _nop_ __NOP
|
|||
// #define _nop_
|
|||
|
|||
|
|||
extern void L3_us_big(U16 *d); |
|||
extern void L3_ui_big(vU32 *d); |
|||
#endif /* __TYPE_H__ */ |
@ -0,0 +1,198 @@ |
|||
$NOMOD51 |
|||
;------------------------------------------------------------------------------ |
|||
; This file is part of the C51 Compiler package |
|||
; Copyright (c) 1988-2005 Keil Elektronik GmbH and Keil Software, Inc. |
|||
; Version 8.01 |
|||
; |
|||
; *** <<< Use Configuration Wizard in Context Menu >>> *** |
|||
;------------------------------------------------------------------------------ |
|||
; STARTUP.A51: This code is executed after processor reset. |
|||
; |
|||
; To translate this file use A51 with the following invocation: |
|||
; |
|||
; A51 STARTUP.A51 |
|||
; |
|||
; To link the modified STARTUP.OBJ file to your application use the following |
|||
; Lx51 invocation: |
|||
; |
|||
; Lx51 your object file list, STARTUP.OBJ controls |
|||
; |
|||
;------------------------------------------------------------------------------ |
|||
; |
|||
; User-defined <h> Power-On Initialization of Memory |
|||
; |
|||
; With the following EQU statements the initialization of memory |
|||
; at processor reset can be defined: |
|||
; |
|||
; <o> IDATALEN: IDATA memory size <0x0-0x100> |
|||
; <i> Note: The absolute start-address of IDATA memory is always 0 |
|||
; <i> The IDATA space overlaps physically the DATA and BIT areas. |
|||
IDATALEN EQU 80H |
|||
; |
|||
; <o> XDATASTART: XDATA memory start address <0x0-0xFFFF> |
|||
; <i> The absolute start address of XDATA memory |
|||
XDATASTART EQU 0 |
|||
; |
|||
; <o> XDATALEN: XDATA memory size <0x0-0xFFFF> |
|||
; <i> The length of XDATA memory in bytes. |
|||
XDATALEN EQU 0 |
|||
; |
|||
; <o> PDATASTART: PDATA memory start address <0x0-0xFFFF> |
|||
; <i> The absolute start address of PDATA memory |
|||
PDATASTART EQU 0H |
|||
; |
|||
; <o> PDATALEN: PDATA memory size <0x0-0xFF> |
|||
; <i> The length of PDATA memory in bytes. |
|||
PDATALEN EQU 0H |
|||
; |
|||
;</h> |
|||
;------------------------------------------------------------------------------ |
|||
; |
|||
;<h> Reentrant Stack Initialization |
|||
; |
|||
; The following EQU statements define the stack pointer for reentrant |
|||
; functions and initialized it: |
|||
; |
|||
; <h> Stack Space for reentrant functions in the SMALL model. |
|||
; <q> IBPSTACK: Enable SMALL model reentrant stack |
|||
; <i> Stack space for reentrant functions in the SMALL model. |
|||
IBPSTACK EQU 0 ; set to 1 if small reentrant is used. |
|||
; <o> IBPSTACKTOP: End address of SMALL model stack <0x0-0xFF> |
|||
; <i> Set the top of the stack to the highest location. |
|||
IBPSTACKTOP EQU 0xFF +1 ; default 0FFH+1 |
|||
; </h> |
|||
; |
|||
; <h> Stack Space for reentrant functions in the LARGE model. |
|||
; <q> XBPSTACK: Enable LARGE model reentrant stack |
|||
; <i> Stack space for reentrant functions in the LARGE model. |
|||
XBPSTACK EQU 1 ; set to 1 if large reentrant is used. |
|||
; <o> XBPSTACKTOP: End address of LARGE model stack <0x0-0xFFFF> |
|||
; <i> Set the top of the stack to the highest location. |
|||
XBPSTACKTOP EQU 0xFFFF +1 ; default 0FFFFH+1 |
|||
; </h> |
|||
; |
|||
; <h> Stack Space for reentrant functions in the COMPACT model. |
|||
; <q> PBPSTACK: Enable COMPACT model reentrant stack |
|||
; <i> Stack space for reentrant functions in the COMPACT model. |
|||
PBPSTACK EQU 0 ; set to 1 if compact reentrant is used. |
|||
; |
|||
; <o> PBPSTACKTOP: End address of COMPACT model stack <0x0-0xFFFF> |
|||
; <i> Set the top of the stack to the highest location. |
|||
PBPSTACKTOP EQU 0xFF +1 ; default 0FFH+1 |
|||
; </h> |
|||
;</h> |
|||
;------------------------------------------------------------------------------ |
|||
; |
|||
; Memory Page for Using the Compact Model with 64 KByte xdata RAM |
|||
; <e>Compact Model Page Definition |
|||
; |
|||
; <i>Define the XDATA page used for PDATA variables. |
|||
; <i>PPAGE must conform with the PPAGE set in the linker invocation. |
|||
; |
|||
; Enable pdata memory page initalization |
|||
PPAGEENABLE EQU 0 ; set to 1 if pdata object are used. |
|||
; |
|||
; <o> PPAGE number <0x0-0xFF> |
|||
; <i> uppermost 256-byte address of the page used for PDATA variables. |
|||
PPAGE EQU 0 |
|||
; |
|||
; <o> SFR address which supplies uppermost address byte <0x0-0xFF> |
|||
; <i> most 8051 variants use P2 as uppermost address byte |
|||
PPAGE_SFR DATA 0A0H |
|||
; |
|||
; </e> |
|||
;------------------------------------------------------------------------------ |
|||
|
|||
; Standard SFR Symbols |
|||
ACC DATA 0E0H |
|||
B DATA 0F0H |
|||
SP DATA 81H |
|||
DPL DATA 82H |
|||
DPH DATA 83H |
|||
|
|||
NAME ?C_STARTUP |
|||
|
|||
|
|||
?C_C51STARTUP SEGMENT CODE |
|||
?STACK SEGMENT IDATA |
|||
|
|||
RSEG ?STACK |
|||
DS 1 |
|||
|
|||
EXTRN CODE (?C_START) |
|||
PUBLIC ?C_STARTUP |
|||
|
|||
CSEG AT 0 |
|||
?C_STARTUP: LJMP STARTUP1 |
|||
|
|||
RSEG ?C_C51STARTUP |
|||
|
|||
STARTUP1: |
|||
|
|||
IF IDATALEN <> 0 |
|||
MOV R0,#IDATALEN - 1 |
|||
CLR A |
|||
IDATALOOP: MOV @R0,A |
|||
DJNZ R0,IDATALOOP |
|||
ENDIF |
|||
|
|||
IF XDATALEN <> 0 |
|||
MOV DPTR,#XDATASTART |
|||
MOV R7,#LOW (XDATALEN) |
|||
IF (LOW (XDATALEN)) <> 0 |
|||
MOV R6,#(HIGH (XDATALEN)) +1 |
|||
ELSE |
|||
MOV R6,#HIGH (XDATALEN) |
|||
ENDIF |
|||
CLR A |
|||
XDATALOOP: MOVX @DPTR,A |
|||
INC DPTR |
|||
DJNZ R7,XDATALOOP |
|||
DJNZ R6,XDATALOOP |
|||
ENDIF |
|||
|
|||
IF PPAGEENABLE <> 0 |
|||
MOV PPAGE_SFR,#PPAGE |
|||
ENDIF |
|||
|
|||
IF PDATALEN <> 0 |
|||
MOV R0,#LOW (PDATASTART) |
|||
MOV R7,#LOW (PDATALEN) |
|||
CLR A |
|||
PDATALOOP: MOVX @R0,A |
|||
INC R0 |
|||
DJNZ R7,PDATALOOP |
|||
ENDIF |
|||
|
|||
IF IBPSTACK <> 0 |
|||
EXTRN DATA (?C_IBP) |
|||
|
|||
MOV ?C_IBP,#LOW IBPSTACKTOP |
|||
ENDIF |
|||
|
|||
IF XBPSTACK <> 0 |
|||
EXTRN DATA (?C_XBP) |
|||
|
|||
MOV ?C_XBP,#HIGH XBPSTACKTOP |
|||
MOV ?C_XBP+1,#LOW XBPSTACKTOP |
|||
ENDIF |
|||
|
|||
IF PBPSTACK <> 0 |
|||
EXTRN DATA (?C_PBP) |
|||
MOV ?C_PBP,#LOW PBPSTACKTOP |
|||
ENDIF |
|||
|
|||
MOV SP,#?STACK-1 |
|||
|
|||
; This code is required if you use L51_BANK.A51 with Banking Mode 4 |
|||
;<h> Code Banking |
|||
; <q> Select Bank 0 for L51_BANK.A51 Mode 4 |
|||
#if 0 |
|||
; <i> Initialize bank mechanism to code bank 0 when using L51_BANK.A51 with Banking Mode 4. |
|||
EXTRN CODE (?B_SWITCH0) |
|||
CALL ?B_SWITCH0 ; init bank mechanism to code bank 0 |
|||
#endif |
|||
;</h> |
|||
LJMP ?C_START |
|||
|
|||
END |
@ -0,0 +1,617 @@ |
|||
#ifndef __STC_stc8a8k_H_ |
|||
#define __STC_stc8a8k_H_ |
|||
// STC_stc8a8k.h
|
|||
#include<intrins.h> |
|||
/////////////////////////////////////////////////
|
|||
//注意: STC15W4K32S4系列的芯片,上电后所有与PWM相关的IO口均为
|
|||
// 高阻态,需将这些口设置为准双向口或强推挽模式方可正常使用
|
|||
//相关IO: P0.6/P0.7/P1.6/P1.7/P2.1/P2.2
|
|||
// P2.3/P2.7/P3.7/P4.2/P4.4/P4.5
|
|||
/////////////////////////////////////////////////
|
|||
|
|||
/////////////////////////////////////////////////
|
|||
|
|||
//包含本头文件后,不用另外再包含"REG51.H"
|
|||
|
|||
//内核特殊功能寄存器 // 复位值 描述
|
|||
sfr ACC = 0xE0; //0000,0000 累加器Accumulator
|
|||
sfr B = 0xF0; //0000,0000 B寄存器
|
|||
sfr PSW = 0xD0; //0000,0000 程序状态字
|
|||
sbit CY = PSW^7; |
|||
sbit AC = PSW^6; |
|||
sbit F0 = PSW^5; |
|||
sbit RS1 = PSW^4; |
|||
sbit RS0 = PSW^3; |
|||
sbit OV = PSW^2; |
|||
sbit P = PSW^0; |
|||
sfr SP = 0x81; //0000,0111 堆栈指针
|
|||
sfr DPL = 0x82; //0000,0000 数据指针低字节
|
|||
sfr DPH = 0x83; //0000,0000 数据指针高字节
|
|||
|
|||
//I/O 口特殊功能寄存器
|
|||
sfr P0 = 0x80; //1111,1111 端口0
|
|||
sbit P00 = P0^0; |
|||
sbit P01 = P0^1; |
|||
sbit P02 = P0^2; |
|||
sbit P03 = P0^3; |
|||
sbit P04 = P0^4; |
|||
sbit P05 = P0^5; |
|||
sbit P06 = P0^6; |
|||
sbit P07 = P0^7; |
|||
sfr P1 = 0x90; //1111,1111 端口1
|
|||
sbit P10 = P1^0; |
|||
sbit P11 = P1^1; |
|||
sbit P12 = P1^2; |
|||
sbit P13 = P1^3; |
|||
sbit P14 = P1^4; |
|||
sbit P15 = P1^5; |
|||
sbit P16 = P1^6; |
|||
sbit P17 = P1^7; |
|||
sfr P2 = 0xA0; //1111,1111 端口2
|
|||
sbit P20 = P2^0; |
|||
sbit P21 = P2^1; |
|||
sbit P22 = P2^2; |
|||
sbit P23 = P2^3; |
|||
sbit P24 = P2^4; |
|||
sbit P25 = P2^5; |
|||
sbit P26 = P2^6; |
|||
sbit P27 = P2^7; |
|||
sfr P3 = 0xB0; //1111,1111 端口3
|
|||
sbit P30 = P3^0; |
|||
sbit P31 = P3^1; |
|||
sbit P32 = P3^2; |
|||
sbit P33 = P3^3; |
|||
sbit P34 = P3^4; |
|||
sbit P35 = P3^5; |
|||
sbit P36 = P3^6; |
|||
sbit P37 = P3^7; |
|||
sfr P4 = 0xC0; //1111,1111 端口4
|
|||
sbit P40 = P4^0; |
|||
sbit P41 = P4^1; |
|||
sbit P42 = P4^2; |
|||
sbit P43 = P4^3; |
|||
sbit P44 = P4^4; |
|||
sbit P45 = P4^5; |
|||
sbit P46 = P4^6; |
|||
sbit P47 = P4^7; |
|||
sfr P5 = 0xC8; //xxxx,1111 端口5
|
|||
sbit P50 = P5^0; |
|||
sbit P51 = P5^1; |
|||
sbit P52 = P5^2; |
|||
sbit P53 = P5^3; |
|||
sbit P54 = P5^4; |
|||
sbit P55 = P5^5; |
|||
sbit P56 = P5^6; |
|||
sbit P57 = P5^7; |
|||
sfr P6 = 0xE8; //0000,0000 端口6
|
|||
sbit P60 = P6^0; |
|||
sbit P61 = P6^1; |
|||
sbit P62 = P6^2; |
|||
sbit P63 = P6^3; |
|||
sbit P64 = P6^4; |
|||
sbit P65 = P6^5; |
|||
sbit P66 = P6^6; |
|||
sbit P67 = P6^7; |
|||
sfr P7 = 0xF8; //0000,0000 端口7
|
|||
sbit P70 = P7^0; |
|||
sbit P71 = P7^1; |
|||
sbit P72 = P7^2; |
|||
sbit P73 = P7^3; |
|||
sbit P74 = P7^4; |
|||
sbit P75 = P7^5; |
|||
sbit P76 = P7^6; |
|||
sbit P77 = P7^7; |
|||
|
|||
|
|||
///00 准双向口 灌电流20mA 拉电流270-150uS
|
|||
///01 推挽输出 20mA 加限流
|
|||
///10 高阻
|
|||
///11 开漏 open-Drain 内部上拉电阻断开 开漏模式既可以度外部状态也可以对外输出高低电平
|
|||
|
|||
|
|||
sfr P0M0 = 0x94; //0000,0000 端口0模式寄存器0
|
|||
sfr P0M1 = 0x93; //0000,0000 端口0模式寄存器1
|
|||
sfr P1M0 = 0x92; //0000,0000 端口1模式寄存器0
|
|||
sfr P1M1 = 0x91; //0000,0000 端口1模式寄存器1
|
|||
sfr P2M0 = 0x96; //0000,0000 端口2模式寄存器0
|
|||
sfr P2M1 = 0x95; //0000,0000 端口2模式寄存器1
|
|||
sfr P3M0 = 0xB2; //0000,0000 端口3模式寄存器0
|
|||
sfr P3M1 = 0xB1; //0000,0000 端口3模式寄存器1
|
|||
sfr P4M0 = 0xB4; //0000,0000 端口4模式寄存器0
|
|||
sfr P4M1 = 0xB3; //0000,0000 端口4模式寄存器1
|
|||
sfr P5M0 = 0xCA; //0000,0000 端口5模式寄存器0
|
|||
sfr P5M1 = 0xC9; //0000,0000 端口5模式寄存器1
|
|||
sfr P6M0 = 0xCC; //0000,0000 端口6模式寄存器0
|
|||
sfr P6M1 = 0xCB; //0000,0000 端口6模式寄存器1
|
|||
sfr P7M0 = 0xE2; //0000,0000 端口7模式寄存器0
|
|||
sfr P7M1 = 0xE1; //0000,0000 端口7模式寄存器1
|
|||
|
|||
//系统管理特殊功能寄存器
|
|||
sfr PCON = 0x87; //0001,0000 电源控制寄存器
|
|||
sfr AUXR = 0x8E; //0000,0000 辅助寄存器
|
|||
|
|||
#define TOx12 BITN7 |
|||
#define T1x12 BITN6 |
|||
#define UART_M0x6 BITN5 //串口1模式0速度 =0 12倍 = 1 两倍
|
|||
#define T2R BITN4 //定时器2 运行 =1
|
|||
#define T2_C BITN3 //定时器/计数器选择
|
|||
#define T2x12 BITN2 |
|||
#define EXTRAM BITN1 |
|||
#define S1ST2 BITN0 //串口1选择定时器1 =0 选择定时器2 =1
|
|||
|
|||
|
|||
sfr VOCTR = 0xBB; //电压控制寄存器
|
|||
///BITN_1(VOCTR, BITN7) VOCTR
|
|||
#define D_VOCTR_SCCIN 0x00 |
|||
#define D_VOCTR_SCC 0x80 |
|||
#define D_VOCTR_SET(X) VOCTR = (X) |
|||
|
|||
sfr AUXR1 = 0xA2; //0000,0000 辅助寄存器1
|
|||
sfr P_SW1 = 0xA2; //0000,0000 外设端口切换寄存器1
|
|||
sfr CLK_DIV = 0x97; //0000,0000 时钟分频控制寄存器
|
|||
sfr BUS_SPEED = 0xA1; //xx10,x011 总线速度控制寄存器
|
|||
sfr P1ASF = 0x9D; //0000,0000 端口1模拟功能配置寄存器
|
|||
//-----------------------------------------------------------------
|
|||
sfr P_SW2 = 0xBA; //0xxx,x000 外设端口切换寄存器
|
|||
#define EAXFR BITN7 |
|||
#define I2C_S1 BITN5 |
|||
#define I2C_S2 BITN4 |
|||
#define CMPO_S BITN3 |
|||
#define S4_S BITN2 |
|||
#define S3_S BITN1 |
|||
#define S2_S BITN0 |
|||
|
|||
//-----------------------------------------------------------------
|
|||
|
|||
//中断特殊功能寄存器
|
|||
sfr IE = 0xA8; //0000,0000 中断控制寄存器
|
|||
sbit EA = IE^7; |
|||
sbit ELVD = IE^6; |
|||
sbit EADC = IE^5; |
|||
sbit ES = IE^4; |
|||
sbit ET1 = IE^3; |
|||
sbit EX1 = IE^2; |
|||
sbit ET0 = IE^1; |
|||
sbit EX0 = IE^0; |
|||
sfr IE2 = 0xAF; //0000,0000 中断控制寄存器2
|
|||
sfr IP = 0xB8; //0000,0000 中断优先级寄存器
|
|||
sbit PPCA = IP^7; |
|||
sbit PLVD = IP^6; |
|||
sbit PADC = IP^5; |
|||
sbit PS = IP^4; |
|||
sbit PT1 = IP^3; |
|||
sbit PX1 = IP^2; |
|||
sbit PT0 = IP^1; |
|||
sbit PX0 = IP^0; |
|||
/// 不可位寻址
|
|||
#define ET4 BITN6 |
|||
#define ET3 BITN5 |
|||
#define ES4 BITN4 |
|||
#define ES3 BITN3 |
|||
#define ET2 BITN2 |
|||
#define ESPI BITN1 |
|||
#define ES2 BITN0 |
|||
|
|||
sfr IPH = 0xB7; //xxxx,xx00 中断优先级寄存器2
|
|||
#define PPCAH BITN7 |
|||
#define PLVDH BITN6 |
|||
#define PADCH BITN5 |
|||
#define PSH BITN4 |
|||
#define PT1H BITN3 |
|||
#define PX1H BITN2 |
|||
#define PT0H BITN1 |
|||
#define PX0H BITN0 |
|||
|
|||
|
|||
|
|||
sfr IP2 = 0xB5; //xxxx,xx00 中断优先级寄存器2
|
|||
#define IP2_7 BITN7 |
|||
#define PI2C BITN6 |
|||
#define PCMP BITN5 |
|||
#define PX4 BITN4 |
|||
#define PPWMFD BITN3 |
|||
#define PPWM BITN2 |
|||
#define PSPI BITN1 |
|||
#define PS2 BITN0 |
|||
|
|||
sfr IP2H = 0xB6; //xxxx,xx00 中断优先级寄存器2
|
|||
#define IP2_7 BITN7 |
|||
#define PI2CH BITN6 |
|||
#define PCMPH BITN5 |
|||
#define PX4H BITN4 |
|||
#define PPWMFDH BITN3 |
|||
#define PPWMH BITN2 |
|||
#define PSPIH BITN1 |
|||
#define PS2H BITN0 |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
sfr INT_CLKO = 0x8F; //0000,0000 外部中断与时钟输出控制寄存器
|
|||
#define INT_EX4 BITN6 |
|||
#define INT_EX3 BITN5 |
|||
#define INT_EX2 BITN4 |
|||
//定时器特殊功能寄存器
|
|||
sfr TCON = 0x88; //0000,0000 T0/T1控制寄存器
|
|||
sbit TF1 = TCON^7; |
|||
sbit TR1 = TCON^6; |
|||
sbit TF0 = TCON^5; |
|||
sbit TR0 = TCON^4; |
|||
sbit IE1 = TCON^3; |
|||
sbit IT1 = TCON^2; |
|||
sbit IE0 = TCON^1; |
|||
sbit IT0 = TCON^0; |
|||
sfr TMOD = 0x89; //0000,0000 T0/T1模式寄存器
|
|||
sfr TL0 = 0x8A; //0000,0000 T0低字节
|
|||
sfr TL1 = 0x8B; //0000,0000 T1低字节
|
|||
sfr TH0 = 0x8C; //0000,0000 T0高字节
|
|||
sfr TH1 = 0x8D; //0000,0000 T1高字节
|
|||
sfr T4T3M = 0xD1; //0000,0000 T3/T4模式寄存器
|
|||
sfr T3T4M = 0xD1; //0000,0000 T3/T4模式寄存器
|
|||
sfr T4H = 0xD2; //0000,0000 T4高字节
|
|||
sfr T4L = 0xD3; //0000,0000 T4低字节
|
|||
sfr T3H = 0xD4; //0000,0000 T3高字节
|
|||
sfr T3L = 0xD5; //0000,0000 T3低字节
|
|||
sfr T2H = 0xD6; //0000,0000 T2高字节
|
|||
sfr T2L = 0xD7; //0000,0000 T2低字节
|
|||
sfr WKTCL = 0xAA; //0000,0000 掉电唤醒定时器低字节
|
|||
sfr WKTCH = 0xAB; //0000,0000 掉电唤醒定时器高字节
|
|||
sfr16 WKTC = 0xAA; |
|||
sfr WDT_CONTR = 0xC1; //0000,0000 看门狗控制寄存器
|
|||
|
|||
//串行口特殊功能寄存器
|
|||
sfr SCON = 0x98; //0000,0000 串口1控制寄存器
|
|||
sbit SM0 = SCON^7; |
|||
sbit SM1 = SCON^6; |
|||
sbit SM2 = SCON^5; |
|||
sbit REN = SCON^4; |
|||
sbit TB8 = SCON^3; |
|||
sbit RB8 = SCON^2; |
|||
sbit TI = SCON^1; |
|||
sbit RI = SCON^0; |
|||
//sfr SBUF = 0x99; //xxxx,xxxx 串口1数据寄存器
|
|||
//sfr S2CON = 0x9A; //0000,0000 串口2控制寄存器
|
|||
//sfr S2BUF = 0x9B; //xxxx,xxxx 串口2数据寄存器
|
|||
//sfr SADDR = 0xA9; //0000,0000 从机地址寄存器
|
|||
//sfr SADEN = 0xB9; //0000,0000 从机地址屏蔽寄存器
|
|||
|
|||
sfr SBUF = 0x99; //Serial Data Buffer
|
|||
sfr SBUF0 = 0x99; //Serial Data Buffer xxxx,xxxx
|
|||
sfr SADEN = 0xB9; //Slave Address Mask 0000,0000
|
|||
sfr SADDR = 0xA9; //Slave Address 0000,0000
|
|||
//-----------------------------------
|
|||
// 7 6 5 4 3 2 1 0 Reset Value
|
|||
sfr S2CON = 0x9A; //S2 Control S2SM0 S2SM1 S2SM2 S2REN S2TB8 S2RB8 S2TI S2RI 00000000B
|
|||
#define S2SM0 BITN7 |
|||
#define S2ST4 BITN6 |
|||
#define S2SM2 BITN5 |
|||
#define S2REN BITN4 |
|||
#define S2TB8 BITN3 |
|||
#define S2RB8 BITN2 |
|||
#define S2TI BITN1 |
|||
#define S2RI BITN0 |
|||
|
|||
sfr S2BUF = 0x9B; //S2 Serial Buffer xxxx,xxxx
|
|||
//sfr BRT = 0x9C; //S2 Baud-Rate Timer 0000,0000
|
|||
|
|||
//---------------------------------------------------------------
|
|||
sfr S3CON = 0xAC; //0000,0000 串口3控制寄存器
|
|||
#define S3SM0 BITN7 |
|||
#define S3ST4 BITN6 |
|||
#define S3SM2 BITN5 |
|||
#define S3REN BITN4 |
|||
#define S3TB8 BITN3 |
|||
#define S3RB8 BITN2 |
|||
#define S3TI BITN1 |
|||
#define S3RI BITN0 |
|||
|
|||
sfr S3BUF = 0xAD; //xxxx,xxxx 串口3数据寄存器
|
|||
//---------------------------------------------------------------
|
|||
sfr S4CON = 0x84; //0000,0000 串口4控制寄存器
|
|||
#define S4SM0 BITN7 |
|||
#define S4ST4 BITN6 |
|||
#define S4SM2 BITN5 |
|||
#define S4REN BITN4 |
|||
#define S4TB8 BITN3 |
|||
#define S4RB8 BITN2 |
|||
#define S4TI BITN1 |
|||
#define S4RI BITN0 |
|||
|
|||
sfr S4BUF = 0x85; //xxxx,xxxx 串口4数据寄存器
|
|||
|
|||
//ADC 特殊功能寄存器
|
|||
sfr ADC_CONTR = 0xBC; //0000,0000 A/D转换控制寄存器
|
|||
sfr ADC_RES = 0xBD; //0000,0000 A/D转换结果高8位
|
|||
sfr ADC_RESL = 0xBE; //0000,0000 A/D转换结果低2位
|
|||
|
|||
//SPI 特殊功能寄存器
|
|||
sfr SPSTAT = 0xCD; //00xx,xxxx SPI状态寄存器
|
|||
sfr SPCTL = 0xCE; //0000,0100 SPI控制寄存器
|
|||
sfr SPDAT = 0xCF; //0000,0000 SPI数据寄存器
|
|||
|
|||
//IAP/ISP 特殊功能寄存器
|
|||
sfr IAP_DATA = 0xC2; //0000,0000 EEPROM数据寄存器
|
|||
sfr IAP_ADDRH = 0xC3; //0000,0000 EEPROM地址高字节
|
|||
sfr IAP_ADDRL = 0xC4; //0000,0000 EEPROM地址第字节
|
|||
sfr IAP_CMD = 0xC5; //xxxx,xx00 EEPROM命令寄存器
|
|||
sfr IAP_TRIG = 0xC6; //0000,0000 EEPRPM命令触发寄存器
|
|||
sfr IAP_CONTR = 0xC7; //0000,x000 EEPROM控制寄存器
|
|||
|
|||
//PCA/PWM 特殊功能寄存器
|
|||
sfr CCON = 0xD8; //00xx,xx00 PCA控制寄存器
|
|||
sbit CF = CCON^7; |
|||
sbit CR = CCON^6; |
|||
sbit CCF2 = CCON^2; |
|||
sbit CCF1 = CCON^1; |
|||
sbit CCF0 = CCON^0; |
|||
sfr CMOD = 0xD9; //0xxx,x000 PCA 工作模式寄存器
|
|||
sfr CL = 0xE9; //0000,0000 PCA计数器低字节
|
|||
sfr CH = 0xF9; //0000,0000 PCA计数器高字节
|
|||
sfr CCAPM0 = 0xDA; //0000,0000 PCA模块0的PWM寄存器
|
|||
sfr CCAPM1 = 0xDB; //0000,0000 PCA模块1的PWM寄存器
|
|||
sfr CCAPM2 = 0xDC; //0000,0000 PCA模块2的PWM 寄存器
|
|||
sfr CCAP0L = 0xEA; //0000,0000 PCA模块0的捕捉/比较寄存器低字节
|
|||
sfr CCAP1L = 0xEB; //0000,0000 PCA模块1的捕捉/比较寄存器低字节
|
|||
sfr CCAP2L = 0xEC; //0000,0000 PCA模块2的捕捉/比较寄存器低字节
|
|||
sfr PCA_PWM0 = 0xF2; //xxxx,xx00 PCA模块0的PWM寄存器
|
|||
sfr PCA_PWM1 = 0xF3; //xxxx,xx00 PCA模块1的PWM寄存器
|
|||
sfr PCA_PWM2 = 0xF4; //xxxx,xx00 PCA模块1的PWM寄存器
|
|||
sfr CCAP0H = 0xFA; //0000,0000 PCA模块0的捕捉/比较寄存器高字节
|
|||
sfr CCAP1H = 0xFB; //0000,0000 PCA模块1的捕捉/比较寄存器高字节
|
|||
sfr CCAP2H = 0xFC; //0000,0000 PCA模块2的捕捉/比较寄存器高字节
|
|||
|
|||
//比较器特殊功能寄存器
|
|||
sfr CMPCR1 = 0xE6; //0000,0000 比较器控制寄存器1
|
|||
sfr CMPCR2 = 0xE7; //0000,0000 比较器控制寄存器2
|
|||
|
|||
|
|||
//sfr P_SW2 = 0xba;
|
|||
sfr PWMCFG = 0xf1; |
|||
sfr PWMIF = 0xf6; |
|||
sfr PWMFDCR = 0xf7; |
|||
sfr PWMCR = 0xfe; |
|||
|
|||
#define PWMC (*(unsigned int volatile xdata *)0xfff0) |
|||
#define PWMCKS (*(unsigned char volatile xdata *)0xfff2) |
|||
#define TADCP (*(unsigned int volatile xdata *)0xfff3) |
|||
#define PWM0T1 (*(unsigned int volatile xdata *)0xff00) |
|||
#define PWM0T2 (*(unsigned int volatile xdata *)0xff02) |
|||
#define PWM0CR (*(unsigned char volatile xdata *)0xff04) |
|||
#define PWM0HLD (*(unsigned char volatile xdata *)0xff05) |
|||
#define PWM1T1 (*(unsigned int volatile xdata *)0xff10) |
|||
#define PWM1T2 (*(unsigned int volatile xdata *)0xff12) |
|||
#define PWM1CR (*(unsigned char volatile xdata *)0xff14) |
|||
#define PWM1HLD (*(unsigned char volatile xdata *)0xff15) |
|||
#define PWM2T1 (*(unsigned int volatile xdata *)0xff20) |
|||
#define PWM2T2 (*(unsigned int volatile xdata *)0xff22) |
|||
#define PWM2CR (*(unsigned char volatile xdata *)0xff24) |
|||
#define PWM2HLD (*(unsigned char volatile xdata *)0xff25) |
|||
#define PWM3T1 (*(unsigned int volatile xdata *)0xff30) |
|||
#define PWM3T2 (*(unsigned int volatile xdata *)0xff32) |
|||
#define PWM3CR (*(unsigned char volatile xdata *)0xff34) |
|||
#define PWM3HLD (*(unsigned char volatile xdata *)0xff35) |
|||
#define PWM4T1 (*(unsigned int volatile xdata *)0xff40) |
|||
#define PWM4T2 (*(unsigned int volatile xdata *)0xff42) |
|||
#define PWM4CR (*(unsigned char volatile xdata *)0xff44) |
|||
#define PWM4HLD (*(unsigned char volatile xdata *)0xff45) |
|||
#define PWM5T1 (*(unsigned int volatile xdata *)0xff50) |
|||
#define PWM5T2 (*(unsigned int volatile xdata *)0xff52) |
|||
#define PWM5CR (*(unsigned char volatile xdata *)0xff54) |
|||
#define PWM5HLD (*(unsigned char volatile xdata *)0xff55) |
|||
#define PWM6T1 (*(unsigned int volatile xdata *)0xff60) |
|||
#define PWM6T2 (*(unsigned int volatile xdata *)0xff62) |
|||
#define PWM6CR (*(unsigned char volatile xdata *)0xff64) |
|||
#define PWM6HLD (*(unsigned char volatile xdata *)0xff65) |
|||
#define PWM7T1 (*(unsigned int volatile xdata *)0xff70) |
|||
#define PWM7T2 (*(unsigned int volatile xdata *)0xff72) |
|||
#define PWM7CR (*(unsigned char volatile xdata *)0xff74) |
|||
#define PWM7HLD (*(unsigned char volatile xdata *)0xff75) |
|||
|
|||
|
|||
#define CKSEL (*(unsigned char volatile xdata *)0xfE00)//108@ST8.PDF
|
|||
#define MCLKODIV BIT4 |
|||
#define MCLKO_S BITN3 |
|||
#define MCLKSEL BIT0 |
|||
|
|||
#define CLKDIV (*(unsigned char volatile xdata *)0xfE01)//108@ST8.PDF
|
|||
#define IRC24MCR (*(unsigned char volatile xdata *)0xfE02)//108@ST8.PDF
|
|||
#define XOSCCR (*(unsigned char volatile xdata *)0xfE03)//108@ST8.PDF
|
|||
#define IRC32KCR (*(unsigned char volatile xdata *)0xfE04)//108@ST8.PDF
|
|||
|
|||
|
|||
|
|||
#define I2CTXD (*(unsigned char volatile xdata *)0xfE86)//423@ST8.PDF
|
|||
|
|||
#define I2CRXD (*(unsigned char volatile xdata *)0xfE87)//423@ST8.PDF
|
|||
|
|||
|
|||
|
|||
///-------------------------------------
|
|||
|
|||
#define gRccUs01_H (*(unsigned char volatile data *)0xd2) |
|||
#define gRccUs01_L (*(unsigned char volatile data *)0xd3) |
|||
|
|||
|
|||
|
|||
#define gRccUs01 (*(unsigned short volatile data *)0xd2)//226@ST8.PDF T4H定时器4的高字节 D2H T4H定时器4的低字节 D3H
|
|||
#define gRccUs02 (*(unsigned short volatile data *)0xEA)//351@ST8.PDF CCAP0l CCAP1L EAH EBH
|
|||
#define gRccUs03 (*(unsigned short volatile data *)0xEC)//351@ST8.PDF CCAP0l CCAP1L EAH EBH
|
|||
//#define gRccUs03 s_task_GC032A.n
|
|||
|
|||
|
|||
|
|||
#define gRccUs04 (*(unsigned short volatile data *)0xFA)///351@ST8.PDF
|
|||
#define gRccUs05 (*(unsigned short volatile data *)0xFC)///351@ST8.PD CCAP2H
|
|||
|
|||
/////////////////////////////////////////////////
|
|||
|
|||
|
|||
|
|||
/* P3 */ |
|||
sbit RD = 0xB7; |
|||
sbit WR = 0xB6; |
|||
sbit T1 = 0xB5; |
|||
sbit T0 = 0xB4; |
|||
sbit INT1 = 0xB3; |
|||
sbit INT0 = 0xB2; |
|||
sbit TXD = 0xB1; |
|||
sbit RXD = 0xB0; |
|||
|
|||
|
|||
sfr AUXINTIF = 0xef; |
|||
|
|||
#define T2IF 0x01 |
|||
#define INT4IF BITN6 |
|||
#define INT3IF BITN5 |
|||
#define INT2IF BITN4 |
|||
|
|||
//#define T4IF BITN2
|
|||
//#define T3IF BITN1
|
|||
//#define T2IF BITN0
|
|||
|
|||
|
|||
/// >>>>> add by cc
|
|||
|
|||
#include "../clib/bit.h" |
|||
|
|||
#define D_stdIO_P0_ALL() P0M1=0;P0M0=0; |
|||
#define D_HighI_P0_ALL() P0M1=0;P0M0=0XFF; |
|||
#define D_HighR_P0_ALL() P0M1=0XFF;P0M0=0; |
|||
#define D_OpenD_P0_ALL() P0M1=0XFF;P0M0=0XFF; |
|||
|
|||
#define D_stdIO_P1_ALL() P1M1=0;P1M0=0; |
|||
#define D_HighI_P1_ALL() P1M1=0;P1M0=0XFF; |
|||
#define D_HighR_P1_ALL() P1M1=0XFF;P1M0=0; |
|||
#define D_OpenD_P1_ALL() P1M1=0XFF;P1M0=0XFF; |
|||
|
|||
|
|||
#define D_stdIO_P0(n) BITN_0(P0M1,n);BITN_0(P0M0,n); //////00 准双向口 灌电流20mA 拉电流270-150uS
|
|||
#define D_HighI_P0(n) BITN_0(P0M1,n);BITN_1(P0M0,n); //////01 推挽输出 20mA 加限流
|
|||
#define D_HighR_P0(n) BITN_1(P0M1,n);BITN_0(P0M0,n); /////////10 高阻
|
|||
#define D_OpenD_P0(n) BITN_1(P0M1,n);BITN_1(P0M0,n); /////11 开漏 open-Drain 内部上拉电阻断开 开漏模式既可以度外部状态也可以对外输出高低电平
|
|||
|
|||
#define D_stdIO_P1(n) BITN_0(P1M1,n);BITN_0(P1M0,n); //////00 准双向口 灌电流20mA 拉电流270-150uS
|
|||
#define D_HighI_P1(n) BITN_0(P1M1,n);BITN_1(P1M0,n); //////01 推挽输出 20mA 加限流
|
|||
#define D_HighR_P1(n) BITN_1(P1M1,n);BITN_0(P1M0,n); /////////10 高阻
|
|||
#define D_OpenD_P1(n) BITN_1(P1M1,n);BITN_1(P1M0,n); /////11 开漏 open-Drain 内部上拉电阻断开 开漏模式既可以度外部状态也可以对外输出高低电平
|
|||
|
|||
#define D_stdIO_P2(n) BITN_0(P2M1,n);BITN_0(P2M0,n); //////00 准双向口 灌电流20mA 拉电流270-150uS
|
|||
#define D_HighI_P2(n) BITN_0(P2M1,n);BITN_1(P2M0,n); //////01 推挽输出 20mA 加限流
|
|||
#define D_HighR_P2(n) BITN_1(P2M1,n);BITN_0(P2M0,n); /////////10 高阻
|
|||
#define D_OpenD_P2(n) BITN_1(P2M1,n);BITN_1(P2M0,n); /////11 开漏 open-Drain 内部上拉电阻断开 开漏模式既可以度外部状态也可以对外输出高低电平
|
|||
|
|||
#define D_stdIO_P3(n) BITN_0(P3M1,n);BITN_0(P3M0,n); //////00 准双向口 灌电流20mA 拉电流270-150uS
|
|||
#define D_HighI_P3(n) BITN_0(P3M1,n);BITN_1(P3M0,n); //////01 推挽输出 20mA 加限流
|
|||
#define D_HighR_P3(n) BITN_1(P3M1,n);BITN_0(P3M0,n); /////////10 高阻
|
|||
#define D_OpenD_P3(n) BITN_1(P3M1,n);BITN_1(P3M0,n); /////11 开漏 open-Drain 内部上拉电阻断开 开漏模式既可以度外部状态也可以对外输出高低电平
|
|||
|
|||
#define D_stdIO_P4(n) BITN_0(P4M1,n);BITN_0(P4M0,n); //////00 准双向口 灌电流20mA 拉电流270-150uS
|
|||
#define D_HighI_P4(n) BITN_0(P4M1,n);BITN_1(P4M0,n); //////01 推挽输出 20mA 加限流
|
|||
#define D_HighR_P4(n) BITN_1(P4M1,n);BITN_0(P4M0,n); /////////10 高阻
|
|||
#define D_OpenD_P4(n) BITN_1(P4M1,n);BITN_1(P4M0,n); /////11 开漏 open-Drain 内部上拉电阻断开 开漏模式既可以度外部状态也可以对外输出高低电平
|
|||
|
|||
#define D_stdIO_P5(n) BITN_0(P5M1,n);BITN_0(P5M0,n); //////00 准双向口 灌电流20mA 拉电流270-150uS
|
|||
#define D_HighI_P5(n) BITN_0(P5M1,n);BITN_1(P5M0,n); //////01 推挽输出 20mA 加限流
|
|||
#define D_HighR_P5(n) BITN_1(P5M1,n);BITN_0(P5M0,n); /////////10 高阻
|
|||
#define D_OpenD_P5(n) BITN_1(P5M1,n);BITN_1(P5M0,n); /////11 开漏 open-Drain 内部上拉电阻断开 开漏模式既可以度外部状态也可以对外输出高低电平
|
|||
|
|||
#define D_stdIO_P6(n) BITN_0(P6M1,n);BITN_0(P6M0,n); //////00 准双向口 灌电流20mA 拉电流270-150uS
|
|||
#define D_HighI_P6(n) BITN_0(P6M1,n);BITN_1(P6M0,n); //////01 推挽输出 20mA 加限流
|
|||
#define D_HighR_P6(n) BITN_1(P6M1,n);BITN_0(P6M0,n); /////////10 高阻
|
|||
#define D_OpenD_P6(n) BITN_1(P6M1,n);BITN_1(P6M0,n); /////11 开漏 open-Drain 内部上拉电阻断开 开漏模式既可以度外部状态也可以对外输出高低电平
|
|||
|
|||
#define D_stdIO_P7(n) BITN_0(P7M1,n);BITN_0(P7M0,n); //////00 准双向口 灌电流20mA 拉电流270-150uS
|
|||
#define D_HighI_P7(n) BITN_0(P7M1,n);BITN_1(P7M0,n); //////01 推挽输出 20mA 加限流
|
|||
#define D_HighR_P7(n) BITN_1(P7M1,n);BITN_0(P7M0,n); /////////10 高阻
|
|||
#define D_OpenD_P7(n) BITN_1(P7M1,n);BITN_1(P7M0,n); /////11 开漏 open-Drain 内部上拉电阻断开 开漏模式既可以度外部状态也可以对外输出高低电平
|
|||
|
|||
/***
|
|||
|
|||
#define P0_conf_in(n) BITN_1(P0M1,n);BITN_0(P0M0,n); |
|||
#define P1_conf_in(n) BITN_1(P1M1,n);BITN_0(P1M0,n); |
|||
#define P2_conf_in(n) BITN_1(P2M1,n);BITN_0(P2M0,n); |
|||
#define P2_conf_port(n) BITN_0(P2M1,n);BITN_0(P2M0,n); |
|||
|
|||
|
|||
#define P3_conf_in(n) BITN_1(P3M1,n);BITN_0(P3M0,n); |
|||
#define P3_conf_port(n) BITN_0(P3M1,n);BITN_0(P3M0,n); |
|||
|
|||
#define P4_conf_in(n) BITN_1(P4M1,n);BITN_0(P4M0,n); |
|||
#define P5_conf_in(n) BITN_1(P5M1,n);BITN_0(P5M0,n); |
|||
|
|||
***/ |
|||
|
|||
|
|||
|
|||
#define NOP() _nop_() |
|||
|
|||
#define L0_INT4_OPEN() BITN_1(INT_CLKO, INT_EX4) |
|||
#define L0_INT4_CLOSE() BITN_0(INT_CLKO, INT_EX4) |
|||
|
|||
#define L0_INT4_AT() BITN_G(INT_CLKO, INT_EX4) |
|||
|
|||
|
|||
|
|||
|
|||
#define L0_INT4_CLEAR() BITN_0(AUXINTIF, INT4IF) |
|||
#define L0_INT3_CLEAR() BITN_0(AUXINTIF, INT3IF) |
|||
#define L0_INT2_CLEAR() BITN_0(AUXINTIF, INT2IF) |
|||
|
|||
|
|||
|
|||
|
|||
//////
|
|||
|
|||
#define L0_INT3_OPEN() BITN_1(INT_CLKO, INT_EX3); |
|||
#define L0_INT3_CLOSE() BITN_0(INT_CLKO, INT_EX3); |
|||
#define L0_INT2_OPEN() BITN_1(INT_CLKO, INT_EX2); |
|||
#define L0_INT2_CLOSE() BITN_0(INT_CLKO, INT_EX2); |
|||
#define L0_INT1_OPEN() EX1 = 1; |
|||
#define L0_INT1_CLOSE() EX1 = 0; |
|||
#define L0_INT0_OPEN() EX0 = 1; |
|||
#define L0_INT0_CLOSE() EX0 = 0; |
|||
|
|||
#define D_ISR_int0 0 ///int0 下降沿触发 = 0 上下沿均可触发
|
|||
#define D_ISR_timer0 1 |
|||
#define D_ISR_int1 2 ///int1 下降沿触发 = 0 上下沿均可触发
|
|||
#define D_ISR_timer1 3 |
|||
#define D_ISR_int2 10 /////只有下降沿
|
|||
#define D_ISR_int3 11 /////只有下降沿
|
|||
#define D_SERVE_UART 4 |
|||
#define D_ISR_int4 16 /////只有下降沿
|
|||
|
|||
#if 0 |
|||
#define L0_TIMER1_start() TR1 = 1; |
|||
#define L0_TIMER1_end() TR1 = 0; |
|||
|
|||
|
|||
#define L0_TIMER1_isr_OPEN() ET1 = 1; |
|||
#define L0_TIMER1_isr_CLOSE() ET1 = 0; |
|||
|
|||
|
|||
#else |
|||
|
|||
#define L0_TIMER1_start() ET1 = 1; |
|||
#define L0_TIMER1_end() ET1 = 0; |
|||
|
|||
|
|||
#define L0_TIMER1_isr_OPEN() TR1 = 1; |
|||
#define L0_TIMER1_isr_CLOSE() TR1 = 0; |
|||
|
|||
|
|||
#endif |
|||
|
|||
/// fixme 颠倒定义会让c51锁死#define _nop_() NOP()
|
|||
|
|||
///#define L0_INT3_OPEN() BITN_1(INT_CLKO,INT_EX3); //使能INT3中断
|
|||
///#define L0_INT3_CLOSE() BITN_0(INT_CLKO,INT_EX3);
|
|||
#endif //STC_stc8a8k
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
@ -0,0 +1,301 @@ |
|||
//////////////////////////////////////////////////////////////////////////
|
|||
/// COPYRIGHT NOTICE
|
|||
/// Copyright (c) 2018, 传控科技
|
|||
/// All rights reserved.
|
|||
///
|
|||
/// @file __C51_MACRO_H_
|
|||
/// @brief macro define 和cpu相关,可以和同一个系列的cpu共享
|
|||
///
|
|||
///(本文件实现的功能的详述)
|
|||
///
|
|||
/// @version 1.1 CCsens technology
|
|||
/// @author CC
|
|||
/// @date 20180102
|
|||
|
|||
//
|
|||
//////////////////////////////////////////////////////////////////////////
|
|||
|
|||
|
|||
|
|||
#ifndef __C51_MACRO_H_ |
|||
#define __C51_MACRO_H_ |
|||
|
|||
#include<intrins.h> |
|||
|
|||
#define D_P07_ON() P07 = 1 |
|||
#define D_P06_ON() P06 = 1 |
|||
#define D_P05_ON() P05 = 1 |
|||
#define D_P04_ON() P04 = 1 |
|||
#define D_P03_ON() P03 = 1 |
|||
#define D_P02_ON() P02 = 1 |
|||
#define D_P01_ON() P01 = 1 |
|||
#define D_P00_ON() P00 = 1 |
|||
#define D_P07_OFF() P07 = 0 |
|||
#define D_P06_OFF() P06 = 0 |
|||
#define D_P05_OFF() P05 = 0 |
|||
#define D_P04_OFF() P04 = 0 |
|||
#define D_P03_OFF() P03 = 0 |
|||
#define D_P02_OFF() P02 = 0 |
|||
#define D_P01_OFF() P01 = 0 |
|||
#define D_P00_OFF() P00 = 0 |
|||
#define D_P07_AT() (P07) |
|||
#define D_P06_AT() (P06) |
|||
#define D_P05_AT() (P05) |
|||
#define D_P04_AT() (P04) |
|||
#define D_P03_AT() (P03) |
|||
#define D_P02_AT() (P02) |
|||
#define D_P01_AT() (P01) |
|||
#define D_P00_AT() (P00) |
|||
#define D_P07_REV() P07 = ~P07 |
|||
#define D_P06_REV() P06 = ~P06 |
|||
#define D_P05_REV() P05 = ~P05 |
|||
#define D_P04_REV() P04 = ~P04 |
|||
#define D_P03_REV() P03 = ~P03 |
|||
#define D_P02_REV() P02 = ~P02 |
|||
#define D_P01_REV() P01 = ~P01 |
|||
#define D_P00_REV() P00 = ~P00 |
|||
|
|||
|
|||
#define D_P17_ON() P17 = 1 |
|||
#define D_P16_ON() P16 = 1 |
|||
#define D_P15_ON() P15 = 1 |
|||
#define D_P14_ON() P14 = 1 |
|||
#define D_P13_ON() P13 = 1 |
|||
#define D_P12_ON() P12 = 1 |
|||
#define D_P11_ON() P11 = 1 |
|||
#define D_P10_ON() P10 = 1 |
|||
#define D_P17_OFF() P17 = 0 |
|||
#define D_P16_OFF() P16 = 0 |
|||
#define D_P15_OFF() P15 = 0 |
|||
#define D_P14_OFF() P14 = 0 |
|||
#define D_P13_OFF() P13 = 0 |
|||
#define D_P12_OFF() P12 = 0 |
|||
#define D_P11_OFF() P11 = 0 |
|||
#define D_P10_OFF() P10 = 0 |
|||
#define D_P17_AT() (P17) |
|||
#define D_P16_AT() (P16) |
|||
#define D_P15_AT() (P15) |
|||
#define D_P14_AT() (P14) |
|||
#define D_P13_AT() (P13) |
|||
#define D_P12_AT() (P12) |
|||
#define D_P11_AT() (P11) |
|||
#define D_P10_AT() (P10) |
|||
#define D_P17_REV() P17 = ~P17 |
|||
#define D_P16_REV() P16 = ~P16 |
|||
#define D_P15_REV() P15 = ~P15 |
|||
#define D_P14_REV() P14 = ~P14 |
|||
#define D_P13_REV() P13 = ~P13 |
|||
#define D_P12_REV() P12 = ~P12 |
|||
#define D_P11_REV() P11 = ~P11 |
|||
#define D_P10_REV() P10 = ~P10 |
|||
|
|||
#define D_P27_ON() P27 = 1 |
|||
#define D_P26_ON() P26 = 1 |
|||
#define D_P25_ON() P25 = 1 |
|||
#define D_P24_ON() P24 = 1 |
|||
#define D_P23_ON() P23 = 1 |
|||
#define D_P22_ON() P22 = 1 |
|||
#define D_P21_ON() P21 = 1 |
|||
#define D_P20_ON() P20 = 1 |
|||
#define D_P27_OFF() P27 = 0 |
|||
#define D_P26_OFF() P26 = 0 |
|||
#define D_P25_OFF() P25 = 0 |
|||
#define D_P24_OFF() P24 = 0 |
|||
#define D_P23_OFF() P23 = 0 |
|||
#define D_P22_OFF() P22 = 0 |
|||
#define D_P21_OFF() P21 = 0 |
|||
#define D_P20_OFF() P20 = 0 |
|||
#define D_P27_AT() (P27) |
|||
#define D_P26_AT() (P26) |
|||
#define D_P25_AT() (P25) |
|||
#define D_P24_AT() (P24) |
|||
#define D_P23_AT() (P23) |
|||
#define D_P22_AT() (P22) |
|||
#define D_P21_AT() (P21) |
|||
#define D_P20_AT() (P20) |
|||
#define D_P27_REV() P27 = ~P27 |
|||
#define D_P26_REV() P26 = ~P26 |
|||
#define D_P25_REV() P25 = ~P25 |
|||
#define D_P24_REV() P24 = ~P24 |
|||
#define D_P23_REV() P23 = ~P23 |
|||
#define D_P22_REV() P22 = ~P22 |
|||
#define D_P21_REV() P21 = ~P21 |
|||
#define D_P20_REV() P20 = ~P20 |
|||
|
|||
|
|||
#define D_P37_ON() P37 = 1 |
|||
#define D_P36_ON() P36 = 1 |
|||
#define D_P35_ON() P35 = 1 |
|||
#define D_P34_ON() P34 = 1 |
|||
#define D_P33_ON() P33 = 1 |
|||
#define D_P32_ON() P32 = 1 |
|||
#define D_P31_ON() P31 = 1 |
|||
#define D_P30_ON() P30 = 1 |
|||
#define D_P37_OFF() P37 = 0 |
|||
#define D_P36_OFF() P36 = 0 |
|||
#define D_P35_OFF() P35 = 0 |
|||
#define D_P34_OFF() P34 = 0 |
|||
#define D_P33_OFF() P33 = 0 |
|||
#define D_P32_OFF() P32 = 0 |
|||
#define D_P31_OFF() P31 = 0 |
|||
#define D_P30_OFF() P30 = 0 |
|||
#define D_P37_AT() (P37) |
|||
#define D_P36_AT() (P36) |
|||
#define D_P35_AT() (P35) |
|||
#define D_P34_AT() (P34) |
|||
#define D_P33_AT() (P33) |
|||
#define D_P32_AT() (P32) |
|||
#define D_P31_AT() (P31) |
|||
#define D_P30_AT() (P30) |
|||
#define D_P37_REV() P37 = ~P37 |
|||
#define D_P36_REV() P36 = ~P36 |
|||
#define D_P35_REV() P35 = ~P35 |
|||
#define D_P34_REV() P34 = ~P34 |
|||
#define D_P33_REV() P33 = ~P33 |
|||
#define D_P32_REV() P32 = ~P32 |
|||
#define D_P31_REV() P31 = ~P31 |
|||
#define D_P30_REV() P30 = ~P30 |
|||
|
|||
|
|||
#define D_P47_ON() P47 = 1 |
|||
#define D_P46_ON() P46 = 1 |
|||
#define D_P45_ON() P45 = 1 |
|||
#define D_P44_ON() P44 = 1 |
|||
#define D_P43_ON() P43 = 1 |
|||
#define D_P42_ON() P42 = 1 |
|||
#define D_P41_ON() P41 = 1 |
|||
#define D_P40_ON() P40 = 1 |
|||
#define D_P47_OFF() P47 = 0 |
|||
#define D_P46_OFF() P46 = 0 |
|||
#define D_P45_OFF() P45 = 0 |
|||
#define D_P44_OFF() P44 = 0 |
|||
#define D_P43_OFF() P43 = 0 |
|||
#define D_P42_OFF() P42 = 0 |
|||
#define D_P41_OFF() P41 = 0 |
|||
#define D_P40_OFF() P40 = 0 |
|||
#define D_P47_AT() (P47) |
|||
#define D_P46_AT() (P46) |
|||
#define D_P45_AT() (P45) |
|||
#define D_P44_AT() (P44) |
|||
#define D_P43_AT() (P43) |
|||
#define D_P42_AT() (P42) |
|||
#define D_P41_AT() (P41) |
|||
#define D_P40_AT() (P40) |
|||
#define D_P47_REV() P47 = ~P47 |
|||
#define D_P46_REV() P46 = ~P46 |
|||
#define D_P45_REV() P45 = ~P45 |
|||
#define D_P44_REV() P44 = ~P44 |
|||
#define D_P43_REV() P43 = ~P43 |
|||
#define D_P42_REV() P42 = ~P42 |
|||
#define D_P41_REV() P41 = ~P41 |
|||
#define D_P40_REV() P40 = ~P40 |
|||
|
|||
#define D_P57_ON() P57 = 1 |
|||
#define D_P56_ON() P56 = 1 |
|||
#define D_P55_ON() P55 = 1 |
|||
#define D_P54_ON() P54 = 1 |
|||
#define D_P53_ON() P53 = 1 |
|||
#define D_P52_ON() P52 = 1 |
|||
#define D_P51_ON() P51 = 1 |
|||
#define D_P50_ON() P50 = 1 |
|||
#define D_P57_OFF() P57 = 0 |
|||
#define D_P56_OFF() P56 = 0 |
|||
#define D_P55_OFF() P55 = 0 |
|||
#define D_P54_OFF() P54 = 0 |
|||
#define D_P53_OFF() P53 = 0 |
|||
#define D_P52_OFF() P52 = 0 |
|||
#define D_P51_OFF() P51 = 0 |
|||
#define D_P50_OFF() P50 = 0 |
|||
#define D_P57_AT() (P57) |
|||
#define D_P56_AT() (P56) |
|||
#define D_P55_AT() (P55) |
|||
#define D_P54_AT() (P54) |
|||
#define D_P53_AT() (P53) |
|||
#define D_P52_AT() (P52) |
|||
#define D_P51_AT() (P51) |
|||
#define D_P50_AT() (P50) |
|||
#define D_P57_REV() P57 = ~P57 |
|||
#define D_P56_REV() P56 = ~P56 |
|||
#define D_P55_REV() P55 = ~P55 |
|||
#define D_P54_REV() P54 = ~P54 |
|||
#define D_P53_REV() P53 = ~P53 |
|||
#define D_P52_REV() P52 = ~P52 |
|||
#define D_P51_REV() P51 = ~P51 |
|||
#define D_P50_REV() P50 = ~P50 |
|||
|
|||
#define D_P67_ON() P67 = 1 |
|||
#define D_P66_ON() P66 = 1 |
|||
#define D_P65_ON() P65 = 1 |
|||
#define D_P64_ON() P64 = 1 |
|||
#define D_P63_ON() P63 = 1 |
|||
#define D_P62_ON() P62 = 1 |
|||
#define D_P61_ON() P61 = 1 |
|||
#define D_P60_ON() P60 = 1 |
|||
#define D_P67_OFF() P67 = 0 |
|||
#define D_P66_OFF() P66 = 0 |
|||
#define D_P65_OFF() P65 = 0 |
|||
#define D_P64_OFF() P64 = 0 |
|||
#define D_P63_OFF() P63 = 0 |
|||
#define D_P62_OFF() P62 = 0 |
|||
#define D_P61_OFF() P61 = 0 |
|||
#define D_P60_OFF() P60 = 0 |
|||
#define D_P67_AT() (P67) |
|||
#define D_P66_AT() (P66) |
|||
#define D_P65_AT() (P65) |
|||
#define D_P64_AT() (P64) |
|||
#define D_P63_AT() (P63) |
|||
#define D_P62_AT() (P62) |
|||
#define D_P61_AT() (P61) |
|||
#define D_P60_AT() (P60) |
|||
#define D_P67_REV() P67 = ~P67 |
|||
#define D_P66_REV() P66 = ~P66 |
|||
#define D_P65_REV() P65 = ~P65 |
|||
#define D_P64_REV() P64 = ~P64 |
|||
#define D_P63_REV() P63 = ~P63 |
|||
#define D_P62_REV() P62 = ~P62 |
|||
#define D_P61_REV() P61 = ~P61 |
|||
#define D_P60_REV() P60 = ~P60 |
|||
|
|||
#define D_P77_ON() P77 = 1 |
|||
#define D_P76_ON() P76 = 1 |
|||
#define D_P75_ON() P75 = 1 |
|||
#define D_P74_ON() P74 = 1 |
|||
#define D_P73_ON() P73 = 1 |
|||
#define D_P72_ON() P72 = 1 |
|||
#define D_P71_ON() P71 = 1 |
|||
#define D_P70_ON() P70 = 1 |
|||
#define D_P77_OFF() P77 = 0 |
|||
#define D_P76_OFF() P76 = 0 |
|||
#define D_P75_OFF() P75 = 0 |
|||
#define D_P74_OFF() P74 = 0 |
|||
#define D_P73_OFF() P73 = 0 |
|||
#define D_P72_OFF() P72 = 0 |
|||
#define D_P71_OFF() P71 = 0 |
|||
#define D_P70_OFF() P70 = 0 |
|||
#define D_P77_AT() (P77) |
|||
#define D_P76_AT() (P76) |
|||
#define D_P75_AT() (P75) |
|||
#define D_P74_AT() (P74) |
|||
#define D_P73_AT() (P73) |
|||
#define D_P72_AT() (P72) |
|||
#define D_P71_AT() (P71) |
|||
#define D_P70_AT() (P70) |
|||
#define D_P77_REV() P77 = ~P77 |
|||
#define D_P76_REV() P76 = ~P76 |
|||
#define D_P75_REV() P75 = ~P75 |
|||
#define D_P74_REV() P74 = ~P74 |
|||
#define D_P73_REV() P73 = ~P73 |
|||
#define D_P72_REV() P72 = ~P72 |
|||
#define D_P71_REV() P71 = ~P71 |
|||
#define D_P70_REV() P70 = ~P70 |
|||
|
|||
|
|||
|
|||
#endif //__C51_MACRO_H_
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
@ -0,0 +1,288 @@ |
|||
/*****************************************************
|
|||
*============================================================================ |
|||
* HISTORY |
|||
* Below this line, this part is controlled by TSTS. DO NOT MODIFY!! |
|||
伪时间片嵌入式平台(Task Step by Step Turn by Turn Structure,简称TSTS) |
|||
*============================================================================ |
|||
****************************************************************************/ |
|||
|
|||
#include "task.h" |
|||
//任务命名规则:
|
|||
// 1:第一层
|
|||
/// 0驱动芯片级 flash
|
|||
/// 1芯片应用级 save
|
|||
/// 2任务应用级 jilu_save
|
|||
//
|
|||
// 2:第二层/flash/i2c/7290/等各类芯片
|
|||
// 3:任务序号/不同的芯片/
|
|||
//
|
|||
|
|||
void L1_task_init(TS_task *s) |
|||
{ |
|||
// s->en = 1;
|
|||
// s->pfun = 0;
|
|||
s->sh = 0; |
|||
s->sh_next= 0; |
|||
/// s->sh_pre= 0;
|
|||
s->n= 0; |
|||
} |
|||
|
|||
|
|||
/////》》》》》》》》》》》》》》》》供演示task 结构的使用 不可删除
|
|||
#define D_task_test_01 0x20 |
|||
#define D_task_test_02 0x22 |
|||
#define D_task_test_03 0x23 |
|||
#ifdef D_debug_task_test |
|||
////>>>>>>>>>>>>>>>>>>>>>_s_task_test_>>>>>>>>>>>>>>>>>>>>>>
|
|||
struct _s_task_test_ s_task_test; |
|||
void L2_task_test_init(void) |
|||
{ |
|||
ddd |
|||
L1_task_init(&s_task_test.task); |
|||
L3_task_s_go(s_task_test,D_task_init); |
|||
} |
|||
|
|||
|
|||
///L2_task_test_handle(&s_task_test);
|
|||
void L2_task_test_handle(struct _s_task_test_ *s) |
|||
{ |
|||
unsigned char d = 0; |
|||
TTSS_Task_init(); |
|||
L2_task_go(D_task_test_01); |
|||
TTSS_Task_step(D_task_test_01): |
|||
if(d > 8) |
|||
{ |
|||
d = 0; |
|||
L2_task_go(D_task_test_02); |
|||
L1_task_Cdelay(D_Cdelay_200us); |
|||
}else |
|||
{ |
|||
d ++; |
|||
} |
|||
TTSS_Task_step(D_task_test_02): |
|||
if(d > 4) |
|||
{ |
|||
d = 0; |
|||
L2_task_go(D_task_test_01); |
|||
L1_task_Tdelay(D_Tdelay_100ms); |
|||
}else |
|||
{ |
|||
d ++; |
|||
} |
|||
|
|||
TTSS_Task_end(); |
|||
} |
|||
#endif//#ifdef D_debug_task_test
|
|||
////<<<<<<<<<<<<<<<<<<<<<_s_task_test_<<<<<<<<<<<<<<<<<<<<<<
|
|||
|
|||
/////<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<供演示task 结构的使用 不可删除
|
|||
|
|||
|
|||
//example :
|
|||
#if 0 |
|||
|
|||
|
|||
//L2_task_voice_handle(&s_task_music.task);
|
|||
//L1_task_go(D_task_close);
|
|||
//if(L1_task_busy(s)){ L1_task_goout(s_task_music.task,D_task_voice_send_single) }
|
|||
void L2_task_voice_handle(struct _s_task_music_ *s) |
|||
{ //s_task_music.task.sh
|
|||
switch(s->task.sh) |
|||
{ |
|||
|
|||
case D_task_voice_init://
|
|||
|
|||
s->sector = 0; |
|||
break; |
|||
case D_task_voice_cuimian : |
|||
s->sector = D_voice_music_wantsleep; |
|||
L2_task_go_son(D_task_voice_play,D_task_voice_cuimian1); |
|||
break; |
|||
case D_task_voice_cuimian1://
|
|||
L2_task_go(D_task_voice_cuimian2); |
|||
|
|||
break; |
|||
case D_task_voice_cuimian2://
|
|||
|
|||
if(0 == s->volume_change) |
|||
{ |
|||
//L3_voice_stop();
|
|||
s->sector = D_voice_stop; |
|||
s->status = D_voice_status_stop; |
|||
//L2_task_go(D_task_voice_play);
|
|||
L2_task_go_son(D_task_voice_play,0); |
|||
}else |
|||
{ |
|||
s->volume_change --; |
|||
s->volume_temp = s->volume; |
|||
s->volume = s->volume_change*s->volume_shop/20;//
|
|||
if (s->volume_temp != s->volume) |
|||
{ |
|||
s->sector = D_voice_volume|s->volume; |
|||
//s->status = D_voice_status_stop;
|
|||
//L2_task_go(D_task_voice_volume3);
|
|||
L2_task_go_son(D_task_voice_play,D_task_voice_cuimian2); |
|||
} |
|||
//else
|
|||
{ |
|||
L2_task_delay(D_task_delay_1m); |
|||
} |
|||
} |
|||
break; |
|||
|
|||
//>>>>>>>>>>>>>>>>>> son function
|
|||
case D_task_voice_play://
|
|||
if(L3_task_s_busy(s_task_wt558d)) |
|||
{ |
|||
}else |
|||
{ |
|||
s_task_wt558d.reg = s_task_music.sector; |
|||
L3_task_s_go(s_task_wt558d,D_task_wt558d_fun); |
|||
|
|||
L2_task_go(D_task_voice_ask); |
|||
} |
|||
break; |
|||
case D_task_voice_ask://
|
|||
if(L3_task_s_busy(s_task_wt558d)) |
|||
{ |
|||
|
|||
}else |
|||
{ |
|||
|
|||
L2_task_go_father();//回到
|
|||
} |
|||
break; |
|||
//<<<<<<<<<<<<<<<<<<<<<< son function
|
|||
//-----------------------task standerd code
|
|||
case D_task_Tdelay://----
|
|||
s->task.n--; |
|||
if (s->task.n == 0) |
|||
{ |
|||
s->task.n = 0; |
|||
L2_task_delay_over(); |
|||
} |
|||
break; |
|||
|
|||
default : |
|||
break; |
|||
} |
|||
L2_task_wt558d_handle(&s_task_wt558d); |
|||
} |
|||
|
|||
|
|||
void L2_task_voice_handle(struct _s_task_music_ *s) |
|||
{ //s_task_music.task.sh
|
|||
switch(s->task.sh) |
|||
{ |
|||
|
|||
case D_task_voice_init://
|
|||
|
|||
s->sector = 0; |
|||
break; |
|||
case D_task_voice_cuimian : |
|||
s->sector = D_voice_music_wantsleep; |
|||
L2_task_go_son(D_task_voice_play,D_task_voice_cuimian1); |
|||
break; |
|||
case D_task_voice_cuimian1://
|
|||
L2_task_go(D_task_voice_cuimian2); |
|||
|
|||
break; |
|||
|
|||
//-----------------------task standerd code
|
|||
case D_task_Tdelay://----
|
|||
s->task.n--; |
|||
if (s->task.n == 0) |
|||
{ |
|||
s->task.n = 0; |
|||
L2_task_delay_over(); |
|||
} |
|||
break; |
|||
|
|||
default : |
|||
break; |
|||
} |
|||
L2_task_wt558d_handle(&s_task_wt558d); |
|||
} |
|||
|
|||
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|||
//>>>>>>>>>>>>>>>>>>>>>记录task
|
|||
struct _s_task_4ChuShengRiQi_ |
|||
{ |
|||
TS_task task; |
|||
unsigned char pic_id;//画面ID
|
|||
|
|||
|
|||
}; |
|||
extern struct _s_task_4ChuShengRiQi_ s_task_4ChuShengRiQi_; |
|||
|
|||
#define D_task_4ChuShengRiQi_init 0x10 |
|||
#define D_task_4ChuShengRiQi_key 0x11 |
|||
|
|||
|
|||
extern void L2_task_4ChuShengRiQi_handle(struct _s_task_4ChuShengRiQi_ *s); |
|||
|
|||
void L2_task_4ChuShengRiQi_handle(struct _s_task_4ChuShengRiQi_ *s) |
|||
{ |
|||
switch(s->task.sh) |
|||
{ |
|||
|
|||
case D_task_4ChuShengRiQi_init://
|
|||
|
|||
s->pic_id= 0; |
|||
break; |
|||
case D_task_4ChuShengRiQi_key : |
|||
if(1 == s_task_keyx1.down ) |
|||
{ |
|||
s_task_keyx1.down = 0; |
|||
|
|||
if(D_keyx_left == s_task_keyx1.key_value) |
|||
{} |
|||
|
|||
|
|||
}else if(1 == s_task_keyx_4.down) |
|||
{ |
|||
s_task_keyx_4.down = 0; |
|||
|
|||
|
|||
} |
|||
else {} |
|||
|
|||
//L2_task_go_son(D_task_4ChuShengRiQi_play,D_task_4ChuShengRiQi_cuimian1);
|
|||
break; |
|||
|
|||
L0_task_delay(); |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
//<<<<<<<<<<<<<<<<<<<记录task
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
/*****************************************************
|
|||
*============================================================== |
|||
* HISTORY |
|||
* Below this line, this part is controlled by TSTS. DO NOT MODIFY!! |
|||
伪时间片嵌入式平台(Task Step by Step Turn by Turn Structure,简称TSTS) |
|||
*============================================================== |
|||
****************************************************************************/ |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
#endif |
|||
|
|||
|
@ -0,0 +1,288 @@ |
|||
/********************************
|
|||
2013.7.23 add dictionary and task step by cc |
|||
|
|||
任务:task |
|||
任务段:task step |
|||
任务标志:sh ( struct handle) |
|||
|
|||
下一个任务段sh_next |
|||
缓存的任务段,sh_next执行完后执行sh_pre |
|||
|
|||
***************************/ |
|||
/*****************************************************
|
|||
*============================================================== |
|||
* HISTORY |
|||
* Below this line, this part is controlled by TSTS. DO NOT MODIFY!! |
|||
伪时间片嵌入式平台(Task Step by Step Turn by Turn Structure,简称TSTS) |
|||
*============================================================== |
|||
|
|||
20190217 and step01 并且把delay_n添加括号保护 |
|||
|
|||
|
|||
|
|||
****************************************************************************/ |
|||
|
|||
#ifndef _TASK_H_ |
|||
#define _TASK_H_ |
|||
#include "../clib/type.h" |
|||
#include "../msp/time.h" |
|||
#include "task.h" |
|||
#include "tick.h" |
|||
|
|||
typedef struct |
|||
{ |
|||
vU32 n; |
|||
/// volatile UN_TYPE en; //关闭任务,也可以理解为暂停,但是使用idelay的地方时间在后台计数任务在延时到了后才暂停,而的delay相当于暂停
|
|||
volatile UN_TYPE sh; //当前任务段
|
|||
volatile UN_TYPE sh_next; //下一个任务段,并不代表一定下一任务段一定是他,有可能中间插入延时等任务段
|
|||
/// volatile UN_TYPE sh_pre; //前一个任务段,一般为调出缓存任务段使用
|
|||
}TS_task; |
|||
//extern TS_task ts_task_stcadc;
|
|||
#define D_task_close 0 |
|||
|
|||
#define D_task_Tdelay 0x01 |
|||
#define D_task_stop 0x04 |
|||
#define D_task_Cdelay 0x09 |
|||
#define D_task_init 0x10 |
|||
#define D_task_quit 0xf0 |
|||
|
|||
#define TTS_for_add(i,start,len) for((i) = (start); (i) < (len); (i) ++){ |
|||
#define TTS_for_add_end() } |
|||
|
|||
|
|||
|
|||
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>内部调用 s->task
|
|||
#define L2_task_delay_over() s->task.sh = s->task.sh_next |
|||
#define L2_task_go(next) s->task.sh = next |
|||
#define L2_task_en(onf) s->task.en = onf |
|||
|
|||
#define L2_task_busy(s) (D_task_close != s.task.sh) |
|||
#define L2_task_free(s) (D_task_close == s.task.sh) |
|||
|
|||
#define L2_task_go_father() s->task.sh = s->task.sh_pre |
|||
#define L2_task_go_son(fun,pre) s->task.sh = fun;s->task.sh_pre = pre |
|||
|
|||
|
|||
//>task 定时>>>>>>>>>>>>>>TTSS
|
|||
/// D_task_Tdelay == task timer delay 需要额外有个定时单元 和time0定时器设置相关
|
|||
/// Delay_cycle适用于 时间短的,其一次循环取决于主循环的时间,和Tdelay比,Cdelay长时间计时误差大
|
|||
#define L2_task_switch_default_idelay(); \ |
|||
case D_task_Tdelay:\ |
|||
if (s_nos_tick.t_10ms >= s->task.n)\ |
|||
{\ |
|||
L2_task_delay_over();\ |
|||
}\ |
|||
break; \ |
|||
case D_task_Cdelay:\ |
|||
s->task.n--; \ |
|||
if (s->task.n == 0) \ |
|||
{ \ |
|||
s->task.n = 0; \ |
|||
L2_task_delay_over();\ |
|||
} \ |
|||
break;\ |
|||
default : \ |
|||
break; |
|||
#if 0 |
|||
|
|||
#define L2_task_switch_default_idelay2(); \ |
|||
case D_task_Tdelay:\ |
|||
if (s_nos_tick.t_10ms >= s->task.n)\ |
|||
{\ |
|||
L2_task_delay_over();\ |
|||
}else\ |
|||
{\ |
|||
L2_time_beat_heart(D_TBH_ch0,3,'i');\ |
|||
}\ |
|||
break; \ |
|||
case D_task_Cdelay:\ |
|||
s->task.n--; \ |
|||
if (s->task.n == 0) \ |
|||
{ \ |
|||
s->task.n = 0; \ |
|||
L2_task_delay_over();\ |
|||
} \ |
|||
break;\ |
|||
default : \ |
|||
break; |
|||
|
|||
|
|||
|
|||
//在等待的过程中设置间隔时间,定时调用funxx
|
|||
//这样在等待的空闲时间可以定时显示一些心跳信息和
|
|||
//执行心跳功能
|
|||
|
|||
#define L2_task_switch_fun_idelay(invent,ch) L2_task_switch_default_idelay() |
|||
#define L2_task_switch_fun_idelay0000(chhh,invent,funxx); \ |
|||
case D_task_Tdelay:\ |
|||
if (s_nos_tick.t_10ms >= s->task.n)\ |
|||
{\ |
|||
L2_task_delay_over();\ |
|||
}else\ |
|||
{\ |
|||
L2_time_beat_heart_fun(chhh,invent,funxx);\ |
|||
}\ |
|||
break; \ |
|||
case D_task_Cdelay:\ |
|||
s->task.n--; \ |
|||
if (s->task.n == 0) \ |
|||
{ \ |
|||
s->task.n = 0; \ |
|||
L2_task_delay_over();\ |
|||
} \ |
|||
break;\ |
|||
default : \ |
|||
break; |
|||
|
|||
|
|||
|
|||
|
|||
//在等待的过程中设置间隔时间,定时显示字符ch
|
|||
//这样在等待的空闲时间可以定时显示一些待机信息ch
|
|||
// 通过ch表明目前运行的阶段和心跳信息
|
|||
#define L2_task_switch_flag_idelay(invent,ch) L2_task_switch_default_idelay() |
|||
#define L2_task_switch_flag_idelay000(invent,ch); \ |
|||
case D_task_Tdelay:\ |
|||
if (s_nos_tick.t_10ms >= s->task.n)\ |
|||
{\ |
|||
L2_task_delay_over();\ |
|||
}else\ |
|||
{\ |
|||
L2_time_beat_heart(D_TBH_ch0,invent,ch);\ |
|||
}\ |
|||
break; \ |
|||
case D_task_Cdelay:\ |
|||
s->task.n--; \ |
|||
if (s->task.n == 0) \ |
|||
{ \ |
|||
s->task.n = 0; \ |
|||
L2_task_delay_over();\ |
|||
} \ |
|||
break;\ |
|||
default : \ |
|||
break; |
|||
|
|||
|
|||
TTSS_Task_init, Highlight |
|||
TTSS_Task_step, Highlight |
|||
TTSS_Task_end, Highlight |
|||
L2_task_go, Highlight |
|||
L1_task_Tdelay, Highlight |
|||
L1_task_Cdelay, Highlight |
|||
L2_task_go, Highlight |
|||
|
|||
|
|||
|
|||
|
|||
#endif |
|||
|
|||
|
|||
//if(delay_n+s_time0.t_10ms > 655340)
|
|||
//{s_time0.t_10ms = 0;}
|
|||
|
|||
//fix 201312 防止s_time0.t_10ms 溢出
|
|||
// 但是有风险
|
|||
//>>L2_task_delay一定要放在L2_task_go之后
|
|||
#define L1_task_Tdelay(delay_n) s->task.sh_next = s->task.sh;\ |
|||
s->task.sh = D_task_Tdelay;\ |
|||
s->task.n = (delay_n) + s_nos_tick.t_10ms; |
|||
|
|||
|
|||
//>>L2_task_delay一定要放在L2_task_go之后
|
|||
#define L1_task_Cdelay(delay_n) s->task.sh_next = s->task.sh;\ |
|||
s->task.sh = D_task_Cdelay;\ |
|||
s->task.n = (delay_n) |
|||
|
|||
|
|||
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<内部调用 s->task
|
|||
|
|||
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 外部调用
|
|||
#define L2_task_s_go_son(s,fun,pre) (s).task.sh = fun;(s).task.sh_pre = pre; |
|||
|
|||
#define L3_task_s_time_start(s,delay) (s).task.n = delay+s_nos_tick.t_1s; |
|||
#define L3_task_s_go(s,next) (s).task.sh = next; |
|||
#define L3_task_s_en(s,onf) (s).task.en = onf; |
|||
//L1_task_goout(s_task_music.task,D_task_close);
|
|||
|
|||
#define L3_task_s_busy(s) (D_task_close != (s).task.sh) |
|||
#define L3_task_s_free(s) (D_task_close == (s).task.sh) |
|||
|
|||
#define L3_task_s_step(s) ((s).task.sh) |
|||
|
|||
|
|||
#define D_task_uc unsigned char |
|||
#define D_task_ui unsigned int |
|||
///>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|||
#define TTSS_Task_init() switch(s->task.sh){\ |
|||
case D_task_init |
|||
|
|||
#define TTSS_Task_step(step) break;\ |
|||
case (step) |
|||
#define TTSS_step01(step) break;case (step) |
|||
#define TTSS_step02(step) break;case (step) |
|||
#define TTSS_step03(step) break;case (step) |
|||
#define TTSS_step04(step) break;case (step) |
|||
#define TTSS_step05(step) break;case (step) |
|||
#define TTSS_step06(step) break;case (step) |
|||
#define TTSS_step07(step) break;case (step) |
|||
#define TTSS_step08(step) break;case (step) |
|||
#define TTSS_step09(step) break;case (step) |
|||
#define TTSS_step10(step) break;case (step) |
|||
#define TTSS_step11(step) break;case (step) |
|||
#define TTSS_step12(step) break;case (step) |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
#define TTSS_Task_end(); break;\ |
|||
L2_task_switch_default_idelay();} |
|||
|
|||
|
|||
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
|||
|
|||
|
|||
extern void L1_task_init(TS_task *s); |
|||
|
|||
|
|||
|
|||
////>>>>>>>>>>>>>>>>>>>_s_task_test_>>>>>>>>>>>>>>>>>>>>>>>>
|
|||
|
|||
#ifdef D_debug_task_test |
|||
|
|||
struct _s_task_test_ |
|||
{ |
|||
TS_task task; |
|||
}; |
|||
extern struct _s_task_test_ s_task_test; |
|||
extern void L2_task_test_handle(struct _s_task_test_ *s); |
|||
extern void L2_task_test_init(void); |
|||
#else |
|||
|
|||
#define L2_task_test_handle(x); |
|||
#define L2_task_test_init(); |
|||
|
|||
#endif//#ifdef D_debug_task_test
|
|||
|
|||
////<<<<<<<<<<<<<<<<<<<_s_task_test_<<<<<<<<<<<<<<<<<<<<<<<<
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
#endif//_TASK_H_
|
|||
/*****************************************************
|
|||
*============================================================== |
|||
* HISTORY |
|||
* Below this line, this part is controlled by TSTS. DO NOT MODIFY!! |
|||
伪时间片嵌入式平台(Task Step by Step Turn by Turn Structure,简称TSTS) |
|||
*============================================================== |
|||
****************************************************************************/ |
|||
|
|||
|
|||
|
@ -0,0 +1,133 @@ |
|||
/*****************************************************************************
|
|||
* uart.h: Header file for NXP LPC17xx Family Microprocessors |
|||
* |
|||
* Copyright(C) 2017,SensorControl |
|||
* All rights reserved. |
|||
* |
|||
* History |
|||
* 2009.05.27 ver 1.00 Prelimnary version, first Release |
|||
*2017.01.10 ver 1.10 rename tick.h tick.c |
|||
2019.03.11 ver 1.30 定时时间更改为25ms 解决串口接收受干扰的情况 |
|||
****************************************************************************************/ |
|||
/*****************************************************
|
|||
*============================================================================ |
|||
* HISTORY |
|||
* Below this line, this part is controlled by TSTS. DO NOT MODIFY!! |
|||
伪时间片嵌入式平台(Task Step by Step Turn by Turn Structure,简称TSTS) |
|||
*============================================================================ |
|||
****************************************************************************/ |
|||
|
|||
#include "tick.h" |
|||
|
|||
|
|||
struct _s_nos_tick_ s_nos_tick; |
|||
|
|||
|
|||
|
|||
#ifdef D_use_tick_fum |
|||
void L1_tick_init(void) |
|||
{ |
|||
s_nos_tick.tp_count = 0; |
|||
|
|||
s_nos_tick.n_stamp = 0; |
|||
s_nos_tick.t1s_heatbeart= 0; |
|||
/*****
|
|||
s_nos_tick.t1s_flag[0] = 0; |
|||
s_nos_tick.t1s_flag[1] = 0; |
|||
s_nos_tick.t1s_flag[2] = 0; |
|||
s_nos_tick.t1s_flag[3] = 0; |
|||
s_nos_tick.t1s_flag[4] = 0; |
|||
s_nos_tick.t1s_flag[5] = 0; |
|||
if(L2_tick_time_interval(n_stamp,7*D_Tdelay_1s)) |
|||
{// 时间溢出
|
|||
|
|||
|
|||
L2_tick_time_stamp(s->t_stamp); |
|||
|
|||
|
|||
********/ |
|||
|
|||
s_nos_tick.t_10ms = 0; |
|||
s_nos_tick.t_1s = 0; |
|||
|
|||
/// s_nos_tick.flag_1s = 0;
|
|||
|
|||
/// s_nos_tick.t_n = 0;
|
|||
//s_nos_tick.tmp = 0;
|
|||
//L0_timer0_ONF(1);
|
|||
} |
|||
|
|||
/// 定时器调用 10ms 一个中断
|
|||
/// 定时器调用 25ms 一个中断
|
|||
void L1_tick_tick (void) |
|||
{ /// 65535*65535 /3600/24/365=139nian/s=1.39nian/10ms
|
|||
///相当于1.39年后t_10ms 溢出,对于电池供电的系统而言 完全可以满足
|
|||
// 4,294,836,225 = 65535*65535 ;3600*24*60*60 = 31,536,000秒/年
|
|||
s_nos_tick.tp_count++; |
|||
s_nos_tick.t_10ms ++;//D_led_D1_REV(); 20160522 验证
|
|||
if(s_nos_tick.t_10ms%D_TIMER0_1S_COUNT == 0) |
|||
{// 65535*65535/24/60/60/356/10 =12.7年
|
|||
s_nos_tick.t_1s ++;//// 65535*65535/24/60/60/356/10 =12.7年
|
|||
s_nos_tick.flag_1s2 = 1; |
|||
s_nos_tick.t1s_heatbeart = 1; |
|||
} |
|||
//<<<<<<<<<<<<<<<<<<<<<<
|
|||
} |
|||
#else |
|||
|
|||
#endif |
|||
|
|||
#if 0 |
|||
void L1_tick_tick (void) |
|||
{ |
|||
s_nos_tick.t_n++; |
|||
if (s_nos_tick.t_n >= D_TIMER0_10MS_COUNT)// 5500--- 100 10s--556
|
|||
/// s 5ms 65535*65535 /3600/24/365=139nian/s
|
|||
// 4,294,836,225 = 65535*65535 ;3600*24*60*60 = 31,536,000秒/年
|
|||
// fixme:此处 保留了一个百年bug:)
|
|||
{ |
|||
s_nos_tick.t_10ms ++;//D_led_D1_REV(); 20160522 验证
|
|||
if(s_nos_tick.t_10ms%D_TIMER0_1S_COUNT == 0) |
|||
{// 65535*65535/24/60/60/356/10 =12.7年
|
|||
s_nos_tick.t_1s ++;//
|
|||
|
|||
// led_red =~led_red;
|
|||
//s_nos_tick.t1s_flag[0] = 1;
|
|||
//s_nos_tick.t1s_flag[1] = 1;
|
|||
//s_nos_tick.t1s_flag[2] = 1;
|
|||
//s_nos_tick.t1s_flag[3] = 1;
|
|||
//s_nos_tick.t1s_flag[4] = 1;
|
|||
//s_nos_tick.t1s_flag[5] = 1;
|
|||
s_nos_tick.flag_1s = 1; |
|||
s_nos_tick.t1s_heatbeart = 1; |
|||
} |
|||
s_nos_tick.t_n = 0; |
|||
} |
|||
/*******************
|
|||
// 0.2mm 4/0.2 = 20 20/60s = 333ms/maicong
|
|||
// 0.2mm 60s 60 100 ms
|
|||
// 0.2 6000ms
|
|||
// 平时为1 水满一次为0
|
|||
// rain = 1;必须要做的初始化
|
|||
if(0 == rain) |
|||
{ |
|||
if(1 == s_rain.temp) |
|||
{// ````\___
|
|||
s_rain.pool = s_rain.t; |
|||
s_rain.all ++; |
|||
s_rain.t = 0; |
|||
} |
|||
s_rain.temp = 0; |
|||
}else |
|||
{ |
|||
s_rain.temp = 1; |
|||
} |
|||
s_rain.t ++; |
|||
|
|||
******/ |
|||
//<<<<<<<<<<<<<<<<<<<<<<
|
|||
} |
|||
|
|||
|
|||
#endif |
|||
|
@ -0,0 +1,210 @@ |
|||
/*****************************************************************************
|
|||
* uart.h: Header file for NXP LPC17xx Family Microprocessors |
|||
* |
|||
* Copyright(C) 2017,SensorControl |
|||
* All rights reserved. |
|||
* |
|||
* History |
|||
* 2009.05.27 ver 1.00 Prelimnary version, first Release |
|||
*2017.01.10 ver 1.10 rename tick.h tick.c |
|||
******************************************************************************/ |
|||
/*****************************************************
|
|||
*============================================================================ |
|||
* HISTORY |
|||
* Below this line, this part is controlled by TSTS. DO NOT MODIFY!! |
|||
伪时间片嵌入式平台(Task Step by Step Turn by Turn Structure,简称TSTS) |
|||
*============================================================================ |
|||
****************************************************************************/ |
|||
#ifndef __tick_H |
|||
#define __tick_H |
|||
#include "../clib/Type.h" |
|||
//#include "../bsp/type_hs.h"
|
|||
#include "../msp/time.h" |
|||
#define D_use_tick_fum |
|||
|
|||
|
|||
struct _s_nos_tick_ |
|||
{ |
|||
vU32 tp_count; //最后一次接收数据时间到目前的tick数量
|
|||
/// vU32 sys_clock;
|
|||
// vU32 t_n; // noos系统定时器最小技术单元
|
|||
vU32 t_10ms; // noos 系统定时器10m技术
|
|||
#ifdef D_use_tick_fum |
|||
|
|||
|
|||
//volatile INT32U t_100ms;
|
|||
vU32 t_1s; |
|||
/// vU32 t_10s;
|
|||
// vU32 t_60s;
|
|||
vU8 flag_1s; |
|||
vU8 flag_1s2; |
|||
/// volatile INT32U tmp;
|
|||
/// volatile INT32U time_left;
|
|||
/// volatile INT32U h;
|
|||
/// volatile INT32U m;
|
|||
vU32 n_stamp; |
|||
// vU32 t1s_flag[6]; //fixme: INT32U 根据不同的系统来决定
|
|||
//volatile unsigned char t1s_flag;
|
|||
/// vU8 ts_flag;
|
|||
vU32 n_stamp3; |
|||
#endif |
|||
vU8 t1s_heatbeart; //noos 系统定时器整秒时刻标志,需要软件清除
|
|||
}; |
|||
extern struct _s_nos_tick_ s_nos_tick; |
|||
|
|||
#ifdef D_timer0_10ms |
|||
//10ms 不能使用,10ms是最小颗粒时长,存在误差,无法使用
|
|||
#define D_Tdelay_ms D_TIMER0_10MS_COUNT//D_TIMER0_10MS_COUNT
|
|||
#define D_Tdelay_10ms 2 |
|||
#define D_Tdelay_20ms (2+D_Tdelay_ms) |
|||
#define D_Tdelay_30ms (3+D_Tdelay_ms) |
|||
#define D_Tdelay_40ms (4+D_Tdelay_ms) |
|||
#define D_Tdelay_50ms (5+D_Tdelay_ms) |
|||
#define D_Tdelay_60ms (6+D_Tdelay_ms) |
|||
|
|||
#define D_Tdelay_80ms (8+D_Tdelay_ms) |
|||
|
|||
|
|||
#define D_Tdelay_100ms (10+D_Tdelay_ms) |
|||
|
|||
#else |
|||
//10ms 不能使用,10ms是最小颗粒时长,存在误差,无法使用
|
|||
#define D_Tdelay_ms D_TIMER0_10MS_COUNT//D_TIMER0_10MS_COUNT
|
|||
#define D_Tdelay_10ms 1 |
|||
#define D_Tdelay_20ms (0+D_Tdelay_ms) |
|||
#define D_Tdelay_30ms (0+D_Tdelay_ms) |
|||
#define D_Tdelay_40ms (2+D_Tdelay_ms) |
|||
#define D_Tdelay_50ms (2+D_Tdelay_ms) |
|||
#define D_Tdelay_60ms (2+D_Tdelay_ms) |
|||
|
|||
#define D_Tdelay_80ms (3+D_Tdelay_ms) |
|||
|
|||
#define D_Tdelay_100ms (4+D_Tdelay_ms) |
|||
|
|||
#endif |
|||
|
|||
|
|||
#define D_Tdelay_200ms (D_Tdelay_100ms*2) |
|||
#define D_Tdelay_300ms (D_Tdelay_100ms*3) |
|||
#define D_Tdelay_400ms (D_Tdelay_100ms*4) |
|||
#define D_Tdelay_500ms (D_Tdelay_100ms*5) |
|||
|
|||
#define D_Tdelay_600ms (D_Tdelay_100ms*6) |
|||
#define D_Tdelay_700ms (D_Tdelay_100ms*7) |
|||
#define D_Tdelay_800ms (D_Tdelay_100ms*8) |
|||
#define D_Tdelay_900ms (D_Tdelay_100ms*9) |
|||
|
|||
|
|||
#define D_Tdelay_1s (D_Tdelay_100ms*10) |
|||
#define D_Tdelay_1s2 (D_Tdelay_100ms*12) |
|||
#define D_Tdelay_1s5 (D_Tdelay_100ms*15) |
|||
#define D_Tdelay_2s (D_Tdelay_100ms*20) |
|||
#define D_Tdelay_2s5 (D_Tdelay_100ms*25) |
|||
#define D_Tdelay_3s (D_Tdelay_100ms*30) |
|||
#define D_Tdelay_5s (D_Tdelay_100ms*50) |
|||
#define D_Tdelay_8s (D_Tdelay_100ms*80) |
|||
#define D_Tdelay_9s (D_Tdelay_100ms*90) |
|||
#define D_Tdelay_10s (D_Tdelay_100ms*100) |
|||
|
|||
#define D_Tdelay_1min (D_Tdelay_1s*60) |
|||
#define D_Tdelay_1h (D_Tdelay_1min*60) |
|||
#define D_Tdelay_1day (D_Tdelay_1h*24) |
|||
#define D_TIMER0_1S_COUNT 100 |
|||
//#define D_10mS 1//D_TIMER0_10MS_COUNT
|
|||
//#define D_100mS (D_10mS*10)
|
|||
//#define D_1S (D_10mS*100)
|
|||
|
|||
|
|||
|
|||
|
|||
//>> 定时器: 初始化 间隔时间到
|
|||
// L0_nos_tick10ms_start(s->times); 开始初始化s->times 以10ms为一个单位
|
|||
// if( L0_nos_tick10ms_interval(s->times) < 20)// s->times 执行了20次后,也就是 定时20*10m到达
|
|||
|
|||
|
|||
//必须配对
|
|||
#define L0_nos_tick10ms_start(start_n) start_n = s_nos_tick.t_10ms |
|||
#define L0_nos_tick10ms_interval(start_n) (s_nos_tick.t_10ms - start_n) |
|||
|
|||
|
|||
|
|||
#define L0_nos_tick1s_start(start_n) start_n = s_nos_tick.t_1s |
|||
#define L0_nos_tick1s_interval(start_n) (s_nos_tick.t_1s - start_n) |
|||
|
|||
|
|||
|
|||
//>>>//必须配对
|
|||
#define L2_tick_time_stamp(time_stamp) time_stamp = s_nos_tick.t_10ms; |
|||
#define L2_tick_time_interval(time_stamp,time_overflow) (( s_nos_tick.t_10ms - time_stamp) > time_overflow) |
|||
|
|||
|
|||
#define L3_tick_interval(x) L2_tick_time_interval(s_nos_tick.n_stamp,x) |
|||
#define L2_tick_stamp() L2_tick_time_stamp(s_nos_tick.n_stamp); |
|||
|
|||
|
|||
//>>>示例如下:
|
|||
#if 0 |
|||
{ |
|||
case D_task_init://
|
|||
Lc_print_buf(" \r\n YL_ init"); |
|||
s->step = D_AT; |
|||
L0_esp_open(); |
|||
L2_task_go(D_task_YL_ready); |
|||
s_uart0_rec.ok = 0; |
|||
L2_tick_time_stamp(s->t_stamp); |
|||
// L1_task_Tdelay(1*D_Tdelay_1s); //大约6s
|
|||
break; |
|||
case D_task_YL_ready: |
|||
if(1 == s_uart0_rec.ok) |
|||
{ |
|||
if(strstr(s_uart0_rec.array,"ready") != NULL) |
|||
{ |
|||
|
|||
Ldi_print("ready..\r\n"); |
|||
s->step = D_AT; |
|||
L2_task_go(D_task_YL_ask); |
|||
} |
|||
s_uart0_rec.ok = 0; |
|||
} |
|||
if(L2_tick_time_stamp(s->t_stamp,1*D_Tdelay_1s)) |
|||
{// 时间溢出
|
|||
L0_esp_close(); |
|||
Ldi_print("fail esp restart.\r\n"); |
|||
L2_task_go(D_task_init); |
|||
L1_task_Tdelay(2*D_Tdelay_1s); |
|||
} |
|||
break; |
|||
} |
|||
#endif |
|||
|
|||
// 他和t_10ms 关联,如果t_10ms递增为1时间隔为(D_TIMER0_10MS_COUNT*定时器间隔)
|
|||
/// #define D_TIMER0_10MS_COUNT 1 //定时器为 10ms一中断
|
|||
#ifdef D_use_tick_fum |
|||
extern void L1_tick_init(void); |
|||
extern void L1_tick_tick (void); |
|||
|
|||
#else |
|||
|
|||
|
|||
#define L1_tick_init() |
|||
#define L1_tick_tick() s_nos_tick.t_10ms ++; |
|||
|
|||
#endif |
|||
|
|||
|
|||
|
|||
//L2_time_beat_heart(D_TBH_ch1,2,'t')
|
|||
#define D_TBH_ch0 0 |
|||
#define D_TBH_ch1 1 |
|||
#define D_TBH_ch2 2 |
|||
#define D_TBH_ch3 3 |
|||
#define D_TBH_ch4 4 |
|||
#define D_TBH_ch5 5 |
|||
extern void L2_time_beat_heart(vU32 ch,U8 invent,U8 s); |
|||
//void L2_time_beat_heart_fun(INT32U ch,unsigned char invent,void *fun(void));
|
|||
extern void L2_time_beat_heart_fun(vU32 ch,U8 invent,void (*fun)(void)); |
|||
|
|||
#endif /* end __tick_H */ |
|||
/*****************************************************************************
|
|||
** End Of File |
|||
******************************************************************************/ |
@ -0,0 +1,448 @@ |
|||
//////////////////////////////////////////////////////////////////////////
|
|||
/// COPYRIGHT NOTICE
|
|||
/// Copyright (c) 2015, 传控科技
|
|||
/// All rights reserved.
|
|||
///
|
|||
/// @file main.c
|
|||
/// @brief main app
|
|||
///
|
|||
///(本文件实现的功能的详述)
|
|||
///
|
|||
/// @version 1.1 CCsens technology
|
|||
/// @author CC
|
|||
/// @date 20150102
|
|||
///
|
|||
///
|
|||
/// 修订说明:最初版本
|
|||
/// Modified by:
|
|||
/// Modified date:
|
|||
/// Version:
|
|||
/// Descriptions:
|
|||
|
|||
/*****************************************************************************
|
|||
update by cc @201800400 |
|||
针对多串口 和 单一串口 有区别 每个串口是独立的还是分开的有讲究 程序是复杂的还是软件应用简单是 |
|||
个需要平衡的事情. |
|||
|
|||
clib/clib.c: |
|||
公用的函数 和硬件无关 |
|||
放置串行模式(串口等其他通讯总线类的输出)输出的函数, |
|||
一些覆盖模式输出的(lcd等固屏输出的)的也可使用 |
|||
void Lc_print(void (*L0pf_send_uc)(char ww), char *dat,...) |
|||
----------------------------------------------------------------------------------------- |
|||
|
|||
----------------------------------------------------------------------------------------- |
|||
|
|||
-------------------------------------------------------------------------------------------- |
|||
msp/uartx.c 底层代码 和cpu相关 缓存发送也放在里面 |
|||
L0_UART0_Init |
|||
UART0_IRQHandler |
|||
L0_Usend_uc------UserDef |
|||
----------------------------------------------------------------------------------------- |
|||
********************************************************************************/ |
|||
#include "uart0.h" |
|||
//#include "uart2.h"
|
|||
//#include "uart3.h"
|
|||
//#include "uart4.h"
|
|||
#include <stdio.h> |
|||
#include "../ctask/tick.h" |
|||
#include "../app/common.h" |
|||
#include "../msp/time.h" |
|||
|
|||
// TS_Handle_PH1 volatile s_uart0_rec;
|
|||
// TS_Handle_PH1A volatile s_uart0_rec;
|
|||
TS_Handle_PH4 volatile s_uart0_rec; |
|||
|
|||
///struct _s_uart0_send_buf_ ts_uart_send_shop;
|
|||
//struct _s_uart0_send_buf_ ts_uart_send_depot;
|
|||
volatile Ts_uart_send_buf ts_uart_send_shop; |
|||
////volatile Ts_uart_send_buf ts_uart_send_depot;
|
|||
|
|||
#if(MainFre_5M == D_sys_MainFre) |
|||
void L0_uart0_init32K_290BPS(void) //290bps@32kHz
|
|||
{//定时器2 16位重载 作为串口波特率
|
|||
SCON = 0x50; //8位数据,可变波特率
|
|||
AUXR |= 0x01; //串口1选择定时器2为波特率发生器
|
|||
BITN_1(AUXR, BITN5);// f/2
|
|||
T2L = 0xFE; //设定定时初值
|
|||
T2H = 0xFF; //设定定时初值 /// 32K 280---290BPS
|
|||
AUXR |= 0x10; //启动定时器2
|
|||
} |
|||
|
|||
|
|||
#elif(MainFre_27M == D_sys_MainFre) |
|||
#elif(MainFre_22M == D_sys_MainFre) |
|||
#if(BRT_115200 == D_uart0_BRT) |
|||
void L0_uart0_init(void) //115200bps@22.1184MHz
|
|||
{//定时器2 16位重载 作为串口波特率
|
|||
SCON = 0x50; //8位数据,可变波特率
|
|||
AUXR |= 0x01; //串口1选择定时器2为波特率发生器
|
|||
AUXR &= 0xFB; //定时器2时钟为Fosc/12,即12T
|
|||
T2L = 0xFC; //设定定时初值
|
|||
T2H = 0xFF; //设定定时初值
|
|||
AUXR |= 0x10; //启动定时器2
|
|||
} |
|||
|
|||
#elif(BRT_4800 == D_uart0_BRT) |
|||
void L0_Uart0_Init(void) //4800bps@22.1184MHz
|
|||
{ |
|||
SCON = 0x50; //8位数据,可变波特率
|
|||
AUXR |= 0x01; //串口1选择定时器2为波特率发生器
|
|||
AUXR |= 0x04; //定时器2时钟为Fosc,即1T
|
|||
T2L = 0x80; //设定定时初值
|
|||
T2H = 0xFB; //设定定时初值
|
|||
AUXR |= 0x10; //启动定时器2
|
|||
} |
|||
#elif(BRT_SIM == D_uart0_BRT) |
|||
void L0_uart0_init(void) |
|||
{ |
|||
SCON = 0x50; /* SCON: mode 1, 8-bit UART, enable rcvr */ |
|||
TMOD |= 0x20; /* TMOD: timer 1, mode 2, 8-bit reload */ |
|||
TH1 = 221; /* TH1: reload value for 1200 baud @ 16MHz */ |
|||
TR1 = 1; /* TR1: timer 1 run */ |
|||
TI = 1; /* TI: set TI to send first char of UART */ |
|||
EA = 1; |
|||
AUXR = 0x40; |
|||
// TI = 0;
|
|||
RI = 0; |
|||
D_uart0_ES_INT(1); //打开串口中断
|
|||
} |
|||
#endif |
|||
|
|||
#else ///MainFre_11M
|
|||
|
|||
#if(BRT_115200 == D_uart0_BRT && SBIT_1 == D_uart0_SBIT) |
|||
void L0_uart0_init(void) //115200bps@11.0592MHz
|
|||
{ |
|||
SCON = 0x50; //8位数据,可变波特率
|
|||
AUXR |= 0x01; //串口1选择定时器2为波特率发生器
|
|||
AUXR &= 0xFB; //定时器2时钟为Fosc/12,即12T
|
|||
T2L = 0xFE; //设定定时初值
|
|||
T2H = 0xFF; //设定定时初值
|
|||
AUXR |= 0x10; //启动定时器2
|
|||
} |
|||
#elif(BRT_19200 == D_uart0_BRT && SBIT_1 == D_uart0_SBIT) |
|||
void L0_uart0_init(void) //19200@11.0592MHz
|
|||
{ |
|||
xxxx |
|||
SCON = 0x50; //8位数据,可变波特率
|
|||
AUXR |= 0x01; //串口1选择定时器2为波特率发生器
|
|||
AUXR |= 0x04; //定时器2时钟为Fosc,即1T
|
|||
T2L = 0x70; //设定定时初值
|
|||
T2H = 0xFF; //设定定时初值
|
|||
AUXR |= 0x10; //启动定时器2
|
|||
} |
|||
#elif(BRT_19200 == D_uart0_BRT && SBIT_2 == D_uart0_SBIT) |
|||
void L0_uart0_init(void) //19200@11.0592MHz
|
|||
{ |
|||
//使用第9位数据模拟1个停止位,可变波特率;SM2=0, TB8=1(第9bit总为1模拟1个停止位)
|
|||
SCON = 0xD8; |
|||
AUXR |= 0x01; //串口1选择定时器2为波特率发生器
|
|||
AUXR |= 0x04; //定时器2时钟为Fosc,即1T
|
|||
T2L = 0x70; //设定定时初值
|
|||
T2H = 0xFF; //设定定时初值
|
|||
AUXR |= 0x10; //启动定时器2
|
|||
} |
|||
#elif (BRT_9600 == D_uart0_BRT) |
|||
void L0_uart0_init(void) //9600bps@11.0592MHz
|
|||
{ |
|||
SCON = 0x50; //8位数据,可变波特率
|
|||
AUXR |= 0x01; //串口1选择定时器2为波特率发生器
|
|||
AUXR &= 0xFB; //定时器2时钟为Fosc/12,即12T
|
|||
T2L = 0xE8; //设定定时初值
|
|||
T2H = 0xFF; //设定定时初值
|
|||
AUXR |= 0x10; //启动定时器2
|
|||
} |
|||
#endif |
|||
#endif//D_sys_MainFre)
|
|||
void L1_uart0_buf_init(void) |
|||
{ |
|||
/// ts_uart_send_depot.p = ts_uart_send_depot.buf;
|
|||
ts_uart_send_shop.now = 0; |
|||
s_uart0_rec.head = 0; |
|||
s_uart0_rec.ok = 0; |
|||
s_uart0_rec.num = 0; |
|||
// L1_s2b_PH4_init(&s_uart0_rec,G.p.slaver_id);
|
|||
// s_uart0_rec.sp = s_uart0_rec.buf;
|
|||
// s_uart0_rec.cmd = 0;
|
|||
// head_0 = D_CMD_Filter1_ff;
|
|||
// s_uart0_rec.head_1 = D_CMD_Filter2_fe;
|
|||
// s_uart0_rec.sp = (U8*)&(s_uart0_rec.ts_ccmodbus);
|
|||
|
|||
L0_uart0_init(); |
|||
|
|||
// L0_uart0_init();
|
|||
BITN_0(P3M1,BITN1);BITN_1(P3M0,BITN1);/// p31 01 tuiwan
|
|||
|
|||
ts_uart_send_shop.ok = D_ready; |
|||
|
|||
D_uart0_ES_INT(1); //打开串口中断
|
|||
|
|||
} |
|||
//115200 0.1ms /Byte 115200/4800=23 0.1*23=2.3ms
|
|||
/// 4800 uartb波形 2.1ms 一个数据 b8s 共10bits 1000ms 发送480个Bytes 大约就是2.1ms 一个数据
|
|||
|
|||
//// ````\_b_|___________________________/``s`|```2.1ms 0x00 sscom 测试
|
|||
|
|||
//// s 1 1 1 1 1 1 1 0 b11111111s
|
|||
|
|||
//// ````\_b_/```````````````````````````|``s`|```200us 0xff
|
|||
|
|||
//// ````\_b_|__/```\__/```\__/```\__/```|``s`|```1.9ms`\0xaa
|
|||
//// b 1 0 1 0 1 0 1 0 b10101010s
|
|||
|
|||
////
|
|||
//// ````\_b_|__/```\__/```\__/```\__/```|``s`|```1.9ms`\0xaa
|
|||
//// b 1 0 1 0 1 0 1 0 b10101010s
|
|||
|
|||
/// 1.9ms`\0xaa 0xaa 0xaa
|
|||
//// ````\_b_|__/```\__/```\__/```\__/```|``s`|\_b_|__/```\__/```\__/```\__/```|``s`|\_b_|__/```\__/```\__/```\__/```|``s`|
|
|||
//// b 1 0 1 0 1 0 1 0 s b 1 0 1 0 1 0 1 0 s b 1 0 1 0 1 0 1 0 s
|
|||
|
|||
|
|||
//// ````\_200us_/`````0xff
|
|||
//// ````\_200us_/`````0xff
|
|||
void L0_uart0_uc(U8 ww) |
|||
{ |
|||
L0_uart0_sendArray(&ww,1); |
|||
} |
|||
extern void L2_waitFree_uart0(void); |
|||
|
|||
|
|||
#define D_waitFree_uart0() L2_waitFree_uart0() |
|||
|
|||
|
|||
/*********
|
|||
while(ts_uart_send_shop.ok != D_ready)\ |
|||
{\ |
|||
if(ts_uart_send_shop.over ++ > 600000)\ |
|||
{\ |
|||
break;\ |
|||
}\ |
|||
}\ |
|||
*********************/ |
|||
void L0_uart0_us(vU32 ww) |
|||
{ |
|||
U_U16 uStemp; |
|||
uStemp.word = ww; |
|||
L0_uart0_uc(uStemp.BYTE2.h); |
|||
L0_uart0_uc(uStemp.BYTE2.l); |
|||
} |
|||
void L0_uart0_ul(vU32 ww) |
|||
{ |
|||
L0_uart0_uc(ww >> 24 & 0xFF); |
|||
L0_uart0_uc(ww >> 16 & 0xFF); |
|||
L0_uart0_uc(ww >> 8 & 0xFF); |
|||
L0_uart0_uc(ww >> 0 & 0xFF); |
|||
} |
|||
void L0_uart0_uchex(U8 ww) |
|||
{ |
|||
D_waitFree_uart0(); |
|||
ts_uart_send_shop.buf3[0] = cguHex2Char[D_uc_high(ww)][1]; |
|||
ts_uart_send_shop.buf3[1] = cguHex2Char[D_uc_low(ww)][1]; |
|||
L0_uart0_sendArray(ts_uart_send_shop.buf3,2); |
|||
} |
|||
|
|||
// void L0_uart0_ushex(U16 ww)
|
|||
// {
|
|||
// L0_uart0_uchex(ww >> 8 & 0xFF);
|
|||
// L0_uart0_uchex(ww >> 0 & 0xFF);
|
|||
// }
|
|||
|
|||
void L0_uart0_ulhex(U32 ww) |
|||
{ |
|||
L0_uart0_uchex(ww >> 24 & 0xFF); |
|||
L0_uart0_uchex(ww >> 16 & 0xFF); |
|||
L0_uart0_uchex(ww >> 8 & 0xFF); |
|||
L0_uart0_uchex(ww >> 0 & 0xFF); |
|||
} |
|||
|
|||
void L0_uart0_uldec(U32 ww) |
|||
{ |
|||
L0_uart0_uc(ww / 1000000 % 10 + '0'); |
|||
L0_uart0_uc(ww / 100000 % 10 + '0'); |
|||
L0_uart0_uc(ww / 10000 % 10 + '0'); |
|||
L0_uart0_uc(ww / 1000 % 10 + '0'); |
|||
L0_uart0_uc(ww / 100 % 10 + '0'); |
|||
L0_uart0_uc(ww / 10 % 10 + '0'); |
|||
L0_uart0_uc(ww / 1 % 10 + '0'); |
|||
} |
|||
|
|||
/**********
|
|||
void L0_uart0_uc_debug(U8 ww) |
|||
{ |
|||
L0_uart0_sendArray(&ww,1); |
|||
while(0 != ts_uart_send_shop.now){} |
|||
} |
|||
|
|||
void L0_uart0_ushex(vU16 ww,U8 hex) |
|||
{ |
|||
U8 buf3[4]; |
|||
U_F16 k; |
|||
k.us = ww; |
|||
if(16 == hex ) |
|||
{ |
|||
buf3[0] = cguHex2Char[D_uc_high(k.BYTE2.H)][1]; |
|||
buf3[1] = cguHex2Char[D_uc_low(k.BYTE2.H)][1]; |
|||
buf3[2] = cguHex2Char[D_uc_high(k.BYTE2.L)][1]; |
|||
buf3[3] = cguHex2Char[D_uc_low(k.BYTE2.L)][1]; |
|||
L0_uart0_sendArray(buf3,4); |
|||
|
|||
}else if(2 == hex) |
|||
{ |
|||
buf3[0] = (k.BYTE2.H); |
|||
buf3[1] = (k.BYTE2.L); |
|||
L0_uart0_sendArray(buf3,2); |
|||
}else |
|||
{ |
|||
|
|||
buf3[0] = 0x55; |
|||
buf3[1] = 0x66; |
|||
|
|||
L0_uart0_sendArray(buf3,2); |
|||
|
|||
} |
|||
} |
|||
k.us = 0x1234 |
|||
uc |
|||
[0]=0x12 |
|||
[1]=0x34 |
|||
byte2 |
|||
H=0x12 |
|||
L=0x34 |
|||
|
|||
**********/ |
|||
|
|||
void L0_uart0_ushex(vU16 ww,U8 hex) |
|||
{ |
|||
U_F16 k; |
|||
k.us = ww; |
|||
D_waitFree_uart0(); |
|||
if(16 == hex ) |
|||
{ |
|||
ts_uart_send_shop.buf3[0] = cguHex2Char[D_uc_high(k.BYTE2.H)][1]; |
|||
ts_uart_send_shop.buf3[1] = cguHex2Char[D_uc_low(k.BYTE2.H)][1]; |
|||
ts_uart_send_shop.buf3[2] = cguHex2Char[D_uc_high(k.BYTE2.L)][1]; |
|||
ts_uart_send_shop.buf3[3] = cguHex2Char[D_uc_low(k.BYTE2.L)][1]; |
|||
L0_uart0_sendArray(ts_uart_send_shop.buf3,4); |
|||
|
|||
} |
|||
|
|||
|
|||
/****************
|
|||
else if(2 == hex) |
|||
{ |
|||
ts_uart_send_shop.buf3[0] = (k.BYTE2.H); |
|||
ts_uart_send_shop.buf3[1] = (k.BYTE2.L); |
|||
L0_uart0_sendArray(ts_uart_send_shop.buf3,2); |
|||
}else |
|||
{ |
|||
ts_uart_send_shop.buf3[0] = 0x55; |
|||
ts_uart_send_shop.buf3[1] = 0x66; |
|||
L0_uart0_sendArray(ts_uart_send_shop.buf3,2); |
|||
} |
|||
|
|||
*/ |
|||
} |
|||
void L2_waitFree_uart0(void) |
|||
{ |
|||
while(ts_uart_send_shop.ok != D_ready) |
|||
{ |
|||
if(ts_uart_send_shop.over ++ > 600000) |
|||
{ |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
|
|||
void L0_uart0_sendArray(U8 *buf,U16 len) |
|||
{ |
|||
//D_485_TX(); //切换到输出状态
|
|||
|
|||
D_waitFree_uart0(); // P31 = 1;
|
|||
ts_uart_send_shop.over = 0; |
|||
ts_uart_send_shop.p = buf; |
|||
ts_uart_send_shop.max = len; |
|||
ts_uart_send_shop.now = 1; |
|||
ts_uart_send_shop.ok = D_clear; |
|||
L0_uart0_set(ts_uart_send_shop.p[0]); |
|||
} |
|||
|
|||
|
|||
/*************************************************
|
|||
UART 中断 |
|||
*************************************************/ |
|||
void INTERRUPT_UART(void) interrupt D_SERVE_UART// using 2
|
|||
{ |
|||
NOP(); NOP(); NOP(); |
|||
if(L0_uart0_IntRI()) //如果是U0接收中断
|
|||
{ |
|||
L0_uart0_IntRIClear(); //清除接收中断标志
|
|||
//s_nos_tick.tp_count = 0;
|
|||
L0_timer1_reset(); |
|||
s_uart0_rec.reg = L0_uart0_get(); |
|||
L1_s2b_PH4(&s_uart0_rec); |
|||
} |
|||
if(L0_uart0_IntTI()) //如果是U0发送中断
|
|||
{ |
|||
L0_uart0_IntTIClear(); //清除发送中断标志
|
|||
if(ts_uart_send_shop.max != ts_uart_send_shop.now) |
|||
{ |
|||
L0_uart0_set(ts_uart_send_shop.p[ts_uart_send_shop.now]); |
|||
ts_uart_send_shop.now ++; |
|||
} |
|||
else |
|||
{ |
|||
ts_uart_send_shop.ok = D_ready; |
|||
ts_uart_send_shop.max = 0; |
|||
ts_uart_send_shop.now = 0;//可以发送下一个数据
|
|||
// P31 = 0;
|
|||
//切换到接收状态
|
|||
//D_485_RX();
|
|||
} |
|||
} |
|||
else |
|||
{ |
|||
//其他中断
|
|||
} |
|||
NOP(); NOP(); NOP(); |
|||
} |
|||
|
|||
#if 1 |
|||
void timer1_isrHanddle (void) interrupt D_ISR_timer1 |
|||
{//
|
|||
TF1 = 0; |
|||
//s_nos_tick.uart0_free = 1;
|
|||
if(s_uart0_rec.head == 1) //收到一条协议
|
|||
{ |
|||
s_uart0_rec.head = 0; |
|||
P10 ^= 1; |
|||
if(s_uart0_rec.ok == 0) |
|||
{ |
|||
s_uart0_rec.ok = 1; |
|||
//Lc_buf_copy_uc();
|
|||
} |
|||
} |
|||
} |
|||
|
|||
#else |
|||
|
|||
void timer1_isrHanddle (void) interrupt D_ISR_timer1 |
|||
{//
|
|||
TF1 = 0; |
|||
//s_nos_tick.uart0_free = 1;
|
|||
if(s_uart0_rec.head == 1) //收到一条协议
|
|||
{ |
|||
s_uart0_rec.head = 0; |
|||
s_uart0_rec.ok = 1; |
|||
L3_task_uart0_modbus_handler(&s_uart0_rec); |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
#endif |
|||
|
|||
|
|||
|
|||
|
@ -0,0 +1,152 @@ |
|||
//////////////////////////////////////////////////////////////////////////
|
|||
/// COPYRIGHT NOTICE
|
|||
/// Copyright (c) 2015, 传控科技
|
|||
/// All rights reserved.
|
|||
///
|
|||
/// @file main.c
|
|||
/// @brief main app
|
|||
///
|
|||
///(本文件实现的功能的详述)
|
|||
///
|
|||
/// @version 1.1 CCsens technology
|
|||
/// @author CC
|
|||
/// @date 20150102
|
|||
///
|
|||
///
|
|||
/// 修订说明:最初版本
|
|||
/// Modified by: cc
|
|||
/// Modified date: 20190222
|
|||
/// Version:
|
|||
/// Descriptions: 中断的now和max调整类型 可以支持int型的数据一次发送,前提是指向已有的数组
|
|||
//////////////////////////////////////////////////////////////////////////
|
|||
/*****************************************************************************
|
|||
update by cc @201700110 |
|||
针对多串口 和 单一串口 有区别 每个串口是独立的还是分开的有讲究 程序是复杂的还是软件应用简单是 |
|||
个需要平衡的事情. |
|||
|
|||
clib/clib.c: |
|||
公用的函数 和硬件无关 |
|||
放置串行模式(串口等其他通讯总线类的输出)输出的函数, |
|||
一些覆盖模式输出的(lcd等固屏输出的)的也可使用 |
|||
void Lc_print(void (*L0pf_send_uc)(char ww), char *dat,...) |
|||
----------------------------------------------------------------------------------------- |
|||
uartcom/Uprotocol2app |
|||
协议到应用 |
|||
为了适应不同的通讯协议需要不同的uart口来对应 和应用相关 |
|||
|
|||
typedef struct _ts_lcm_pro_; 应用协议包的定义? LCM的协议------------ |
|||
L3_UARTcom0_exp_protocol 解析应用协议 |
|||
----------------------------------------------------------------------------------------- |
|||
uartcom/urec2protocol: 接收到的数据放入到指向特定协议的缓存中,和协议的格式有关 一般分为 标头式或者标尾式 |
|||
公用的串口通讯定义 |
|||
struct _s_uart_rec_ 的公共协议包(关键的结构体)的声明------struct _s_uart_rec_ |
|||
void L1_uart_2buf(struct _s_uart_rec_ *p)串行数据保存到指向特定协议的缓冲中 |
|||
-------------------------------------------------------------------------------------------- |
|||
msp/uartx.c 底层代码 和cpu相关 缓存发送也放在里面 |
|||
L0_UART0_Init |
|||
UART0_IRQHandler |
|||
L0_Usend_uc------UserDef |
|||
----------------------------------------------------------------------------------------- |
|||
********************************************************************************/ |
|||
|
|||
|
|||
#ifndef _uart0_H |
|||
#define _uart0_H |
|||
#include "../bsp/bsp_config.h" |
|||
#include "../clib/type.h" |
|||
//#include "../debug/debug_drv.h"
|
|||
//#include "../uartcom/urec2protocol.h"
|
|||
//?include "../uartcom/uprotocol2app.h"
|
|||
#include "../tpc/tpc_modbus.h" |
|||
#define Ldi_print(x) Lc_print_buf(x) |
|||
//#include "../uartcom/UProtocol.h"
|
|||
#include "../ctask/task.h" |
|||
#include "../clib/Clib.h" |
|||
|
|||
|
|||
//extern struct _s_uart_rec_ s_uart0_rec;
|
|||
// extern TS_Handle_PH1 volatile s_uart0_rec;
|
|||
//extern TS_Handle_PH1A volatile s_uart0_rec;
|
|||
extern TS_Handle_PH4 s_uart0_rec; |
|||
|
|||
|
|||
///#define D_s_uart0_rec_close(); s_uart0_rec.ok = 2;// 关闭串口协议解析
|
|||
///#define D_s_uart0_rec_open(); s_uart0_rec.ok = 0;// 关闭串口协议解析
|
|||
#define D_uart0_free() (0 == ts_uart_send_shop.max) |
|||
#define D_uart0_busy() (0 != ts_uart_send_shop.max) |
|||
|
|||
|
|||
|
|||
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|||
////fixme:和cpu的程序容量息息相关
|
|||
#define D_send_buf_max 8 /// 9600bps = 10000bps = 1000 Bps = 1Byte/ms
|
|||
/// 19200bps = 20000bps = 2000Bps = 2Byte/ms = 1Byte/0.5ms
|
|||
/// 128Bytes = 128*0.5ms = 64ms
|
|||
|
|||
#define D_send_buf2_max 6 |
|||
|
|||
typedef struct _ts_uart0_send_buf_ |
|||
{//8byte
|
|||
U8 num; //接收到的数目注意数据长度的范围
|
|||
U8 *p; |
|||
vU16 now; /// 当前buf所在的位置 0------(max-1)
|
|||
vU16 max; /// 当前buf的最大值,也就是需要发送的长度
|
|||
vU16 over; /// 当前buf的最大值,也就是需要发送的长度
|
|||
U8 ok; /// 当前buf的最大值,也就是需要发送的长度
|
|||
U8 buf[D_send_buf_max]; |
|||
/// U8 buf2[D_send_buf2_max];
|
|||
U8 buf3[D_send_buf2_max]; |
|||
//// U8 buf4[D_send_buf_max];
|
|||
/// U8 buf[D_send_buf_max + 1];//buffer 的第一位是 长度
|
|||
}Ts_uart_send_buf; |
|||
|
|||
|
|||
extern volatile Ts_uart_send_buf ts_uart_send_shop; |
|||
///extern volatile Ts_uart_send_buf ts_uart_send_depot;
|
|||
|
|||
|
|||
#define D_uart0_ES_INT(x) ES = (x) |
|||
|
|||
|
|||
#define L0_uart0_IntRI() (RI)//BITN_G(SCON,U0RI)
|
|||
#define L0_uart0_IntTI() (TI)//BITN_G(SCON,U0TI)
|
|||
#define L0_uart0_IntRIClear(); RI = 0;//BITN_0(SCON,U0RI)
|
|||
#define L0_uart0_IntTIClear(); TI = 0;//BITN_0(SCON,U0TI)
|
|||
#define L0_uart0_set(x) SBUF = (x); |
|||
#define L0_uart0_get() (SBUF) |
|||
//#define D_send_us(x) gRccUs01 = x;L0_uart0_uc(gRccUs01_H);L0_uart0_uc(gRccUs01_L);
|
|||
|
|||
#define D_send_ushex(x) L0_uart0_ushex(x,16);///Lc_delay_ms(2);//gRccUs01 = x;L0_uart0_uchex(gRccUs01_H);L0_uart0_uchex(gRccUs01_L);
|
|||
#define D_uart0_send_over() (D_ready == ts_uart_send_shop.ok) |
|||
|
|||
|
|||
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
|||
|
|||
void L1_uart0_buf_init(void); |
|||
|
|||
extern void L0_uart0_init(void); |
|||
extern void L0_uart0_init32K_290BPS(void); |
|||
|
|||
extern void L0_Uart0_Init4800(void) ; |
|||
|
|||
extern void L0_uart0_uchex(U8 ww); |
|||
|
|||
extern void L0_uart0_ulhex(vU32 ww); |
|||
|
|||
extern void L0_uart0_ul(vU32 ww); |
|||
extern void L0_uart0_sendstr(U8 *str); |
|||
extern void L0_uart0_0d0a(void); |
|||
extern void L0_uart0_uc(U8 ww); |
|||
extern void L0_uart0_uc_debug(U8 ww); |
|||
extern void L0_uart0_us(vU32 ww); |
|||
extern void L0_uart0_ushex(vU16 ww,U8 hex); |
|||
extern void L0_uart0_uldec(U32 ww); |
|||
|
|||
///////////////////////////////////////////////////////////////
|
|||
extern void L0_uart0_sendArray(U8 *buf,U16 len); |
|||
extern void L0_uart0_sendbuf(void); |
|||
///extern void L0_uart0_sendArraylong(U8 *buf,U16 usStart,U16 usEnd);
|
|||
|
|||
#endif //#ifndef _uart0_H
|
|||
|
|||
|
@ -0,0 +1,170 @@ |
|||
////////////////////////////////////////////////////////////////////////////
|
|||
///@copyright Copyright (c) 2018, 传控科技 All rights reserved.
|
|||
///-------------------------------------------------------------------------
|
|||
/// @file msp_eeprom.c
|
|||
/// @brief msp @ driver config
|
|||
///-------------------------------------------------------------------------
|
|||
/// @version 1.0
|
|||
/// @author CC
|
|||
/// @date 20190106
|
|||
/// @note cc_AS_stc02 由stc-isp v6.0860
|
|||
//////////////////////////////////////////////////////////////////////////////
|
|||
#include "msp_eeprom.h" |
|||
|
|||
#include "../tpc/tpc_uart.h" |
|||
|
|||
|
|||
#define WT_30M 0x80 |
|||
#define WT_24M 0x81 |
|||
#define WT_20M 0x82 |
|||
#define WT_12M 0x83 |
|||
#define WT_6M 0x84 |
|||
#define WT_3M 0x85 |
|||
#define WT_2M 0x86 |
|||
#define WT_1M 0x87 |
|||
|
|||
|
|||
U_F16 uf_ee_add; |
|||
|
|||
|
|||
void L0_Iap_Idle() |
|||
{ |
|||
IAP_CONTR = 0; //关闭IAP功能
|
|||
IAP_CMD = 0; //清除命令寄存器
|
|||
IAP_TRIG = 0; //清除触发寄存器
|
|||
IAP_ADDRH = 0x80; //将地址设置到非IAP区域
|
|||
IAP_ADDRL = 0; |
|||
} |
|||
|
|||
char L0_Iap_Read(vU16 addr) |
|||
{ |
|||
char dat; |
|||
|
|||
IAP_CONTR = WT_12M; //使能IAP
|
|||
IAP_CMD = 1; //设置IAP读命令
|
|||
IAP_ADDRL = addr; //设置IAP低地址
|
|||
IAP_ADDRH = addr >> 8; //设置IAP高地址
|
|||
IAP_TRIG = 0x5a; //写触发命令(0x5a)
|
|||
IAP_TRIG = 0xa5; //写触发命令(0xa5)
|
|||
_nop_(); |
|||
dat = IAP_DATA; //读IAP数据
|
|||
L0_Iap_Idle(); //关闭IAP功能
|
|||
|
|||
return dat; |
|||
} |
|||
|
|||
void L0_Iap_Program(vU16 addr, char dat) |
|||
{ |
|||
IAP_CONTR = WT_12M; //使能IAP
|
|||
IAP_CMD = 2; //设置IAP写命令
|
|||
IAP_ADDRL = addr; //设置IAP低地址
|
|||
IAP_ADDRH = addr >> 8; //设置IAP高地址
|
|||
IAP_DATA = dat; //写IAP数据
|
|||
IAP_TRIG = 0x5a; //写触发命令(0x5a)
|
|||
IAP_TRIG = 0xa5; //写触发命令(0xa5)
|
|||
_nop_(); |
|||
L0_Iap_Idle(); //关闭IAP功能
|
|||
} |
|||
|
|||
///每个扇区512字节
|
|||
///指定地址可以为当前扇区内的任意地址,都会完整擦除当前扇区
|
|||
void L0_Iap_Erase(vU16 addr) |
|||
{ |
|||
IAP_CONTR = WT_12M; //使能IAP
|
|||
IAP_CMD = 3; //设置IAP擦除命令
|
|||
IAP_ADDRL = addr; //设置IAP低地址
|
|||
IAP_ADDRH = addr >> 8; //设置IAP高地址
|
|||
IAP_TRIG = 0x5a; //写触发命令(0x5a)
|
|||
IAP_TRIG = 0xa5; //写触发命令(0xa5)
|
|||
_nop_(); //
|
|||
L0_Iap_Idle(); //关闭IAP功能
|
|||
} |
|||
|
|||
void L0_Iap_Program_array(vU16 addr,U8 *buf,U8 len) |
|||
{ |
|||
U8 i = 0; |
|||
for(i=0;i<len;i++) |
|||
{ |
|||
L0_Iap_Program(addr + i,buf[i]); |
|||
} |
|||
} |
|||
|
|||
void L0_Iap_Read_array(vU16 addr,U8 *buf,U8 len) |
|||
{ |
|||
U8 i = 0; |
|||
for(i=0;i<len;i++) |
|||
{ |
|||
buf[i] = L0_Iap_Read(addr + i); |
|||
} |
|||
} |
|||
|
|||
void L1_Iap_main(void) |
|||
{ |
|||
int i; |
|||
U16 addr = 0x00; |
|||
U8 buf[30]; |
|||
L0_Iap_Read_array(addr,buf,30); |
|||
L0_uart0_uc('^');Lc_delay_ms(2); |
|||
for(i=0;i<30;i++) |
|||
{ |
|||
L0_uart0_uchex(buf[i]); |
|||
Lc_delay_ms(2); |
|||
} |
|||
L0_uart0_uc('$'); |
|||
} |
|||
|
|||
#if 0 |
|||
void L1_Iap_main(void) |
|||
{ |
|||
int i; |
|||
U16 addr = 0x00; |
|||
U8 buf[10]; |
|||
|
|||
L0_Iap_Erase(addr); |
|||
L0_Iap_Program_array(addr,"abcdefg",7); |
|||
L0_Iap_Read_array(addr,buf,10); |
|||
|
|||
for(i=0;i<10;i++) |
|||
{ |
|||
Lc_delay_ms(2); |
|||
L0_uart0_uc(buf[i]); |
|||
} |
|||
|
|||
L0_Iap_Erase(addr + 0x200); |
|||
L0_Iap_Program_array(addr + 0x200,"ABCDEFG",7); |
|||
L0_Iap_Read_array(addr + 0x200,buf,10); |
|||
|
|||
for(i=0;i<10;i++) |
|||
{ |
|||
Lc_delay_ms(2); |
|||
L0_uart0_uc(buf[i]); |
|||
} |
|||
|
|||
#if 0 |
|||
for(i=0; i<0x1000; i++) |
|||
{ |
|||
L0_Iap_Program(i,0); |
|||
} |
|||
|
|||
for(i = 0;i < 0x1010; i++) |
|||
{ |
|||
//L0_uart0_uchex(i%256);
|
|||
L0_uart0_uchex(L0_Iap_Read(addr + i)); |
|||
|
|||
if(i==0x1000-1) |
|||
{ |
|||
Lc_delay_ms(100); |
|||
L0_uart0_uchex(i>>8 & 0xFF); |
|||
L0_uart0_uchex(i>>0 & 0xFF); |
|||
} |
|||
} |
|||
#endif |
|||
Lc_delay_ms(100); |
|||
L0_uart0_uc('%'); |
|||
|
|||
while(1); |
|||
} |
|||
#endif |
|||
|
|||
|
|||
|
@ -0,0 +1,47 @@ |
|||
//////////////////////////////////////////////////////////////////////////
|
|||
/// COPYRIGHT NOTICE
|
|||
/// Copyright (c) 2018, 传控科技
|
|||
/// All rights reserved.
|
|||
///
|
|||
/// @file msp_eeprom
|
|||
/// @brief msp_eeprom
|
|||
/// @info
|
|||
///(本文件实现的功能的详述)
|
|||
///
|
|||
/// @version 1.1 CCsens technology
|
|||
/// @author CC
|
|||
/// @date 20190106
|
|||
|
|||
//
|
|||
//////////////////////////////////////////////////////////////////////////
|
|||
|
|||
#ifndef _msp_eeprom_H_ |
|||
#define _msp_eeprom_H_ |
|||
|
|||
#include "../clib/type.h" |
|||
#include "../clib/clib.h" |
|||
#include "../ctask/tick.h" |
|||
|
|||
|
|||
///>>>端口位定义,可修改!!!!!!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|||
|
|||
#include "../cpu/stc_stc8a8k.h" |
|||
#include "../cpu/c51_macro.h" |
|||
#include "../bsp/bsp_config.h" |
|||
|
|||
|
|||
#include "uart0.h" |
|||
|
|||
extern void L3_eeprom_fun(U8 *pPara); |
|||
|
|||
///每个扇区512字节
|
|||
extern void L0_Iap_Erase(vU16 addr); |
|||
extern void L0_Iap_Program(vU16 addr, char dat); |
|||
extern char L0_Iap_Read(vU16 addr); |
|||
extern void L0_Iap_Program_array(vU16 addr,U8 *buf,U8 len); |
|||
extern void L0_Iap_Read_array(vU16 addr,U8 *buf,U8 len); |
|||
extern void L1_Iap_main(void); |
|||
|
|||
#endif// #ifndef _msp_eeprom_H_
|
|||
|
|||
|
@ -0,0 +1,49 @@ |
|||
|
|||
////////////////////////////////////////////////////////////////////////////
|
|||
///@copyright Copyright (c) 2018, 传控科技 All rights reserved.
|
|||
///-------------------------------------------------------------------------
|
|||
/// @file msp_eeprom.c
|
|||
/// @brief msp @ driver config
|
|||
///-------------------------------------------------------------------------
|
|||
/// @version 1.0
|
|||
/// @author CC
|
|||
/// @date 20190106
|
|||
/// @note cc_AS_stc02 由stc-isp v6.0860
|
|||
//////////////////////////////////////////////////////////////////////////////
|
|||
#include "msp_id.h" |
|||
#include "../app/common.h" |
|||
|
|||
void L0_id_get(U8 *id) |
|||
{ |
|||
U8 i = 0; |
|||
char *ID = (char idata *)0xf1; |
|||
for(i=0;i<MCU_ID_LEN;i++) |
|||
{ |
|||
id[i] = ID[i]; |
|||
} |
|||
} |
|||
|
|||
void L0_id_get_rom(U8 *id) |
|||
{ |
|||
U8 i = 0; |
|||
char *ID = (char code *)0x3ff9; |
|||
for(i=0;i<MCU_ID_LEN;i++) |
|||
{ |
|||
id[i] = ID[i]; |
|||
} |
|||
} |
|||
|
|||
|
|||
#if 1 |
|||
void L0_id_main(void) |
|||
{ |
|||
U8 i,id[MCU_ID_LEN]; |
|||
L0_id_get_rom(id); |
|||
for(i=0;i<MCU_ID_LEN;i++) |
|||
{ |
|||
L0_uart0_uchex(id[i]); |
|||
} |
|||
while(1); |
|||
} |
|||
#endif |
|||
|
@ -0,0 +1,40 @@ |
|||
//////////////////////////////////////////////////////////////////////////
|
|||
/// COPYRIGHT NOTICE
|
|||
/// Copyright (c) 2018, 传控科技
|
|||
/// All rights reserved.
|
|||
///
|
|||
/// @file msp_eeprom
|
|||
/// @brief msp_eeprom
|
|||
/// @info
|
|||
///(本文件实现的功能的详述)
|
|||
///
|
|||
/// @version 1.1 CCsens technology
|
|||
/// @author CC
|
|||
/// @date 20190106
|
|||
|
|||
//
|
|||
//////////////////////////////////////////////////////////////////////////
|
|||
|
|||
#ifndef _msp_id_H_ |
|||
#define _msp_id_H_ |
|||
|
|||
#include "../clib/type.h" |
|||
#include "../clib/clib.h" |
|||
#include "../ctask/tick.h" |
|||
|
|||
|
|||
///>>>端口位定义,可修改!!!!!!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|||
|
|||
#include "../cpu/stc_stc8a8k.h" |
|||
#include "../cpu/c51_macro.h" |
|||
#include "../bsp/bsp_config.h" |
|||
#include "uart0.h" |
|||
|
|||
extern void L0_id_get(U8 *id); |
|||
extern void L0_id_get_rom(U8 *id); |
|||
extern void L0_id_main(void); |
|||
|
|||
#endif// #ifndef _msp_eeprom_H_
|
|||
|
|||
|
|||
|
@ -0,0 +1,255 @@ |
|||
#include "Time.h" |
|||
|
|||
/*************初始化定时器0由 stc-isp v6.86L定时器计算器生成******************/ |
|||
#if(MainFre_5M == D_sys_MainFre) |
|||
#elif(MainFre_27M == D_sys_MainFre) |
|||
#elif(MainFre_22M == D_sys_MainFre) |
|||
void L0_timer0_Init(void) //25毫秒@22.1184MHz
|
|||
{ |
|||
AUXR &= 0x7F; //定时器时钟12T模式
|
|||
TMOD &= 0xF0; //设置定时器模式
|
|||
TL0 = 0x00; //设置定时初值
|
|||
TH0 = 0x4C; //设置定时初值
|
|||
TF0 = 0; //清除TF0标志
|
|||
TR0 = 1; //定时器0开始计时
|
|||
ET0 = 1; //add by cc
|
|||
} |
|||
|
|||
|
|||
/********************************************
|
|||
void L0_timer0_Init(void) //10毫秒@22.1184MHz
|
|||
{ |
|||
AUXR &= 0x7F; //定时器时钟12T模式
|
|||
TMOD &= 0xF0; //设置定时器模式
|
|||
TL0 = 0x00; //设置定时初值
|
|||
TH0 = 0xB8; //设置定时初值
|
|||
TF0 = 0; //清除TF0标志
|
|||
TR0 = 1; //定时器0开始计时
|
|||
ET0 = 1; //add by cc
|
|||
} |
|||
|
|||
void L0_timer0_Init_32k(void) //4fen@32kHz
|
|||
{ |
|||
AUXR &= 0x7F; //定时器时钟12T模式
|
|||
TMOD &= 0xF0; //设置定时器模式
|
|||
#if 0 |
|||
TL0 = 0x00; //设置定时初值
|
|||
TH0 = 0xB8; //设置定时初值/// 4m20s 71
|
|||
#else |
|||
TL0 = 0x00; //设置定时初值
|
|||
TH0 = 0xcc; //设置定时初值// ff 4s
|
|||
|
|||
|
|||
#endif |
|||
TF0 = 0; //清除TF0标志
|
|||
TR0 = 1; //定时器0开始计时
|
|||
ET0 = 1; //add by cc
|
|||
BITN_0(DR_who_wakeup, DRB_who_wakeup_timer0); /// 标志中断类型: 定时器
|
|||
} |
|||
****************************************************/ |
|||
|
|||
#else ///MainFre_11M
|
|||
void L0_timer0_Init(void) //10毫秒@11.0592MHz
|
|||
{ |
|||
AUXR &= 0x7F; //定时器时钟12T模式
|
|||
TMOD &= 0xF0; //设置定时器模式
|
|||
TL0 = 0x00; //设置定时初值
|
|||
TH0 = 0xDC; //设置定时初值
|
|||
TF0 = 0; //清除TF0标志
|
|||
TR0 = 1; //定时器0开始计时
|
|||
ET0 = 1; //add by cc
|
|||
} |
|||
|
|||
/********************************************
|
|||
void L0_timer0_Init(void) //25毫秒@11.0592MHz
|
|||
{ |
|||
AUXR &= 0x7F; //定时器时钟12T模式
|
|||
TMOD &= 0xF0; //设置定时器模式
|
|||
TL0 = 0x00; //设置定时初值
|
|||
TH0 = 0xA6; //设置定时初值
|
|||
TF0 = 0; //清除TF0标志
|
|||
TR0 = 1; //定时器0开始计时
|
|||
ET0 = 1; //add by cc
|
|||
} |
|||
****************************************************/ |
|||
#endif//D_sys_MainFre)
|
|||
|
|||
//10---87 10s
|
|||
/********************** Timer0中断函数************************/ |
|||
/// 和 L0_timer0_Init 关联,需要配置 bsp_config.h中的 D_sys_MainFre
|
|||
/// 默认10ms 作为TTSS系统的定时引擎
|
|||
void timer0_isrHanddle (void) interrupt D_ISR_timer0 |
|||
{//
|
|||
NOP(); NOP(); NOP(); |
|||
TF0 = 0; |
|||
#if 0 |
|||
/// 65535*65535 /3600/24/365=139nian/s=1.39nian/10ms
|
|||
///相当于1.39年后t_10ms 溢出,对于电池供电的系统而言 完全可以满足
|
|||
// 4,294,836,225 = 65535*65535 ;3600*24*60*60 = 31,536,000秒/年
|
|||
s_nos_tick.t_10ms ++;//D_led_D1_REV(); 20160522 验证
|
|||
|
|||
#else |
|||
|
|||
L1_tick_tick(); ///系统中的1sflag 和以10ms为颗粒的延时使用 为tdelay服务
|
|||
|
|||
#endif |
|||
/// BITN_1(DR_who_wakeup, DRB_who_wakeup_timer0);
|
|||
NOP(); NOP(); NOP(); |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
#if(MainFre_5M == D_sys_MainFre) |
|||
#elif(MainFre_27M == D_sys_MainFre) |
|||
#elif(MainFre_22M == D_sys_MainFre) |
|||
/******************************
|
|||
void L0_Timer1_Init(void) //35毫秒@22.1184MHz
|
|||
{///自动重载
|
|||
AUXR &= 0xFB; //定时器时钟12T模式
|
|||
T2L = 0x00; //设置定时初值
|
|||
T2H = 0x04; //设置定时初值
|
|||
AUXR |= 0x10; //定时器2开始计时
|
|||
|
|||
BITN_1(IE2, ET2);// IE2 = ET2; //使能定时器中断
|
|||
} |
|||
**********************************/ |
|||
#else ///MainFre_11M
|
|||
|
|||
void L0_timer1_Init_7ms(void) //7毫秒@11.0592MHz
|
|||
{ |
|||
AUXR &= 0xBF; //定时器时钟12T模式
|
|||
TMOD &= 0x0F; //设置定时器模式
|
|||
TL1 = 0xCD; //设置定时初值
|
|||
TH1 = 0xE6; //设置定时初值
|
|||
TF1 = 0; //清除TF1标志
|
|||
TR1 = 1; //定时器1开始计时
|
|||
ET1 = 1; //add by cc
|
|||
} |
|||
|
|||
void L0_timer1_Init_5ms(void) //5毫秒@11.0592MHz
|
|||
{//0x7F示波器测试大约40ms,led闪烁 肉眼可见
|
|||
AUXR &= 0xBF; //定时器时钟12T模式
|
|||
TMOD &= 0x0F; //设置定时器模式
|
|||
TL1 = 0x00; //设置定时初值
|
|||
TH1 = 0xEE; //设置定时初值
|
|||
TF1 = 0; //清除TF1标志
|
|||
TR1 = 1; //定时器1开始计时
|
|||
ET1 = 1; //add by cc
|
|||
} |
|||
|
|||
void L0_timer1_Init_1ms(void) //1毫秒@11.0592MHz
|
|||
{ |
|||
AUXR |= 0x40; //定时器时钟1T模式
|
|||
TMOD &= 0x0F; //设置定时器模式
|
|||
TL1 = 0xCD; //设置定时初值
|
|||
TH1 = 0xD4; //设置定时初值
|
|||
TF1 = 0; //清除TF1标志
|
|||
TR1 = 1; //定时器1开始计时
|
|||
ET1 = 1; //add by cc
|
|||
} |
|||
|
|||
void L0_timer1_Init(void) //600微秒@11.0592MHz
|
|||
{ |
|||
AUXR |= 0x40; //定时器时钟1T模式
|
|||
TMOD &= 0x0F; //设置定时器模式
|
|||
TL1 = 0x14; //设置定时初值
|
|||
TH1 = 0xE6; //设置定时初值
|
|||
TF1 = 0; //清除TF1标志
|
|||
TR1 = 1; //定时器1开始计时
|
|||
ET1 = 1; //add by cc
|
|||
} |
|||
|
|||
|
|||
//0x7F示波器测试大约40ms,led闪烁 肉眼可见
|
|||
void L0_timer1_reset(void) |
|||
{ |
|||
TR1 = 0; |
|||
TL1 = 0x14; //设置定时初值
|
|||
TH1 = 0xE6; //设置定时初值
|
|||
TR1 = 1; |
|||
TF1 = 0; |
|||
} |
|||
|
|||
#endif//D_sys_MainFre)
|
|||
|
|||
|
|||
#if 0 |
|||
void L0_Timer1Init(void) |
|||
{ |
|||
#if 0 |
|||
|
|||
//30毫秒@22.1184MHz
|
|||
AUXR &= 0xBF; //定时器时钟12T模式
|
|||
TMOD &= 0x0F; //设置定时器模式
|
|||
TMOD |= 0x10; //设置定时器模式
|
|||
TL1 = 0x00; //设置定时初值
|
|||
TH1 = 0x28; //设置定时初值
|
|||
TF1 = 0; //清除TF1标志
|
|||
#else |
|||
TMOD = 0x40; //外部计数模式
|
|||
TL1 = (0xff-10); |
|||
TH1 = 0xff; |
|||
|
|||
|
|||
#endif |
|||
// TR1 = 1; //定时器1开始计时
|
|||
L0_TIMER1_start(); |
|||
//L0_TIMER1_end();
|
|||
L0_TIMER1_isr_CLOSE(); |
|||
/// ET1 = 1; // add by cc 启动定时器1的中断
|
|||
} |
|||
|
|||
void L0_timer1_Init(void) //计数器1初始化
|
|||
{ |
|||
|
|||
TMOD = 0x40; //外部计数模式
|
|||
TL1 = 0x9c; |
|||
TH1 = 0xff; |
|||
// TR1 = 1; //启动定时器
|
|||
ET1 = 1; //使能定时器中断
|
|||
// EA = 1;
|
|||
} |
|||
#define L0_timer1_on(); TR1 = 1; //启动计数器
|
|||
#define L0_timer1_off(); TR1 = 0; //关闭计数器 //启动计数器
|
|||
|
|||
//10---87 10s
|
|||
/********************** Timer0中断函数************************/ |
|||
/// 和 L0_timer0_Init 关联,需要配置 bsp_config.h中的 D_sys_MainFre
|
|||
/// 默认10ms 作为TTSS系统的定时引擎
|
|||
void timer1_inr (void) interrupt 3 |
|||
{ |
|||
|
|||
/*******
|
|||
s_task_GC032A.usN ++; |
|||
s_task_GC032A.buf[s_task_GC032A.usN] = P1; |
|||
if(s_task_GC032A.usN < D_row_max) |
|||
{ |
|||
|
|||
}else |
|||
{ |
|||
s_task_GC032A.status = 1; |
|||
} |
|||
// task_handler.line_camera++;
|
|||
****************/ |
|||
} |
|||
|
|||
#endif |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
/******************************END*********************************/ |
|||
|
|||
|
|||
|
|||
|
@ -0,0 +1,55 @@ |
|||
#ifndef INIT_TIMER0_H |
|||
#define INIT_TIMER0_H |
|||
|
|||
#include "../clib/type.h" |
|||
|
|||
#include "../bsp/bsp_config.h" |
|||
#include "../ctask/tick.h" |
|||
|
|||
|
|||
extern void L0_timer1_Init(void); |
|||
extern void L0_timer1_reset(void); |
|||
extern void L0_timer1_off(void); |
|||
extern void L0_timer1_on(void); |
|||
extern void L0_Timer1Init(void); |
|||
extern void L0_timer0_Init(void); |
|||
extern void L0_timer0_Init_32k(void) ; |
|||
#define L0_timer0_open(x) TR0 = x //
|
|||
|
|||
// 他和t_10ms 关联,如果t_10ms递增为1时间隔为(D_TIMER0_10MS_COUNT*定时器间隔)
|
|||
//#define D_TIMER0_10MS_COUNT 1 //定时器为 10ms一中断
|
|||
|
|||
#define D_TIMER0_10MS_COUNT 1 //定时器为 10ms一中断
|
|||
|
|||
/****************
|
|||
|
|||
#if(MainFre_5M == D_sys_MainFre) |
|||
|
|||
#define D_Cdelay_200us 20 |
|||
#define D_Cdelay_1us 1 ////while p21翻转时测定 500k 2us 一个指令
|
|||
#elif(MainFre_22M == D_sys_MainFre) |
|||
|
|||
#define L0_delay_1us() Lc_delay_nop(2) // 5个nop() 100ns 50个nop() 1us (20)=10us (2)1.5us
|
|||
#define L0_delay_10us() Lc_delay_nop(20) // 5个nop() 100ns 50个nop() 1us (20)=10us (2)1.5us
|
|||
|
|||
#define D_Cdelay_1ms 500 |
|||
#define D_Cdelay_15ms 1200 |
|||
|
|||
|
|||
#define D_Cdelay_200us 20 |
|||
#define D_Cdelay_1us 1 |
|||
|
|||
#elif(MainFre_11M == D_sys_MainFre) |
|||
等待 |
|||
#define L0_delay_1us() NOP();NOP(); // 11.05926M
|
|||
|
|||
|
|||
#endif |
|||
**********/ |
|||
|
|||
|
|||
|
|||
#endif |
|||
|
|||
|
|||
|
@ -0,0 +1,77 @@ |
|||
|
|||
/*****************************************************************************
|
|||
update by cc @201501101001 |
|||
针对多串口 和 单一串口 有区别 每个串口是独立的还是分开的有讲究 程序是复杂的还是软件应用简单是 |
|||
个需要平衡的事情. |
|||
|
|||
uartcom/uartlib.c: |
|||
公用的函数 和硬件无关 |
|||
放置串行模式(串口等其他通讯总线类的输出)输出的函数, |
|||
一些覆盖模式输出的(lcd等固屏输出的)的也可使用 |
|||
void Lc_print(void (*L0pf_send_uc)(char ww), char *dat,...) |
|||
----------------------------------------------------------------------------------------- |
|||
uartcom/uartcom0 |
|||
和uart相关的通讯协议 com + n |
|||
为了适应不同的通讯协议需要不同的uart口来对应 和应用相关 |
|||
|
|||
typedef struct _ts_lcm_pro_; 应用协议包的定义? LCM的协议------------ |
|||
L3_UARTcom0_exp_protocol 解析应用协议 |
|||
----------------------------------------------------------------------------------------- |
|||
uartcom/uprotocol: 主要是为 uartcom + n服务的 驱动层到应用层缓存的过度 |
|||
公用的串口通讯定义 |
|||
struct _s_protocol_ 的公共协议包(关键的结构体)的声明------struct _s_protocol_ |
|||
void L1_uart_2buf(struct _s_protocol_ *p)串行数据保存到缓冲中 |
|||
-------------------------------------------------------------------------------------------- |
|||
msp/uartx.c 底层代码 和cpu相关 |
|||
L0_UART0_Init |
|||
UART0_IRQHandler |
|||
L0_Usend_uc----------s_at0 |
|||
----------------------------------------------------------------------------------------- |
|||
********************************************************************************/ |
|||
|
|||
#include "tpc_modbus.h" |
|||
|
|||
void L1_s2b_PH4_init(TS_Handle_PH4 *p,U8 slaver) |
|||
{ |
|||
p->max = 0; |
|||
p->ok = 0; |
|||
p->head = 0; |
|||
p->num = 0; |
|||
p->slaver = slaver; |
|||
p->error = 0; |
|||
} |
|||
|
|||
void L1_s2b_PH4(TS_Handle_PH4 *p) |
|||
{ |
|||
if(p->head == 0) |
|||
{ |
|||
if(p->reg == p->slaver) |
|||
{ |
|||
p->head = 1; |
|||
p->error = 0; |
|||
p->max = D_s_PH4_modbus_max; |
|||
p->sp = p->buf; |
|||
p->num = 0; |
|||
p->sp[p->num++] = p->reg; |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
if(p->num < p->max) |
|||
{ |
|||
p->sp[p->num++] = p->reg; |
|||
} |
|||
else |
|||
{ |
|||
//P10 ^= 1;
|
|||
p->error = 1; |
|||
} |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
/******************************************************************************
|
|||
** End Of File |
|||
******************************************************************************/ |
|||
|
@ -0,0 +1,57 @@ |
|||
//////////////////////////////////////////////////////////////////////////
|
|||
/// COPYRIGHT NOTICE
|
|||
/// Copyright (c) 2018, 传控科技
|
|||
/// All rights reserved.
|
|||
///
|
|||
/// @file tpc_fsk.c
|
|||
/// @brief transaction protocol control of fsk
|
|||
///
|
|||
///(本文件实现的功能的详述)
|
|||
///
|
|||
/// @version 1.1 CCsens technology
|
|||
/// @author CC
|
|||
/// @date 20150102
|
|||
///
|
|||
///
|
|||
/// @version 1.2 CCsens technology
|
|||
/// @author CC
|
|||
/// @date 20180308
|
|||
/// @info 整理
|
|||
|
|||
//
|
|||
//////////////////////////////////////////////////////////////////////////
|
|||
|
|||
|
|||
#ifndef __TPC_MODBUS_H_ |
|||
#define __TPC_MODBUS_H_ |
|||
|
|||
#include "../clib/Type.h" |
|||
#include "../bsp/bsp_config.h" |
|||
#include "../app/common.h" |
|||
|
|||
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
|||
|
|||
typedef struct |
|||
{ |
|||
U8 reg; |
|||
U8 max; //接收到的数目的最大值
|
|||
U8 slaver; |
|||
vU8 head; //接收标志头标志
|
|||
vU8 ok; //接收协议ok标志
|
|||
vU8 num; |
|||
vU8 error; //错误
|
|||
vU8 *sp; |
|||
U8 buf[D_s_PH4_modbus_max + 8]; |
|||
vU8 crc[2]; |
|||
}TS_Handle_PH4; |
|||
|
|||
extern void L1_s2b_PH4_init(TS_Handle_PH4 *p,U8 slaver); |
|||
extern void L1_s2b_PH4(TS_Handle_PH4 *p); |
|||
|
|||
#endif /* end __TPC_UART_H_ */ |
|||
/*****************************************************************************
|
|||
** End Of File |
|||
******************************************************************************/ |
|||
|
|||
|
|||
|
@ -0,0 +1,192 @@ |
|||
|
|||
/*****************************************************************************
|
|||
update by cc @201501101001 |
|||
针对多串口 和 单一串口 有区别 每个串口是独立的还是分开的有讲究 程序是复杂的还是软件应用简单是 |
|||
个需要平衡的事情. |
|||
|
|||
uartcom/uartlib.c: |
|||
公用的函数 和硬件无关 |
|||
放置串行模式(串口等其他通讯总线类的输出)输出的函数, |
|||
一些覆盖模式输出的(lcd等固屏输出的)的也可使用 |
|||
void Lc_print(void (*L0pf_send_uc)(char ww), char *dat,...) |
|||
----------------------------------------------------------------------------------------- |
|||
uartcom/uartcom0 |
|||
和uart相关的通讯协议 com + n |
|||
为了适应不同的通讯协议需要不同的uart口来对应 和应用相关 |
|||
|
|||
typedef struct _ts_lcm_pro_; 应用协议包的定义? LCM的协议------------ |
|||
L3_UARTcom0_exp_protocol 解析应用协议 |
|||
----------------------------------------------------------------------------------------- |
|||
uartcom/uprotocol: 主要是为 uartcom + n服务的 驱动层到应用层缓存的过度 |
|||
公用的串口通讯定义 |
|||
struct _s_protocol_ 的公共协议包(关键的结构体)的声明------struct _s_protocol_ |
|||
void L1_uart_2buf(struct _s_protocol_ *p)串行数据保存到缓冲中 |
|||
-------------------------------------------------------------------------------------------- |
|||
msp/uartx.c 底层代码 和cpu相关 |
|||
L0_UART0_Init |
|||
UART0_IRQHandler |
|||
L0_Usend_uc----------s_at0 |
|||
----------------------------------------------------------------------------------------- |
|||
********************************************************************************/ |
|||
|
|||
#include "tpc_uart.h" |
|||
|
|||
|
|||
//NUM: 0 1 2 3 4
|
|||
// Fx R1 R2 R3 ocr
|
|||
// F+从机 R1 R2 R3 校验
|
|||
|
|||
|
|||
|
|||
|
|||
/// 实践中发现 如果收到多个以0d0a结束的短协议时,如果
|
|||
/// 协议之间间隔时间太短,ok处理不及时 会出现丢失协议的
|
|||
/// 的情况,所以 对于短暂的多个协议 应该有一定容量的缓冲
|
|||
/// 保留 ,同时 处理完协议后,应该清除接收缓冲,否则缓冲
|
|||
/// 会在自身满了后自动清除
|
|||
//_s_HRTU_P_rf_
|
|||
/// _s_HRTU_Pfx_
|
|||
/// fx 11 22 33 oc -- oc = 11+ 22+33
|
|||
//buf 0 1 2 3 [4]
|
|||
//
|
|||
//// protocol hex 1 serial to buff
|
|||
#ifdef D_use_uart_rx |
|||
void L1_s2b_PH1 (TS_Handle_PH1 *p)// reentrant
|
|||
{ |
|||
if (0 == p->head) |
|||
{ |
|||
if (D_HETU_FX_fi == (p->reg&D_HETU_FX_H4)) |
|||
{//p->ok = 1;p->head = 0;
|
|||
p->head = 1; |
|||
p->num = 0; |
|||
//p->ocx = 0;
|
|||
p->buf[p->num]=p->reg; |
|||
} |
|||
}else |
|||
{ |
|||
p->num ++; |
|||
p->buf[p->num] = p->reg; |
|||
|
|||
if(p->num >= D_HETU_FX_buf_max) // [4]
|
|||
{ |
|||
///p->ocr = p->buf[1]; p->ocr += p->buf[2];p->ocr += p->buf[3];
|
|||
///if(p->ocr == p->buf[D_HETU_FX_buf_max])
|
|||
{ |
|||
// if (p->ok != 1)
|
|||
{ |
|||
// D_led_D2_ON();
|
|||
p->ok = 1;//收到 命令结束,必须有个地方清0,否则无法再次接受报文
|
|||
// D_led_D2_OFF();
|
|||
} |
|||
} |
|||
p->num = 0; //放在if (p->ok != 1) 外
|
|||
p->head = 0; //放在if (p->ok != 1) 外
|
|||
//p->max = 0;
|
|||
} |
|||
} |
|||
} |
|||
#endif |
|||
|
|||
////485
|
|||
//// 带地址判定的
|
|||
void L1_s2b_PH1A (TS_Handle_PH1A *p)// reentrant
|
|||
{ |
|||
if (0 == p->head) |
|||
{ |
|||
if (D_HETU_FXA == p->reg) |
|||
{//p->ok = 1;p->head = 0;
|
|||
p->head = 1; |
|||
p->num = 0; |
|||
//p->ocx = 0;
|
|||
p->buf[p->num]=p->reg; |
|||
} |
|||
}else |
|||
{ |
|||
p->num ++; |
|||
p->buf[p->num] = p->reg; |
|||
if(p->num >= D_HETU_FXA_buf_max - 1) // [4]
|
|||
{ |
|||
///p->ocr = p->buf[1]; p->ocr += p->buf[2];p->ocr += p->buf[3];
|
|||
///if(p->ocr == p->buf[D_HETU_FX_buf_max])
|
|||
{ |
|||
//if (p->add == p->buf[1])///地址不匹配
|
|||
{ |
|||
// D_led_D2_ON();
|
|||
p->ok = 1;//收到 命令结束,必须有个地方清0,否则无法再次接受报文
|
|||
// D_led_D2_OFF();
|
|||
} |
|||
// p->ok = 1;
|
|||
} |
|||
p->num = 0; //放在if (p->ok != 1) 外
|
|||
p->head = 0; //放在if (p->ok != 1) 外
|
|||
//p->max = 0;
|
|||
} |
|||
} |
|||
} |
|||
|
|||
|
|||
///FF FE 08 52 16 11 22 33 44 F5 9F 发送了一个modbus协议包(8个数据52 16 11 22 33 44 F5 9F )
|
|||
/// 1 2 3 4 5 6 7 8
|
|||
/// 0 1 2 3 4 5 6 7 8 9 10
|
|||
/// 协议表达的意思为地址为0x52的从机, 功能码16 数据为11 22 33 44,校验码 F5 9F
|
|||
|
|||
void L1_s2b_PH3_init(TS_Handle_PH3 *p) |
|||
{ |
|||
p->max = 0; |
|||
p->ok = 0; |
|||
p->num = 0; |
|||
p->head = 0; |
|||
p->head_0 = TS_PH3_FILTER0; |
|||
p->head_1 = TS_PH3_FILTER1; |
|||
} |
|||
|
|||
void L1_s2b_PH3(TS_Handle_PH3 *p)// reentrant
|
|||
{ |
|||
p->cashe[1] = p->cashe[0]; |
|||
p->cashe[0] = p->reg;//
|
|||
|
|||
if (0 == p->head) |
|||
{ |
|||
if ((p->cashe[1] == p->head_0)&&(p->cashe[0] == p->head_1)) |
|||
{ |
|||
p->head = 1; |
|||
p->max = D_s_PH3_ccmodbus_max - 1; |
|||
p->sp = p->buf; |
|||
p->sp[0] = p->head_0; |
|||
p->sp[1] = p->head_1; |
|||
p->num = 1; |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
p->num ++; |
|||
p->sp[p->num] = p->cashe[0]; |
|||
if(p->num == 2)//数量 第3个数据
|
|||
{ |
|||
p->max = p->reg + 2;//
|
|||
if(p->max >= D_s_PH3_ccmodbus_max) |
|||
{ |
|||
p->max = D_s_PH3_ccmodbus_max - 1; |
|||
} |
|||
} |
|||
if(p->num >= p->max) |
|||
{ |
|||
//p->ts_ccmodbus.crc = (p->sp[p->num-1] | p->sp[p->num]) & 0xFFFF;
|
|||
if(/*crc()==p->ts_ccmodbus.crc*/ 1) |
|||
{ |
|||
if (p->ok != 1) |
|||
{ |
|||
p->ok = 1;//收到 命令结束,必须有个地方清0,否则无法再次接受报文
|
|||
} |
|||
} |
|||
p->num = 0; |
|||
p->head = 0; |
|||
} |
|||
} |
|||
} |
|||
|
|||
|
|||
/******************************************************************************
|
|||
** End Of File |
|||
******************************************************************************/ |
|||
|
@ -0,0 +1,409 @@ |
|||
//////////////////////////////////////////////////////////////////////////
|
|||
/// COPYRIGHT NOTICE
|
|||
/// Copyright (c) 2018, 传控科技
|
|||
/// All rights reserved.
|
|||
///
|
|||
/// @file tpc_fsk.c
|
|||
/// @brief transaction protocol control of fsk
|
|||
///
|
|||
///(本文件实现的功能的详述)
|
|||
///
|
|||
/// @version 1.1 CCsens technology
|
|||
/// @author CC
|
|||
/// @date 20150102
|
|||
///
|
|||
///
|
|||
/// @version 1.2 CCsens technology
|
|||
/// @author CC
|
|||
/// @date 20180308
|
|||
/// @info 整理
|
|||
|
|||
//
|
|||
//////////////////////////////////////////////////////////////////////////
|
|||
|
|||
|
|||
/*****************************************************************************
|
|||
@version 1.2 |
|||
update by cc @201501101001 |
|||
针对多串口 和 单一串口 有区别 每个串口是独立的还是分开的有讲究 程序是复杂的还是软件应用简单是 |
|||
个需要平衡的事情. |
|||
|
|||
clib/uartlib.c: |
|||
公用的函数 和硬件无关 |
|||
接收各类协议的处理函数 |
|||
放置串行模式(串口等其他通讯总线类的输出)输出的函数, |
|||
一些覆盖模式输出的(lcd等固屏输出的)的也可使用 |
|||
void Lc_print(void (*L0pf_send_uc)(char ww), char *dat,...) |
|||
----------------------------------------------------------------------------------------- |
|||
|
|||
|
|||
----------------------------------------------------------------------------------------- |
|||
|
|||
|
|||
-------------------------------------------------------------------------------------------- |
|||
msp/uartx.c 底层代码 和cpu相关 |
|||
L0_UART0_Init |
|||
UART0_IRQHandler |
|||
L0_Usend_uc----------s_at0 |
|||
----------------------------------------------------------------------------------------- |
|||
********************************************************************************/ |
|||
|
|||
|
|||
|
|||
#ifndef __TPC_UART_H_ |
|||
#define __TPC_UART_H_ |
|||
|
|||
#include "../clib/Type.h" |
|||
#include "../bsp/bsp_config.h" |
|||
|
|||
|
|||
// 20170609
|
|||
|
|||
///-----------------------------------------------------
|
|||
|
|||
|
|||
|
|||
//L0_type_byte(ts_cmd_pro0)[]
|
|||
//#define D_CMD_Filter1 0xA5
|
|||
//#define D_CMD_Filter2 0x5A
|
|||
#define D_CMD_Filter1 0x0a |
|||
#define D_CMD_Filter2 0x0d |
|||
|
|||
#define D_CMD_Filter1_ff 0xFF |
|||
#define D_CMD_Filter2_fe 0xFE |
|||
|
|||
|
|||
|
|||
///协议类型: 十六进制协议1->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|||
/// 发送的数据为有fx开头的十六进制的短协议,和长协议的区别除了帧头简化为1个字节外,数据的长度也是比较精简,大部分按位操作的,适合低波特率rf433之类的传播
|
|||
///定长5个 适合于传感器定时上传
|
|||
/// R1
|
|||
///位数 7 6 5 4 3 2 1 0
|
|||
///定义 动作传感器AS1 (0---15) 动作传感器AS2 (0---15)
|
|||
|
|||
/// R2
|
|||
///位数 7 6 5 4 3 2 1 0
|
|||
///定义 气压Press (0---15) open mic
|
|||
|
|||
/// R3
|
|||
///位数 7 6 5 4 3 2 1 0
|
|||
///定义 Temp (0---15) Gsensor(0---15)
|
|||
|
|||
typedef struct |
|||
{//8byte
|
|||
/////////
|
|||
vU8 as2:4; |
|||
vU8 as1:4; |
|||
/////////
|
|||
vU8 mic:3; |
|||
vU8 open:1; |
|||
vU8 press:4; |
|||
////////////////
|
|||
vU8 Gsensor:4; |
|||
vU8 temp:4; |
|||
///////////
|
|||
}TS_P_pc_dat; |
|||
|
|||
typedef struct |
|||
{//8byte
|
|||
/////////
|
|||
U8 cameraBoardPower; //当前行第4个点采集的图像数据
|
|||
vU16 paperNum:10; //10bit纸张数据 表示最大量程1024 实际170张
|
|||
vU16 cameraIndex:4; //摄像头编号
|
|||
vU16 cameraWorking:1; //是否正常工作
|
|||
vU16 LowPower:1; // =1 lowPower 提醒需要充电,或者未连接电池
|
|||
}TS_P_paper; |
|||
|
|||
//NUM: 0 1 2 3 4
|
|||
// Fx R1 R2 R3 ocr
|
|||
// F+从机 R1 R2 R3 校验
|
|||
typedef struct _s_P_rf_ |
|||
{//8byte
|
|||
vU8 slave:4; |
|||
vU8 filter1:4; |
|||
////////////////
|
|||
TS_P_paper r123; |
|||
vU8 ocr; |
|||
}TS_P_rf; |
|||
|
|||
typedef struct _s_P_rf433_ |
|||
{//8byte
|
|||
vU8 ha; |
|||
// vU8 hb;
|
|||
|
|||
vU8 slave:4; |
|||
vU8 filter1:4; |
|||
////////////////
|
|||
TS_P_paper r123; |
|||
vU8 ocr; |
|||
/// vU8 hc;
|
|||
}TS_P_rf433; |
|||
|
|||
//NUM: 0 1 2 3 4
|
|||
// Fx R1 R2 R3 ocr
|
|||
// F+从机 R1 R2 R3 校验
|
|||
|
|||
typedef struct |
|||
{//8byte
|
|||
vU8 slave:4; |
|||
vU8 filter1:4; |
|||
////////////////
|
|||
vU8 G1; |
|||
////////////////
|
|||
vU8 G2; |
|||
////////////////
|
|||
vU8 Tmp:4; |
|||
vU8 Press:4; |
|||
////////////////
|
|||
vU8 ocr; |
|||
}TS_P_as; |
|||
|
|||
typedef struct |
|||
{//8byte
|
|||
vU8 slave:4; |
|||
vU8 filter1:4; |
|||
////////////////
|
|||
vU8 cmd; |
|||
////////////////
|
|||
vU8 R2; |
|||
////////////////
|
|||
vU8 R3; |
|||
////////////////
|
|||
vU8 ocr; |
|||
}TS_P_debug; |
|||
|
|||
|
|||
#define D_HETU_FX_fi 0xa0 ///2018.7.7
|
|||
#define D_HETU_FX_H4 0xf0 ///2018.7.7
|
|||
|
|||
#define D_HETU_FX_buf_max 4 //max 是是指实际的数量,num或者cnt是指当时的
|
|||
/// Hex RTU Protocol 0xFx
|
|||
typedef struct |
|||
{//8byte
|
|||
vU8 reg; |
|||
vU8 n; |
|||
vU8 head; //接收标志头标志
|
|||
vU8 ok; //接收协议ok标志
|
|||
vU8 num; |
|||
// vU8 cmd;
|
|||
vU8 ocr; |
|||
// vU8 *sp;
|
|||
U8 buf[D_HETU_FX_buf_max+1]; |
|||
}TS_Handle_PH1; |
|||
|
|||
|
|||
extern void L1_s2b_PH1 (TS_Handle_PH1 *p);// reentrant;
|
|||
|
|||
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
|||
|
|||
///协议类型: 十六进制协议2->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|||
/// 发送的数据为有ff fe开头的十六进制的长协议,内有数据数量
|
|||
///FF FE 52 03 98 77 88 99 地址为0x52的从机, 向PC发送了3个数据0x77,0x88,0x99
|
|||
|
|||
///FF FE 06 03 e5 77 88 99 命令(0x06)携带了3个数据0x77,0x88,0x99;校验为0x98(=0x06+0x03+0x77+0x88+0x99三个数据的和)
|
|||
///附:校验位=0x12+0x34+0x56=0x9c;取低位字节得到OCR=0x9c
|
|||
|
|||
typedef struct |
|||
{//8byte
|
|||
vU8 filter1; |
|||
vU8 filter2; |
|||
vU8 addr; //发送方的地址或命令
|
|||
vU8 num; //接收到的数据的计数, 随着数据接收而变化注意数据长度的范围
|
|||
vU8 ocr; |
|||
vU8 buf[4];//--->_s_P_pc_dat_
|
|||
}TS_P_pc; |
|||
|
|||
// FF FE 10 02 0C 51 03
|
|||
// cashe[1] cashe[0] 本机 数量 校验 数据1 从机 数据2 命令
|
|||
// filter2 filter1
|
|||
struct _s_PH2_FFFE_ |
|||
{//8byte
|
|||
vU8 cashe[2]; |
|||
vU8 reg; |
|||
vU8 max; //接收到的数目的最大值
|
|||
vU8 head_0; |
|||
vU8 head_1; |
|||
// vU8 sub_num; //接收到的数目注意数据长度的范围
|
|||
vU8 head; //接收标志头标志
|
|||
vU8 ok; //接收协议ok标志
|
|||
vU8 num; |
|||
vU8 *sp; |
|||
TS_P_pc s_FF; |
|||
// U8 pro[16]; ///解析协议用
|
|||
}; |
|||
|
|||
extern void L1_s2b_PH2(struct _s_PH2_FFFE_ *p);// reentrant;
|
|||
|
|||
|
|||
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
|||
///协议类型: 十六进制协议3->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|||
/// 发送的数据为有ff fe开头的十六进制的长协议,内包含标准的modbus协议
|
|||
///FF FE 08 52 16 11 22 33 44 F5 9F 发送了一个modbus协议包(8个数据52 16 11 22 33 44 F5 9F )
|
|||
/// 协议表达的意思为地址为0x52的从机, 功能码16 数据为11 22 33 44,校验码 F5 9F
|
|||
/// 校验码的范围为
|
|||
#define TS_PH3_FILTER0 0xFF |
|||
#define TS_PH3_FILTER1 0xFE |
|||
|
|||
#define D_s_PH3_ccmodbus_max (16 + 8) |
|||
typedef struct |
|||
{ |
|||
U8 filter0; |
|||
U8 filter1; |
|||
U8 num; |
|||
U8 src; //源设备ID
|
|||
U8 dst; //目标设备ID
|
|||
U8 oper; |
|||
U8 buf[D_s_PH3_ccmodbus_max - 8]; |
|||
U8 crc[2]; |
|||
}TS_PH3_ccmodbus; |
|||
|
|||
typedef struct |
|||
{//8byte
|
|||
U8 cashe[2]; |
|||
U8 reg; |
|||
U8 max; //接收到的数目的最大值
|
|||
U8 head_0; |
|||
U8 head_1; |
|||
// vU8 sub_num; //接收到的数目注意数据长度的范围
|
|||
vU8 head; //接收标志头标志
|
|||
vU8 ok; //接收协议ok标志
|
|||
vU8 num; |
|||
vU8 *sp; |
|||
U8 _buf[D_s_PH3_ccmodbus_max]; ///解析协议用
|
|||
U8 buf[D_s_PH3_ccmodbus_max]; |
|||
}TS_Handle_PH3; |
|||
|
|||
extern void L1_s2b_PH3_init(TS_Handle_PH3 *p); |
|||
extern void L1_s2b_PH3(TS_Handle_PH3 *p);// reentrant;
|
|||
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
|||
|
|||
///协议类型: 字符型协议1->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|||
/// 发送的数据为以回车换行(即0x0a 0x0d)为结尾的字符型长协议,内有意义比较明确的命令字符和对应的数据,适合debug和速率要求不高,数据量
|
|||
/// 不大的场合
|
|||
|
|||
///-----------------------------------------------------------------------------------------
|
|||
#define D_s_SSTR_0D0A_len 16 //str类的协议需要长度大一些,容易bug的地方,限制为接收64bytes的数据
|
|||
struct _s_PC1_0D0A_ |
|||
{//8byte
|
|||
vU8 reg; |
|||
// vU8 sub_num; //接收到的数目注意数据长度的范围
|
|||
vU8 head; //接收标志头标志
|
|||
|
|||
vU8 cashe[2]; |
|||
//vU8 filter1;
|
|||
//vU8 filter2;
|
|||
vU8 num; //接收到的数据的计数, 随着数据接收而变化注意数据长度的范围
|
|||
|
|||
vU8 ok; //接收协议ok标志
|
|||
vU8 max; //接收到的数目的最大值
|
|||
vU8 buf[D_s_SSTR_0D0A_len+1];//buffer 的第一位是 长度
|
|||
// U8 pro[16]; ///解析协议用
|
|||
}; |
|||
extern void L1_s2b_PC1(struct _s_PC1_0D0A_ *p);// reentrant;
|
|||
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
///modebus协议通讯使用>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|||
#ifdef doc_98098908 |
|||
///Modbus网络上以RTU模式通信,在消息中的每个8Bit字节按照原值传送,不做处理,如63H,RTU将直接发送01100011。
|
|||
////这种方式的主要优点是:数据帧传送之间没有间隔,相同波特率下传输数据的密度要比ASCII高,传输速度更快 [1] 。
|
|||
////ASCII模式使用的字符虽是RTU模式的两倍,但ASCII数据的译码和处理更为容易一些,此外,用RTU模式时报文字符必须以连续数据流的形式传送,
|
|||
///用ASCII模式,字符之间可产生长达1s的间隔,以适应速度较慢的机器
|
|||
///01 16 1000 1234 ABCD
|
|||
///这段代码的意思 是 向 地址 01 的 控制器 写入 1000 1234 。 就是这么简单
|
|||
////地址域 就是指 从站的地址,比如一个变频器,或者是一个仪表,这个地址就是它的通讯地址
|
|||
///功能码 就是你要做的事情,通讯的目的 就是读写数据,所以 MODBUS 功能码虽然很多,但是只有两个是我们常用的,就是读和写。
|
|||
///读的功能码是03 写的功能码是16,注意,这里的读写都是一次性写16个位,也就是一个WORD.
|
|||
///Address Function Data Check
|
|||
///8-Bits 8-Bits N x 8-Bits 16-Bits
|
|||
/// 功能(Function)域
|
|||
/// 功能域代码告诉了被寻址到的终端执行何种功能。下表列出了该系列仪表用到的功能码,以及它们的意义和功能。
|
|||
/// 代码 意义 行为
|
|||
/// 03 读数据寄存器 获得一个或多个寄存器的当前二进制值
|
|||
/// 16 预置多寄存器 设定二进制值到一系列多寄存器中(不对ACRXXXE开放)
|
|||
|
|||
|
|||
///离散量、开关量、数字量都是对同一类型信号的不同说法,
|
|||
///0表示断开,1表示接通,在PLC和类似控制设备中,都是一种布尔型的变量?
|
|||
///T谧远///像PLC中的Y/Q,均是这种类型的信号
|
|||
|
|||
|
|||
|
|||
|
|||
///cc改进版的modebus协议,添加了一个帧头
|
|||
/// ff fe num add function dat check
|
|||
#endif |
|||
|
|||
|
|||
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
///协议通讯使用>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|||
#define D_s_protocol_len 32 |
|||
struct _s_protocol_ |
|||
{//8byte
|
|||
vU8 rbr; |
|||
vU8 reg; |
|||
vU8 cashe[3]; |
|||
vU8 filter1; |
|||
vU8 filter2; |
|||
vU8 (*pfun_get)(void); |
|||
vU8 num; //接收到的数目注意数据长度的范围
|
|||
vU8 sub_num; //接收到的数目注意数据长度的范围
|
|||
vU8 head; //接收标志头标志
|
|||
vU8 ok; //接收协议ok标志
|
|||
vU8 data_ok; //接收协议ok标志
|
|||
vU8 ucXor; |
|||
vU8 array[D_s_protocol_len];//buffer 的第一位是 长度
|
|||
vU8 buf[D_s_protocol_len];//buffer 的第一位是 长度
|
|||
vU8 buf2[12];//buffer 的第一位是 长度
|
|||
}; |
|||
|
|||
extern void L1_uart_2buf(struct _s_protocol_ *p); |
|||
|
|||
|
|||
|
|||
//485
|
|||
///协议类型: 十六进制协议2 带地址判定的 第二个是地址->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|||
#define D_HETU_FXA 0xaa |
|||
|
|||
#define D_HETU_FXA_buf_max 8 //max 是是指实际的数量,num或者cnt是指当时的
|
|||
/// Hex RTU Protocol 0xFx
|
|||
typedef struct |
|||
{//8byte
|
|||
vU8 reg; |
|||
vU8 n; |
|||
vU8 head; //接收标志头标志
|
|||
vU8 ok; //接收协议ok标志
|
|||
vU8 num; |
|||
vU8 add; ///数据地址
|
|||
vU8 ocr; |
|||
// vU8 *sp;
|
|||
U8 buf[D_HETU_FXA_buf_max + 1]; |
|||
}TS_Handle_PH1A; |
|||
|
|||
typedef struct |
|||
{ |
|||
vU8 filter; |
|||
vU8 src; |
|||
vU8 dst; |
|||
vU8 dat[4]; |
|||
vU8 ocr; |
|||
}TS_PH1A_DAT; |
|||
|
|||
extern void L1_s2b_PH1A (TS_Handle_PH1A *p); |
|||
|
|||
|
|||
#endif /* end __TPC_UART_H_ */ |
|||
/*****************************************************************************
|
|||
** End Of File |
|||
******************************************************************************/ |
|||
|
|||
|
|||
|
Loading…
Reference in new issue