Files
CMS79F5335_Demo/范例程序(C语言)/IH-CMS79F53X5-C-V1.0/Subfunction.c
2026-10-19 15:33:00 +08:00

119 lines
2.9 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**************************************************************************
**************************************************************************/
#include "Define_Global.h"
/**************************************************************************
* 函数名称:Delay_Xus
* 函数功能:延时处理
* 入口参数:x=延时时间
* 出口参数:无
* 备 注:死循环处理,注意调用
**************************************************************************/
void Delay_Xus(unsigned char x)
{
GIE = 0; //关闭中断
GIE = 0; //确保中断已关闭
GIE = 0; //确保中断已关闭
GIE = 0; //确保中断已关闭
while(--x)
{
NOP();
NOP();
NOP();
}
GIE = 1; //恢复中断
}
/**************************************************************************
* 函数名称:Delay_Xms
* 函数功能:延时处理
* 入口参数:x=延时时间
* 出口参数:无
* 备 注:死循环处理,注意调用
**************************************************************************/
void Delay_Xms(unsigned int x)
{
volatile unsigned int i = 728;
GIE = 0; //关闭中断
GIE = 0; //确保中断已关闭
GIE = 0; //确保中断已关闭
GIE = 0; //确保中断已关闭
while(--x)
{
while(--i);
i = 728;
CLRWDT(); //清看门狗
}
GIE = 1; //恢复中断
}
/***********************************************************************
* 函数名称:Memory_Write
* 函数功能:写入EE数据
* 入口参数:addr=写入地址,value=写入数据
* 出口参数:EE写操作完成状态
* 备 注:无
***********************************************************************/
unsigned char Memory_Write(unsigned char addr, unsigned char value)
{
EEADR = addr; //写入地址
EEDAT = value; //写入数据
CLRWDT(); //清看门狗
EECON1 = 0x10; //EE烧写时间 = 2.5ms
EEPGD = 0; //访问数据存储器
WREN = 1; //允许写周期
GIE = 0; //关闭中断
GIE = 0; //确保中断已关闭
GIE = 0; //确保中断已关闭
GIE = 0; //确保中断已关闭
EECON2 = 0x55; //给EECON2写入0x55
EECON2 = 0xAA; //给EECON2写入0xAA
WR = 1; //启动写周期
NOP();
NOP();
NOP();
NOP();
CLRWDT(); //清看门狗
WREN = 0; //写结束,关闭写入操作
GIE = 1; //恢复中断
if(WRERR)
{
return 0xFF; //EE写操作出错
}
else
{
return 0; //EE写操作OK
}
}
/***********************************************************************
* 函数名称:Memory_Read
* 函数功能:读取EE数据
* 入口参数:addr=读取地址
* 出口参数:读取数据
* 备 注:无
***********************************************************************/
unsigned char Memory_Read(unsigned char addr)
{
EEADR = addr; //读取地址
EEPGD = 0; //访问数据存储器
RD = 1; //使能读信号
NOP(); //这里读取数据,必须加NOP指令
NOP();
NOP();
NOP();
NOP();
return EEDAT; //读取数据
}