电路设计,软件开发,专业项目团队承接电子产品开发!


ISPRO下载型编程器
火爆销售中

RS232/TTL转换器
全IC串口窃电

RS232/TTL转换线
全IC串口窃电

ByteBlasterMV Cable
CPLD/FPGA并口下载线

ByteBlaster II Cable ISPRO下载型编程器
支持S51/AVR/PIC
超级51开发板套件
前卫实用超值

PC/MCU/CPLD
三合一学习套件

全新万年历方案
AVR单片机开发板
 

Min51单片机仿真机
迷你型

ARM7开发板
仅售260元!
 

RS-232/RS-485双向接口电平转换器  

51单片机升级STM32
火爆销售中
MPLAB-ICD2
火爆销售中
LED51开发板
玩具又名图文显示棒

面板模块/开发板
经济危机明智决择

       

GSM MODEM GSM猫

SMS短信模块 工业级/全自动
火爆销售中

大功率数传电台

高速数传电台

您当前位置:电子技术资料 -> 外围驱动 -> 看门狗 ->

祝您阅读愉快!

ISPRO下载型编程器

RS232 TO TTL转换器
↑↑本文相关产品介绍↑↑

X25045看门狗C例程


类别:技术文章
来源:未知
作者:未知
关键字:X25045
加入日期:2010-8-7

/***************************************************************
* X25043/45 application ; Procedures
* absolute one address access
***************************************************************
WARNING: The function with '_' ahead ,user may not use it.as it
used internal
*/
//使用函数:write_status(status) 写状态,一般写0
//clr_wchdog(void) 清看门狗
//unsigned char read_byte(address) //读一个字节
//void write_byte(address,Data) //写一个字节
//中国电子网 www.EC66.com
#define ALONE_COMPILE
#ifdef ALONE_COMPILE
#include "INTRINS.H"
#endif

#ifndef nop2()
#define nop2() _nop_();_nop_();_nop_()
#endif

#define WREN 0x06
#define WRDI 0x04
#define RDSR 0x05
#define WRSR 0x01
#define READ 0x03
#define WRITE 0x02

//#define PORT P1
sfr PORT=0x90; //25045的4根io脚接在同一端口,本例为p1
//请根据实际电路更改引脚定义
#define _SI 0x80 //si接在p1.3,0x80=00001000b
#define _SCK 0x40 //sck接在p1.2,0x80=00000100b
#define _SO 0x20 //so接在p1.1
#define _CS 0x10 //cs接在p1.0

//----------------------------------------------------------------
#ifndef dword
#define dword unsigned long
#define word unsigned int
#define byte unsigned char
typedef union{
word w;
byte bh;
byte bl;
}WordType;

typedef union{
dword dw;
word w[2];
byte b[4];
}DwordType;

#endif

//----------------------------------------------------------------
void _w_byte(Data)
char Data;
{
char i;

PORT &= (_SCK^0xff);
for(i=0;i<8;i++)
{
nop2();nop2();/////////////
if(Data & 0x80) PORT |= _SI;
else PORT &= (_SI^0xff);
nop2();nop2();/////////////
PORT |=_SCK;
nop2();nop2();/////////////
Data=Data<<1;
nop2();nop2();/////////////
PORT &= (_SCK^0xff);
nop2();nop2();/////////////
}
}
//----------------------------------------------------------------
char _r_byte(void)
{
char i;
char result;

result=0;
for(i=0;i<8;i++)
{
nop2();nop2();/////////////
PORT |=_SCK;
result=result<<1;
nop2();nop2();/////////////
if((PORT & _SO) != 0)
result |= 0x01;
nop2();nop2();/////////////
PORT &=(_SCK^0xff);
nop2();nop2();/////////////
}
return(result);
}
//----------------------------------------------------------------
void write_status(status)
char status;
{
PORT &=(_CS^0xff);
nop2();nop2();/////////////
_w_byte(status);
PORT |=_CS;
nop2();nop2();/////////////
return;
}
//----------------------------------------------------------------
void clr_wchdog(void)
{
PORT &= (_CS^0xff);
PORT |=_CS;
}
//----------------------------------------------------------------
void wait_free(void)
{
unsigned int t;

t=3000;
while(--t);
}
//----------------------------------------------------------------
void write_reg(_code)
char _code;
{
write_status(WREN);
PORT &= (_CS^0xff);
nop2();nop2();/////////////
_w_byte(WRSR);
_w_byte(_code);
nop2();nop2();/////////////
PORT |=_CS;
wait_free();
}
//----------------------------------------------------------------

unsigned char read_byte(address)
unsigned int address;
{
char result;

PORT &=(_CS^0xff); // Chip select
nop2();nop2();/////////////
_w_byte((char)(address>255 ? (0x08|READ): READ));
_w_byte((char)(address & 0x00ff));
result=_r_byte();
nop2();nop2();/////////////
PORT |=_CS;
// Chip unselect
return(result);
}
//----------------------------------------------------------------
void write_byte(address,Data)
unsigned int address;
char Data;
{
write_status(WREN);
nop2();nop2();/////////////
PORT &= (_CS^0xff);
nop2();nop2();/////////////
_w_byte((unsigned char)(address>255 ? (0x08|WRITE): WRITE));
_w_byte((unsigned char)(address & 0x00ff));
_w_byte(Data);
nop2();nop2();/////////////
PORT |=_CS;
wait_free();
return;
}
/*
//----------------------------------------------------------------
unsigned long read_data(format,address)
unsigned char format;
unsigned int address;
{
DwordType result;

switch(format&0xdf)
{
case 'L':
result.b[0]=read_byte(address);
result.b[1]=read_byte(address+1);
result.b[2]=read_byte(address+2);
result.b[3]=read_byte(address+3);
break;
case 'D':
result.b[2]=read_byte(address);
result.b[3]=read_byte(address+1);
break;
case 'C':
result.b[3]=read_byte(address);
break;
}
return(result.dw);
}
//----------------------------------------------------------------
void write_data(format,address,Data)
unsigned char format;
unsigned int address;
DwordType data* Data;
{
switch(format&0xdf)
{
case 'L':
write_byte(address , Data->b[0]);
write_byte(address+1, Data->b[1]);
write_byte(address+2, Data->b[2]);
write_byte(address+3, Data->b[3]);
break;
case 'D':
write_byte(address , Data->b[2]);
write_byte(address+1, Data->b[3]);
break;
case 'C':
write_byte(address , Data->b[3]);
break;
}

}
//----------------------------------------------------------------
*/

您可能还会关注的相关技术资料:

中国电子网
www.EC66.com
QQ:34740080 EMAIL:iloveaoe@163.com
最佳浏览:1024*768
Copyright (C) 2001-2010 EC66.COM All Rights Reserved
Aoe/帝国 制作维护
粤ICP备18061901号