Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

4bit LCD on custom pinout ??

Status
Not open for further replies.
delay_us c30

I manage to make it work, but only writing not reading,
I guess that's all I need for now. If any1's able to port
the code from the link I posted above, please share;

Here's what I came up with, might be usefull to some.

Code:
/*Thanks to Original Author*/
#include <p24Hxxxx.h>
typedef char		int8;
typedef unsigned char 	uint8;
typedef int		int16;//signed 16bits
typedef unsigned int	uint16;
typedef long		int32;//signed 32bits
typedef unsigned long	uint32;
typedef unsigned char   BYTE;

/* #defines of the data pins and the corresponding tris pins
   MCU specific */
#define LCD_DB7            _LATB10
#define LCD_DB6            _LATB12
#define LCD_DB5            _LATB9
#define LCD_DB4            _LATB11

#define TRIS_DATA_PIN_7    _TRISB10
#define TRIS_DATA_PIN_6    _TRISB12
#define TRIS_DATA_PIN_5    _TRISB9
#define TRIS_DATA_PIN_4    _TRISB11

/* #defines of the control pins and the corresponding tris pins*/
#define LCD_E              _LATB14       /* PORT for E */
#define LCD_RW             _LATB13       /* PORT for RW */
#define LCD_RS             _LATB8        /* PORT for RS */

#define TRIS_E             _TRISB14    /* TRIS for E */
#define TRIS_RW            _TRISB13    /* TRIS for RW */
#define TRIS_RS            _TRISB8     /* TRIS for RS */

//#define USE_RW_PIN   1

// These are the line addresses for most 4x20 LCDs.
#define LCD_LINE_1_ADDRESS 0x00
#define LCD_LINE_2_ADDRESS 0x40
#define LCD_LINE_3_ADDRESS 0x14
#define LCD_LINE_4_ADDRESS 0x54

// These are the line addresses for LCD's which use
// the Hitachi HD66712U controller chip.
/*
#define LCD_LINE_1_ADDRESS 0x00
#define LCD_LINE_2_ADDRESS 0x20
#define LCD_LINE_3_ADDRESS 0x40
#define LCD_LINE_4_ADDRESS 0x60
*/

//========================================

#define lcd_type 2   // 0=5x7, 1=5x10, 2=2 lines(or more)

void lcd_send_nibble(uint8 nibble);
void lcd_send_byte(uint8 address, uint8 n);
void lcd_gotoxy(uint8 x, uint8 y);
void lcd_putc(char c);
void prints(char *str);
void lcd_init();

uint8 lcd_line;

uint8 const LCD_INIT_STRING[4] =
{
 0x20 | (lcd_type << 2),  // Set mode: 4-bit, 2+ lines, 5x8 dots      0x20 | (lcd_type << 2)
 0xc,                     // Display on
 1,                       // Clear display
 6                        // Increment cursor
 };
//-------------------------------------
void lcd_send_nibble(uint8 nibble)
{   
    TRIS_DATA_PIN_7 = 0;
    TRIS_DATA_PIN_6 = 0;
    TRIS_DATA_PIN_5 = 0;
    TRIS_DATA_PIN_4 = 0;

// Note:  !! converts an integer expression
// to a boolean (1 or 0).
 LCD_DB4 = !!(nibble & 1);
 LCD_DB5 = !!(nibble & 2);
 LCD_DB6 = !!(nibble & 4);
 LCD_DB7 = !!(nibble & 8);

 Delay_Us(1);
 LCD_E = 1; //output_high(LCD_E);
 Delay_Us(2);
 LCD_E = 0; //output_low(LCD_E);
}

//----------------------------------------
// Send a byte to the LCD.
void lcd_send_byte(uint8 address, uint8 n)
{

LCD_RS = 0;

Delay_Ms(10);/* can't get the busy flag
                working, this works for now
                */
if(address)
   LCD_RS = 1;
else
   LCD_RS = 0;

Delay_Us(1);
LCD_RW = 0;
Delay_Us(1);
LCD_E = 0;

lcd_send_nibble(n >> 4);
lcd_send_nibble(n & 0xf);
}
//----------------------------

void lcd_init(void)
{
uint8 i;
lcd_line = 1;

	TRIS_DATA_PIN_7 = 0;
    	TRIS_DATA_PIN_6 = 0;
    	TRIS_DATA_PIN_5 = 0;
    	TRIS_DATA_PIN_4 = 0;
    	TRIS_E = 0;
	TRIS_RW = 0;
	TRIS_RS = 0;

     //TRISB = 0;

LCD_RS  = 0;
LCD_RW = 0;
LCD_E = 0;
// Some LCDs require 15 ms minimum delay after
// power-up.  Others require 30 ms.  I'm going
// to set it to 35 ms, so it should work with
// all of them.
Delay_Ms(35);

for(i=0 ;i < 3; i++)
   {
    lcd_send_nibble(0x03);
    Delay_Ms(5);
   }
 
lcd_send_nibble(0x02);
//lcd_send_nibble(0x28);
//lcd_send_nibble(0x0C);
//lcd_send_nibble(0x06);
//lcd_send_nibble(0x01);


for(i=0; i < sizeof(LCD_INIT_STRING); i++)
   {
   	 lcd_send_byte(0, LCD_INIT_STRING[i]);

   }

}

//----------------------------

void lcd_gotoxy(uint8 x, uint8 y)
{
uint8 address;


switch(y)
  {
   case 1:
     address = LCD_LINE_1_ADDRESS;
     break;

   case 2:
     address = LCD_LINE_2_ADDRESS;
     break;

   case 3:
     address = LCD_LINE_3_ADDRESS;
     break;

   case 4:
     address = LCD_LINE_4_ADDRESS;
     break;

   default:
     address = LCD_LINE_1_ADDRESS;
     break;
     
  }

address += x-1;
lcd_send_byte(0, 0x80 | address);
}

//-----------------------------
void lcd_putc(char c)
{
 switch(c)
   {
    case '\f':
      lcd_send_byte(0,1);
      lcd_line = 1;
      Delay_Ms(2);
      break;
   
    case '\n':
       lcd_gotoxy(1, ++lcd_line);
       break;
   
    case '\b':
       lcd_send_byte(0,0x10);
       break;
   
    default:
       lcd_send_byte(1,c);
       break;
   }
}

void prints(char *str)
{
  uint8 i;

  i = 0;
  while (str[i]) {
    lcd_putc(str[i++]);
  }
}
 

Re: LCD asm code pic

hi

see this asm code at romux

Code:
MAIN        
            MOVLW  .23 
            MOVWF   TEMP        ;Put any value   to variable  temp ; for printing on LCD        
                    
            LCDINIT                ;Incitializing LCD        
LOOP        
            LCDCMD 0X01            ;Clear  LCD
            LCDTEXT 1,"   ROMUX   ";Print text from line  1,   char  1 
            LCDTEXT 2,"PROBA LCD";Print text from line  2,   char  1 
            PAUSEMS .2000         ;2  sec pause  
            LCDCMD 0X01            ;Clear  LCD   
            LCDTEXT 1,"TEMPERATURE" ;Print text from line  1,   char  1 
            LCDTEXT 2,"TEMP="    ;Print text from line  2,   char  1 
            LCDBYTE TEMP        ;Print decimal value  of variable
            LCDTEXT 0,"C"        ;Print text from the  current 
            PAUSEMS    .2000          ;cursor position
                                               
              GOTO  LOOP                
            END
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top