最近偶得一顯示屏 是ST7567 網上搜到引腳資料 和源碼 但是奈何小弟才疏學淺 看不懂 能否有高人指點 用arduino驅動 源碼貼上
- #include "msp430g2452.h"
- #define LCD P1OUT
- #define CSB 0x20
- #define RSTB 0x08
- #define A0 0x04
- #define SCLK 0x02
- #define SDA 0x01
- unsigned const char tab[]={
- 0xFF,0x01,0x01,0x01,0x41,0xD1,0x01,0x01,0x01,0x80,0x40,0x40,0x80,0x00,0x00,0xC0,
- 0x40,0xC0,0x40,0x80,0x00,0x40,0xC0,0x00,0x40,0xC0,0x00,0x00,0xC0,0x40,0x40,0x40,
- 0x00,0x10,0xF0,0x40,0x40,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0xFF,
- 0x03,0x00,0x00,0x80,0x84,0x87,0x84,0x80,0x00,0x82,0x85,0x05,0x07,0x84,0x80,0x07,
- 0x00,0x87,0x00,0x07,0x00,0x00,0x03,0x84,0x84,0x07,0x04,0x00,0x04,0x85,0x85,0x06,
- 0x00,0x00,0x87,0x84,0x84,0x03,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x80,
- 0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x80,
- 0x80,0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,
- 0x00,0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
- 0x00,0x00,0x00,0x01,0x20,0x3F,0x20,0x01,0x00,0x20,0x3F,0x0F,0x07,0x3F,0x20,0x00,
- 0x21,0x3F,0x20,0x00,0x00,0x00,0x31,0x28,0x24,0x23,0x00,0x00,0x1B,0x24,0x24,0x1B,
- 0x00,0x1F,0x24,0x24,0x24,0x18,0x00,0x0C,0x0A,0x09,0x3F,0x08,0x00,0x00,0x21,0x3F,
- 0x20,0x00,0x00,0x00,0x00,0x3C,0x03,0x00,0x00,0x20,0x3F,0x22,0x22,0x1D,0x00,0x20,
- 0x3F,0x24,0x0E,0x01,0x00,0x03,0x3C,0x03,0x0C,0x3C,0x03,0x1F,0x20,0x28,0x18,0x08,
- 0x00,0x00,0x23,0x3C,0x23,0x00,0x00,0x20,0x3E,0x09,0x3E,0x20,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x20,0x3F,0x22,0x22,0x1D,0x00,0x02,0x02,0x02,0x02,0x02,0x00,0x00,
- 0x31,0x28,0x24,0x23,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x88,0x44,0x24,0x18,0x00,0x00,0xF8,0x04,0x04,0xF8,0x00,0x00,
- 0x08,0xFC,0x00,0x00,0x00,0x00,0x9C,0x14,0x14,0xE4,0x00,0x00,0xC0,0x30,0x0E,0x01,
- 0x00,0x00,0x08,0xFC,0x00,0x00,0x00,0x00,0xF8,0x04,0x04,0xF8,0x00,0x00,0xC0,0x30,
- 0x0E,0x01,0x00,0x00,0x08,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x40,0xE0,
- 0x00,0x00,0x00,0x00,0x00,0xC0,0x20,0x20,0x20,0x20,0xC0,0x00,0x00,0xC0,0x20,0x20,
- 0x20,0x20,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x40,0x20,
- 0x20,0x60,0x00,0x00,0x00,0x00,0x00,0x80,0x40,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x41,0x21,0x21,0xC1,0x00,0x00,0x40,0xE1,0x01,0x00,0x00,0x00,
- 0x01,0x81,0x01,0x00,0x00,0x00,0x80,0x41,0xF1,0x00,0x00,0x02,0x41,0x20,0x20,0xC0,
- 0x00,0x00,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x02,0x01,0x00,
- 0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0xFF,
- 0x80,0x80,0x00,0x00,0x00,0xC1,0xA0,0x90,0x88,0x86,0xC1,0x00,0x00,0x71,0x8A,0x84,
- 0x84,0x8A,0x71,0x00,0x00,0x82,0xC6,0xB8,0x3A,0xC6,0x82,0x00,0x00,0x3F,0x44,0x82,
- 0x82,0x44,0x38,0x00,0x00,0x1C,0x13,0x90,0x90,0xFF,0x90,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x0C,0x0A,0x09,0x08,0x00,0x00,0x08,0x0F,0x08,0x00,0x00,0x00,
- 0x00,0x08,0x00,0x00,0x00,0x03,0x02,0x02,0x0F,0x02,0x00,0x00,0x04,0x09,0x09,0x06,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x03,0x41,0x7F,0x41,0x03,0x00,0x41,0x7F,0x1E,0x0E,0x7F,0x41,0x00,
- 0x42,0x7F,0x40,0x00,0x00,0x00,0x62,0x51,0x49,0x46,0x00,0x00,0x36,0x49,0x49,0x36,
- 0x00,0x3E,0x49,0x49,0x49,0x30,0x00,0x18,0x14,0x12,0x7F,0x10,0x00,0x00,0x42,0x7F,
- 0x40,0x00,0x00,0x00,0x01,0x79,0x07,0x01,0x00,0x41,0x7F,0x45,0x45,0x3A,0x00,0x41,
- 0x7F,0x49,0x1D,0x03,0x00,0x07,0x79,0x07,0x19,0x79,0x07,0x3E,0x41,0x51,0x31,0x10,
- 0x00,0x01,0x47,0x78,0x47,0x01,0x00,0x40,0x7C,0x13,0x7C,0x40,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x41,0x7F,0x45,0x45,0x3A,0x00,0x04,0x04,0x04,0x04,0x04,0x00,0x00,
- 0x62,0x51,0x49,0x46,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0xFC,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0xFE
- };
- void init_sys(void)
- {
- DCOCTL=0;
- BCSCTL1=CALBC1_1MHZ;
- DCOCTL=CALDCO_1MHZ;
- //==GPIO==
- P2DIR=0xff;//輸出
- P1DIR=0xff;//輸出
- P1OUT=0xff;
- }
- void lcd_spi(unsigned char t)
- {
- unsigned char i=0x80,s;
- do
- {
- LCD &=~(SCLK);
- s=t&i;
- if(s==0)
- LCD &=~SDA;
- else
- LCD |=SDA;
- i=i>>1;
- LCD |=SCLK;
- }while(i!=0) ;
- }
- void lcd_wcom(unsigned char cmd)
- {
- LCD &=~(A0+CSB);
- lcd_spi(cmd);
- LCD |=A0+CSB;
- }
- void lcd_wdat(unsigned char dat)
- {
- LCD &=~(CSB);
- LCD |=A0;
- lcd_spi(dat);
- LCD |=A0+CSB;
- }
- void setpage(unsigned char page)//page 0-7
- {
- lcd_wcom(page+0xb0);
- }
- void setcol_0(void)
- {
- lcd_wcom(0x10);
- lcd_wcom(0x00);
- }
- void clrscr(unsigned char u)
- {
- unsigned char page,col;
- for(page=0xb0;page!=0xb8;page++)
- {
- lcd_wcom(page);
- setcol_0();
- for(col=0;col!=132;col++)
- {
- lcd_wdat(u);
- }
- }
- }
- void init_lcd(void)
- {
- LCD &=~RSTB;
- __delay_cycles(1500);//50ms
- LCD |=RSTB;
- __delay_cycles(1500);//50ms
- lcd_wcom(0xe2);//soft rest
- __delay_cycles(1500);//50ms
- lcd_wcom(0xaf);//turn on
- lcd_wcom(0x2f);//power magn on
- lcd_wcom(0xa1);//left<->right
- lcd_wcom(0x22);//對比度粗調0x20-0x27
- lcd_wcom(0x81);//對比度細調前行命令
- lcd_wcom(0x2f);//對比度細調
- lcd_wcom(0xa3);//chose bias
- clrscr(0xf0);
- }
- void display_bmp()
- {
- unsigned int i=0;
- unsigned char page,col;
- for(page=0xb0;page!=0xb8;page++)
- {
- lcd_wcom(page);
- setcol_0();
- for(col=0;col!=128;col++)
- {
- lcd_wdat(tab[i]);
- i++;
- }
- }
- }
- void main(void) {
-
- // Stop watchdog timer to prevent time out reset
- WDTCTL = WDTPW + WDTHOLD;
- unsigned char i=0;
- unsigned long p=1;
- init_sys();
- init_lcd();
- display_bmp();
- while(p!=0)
- {
- p++;
- __delay_cycles(150000);//50ms
- }
- }
復制代碼 |