Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: PCF8583_rtc mbed
Diff: main.cpp
- Revision:
- 1:a8b9fb95696b
- Parent:
- 0:f09cf90def53
- Child:
- 2:4184f92440a1
--- a/main.cpp Sun Feb 09 00:25:21 2014 +0000
+++ b/main.cpp Thu Feb 13 21:46:08 2014 +0000
@@ -1,17 +1,16 @@
-#include "mbed.h"
+#include <mbed.h>
+//#include "IRremote.h"
#include "PCF8583_rtc.h"
void NixieDisplay(void);
-//void ChangeTime(void);
DigitalOut Red(P0_7);
DigitalOut Green(P0_17);
DigitalOut Blue(P0_16);
I2C i2c(P0_10, P0_11); // sda, scl
-Serial pc(USBTX, USBRX); // tx, rx
-Ticker TickerFunc;
-PCF8583rtc rtc(&i2c);
+PCF8583rtc rtc(&i2c, PCF8583_addr);
+//IRremote rc5(P0_0);
// i2c addresses
const int ADDR_8574_1 = 0x70;
@@ -22,61 +21,76 @@
int main()
{
- struct DateTime_t dtBCD;
-
+ struct DateTime_t dtw;
+ struct DateTime_t dtr;
+ char hours;
+ char mins;
+ char tmp[8] = {1, 2, 3, 4, 5, 6, 7, 8};
+ char tmp1[8];
+
Red = Green = Blue = 1;
-// TickerFunc.attach(&NixieDisplay, 1.0); // The address of the function to be attached and the interval (1 seconds)
i2c.frequency(400000);
- while(1) {
- rtc.read(TIME);
- dtBCD = rtc.GetDateTimeBCD(); //get the date and time in BCD form
- i2c.write(ADDR_8574_1, &dtBCD.time.hours, 1);
- i2c.write(ADDR_8574_2, &dtBCD.time.minutes, 1);
-
- Blue = !Blue;
- wait(.5);
-// if(!sw3.read()) { // Change Time
-// ChangeTime();
-// }
-
-// pc.printf("Magnet = %d\n", magnet.read());
- }
-}
-
-void NixieDisplay()
-{
-// i2c.write(ADDR_8574_1, &HoursBCD, 1);
-// i2c.write(ADDR_8574_2, &MinsBCD, 1);
+ dtw = rtc.read(TIME);
+ dtw.time.hours = rtc.bin2bcd(6);
+ dtw.time.minutes = rtc.bin2bcd(38);
+ rtc.write(TIME, dtw);
- Red = !Red;
-// time_t seconds = time(NULL);
-// struct tm *t = localtime(&seconds);
-//
-// data = bin2bcd(t.tm_hour);
-// i2c.writeite(ADDR_8574_1, &data, 1);
-//
-// data = bin2bcd(t.tm_min);
-// i2c.writeite(ADDR_8574_2, &data, 1);
-}
+ while(1) {
+ for(int x = 0; x < 7; x++) {
+ tmp[x] = rtc.bin2bcd(rand());
+ }
+ rtc.WriteNVram(USER_REG, tmp, 8);
+ wait(1);
+ rtc.ReadNVram(USER_REG, tmp1, 8);
+
+ for(int x = 0; x < 7; x++) {
+ Blue = !Blue;
+ if(tmp[x] != tmp1[x]) {
+ i2c.write(ADDR_8574_1, tmp, 1);
+ tmp1[0] = 0;
+ i2c.write(ADDR_8574_2, tmp1, 1);
+ }
+ }
+ }
+
+/*
+ while(1) {
+ dtr = rtc.read(TIME);
+ i2c.write(ADDR_8574_1, &dtr.time.hours, 1);
+ i2c.write(ADDR_8574_2, &dtr.time.minutes, 1);
+
+ if (rc5.readclear(0) != 0xff) {
+ if(rc5.read(2) != 0xff && rc5.read(3) != 0xff) {
+ hours = (dtr.time.hours & 0xf0) + (dtr.time.hours & 0x0f);
+ mins = (dtr.time.minutes & 0xf0) + (dtr.time.minutes & 0x0f);
+
+ switch(rc5.read(2)) {
+ case 0x47: //Up
+ hours++;
+ dtr.time.hours = rtc.bin2bcd(hours);
+ break;
+ case 0x48: //Down
+ hours--;
+ dtr.time.hours = rtc.bin2bcd(hours);
+ break;
+ case 0x59: //Left
+ mins++;
+ dtr.time.minutes = rtc.bin2bcd(mins);
+ break;
+ case 0x5a: //Right
+ mins--;
+ dtr.time.minutes = rtc.bin2bcd(mins);
+ break;
+ }
-//void ChangeTime() {
-// time_t seconds = time(NULL);
-// wait(0.1);
-// struct tm *t = localtime(&seconds);
-//
-// while(!sw3.read()) {
-// if(!sw2.read()) { //Change Hour
-// t.tm_hour += 1;
-// } else {
-// if(!sw1.read()) { //Change Minute
-// t.tm_min += 1;
-// }
-// }
-//
-// set_time(mktime(t));
-// wait(0.2);
-// }
-//}
-
+ rtc.write(TIME, dtr); //Set the current date and time
+ rc5.clear();
+ }
+ }
+
+ wait(.5);
+ }
+*/
+}