We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I have a Real Time Clock (RTC) located at address 0x180000 I would like to create a struct of the RTC registers and map it to 0x180000 where the RTC registers start, located in far xdata memory or (HDATA). I want to access the RTC such as
RTC.Month = 8;
I think that would be a reasonable thing to do, yes. Something like:
#define RtcAddr 0x180000 typedef struct { U16 year; U8 month; U8 day; } RtcReg; #define Rtc FVAR (RtcReg, RtcAddr) ... Rtc.month = 8;
RtcReg far Rtc _at_ 0x180000UL; Rtc.month = 8;
This is what I came up with that works, it is accessing the RTC at 0x180000.
#define RTC_ADDRESS (0x180000ul) typedef struct RTC_REGS { unsigned char hsec; unsigned char sec; unsigned char min; unsigned char min_alarm; unsigned char hour; unsigned char hour_alarm; unsigned char day; unsigned char day_alarm; unsigned char date; unsigned char month; unsigned char year; unsigned char cmd; unsigned char wd_hsec; unsigned char wd_sec; unsigned char dummy1; unsigned char dummy2; unsigned char user[48]; } RTC_regs; RTC_regs far *RTC_registers = &FVAR(RTC_regs, RTC_ADDRESS); void RTC_Init( void ) { RTC_registers->hsec = 0; RTC_registers->sec = 0; RTC_registers->min = 0; }