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: mbed
Fork of Digital_project by
Revision 0:4585326daab4, committed 2015-12-07
- Comitter:
- 57340500039
- Date:
- Mon Dec 07 16:05:23 2015 +0000
- Child:
- 1:a4c852d25ead
- Commit message:
- digital_project
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/LCD4884.cpp Mon Dec 07 16:05:23 2015 +0000
@@ -0,0 +1,166 @@
+/*
+Modified by COX
+version 0.1
+
+Editor : COX
+Date : 06.03.2013
+
+*
+* Update DFRobot source to work on FRDM KL25Z
+*
+*/
+
+#include "LCD4884.h"
+#include "font_6x8.h"
+#include "font_big.h"
+#include "mbed.h"
+#include <SPI.h>
+
+DigitalOut SpiClk(D2); //2- Serial Clock(Master Output)
+DigitalOut SpiMosi(D3); //3- Master Output,Slave Input
+DigitalOut LcdDC(D4); //4- Data/Command(command active low)
+DigitalOut SpiCS(D5); //5- Chip Select,Slave Transmit Enable(active low,Master Output)
+DigitalOut LcdRst(D6); //6- One Reset button
+PwmOut LcdBl(D7); //7- LCD backlight
+
+LCD4884::LCD4884()
+{};
+
+/********************************************************************/
+void LCD4884::backlight(float dat)
+{
+ LcdBl = dat;
+}
+/********************************************************************/
+void LCD4884::LCD_write_byte(unsigned char dat, unsigned char dat_type)
+{
+ unsigned int i;
+ SpiCS = 0; //Chip Enable:Active LOW
+ unsigned char compare[8] = {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
+
+ if (dat_type == 0)
+ LcdDC = 0; // D/C=0:the current data byte is interpreted as command byte
+ else
+ LcdDC = 1; // D/C=1:write data to display RAM
+
+
+ for(i=0;i<8;i++) {
+ if(dat&compare[7-i])
+ {
+ SpiMosi = 1;
+ }
+ else
+ {
+ SpiMosi = 0;
+ }
+ SpiClk = 0;
+
+ SpiClk = 1;
+ }
+ SpiCS = 1;
+ //printf("a\n");
+}
+/********************************************************************/
+void LCD4884::LCD_write_char(unsigned char c, char mode)
+{
+ unsigned char line;
+ unsigned char *pFont;
+ unsigned char ch;
+
+ pFont = (unsigned char *)font6_8; //pointer *pFont points at font6_8[][6]
+ c -= 32; // the ASCII of "SP" is 32
+
+ for (line=0; line<6; line++)
+ {
+ ch = *(pFont+c*6+line); //read c from the font6_8[][6] (the detail information is in the "font6x8.h")
+ LCD_write_byte((mode==MENU_NORMAL)? ch:(ch^ 0xff), 1); //MENU_NORMAL=0,True:return ch;False:return ch
+ }
+}
+/********************************************************************/
+void LCD4884::LCD_set_XY(unsigned char X, unsigned char Y)
+{
+ LCD_write_byte(0x40 | Y, 0); // column
+ LCD_write_byte(0x80 | X, 0); // row
+}
+/********************************************************************/
+void LCD4884::LCD_clear(void)
+{
+ unsigned int i;
+
+ LCD_write_byte(0x0c, 0);
+ LCD_write_byte(0x80, 0);
+
+ for (i=0; i<504; i++) //6*84
+ {
+ LCD_write_byte(0, 1);
+ }
+}
+/********************************************************************/
+void LCD4884::LCD_init(void)
+{
+ /* pin intializer */
+ SpiClk = LOW;
+ SpiMosi = LOW;
+ SpiCS = LOW;
+ LcdDC = LOW;
+ LcdBl = LOW;
+
+ LcdRst = LOW;
+ wait(ONE_US);
+ LcdRst = HIGH;
+
+ SpiCS = LOW; //Chip Select, Slave Transmit Enable(active low, Master Output)
+ wait(ONE_US);
+ SpiCS = HIGH;
+ wait(ONE_US);
+ LcdBl = LCD_INITIAL_BRIGHTNESS;
+
+ //data_type=0, all are command bytes
+ LCD_write_byte(0x21, 0); //Function Set:0 0 1 0 0 PD V H=0010 0001;PD=0,V=0,H=1;
+ LCD_write_byte(0xc0, 0); //Set Vop:1 Vop6 Vop5 Vop4 Vop3 Vop2 Vop1 Vop0=1100 0000
+ LCD_write_byte(0x06, 0); //Set Temperature Coefficient:0 0 0 0 0 1 Tc1 Tc0=0000 0110;Tc1=1,Tc0=0(Vlcd temperature coefficient 2)
+ LCD_write_byte(0x13, 0); //Set Bias System (BSx):0 0 0 1 0 BS2 BS1 BS0=0001 0011;BS2=0, BS1=1, BS0=1==>N=4,MUX RATE=1:48
+
+ LCD_write_byte(0x20, 0);//Function Set:0 0 1 0 0 PD V H=0010 0000;PD=0,V=0,H=0;
+ LCD_clear();
+ LCD_write_byte(0x0c, 0);//Display Control: 0 0 0 0 1 D 0 E=0000 1100 ;D=1,E=0:normal mode
+
+ SpiCS = LOW;
+}
+/********************************************************************/
+void LCD4884::LCD_write_string(unsigned char X,unsigned char Y,char *s, char mode)
+{
+ LCD_set_XY(X,Y);
+ while (*s)
+ {
+ LCD_write_char(*s, mode);
+ s++;
+ }
+}
+/********************************************************************/
+void LCD4884::LCD_pixel(unsigned char X, unsigned char Y, char mode)
+{
+ unsigned char line=0;
+ unsigned char offset=0;
+ unsigned char Pix=0;
+ if(X>83) X = X%83;
+ if(Y>47) Y = Y%47;
+ line = Y/8;
+ offset = Y%8;
+
+ switch(offset){
+ case 0: Pix = 0x01; break;
+ case 1: Pix = 0x02; break;
+ case 2: Pix = 0x04; break;
+ case 3: Pix = 0x08; break;
+ case 4: Pix = 0x10; break;
+ case 5: Pix = 0x20; break;
+ case 6: Pix = 0x40; break;
+ case 7: Pix = 0x80; break;
+ }
+
+ LCD_set_XY(X,line);
+ LCD_write_byte(Pix,1);
+ printf("%d %d %d\n",X,line,Pix);
+ wait_ms(10);
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/LCD4884.h Mon Dec 07 16:05:23 2015 +0000
@@ -0,0 +1,56 @@
+/*
+Modified by COX
+version 0.1
+
+Editor : COX
+Date : 06.03.2013
+
+*
+* Update DFRobot source to work on FRDM KL25Z
+*
+*/
+
+#ifndef LCD4884_h
+#define LCD4884_h
+
+#include "mbed.h"
+
+// SPI Interface --- (on arduino Arduino Digital Pin 2,3,4,5,6)
+#define SPI_SCK D2 //Serial Clock(Master Output)
+#define SPI_MOSI D3 //Master Output,Slave Input
+#define LCD_DC D4 //Data/Command(command active low)
+#define SPI_CS D5 //Chip Select,Slave Transmit Enable(active low,Master Output)
+#define LCD_RST D6 //One Reset button
+#define LCD_BL D7 //PWM Backlit control (Arduino DIO Pin 7)
+
+
+//display mode -- normal / highlight
+#define MENU_NORMAL 0
+#define MENU_HIGHLIGHT 1
+#define OFF 0
+#define ON 1
+#define LOW 0
+#define HIGH 1
+#define ONE_US 0.000001
+#define LCD_INITIAL_BRIGHTNESS 1
+
+namespace mbed {
+
+class LCD4884
+ {
+ public:
+ LCD4884();
+ void LCD_init(void);
+ void LCD_write_byte(unsigned char dat, unsigned char dat_type);
+ void LCD_write_char(unsigned char c, char mode);
+ void backlight(float dat);
+ void LCD_set_XY(unsigned char X, unsigned char Y);
+ void LCD_write_string(unsigned char X,unsigned char Y,char *s, char mode); // *s can be input as "<your string>"
+ void LCD_clear(void); // blank the screen
+ void LCD_pixel(unsigned char X, unsigned char Y, char mode); //X,Y = x,y coodinate, mode : MENU_NORMAL = off/ others = on
+ };
+}
+extern LCD4884 lcd;
+
+#endif
+
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/font_6x8.h Mon Dec 07 16:05:23 2015 +0000
@@ -0,0 +1,99 @@
+// 6 x 8 font
+// 1 pixel space at left and bottom
+// index = ASCII - 32
+
+unsigned char font6_8[][6]=
+{
+ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // sp
+ { 0x00, 0x00, 0x00, 0x2f, 0x00, 0x00 }, // !
+ { 0x00, 0x00, 0x07, 0x00, 0x07, 0x00 }, // "
+ { 0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14 }, // #
+ { 0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12 }, // $
+ { 0x00, 0x62, 0x64, 0x08, 0x13, 0x23 }, // %
+ { 0x00, 0x36, 0x49, 0x55, 0x22, 0x50 }, // &
+ { 0x00, 0x00, 0x05, 0x03, 0x00, 0x00 }, // '
+ { 0x00, 0x00, 0x1c, 0x22, 0x41, 0x00 }, // (
+ { 0x00, 0x00, 0x41, 0x22, 0x1c, 0x00 }, // )
+ { 0x00, 0x14, 0x08, 0x3E, 0x08, 0x14 }, // *
+ { 0x00, 0x08, 0x08, 0x3E, 0x08, 0x08 }, // +
+ { 0x00, 0x00, 0x00, 0xA0, 0x60, 0x00 }, // ,
+ { 0x00, 0x08, 0x08, 0x08, 0x08, 0x08 }, // -
+ { 0x00, 0x00, 0x60, 0x60, 0x00, 0x00 }, // .
+ { 0x00, 0x20, 0x10, 0x08, 0x04, 0x02 }, // /
+ { 0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E }, // 0
+ { 0x00, 0x00, 0x42, 0x7F, 0x40, 0x00 }, // 1
+ { 0x00, 0x42, 0x61, 0x51, 0x49, 0x46 }, // 2
+ { 0x00, 0x21, 0x41, 0x45, 0x4B, 0x31 }, // 3
+ { 0x00, 0x18, 0x14, 0x12, 0x7F, 0x10 }, // 4
+ { 0x00, 0x27, 0x45, 0x45, 0x45, 0x39 }, // 5
+ { 0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30 }, // 6
+ { 0x00, 0x01, 0x71, 0x09, 0x05, 0x03 }, // 7
+ { 0x00, 0x36, 0x49, 0x49, 0x49, 0x36 }, // 8
+ { 0x00, 0x06, 0x49, 0x49, 0x29, 0x1E }, // 9
+ { 0x00, 0x00, 0x36, 0x36, 0x00, 0x00 }, // :
+ { 0x00, 0x00, 0x56, 0x36, 0x00, 0x00 }, // ;
+ { 0x00, 0x08, 0x14, 0x22, 0x41, 0x00 }, // <
+ { 0x00, 0x14, 0x14, 0x14, 0x14, 0x14 }, // =
+ { 0x00, 0x00, 0x41, 0x22, 0x14, 0x08 }, // >
+ { 0x00, 0x02, 0x01, 0x51, 0x09, 0x06 }, // ?
+ { 0x00, 0x32, 0x49, 0x59, 0x51, 0x3E }, // @
+ { 0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C }, // A
+ { 0x00, 0x7F, 0x49, 0x49, 0x49, 0x36 }, // B
+ { 0x00, 0x3E, 0x41, 0x41, 0x41, 0x22 }, // C
+ { 0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C }, // D
+ { 0x00, 0x7F, 0x49, 0x49, 0x49, 0x41 }, // E
+ { 0x00, 0x7F, 0x09, 0x09, 0x09, 0x01 }, // F
+ { 0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A }, // G
+ { 0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F }, // H
+ { 0x00, 0x00, 0x41, 0x7F, 0x41, 0x00 }, // I
+ { 0x00, 0x20, 0x40, 0x41, 0x3F, 0x01 }, // J
+ { 0x00, 0x7F, 0x08, 0x14, 0x22, 0x41 }, // K
+ { 0x00, 0x7F, 0x40, 0x40, 0x40, 0x40 }, // L
+ { 0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F }, // M
+ { 0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F }, // N
+ { 0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E }, // O
+ { 0x00, 0x7F, 0x09, 0x09, 0x09, 0x06 }, // P
+ { 0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E }, // Q
+ { 0x00, 0x7F, 0x09, 0x19, 0x29, 0x46 }, // R
+ { 0x00, 0x46, 0x49, 0x49, 0x49, 0x31 }, // S
+ { 0x00, 0x01, 0x01, 0x7F, 0x01, 0x01 }, // T
+ { 0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F }, // U
+ { 0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F }, // V
+ { 0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F }, // W
+ { 0x00, 0x63, 0x14, 0x08, 0x14, 0x63 }, // X
+ { 0x00, 0x07, 0x08, 0x70, 0x08, 0x07 }, // Y
+ { 0x00, 0x61, 0x51, 0x49, 0x45, 0x43 }, // Z
+ { 0x00, 0x00, 0x7F, 0x41, 0x41, 0x00 }, // [
+ { 0x00, 0x55, 0x2A, 0x55, 0x2A, 0x55 }, // 55
+ { 0x00, 0x00, 0x41, 0x41, 0x7F, 0x00 }, // ]
+ { 0x00, 0x04, 0x02, 0x01, 0x02, 0x04 }, // ^
+ { 0x00, 0x40, 0x40, 0x40, 0x40, 0x40 }, // _
+ { 0x00, 0x00, 0x01, 0x02, 0x04, 0x00 }, // '
+ { 0x00, 0x20, 0x54, 0x54, 0x54, 0x78 }, // a
+ { 0x00, 0x7F, 0x48, 0x44, 0x44, 0x38 }, // b
+ { 0x00, 0x38, 0x44, 0x44, 0x44, 0x20 }, // c
+ { 0x00, 0x38, 0x44, 0x44, 0x48, 0x7F }, // d
+ { 0x00, 0x38, 0x54, 0x54, 0x54, 0x18 }, // e
+ { 0x00, 0x08, 0x7E, 0x09, 0x01, 0x02 }, // f
+ { 0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C }, // g
+ { 0x00, 0x7F, 0x08, 0x04, 0x04, 0x78 }, // h
+ { 0x00, 0x00, 0x44, 0x7D, 0x40, 0x00 }, // i
+ { 0x00, 0x40, 0x80, 0x84, 0x7D, 0x00 }, // j
+ { 0x00, 0x7F, 0x10, 0x28, 0x44, 0x00 }, // k
+ { 0x00, 0x00, 0x41, 0x7F, 0x40, 0x00 }, // l
+ { 0x00, 0x7C, 0x04, 0x18, 0x04, 0x78 }, // m
+ { 0x00, 0x7C, 0x08, 0x04, 0x04, 0x78 }, // n
+ { 0x00, 0x38, 0x44, 0x44, 0x44, 0x38 }, // o
+ { 0x00, 0xFC, 0x24, 0x24, 0x24, 0x18 }, // p
+ { 0x00, 0x18, 0x24, 0x24, 0x18, 0xFC }, // q
+ { 0x00, 0x7C, 0x08, 0x04, 0x04, 0x08 }, // r
+ { 0x00, 0x48, 0x54, 0x54, 0x54, 0x20 }, // s
+ { 0x00, 0x04, 0x3F, 0x44, 0x40, 0x20 }, // t
+ { 0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C }, // u
+ { 0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C }, // v
+ { 0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C }, // w
+ { 0x00, 0x44, 0x28, 0x10, 0x28, 0x44 }, // x
+ { 0x00, 0x1C, 0xA0, 0xA0, 0xA0, 0x7C }, // y
+ { 0x00, 0x44, 0x64, 0x54, 0x4C, 0x44 }, // z
+ { 0x00,0x00, 0x06, 0x09, 0x09, 0x06 } // horiz lines
+};
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/font_big.h Mon Dec 07 16:05:23 2015 +0000
@@ -0,0 +1,138 @@
+// big font
+
+
+//******* VERY LARGE FONTS **********
+//used here for displaying temperature
+unsigned char big_number[13][3][16] = {
+
+0,128,192,224,224,96,224,224, //'0'
+192,128,0,0,0,0,0,0
+,
+112,255,255,1,0,0,0,0,
+255,255,254,0,0,0,0,0
+,
+0,15,31,60,56,48,56,56,
+31,15,3,0,0,0,0,0
+,
+
+0,0,0,0,128,224,224,0, //'1'
+0,0,0,0,0,0,0,0
+,
+0,0,3,3,3,255,255,0,
+0,0,0,0,0,0,0,0
+,
+0,0,56,56,56,63,63,56,
+56,56,0,0,0,0,0,0
+,
+
+0,192,192,224,96,96,224,224, //'2'
+192,128,0,0,0,0,0,0
+,
+0,1,0,0,128,192,224,249,
+63,31,0,0,0,0,0,0
+,
+0,60,62,63,63,59,57,56,
+56,56,56,0,0,0,0,0
+,
+
+0,192,224,224,96,96,224,224, //'3'
+192,192,0,0,0,0,0,0
+,
+0,1,0,0,48,48,56,125,
+239,207,0,0,0,0,0,0
+,
+0,28,56,56,48,48,56,60,
+31,15,1,0,0,0,0,0
+,
+
+0,0,0,0,0,128,192,224, //'4'
+224,0,0,0,0,0,0,0
+,
+224,240,248,222,207,199,193,255,
+255,192,192,0,0,0,0,0
+,
+0,0,0,0,0,0,0,63,
+63,0,0,0,0,0,0,0
+,
+
+0,224,224,224,224,224,224,224, //'5'
+224,224,224,0,0,0,0,0
+,
+0,63,63,63,56,56,48,112,
+240,224,0,0,0,0,0,0
+,
+0,28,56,56,48,48,56,60,
+31,15,1,0,0,0,0,0
+,
+
+0,0,128,192,192,224,96,96, //'6'
+224,224,0,0,0,0,0,0
+,
+224,254,255,55,57,24,24,56,
+240,240,192,0,0,0,0,0
+,
+0,15,31,28,56,48,48,56,
+31,15,7,0,0,0,0,0
+,
+
+0,224,224,224,224,224,224,224, //'7'
+224,224,224,0,0,0,0,0
+,
+0,0,0,0,128,224,248,126,
+31,7,1,0,0,0,0,0
+,
+0,0,56,62,31,7,1,0,
+0,0,0,0,0,0,0,0
+,
+
+0,128,192,224,224,96,96,224, //'8'
+192,192,0,0,0,0,0,0
+,
+0,207,255,127,56,48,112,112,
+255,239,199,0,0,0,0,0
+,
+3,15,31,60,56,48,48,56,
+31,31,15,0,0,0,0,0
+,
+
+0,128,192,224,224,96,224,224, //'9'
+192,128,0,0,0,0,0,0
+,
+12,63,127,241,224,192,192,225,
+255,255,254,0,0,0,0,0
+,
+0,0,56,48,48,56,56,30,
+15,7,0,0,0,0,0,0
+,
+
+
+0,0,0,0,0,0,0,0, //'.'
+0,0,0,0,0,0,0,0
+,
+0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0
+,
+60,60,60,0,0,0,0,0,
+0,0,0,0,0,0,0,0
+,
+
+0,0,0,0,0,0,0,0, //'+'
+0,0,0,0,0,0,0,0
+,
+0,0,64,64,64,64,64,254,
+254,64,64,64,64,64,0,0
+,
+0,0,0,0,0,0,0,15,
+15,0,0,0,0,0,0,0
+,
+
+0,0,0,0,0,0,0,0, //'-'
+0,0,0,0,0,0,0,0
+,
+0,64,64,64,64,64,64,0,
+0,0,0,0,0,0,0,0
+,
+0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0
+};
+
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Mon Dec 07 16:05:23 2015 +0000
@@ -0,0 +1,39 @@
+#include "mbed.h"
+#include "LCD4884.h"
+#include <string.h>
+
+DigitalOut myled(LED1);
+DigitalIn b(USER_BUTTON);
+DigitalOut backlight(D7);
+AnalogIn joy(A0); //up = 1.00, down = 0.47, right = 0.73, left = 0.00, middle = 0.79
+
+int main() {
+ char I[2] = {MENU_NORMAL,'1'};
+ int i = 0;
+ float pos = 0.00;
+ backlight = 1;
+ unsigned char x=0,y=0;
+ LCD4884 test;
+
+ test.LCD_init();
+ //test.LCD_clear();
+ //test.LCD_write_byte(0x01, 0);
+ //test.LCD_write_byte(0x01, 1);
+ //test.LCD_write_string('0','0',"1324",'0');
+
+
+ while(1) {
+ test.LCD_pixel(x,y,1);
+ pos = joy.read();
+ if(pos>0.98){
+ if(y==0) y=47;
+ else y-=1; }
+ else if(0.46<pos&&pos<0.48) y+=1;
+ else if(0.72<pos&&pos<0.74) x+=1;
+ else if(0.02>pos){
+ if(x==0) x=83;
+ else x-=1; }
+ wait_ms(150);
+ test.LCD_clear();
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon Dec 07 16:05:23 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/34e6b704fe68 \ No newline at end of file
