基于晓程PL3107载波芯片采集器系统软件源代码_第1页
基于晓程PL3107载波芯片采集器系统软件源代码_第2页
基于晓程PL3107载波芯片采集器系统软件源代码_第3页
基于晓程PL3107载波芯片采集器系统软件源代码_第4页
基于晓程PL3107载波芯片采集器系统软件源代码_第5页
已阅读5页,还剩54页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

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 / 串口接收缓冲区长度#define GBL_TICKS_PER_SEC 100ul / 每秒时钟滴答数struct

16、 def_com int16s actv; / 串口工作模式定义(0表示接收,非零表示发送剩余时间) int16s dcnt; / 串口缓冲区中有效数据个数 int8u wptr; / 指向缓冲区中下一个数据写入的地址 int8u rptr; / 指向缓冲区中下一个数据读取的地址 int8u dbufCOM_BUF_LEN; / 串口数据缓冲区;#ifdef GLOBAL volatile int32s data sys_ticks = 2880000l; / 系统运行滴答数(10ms * 8 * 60 * 60 * GBL_TICKS_PER_SEC),每8小时主动复位一次 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) / 设置一个时间#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; / 偶校验位 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设置为8位自动重装模式 TMOD1 = TMOD1 | 0x10; / T1时钟不分频 PCON = (STATUS & 0xc0) & (0x80

20、); / 串口波特率不加倍 TH1 = 0x83; ES = 1; TR1 = 1; / 开串口0中断,并启动波特率发生定时器static void isr_infrared(void) interrupt 4 if (1 = TI) TI = 0; if (0 = infcom.dcnt) IR38K = 0, IR_CNT1 = 0x00; / 关闭38k红外调制信号 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; / 偶校验位 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; / 打开38k红外调制信号 return; if (rdmcom = com) rs485rcv(off); ETI = 0, ACC = chr; ETB8 = P, SBUF1 = chr; return; static void cpu_init(void) CKCON =

23、0xf8; / 控制看门狗喂狗时间长度 109 * 8 ms ALU_MOD = 0; / 设置成 8 位运算模式 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位计数器 load_timer_reg(); TR0 = 1; ET0 = 1; / 启动定时器并使能定时

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/ 记录档案类型列表static struct def_filelist code filelist = GBL_ADDR_LEN, 1, / 地址 0000 - 0007(0008个字节) 3, GBL_METER_NUM, / 表档案 0008 - 002F(0028个字节) 2, 1, /

26、采集器复位次数 0030 - 0033(0004个字节) 2, 1, / 集中器信息 0034 - 0037(0004个字节);#define GBL_FILE_NUM (sizeof(filelist) / sizeof(struct def_filelist) / 不同档案的数量static int8u code filepaddrGBL_FILE_NUM = / 档案的操作地址 / 计算方法: addr = filelisti.len * filelisti.blk 0x00, / 采集器地址参数的起始存储地址 0x08, / 采集器管理的电表地址的存储起始地址 0x30, / 采集器复

27、位次数起始存储地址 0x34, / 集中器信息起始存储地址;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; / 数据的长度 int8u blk; / 块数;/ 数据标识,必需唯一(与FileList内的数据项一一对应)#define SELFADDR_ID ( 0) / 采集器地址参数数据标识编号#define METERFILE_ID (SELFADDR_ID + 1) / 采集器管理的电表地址数据标识编号(低2位加一个属性)#define SELFRESET_ID (METERFILE_ID + 1) / 采集器复位次数#define CONINFO_ID (SELFRESET_ID + 1)

33、/ 集中器相关信息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. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论