//16f887
//20MHz 外部晶振
#include"OCP.h"
const uchar led[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; //位显示数组
bank2 uchar displaybuf[10] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
bank2 static uchar ledtemp1; //对应显示用变量
bank2 static uchar ledtemp2; //对应显示用变量
bank2 static uchar ledtemp3; //对应显示用变量
bank2 static uchar ledtemp4; //对应显示用变量
bank2 static uchar ledtemp5; //对应显示用变量
bank2 static uchar ledtemp6; //对应显示用变量
bank2 static uchar ledtemp8; //对应显示用变量
bank2 static uchar ledtemp9; //对应显示用变量
static uchar ledtemp10; //对应显示用变量
static uchar ledtemp7;
static uint ad_data0,ad_data1,ad_data2,ad_data3; //AD取样值
static unsigned long int cadd,cadd1; //通用长整变量
static unsigned long int add,add1;
//static uint zero = 510; //零点
//static uint zero1 = 510; //零点
static uint sc_data; //测试数值
static uint sc_data1; //测试数值
static uint sd; //控制显示闪动
static uint sddata=0; //闪动位置
static uint xsdata; //小数点位置
static uint full; //显示比值
static uint full1; //显示比值
static uchar s1_j;
static bit s1_z,s2_z,s3_z,s2_j,s3_j; //按键动作记录
bank1 static uchar tempchar; //临时变量
//static uint flash; //控制显示闪动
//static uchar flashdata=0; //闪动位置
//static uchar pointdata; //小数点位置
//static uchar dctime = 0; //时间控制约100秒刷新一次
static uchar antime = 0; //按键复用计时
static uchar keychar; //菜单位置
static uint time; //延时时间
bank1 static uint Current1; //告警阀值EEPROM位置为0x10-0x13
bank1 static uint Current2; //告警阀值EEPROM位置为0x10-0x13
bank1 static uint Current11;
bank1 static uint Current22;
bank1 static uint CurrentS1;
bank1 static uint CurrentS2;
bank1 static uint CurrentS11;
bank1 static uint CurrentS22;
bank1 static uint Power1;
bank1 static uint Power2;
bank1 static uint PowerS1;
bank1 static uint PowerS2;
bank1 static uchar relayflag = 0;
bank1 static uchar disp_x; //显示菜单
static uint i,j;
bank1 static uint kad_data;
bank1 static uint kac_data;
bank1 static uint fen = 0; //分闸次数 eeprom address 55
//bank1 static uint edin; //额定电流
//static uint time_ms = 0; //6.5536毫秒计时
//static uint time_s = 0; //秒计时
bank1 static uint time_ds; //显示秒计时
static uint antimes;
//static uchar main_cr = 0;
//static uchar relay_o = 0;
//static uint AdResult;
//static uchar AdCount;
uint loop = 0x0001;
uchar data1,data2,data3,data4;
uchar dater[7] = {0,0,0,0,0,0,0};
bank2 uchar daterbuf[7] = {0,0,0,0,0,0,0};
uchar date[7] = {0x10,0x05,0x27,0x04,0x13,0x10,0x55}; //日期数组
/*
bank1 uchar year = 0x10;
bank1 uchar month = 0x05;
bank1 uchar day = 0x27;
bank1 uchar week = 0x04;
bank1 uchar hour = 0x13;
bank1 uchar minute = 0x10;
bank1 uchar second = 0x55;
*/
uint ct1 = 100; //一次侧互感器变比 eeprom adress 50 51
uint ct2 = 100; //二次侧互感器变比 eeprom adress 52 53
uchar ntran = 80; //变压器功率因数 eeprom adress 54
/*********延时子程序*********/
void Delay(uint nn)
{
while(nn--);
}
/********开启SD2200的I2C总线********/
bit I2CStart(void)
{
volatile unsigned long temp;
TRISC4 = 0;
SDA=1;
SCL=1;
Delay(1);
TRISC4 = 1;//SDA input
Delay(1);
if(!SDA)return false;//SDA线为低电平则总线忙,退出
TRISC4 = 0;//SDA output
Delay(1);
SDA=0;
Delay(1);
TRISC4 = 1;
Delay(1);
/*while(SDA)
{
return false;//SDA线为高电平则总线出错,退出
}*/
TRISC4 = 0;
Delay(1);
SCL=0;
Delay(1);
return true;
}
/********关闭SD2200的I2C总线*******/
void I2CStop(void)
{
TRISC4 = 0;
Delay(1);
SDA=0;
SCL=0;
Delay(1);
SCL=1;
Delay(1);
SDA=1;
}
/*********发送 ACK*********/
void I2CAck(void)
{
TRISC4 = 0;
Delay(1);
SDA=0;
SCL=0;
Delay(1);
SCL=1;
Delay(1);
SCL=0;
}
/*********发送NO ACK*********/
void I2CNoAck(void)
{
TRISC4 = 0;
Delay(1);
SDA=1;
SCL=0;
Delay(1);
SCL=1;
Delay(1);
SCL=0;
}
/*********读取ACK信号*********/
bit I2CWaitAck(void) //返回为:1=有ACK,0=无ACK
{
uchar errtime=255;
TRISC4 = 0;
Delay(1);
SCL=0;
SDA=1;
Delay(1);
SCL=1;
Delay(1);
TRISC4 = 1;
Delay(1);
while(SDA)
{
errtime--;
if(!errtime)
SCL=0;
return false;
}
SCL=0;
return true;
}
/************从SD2200发送一个字节*************/
void I2CSendByte(uchar demand,uchar order) //order=1,H_L;order=0,L_H
{
uint temp;
uchar i=8; //order=1,从HI-->LO发送8bit数据
//order=0,从LO-->HI发送8bit数据
if(order)
{
while(i--)
{
SCL=0;
Delay(1);
TRISC4 = 0;
Delay(1);
if((demand&0x80)==0x80)
SDA = 1;
else
SDA = 0;
demand<<=1;
Delay(1);
SCL=1;
Delay(1);
}
SCL=0;
}
else
{
while(i--)
{
SCL=0;
Delay(1);
TRISC4 = 0;
Delay(1);
SDA=(bit)(demand&0x01);
demand>>=1;
Delay(1);
SCL=1;
Delay(1);
}
SCL=0;
}
}
/*********MCU从SD2200读入一字节*********/
uchar I2CReceiveByte(uchar order)//order=1,H_L;order=0,L_H
{
uchar i=8;
uchar ddata=0;
TRISC4 = 0;
Delay(1);
SDA=1;
if(order)
{
TRISC4 = 1;
Delay(1);
while(i--)
{
ddata<<=1; //数据从高位开始读取
SCL=0;
Delay(1);
SCL=1;
Delay(1); //从高位开始 ddata|=SDA;ddata<<=1
if(SDA)
{
ddata|=0x01;
}
}
}
else
{
while(i--)
{
ddata>>=1; //数据从低位开始读取
SCL=0;
Delay(1);
SCL=1;
Delay(1); //从低位开始 ddata|=SDA;ddata>>=1
TRISC4 = 1;
Delay(1);
if(SDA)
{
ddata|=0x80;
}
}
}
SCL=0;
return ddata;
}
/*写SD2200状态寄存器命令*/
void I2CWriteStatus(void)
{
if(!I2CStart())return;
I2CSendByte(0x60,1); //发送SD2200状态寄存器_1命令
if(!I2CWaitAck()){I2CStop();return;}
I2CSendByte(0x03,0); //IC进行复位初始化,24小时制
I2CWaitAck();
I2CStop();
I2CStart();
I2CSendByte(0x62,1); //发送SD2200状态寄存器_2命令
I2CWaitAck();
I2CSendByte(0x00,0); //清TEST位,禁止中断输出
I2CWaitAck();
I2CStop();
}
/*写SD2200时间寄存器命令*/
void I2CWriteTime(void)
{
uchar n;
/* date[0]=0x10;//year;2006/03/03/05/13/14/50
date[1]=0x05;//month
date[2]=0x27;//day
date[3]=0x04;//week
date[4]=0x13;//hour
date[5]=0x04;//minute
date[6]=0x00;//second */
I2CStart();
I2CSendByte(0x64,1); //发送SD2200写时间寄存器命令,
I2CWaitAck();
for(n=0;n<7;n++)
{
I2CSendByte(date[n],0);
I2CWaitAck();
}
I2CStop();
}
/******读SD2200EEsram数据寄存器-单字节******/
/*
uchar I2CReadEEram(uchar sramadd_hi,uchar sramadd_lo)
{
uchar ddata=0xFF;
I2CStart();
I2CSendByte(0x0A0,1);
I2CWaitAck();
I2CSendByte(sramadd_hi,1);
I2CWaitAck();
I2CSendByte(sramadd_lo,1);
I2CWaitAck();
I2CStart();
I2CSendByte(0x0A1,1);
I2CWaitAck();
ddata=I2CReceiveByte(1);
I2CNoAck();
I2CStop();
return ddata;
}
*/
/******写SD2200EEsram数据寄存器-单字节******/
/*
void I2CWriteEEram(uchar sramadd_hi,uchar sramadd_lo,uchar sramdata)
{
I2CStart();
I2CSendByte(0x0A0,1);
I2CWaitAck();
I2CSendByte(sramadd_hi,1);
I2CWaitAck();
I2CSendByte(sramadd_lo,1);
I2CWaitAck();
I2CSendByte(sramdata,1);
I2CWaitAck
OCP.rar_装置
版权申诉
25 浏览量
2022-09-14
18:00:36
上传
评论
收藏 23KB RAR 举报
刘良运
- 粉丝: 70
- 资源: 1万+
最新资源
- 5G RAN NR TDD单用户峰值吞吐率计算过程.pptx
- 基于Objective-C开发的手势密码解锁和面容解锁(代码简洁高效通俗易懂)+源码+开发文档+源码解析(毕业设计&课程设计)
- LangChain学习之 Question And Answer的操作附带数据文件
- linux常用命令大全.zip
- CATIA入门操作案例-正八边异形带孔凸台绘制,等距点绘制正多边形,凸台绘制
- 大型代码语言模型的项目级提示生成pdf
- 纸片战争The War of paper.sb3
- testedtestedtested
- 基于C语言+STM32开发的智能门锁优秀项目+包含指纹识别、人脸识别、RFID解锁、密码解锁、蓝牙解锁功能+源码+项目解析
- 目标检测-智能零售柜商品检测数据集-5000张图-+对应VOC-COCO-YOLO三种格式标签+数据集划分脚本
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈