ARM9教程DSP教程FPGA教程CPLD教程36A软硬件设计0229

发布时间:2024-09-25

ARM9教程DSP教程FPGA教程CPLD教程36A软硬件设计0229

ARM9教程DSP教程FPGA教程CPLD教程 36A多核软硬件系统设计

Ds1391 rtc Timing Software

第一部分 原理图

1.1

ARM9教程DSP教程FPGA教程CPLD教程36A软硬件设计0229

1.2 DS1391_RTC_System. OpenBus

IO

MEM

SOFT_TERMINAL

RTC

MEM

IO

MEM

SOFT_TERMINAL

RTC

MEM

ARM9教程DSP教程FPGA教程CPLD教程36A软硬件设计0229

1.3 main.c

/********************************************************************\ |*

|* Copyright: Copyright (c) 2008, PurPer |*

|* Description: Show how to use the DS1391 device driver with SPI |* bus arbitration being handled by the driver. |*

\********************************************************************/

#include <stdlib.h> #include <stdio.h> #include <string.h> #include <time.h>

// Device driver interface #include <devices.h> #include <drv_ds1391.h>

static void str2ts( const char * timestring, const char * datestring, struct tm * timestruct ); static void init( void );

// Device driver pointer ds1391_t * rtc;

char * month[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" } ;

/********************************************************************** |*

|* Function : main

ARM9教程DSP教程FPGA教程CPLD教程36A软硬件设计0229

|*

|* Parameters : None |*

|* Returns : None |*

|* Description : Main loop - write compilation time to RTC and loop |* printing calendar time from that */

void main( void ) {

time_t t; struct tm ts; int sec;

init();

str2ts( __TIME__, __DATE__, &ts ); t = mktime( &ts ); ts = * localtime( &t );

printf( "Date/time = %s", asctime( &ts ));

if ( ds1391_set_time( rtc, &ts ) == -1 ) {

// Setting time and date failed for some reason puts( "Unable to set time" ); abort(); }

memset( &ts, 0, sizeof( ts ));

ARM9教程DSP教程FPGA教程CPLD教程36A软硬件设计0229

sec = ts.tm_sec; for (;;) {

// Loop forever: print date & time once per second do {

ds1391_get_time( rtc, &ts ); } while ( ts.tm_sec == sec ); sec = ts.tm_sec;

printf( asctime( &ts )); } }

/********************************************************************** |*

|* Function : str2ts |*

|* Parameters : timestring = ASCII representation of time (hh:mm:ss) |* datestring = ASCII representation of date (mon dd yyyy)

|* timestruct = pointer to time structure to encode date and time in |*

|* Returns : None |*

|* Description : Convert a date and time as generated by __FILE__ and __DATE__ macros |* to broken down calendartime */

static void str2ts( const char * timestring, const char * datestring, struct tm * timestruct ) {

if ( timestring ) {

ARM9教程DSP教程FPGA教程CPLD教程36A软硬件设计0229

timestruct->tm_hour = 10 * (timestring[0] - '0') + (timestring[1] - '0'); timestruct->tm_min = 10 * (timestring[3] - '0') + (timestring[4] - '0'); timestruct->tm_sec = 10 * (timestring[6] - '0') + (timestring[7] - '0'); }

if ( datestring ) {

int i;

char *p = (char *)datestring + 3; *p++ = '\0';

for ( i = 11; i; i-- ) {

if ( !strcmp( datestring, month[i] )) break; }

timestruct->tm_mon = i;

if ( *p == ' ' ) p++; timestruct->tm_mday = 0; while( *p != ' ') {

timestruct->tm_mday = timestruct->tm_mday * 10 + (*p++ - '0');

}

timestruct->tm_year = 1000 * (p[1] - '0') + 100 * (p[2] - '0') + 10 * (p[3] - '0') + (p[4] - '0') - 1900; } }

/********************************************************************** |*

|* Function : init

ARM9教程DSP教程FPGA教程CPLD教程36A软硬件设计0229

|*

|* Parameters : None |*

|* Returns : None |*

|* Description : Initialize hardware & device drivers */

static void init( void ) {

puts( "File '" __FILE__ "' compiled " __DATE__ ", " __TIME__ ); rtc = ds1391_open( DRV_DS1391_1 ); }

ARM9教程DSP教程FPGA教程CPLD教程36A软硬件设计0229

1.4 DS1391_RTC. SwPlatform

ARM9教程DSP教程FPGA教程CPLD教程36A软硬件设计0229.doc 将本文的Word文档下载到电脑

    精彩图片

    热门精选

    大家正在看

    × 游客快捷下载通道(下载后可以自由复制和排版)

    限时特价:7 元/份 原价:20元

    支付方式:

    开通VIP包月会员 特价:29元/月

    注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
    微信:fanwen365 QQ:370150219