===== Description =====
This demo shows how to use some of the RTC function made available via the nz_rtc.h and nz_rtc.c drivers. It is meant to be used together with the Netcruzer USB Terminal App. This app is used to send debug commands to, an receive debug messages from the target SBC66 board.
Using this app, various debug commands can be sent to the SBC66 board. These commands are processed in the debugService() function. For example:
- Sending the "st" string will set the time of the RTC to 11:40:50.
- Sending the "t" string will request the current time and date, which will be displayed in the "Netcruzer USB Terminal" app.
===== Required Hardware =====
The project requires a SBC66 Netcruzer board with a RTC and USB Port (not USB Host), like the SBC66EC for example.
===== Building Project =====
This project is located in the "src/demos/template/rtc_debug_demo" folder of the Netcruzer Download. To compile for Netcruzer Board, open this project in MPLAB X, and select the "Project Configuration" for desired board. For example "SBC66EC_R2" for the SBC66EC Revision 2 board. For details click here
===== Programming Board =====
After compiling (build), the board can be programmed via the USB Bootloader or a PIC Programmer. USB Programming is simplified when using the SBC board together with a Prototype Board.
===== File History =====
2014-01-08, David H. (DH):
#define THIS_IS_MAIN_FILE //Uniquely identifies this as the file with the main application entry function main()
#include "HardwareProfile.h"
#if !defined(DEBUG_CONF_MAIN)
#define DEBUG_CONF_MAIN DEBUG_CONF_DEFAULT //Default Debug Level, disabled if DEBUG_LEVEL_ALLOFF defined, else DEBUG_LEVEL_ERROR
#endif
#define MY_DEBUG_LEVEL DEBUG_CONF_MAIN
static WORD tmrFlashLed = 0;
int main(void) {
DEBUG_PUT_STR(DEBUG_LEVEL_INFO,
"\nThis is a test debug message from rtc_debug_demo demo");
DIR_SYSLED = OUTPUT_PIN;
rtcUnlock();
while(1)
{
LAT_SYSLED = !LAT_SYSLED;
}
}
}
#if defined(HAS_NZ_DEBUGGING)
void debugService(void) {
debugPutString("\nHello");
}
debugPutString("\nRTC Lock");
rtcLock();
}
debugPutString("\nRTC Unlock");
rtcUnlock();
}
debugPutString("\nSec = ");
debugPutByte(rtcGetSec());
}
tm.hour = 11;
tm.min = 40;
tm.sec = 50;
rtcSetTime(&tm);
debugPutString("\nSet time to 11:40:50");
}
RTC_TIME_AND_DATE td = {8,15,30,25,12,10,0};
rtcSetTimeAndDate(&td);
debugPutString("\nSet time to 8:15:30, and date to 25 Dec 2010");
}
BYTE ram1, ram2;
rtcSetRAM1(0x56);
rtcSetRAM2(0xAB);
ram1 = rtcGetRAM1();
ram2 = rtcGetRAM2();
if ((ram1 == 0x56) && (ram2 == 0xAB))
debugPutString("\nRAM OK!");
else
debugPutString("\nRAM Error!");
}
RTC_TIME_AND_DATE td;
rtcGetTimeAndDate(&td, 0);
printf(
"\nTime: %02d:%02d:%02d, Date: %02d-%02d-%d", td.hour, td.min, td.sec, td.day, td.month, td.year+2000);
}
rtcGetTime(&tm, 0);
printf(
"\nTime: %02d:%02d:%02d", tm.hour, tm.min, tm.sec);
}
rtcGetTime(&tm, 1);
debugPutString("\nTime: ");
debugPutChar('0' + (tm.hour>>4));
debugPutChar('0' + (tm.hour&0x0f));
debugPutChar(':');
debugPutChar('0' + (tm.min>>4));
debugPutChar('0' + (tm.min&0x0f));
debugPutChar(':');
debugPutChar('0' + (tm.sec>>4));
debugPutChar('0' + (tm.sec&0x0f));
}
RTC_DATE dt;
rtcGetDate(&dt, 0);
printf(
"\nDate: %02d-%02d-%d", dt.day, dt.month, dt.year+2000);
}
}
}
}
#endif