Menu

Clock with Large Digits and a Cheap LCD2004

Ralf Pagel
7 days ago
2 days ago
  • Ralf Pagel

    Ralf Pagel - 7 days ago

    Hi,

    Today I'd like to present my program for a digital clock. The clock uses a cheap LCD display with 4 lines of 20 characters each. An ATmega328p, an ATmega2560, or an AVR128DA28 can be used as the microcontroller. I used the corresponding Arduino boards for program development.

    The program uses block graphics. Some readers may remember this technique from the days of the first home computers. Due to their limited processing power, graphics capabilities were very restricted back then. Therefore, home computers included characters in their character sets that allowed users to create graphics on the screen (i.e., the television). These characters made it possible to create attractive borders around text, as well as simple graphics for games.

    The LC display 2004 contains eight registers for user-defined characters. Together with two characters from the regular character set (254 and 255), these ten characters are sufficient to generate six attractive digits and two separators, which are displayed across the entire screen. This allows the clock to be easily read even from a distance.

    Because this project is only a study, the CPU clock speed is used as a time reference. A timer is set to generate interrupts at 10ms intervals. This frequency is then divided down to 1Hz to increment the displayed time in one-second intervals. The CPU clock speed, of course, does not meet the accuracy requirements of a functioning clock. Therefore, if this clock is used in a real-world application, a better time reference (e.g., a TCXO) must be used.

    Ralf

     
    👍
    1
  • Anobium

    Anobium - 7 days ago

    Very nice. I like the configuration for many chips. Very clever.

    May I put this in the demonstration Git/Repository? This has some clever techniques.

    Evan

     
  • Roger Jönsson

    Roger Jönsson - 7 days ago

    Very Cool!

     
  • Ralf Pagel

    Ralf Pagel - 3 days ago

    Hi,

    I only have an ATmega328pb and not an ATmega328p in my parts bin. Therefore, I tested the program with an ATmega328pb and not an ATmega328p. I specified the ATmega328p as the chip because the compiler worked with that chip. I've since managed to fix this error (more details in another post). Therefore, I've updated the file again (see attachment). However, I have no way to test the program with an ATmega328p, but it will most likely work as well. Perhaps someone who owns an ATmega328p could test it and report back here bevore Evan put this in the demonstration Git/Repository. Thanks.

    Ralf

     
    • Anobium

      Anobium - 3 days ago

      Add a Warning into the #script to say that ATmega328p has not been tested, but, should work... let us know if is does....

       
  • Ralf Pagel

    Ralf Pagel - 3 days ago

    I've added the warning. The file is attached.

     
  • Anobium

    Anobium - 2 days ago

    Ralf is this good to add? This is meant to explain the port usage.

    Evan

    #IF CHIPNAME = mega328p or CHIPNAME = mega328pb
      /*
             ------------PORTA---------------
      Bit#:  -7---6---5---4---3---2---1---0---
      IO:    ---------------------------------
      IO:    ---------------------------------   (PORTA not used in this program)
    
             ------------PORTB----------------
      Bit#:  -7---6---5---4---3---2---1---0---
      IO:    --  --  LED  Btn-d Btn-u Btn-s --  --
      IO:    PB7 PB6 PB5  PB4   PB3   PB2  PB1 PB0
             LED on PB5 (Arduino pin 13)
             Buttons: PB2=Set, PB3=Up, PB4=Down (active low, internal pull-ups)
    
             ------------PORTC----------------
      Bit#:  -7---6---5---4---3---2---1---0---
      IO:    --  --  SCL  SDA  --  --  --  --
      IO:    PC6 PC5 PC5  PC4  PC3 PC2 PC1 PC0
             I2C:   PC4=SDA, PC5=SCL  (Arduino A4/A5)
      */
    #ENDIF
    
    #IF CHIPNAME = mega2560
      /*
             ------------PORTA---------------
      Bit#:  -7---6---5---4---3---2---1---0---
      IO:    ---------------------------------
      IO:    ---------------------------------   (PORTA not used in this program)
    
             ------------PORTB----------------
      Bit#:  -7---6---5---4---3---2---1---0---
      IO:    --  --  --  LED  Btn-d Btn-u Btn-s -- 
      IO:    PB7 PB6 PB5  PB4   PB3   PB2   PB1 PB0
             LED on PB7
             Buttons: PB4=Set, PB5=Up, PB6=Down (active low, internal pull-ups)
    
             ------------PORTC----------------
      Bit#:  -7---6---5---4---3---2---1---0---
      IO:    ---------------------------------
      IO:    PC7 PC6 PC5  PC4  PC3 PC2 PC1 PC0    (PORTC not used)
    
             ------------PORTD----------------   (extra port used for I2C)
      Bit#:  -7---6---5---4---3---2---1---0---
      IO:    --  --  --  --  --  --  SCL  SDA
      IO:    PD7 PD6 PD5 PD4 PD3 PD2 PD1  PD0
             I2C: PD0=SCL, PD1=SDA   (Arduino Mega pins 21/20)
      */
    #ENDIF
    
    #IF CHIPNAME = avr128da28
      /*
             ------------PORTA----------------   (I2C here)
      Bit#:  -7---6---5---4---3---2---1---0---
      IO:    --  --  --  --  --  SCL  SDA  --
      IO:    PA7 PA6 PA5 PA4 PA3 PA2  PA1 PA0
             I2C: PA2=SDA, PA3=SCL
    
             ------------PORTB----------------
      Bit#:  -7---6---5---4---3---2---1---0---
      IO:    ---------------------------------
      IO:    PB7 PB6 PB5 PB4 PB3 PB2 PB1 PB0    (PORTB not used)
    
             ------------PORTC----------------   (LED + buttons)
      Bit#:  -7---6---5---4---3---2---1---0---
      IO:    --  --  --  -- Btn-s LED  Btn-d Btn-u
      IO:    PC7 PC6 PC5 PC4  PC3  PC2   PC1  PC0
             LED on PC2
             Buttons: PC3=Set, PC0=Up, PC1=Down (active low, pull-ups enabled via PORTC_PINxCTRL)
      */
    #ENDIF
    
     
  • Ralf Pagel

    Ralf Pagel - 2 days ago

    Hi Evan,

    First of all:
    You've written a very nice website about it. Thank you!

    Explaination of port usage:
    Port usage is flawless and certainly very helpful.
    Do you mean I should add it to the GCB file, or do you want to add it to the demonstration Git/Repository web side? I think both options are fine.

    Ralf

     
  • Anobium

    Anobium - 2 days ago

    I added to your source as a header. Looks nice.


    Most interestng. I also compiled using AVRASM2 ( as a validation ). Compiled very nicely. :-)
    This means the ASM generated is 100% valid. I have attached the LST file for your review.

     

Log in to post a comment.