Pages: [1]   Go Down
Author Topic: [Solved]correct output on 1 lcd, wrong on another  (Read 469 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 2
Posts: 148
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hello. im using this display http://www.dfrobot.com/wiki/index.php?title=Arduino_LCD_KeyPad_Shield_(SKU:_DFR0009). i am getting correct output on a scott edwards bpp420 serial lcd, but not on the dfrobot display. example, the first displays the year correctly as 2013, the dfrobot displays 2165. ofcourse the code has been modified to work with each one, and text formats correctly on the dfrobot. original code from 1302 library modified to suit my needs for testing. heres the code for the dfrobot display. thank you for looking and taking a crack at it.

Code:
#include <LiquidCrystal.h>
#include <stdio.h>
#include <string.h>
#include <DS1302.h>

/* Set the appropriate digital I/O pin connections */
uint8_t CE_PIN   = 11;                                                 // also tried pins 2, 11, 12, wrang the pins out to ensure im landing the right ones
uint8_t IO_PIN   = 12;
uint8_t SCLK_PIN = 13;

/* Create buffers */
char buf[50];
char day[10];

/* Create a DS1302 object */
DS1302 rtc(CE_PIN, IO_PIN, SCLK_PIN);
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

void print_time()
{
  /* Get the current time and date from the chip */
  Time t = rtc.time();

  /* Name the day of the week */
  memset(day, 0, sizeof(day));  /* clear day buffer */
  switch (t.day) {
  case 1:
    strcpy(day, "Sunday");
    break;
  case 2:
    strcpy(day, "Monday");
    break;
  case 3:
    strcpy(day, "Tuesday");
    break;
  case 4:
    strcpy(day, "Wednesday");
    break;
  case 5:
    strcpy(day, "Thursday");
    break;
  case 6:
    strcpy(day, "Friday");
    break;
  case 7:
    strcpy(day, "Saturday");
    break;
  }

  //Format the time and date and insert into the temporary buffer
  snprintf(buf, sizeof(buf), "%s %04d-%02d-%02d %02d:%02d:%02d",
  day,
  t.yr, t.mon, t.date,
  t.hr, t.min, t.sec);
  // snprintf(buf, sizeof(buf),"%02d:%02d",t.hr,t.min);

  /* Print the formatted string to serial so we can see the time */
  lcd.print(t.yr);                                                                        // <--------here is output
  Serial.print(t.yr);                                                                        //        it prints wrong in the serial window also, but not on the other bpp420 using softserial library
}


void setup()
{
  Serial.begin(9600);
  lcd.begin(16,2);
   /* Initialize a new chip by turning off write protection and clearing the
   clock halt flag. These methods needn't always be called. See the DS1302
   datasheet for details. */

  rtc.write_protect(false);
  rtc.halt(false);

  // Make a new time object to set the date and time
  // Tuesday, May 19, 2009 at 21:16:37.          
  // Time t(2013, 1, 24, 18, 55, 00, 5);

  // Set the time and date on the chip
  // rtc.time(t);
}


/* Loop and print the time every second */
void loop()
{
  print_time();
  delay(1000);
  lcd.clear();

}
« Last Edit: January 25, 2013, 01:04:53 pm by grendle » Logged

Offline Offline
Full Member
***
Karma: 2
Posts: 148
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

pins 2, 3, and 11 work. had to ring them out again. counting DO (on the shield) from low to high #2 pin is 5 over, 3 is 6, and 11 is 7th. it works now, ill have to map them all out.
Logged

Pages: [1]   Go Up
Jump to: