////////////////////////////////////////////////////////////////////////// //// NJU6355.C //// //// Driver for Real Time Clock //// //// //// //// rtc_init() Call after power up//// //// //// //// rtc_set_datetime(day,mth,year,dow,hour,min) Set the date/time //// //// //// //// rtc_get_date(day,mth,year,dow) Get the date //// //// //// //// rtc_get_time(hr,min,sec) Get the time //// //// //// ////////////////////////////////////////////////////////////////////////// //// (C) Copyright 1996,1997 Custom Computer Services //// //// This source code may only be used by licensed users of the CCS C //// //// compiler. This source code may only be distributed to other //// //// licensed users of the CCS C compiler. No other use, reproduction //// //// or distribution is permitted without written permission. //// //// Derivative programs created using this software in object code //// //// form are not restricted in any way. //// //////////////////////////////////////////////////////////////////////////// #ifndef RTC_CE #define RTC_IO PIN_B3 #define RTC_CE PIN_B2 #define RTC_CLK PIN_B1 #define RTC_DATA PIN_B0 #endif void rtc_init() { output_low(RTC_CE); output_low(RTC_IO); } void write_rtc_byte(byte data_byte, byte number_of_bits) { byte i; for(i=0; i>1; output_high(RTC_CLK); output_low(RTC_CLK); } } byte read_rtc_byte(byte number_of_bits) { byte i,data; for(i=0;i>4; read_rtc_byte(8*3); output_low(RTC_CE); output_low(RTC_IO); } void rtc_get_time(byte & hr,byte & min,byte & sec) { byte i; output_low(RTC_CLK); output_low(RTC_IO); output_high(RTC_CE); read_rtc_byte(8*3+4); hr=read_rtc_byte(8); min=read_rtc_byte(8); sec=read_rtc_byte(8); output_low(RTC_CE); output_low(RTC_IO); }