




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、59基于曉程PL3107載波芯片的采集器軟件 源程序$NOMOD51;-; This file is part of the C51 Compiler package; Copyright (c) 1988-2005 Keil Elektronik GmbH and Keil Software, Inc.; Version 8.01; * *;-; STARTUP.A51: This code is executed after processor reset.; To translate this file use A51 with the following invocation:; A5
2、1 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 Power-On Initialization of Memory; With the following EQU statements the initialization of memory; at processor reset can be
3、defined:; IDATALEN: IDATA memory size ; Note: The absolute start-address of IDATA memory is always 0; The IDATA space overlaps physically the DATA and BIT areas.IDATALEN EQU 80H; XDATASTART: XDATA memory start address ; The absolute start address of XDATA memoryXDATASTART EQU 0 ; XDATALEN: XDATA mem
4、ory size ; The length of XDATA memory in bytes.XDATALEN EQU 0 ; PDATASTART: PDATA memory start address ; The absolute start address of PDATA memoryPDATASTART EQU 0H; PDATALEN: PDATA memory size ; The length of PDATA memory in bytes.PDATALEN EQU 0H;-; Reentrant Stack Initialization; The following EQU
5、 statements define the stack pointer for reentrant; functions and initialized it:; Stack Space for reentrant functions in the SMALL model.; IBPSTACK: Enable SMALL model reentrant stack; Stack space for reentrant functions in the SMALL model.IBPSTACK EQU 0 ; set to 1 if small reentrant is used.; IBPS
6、TACKTOP: End address of SMALL model stack ; Set the top of the stack to the highest location.IBPSTACKTOP EQU 0xFF +1 ; default 0FFH+1 ; ; Stack Space for reentrant functions in the LARGE model. ; XBPSTACK: Enable LARGE model reentrant stack; Stack space for reentrant functions in the LARGE model.XBP
7、STACK EQU 0 ; set to 1 if large reentrant is used.; XBPSTACKTOP: End address of LARGE model stack ; Set the top of the stack to the highest location.XBPSTACKTOP EQU 0xFFFF +1 ; default 0FFFFH+1 ; ; Stack Space for reentrant functions in the COMPACT model. ; PBPSTACK: Enable COMPACT model reentrant s
8、tack; Stack space for reentrant functions in the COMPACT model.PBPSTACK EQU 0 ; set to 1 if compact reentrant is used.; PBPSTACKTOP: End address of COMPACT model stack ; Set the top of the stack to the highest location.PBPSTACKTOP EQU 0xFF +1 ; default 0FFH+1 ; ;-; Memory Page for Using the Compact
9、Model with 64 KByte xdata RAM; Compact Model Page Definition; Define the XDATA page used for PDATA variables. ; PPAGE must conform with the PPAGE set in the linker invocation.; Enable pdata memory page initalizationPPAGEENABLE EQU 0 ; set to 1 if pdata object are used.; PPAGE number ; uppermost 256-
10、byte address of the page used for PDATA variables.PPAGE EQU 0; SFR address which supplies uppermost address byte ; most 8051 variants use P2 as uppermost address bytePPAGE_SFR DATA 0A0H; ;-; Standard SFR Symbols ACC DATA 0E0HB DATA 0F0HSP DATA 81HDPL DATA 82HDPH DATA 83H NAME ?C_STARTUP?C_C51STARTUP
11、 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_C51STARTUPSTARTUP1:IF IDATALEN 0 MOV R0,#IDATALEN - 1 CLR AIDATALOOP: MOV R0,A DJNZ R0,IDATALOOPENDIFIF XDATALEN 0 MOV DPTR,#XDATASTART MOV R7,#LOW (XDATALEN) IF (LOW
12、 (XDATALEN) 0 MOV R6,#(HIGH (XDATALEN) +1 ELSE MOV R6,#HIGH (XDATALEN) ENDIF CLR AXDATALOOP: MOVX DPTR,A INC DPTR DJNZ R7,XDATALOOP DJNZ R6,XDATALOOPENDIFIF PPAGEENABLE 0 MOV PPAGE_SFR,#PPAGEENDIFIF PDATALEN 0 MOV R0,#LOW (PDATASTART) MOV R7,#LOW (PDATALEN) CLR APDATALOOP: MOVX R0,A INC R0 DJNZ R7,P
13、DATALOOPENDIFIF IBPSTACK 0EXTRN DATA (?C_IBP) MOV ?C_IBP,#LOW IBPSTACKTOPENDIFIF XBPSTACK 0EXTRN DATA (?C_XBP) MOV ?C_XBP,#HIGH XBPSTACKTOP MOV ?C_XBP+1,#LOW XBPSTACKTOPENDIFIF PBPSTACK 0EXTRN DATA (?C_PBP) MOV ?C_PBP,#LOW PBPSTACKTOPENDIF MOV SP,#?STACK-1; This code is required if you use L51_BANK.
14、A51 with Banking Mode 4; Code Banking; Select Bank 0 for L51_BANK.A51 Mode 4#if 0 ; 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; LJMP ?C_START END#ifndef _BSP_H_#define _BSP_H_
15、#include pl3105.h#include cpu.h#define off 0ul#define on 1ul#define false 0ul#define true 1ul#define free 0ul#define busy 1ul#define def_1200bps 0ul#define def_2400bps 1ul#define def_4800bps 2ul#define def_9600bps 3ul#define COM_BUF_LEN 40ul / 串口接收緩沖區(qū)長(zhǎng)度#define GBL_TICKS_PER_SEC 100ul / 每秒時(shí)鐘滴答數(shù)struct
16、 def_com int16s actv; / 串口工作模式定義(0表示接收,非零表示發(fā)送剩余時(shí)間) int16s dcnt; / 串口緩沖區(qū)中有效數(shù)據(jù)個(gè)數(shù) int8u wptr; / 指向緩沖區(qū)中下一個(gè)數(shù)據(jù)寫(xiě)入的地址 int8u rptr; / 指向緩沖區(qū)中下一個(gè)數(shù)據(jù)讀取的地址 int8u dbufCOM_BUF_LEN; / 串口數(shù)據(jù)緩沖區(qū);#ifdef GLOBAL volatile int32s data sys_ticks = 2880000l; / 系統(tǒng)運(yùn)行滴答數(shù)(10ms * 8 * 60 * 60 * GBL_TICKS_PER_SEC),每8小時(shí)主動(dòng)復(fù)位一次 volatile
17、 struct def_com xdata plccom, infcom, plcrdm, infrdm, secrdm, *rdmcom = &secrdm;#else extern volatile int32s data sys_ticks; extern volatile struct def_com xdata plccom, infcom, plcrdm, infrdm, secrdm, *rdmcom;#endif#define set_time(ticks) (sys_ticks) - (int32s)(ticks) / 設(shè)置一個(gè)時(shí)間#define chk_time(ticks
18、) (sys_ticks) = rdmcom-dcnt) rs485rcv(on); rdmcom-actv = 0, rdmcom-dcnt = 0; rdmcom-rptr = 0, rdmcom-wptr = 0; return; rdmcom-dcnt = rdmcom-dcnt - 1; ACC = rdmcom-dbufrdmcom-rptr; ETB8 = P; / 偶校驗(yàn)位 SBUF1 = rdmcom-dbufrdmcom-rptr+; if (COM_BUF_LEN = rdmcom-rptr) rdmcom-rptr = 0; if (1 = ERI) ERI = 0;
19、if (rdmcom-actv) return; rdmcom-dcnt = rdmcom-dcnt + 1; rdmcom-dbufrdmcom-wptr+ = SBUF1; if (COM_BUF_LEN = rdmcom-wptr) rdmcom-wptr = 0; static void infrared_init(void) SCON = 0xd0; / 串口0工作方式3 TMOD = (TMOD & 0x0f) | 0x20; / T1設(shè)置為8位自動(dòng)重裝模式 TMOD1 = TMOD1 | 0x10; / T1時(shí)鐘不分頻 PCON = (STATUS & 0xc0) & (0x80
20、); / 串口波特率不加倍 TH1 = 0x83; ES = 1; TR1 = 1; / 開(kāi)串口0中斷,并啟動(dòng)波特率發(fā)生定時(shí)器static void isr_infrared(void) interrupt 4 if (1 = TI) TI = 0; if (0 = infcom.dcnt) IR38K = 0, IR_CNT1 = 0x00; / 關(guān)閉38k紅外調(diào)制信號(hào) infcom.actv = 0, infcom.dcnt = 0; infcom.rptr = 0, infcom.wptr = 0; return; infcom.dcnt = infcom.dcnt - 1; ACC =
21、 infcom.dbufinfcom.rptr; TB8 = P; / 偶校驗(yàn)位 SBUF = infcom.dbufinfcom.rptr+; if (COM_BUF_LEN = infcom.rptr) infcom.rptr = 0; if (1 = RI) RI = 0; if (infcom.actv) return; infcom.dcnt = infcom.dcnt + 1; infcom.dbufinfcom.wptr+ = SBUF; if (COM_BUF_LEN = infcom.wptr) infcom.wptr = 0; void sendbyte(struct de
22、f_com *com, int8u chr) com-dcnt = com-dcnt - 1; com-rptr = com-rptr + 1; if (&infcom = com) TI = 0, ACC = chr; TB8 = P, SBUF = chr; IR_CNT1 = 0x1f, IR38K = 1; / 打開(kāi)38k紅外調(diào)制信號(hào) return; if (rdmcom = com) rs485rcv(off); ETI = 0, ACC = chr; ETB8 = P, SBUF1 = chr; return; static void cpu_init(void) CKCON =
23、0xf8; / 控制看門(mén)狗喂狗時(shí)間長(zhǎng)度 109 * 8 ms ALU_MOD = 0; / 設(shè)置成 8 位運(yùn)算模式 LED_LCD = 0; / 不顯示使能/ 中斷周期為10ms#define load_timer_reg(void) (TH0 = 0xf0, TL0 = 0x60) / reg = 2 n - (t * fosc) / 12static void timer0_open(void) TMOD = (TMOD & 0xf0) | 0x01; / timer0工作方式1,16位計(jì)數(shù)器 load_timer_reg(); TR0 = 1; ET0 = 1; / 啟動(dòng)定時(shí)器并使能定時(shí)
24、器中斷static void isr_timer0(void) interrupt 1 load_timer_reg(); ext_isr_ticks(); feed_plc();void hdware_init(void) cpu_init(); plc_init(); infrared_init(); timer0_open();#ifndef _CPU_H_#define _CPU_H_typedef signed char int8s;typedef unsigned char int8u;typedef signed short int16s;typedef unsigned sho
25、rt int16u;typedef signed long int32s;typedef unsigned long int32u;#endif#include bsp.h#include lib.h#include string.h#include global.h#include opfile.h/ 記錄檔案類(lèi)型列表static struct def_filelist code filelist = GBL_ADDR_LEN, 1, / 地址 0000 - 0007(0008個(gè)字節(jié)) 3, GBL_METER_NUM, / 表檔案 0008 - 002F(0028個(gè)字節(jié)) 2, 1, /
26、采集器復(fù)位次數(shù) 0030 - 0033(0004個(gè)字節(jié)) 2, 1, / 集中器信息 0034 - 0037(0004個(gè)字節(jié));#define GBL_FILE_NUM (sizeof(filelist) / sizeof(struct def_filelist) / 不同檔案的數(shù)量static int8u code filepaddrGBL_FILE_NUM = / 檔案的操作地址 / 計(jì)算方法: addr = filelisti.len * filelisti.blk 0x00, / 采集器地址參數(shù)的起始存儲(chǔ)地址 0x08, / 采集器管理的電表地址的存儲(chǔ)起始地址 0x30, / 采集器復(fù)
27、位次數(shù)起始存儲(chǔ)地址 0x34, / 集中器信息起始存儲(chǔ)地址;static void _writfile_(int8u addr, int8u len, int8u data *ptr) EXT_ADR = 0x1e, EXT_DAT = 0x5a; EXT_ADR = 0xe0, EXT_DAT = addr; EXT_ADR = 0xe1, EXT_DAT = ptr; EXT_ADR = 0xe2, EXT_DAT = len; EXT_ADR = 0xe3, EXT_DAT = 0x01; EXT_ADR = 0x1e, EXT_DAT = 0x00;static void _readf
28、ile_(int8u addr, int8u len, int8u data *ptr) EXT_ADR = 0x1e, EXT_DAT = 0x5a; EXT_ADR = 0xe0, EXT_DAT = addr; EXT_ADR = 0xe1, EXT_DAT = ptr; EXT_ADR = 0xe2, EXT_DAT = len; EXT_ADR = 0xe3, EXT_DAT = 0x10; EXT_ADR = 0x1e, EXT_DAT = 0x00;static int8u data ep_dbuf8;int8u writfile(int8u id, int8u blk, int
29、8u *ptr) int16u data crc; memcpy(&ep_dbuf0, ptr, filelistid.len); crc = lib_cal_crc(&ep_dbuf0, filelistid.len); ep_dbuffilelistid.len = crc, ep_dbuffilelistid.len + 1 = crc 8; _writfile_(filepaddrid + (filelistid.len + 2) * blk, filelistid.len + 2, &ep_dbuf0); if (false = readfile(id, blk, &ep_dbuf0
30、) | (0 != memcmp(&ep_dbuf0, ptr, filelistid.len) return false; return true;int8u readfile(int8u id, int8u blk, int8u *ptr) memset(&ep_dbuf0, 0xff, sizeof(ep_dbuf); _readfile_(filepaddrid + (filelistid.len + 2) * blk, filelistid.len + 2, &ep_dbuf0); if (int16u)(ep_dbuffilelistid.len + 1 8) | ep_dbuff
31、ilelistid.len) != lib_cal_crc(&ep_dbuf0, filelistid.len) return false; memmove(ptr, &ep_dbuf0, filelistid.len); return true;void delefile(int8u id, int8u blk) memset(&ep_dbuf0, 0xff, sizeof(ep_dbuf); _writfile_(filepaddrid + (filelistid.len + 2) * blk, filelistid.len + 2, &ep_dbuf0);#ifndef _OPFILE_
32、H_#define _OPFILE_H_struct def_filelist int8u len; / 數(shù)據(jù)的長(zhǎng)度 int8u blk; / 塊數(shù);/ 數(shù)據(jù)標(biāo)識(shí),必需唯一(與FileList內(nèi)的數(shù)據(jù)項(xiàng)一一對(duì)應(yīng))#define SELFADDR_ID ( 0) / 采集器地址參數(shù)數(shù)據(jù)標(biāo)識(shí)編號(hào)#define METERFILE_ID (SELFADDR_ID + 1) / 采集器管理的電表地址數(shù)據(jù)標(biāo)識(shí)編號(hào)(低2位加一個(gè)屬性)#define SELFRESET_ID (METERFILE_ID + 1) / 采集器復(fù)位次數(shù)#define CONINFO_ID (SELFRESET_ID + 1)
33、/ 集中器相關(guān)信息extern int8u writfile(int8u id, int8u blk, int8u *ptr);extern int8u readfile(int8u id, int8u blk, int8u *ptr);extern void delefile(int8u id, int8u blk);#endif/* (C) COPYRIGHT 2009 FXXC E-TECH LIMITED* File Name: pl3105.h* Author : Deng Jian* Version : V1.0.0* Last Modify : 07/10/2009* Description : Header file for PL3105 & PL3106 m
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 文化產(chǎn)業(yè)管理考試模式試題與答案總結(jié)
- 激光技術(shù)工程師證書(shū)考試的溫馨提示試題及答案
- 深入解析2024年專(zhuān)利考試試題及答案
- 激光焊接中的氣體保護(hù)技術(shù)試題及答案
- 藥師考試策略性試題及答案
- 行政組織學(xué)試題及答案
- 川大拔尖計(jì)劃試題及答案
- 小升初直播測(cè)試題及答案
- 學(xué)習(xí)2025年公共營(yíng)養(yǎng)師考試時(shí)的備考資源分析試題及答案
- 激光項(xiàng)目技術(shù)支持試題及答案
- 土石壩設(shè)計(jì)計(jì)算書(shū)
- 重慶市兩江新區(qū)2023-2024學(xué)年七年級(jí)下學(xué)期期末考試語(yǔ)文試題
- 福建省廈門(mén)市第一中學(xué)2022-2023學(xué)年八下期中考試數(shù)學(xué)試卷(解析版)
- 中國(guó)痔病診療指南(2020版)
- 神經(jīng)病學(xué)(第8版)第六章-周?chē)窠?jīng)疾病
- 國(guó)際標(biāo)準(zhǔn)《風(fēng)險(xiǎn)管理指南》(ISO31000)的中文版
- 學(xué)習(xí)興稅-稅收基礎(chǔ)知識(shí)考試參考題庫(kù)及答案
- 印刷服務(wù)投標(biāo)方案(技術(shù)方案)
- 2024年愛(ài)國(guó)知識(shí)競(jìng)賽考試題庫(kù)400題(供參考)
- (高清版)DZT 0004-2015 重力調(diào)查技術(shù)規(guī)范(150 000)
- 永磁同步電機(jī)直接轉(zhuǎn)矩控制
評(píng)論
0/150
提交評(píng)論