ON 20040914@7:01:57 AM at page: http://www.piclist.com/techref/member/window_fish-yahoo-a/index.htm#38244.2930208333 [window_fish-yahoo-a] Questions: Hi, I am new to LCD. I tried to output the character "B" to the F-51553 Optrex graphical LCD which uses display controller SED1565, just to see if I can talk to the LCD in serial. Unfortunately LCD showed nothing. The uprocessor I am using is 16F877. The pin connections are as followed: 16F877 SED1565 RA4 ----> RST RC0 ----> SI (serial input) RC1 ----> SCL (serial clock) RD4 ----> CS (chip select) RD7 ----> A0 (data/command) Any help would be greatly appreciated. thanks! Here are the codes I wrote #include <16F877.h> #include /************************************************************************** * * * Global System Contant Definitions * * * *************************************************************************/ #define PORTLCD1 PORTC #define PORTLCD1DIR TRISC #define TRISC_INIT 0b10111000 #define LCD_CLK 1 #define LCD_DAT 0 #define PORTLCD2 PORTD #define PORTLCD2DIR TRISD #define TRISD_INIT 0b11000000 #define LCD_A0 7 #define LCD_CS 4 #define PORTLCD3 PORTA #define PORTLCD3DIR TRISA #define TRISA_INIT 0b00101111 #define LCD_RES 4 #define NUMBER_OF_COLUMNS 128 #define NUMBER_OF_ROWS 64 #define NUMBER_OF_PAGES 8 #define FIRST_PAGE 0 #define FIRST_COLUMN 0 #define LAST_PAGE 7 #define LAST_COLUMN 127 /* These are the flags that are passed to Write_Display() */ #define CMD 0x01 #define DATA 0xFF /* The individual bit declarations of the control lines. */ #define CS1_BIT 0x80 #define A0_BIT 0x40 #define WR_BIT 0x20 #define RD_BIT 0x10 #define RES_BIT 0x08 #define C86_BIT 0x04 /* The BUS_RELEASE define is used to the control bus output so that all control signals are pulled high. This ensures that when the microcontroller gains control of the bus, it does not change the direction of the bus to outputs while the display is driving the bus. */ #define BUS_RELEASE 0xF8 /* The following definitions are the command codes that are passed to the display via the data bus. */ #define DISPLAY_ON 0xAF #define DISPLAY_OFF 0xAE #define START_LINE_SET 0x40 #define PAGE_ADDRESS_SET 0xB0 #define COLUMN_ADDRESS_HIGH 0x10 #define COLUMN_ADDRESS_LOW 0x00 #define ADC_SELECT_NORMAL 0xA0 #define ADC_SELECT_REVERSE 0xA1 #define DISPLAY_NORMAL 0xA6 #define DISPLAY_REVERSE 0xA7 #define ALL_POINTS_ON 0xA5 #define LCD_BIAS_1_9 0xA2 #define LCD_BIAS_1_7 0xA3 #define READ_MODIFY_WRITE 0xE0 #define END 0xEE #define RESET_DISPLAY 0xE2 #define COMMON_OUTPUT_NORMAL 0xC0 #define COMMON_OUTPUT_REVERSE 0xC8 /* The power control set value */ #define POWER_CONTROL_SET 0x28 #define BOOSTER_CIRCUIT 0x04 #define VOLTAGE_REGULATOR 0x02 #define VOLTAGE_FOLLOWER 0x01 /* The initial value of the V5_RESISTOR_RATIO sets the Rb/Ra ratio to the smallest setting. The valid range of the ratio is: 0x20 <= V5_RESISTOR_RATIO <= 0x27 */ #define V5_RESISTOR_RATIO 0x26 #define ELECTRONIC_VOLUME_SET 0x81 #define ELECTRONIC_VOLUME_INIT 0x20 /* Configuration word definitions for 16F87x */ #define LP_OSC 0b00000000000000 /* Low power crystal */ #define XT_OSC 0b00000000000001 /* Crystal */ #define HS_OSC 0b00000000000010 /* High Speed crystal */ #define RC_OSC 0b00000000000011 /* RC Oscillator */ #define DEBUG_OFF 0b00100000000000 /* ICD disabled, RB6&7 are I/O */ #define WRT_ON 0b00001000000000 /* Flash Write Enable */ #define CPD_OFF 0b00000100000000 /* EEPROM Code Protect Off */ #define LVP_ON 0b00000010000000 /* Enable LVP - use RB3 */ #define BODEN 0b00000001000000 /* Enable brown-out reset */ #define PWRTEN 0b00000000001000 /* disable power-up timer */ #define WDTE 0b00000000000100 /* Enable WDT */ #define CP_ALL 0b00000000000000 /* Code protect all flash */ #define CP_UPR_1_2 0b01000000010000 /* Protect upper half */ #define CP_UPR_1_4 0b10000000100000 /* Protect upper 1/4 */ #define CP_OFF 0b11000000110000 /* Code protection off */ #pragma __CONFIG @ 0x2007 = XT_OSC | CP_OFF | PWRTEN | BODEN; /************************************************************************** * * * Global Function Prototypes * * * *************************************************************************/ void Write_Display(unsigned short command, unsigned short data); void Init_Display(void); void DISPLAY_CHAR(void); /************************************************************************** * * * SYSTEM VARIABLES * * * **************************************************************************/ unsigned int tmpb; unsigned int tmpa; const unsigned int test[8]={0,255,137,137,137,150,96,0}; /************************************************************************** * * * Init_Display * * * *************************************************************************/ void Init_Display(void){ PORTLCD3.LCD_RES = 0; /* Hold the display in reset. */ PORTLCD3.LCD_RES = 0; /* Multiple instructions to guarantee timing. */ PORTLCD3.LCD_RES = 1; /* Release the display in reset. */ PORTLCD3.LCD_RES = 1; /* Multiple instructions to guarantee timing. */ Write_Display(CMD,RESET_DISPLAY); Write_Display(CMD,LCD_BIAS_1_9); Write_Display(CMD,ADC_SELECT_NORMAL); Write_Display(CMD,COMMON_OUTPUT_NORMAL); Write_Display(CMD,V5_RESISTOR_RATIO); Write_Display(CMD,ELECTRONIC_VOLUME_SET); Write_Display(CMD,ELECTRONIC_VOLUME_INIT); Write_Display(CMD,(POWER_CONTROL_SET | VOLTAGE_REGULATOR |VOLTAGE_FOLLOWER | BOOSTER_CIRCUIT)); Write_Display(CMD,DISPLAY_ON); } /************************************************************************** * * * Write_Display * * * *************************************************************************/ void Write_Display(unsigned short command, unsigned short data) { PORTLCD1DIR = TRISC_INIT; PORTLCD2DIR = TRISD_INIT; PORTLCD3DIR = TRISA_INIT; /* Load the control signals and data for a particular command. */ if(command == CMD) PORTLCD2.LCD_A0 = 0; else PORTLCD2.LCD_A0 = 1; PORTLCD2.LCD_CS=0; /* Latch the data into the display. The minimum latch time is 60 nsec for a display write (ie. 60nsec X 8). Since LCD clock's period is 1200 nsec. Therefore, back to back instructions can be used. */ tmpb = data; tmpa = 8; do{ if(tmpb & 0x80) /* Set data line as req'd by MSB */ PORTLCD1.LCD_DAT = 1; else PORTLCD1.LCD_DAT = 0; NOP(); NOP(); PORTLCD1.LCD_CLK = 1; NOP(); NOP(); /* Clock high 600nS usec */ PORTLCD1.LCD_CLK = 0; tmpb <<= 1; /* Get next bit into MSB (B11) position */ }while(--tmpa); PORTLCD2.LCD_CS=1; } /************************************************************************** * * * Display_CHAR * * * *************************************************************************/ void DISPLAY_CHAR(void) { int i,j,page; page=0; j=0; Write_Display(CMD,START_LINE_SET); Write_Display(CMD,PAGE_ADDRESS_SET + page); Write_Display(CMD,COLUMN_ADDRESS_HIGH); Write_Display(CMD,COLUMN_ADDRESS_LOW); for(i=0;i<8;i++) { Write_Display(DATA,test[j]); j++; } Write_Display(CMD,DISPLAY_ON); } /************************************************************************** * * * Main * * * *************************************************************************/ void main(void) { Init_Display(); DISPLAY_CHAR(); } ON 20040914@6:04:06 PM at page: http://www.piclist.com/techref/member/window_fish-yahoo-a/index.htm# James Newton[JMN-EFP-786] edited the page. Difference: http://www.piclist.com/techref/diff.asp?url=H:\techref\member\window_fish-yahoo-a\index.htm&version=1 ON 20040914@6:04:56 PM at page: http://www.piclist.com/techref/member/window_fish-yahoo-a/index.htm# James Newton[JMN-EFP-786] edited the page. Difference: http://www.piclist.com/techref/diff.asp?url=H:\techref\member\window_fish-yahoo-a\index.htm&version=2