📄 common.c
字号:
/************************************************
* 文件名:common.c *
* 文件功能:公共子函数 *
* 作者:xxlxws *
* 日期:2007-02-02 *
* 版本号:1.0 *
************************************************/
#include <ioavr.h>
#include <intrinsics.h>
#include <stdlib.h>
#include "mylib.h"
#include "common.h"
#include "main.h"
#include "init.h"
#include "func.h"
#include "inter.h"
/************************************************
* 函数名:Delayms *
* 入口参数:uint32 *
* 出口参数:无 *
* 作者:xxlxws *
* 日期:2007-02-02 *
* 函数功能:延时nms *
************************************************/
void Delayms(uint32 Tms)
{
uint32 i;
i = Tms;
do
{
#if SYSCLK_4M
__delay_cycles(3955);
if(i>1)
{
__delay_cycles(34);
}
#elif SYSCLK_8M
__delay_cycles(7955);
if(i>1)
{
__delay_cycles(34);
}
#else
#error: System Clock for function "Delayms" undefined!
#endif
}while(--i);
return;
}
/************************************************
* 函数名:Led_Onebyte *
* 入口参数:无 *
* 出口参数:无 *
* 作者:xxlxws *
* 日期:2006-10-06 *
* 函数功能:发送一个字节 *
************************************************/
void Led_Onebyte(uint8 Data_Disp)
{
uint8 i;
for(i=8; i>0; i--)
{
if((Data_Disp&0x80) == 0x80) //送数据
{
SI=1;
}
else
{
SI=0;
}
Data_Disp <<= 1;
SCK = 0;
SCK = 1;
SCK = 0;
}
for(i=100; i>0; i--);
return;
}
/************************************************
* 函数名:E2prom_Write *
* 入口参数:要写入EEPROM的地址及数据 *
* 出口参数:无 *
* 作者:xxlxws *
* 日期:2006-10-06 *
* 函数功能:写EEPROM *
************************************************/
void E2prom_Write(uint8 E2prom_Address,uint8 E2prom_Data)
{
while(EECR & (1 << EEPE))
;
EEAR = E2prom_Address;
EEDR = E2prom_Data;
EECR |= (1 << EEMPE);
EECR |= (1 << EEPE);
return;
}
/************************************************
* 函数名:E2prom_Read *
* 入口参数:要读出EEPROM的地址 *
* 出口参数:返回读出的数据 *
* 作者:xxlxws *
* 日期:2006-10-06 *
* 函数功能:读EEPROM *
************************************************/
uint8 E2prom_Read(uint8 E2prom_Address)
{
while(EECR & (1 << EEPE))
;
EEAR = E2prom_Address;
EECR |= (1 << EERE);
return EEDR;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -