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 // AD-12864-SPI test program 00002 // About AD-12864-SPI, see http://www.aitendo.co.jp/product/1622. 00003 00004 // Pin allocation 00005 // 1 p21 #CS1 with 10k ohm pull-up 00006 // 2 p22 #RESET with 10k ohm pull-up 00007 // 3 p23 A0 ... 0:command 1:data 00008 // 4 p13 SCK 00009 // 5 p11 MOSI 00010 // 6 Vdd 00011 // 7 Vss 00012 // 8 NC LED_A 00013 00014 #include "mbed.h" 00015 00016 DigitalOut cs(p21); 00017 DigitalOut rst(p22); 00018 DigitalOut a0(p23); 00019 SPI spi(p11, p12, p13); // mosi, miso, sclk 00020 00021 void regwrite(unsigned char c){ 00022 cs = a0 = 0; 00023 spi.write(c); 00024 cs = 1; 00025 } 00026 00027 void datawrite(unsigned char c){ 00028 cs = 0; 00029 a0 = 1; 00030 spi.write(c); 00031 cs = 1; 00032 } 00033 00034 // set position (x, 8*y) 00035 void locate(int x, int y){ 00036 regwrite(0xb0 | (y & 0x0f)); // Page Address Set (see 2.4.3) 00037 regwrite(0x10 | (x >> 4 & 0x0f)); // Column Address Set (see 2.4.4) 00038 regwrite(x & 0x0f); 00039 } 00040 00041 void cls(void){ 00042 int x, y; 00043 for(y = 0; y < 8; y++){ 00044 locate(0, y); 00045 for(x = 0; x < 128; x++) datawrite(0x00); 00046 } 00047 } 00048 00049 void plot(int x, int y){ 00050 locate(x, y >> 3); 00051 datawrite(1 << (y & 7)); 00052 } 00053 00054 void init(){ 00055 spi.format(8,0); // nazo 00056 spi.frequency(20000000); // modify later 00057 00058 // reset 00059 wait_ms(200); 00060 rst = 0; 00061 wait_ms(200); 00062 rst = 1; 00063 00064 // initialize sequence 00065 regwrite(0xaf); // display on (see 2.4.1) 00066 regwrite(0x2f); // power control set (see 2.4.16) 00067 regwrite(0x81); // set electronic volume mode (see 2.4.18) 00068 // regwrite(0x1f); // electronic volume data 00-3f 00069 regwrite(0x00); // electronic volume data 00-3f 00070 regwrite(0x27); // V5 Volatge Regulator Internal Resister Ratio Set (see 2.4.17) 00071 regwrite(0xa2); // LCD Bias Set ... 1/9 bias (see 2.4.11) 00072 regwrite(0xc8); // Common Output Mode Select ... Reverse (see 2.4.15) 00073 regwrite(0xa0); // ADC Select ... Normal (see 2.4.8) 00074 regwrite(0xa4); // Display All Points ON/OFF ... normal (see 2.4.10) 00075 regwrite(0xa6); // Display Normal/Reverse ... normal (see 2.4.9) 00076 regwrite(0xac); // Static Indicator ... off (see 2.4.19) 00077 regwrite(0x00); // off 00078 regwrite(0x40); // Display Strat Line Set ... 0 (see 2.4.2) 00079 regwrite(0xe0); // Write Mode Set 00080 } 00081 00082 DigitalOut myled(LED1); 00083 00084 int main() { 00085 int i; 00086 00087 init(); 00088 00089 cls(); 00090 locate(0, 0); 00091 for(i = 0; i < 256; i++) datawrite(i); 00092 00093 for(i = 0; i < 64; i++){ 00094 plot(64 + i, 0); 00095 plot(64 + i, 63); 00096 } 00097 00098 for(i = 0; i < 8; i++){ 00099 locate(64, i); 00100 datawrite(0xff); 00101 locate(127,i); 00102 datawrite(0xff); 00103 } 00104 00105 for(i = 0; i < 64; i++) plot(i, i); 00106 00107 while(1) { 00108 myled = 1; 00109 wait_ms(200); 00110 myled = 0; 00111 wait_ms(200); 00112 } 00113 }
Generated on Sat Jul 16 2022 08:13:06 by
1.7.2