CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

serial LCD ----16f877--

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Brian M
Guest







serial LCD ----16f877--
PostPosted: Tue Mar 02, 2004 6:23 pm     Reply with quote

Hi,

has anybody got some sample code for writing to serial LCD from a 16F877.

i've used the search function and could only find code for parallel LCD's

i choose the serial LCD as i persummed that it would be easier to program.

i'd apprecaits if you could include the whole code. (preprocess, defintions, main , functions etc.)

thanks in advance.
dyeatman



Joined: 06 Sep 2003
Posts: 1912
Location: Norman, OK

View user's profile Send private message

Serial LCD Code
PostPosted: Tue Mar 02, 2004 10:59 pm     Reply with quote

This is not the only resource on the web. I went on Google and in 20 seconds searched for "CCS Serial LCD" and found lots of hits:

Go here and put a little effort into it:

http://www.phanderson.com/PIC/PICC/CCS_PCM/lcd_f84.html

To find more stuff try the same thing I did ...

To find out the control code format you will have to read the data sheet for the specific LCD to know exactly what sequence you neeed to send.
jds-pic2
Guest







Re: serial LCD ----16f877--
PostPosted: Wed Mar 03, 2004 2:38 pm     Reply with quote

Brian M wrote:
has anybody got some sample code for writing to serial LCD from a 16F877.


Code:


// lcd-optrex-dmc50747.h

// CCS PIC C driver functions for the Optrex DMC50747 LCD unit,
// which uses the Seiko SED1200 series controller SED1233DGB.

// the SED1233DGB is a 3.3v, 16 char x 2 line LCD controller;
// it can operate with a 2 wire serial or 4b/8b parallel interface.
// this driver is designed for the 2 wire serial interface.

// notes:
// * DMC-50747NF-AK is available from Digi-Key as PN 73-1177-ND.
// * read and understand the datasheets before modifying this code.
// * the DMC50747 requires a bipolar power supply to bias the LCD
//   contrast.  for low cost designs, the -12V charge pump found on
//   RS232 level converters can provide a suitable negative rail. 
//   use a diode and capacitive filtering to isolate switching noise,
//   and a potentiometer to adjust the negative bias voltage.

// (C) copyright 2003 j.d.sandoz / jds-pic !at! losdos.dyndns.org

// released under the GNU GENERAL PUBLIC LICENSE (GPL)
// refer to http://www.gnu.org/licenses/gpl.txt

// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

// pin definitions:
//
//    A0 = a0     // LCD data/command select control
//    A1 = wrbar  // LCD read/write select control -- unused
//    A2 = RES    // LCD reset control
//    A3 = csbar  // LCD chip select control
//    B1 = SCL    // LCD serial clock
//    B2 = SI     // LCD serial input

#define LCD_A0_COMMAND        0
#define LCD_A0_DATA           1

#define LCD_RESET_ACTIVE      1
#define LCD_RESET_INACTIVE    0

#define LCD_CS_ACTIVE         0
#define LCD_CS_INACTIVE       1

#define LCD_WR_ACTIVE         1
#define LCD_WR_INACTIVE       0

#define LCD_CMD_NOOP          0b00000000
#define LCD_CMD_CURSOR_HOME   0b00010000
#define LCD_CMD_STATIC_CTL    0b00100000
#define LCD_CMD_DISPLAY_CTL   0b00110000
#define LCD_CMD_POWER_SAVE    0b01000000
#define LCD_CMD_POWER_CTL     0b01010000
#define LCD_CMD_SYSTEM_SET    0b01100000
#define LCD_CMD_CONTRAST_SET  0b01110000
#define LCD_CMD_RAM_ADDR      0b10000000  //  | 0b0xxxxxxx = address

#define LCD_ADDR_DDRAM_LINE_1 0x30
#define LCD_ADDR_DDRAM_LINE_2 0x40


// some useful user level defines

// basic initialization
#define LCD_USER_SET_LINES_2        (LCD_CMD_SYSTEM_SET | 0b00000000)

// these are for standby mode only
// note that the oscillator must be running for static display
#define LCD_USER_STATIC_DISPLAY_OFF (LCD_CMD_STATIC_CTL | 0b00000000)
#define LCD_USER_STATIC_DISPLAY_ON  (LCD_CMD_STATIC_CTL | 0b00000011)

// these are for active mode
#define LCD_USER_DISPLAY_DISABLE    (LCD_CMD_DISPLAY_CTL | 0b00000000)
#define LCD_USER_DISPLAY_ENABLE     (LCD_CMD_DISPLAY_CTL | 0b00000001)

// these are for power save control
#define LCD_USER_POWERSAVE_DISABLE  (LCD_CMD_POWER_SAVE | 0b00000000)
#define LCD_USER_POWERSAVE_OSC_ON   (LCD_CMD_POWER_SAVE | 0b00000010)
#define LCD_USER_POWERSAVE_ENABLE   (LCD_CMD_POWER_SAVE | 0b00000001)

// these are for power supply control
#define LCD_USER_POWER_CKT_DISABLE  (LCD_CMD_POWER_CTL | 0b00000000)
#define LCD_USER_POWER_CKT_ENABLE   (LCD_CMD_POWER_CTL | 0b00000010)

// these are contrast control
#define LCD_USER_CONTRAST_MIN       (LCD_CMD_CONTRAST_SET | 0b00000000)
#define LCD_USER_CONTRAST_MID       (LCD_CMD_CONTRAST_SET | 0b00001000)
#define LCD_USER_CONTRAST_MAX       (LCD_CMD_CONTRAST_SET | 0b00001111)
#define LCD_USER_CONTRAST_DEFAULT   (LCD_CMD_CONTRAST_SET | 0b00001111)

#define LCD_USER_SET_CURSOR_LINE1   (LCD_CMD_RAM_ADDR | LCD_ADDR_DDRAM_LINE_1)
#define LCD_USER_SET_CURSOR_LINE2   (LCD_CMD_RAM_ADDR | LCD_ADDR_DDRAM_LINE_2)

enum { LCDLINE1=1, LCDLINE2 };
enum { COMMAND, DATA };


void lcd_preinit() {
   OUTPUT_HIGH(PIN_LCD_CS);
   OUTPUT_HIGH(PIN_LCD_SCL);
   OUTPUT_LOW(PIN_LCD_SI);
   OUTPUT_LOW(PIN_LCD_RES);
   delay_us(20);
   OUTPUT_HIGH(PIN_LCD_RES);
   delay_us(20);
   OUTPUT_LOW(PIN_LCD_RES);
   delay_us(20);
   OUTPUT_HIGH(PIN_LCD_RES);
   delay_us(20);
   }


void lcd_DMC50747_reset() {       // see datasheet; this is the 80 series method
   OUTPUT_LOW(PIN_LCD_RES);
   delay_us(20);
   OUTPUT_HIGH(PIN_LCD_RES);
   delay_us(20);
   OUTPUT_LOW(PIN_LCD_RES);
   delay_us(20);
   OUTPUT_HIGH(PIN_LCD_RES);
   delay_us(20);
   OUTPUT_LOW(PIN_LCD_RW);       // no-op in serial mode.
   }


void lcd_DMC50747_sendbyte(int thebyte, int cmdflag) {  // lcd comms primitive
   int i;
   disable_interrupts(GLOBAL);
   OUTPUT_LOW(PIN_LCD_CS);
   delay_us(5);
   OUTPUT_HIGH(PIN_LCD_CS);
   delay_us(5);
   OUTPUT_LOW(PIN_LCD_CS);
   delay_us(5);
   if (cmdflag==COMMAND)
      OUTPUT_LOW(PIN_LCD_A0);
   else
      OUTPUT_HIGH(PIN_LCD_A0);
   delay_us(10);
   for(i=0;i<=7;i++) {
      OUTPUT_LOW(PIN_LCD_SCL);
      delay_us(10);
      if (BIT_TEST(thebyte,(7-i)))
         OUTPUT_HIGH(PIN_LCD_SI);
      else
         OUTPUT_LOW(PIN_LCD_SI);
      delay_us(10);
      OUTPUT_HIGH(PIN_LCD_SCL);
      delay_us(10);
      }
   delay_us(10);
   OUTPUT_HIGH(PIN_LCD_A0);
   delay_us(10);
   OUTPUT_HIGH(PIN_LCD_CS);
   delay_us(20);
   enable_interrupts(GLOBAL);
   }


void lcd_putc(char c) {
   lcd_DMC50747_sendbyte(c,DATA);
   }


void lcd_clear() {   // there doesn't seem to be a "LCD clear" CMD
   int i;
   lcd_DMC50747_sendbyte(LCD_CMD_CURSOR_HOME,COMMAND);
   lcd_DMC50747_sendbyte(LCD_USER_SET_CURSOR_LINE1,COMMAND);
   for (i=0;i<=15;i++)
      lcd_DMC50747_sendbyte(ASCII_SPACE,DATA);
   lcd_DMC50747_sendbyte(LCD_USER_SET_CURSOR_LINE2,COMMAND);
   for (i=0;i<=15;i++)
      lcd_DMC50747_sendbyte(ASCII_SPACE,DATA);
   lcd_DMC50747_sendbyte(LCD_CMD_CURSOR_HOME,COMMAND);
   }


void lcd_init() {    // see epson SED 1230 series datasheet, page 6-41
   lcd_DMC50747_reset();
   delay_ms(1);
   lcd_DMC50747_sendbyte(LCD_CMD_SYSTEM_SET,COMMAND);
   delay_ms(1);
   lcd_DMC50747_sendbyte(LCD_USER_POWER_CKT_ENABLE,COMMAND);
   delay_ms(1);
   lcd_DMC50747_sendbyte(LCD_USER_SET_LINES_2,COMMAND);
   delay_ms(1);
   lcd_DMC50747_sendbyte(LCD_USER_STATIC_DISPLAY_OFF,COMMAND);
   delay_ms(1);
   lcd_DMC50747_sendbyte(LCD_USER_DISPLAY_ENABLE,COMMAND);
   delay_ms(1);
   lcd_DMC50747_sendbyte(LCD_USER_POWERSAVE_OSC_ON,COMMAND);
   delay_ms(25);
   lcd_clear();
}


void lcd_setcursor(int line) {
   if (line==LCDLINE1)
      lcd_DMC50747_sendbyte(LCD_USER_SET_CURSOR_LINE1,COMMAND);
   if (line==LCDLINE2)
      lcd_DMC50747_sendbyte(LCD_USER_SET_CURSOR_LINE2,COMMAND);
}


void lcd_powerdown() {
   lcd_DMC50747_sendbyte(LCD_USER_POWER_CKT_DISABLE,COMMAND);
   lcd_DMC50747_sendbyte(LCD_USER_POWERSAVE_ENABLE,COMMAND);
   lcd_DMC50747_sendbyte(LCD_USER_DISPLAY_DISABLE,COMMAND);
}


jds-pic2
Guest







PostPosted: Wed Mar 03, 2004 2:53 pm     Reply with quote

usage:

in main()

Code:

   lcd_preinit();
   lcd_init();


there is a reason that these two inits are separate, and it has to do with how you want the display to come out of power down mode. if you want to reset the contents of the display, you can combine these two functions. otherwise, you can keep them separate, wake the display up using just lcd_init(), and at that point the display will show the exact contents that it went to sleep with. lcd_preinit() needs to be run at LCD cold start only.

as configured above, the controller has line wrap enabled, and so knowing the geometry of the display you can do things like this:
Code:

printf(lcd_putc,"> Low Battery! <>  1 x CR123A  <");

which leads to a 2x16 format display of
Code:

> Low Battery! <
>  1 x CR123A  <


also, you can explicitly control Y-axis positioning as such
Code:

lcd_setcursor(LCDLINE1);
buffer_fill_A(somedata);
printf(lcd_putc,buffer);
lcd_setcursor(LCDLINE2);
buffer_fill_B(somedata);
printf(lcd_putc,buffer);


there is no provision in the driver above to control X positioning. i leave that as an exercise to the reader but it would be nice to get the code back. open source you, open source me.

jds
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group