Go Down

Topic: Please help with this code its throwing errors everywhere (Read 62 times) previous topic - next topic

thepratotype

Please I need lots of help and would greatly appreciate it this code is throwing codes everywhere please help
I can not post it all so message me for all of it please



*/

#include <stdio.h>
#include <LiquidCrystal.h>
#include <Wire.h>

//
// Initializations

// Debugging mode - prints debugging information on the Serial port.
boolean debug = true;

// Front Panel Light
int lightPin = 13;

// WWVB Receiver Pin
int wwvbInPin = 2;

// LCD init
LiquidCrystal lcd(12, 11, 6, 5, 4, 3);

// RTC init
// RTC uses pins Analog4 = SDA, Analog5 = SCL

// RTC I2C Slave Address
#define DS1307 0xD0 >> 1

// RTC Memory Registers
#define RTC_SECS        0
#define RTC_MINS        1
#define RTC_HRS         2
#define RTC_DAY         3
#define RTC_DATE        4
#define RTC_MONTH       5
#define RTC_YEAR        6
#define RTC_SQW         7

// Month abbreviations
char *months[12] = {
 "Jan",
 "Feb",
 "Mar",
 "Apr",
 "May",
 "Jun",
 "Jul",
 "Aug",
 "Sep",
 "Oct",
 "Nov",
 "Dec"
};

// Day of Year to month translation (thanks to Capt.Tagon)
// End of Month - to calculate Month and Day from Day of Year
int eomYear[14][2] = {
 {0,0},      // Begin
 {31,31},    // Jan
 {59,60},    // Feb
 {90,91},    // Mar
 {120,121},  // Apr
 {151,152},  // May
 {181,182},  // Jun
 {212,213},  // Jul
 {243,244},  // Aug
 {273,274},  // Sep
 {304,305},  // Oct
 {334,335},  // Nov
 {365,366},  // Dec
 {366,367}   // overflow
};


//
// Globals

// Timing and error recording
unsigned long pulseStartTime = 0;
unsigned long pulseEndTime = 0;
unsigned long frameEndTime = 0;
unsigned long lastRtcUpdateTime = 0;
boolean bitReceived = false;
boolean wasMark = false;
int framePosition = 0;
int bitPosition = 1;
char lastTimeUpdate[17];
char lastBit = ' ';
int errors[10] = { 1,1,1,1,1,1,1,1,1,1 };
int errIdx = 0;
int bitError = 0;
boolean frameError = false;

// RTC clock variables
byte second = 0x00;
byte minute = 0x00;
byte hour = 0x00;
byte day = 0x00;
byte date = 0x01;
byte month = 0x01;
byte year = 0x00;
byte ctrl = 0x00;

// WWVB time variables
byte wwvb_hour = 0;
byte wwvb_minute = 0;
byte wwvb_day = 0;
byte wwvb_year = 0;


/* WWVB time format struct - acts as an overlay on wwvbRxBuffer to extract time/date data.
* This points to a 64 bit buffer wwvbRxBuffer that the bits get inserted into as the
* incoming data stream is received.  (Thanks to Capt.Tagon @ duinolab.blogspot.com)
*/
struct wwvbBuffer {
 unsigned long long U12       :4;  // no value, empty four bits only 60 of 64 bits used
 unsigned long long Frame     :2;  // framing
 unsigned long long Dst       :2;  // dst flags
 unsigned long long Leapsec   :1;  // leapsecond
 unsigned long long Leapyear  :1;  // leapyear
 unsigned long long U11       :1;  // no value
 unsigned long long YearOne   :4;  // year (5 -> 2005)
 unsigned long long U10       :1;  // no value
 unsigned long long YearTen   :4;  // year (5 -> 2005)
 unsigned long long U09       :1;  // no value
 unsigned long long OffVal    :4;  // offset value
 unsigned long long U08       :1;  // no value
 unsigned long long OffSign   :3;  // offset sign
 unsigned long long U07       :2;  // no value
 unsigned long long DayOne    :4;  // day ones
 unsigned long long U06       :1;  // no value
 unsigned long long DayTen    :4;  // day tens
 unsigned long long U05       :1;  // no value
 unsigned long long DayHun    :2;  // day hundreds
 unsigned long long U04       :3;  // no value
 unsigned long long HourOne   :4;  // hours ones
 unsigned long long U03       :1;  // no value
 unsigned long long HourTen   :2;  // hours tens
 unsigned long long U02       :3;  // no value
 unsigned long long MinOne    :4;  // minutes ones
 unsigned long long U01       :1;  // no value
 unsigned long long MinTen    :3;  // minutes tens
};

struct wwvbBuffer * wwvbFrame;
unsigned long long receiveBuffer;
unsigned long long lastFrameBuffer;


/*
* setup()
*
* uC Initialization
*/

void setup() {

 // Debugging information prints to the serial line
 if (debug) { Serial.begin(9600); }
 if (debug) { Serial.println("Ready."); }

 // Initialize the I2C Two Wire Communication for the RTC
 Wire.begin();

 // Set up the LCD's number of rows and columns:
 lcd.begin(16, 2);
 
 // Setup the light pin
 pinMode(lightPin, OUTPUT);
 digitalWrite(lightPin, HIGH);

 // Print a message to the LCD.
 lcd.clear();
 lcd.setCursor(0, 0);
 lcd.print("WWVB Clock v 1.0");
 lcd.setCursor(0, 1);
 lcd.print("PopSci Apr. 2010");
 delay(5000);

 // Front panel light lights for 10 seconds on a successful frame rcpt.
 digitalWrite(lightPin, LOW);
 
 // Setup the WWVB Signal In Handling
 pinMode(wwvbInPin, INPUT);
 attachInterrupt(0, wwvbChange, CHANGE);

 // Setup the WWVB Buffer
 lastFrameBuffer = 0;
 receiveBuffer = 0;
 wwvbFrame = (struct wwvbBuffer *) &lastFrameBuffer;

}


/*
* loop()
*
* Main program loop
*/

void loop() {

 // If we've received another bit, process it
 if (bitReceived == true) {
   processBit();
 }

 // Read from the RTC and update the display 4x per second
 if (millis() - lastRtcUpdateTime > 250) {

   // Snag the RTC time and store it locally
   getRTC();
   
   // And record the time of this last update.
   lastRtcUpdateTime = millis();

   // Update RTC if there has been a successfully received WWVB Frame
   if (frameEndTime != 0) {
     updateRTC();
     frameEndTime = 0;
   }

   // Update the display
   updateDisplay();

 }

}


/*
* updateDisplay()
*
* Update the 2 line x 16 char LCD display
*/

void updateDisplay() {

 // Turn off the front panel light marking a successfully
 // received frame after 10 seconds of being on.
 if (bcd2dec(second) >= 10) {
   digitalWrite(lightPin, LOW);
 }

 // Update the LCD
 lcd.clear();

 // Update the first row
 lcd.setCursor(0,0);
 char *time = buildTimeString();
 lcd.print(time);

 // Update the second row
 // Cycle through our list of status messages
 lcd.setCursor(0,1);
 int cycle = bcd2dec(second) / 10; // This gives us 6 slots for messages
 char msg[17]; // 16 chars per line on display

 switch (cycle) {

   // Show the Date
   case 0:
   {
     sprintf(msg, "%s %0.2i 20%0.2i",
             months[bcd2dec(month)-1], bcd2dec(date), bcd2dec(year));
     break;
   }

   // Show the WWVB signal strength based on the # of recent frame errors
   case 1:
   {
     int signal = (10 - sumFrameErrors()) / 2;
     sprintf(msg, "WWVB Signal: %i", signal);
     break;
   }

   // Show LeapYear and LeapSecond Warning bits
   case 2:
   {
     const char *leapyear = ( ((byte) wwvbFrame->Leapyear) == 1)?"Yes":"No";
     const char *leapsec  = ( ((byte) wwvbFrame->Leapsec) == 1)?"Yes":"No";
     sprintf(msg, "LY: %s  LS: %s", leapyear, leapsec);
     break;
   }

   // Show our Daylight Savings Time status
   case 3:
   {  
     switch((byte)wwvbFrame->Dst) {
       case 0:
 sprintf(msg, "DST: No");
         break;
       case 1:
         sprintf(msg, "DST: Ending");
         break;
       case 2:
         sprintf(msg, "DST: Starting");
         break;
       case 3:
         sprintf(msg, "DST: Yes");
         break;
     }
     break;
   }

   // Show the UT1 correction sign and amount
   case 4:
   {
     char sign;
     if ((byte)wwvbFrame->OffSign == 2) {
sign = '-';
     } else if ((byte)wwvbFrame->OffSign == 5) {
sign = '+';
     } else {
sign = '?';
     }
     sprintf(msg, "UT1 %c 0.%i", sign, (byte) wwvbFrame->OffVal);
     break;
   }

   // Show the time and date of the last successfully received
   // wwvb frame
   case 5:
   {
     sprintf(msg, "[%s]", lastTimeUpdate);
     break;
   }
 }
 
 lcd.print(msg);

}


/*
* buildTimeString
*
* Prepare the string for displaying the time on line 1 of the LCD
*/

char* buildTimeString() {
 char rv[255];
 sprintf(rv,"%0.2i:%0.2i:%0.2i UTC   %c",
       bcd2dec(hour),
       bcd2dec(minute),
       bcd2dec(second),
       lastBit);
 return rv;
}


/*
* getRTC
*
* Read data from the DS1307 RTC over the I2C 2 wire interface.
* Data is stored in the uC's global clock variables.
*/

void getRTC() {

 // Begin the Transmission
 Wire.beginTransmission(DS1307);

 // Point the request at the first register (seconds)
 Wire.send(RTC_SECS);

 // End the Transmission and Start Listening
 Wire.endTransmission();
 Wire.requestFrom(DS1307, 8);
 second = Wire.receive();
 minute = Wire.receive();
 hour = Wire.receive();
 day = Wire.receive();
 date = Wire.receive();
 month = Wire.receive();
 year = Wire.receive();
 ctrl = Wire.receive();
}



Ballscrewbob

It may not be the answer you were looking for but its the one I am giving based on either experience, educated guess, google or the fact that you gave nothing to go with in the first place so I used my wonky crystal ball.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy