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 CCS Technical Support

LCD DMC50448 samsung S6A0069X01

 
Post new topic   Reply to topic    CCS Forum Index -> Code Library
View previous topic :: View next topic  
Author Message
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

LCD DMC50448 samsung S6A0069X01
PostPosted: Thu Jan 20, 2005 3:15 pm     Reply with quote

Code:

///////////////////////////////////////////////////////////////////////////
////                 LCD-DMC50448.c  www.apollodisplays.com            ////
////                 Driver for common LCD modules                     ////
////                                                                   ////
////  lcd_init()   Must be called before any other function.           ////
////                                                                   ////
////  lcd_putc(c)  Will display c on the next position of the LCD.     ////
////                     The following have special meaning:           ////
////                      \f  Clear display                            ////
////                      \n  Go to start of second line               ////
////                      \b  Move back one position                   ////
////                                                                   ////
////  lcd_gotoxy(x,y) Set write position on LCD (upper left is 1,1)    ////
///////////////////////////////////////////////////////////////////////////
#define set_tris_lcd_default() set_tris_d(0xff);set_tris_e(0);lcd.rs=0;lcd.rw=0

#define set_tris_lcd_r()       set_tris_d(0xff);set_tris_e(0)
#define set_tris_lcd_w()       set_tris_d(0x00);set_tris_e(0)
#define d_cycle 250
#define lcd_line_1 0x00  //address of the first line
#define lcd_line_2 0x40  //address of the second line
//#define lcd_line_3 0x10
//#define lcd_line_4 0x50
////////////////////commands///////////////////

const int8 clr_display = 0x01;  //
const int8 return_home = 0x02;  //

const int8 fctn_set    = 0x20;  //send this OR'd with one of the below
const int8 bus_8bit    = 0x10;  //    Data length 8bit/4bit
const int8 bus_4bit    = 0x00;  //    Data length 8bit/4bit
const int8 two_lines   = 0x08;  //    one or two line display
const int8 one_line    = 0x00;  //    one or two line display
const int8 font2       = 0x04;  //    font to use both look the same??
const int8 font1       = 0x00;  //    font to use both look the same??

const int8 entry_mode  = 0x04;  //send this OR'd with one of the below
const int8 pointer_incr= 0x02;  //    increment the address
const int8 display_shift=0x01;  //    shift the display
const int8 pointer_decr= 0x00;  //    decrement the address

const int8 display_ctrl= 0x08;  //send this OR'd with one of the below
const int8 ON          = 0x04;  //    display is on
const int8 cursor      = 0x02;  //    cursor is on
const int8 blink       = 0x01;  //    blink is on
const int8 OFF         = 0x00;  //    display is off

///////////////////////////////////////////////

struct lcd_pin_map
{
  int8    data;//data bus
  BOOLEAN rs; //command/data_bar  sometimes refered to as rs..register select
  BOOLEAN rw; //read/write_bar
  BOOLEAN enable;//chip enable
} lcd;

#BYTE lcd = 8 // This puts the entire structure on D and E
#BIT lcd_busy=0x08.7 //7th bit of data bus
int8 lcd_delay=50;

int8  lcd_wait(void)
{
  int8 n;
  set_tris_lcd_r();
  lcd.rs=0;
  lcd.rw=1;//read/write_bar
  lcd.enable=1;
  while(lcd_busy);//wait in loop for busy flag to clear
  n=lcd.data;
  lcd.enable=0;
  set_tris_lcd_default();
  return(n); //returns address pointer
}

void lcd_write_byte(BOOLEAN rs, BYTE n)//rs=0=command dc=1=data
{
  lcd_wait();
  set_tris_lcd_w();
  lcd.rs=rs;
  lcd.rw=0;//read/write_bar
  lcd.data=n;
  delay_us(1);
  lcd.enable=1;
  delay_us(2);
  lcd.enable=0;
  set_tris_lcd_default();
}

void lcd_init()
{
  delay_ms(15);//delay the required 15mS
  set_tris_lcd_w();
  lcd.enable=0;
  lcd.rs=0;//rs=0=Instruction register
  lcd.rw=0;//rw=0=write
  lcd.data=fctn_set|bus_8bit;
  lcd.enable=1;
  delay_ms(5);//delay the required 4.1mS
  lcd.enable=0;
  delay_us(lcd_delay);
  lcd.data=fctn_set|bus_8bit;
  lcd.enable=1;
  delay_us(100);//delay the required 100uS
  lcd.enable=0;
  lcd.data=fctn_set|bus_8bit;
  lcd.enable=1;
  //////////////////////////////////////////////////
  // From here on we can listen to lcd_busy signal//
  //////////////////////////////////////////////////
  //lcd_write_byte(data/instruction_bar,byte_of_data);
  lcd_write_byte(0,fctn_set|bus_8bit|two_lines);//(fctn set) 8bit/4bit,# lines,font
  lcd_write_byte(0,display_ctrl|OFF|cursor|blink);//(display ctrl),ON,cursor,blink
  lcd_write_byte(0,clr_display);
  lcd_write_byte(0,entry_mode|pointer_incr);
  lcd_write_byte(0,display_ctrl|ON|cursor|blink);//(display ctrl),ON,cursor,blink
}

//read_byte not finished,.. but should be easy enough,, same type of shift
BYTE lcd_read_byte()
{
  int temp;
  lcd_wait();
  set_tris_lcd_r();
  lcd.rs=0;
  lcd.rw=1;
  delay_cycles(d_cycle);
  lcd.enable=1;
  delay_cycles(d_cycle);
  temp=lcd.data;
  lcd.enable=0;
  delay_cycles(d_cycle);
  lcd.rw=0;
  delay_cycles(d_cycle);
  set_tris_lcd_w();
  return(temp);
}

void lcd_putc(char c)
{
  if(c<20 || (c>0x7F && c<0xA0)) return;
  switch (c) {
    //    case '\f'   : lcd_write_byte(0,1);
    //    lcdline=1;
    //    delay_ms(2);
    //    break;
    //    case '\n'   : lcd_gotoxy(1,++lcdline);        break;
    //    case '\b'   : lcd_write_byte(0,0x10);  break;
    default     : lcd_write_byte(1,c);     break;
  }
}

void lcd_gotoxy( BYTE x, BYTE y) {
  BYTE address;
  switch (y) {
    case 1: address=lcd_line_1; break;
    case 2: address=lcd_line_2; break;
    //   case 3: address=lcd_line_3; break;
    //   case 4: address=lcd_line_4; break;
    default: address=lcd_line_1; break;
  }
  address+=x-1;
  lcd_write_byte(0,0x80|address);
}
/////////////////////////////////////////////////////
////////////////////////////////////////////////////

#include <16f877.h>
#device *=16
#include <string.h> //FOR MEMCMP
#case
#use delay(clock=16000000,restart_wdt)
#fuses hs,nowdt,noprotect,nolvp//we have a wdt now
#define VER_MAJOR 1
#define VER_MINOR 02
#use rs232(baud=19200,xmit=PIN_C0,rcv=PIN_C1,invert,stream=DEBUG,errors)
#zero_ram
#include "LCD-DMC50448.c"
//======================= MAIN ============================//
void main(void)
{
  int8 i=0x0;
  //--------- START -------//
//  fprintf(DEBUG,".");
  fprintf(DEBUG,"STARTING U11\n\r");
  fprintf(DEBUG,"FIRMWARE VERSION %u.%02u\n\r",VER_MAJOR,VER_MINOR);
  setup_adc_ports(NO_ANALOGS);
  set_tris_a(0x00);
  set_tris_b(0x00);
  set_tris_c(0x00);
  set_tris_d(0x00);
  set_tris_e(0x0);
  lcd_init();
  lcd_gotoxy(3,1);
  printf(lcd_putc,"Hi");
  lcd_gotoxy(2,2);
  printf(lcd_putc,"dude");
 
 
 
  while(1)
  {
//    i++;
//    printf(lcd_putc,"%c",i);
//    delay_ms(1);

//    if(!kbhit())
//    {
//      i=fgetc(DEBUG);
//      printf(lcd_putc,"%c",i);
//    }
  }
}





Last edited by treitmey on Mon Jan 24, 2005 2:07 pm; edited 2 times in total
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

4 bit mode
PostPosted: Thu Jan 20, 2005 4:58 pm     Reply with quote

Code:

///////////////////////////////////////////////////////////////////////////
////                 LCD-DMC50448.c  www.apollodisplays.com            ////
////                 Driver for common LCD modules                     ////
////                 4 bit mode                                        ////
////  lcd_init()   Must be called before any other function.           ////
////                                                                   ////
////  lcd_putc(c)  Will display c on the next position of the LCD.     ////
////                     The following have special meaning:           ////
////                      \f  Clear display                            ////
////                      \n  Go to start of second line               ////
////                      \b  Move back one position                   ////
////                                                                   ////
////  lcd_gotoxy(x,y) Set write position on LCD (upper left is 1,1)    ////
///////////////////////////////////////////////////////////////////////////
#define set_tris_lcd_default() set_tris_d(0xff);set_tris_e(0);lcd.rs=0;lcd.rw=0

#define set_tris_lcd_r()       set_tris_d(0xff);set_tris_e(0)
#define set_tris_lcd_w()       set_tris_d(0x00);set_tris_e(0)
#define d_cycle 250
#define lcd_line_1 0x00  //address of the first line
#define lcd_line_2 0x40  //address of the second line
//#define lcd_line_3 0x10
//#define lcd_line_4 0x50
////////////////////commands///////////////////

const int8 clr_display = 0x01;  //
const int8 return_home = 0x02;  //

const int8 fctn_set    = 0x20;  //send this OR'd with one of the below
const int8 bus_8bit    = 0x10;  //    Data length 8bit/4bit
const int8 bus_4bit    = 0x00;  //    Data length 8bit/4bit
const int8 two_lines   = 0x08;  //    one or two line display
const int8 one_line    = 0x00;  //    one or two line display
const int8 font2       = 0x04;  //    font to use both look the same??
const int8 font1       = 0x00;  //    font to use both look the same??

const int8 entry_mode  = 0x04;  //send this OR'd with one of the below
const int8 pointer_incr= 0x02;  //    increment the address
const int8 display_shift=0x01;  //    shift the display
const int8 pointer_decr= 0x00;  //    decrement the address

const int8 display_ctrl= 0x08;  //send this OR'd with one of the below
const int8 ON          = 0x04;  //    display is on
const int8 cursor      = 0x02;  //    cursor is on
const int8 blink       = 0x01;  //    blink is on
const int8 OFF         = 0x00;  //    display is off

///////////////////////////////////////////////

struct lcd_pin_map
{
  int junk:4;//data bus
  int data:4;//data bus
  BOOLEAN rs; //command/data_bar  sometimes refered to as rs..register select
  BOOLEAN rw; //read/write_bar
  BOOLEAN enable;//chip enable
} lcd;

#BYTE lcd = 8 // This puts the entire structure on D and E
#BIT lcd_busy=0x08.7 //7th bit of data bus
int8 lcd_delay=50;

int8  lcd_wait(void)
{
  int8 n;
  set_tris_lcd_r();
  lcd.rs=0;
  lcd.rw=1;//read/write_bar
  lcd.enable=1;
  while(lcd_busy);//wait in loop for busy flag to clear
  n=lcd.data;
  lcd.enable=0;
  set_tris_lcd_default();
  return(n);
}

void lcd_write_byte(BOOLEAN rs, BYTE n)//rs=0=command dc=1=data
{
fprintf(DEBUG,".");
  lcd_wait();
  set_tris_lcd_w();
  lcd.rs=rs;
  lcd.rw=0;//read/write_bar
  lcd.data=n>>4;
  delay_us(1);
  lcd.enable=1;
  delay_us(2);
  lcd.enable=0;
  delay_us(2);
  lcd.data=n;
  delay_us(1);
  lcd.enable=1;
  delay_us(2);
  lcd.enable=0;
  set_tris_lcd_default();
fprintf(DEBUG,".");
}

void lcd_init()
{
  set_tris_lcd_w();

  delay_ms(15);//delay the required 15mS
  lcd.enable=0;
  lcd.rs=0;//rs=0=Instruction register
  lcd.rw=0;//rw=0=write
  //lcd.data=(fctn_set|bus_8bit)>>4;
fprintf(DEBUG,"1");
  lcd.data=0b0011;
  lcd.enable=1;
  delay_ms(5);//delay the required 4.1mS
  lcd.enable=0;
fprintf(DEBUG,"2");
  lcd.data=0b0011;
  lcd.enable=1;
  delay_us(100);
  lcd.enable=0;
fprintf(DEBUG,"3");
  lcd.data=0b0011;
  lcd.enable=1;
  delay_us(100);
  lcd.enable=0;
fprintf(DEBUG,"4");
  lcd.data=0b0010;
  lcd.enable=1;
  delay_us(100);
  lcd.enable=0;

//  //lcd.data=(fctn_set|bus_8bit)>>4;
//  lcd.data=0b0010;
//  lcd.enable=1;
//  delay_us(100);//delay the required 100uS
//  lcd.enable=0;
//fprintf(DEBUG,"3"); 
//  lcd.data=(fctn_set|bus_8bit)>>4;
//  lcd.enable=1;
//  //////////////////////////////////////////////////
//  // From here on we can listen to lcd_busy signal//
//  //////////////////////////////////////////////////
//  //lcd_write_byte(data/instruction_bar,byte_of_data);
//fprintf(DEBUG,"4");
  lcd_write_byte(0,fctn_set|bus_4bit|two_lines);//(fctn set) 8bit/4bit,# lines,font
  lcd_write_byte(0,display_ctrl|OFF|cursor|blink);//(display ctrl),ON,cursor,blink
  lcd_write_byte(0,clr_display);
  lcd_write_byte(0,entry_mode|pointer_incr);
  lcd_write_byte(0,display_ctrl|ON|cursor|blink);//(display ctrl),ON,cursor,blink
fprintf(DEBUG,"5");
}

BYTE lcd_read_byte()
{
  int temp;
  lcd_wait();
  set_tris_lcd_r();
  lcd.rs=0;
  lcd.rw=1;
  delay_cycles(d_cycle);
  lcd.enable=1;
  delay_cycles(d_cycle);
  temp=lcd.data;
  lcd.enable=0;
  delay_cycles(d_cycle);
  lcd.rw=0;
  delay_cycles(d_cycle);
  set_tris_lcd_w();
  return(temp);
}

void lcd_putc(char c)
{
  if(c<20 || (c>0x7F && c<0xA0)) return;
  switch (c) {
    //    case '\f'   : lcd_write_byte(0,1);
    //    lcdline=1;
    //    delay_ms(2);
    //    break;
    //    case '\n'   : lcd_gotoxy(1,++lcdline);        break;
    //    case '\b'   : lcd_write_byte(0,0x10);  break;
    default     : lcd_write_byte(1,c);     break;
  }
}

void lcd_gotoxy( BYTE x, BYTE y) {
  BYTE address;
  switch (y) {
    case 1: address=lcd_line_1; break;
    case 2: address=lcd_line_2; break;
    //   case 3: address=lcd_line_3; break;
    //   case 4: address=lcd_line_4; break;
    default: address=lcd_line_1; break;
  }
  address+=x-1;
  lcd_write_byte(0,0x80|address);
}


///////////////////////////
///////////////////////////
#include <16f877.h>
#device *=16
#case
#use delay(clock=16000000,restart_wdt)
#fuses hs,nowdt,noprotect,nolvp//we have a wdt now
#define VER_MAJOR 1
#define VER_MINOR 02
#use rs232(baud=19200,xmit=PIN_C0,rcv=PIN_C1,invert,stream=DEBUG)
#zero_ram
#include "LCD-DMC50448.c"
//======================= MAIN ============================//
void main(void)
{
  setup_adc_ports(NO_ANALOGS);
  set_tris_a(0);set_tris_b(0);set_tris_c(0);set_tris_d(0);set_tris_e(0);
  fprintf(DEBUG,"STARTING U11\n\r");
  fprintf(DEBUG,"FIRMWARE VERSION %u.%02u\n\r",VER_MAJOR,VER_MINOR);
  lcd_init();
  delay_ms(1000);
  printf(lcd_putc,"Hi baby");
  while(1);
 
}

Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> Code Library 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