/* setup.c * * Copyright (c) 2012 Ben Dooks */ #define F_CPU 16000000 #include #include /* setup values from: http://www.farnell.com/datasheets/12825.pdf */ /* wiring: * PBx = D[x+10] * PC5 = read [active low] * PC4 = write [active low] * PC7 = regsel [0=command,1=data] * PD5 = reset [active low] * PC6 = CSB [active low] * PD6 = 13V5 DCDC enable */ #define SEL_CMD 0 #define SEL_DATA 1 static void inline display_select(unsigned which) { if (which == SEL_CMD) PORTC &= ~(1 << 7); else PORTC |= (1 << 7); } static void display_send(unsigned char byte) { PORTB = byte; PORTC &= ~(1 << 6); PORTC &= ~(1 << 4); PORTC |= (1 << 4); PORTC |= (1 << 6); } static void display_command(unsigned char command) { display_select(SEL_CMD); display_send(command); display_select(SEL_DATA); } static void display_command_data(unsigned char command, unsigned char data) { display_select(SEL_CMD); display_send(command); display_select(SEL_DATA); display_send(data); } static void display_power_up(void) { DDRB = 0xff; PORTB = 0x00; // PORTB = 0x00; DDRC = 0xff; PORTC = (1 << 5) | (1 << 4); // ensure read/write strobes high PORTC |= (1 << 6); // csb high DDRD = 0x7f; PORTD = 0x00; PORTD |= (1 << 6); // power the DCDC _delay_ms(1); PORTD |= (1 << 5); // release reset _delay_ms(1); display_command_data(0x4, 0x1); _delay_ms(1); display_command_data(0x4, 0x0); _delay_ms(1); } #define T0_05sec() _delay_ms(500) void display_init(void) { display_power_up(); //Reg:04h Action:Normal current and PS ON ; Internal osc power off display_command_data(0x04,0x03); T0_05sec(); //Reg:04h Action:Normal current and PS OFF display_command_data(0x4,0x00); T0_05sec(); //Reg:3Bh Action:Screen Saver OFF display_command_data(0x3b,0x00); //Reg:02h Action:Export 0 /OSC with external resister/Internal OSC ON display_command_data(0x02,/*0x41*/ 0x01); //Reg:03h Action:FR=90Hz DIV=1 display_command_data(0x03,/*0x30*/ 0x90); //Reg:80h Action:PDAC OFF,DDAC OFF/Reference Volt.control with external resister display_command_data(0x80,0x00); //Reg:08h Action:set color R precharge time display_command_data(0x08,0x03); //Reg:09h Action:set color G precharge time display_command_data(0x09,0x05); //Reg:0Ah Action:set color B precharge tiem display_command_data(0x0a,0x05); //Reg:0Bh Action:set color R precharge current display_command_data(0x0b,0x0a); //Reg:0Ch Action:set color G precharge current display_command_data(0x0c,0x0a); //Reg:0Dh Action:set color B precharge current display_command_data(0x0d,0x0a); //Reg:10h Action:set color R dot driving current display_command_data(0x10,0x56); //Reg:11h Action:set color G dot driving current display_command_data(0x11,0x4d); //Reg:12h Action:set color B dot driving current display_command_data(0x12,0x46); //Reg:13h Action:Col D0 to D159/col normal display display_command_data(0x13,0x00); //Reg:14h Action:MPU mode display_command_data(0x14,0x31); //Reg:16h Action:8btis dual transfer,65K support display_command_data(0x16,0x66); //Reg:17h Action:Memory addr.X start display_command_data(0x17,0x00); //Reg:18h Action:Memory addr.X end display_command_data(0x18,0x9f); //Reg:18h Action:Memory addr.Y start display_command_data(0x19,0x00); //Reg:1Ah Action:Memory addr.Y end display_command_data(0x1a,0x7f); //Reg:20h Action:Memory X start addr. display_command_data(0x20,0x00); //Reg:21h Action:Memory Y start addr. display_command_data(0x21,0x00); //Reg:28h Action:Display duty ratio display_command_data(0x28,0x7f); //Reg:29h Action:Display start line display_command_data(0x29,0x00); //Reg:2Eh Action:Display First screen X start point display_command_data(0x2e,0x00); //Reg:2Fh Action:Display First screen Y start point display_command_data(0x2f,0x00); //Reg:31h Action:Display Second screen X start point display_command_data(0x31,0x00); //Reg:32h Action:Display Second screen Y start point display_command_data(0x32,0x00); //Reg:33h Action:Display size X start display_command_data(0x33,0x00); //Reg:34h Action:Display size X end display_command_data(0x34,0x9f); //Reg:35h Action:Display size Y start display_command_data(0x35,0x00); //Reg:36h Action:Display size Y end display_command_data(0x36,0x7f); //Reg:06h Action:Scan signal is high level at precharge period/Dispaly ON display_command_data(0x06,0x01); _delay_ms(10); /* write is dual transfer, 8bit */ // already done. display_command_data(0x16, (1<<5) | (1<<6) | (3<<1) | 0); { int x, y; display_command(0x22); // access memory display_select(SEL_DATA); for (y = 0; y < 64; y++) { for (x = 0; x < 160; x++) { display_send(0xf8); display_send(0x00); } } for (; y < 128; y++) { for (x = 0; x < 160; x++) { display_send(0x00); display_send(0x1f); } } } }