DCF77 clock using the HY-1.8 LCD display. Sets KL25Z RTC clock and will continue to run with no DCF signal. Import the libraries to work on FRDM-KL25Z board, sends 8 bit writes to the LCD.

Dependencies:   HY-1_8TFT_ST7735 TSI mbed

Fork of KL25Z_DCF77_HY-1_8LCD by Paul Staron

This project shows the KL25Z connected to a very cheap (3 Euros) Chinese TFT LCD Display (HY-1.8 SPI from Ebay). I have modified a ST7753 driver library to work the 8 bit SPI write that the Mbed library sets the FRDM board to (not sure why as the KL25Z MCU has16 bit cababiliy). The libraries are available for import from my home page. and includes five different fonts (three are needed for this example).

I have also used the Analog Out (pin PTE30) to control the LED back light level, simply connect a small NPN transistor in the LED -ve connection to ground and feed the analog out pin to the base of the transistor via a 10k ohm resistor. When you slide your finger across the TSI touch slider the display brightness can be changed from off to full level.

The code it much the same as the other projects I have published, just with different LCD drive code. This program will decode the DCF77 signal connected to pin PTE20 and set the RTC clock. The photo shows the display before I modified the LED backlight drive circuit.

The display runs at 5V and draws arround 20mA, the backlight led will also run at this voltage and is nice and bright. It can also be connected to the USB 3v pin and runs at a lower level. there is a solder jumper to bypass the 5v regulator, leave this open and it will run on both volages, if this jumper is closed it will bypass the regulator and if connected to the 5v supply, the display will be 'bricked' so take care!.

This display is considerably better and cheaper than the Nokia display but not as good as Oled. Easy to connect, 5 data connections and 2 power wires. It also includes a SD card slot that can be connected to the FRDM board.

The backlight is LED it does not use a switch mode DC-DC converter circuit so RF noise is very low, this is essential when using a sensitive VLF DCF77 radio receiver close by.

The FRDM board and display runs at 50mA depending on LED brightness.

/media/uploads/star297/_scaled_20130322_132442.jpg

Committer:
smultron1977
Date:
Mon Dec 12 21:35:42 2011 +0000
Revision:
0:2353da390056
Child:
1:6f4c5876140d
Original 2 hour hack

Who changed what in which revision?

UserRevisionLine numberNew contents of line
smultron1977 0:2353da390056 1 /** ST7735 Pong by Jonne Valola, derived work from William Johnston's mbed Pong for NokiaLCD / PS2 keyboard
smultron1977 0:2353da390056 2 * This pong uses a rotary encoder hooked to pins 21 and 22,
smultron1977 0:2353da390056 3 * ST7735_TFT library by me, RotaryEncoder library by Shinichiro Nakamura
smultron1977 0:2353da390056 4 * All copyrights of respective owners. Use on your own risk and discretion.
smultron1977 0:2353da390056 5 */
smultron1977 0:2353da390056 6
smultron1977 0:2353da390056 7 #include "mbed.h"
smultron1977 0:2353da390056 8 #include "ball.h"
smultron1977 0:2353da390056 9 #include "paddle.h"
smultron1977 0:2353da390056 10 #include "ST7735_TFT.h"
smultron1977 0:2353da390056 11 #include "string"
smultron1977 0:2353da390056 12 #include "Arial12x12.h"
smultron1977 0:2353da390056 13 #include "Arial24x23.h"
smultron1977 0:2353da390056 14 #include "RotaryEncoder.h"
smultron1977 0:2353da390056 15
smultron1977 0:2353da390056 16 RotaryEncoder re(p21, p22, 0, 600, 300);
smultron1977 0:2353da390056 17
smultron1977 0:2353da390056 18 // State enumerator
smultron1977 0:2353da390056 19 typedef enum {
smultron1977 0:2353da390056 20 RESET, RUN, PAUSE
smultron1977 0:2353da390056 21 } STATES;
smultron1977 0:2353da390056 22
smultron1977 0:2353da390056 23 ST7735_TFT lcd(p5, p6, p7, p8, p11, p15,"TFT"); // mosi, miso, sclk, cs, rs, reset
smultron1977 0:2353da390056 24
smultron1977 0:2353da390056 25 /*
smultron1977 0:2353da390056 26 * Subroutine drawScreen:
smultron1977 0:2353da390056 27 * Description: Draws both paddles
smultron1977 0:2353da390056 28 * and the ball.
smultron1977 0:2353da390056 29 */
smultron1977 0:2353da390056 30 void drawScreen(Paddle paddle1, Paddle paddle2, Ball theBall, bool isBlack) {
smultron1977 0:2353da390056 31 paddle1.draw(lcd, isBlack);
smultron1977 0:2353da390056 32 paddle2.draw(lcd ,isBlack);
smultron1977 0:2353da390056 33 theBall.draw(lcd ,isBlack);
smultron1977 0:2353da390056 34 }
smultron1977 0:2353da390056 35
smultron1977 0:2353da390056 36 /*
smultron1977 0:2353da390056 37 * Subroutine drawScores:
smultron1977 0:2353da390056 38 * Description: Draws the scoreboard
smultron1977 0:2353da390056 39 */
smultron1977 0:2353da390056 40 void drawScores(Paddle paddle1, Paddle paddle2) {
smultron1977 0:2353da390056 41 lcd.locate(60,1);
smultron1977 0:2353da390056 42 lcd.printf("%d", paddle1.getScore());
smultron1977 0:2353da390056 43 lcd.locate(90,1);
smultron1977 0:2353da390056 44 lcd.printf("%d", paddle2.getScore());
smultron1977 0:2353da390056 45 lcd.fillrect(79,0,81,128,0xFFFFFF);
smultron1977 0:2353da390056 46 }
smultron1977 0:2353da390056 47
smultron1977 0:2353da390056 48 int main() {
smultron1977 0:2353da390056 49 lcd.background(0x000000);
smultron1977 0:2353da390056 50 lcd.cls();
smultron1977 0:2353da390056 51 lcd.set_orientation(1);
smultron1977 0:2353da390056 52 lcd.set_font((unsigned char*) Arial12x12); // select the font
smultron1977 0:2353da390056 53 Paddle paddle1, paddle2;
smultron1977 0:2353da390056 54 Ball theBall;
smultron1977 0:2353da390056 55 int temp, count=0, oldY;
smultron1977 0:2353da390056 56 drawScreen(paddle1, paddle2, theBall, false);
smultron1977 0:2353da390056 57 drawScores(paddle1, paddle2);
smultron1977 0:2353da390056 58 STATES state = RESET; // Initial state is RESET
smultron1977 0:2353da390056 59 while(1) {
smultron1977 0:2353da390056 60 switch(state) {
smultron1977 0:2353da390056 61 case RESET: // Reset objects, draw the screen, state = PAUSE
smultron1977 0:2353da390056 62 lcd.cls();
smultron1977 0:2353da390056 63 paddle1 = Paddle(0,40,5,25,0xFFFFFF,paddle1.getLives(),paddle1.getScore());
smultron1977 0:2353da390056 64 paddle2 = Paddle(154,40,5,25,0xFFFFFF,paddle2.getLives(),paddle2.getScore());
smultron1977 0:2353da390056 65 theBall = Ball(80,64,5,5,0xFFFF00,1,1);
smultron1977 0:2353da390056 66 drawScreen(paddle1, paddle2, theBall, false);
smultron1977 0:2353da390056 67 drawScores(paddle1, paddle2);
smultron1977 0:2353da390056 68 oldY = re.getVal();
smultron1977 0:2353da390056 69 state = RUN;
smultron1977 0:2353da390056 70 break;
smultron1977 0:2353da390056 71 case RUN:
smultron1977 0:2353da390056 72 if (oldY > re.getVal()) { // Executes if encoder turned
smultron1977 0:2353da390056 73 if(paddle1.getY()>2)
smultron1977 0:2353da390056 74 paddle1.move(lcd, -2);
smultron1977 0:2353da390056 75 }
smultron1977 0:2353da390056 76 if (oldY < re.getVal()) { // Executes if encoder turned
smultron1977 0:2353da390056 77 if(paddle1.getY()+paddle1.getHeight()<128)
smultron1977 0:2353da390056 78 paddle1.move(lcd, 2);
smultron1977 0:2353da390056 79 }
smultron1977 0:2353da390056 80 oldY = re.getVal();
smultron1977 0:2353da390056 81
smultron1977 0:2353da390056 82 if(count%2) // Only let CPU move once every 2 times through the loop
smultron1977 0:2353da390056 83 paddle2.moveCPU(lcd, theBall.getY());
smultron1977 0:2353da390056 84 if(++count==5) { // Only move the ball once every 5 times through the loop
smultron1977 0:2353da390056 85 count = 0;
smultron1977 0:2353da390056 86 if(theBall.hitP1((paddle1.getX()+paddle1.getWidth()), paddle1.getY(), paddle1.getHeight()))
smultron1977 0:2353da390056 87 theBall.reverseX();
smultron1977 0:2353da390056 88 if(theBall.hitP2(paddle2.getX(), paddle2.getY(), paddle2.getHeight()))
smultron1977 0:2353da390056 89 theBall.reverseX();
smultron1977 0:2353da390056 90 if(theBall.hitX()) { // If the ball hits one of the sides of the screen
smultron1977 0:2353da390056 91 if(theBall.getX()<7) { // If the ball hit paddle1's side
smultron1977 0:2353da390056 92 paddle2.addPoint();
smultron1977 0:2353da390056 93 }
smultron1977 0:2353da390056 94 else if(theBall.getX()>153) { // If the ball hit paddle2's side
smultron1977 0:2353da390056 95 paddle1.addPoint();
smultron1977 0:2353da390056 96 }
smultron1977 0:2353da390056 97 theBall.reverseX();
smultron1977 0:2353da390056 98 state = RESET; // Reset the objects
smultron1977 0:2353da390056 99 }
smultron1977 0:2353da390056 100 if(theBall.hitY())
smultron1977 0:2353da390056 101 theBall.reverseY();
smultron1977 0:2353da390056 102 theBall.move(lcd);
smultron1977 0:2353da390056 103 }
smultron1977 0:2353da390056 104 break;
smultron1977 0:2353da390056 105 }
smultron1977 0:2353da390056 106 drawScreen(paddle1, paddle2, theBall, false);
smultron1977 0:2353da390056 107 drawScores(paddle1, paddle2);
smultron1977 0:2353da390056 108 }
smultron1977 0:2353da390056 109 }