Here's a basic routine wriutten in CCS PICC.
Code: Select all
//basic routines to drive an ERpson S1D15G00 series based LCD, like the ones from sparkfun.com
// Epson S1D15G10 Command Set and init sequence stolen from sparkfun.com example source code
#include <18F4620.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES INTRC_IO //Internal RC Osc, no CLKOUT
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOIESO //Internal External Switch Over mode disabled
#FUSES BORV21 //Brownout reset at 2.1V
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOPUT //No Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES STVREN //Stack full/underflow will cause reset
//#FUSES DEBUG
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOCPB //No Boot Block code protection
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES NOFCMEN //Fail-safe clock monitor disabled
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES NOPBADEN //PORTB pins are configured as digital I/O on RESET
#FUSES LPT1OSC //Timer1 configured for low-power operation
//#FUSES MCLR
#FUSES NOMCLR //Master Clear pin used for I/O
#use delay(clock=8000000)
#define EEPROM_SDA PIN_D6
#define EEPROM_SCL PIN_D7
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,errors)
//#include <24512mod.c>
#DEFINE PICTX PIN_C6
#DEFINE PICRX PIN_C7
#DEFINE _LCDPWR PIN_D1
#DEFINE CS PIN_A5
#DEFINE LCDCLOCK PIN_C3
#DEFINE LCDDATA PIN_C5
#DEFINE _RESET PIN_C4
void write_lcd(int1, unsigned int);
void init_lcd(void);
void LCD_pixel_write(unsigned int8, unsigned int8, unsigned int8);//8 bit color
void main()
{
int8 eepromdata=123;
long int eepromaddress=0;
setup_wdt(WDT_OFF);
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF|ADC_TAD_MUL_0);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
setup_low_volt_detect(FALSE);
/*
for (eepromaddress=0; eepromaddress<512; eepromaddress++)
{
init_ext_eeprom();
delay_ms(10);
eepromdata=123;
write_ext_eeprom(eepromaddress, eepromdata);
delay_ms(100);
printf ("done writing\n\r");
eepromdata=read_ext_eeprom(eepromaddress);
printf ("EEprom memory address %Ld wrote 123 read %u\n\r", eepromaddress, eepromdata);
delay_ms(10);
}
*/
while(1)
{
init_lcd();
delay_ms(1000);
}
}
void write_lcd(int1 LCDmode, unsigned int data)//mode ==0 send a command, mode==1 sends data
{
if (!LCDmode)
output_low(LCDDATA);//when entering commands: SI=LOW at rising edge of 1st SCL
else
output_high(LCDDATA);//send data
output_low(LCDCLOCK);
output_high(LCDCLOCK);
//send data, 8th bit first
if (data & 128)
output_high(LCDDATA);
else
output_low(LCDDATA);
output_low(LCDCLOCK);
output_high(LCDCLOCK);
//7th bit
if (data & 64)
output_high(LCDDATA);
else
output_low(LCDDATA);
output_low(LCDCLOCK);
output_high(LCDCLOCK);
//6th bit
if (data & 32)
output_high(LCDDATA);
else
output_low(LCDDATA);
output_low(LCDCLOCK);
output_high(LCDCLOCK);
//5th bit
if (data & 16)
output_high(LCDDATA);
else
output_low(LCDDATA);
output_low(LCDCLOCK);
output_high(LCDCLOCK);
//4th bit
if (data & 8)
output_high(LCDDATA);
else
output_low(LCDDATA);
output_low(LCDCLOCK);
output_high(LCDCLOCK);
//3rd bit
if (data & 4)
output_high(LCDDATA);
else
output_low(LCDDATA);
output_low(LCDCLOCK);
output_high(LCDCLOCK);
//2nd bit
if (data & 2)
output_high(LCDDATA);
else
output_low(LCDDATA);
output_low(LCDCLOCK);
output_high(LCDCLOCK);
//1st bit
if (data & 1)
output_high(LCDDATA);
else
output_low(LCDDATA);
output_low(LCDCLOCK);
output_high(LCDCLOCK);
output_high(CS);
output_low(CS);
}
// Epson S1D15G10 Command Set
#define DISON 0xaf
#define DISOFF 0xae
#define DISNOR 0xa6
#define DISINV 0xa7
#define COMSCN 0xbb
#define DISCTL 0xca
#define SLPIN 0x95
#define SLPOUT 0x94
#define PASET 0x75
#define CASET 0x15
#define DATCTL 0xbc
#define RGBSET8 0xce
#define RAMWR 0x5c
#define RAMRD 0x5d
#define PTLIN 0xa8
#define PTLOUT 0xa9
#define RMWIN 0xe0
#define RMWOUT 0xee
#define ASCSET 0xaa
#define SCSTART 0xab
#define OSCON 0xd1
#define OSCOFF 0xd2
#define PWRCTR 0x20
#define VOLCTR 0x81
#define VOLUP 0xd6
#define VOLDOWN 0xd7
#define TMPGRD 0x82
#define EPCTIN 0xcd
#define EPCOUT 0xcc
#define EPMWR 0xfc
#define EPMRD 0xfd
#define EPSRRD1 0x7c
#define EPSRRD2 0x7d
#define NOP 0x25
void init_lcd(void)
{//mode ==0 send a command, mode==1 sends data
unsigned int16 i;
output_low(_LCDPWR);//apply power to LCD
delay_ms(250);
output_low(CS);
output_low(LCDDATA);
output_high(LCDCLOCK);
output_high(_reset);
output_low(_reset);
output_high(_reset);
output_high(LCDCLOCK);
output_high(LCDDATA);
output_high(LCDCLOCK);
delay_ms(10);
write_lcd(0, DISCTL);//display control
write_LCD(1, 0x03);
write_LCD(1, 0x1A);
write_LCD(1, 0x0C);
write_LCD(1, 0x00);
write_lcd(0, COMSCN);//common scan direction
write_LCD(1, 0x01);
write_lcd(0, OSCON);//oscillator on
write_lcd(0, SLPOUT);//sleep out
write_lcd(0, VOLCTR);//electronic volume control
write_LCD(1, 0x05);//cares about lower 6 bits V1 volume
write_LCD(1, 0x01);//cares about lower 3 bits 1+Rb/Ra, supposed to specify "resistance ratio of internal resistor"
write_lcd(0, PWRCTR);//power control
write_LCD(1, 0x0f);//turn stuff on
write_LCD(1, 0x64);
write_lcd(0, DISINV);//inverse display
write_lcd(0, DATCTL);//Data control
write_LCD(1, 0x00);
write_LCD(1, 0x00);
write_LCD(1, 0x01);
write_LCD(1, 0x00);
write_lcd(0, RGBSET8);//setup color lookup table
//red
write_LCD(1, 0);
write_LCD(1, 2);
write_LCD(1, 4);
write_LCD(1, 6);
write_LCD(1, 8);
write_LCD(1, 10);
write_LCD(1, 12);
write_LCD(1, 15);
//green
write_LCD(1, 0);
write_LCD(1, 2);
write_LCD(1, 4);
write_LCD(1, 6);
write_LCD(1, 8);
write_LCD(1, 10);
write_LCD(1, 12);
write_LCD(1, 15);
//blue
write_LCD(1, 0);
write_LCD(1, 4);
write_LCD(1, 9);
write_LCD(1, 15);
write_lcd(0, NOP);//no op
write_lcd(0, PASET);//page start/end ram
write_LCD(1, 2);//for some reason it starts at 2
write_LCD(1, 131);
write_lcd(0, CASET);//column start/end ram
write_LCD(1, 0);
write_LCD(1, 131);
write_lcd(0, RAMWR);//write a background
for (i=0; i< 18000; i++)
{
write_LCD(1, 28); //green
}
write_lcd(0, DISON);//display on
delay_ms(200);
for (i=0; i<160; i++)
{
write_lcd(0, VOLUP);//changes contrast, find correct setting by trial and error
delay_ms(20);
}
//draw a square in the middle of the screen
for (i=0; i<4096; i++)
{
lcd_pixel_write((i%64) + 32, (i/64)+32, i);
}
}
void LCD_pixel_write(unsigned int8 x, unsigned int8 y, unsigned int8 color)//8 bit color
{
x=x+2;
write_lcd(0, 0x75);//page start/end ram
write_lcd(1, x);
write_lcd(1, 132);
write_lcd(0, 0x15);//column start/end ram
write_lcd(1, y);
write_lcd(1, 131);
write_lcd(0, 0x5C);//color
write_lcd(1, color);
}