Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to use a real time clock chip with an hc11 in expanded mode?

Status
Not open for further replies.

ZeleC

Full Member level 5
Joined
Dec 18, 2002
Messages
261
Helped
3
Reputation
6
Reaction score
1
Trophy points
1,298
Activity points
2,173
can anyone help me find schematics and help(links ,pdf,...) on how to use a real time clock chip with an hc11 in expanded mode .
andif there is other examples or links on using real time clock with different uC please post maybe i could get an idea
thx in advance
 

'***************************************************
'***** mbyka **********
'***************************************************
' DS1302 RTC use

Include "MODEDEFS.BAS"

Define LCD_DREG PORTB
Define LCD_DBIT 4
Define LCD_RSREG PORTB
Define LCD_RSBIT 0
Define LCD_EREG PORTB
Define LCD_EBIT 1

'pins
RST var PORTA.0
IO var PORTA.1
SCLK var PORTA.2

'variables
rtcyear var byte
rtcday var byte
rtcmonth var byte
rtcdate var byte
rtchr var byte
rtcmin var byte
rtcsec var byte
rtccontrol var byte


Main:
Low RST ' Reset RTC
Low SCLK
' saat Set 13:42:00 04/13/02
rtcyear = $02
rtcday = $06
rtcmonth = $04
rtcdate = $13
rtchr = $13
rtcmin = $42
rtcsec = $00
Gosub SetTime
Goto Main_Loop

Main_Loop:
Gosub gettime ' clock read
Lcdout $fe, 1 '1.satır
lcdout hex2 rtcmonth, "/", hex2 rtcdate, "/" , hex2 rtcyear
lcdout $fe,$c0
lcdout hex2 rtchr, ":", hex2 rtcmin, ":", hex2 rtcsec
Pause 300 ' 0.3 sn
Goto Main_Loop




SetTime:
RST = 1 ' Ready for transfer
' Enable write
Shiftout IO, SCLK, LSBFIRST, [$8e, 0]
RST = 0 ' Reset RTC
RST = 1 ' Ready for transfer
' Write all 8 RTC registers in burst mode
Shiftout IO, SCLK, LSBFIRST, [$be, rtcsec, rtcmin, rtchr, rtcdate, rtcmonth, rtcday, rtcyear, 0]
RST = 0 ' Reset RTC
Return


GetTime: ' Subroutine to read time from RTC
RST = 1 ' Ready for transfer
Shiftout IO, SCLK, LSBFIRST, [$bf] ' Read all 8 RTC registers in burst mode
Shiftin IO, SCLK, LSBPRE, [rtcsec, rtcmin, rtchr, rtcdate, rtcmonth, rtcday, rtcyear, rtccontrol]
RST = 0 ' Reset RTC
Return

End
 

Epson and philips also have a lot of RTC.
Epson RTC are also serial.
 

Look this topic:
**broken link removed**
 

Dallas Semiconductors/Maxim (**broken link removed**) also has other greater RTCs. Some of them are serial w/ onboard EEPROM or parallel in combination w/ a few kB of SRAM.
 

Another RTC is the Holtek HT1381, very cheap RTC available in DIP8 and SO8 packages.


Here is the sample ANSI C code I use (with Nec 78k microcontroller) to communicate with HT1381 RTC.
Regards. Paolo


Code:
void ht1381write(uchar addr, uchar data) {
  // Write a byte to the RTC on the specified address
  uchar i;
  rtcrst=1;
  addr<<=1;
  addr|=0x80;
  // Write command byte
  for (i=8;i;i--) {
    if (addr&0x01)
      rtcio=1;
    else
      rtcio=0;
    rtcsck=1;
    addr>>=1;
    rtcsck=0;
  }
  for (i=8;i;i--) {
    if (data&0x01)
      rtcio=1;
    else
      rtcio=0;
    rtcsck=1;
    data>>=1;
    rtcsck=0;
  }
  rtcrst=0;
  rtcio=0;
}

uchar ht1381read(uchar addr) {
  // Read a byte from the RTC on the specified address
  uchar i;
  uchar data;
  rtcrst=1;
  addr<<=1;
  addr|=0x81;
  // Write command byte
  for (i=8;i;i--) {
    rtcsck=0;
    if (addr&0x01)
      rtcio=1;
    else
      rtcio=0;
    rtcsck=1;
    addr>>=1;
  }
  rtciom=1;
  for (i=8;i;i--) {
    rtcsck=0;
    data>>=1;
    if (rtcio)
      data|=0x80;
    rtcsck=1;
  }
  rtcsck=0;
  rtcrst=0;
  rtcio=0;
  rtciom=0;
  return data;
}

uchar rtcGetSeconds(void) {
  uchar value;
  value=ht1381read(0);  // read seconds
  return (((value>>4)&0x07)*10+(value&0x0f));
}

uchar rtcGetMinutes(void) {
  uchar value;
  value=ht1381read(1);
  return (((value>>4)&0x07)*10+(value&0x0f));
}

uchar rtcGetHours(void) {
  uchar value;
  value=ht1381read(2);
  return (((value>>4)&0x03)*10+(value&0x0f));
}

uchar rtcGetDate(void) {
  uchar value;
  value=ht1381read(3);
  return (((value>>4)&0x03)*10+(value&0x0f));
}

uchar rtcGetMonth(void) {
  uchar value;
  value=ht1381read(4);
  return (((value>>4)&0x01)*10+(value&0x0f));
}

uchar rtcGetYear(void) {
  uchar value;
  value=ht1381read(6);
  return (((value>>4)&0x0f)*10+(value&0x0f));
}

uchar rtcGetDay(void) {
  uchar value;
  value=ht1381read(5);
  return (value&0x0f);  // 1..7
}

void rtcGetDateTime(void) {
  seconds=rtcGetSeconds();
  minutes=rtcGetMinutes();
  hours=rtcGetHours();
  day=rtcGetDay();
  date=rtcGetDate();
  month=rtcGetMonth();
  year=rtcGetYear();
}

void rtcPutSeconds(uchar seconds) {
  ht1381write(0,(seconds%10)|((seconds/10)<<4));
}

void rtcPutMinutes(uchar minutes) {
  ht1381write(1,(minutes%10)|((minutes/10)<<4));
}

void rtcPutHours(uchar hours) {
  ht1381write(2,(hours%10)|((hours/10)<<4));
}

void rtcPutDate(uchar date) {
  ht1381write(3,(date%10)|((date/10)<<4));
}

void rtcPutMonth(uchar month) {
  ht1381write(4,(month%10)|((month/10)<<4));
}

void rtcPutDay(uchar day) {
  ht1381write(5,day);
}

void rtcPutYear(uchar year) {
  ht1381write(6,(year%10)|((year/10)<<4));
}


void rtcSetDateTime(void) {
  #ifdef DEBUGRTC
  rs232puts("Start RTC oscillator and initialize date/time!\n");
  #endif
  ht1381write(7,0);
  ht1381write(0,(seconds%10)|((seconds/10)<<4));
  msleep(3000); //wait until 32KHz ckock start
  ht1381write(1,(minutes%10)|((minutes/10)<<4));
  ht1381write(2,(hours%10)|((hours/10)<<4));
  ht1381write(3,(date%10)|((date/10)<<4));
  ht1381write(4,(month%10)|((month/10)<<4));
  ht1381write(5,day);
  ht1381write(6,(year%10)|((year/10)<<4));
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top