Advertisement
saper_2

SED1330 init for ITM400160 LCD (400x160)

Nov 11th, 2018
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.21 KB | None | 0 0
  1. void sed_init(void) {
  2.     SED_PORT_DATA = 0xff;
  3.     //DDR(SED_PORT_DATA) = 0xff;
  4.     sed_data_out();
  5.     SED_DDR_CTRL |= (1<<SED_PIN_RST | 1<<SED_PIN_CS | 1<<SED_PIN_WR | 1<<SED_PIN_RD | 1<<SED_PIN_A0);
  6.     SED_PORT_CTRL |= (1<<SED_PIN_RST | 1<<SED_PIN_CS | 1<<SED_PIN_WR | 1<<SED_PIN_RD | 1<<SED_PIN_A0);
  7.     // Reset :)
  8.     delay1ms(20);
  9.     //sed_cs_control = SED_CS_CTRL_AUTO;
  10.     sed_set_cs();
  11.     sed_set_rd();
  12.     sed_set_wr();
  13.    
  14.     sed_clr_rst();
  15.    
  16.     delay1ms(5); // min. 200us
  17.     sed_set_rst();
  18.     delay1ms(10);
  19.     // SYSTEM SET
  20.     sed_command(0x40); // system set
  21.         // P1:
  22.         //  *[0] M0 (0x01) - 0=Internal CG ROM, 1=External
  23.         //  *[1] M1 (0x02) - 0=CG RAM1 32char, 1=64char CG RAM + CG RAM2
  24.         //  *[2] M2 (0x04) - 0=8px char height , 1=16px char height <- External CG ROM
  25.         //  *[3] W/S (0x08) - 0=Single panel LCD , 1=Dual panel LCD
  26.         //  *[4] 1 (0x10) - 1= Always 1...
  27.         //  *[5] IV (0x20) - 0=Screen top-line correction , 1=No correction
  28.         //  *[6] TL (0x40) - 0=LCD Mode , 1=TV Mode (Only SED1336 ?)
  29.         //  *[7] DR (0x80) - 0=Normal , 1=Additional Shift clock cycles
  30.         sed_data(0x10|0x20); // M2:M0=000, WS=0, IV=1, TL=0, DR=0
  31.         // P2:
  32.         //  *[2:0] FX (0x00...0x07) - Character field width + 1 (1...8)
  33.         //  *[7] WF (0x80) - 0=16line AC Drive, 1=Two-frame AC Drive
  34.         sed_data(0x80|7); // FX=7 (8px) or FX=5 (6px), WF=0 ::: FX >= DisplayWidth / CharsPerLine
  35.         // P3:
  36.         //  *[3:0] FY (0x00...0x0F) - Height in pixels of character + 1 (1...16)
  37.         sed_data(7); // FY=7 (8px)
  38.         // P4:
  39.         //  *[7:0] CR (0x00...0xEF - 0...239) - "Section 3.2.1.12" :::  CR=RND(FX / 8) * CharsPerLine
  40.         sed_data(49); //50
  41.         // P5:
  42.         //  *[7:0] TCR (0x00...0xFF - 1...256) - must be: >= CR+4
  43.         #define SED_TCR_VALUE 54
  44.         sed_data(SED_TCR_VALUE); // P5
  45.         // P6:
  46.         //  *[7:0] LF (0x00...0xFF) - Height in lines of frame, height=LF+1
  47.         #define SED_LF_VALUE 160
  48.         sed_data(SED_LF_VALUE); // LF=(239+2=dummy lines)+1=242
  49.         // P7 & P8 - AP - horizontal address range = 256 = 0x0100 => [15:8-7:0] 0x01-0x00
  50.         //  *[15:0] AP - horiontal address range of the virtual screen (same as CR??)
  51.         #define SED_AP_GRAPH (uint16_t)50
  52.         #define SED_APL_GRAPH (SED_AP_GRAPH&0xff)
  53.         #define SED_APH_GRAPH (SED_AP_GRAPH>>8)
  54.         sed_data(SED_APL_GRAPH); // P7 - AP Low
  55.         sed_data(SED_APH_GRAPH); // P8 - AP High
  56.        
  57.         #if (SED_XTAL/((SED_TCR_VALUE*9+1)*SED_LF_VALUE)) < 50
  58.             #warning "SED1330 Crystal Oscillator Frequency is too low, lcd screen might flicker!"
  59.         #endif
  60.     // Memory map:
  61.     // TEXT: Chars per display: 50*20=1000chars (bytes) per display
  62.     // GRAPH: ((400*160)/8) = 8000bytes
  63.     // SAD1 :> dispaly 1, Layer 1 ( TEXT ) - 20rows, 50char = 1000chars per panel
  64.     // SAD2 :> display 1, Layer 2 ( Graphic ) ; 160 rows, 400cols = 64000 / 8bits = 8000 bytes per panel
  65.     // SAD3 :> display 2, Layer 1 ( TEXT )
  66.     // SAD4 :> display 2, Layer 2 ( Graphic ) - INVALID FOR THIS PANEL (WS=0)
  67.     sed_command(0x44); // Scroll
  68.         // P1:P2 = SAD1 L:H
  69.         sed_data(SED_SAD1L); // P1
  70.         sed_data(SED_SAD1H); // P2
  71.         // P3 - SL1 - Screen block start address - numbers of lines per display
  72.         sed_data(SED_SL); // P3
  73.         // P4:P5 = SAD2 L:H
  74.         sed_data(SED_SAD2L); // P4
  75.         sed_data(SED_SAD2H); // P5
  76.         // P6 - SL2 - same as SL1
  77.         sed_data(SED_SL); // P6
  78.         // P7:P8 = SAD3 L:H
  79.         sed_data(SED_SAD3L); // P7
  80.         sed_data(SED_SAD3H); // P8
  81.         // P9:P10 = SAD4 L:H
  82.         sed_data(SED_SAD4L); // P9
  83.         sed_data(SED_SAD4H); // P10    
  84.     sed_command(0x5A); // HDOT SCR
  85.         sed_data(0x00); // 0=no horizontal scroll of display
  86.     sed_command(0x5B); // OVLAY
  87.         // MX0,MX1 = [0:1] 0,0 0x00=OR (0x00) [ L1 | L2 | L3 ]
  88.         // MX0,MX1 = [0:1] 0,1 0x01=EX-OR (0x01) [ (L1 ^ L2) | (L3 ^ L4) ] // L2 and L4 equal?
  89.         // MX0,MX1 = [0:1] 1,0 0x02=AND (0x02) [ (L1 & L2) | (L3 & L4) ]
  90.         // MX0,MX1 = [0:1] 1,1 0x03=PriorityOR (0x03) [ L1 > L2(L4??) > L3)
  91.         // DM1,DM2 = [2:3] 0,0 0x00=Text mode for Layer 1 and 3 (Layer 1 Upper panel, Layer 1 lower panel) (0x00)
  92.         // DM1,DM2 = [2:3] 1,1 0x0c=Graphic mode for Layer 1 and 3 (Layer 1 Upper panel, Layer 1 lower panel) (0x0C)
  93.         // OV = [4] 0 - Mixed mode (text+graph), two layer (0x10)
  94.         sed_data(0x00);
  95.     sed_command(0x58); // disp ON/OFF => disable screen
  96.         // FC0,1 = [0:1] (0x01,0x02) - cursor flash rate
  97.         // FP0,1 = [2:3] (0x04,0x08) - SAD1 ON/OFF + flashing
  98.         // FP2,3 = [4:5] (0x10,0x20) - SAD2,4 ON/OFF + flashing
  99.         // FP4,5 = [6:7] (0x40,0x80) - SAD3 ON/OFF + flashing
  100.         sed_data(0x04|0x10); // SAD1, SAD2&4, SAD3 = ON
  101.     sed_command(0x5D); // CSR FORM
  102.         sed_data(7); // CRX <= FX - cursor width (8px - same as char width)
  103.         //sed_data(0x87); // CRY = FY-1 - cursor height (8px - same as char height) ; CM=1 - block cursor
  104.         sed_data(0x80|7); // CRY = FY-1 - cursor height (8px - same as char height) ; CM=0 - line cursor
  105.     sed_command(0x4C); // CSRDIR - Cursor move in right dir.
  106.     // "zero" whole memory
  107.     sed_command(SED_DRAW_CSRW);
  108.         sed_data(0); sed_data(0);
  109.     sed_command(SED_MEM_MWRITE);
  110.     for (uint16_t t=0;t<0x8000;t++) sed_data(0); // wipe 32k memory
  111.     // for the end switch back on display
  112.     sed_command(0x59); // disp ON/OFF => DISP_ON
  113.         // FC0,1 = [0:1] (0x01,0x02) - cursor flash rate
  114.         // FP0,1 = [2:3] (0x04,0x08) - SAD1 ON/OFF + flashing
  115.         // FP2,3 = [4:5] (0x10,0x20) - SAD2,4 ON/OFF + flashing
  116.         // FP4,5 = [6:7] (0x40,0x80) - SAD3 ON/OFF + flashing
  117.         sed_data(0x04|0x10); // SAD1, SAD2&4
  118.    
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement