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.
main.cpp
00001 #include "mbed.h" 00002 #include "bitmap.h" 00003 00004 #define NOP 0x00 00005 #define Function_Set 0x20 00006 #define Display_Control 0x08 00007 #define Set_Y_Address 0x40 00008 #define Set_X_Address 0x80 00009 #define Set_V0 0x80 00010 #define Set_Test_Mode 0x30 00011 00012 DigitalOut SCK_pin(D13); // SPI clock 00013 DigitalOut SDI_pin(D11); // SPI MOSI 00014 DigitalOut DC_pin(D10); // Data/command selector 00015 DigitalOut RST_pin(D9); // HW Reset 00016 DigitalOut CS_pin(D8); // SPI chip select 00017 00018 00019 void LCDShiftWrite(unsigned char dat) 00020 { 00021 unsigned char i; 00022 unsigned char Series,Temp; 00023 SCK_pin = false; 00024 Series = dat; 00025 for(i=0; i<8; i++) { 00026 SCK_pin = false; 00027 Temp=Series & 0x80; 00028 if(Temp) { 00029 SDI_pin = true; 00030 } else { 00031 SDI_pin = false; 00032 } 00033 SCK_pin = true; 00034 Series = Series << 1; 00035 } 00036 } 00037 00038 00039 void send_cmd(unsigned char cmd, unsigned char dat) 00040 { 00041 DC_pin = false; //digitalWrite(RSX,LOW); 00042 CS_pin = false; //digitalWrite(CSX,LOW); 00043 LCDShiftWrite(cmd|dat); 00044 CS_pin = true; //digitalWrite(CSX,HIGH); 00045 DC_pin = true; //digitalWrite(RSX,HIGH); 00046 } 00047 00048 void send_dat(unsigned char dat) 00049 { 00050 DC_pin = true; //digitalWrite(RSX,HIGH); 00051 CS_pin = false; //digitalWrite(CSX,LOW); 00052 LCDShiftWrite(dat); 00053 CS_pin = true; //digitalWrite(CSX,HIGH); 00054 } 00055 00056 00057 void LCDInit() 00058 { 00059 RST_pin = false; //digitalWrite(RESX,LOW); 00060 wait_ms(10); 00061 RST_pin = true; //digitalWrite(RESX,HIGH); 00062 wait_ms(100); 00063 send_cmd(Function_Set,0x01); 00064 send_cmd(Set_V0,0x20); 00065 send_cmd(Set_Test_Mode,0x02); 00066 send_cmd(Function_Set,0x00); 00067 send_cmd(Display_Control,0x04); 00068 } 00069 00070 void LCD_set_XY(unsigned char x,unsigned char y) 00071 { 00072 send_cmd(Set_X_Address,x); 00073 send_cmd(Set_Y_Address,y); 00074 } 00075 00076 void cls(void) 00077 { 00078 int i; 00079 send_cmd(Set_X_Address,0); 00080 send_cmd(Set_Y_Address,0); 00081 for(i=0; i<960; i++) 00082 send_dat(0x00); 00083 send_cmd(Set_X_Address,0); 00084 send_cmd(Set_Y_Address,0); 00085 } 00086 00087 void putch(unsigned char x, unsigned char y, unsigned int ch) 00088 { 00089 unsigned char i; 00090 send_cmd(Set_X_Address,x); 00091 send_cmd(Set_Y_Address,y); 00092 for(i=0; i<5; i++) 00093 send_dat(FONT[(ch-0x20)*5+i]); 00094 } 00095 00096 void putstr(unsigned char x, unsigned char y, char *str) 00097 { 00098 while(*str!=0) { 00099 putch(x,y,*str++); 00100 x=x+6; 00101 } 00102 } 00103 00104 void SHOW_BMP() 00105 { 00106 unsigned int i,j,n=0; 00107 for(i=0; i<8; i++) { 00108 for(j=0; j<96; j++) { 00109 send_cmd(Set_Y_Address,7-i); 00110 send_cmd(Set_X_Address,j); 00111 send_dat(BMP[n++]); 00112 } 00113 } 00114 } 00115 00116 void SHOW_ICO() 00117 { 00118 unsigned char i; 00119 for(i=0; i<96; i++) { 00120 send_cmd(Set_Y_Address,8); 00121 send_cmd(Set_X_Address,i); 00122 send_dat(0xFF); 00123 } 00124 } 00125 00126 void SHOW_LINE() 00127 { 00128 unsigned int i,j; 00129 const unsigned char line[8] = { 00130 0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80 00131 }; 00132 for(i=0; i<8; i++) { 00133 send_cmd(Set_Y_Address,7-i); 00134 for(j=0; j<8; j++) { 00135 send_cmd(Set_X_Address,j+8*i); 00136 send_dat(line[j]); 00137 } 00138 } 00139 } 00140 00141 int main() 00142 { 00143 00144 LCDInit(); 00145 00146 00147 while(1) { 00148 SHOW_ICO(); 00149 putstr(30,5,"ST7585"); 00150 putstr(15,3,"96*64 GLCD"); 00151 putstr(10,1,"ARM Mbed demo"); 00152 wait_ms(5000); 00153 cls(); 00154 SHOW_LINE(); 00155 wait_ms(5000); 00156 cls(); 00157 00158 SHOW_BMP(); 00159 wait_ms(5000); 00160 cls(); 00161 } 00162 } 00163
Generated on Fri Sep 15 2023 17:31:42 by
1.7.2