Liu Zhixian / Mbed 2 deprecated Nucleo_spi_5110

Dependencies:   mbed

Revision:
0:ded1a1350d0d
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Oct 04 04:00:38 2014 +0000
@@ -0,0 +1,272 @@
+#include "mbed.h"
+#include "LCD.h"
+
+typedef unsigned char byte;
+
+DigitalOut LCD_DC(D10);
+DigitalOut LCD_CS(D9);
+DigitalOut LCD_RES(D8);
+
+SPI Lcd_5110(SPI_MOSI, SPI_MISO, SPI_SCK); 
+
+const byte CharTable[][14]=
+{
+    {0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x30,0x33,0x00,0x00,0x00},/*"!",0*/
+    {0x00,0x10,0x0C,0x16,0x0C,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*""",1*/
+    {0x40,0x40,0xF8,0x40,0xF8,0x40,0x00,0x04,0x3E,0x05,0x3F,0x05,0x04,0x00},/*"#",2*/
+    {0x00,0x70,0x88,0xFC,0x08,0x30,0x00,0x00,0x18,0x20,0xFF,0x21,0x1E,0x00},/*"$",3*/
+    {0xF0,0x08,0xF0,0x80,0x70,0x08,0x00,0x00,0x21,0x1C,0x03,0x1E,0x21,0x1E},/*"%",4*/
+    {0x00,0xF0,0x88,0x70,0x00,0x00,0x00,0x1F,0x20,0x27,0x28,0x1F,0x21,0x10},/*"&",5*/
+    {0x10,0x16,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"'",6*/
+    {0x00,0x00,0x00,0xF0,0x0C,0x02,0x00,0x00,0x00,0x00,0x0F,0x30,0x40,0x00},/*"(",7*/
+    {0x00,0x06,0x18,0xE0,0x00,0x00,0x00,0x00,0x60,0x18,0x07,0x00,0x00,0x00},/*")",8*/
+    {0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x02,0x02,0x01,0x0F,0x01,0x02,0x02},/*"*",9*/
+    {0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x01,0x01,0x01,0x1F,0x01,0x01,0x01},/*"+",10*/
+    {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xB0,0x70,0x00,0x00,0x00,0x00},/*",",11*/
+    {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x00},/*"-",12*/
+    {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00},/*".",13*/
+    {0x00,0x00,0x00,0x00,0xC0,0x38,0x0C,0x00,0x60,0x38,0x07,0x01,0x00,0x00},/*"/",14*/
+    {0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00},/*"0",15*/
+    {0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00},/*"1",16*/
+    {0x00,0x70,0x08,0x08,0x08,0xF0,0x00,0x00,0x30,0x2C,0x22,0x21,0x30,0x00},/*"2",17*/
+    {0x00,0x30,0x08,0x88,0x88,0x70,0x00,0x00,0x18,0x20,0x20,0x31,0x1E,0x00},/*"3",18*/
+    {0x00,0x80,0x40,0x20,0xF8,0x00,0x00,0x06,0x05,0x04,0x24,0x3F,0x24,0x04},/*"4",19*/
+    {0x00,0xF8,0x08,0x88,0x88,0x08,0x00,0x00,0x19,0x21,0x20,0x31,0x1F,0x00},/*"5",20*/
+    {0xE0,0x10,0x88,0x88,0x88,0x18,0x00,0x0F,0x11,0x20,0x20,0x31,0x1F,0x00},/*"6",21*/
+    {0x00,0x38,0x08,0x08,0xE8,0x18,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00},/*"7",22*/
+    {0x70,0x98,0x88,0x08,0x98,0x70,0x00,0x1E,0x21,0x21,0x21,0x31,0x1E,0x00},/*"8",23*/
+    {0xF0,0x08,0x08,0x08,0x18,0xE0,0x00,0x31,0x22,0x22,0x32,0x19,0x07,0x00},/*"9",24*/
+    {0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00},/*":",25*/
+    {0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x80,0x60,0x00,0x00,0x00},/*";",26*/
+    {0x00,0x00,0x80,0x60,0x10,0x08,0x00,0x00,0x01,0x02,0x0C,0x10,0x20,0x00},/*"<",27*/
+    {0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x00},/*"=",28*/
+    {0x00,0x08,0x30,0x40,0x80,0x00,0x00,0x00,0x20,0x18,0x04,0x02,0x01,0x00},/*">",29*/
+    {0x70,0x08,0x08,0x08,0x18,0xF0,0x00,0x00,0x00,0x30,0x37,0x01,0x00,0x00},/*"?",30*/
+    {0xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x07,0x18,0x27,0x24,0x23,0x14,0x0B},/*"@",31*/
+    {0x00,0x00,0xE0,0x18,0xE0,0x00,0x00,0x20,0x3C,0x23,0x02,0x23,0x3C,0x20},/*"A",32*/
+    {0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x20,0x31,0x1E,0x00},/*"B",33*/
+    {0xE0,0x30,0x08,0x08,0x08,0x38,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x00},/*"C",34*/
+    {0x08,0xF8,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x10,0x0F,0x00},/*"D",35*/
+    {0x08,0xF8,0x88,0x88,0xE8,0x18,0x00,0x20,0x3F,0x20,0x20,0x23,0x30,0x00},/*"E",36*/
+    {0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x20,0x3F,0x20,0x00,0x03,0x00,0x00},/*"F",37*/
+    {0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x22,0x1E,0x02},/*"G",38*/
+    {0x08,0xF8,0x08,0x00,0x08,0xF8,0x08,0x20,0x3F,0x21,0x01,0x21,0x3F,0x20},/*"H",39*/
+    {0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00},/*"I",40*/
+    {0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0xC0,0x80,0x80,0x7F,0x00,0x00,0x00},/*"J",41*/
+    {0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x20,0x3F,0x20,0x01,0x26,0x38,0x20},/*"K",42*/
+    {0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x30,0x00},/*"L",43*/
+    {0x08,0xF8,0xF8,0x80,0xF8,0xF8,0x08,0x20,0x3F,0x00,0x3F,0x00,0x3F,0x20},/*"M",44*/
+    {0x08,0xF8,0x38,0xC0,0x08,0xF8,0x08,0x20,0x3F,0x20,0x03,0x1C,0x3F,0x00},/*"N",45*/
+    {0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00},/*"O",46*/
+    {0x08,0xF8,0x08,0x08,0x08,0xF0,0x00,0x20,0x3F,0x21,0x01,0x01,0x00,0x00},/*"P",47*/
+    {0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x0F,0x18,0x24,0x24,0x78,0x4F,0x00},/*"Q",48*/
+    {0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x01,0x06,0x38,0x20},/*"R",49*/
+    {0x00,0x70,0x88,0x08,0x08,0x18,0x00,0x00,0x30,0x20,0x21,0x23,0x1E,0x00},/*"S",50*/
+    {0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x20,0x3F,0x20,0x00,0x00},/*"T",51*/
+    {0x08,0xF8,0x08,0x00,0x08,0xF8,0x08,0x00,0x1F,0x20,0x20,0x20,0x1F,0x00},/*"U",52*/
+    {0x08,0x78,0x88,0x00,0x88,0x78,0x08,0x00,0x00,0x0F,0x38,0x0F,0x00,0x00},/*"V",53*/
+    {0x08,0xF8,0xC4,0xF8,0x00,0xF8,0x08,0x00,0x07,0x3F,0x01,0x3E,0x07,0x00},/*"W",54*/
+    {0x08,0x38,0xE8,0x80,0xE8,0x18,0x08,0x20,0x30,0x2C,0x03,0x2E,0x38,0x20},/*"X",55*/
+    {0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,0x00,0x20,0x3F,0x20,0x00,0x00},/*"Y",56*/
+    {0x10,0x08,0x08,0xC8,0x38,0x08,0x00,0x30,0x2C,0x23,0x20,0x20,0x10,0x00},/*"Z",57*/
+    {0x00,0x00,0x00,0xFE,0x02,0x02,0x00,0x00,0x00,0x00,0x7F,0x40,0x40,0x00},/*"[",58*/
+    {0x00,0x1C,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x1C,0x60,0x00},/*"\",59*/
+    {0x00,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,0x40,0x40,0x7F,0x00,0x00,0x00},/*"]",60*/
+    {0x00,0x00,0x04,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"^",61*/
+    {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80},/*"_",62*/
+    {0x00,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"`",63*/
+    {0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x1D,0x24,0x22,0x22,0x3F,0x20},/*"a",64*/
+    {0x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,0x3F,0x21,0x20,0x20,0x1F,0x00},/*"b",65*/
+    {0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x1F,0x31,0x20,0x20,0x11,0x00},/*"c",66*/
+    {0x00,0x00,0x80,0x80,0x88,0xF8,0x00,0x00,0x1F,0x21,0x20,0x20,0x3F,0x20},/*"d",67*/
+    {0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x13,0x00},/*"e",68*/
+    {0x80,0x80,0xF0,0x88,0x88,0x18,0x00,0x00,0x20,0x3F,0x20,0x20,0x00,0x00},/*"f",69*/
+    {0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x6B,0x94,0x94,0x93,0x60,0x00},/*"g",70*/
+    {0x08,0xF8,0x00,0x80,0x80,0x80,0x00,0x20,0x3F,0x21,0x00,0x20,0x3F,0x20},/*"h",71*/
+    {0x00,0x80,0x80,0x98,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00},/*"i",72*/
+    {0x00,0x00,0x80,0x80,0x98,0x00,0x00,0x00,0xC0,0x80,0x80,0x7F,0x00,0x00},/*"j",73*/
+    {0x08,0xF8,0x00,0x80,0x80,0x80,0x00,0x20,0x3F,0x24,0x06,0x39,0x20,0x00},/*"k",74*/
+    {0x00,0x08,0x08,0xF8,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00},/*"l",75*/
+    {0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x00,0x3F,0x00,0x3F,0x20},/*"m",76*/
+    {0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x20,0x3F,0x21,0x00,0x20,0x3F,0x20},/*"n",77*/
+    {0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x31,0x20,0x21,0x1F,0x00},/*"o",78*/
+    {0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x80,0xFF,0xA1,0x20,0x30,0x1F,0x00},/*"p",79*/
+    {0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x1F,0x21,0x20,0xA0,0xFF,0x80},/*"q",80*/
+    {0x80,0x80,0x80,0x00,0x80,0x80,0x00,0x20,0x20,0x3F,0x21,0x20,0x01,0x00},/*"r",81*/
+    {0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x33,0x24,0x24,0x24,0x19,0x00},/*"s",82*/
+    {0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x00},/*"t",83*/
+    {0x80,0x80,0x00,0x00,0x80,0x80,0x00,0x00,0x3F,0x20,0x20,0x20,0x3F,0x20},/*"u",84*/
+    {0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x03,0x1C,0x30,0x1C,0x03,0x00},/*"v",85*/
+    {0x80,0x80,0xC0,0x80,0x00,0x80,0x80,0x00,0x0F,0x3F,0x07,0x38,0x0F,0x00},/*"w",86*/
+    {0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x20,0x31,0x2E,0x0E,0x31,0x20,0x00},/*"x",87*/
+    {0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x80,0x83,0x4E,0x30,0x0E,0x01,0x00},/*"y",88*/
+    {0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x21,0x38,0x24,0x23,0x30,0x00},/*"z",89*/
+    {0x00,0x00,0x00,0x80,0x7E,0x02,0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x00},/*"{",90*/
+    {0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00},/*"|",91*/
+    {0x00,0x02,0x7E,0x80,0x00,0x00,0x00,0x00,0x40,0x3F,0x00,0x00,0x00,0x00},/*"}",92*/
+    {0x00,0x06,0x01,0x01,0x02,0x04,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"~",93*/
+};
+
+byte StringTable[12];
+byte const String_1[]={"bbs.eeworld"};
+byte const String_2[]={"ID:zhimagod"};
+
+const byte S1_Long = sizeof(String_1)/sizeof(String_1[0])-1;
+const byte S2_Long = sizeof(String_2)/sizeof(String_2[0])-1;
+
+
+//LCD Initials Values Array
+const byte LCD_Init_Array[8]=
+{
+    Function|PowerUp|EntryVer|InstrucExtern,
+    Vop|55,
+    Temper|0,
+    Bias|3,
+    Function|PowerUp|EntryHor|InstrucBasic,
+    DispCtrl|Normal,
+    AddressX(0),
+    AddressY(0),
+};
+//LCD write function
+//just add the cs signal for SPI operation
+void LCD_Write(unsigned char data)
+{
+    LCD_CS=0;
+    Lcd_5110.write(data);
+    LCD_CS=1;
+    return;
+}
+//LCD Initials Function
+//Initials the LCD use the Initials values
+void LCD_Init(void)
+{
+    unsigned int i;
+    Lcd_5110.frequency(10000000);
+    LCD_RES=0;
+    wait_us(10);
+    LCD_DC=0;               //command
+    LCD_RES=1;
+    for(i=0;i<8;i++)
+    {
+        LCD_Write(LCD_Init_Array[i]);
+    }
+    LCD_DC=1;               //Data
+    for(i=0;i<504;i++)
+    {
+        LCD_Write(0x00);//clear DDR
+    }
+}
+
+//Locate the pointer to x,y on the screen
+void LCD_XY(unsigned char x,unsigned char y)
+{
+    LCD_DC=0;
+    LCD_Write(Hor_Basic);   //basic activ
+    LCD_Write(AddressX(x)); //set x
+    LCD_Write(AddressY(y)); //set y
+    LCD_DC=1;
+}
+
+//Display one char at position x,y with 16*7 or 16*14 pix
+//x     :x address
+//y     :y address
+//Invert:Invert Display this char
+//Index :the Char Index in the CharTable
+void LCD_Disp_Char(byte x,byte y,byte Invert,byte Index)
+{
+    byte i,mask;
+    const byte *p;
+    //adjust the Index's vvalue
+    if(Index<33)
+        Index=33;
+    else if(Index>126)
+        Index=125;
+        
+    p=&CharTable[Index-33][0];
+    LCD_DC=1;
+    //adjust if Invert
+    if(Invert!=0)
+        mask=0xFF;
+    else
+        mask=0x00;
+    //upper half of a letter
+    LCD_XY(x,y);
+    for(i=0;i<7;i++)
+    {
+        LCD_Write((*p)^mask);
+        p++;
+    }
+    y++;
+    //down half of a letter
+    LCD_XY(x,y);
+    for(i=0;i<7;i++)
+    {
+        LCD_Write((*p)^mask);
+        p++;
+    }
+}
+//display string 
+//ROM source
+void LCD_Disp_String_Rom(byte Line,byte row,byte Number,const byte *String)
+{
+    byte x,y;
+    byte i;
+    if(Line>2){
+        return;
+    }
+    y=Line*2;
+    x=row;
+    for(i=0;i<Number;i++)
+    {
+        LCD_Disp_Char(x,y,0,*String);
+        x+=7;
+        if(x>84){
+            return;
+        }
+        String++;
+    }
+}
+//display string 
+//RAM source
+void LCD_Disp_String_Ram(byte Line,byte row,byte Number,byte *String)
+{
+    byte x,y;
+    byte i;
+    if(Line>2){
+        return;
+    }
+    y=Line*2;
+    x=row;
+    for(i=0;i<Number;i++)
+    {
+        LCD_Disp_Char(x,y,1,*String);
+        x+=7;
+        if(x>84){
+            return;
+        }
+        String++;
+    }
+} 
+ 
+int main() {
+    int i = 0;
+    LCD_CS=1;
+    LCD_RES=1;
+    LCD_Init();
+    for(i=0;i<12;i++){
+        StringTable[i]=(i+48);
+    }
+    while(1)
+    {
+        LCD_Init();
+        wait(0.2);
+        LCD_Disp_String_Ram(0,0,12,&StringTable[0]);
+        wait(0.2);
+        LCD_Disp_String_Rom(1,0,S1_Long,&String_1[0]);
+        wait(0.2);
+        LCD_Disp_String_Rom(2,0,S2_Long,&String_2[0]);
+        wait(1);
+        
+    }
+}
+ 
\ No newline at end of file