在线时间0 小时
UID43804
注册时间2007-11-4
NXP金币0
该用户从未签到
新手上路

- 积分
- 0
- 最后登录
- 1970-1-1
|
发表于 2008-9-9 23:09:10
|
显示全部楼层
回复:求助:调试68HC908时离开调试环境后程序运行不正常?
您好!
我现在正在使用DS1306,但是我我往寄存器里面写数据,然后读出来之后 ff . 能否提供一下参考例程呢?
还有那个cpol怎么设置呢?没有找着对应的控制寄存器啊 。我是参照1305的一个程序来写的。下面是源代码
/***************************************************************************/
/* DEMO1305.C - This file is provided to show an example of routines */
/* for interfacing the DS2250 to the DS1305. */
/* These routines are provided for example only and are not supported by */
/* by Dallas Semiconductor MAXIM. */
/***************************************************************************/
#include /* Prototypes for I/O functions */
#include /* Register declarations for DS2250 */
/************************** Function Prototypes ****************************/
void reset_3w(void);
void WBYTE_3W(uchar W_Byte);
uchar RBYTE_3W(void);
void Initialize();
void BurstReadTime();
void BurstRamRead(void);
void BurstRamWrite(void);
void writebyte1305();
void readbyte1305();
void alarm_set();
void alarm_rd();
/************************** Bit Declarations *******************************/
sbit CE = P0^0; /* to CE pin on DS1305 */
sbit SCLK = P0^1; /* to SCLK pin on DS1305 */
sbit SDI_IO = P0^2; /* to SDI & SDO pins on DS1305 */
sbit INT0b = P3^2; /* to INT0b pin on DS1305 */
/************************** Global Variables *******************************/
uchar CPOL = 0;
void reset_3w()
{
SCLK = 0;
CE = 0;
CE = 1;
}
void WBYTE_3W(uchar W_Byte) /* --- This routine writes one byte from the RTC --- */
{
uchar i;
for(i = 0; i < 8; ++i)
{
SDI_IO = 0;
if(W_Byte & 0x01)
{
SDI_IO = 1;
}
SCLK = 0;
SCLK = 1;
W_Byte >>= 1;
}
}
uchar RBYTE_3W() /* ---- This routine reads one byte from the RTC ----- */
{
uchar i, R_Byte, TmpByte;
R_Byte = 0x00;
SDI_IO = 1; /* set to read */
for(i = 0; i < 8; ++i)
{
SCLK = 1;
SCLK = 0;
TmpByte = (uchar)SDI_IO;
TmpByte = 1;
R_Byte |= TmpByte;
}
return R_Byte;
}
void readbyte1305() /* ------------------------------------------------ */
{
uchar Add;
uchar Data;
/* Get Address & Data */
printf("\nEnter the Read Address (hex): ");
scanf("%bx", &Add);
reset_3w();
WBYTE_3W(Add);
printf("%2.bx", RBYTE_3W() );
reset_3w();
}
void writebyte1305() /* ------------------------------------------------ */
{
uchar Add, Data;
/* Get Address & Data */
printf("\nEnter the Read Address (hex): ");
scanf("%bx", &Add);
printf("Enter data (hex): ");
scanf("%bx", &Data);
/* User enters read address. Must convert to write address. */
Add |= 0x80;
reset_3w();
WBYTE_3W(Add);
WBYTE_3W(Data);
reset_3w();
}
void Initialize() /* ------------------------------------ */
{
/* Note: NO error checking is done on the user entries! */
uchar yr, mn, dt, dy, hr, min, sec, day;
reset_3w(); /* Read contents of Write Protect Register */
WBYTE_3W(0x8F);
WBYTE_3W(0); /* if write protect bit is set, this will only clear WP */
reset_3w();
WBYTE_3W(0x8F);
WBYTE_3W(0); /* if WP was set, now /eosc will be set to a zero */
reset_3w(); /* if we were setting WP to a 1, we could set all bits at once */
printf("\nEnter the year (0-99): ");
scanf("%bx", &yr);
printf("Enter the month (1-12): ");
scanf("%bx", &mn);
printf("Enter the date (1-31): ");
scanf("%bx", &dt);
printf("Enter the day (1-7): ");
scanf("%bx", &dy);
printf("Enter the hour (1-24): ");
scanf("%bx", &hr);
hr = hr & 0x3f; /* force clock to 24 hour mode */
printf("Enter the minute (0-59): ");
scanf("%bx", &min);
printf("Enter the second (0-59): ");
scanf("%bx", &sec);
reset_3w();
WBYTE_3W(0x80); /* write address for the seconds register */
WBYTE_3W(sec);
WBYTE_3W(min);
WBYTE_3W(hr);
WBYTE_3W(dy);
WBYTE_3W(dt);
WBYTE_3W(mn);
WBYTE_3W(yr);
reset_3w();
}
void BurstReadTime() /* ------------------------------------ */
{ |
|