Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Write to a 16 Character LCD with Atmel Microcontroller Board?

Status
Not open for further replies.

fouadalnoor

Member
Hello,

I am currently using the Atmel SAM4L Xplained board in order to write to a simple 16 character LCD display module (DEM 16217 SYH-LY). Unfortunately, I can't get any characters to display on the board. I suspect my programming (using C in Atmel Studio 6.1) might be wrong (I have double checked all the connections). I only have the display showing one line with 16 black rectangles, but no letters. According to the data sheet, the LCD initializes automatically on power up and gives an example of how to write to the display [www.display-elektronik.de/DEM16217SYH-LY.PDF] and [], but as I follow the example I can't get any letters to display. I also tried initializing it by instruction, but to no avail. I hope you can take a look at my main.c file and see if there are any obvious errors that I am making (I only need to functions so the code is not too complex).

Thanks in advance!

Below is my main.c file code

Code:
/**
* \file
*
* \brief Empty user application template
*
*/

/**
* \mainpage User Application template doxygen documentation
*
* \par Empty user application template
*
* This is a bare minimum user application template.
*
* For documentation of the board, go \ref group_common_boards "here" for a link
* to the board-specific documentation.
*
* \par Content
*
* -# Include the ASF header files (through asf.h)
* -# Minimal main function that starts with a call to board_init()
* -# Basic usage of on-board LED and button
* -# "Insert application code here" comment
*
*/

/*
* Include header files for all drivers that have been imported from
* Atmel Software Framework (ASF).
*/
#include <asf.h>


void initIO(void)
{
    //Setting the pins for: RS, R/W and E as outputs.
    ioport_set_pin_dir(EXT3_PIN_15, IOPORT_DIR_OUTPUT); //RS
    ioport_set_pin_dir(EXT4_PIN_5, IOPORT_DIR_OUTPUT); //R/W
    ioport_set_pin_dir(EXT4_PIN_6, IOPORT_DIR_OUTPUT); //E

    //Setting the pins for: Data DB0-DB7
        ioport_set_pin_dir(EXT1_PIN_5, IOPORT_DIR_OUTPUT); //DB0
        ioport_set_pin_dir(EXT1_PIN_6, IOPORT_DIR_OUTPUT); //DB1
        ioport_set_pin_dir(EXT2_PIN_5, IOPORT_DIR_OUTPUT); //DB2
        ioport_set_pin_dir(EXT2_PIN_6, IOPORT_DIR_OUTPUT); //DB3
        ioport_set_pin_dir(EXT2_PIN_10, IOPORT_DIR_OUTPUT); //DB4
        ioport_set_pin_dir(EXT3_PIN_5, IOPORT_DIR_OUTPUT); //DB5
        ioport_set_pin_dir(EXT3_PIN_6, IOPORT_DIR_OUTPUT); //DB6
        ioport_set_pin_dir(EXT3_PIN_10, IOPORT_DIR_OUTPUT); //DB7 <- Will need to change this to input later on (to check for busy signal).
    
}

void EightbitInit(void)
{
    //8-bit interface mode.

     //Function Set
     ioport_set_pin_level(EXT3_PIN_15, 0); //RS = 0
     ioport_set_pin_level(EXT4_PIN_5, 0); //R/W = 0
 
     ioport_set_pin_level(EXT3_PIN_10,0); //DB7 = 0
     ioport_set_pin_level(EXT3_PIN_6,0); //DB6 = 0
     ioport_set_pin_level(EXT3_PIN_5,1); //DB5 = 1
     ioport_set_pin_level(EXT2_PIN_10,1); //DB4 = 1
     ioport_set_pin_level(EXT2_PIN_6,1); //DB3 = N =  1,  N = Numbers of display line (N:2-line/1-line)
     ioport_set_pin_level(EXT2_PIN_5,1); //DB2 = F =  1, F = Display font type (F:5*10 dots/5*7 dots)
 
     ioport_set_pin_level(EXT1_PIN_6,0); //DB1 = 0 (don't care)
     ioport_set_pin_level(EXT1_PIN_5,0); //DB0 = 0 (don't care)
 
     delay_us(50); //wait more than 39us

      //Display ON/OFF Control
               ioport_set_pin_level(EXT3_PIN_15,0); //RS = 0
               ioport_set_pin_level(EXT4_PIN_5,0); //R/W = 0
           
               ioport_set_pin_level(EXT3_PIN_10,0); //DB7 = 0
               ioport_set_pin_level(EXT3_PIN_6,0); //DB6 = 0
               ioport_set_pin_level(EXT3_PIN_5,0); //DB5 = 0
               ioport_set_pin_level(EXT2_PIN_10,0); //DB4 = 0
               ioport_set_pin_level(EXT2_PIN_6,1); //DB3 = 1
               ioport_set_pin_level(EXT2_PIN_5,1); //DB2 = D = 1, D = Set Display (ON)
           
               ioport_set_pin_level(EXT1_PIN_6,1); //DB1 = C = 1, C =  cursor on
               ioport_set_pin_level(EXT1_PIN_5,1); //DB0 = B = 1, Blinking  cursor (ON/OFF)- on.
      
          delay_us(50); //wait more than 39us
      
          //Display clear
      
          ioport_set_pin_level(EXT3_PIN_15,0); //RS = 0
          ioport_set_pin_level(EXT4_PIN_5,0); //R/W = 0
      
          ioport_set_pin_level(EXT3_PIN_10,0); //DB7 = 0
          ioport_set_pin_level(EXT3_PIN_6,0); //DB6 = 0
          ioport_set_pin_level(EXT3_PIN_5,0); //DB5 = 0
          ioport_set_pin_level(EXT2_PIN_10,0); //DB4 = 0
          ioport_set_pin_level(EXT2_PIN_6,0); //DB3 = 0
          ioport_set_pin_level(EXT2_PIN_5,0); //DB2 = 0
      
          ioport_set_pin_level(EXT1_PIN_6,0); //DB1 = 0
          ioport_set_pin_level(EXT1_PIN_5,1); //DB0 = 1
      
          delay_ms(2);
          //Entry mode set
      
                ioport_set_pin_level(EXT3_PIN_15,0); //RS = 0
                ioport_set_pin_level(EXT4_PIN_5,0); //R/W = 0
            
                ioport_set_pin_level(EXT3_PIN_10,0); //DB7 = 0
                ioport_set_pin_level(EXT3_PIN_6,0); //DB6 = 0
                ioport_set_pin_level(EXT3_PIN_5,0); //DB5 = 0
                ioport_set_pin_level(EXT2_PIN_10,0); //DB4 = 0
                ioport_set_pin_level(EXT2_PIN_6,0); //DB3 = 0
                ioport_set_pin_level(EXT2_PIN_5,1); //DB2 = 1
            
                ioport_set_pin_level(EXT1_PIN_6,1); //DB1 = I/D = 1, Assign cursor moving direction. (increment/decrement)
                ioport_set_pin_level(EXT1_PIN_5,1); //DB0 = S = 1, Enable the shift of entire display (entire shift off/entire shift on).
            
                //initialization end.
      
}

void sendChar(void)
{
    ////////Do NOT NEED TO DO This stuff as I have already initilized the LCD Screen.
    /*
    //Function set.

     ioport_set_pin_level(EXT3_PIN_15, 0); //RS = 0
     ioport_set_pin_level(EXT4_PIN_5, 0); //R/W = 0
 
     ioport_set_pin_level(EXT3_PIN_10,0); //DB7 = 0
     ioport_set_pin_level(EXT3_PIN_6,0); //DB6 = 0
     ioport_set_pin_level(EXT3_PIN_5,1); //DB5 = 1
     ioport_set_pin_level(EXT2_PIN_10,1); //DB4 = 1
     ioport_set_pin_level(EXT2_PIN_6,1); //DB3 = N =  1,  N = Numbers of display line (N:2-line/1-line)
     ioport_set_pin_level(EXT2_PIN_5,0); //DB2 = F =  0, F = Display font type (F:5*11 dots/5*8 dots) (probably mean 5*10 dots and NOT 5*11 dots)
 
     ioport_set_pin_level(EXT1_PIN_6,0); //DB1 = 0 (don't care)
     ioport_set_pin_level(EXT1_PIN_5,0); //DB0 = 0 (don't care)
 
     delay_us(50); //wait more than 39us
 
      //Display ON/OFF Control
      ioport_set_pin_level(EXT3_PIN_15,0); //RS = 0
      ioport_set_pin_level(EXT4_PIN_5,0); //R/W = 0
  
      ioport_set_pin_level(EXT3_PIN_10,0); //DB7 = 0
      ioport_set_pin_level(EXT3_PIN_6,0); //DB6 = 0
      ioport_set_pin_level(EXT3_PIN_5,0); //DB5 = 0
      ioport_set_pin_level(EXT2_PIN_10,0); //DB4 = 0
      ioport_set_pin_level(EXT2_PIN_6,1); //DB3 = 1
      ioport_set_pin_level(EXT2_PIN_5,1); //DB2 = D = 1, D = Set Display
  
      ioport_set_pin_level(EXT1_PIN_6,1); //DB1 = C = 1, C =  cursor on
      ioport_set_pin_level(EXT1_PIN_5,0); //DB0 = B = 0, Blinking of cursor (ON/OFF) off.
       delay_us(50); //wait more than 39us
   
       //Entry mode set (increment)
   
       ioport_set_pin_level(EXT3_PIN_15,0); //RS = 0
       ioport_set_pin_level(EXT4_PIN_5,0); //R/W = 0
   
       ioport_set_pin_level(EXT3_PIN_10,0); //DB7 = 0
       ioport_set_pin_level(EXT3_PIN_6,0); //DB6 = 0
       ioport_set_pin_level(EXT3_PIN_5,0); //DB5 = 0
       ioport_set_pin_level(EXT2_PIN_10,0); //DB4 = 0
       ioport_set_pin_level(EXT2_PIN_6,0); //DB3 = 0
       ioport_set_pin_level(EXT2_PIN_5,1); //DB2 = 1
        ioport_set_pin_level(EXT1_PIN_6,1); //DB1 = I/D = 1 (increment/decrement)
       ioport_set_pin_level(EXT1_PIN_5,0); //DB0 = S = 0, Enable the shift of entire display (entire shift off/entire shift on).
   
       */

       //Write 'S' in ASCII:
   
        ioport_set_pin_level(EXT3_PIN_15,1); //RS = 1 //Set the RS bit for writing into the data register.
        ioport_set_pin_level(EXT4_PIN_5,0); //R/W = 0
    
        ioport_set_pin_level(EXT3_PIN_10,0); //DB7 =0
        ioport_set_pin_level(EXT3_PIN_6,1); //DB6 = 1
        ioport_set_pin_level(EXT3_PIN_5,0); //DB5 = 0
        ioport_set_pin_level(EXT2_PIN_10,1); //DB4 =1
        ioport_set_pin_level(EXT2_PIN_6,0); //DB3 = 0
        ioport_set_pin_level(EXT2_PIN_5,0); //DB2 = 0
        ioport_set_pin_level(EXT1_PIN_6,1); //DB1 = 1
        ioport_set_pin_level(EXT1_PIN_5,1); //DB0 = 1
   
}

int main (void)
{
    board_init();
       initIO(); //Setting all the directions of all the pins as outputs.
    //INITIALIZING BY INSTRUCTION
    delay_ms(50);  //Wait more than 30ms after Vdd reaches 4.5V.
    //Set up the enable pin (needs to be 0 for writing, but needs to go from High -> Low)
    ioport_set_pin_level(EXT4_PIN_6,1); //Enable = 1;
    ioport_set_pin_level(EXT4_PIN_6,0); //Enable = 0;
                  
    //EightbitInit();
   //Send The letter 'S' to the LCD.
   sendChar();


}
 
I have updated the code (still not working though..) according to: https://www.circuitstoday.com/a-note-on-character-lcd-displays

Code:
/**
* \file
*
* \brief Empty user application template
*
*/

/**
* \mainpage User Application template doxygen documentation
*
* \par Empty user application template
*
* This is a bare minimum user application template.
*
* For documentation of the board, go \ref group_common_boards "here" for a link
* to the board-specific documentation.
*
* \par Content
*
* -# Include the ASF header files (through asf.h)
* -# Minimal main function that starts with a call to board_init()
* -# Basic usage of on-board LED and button
* -# "Insert application code here" comment
*
*/

/*
* Include header files for all drivers that have been imported from
* Atmel Software Framework (ASF).
*/
#include <asf.h>


void initIO(void);
void EightbitInit (void);
void sendChar(void);

int main (void)
{
    board_init();
       initIO(); //Setting all the directions of all the pins as outputs.
      
    //INITIALIZING BY INSTRUCTION
    delay_ms(50);  //Wait more than 30ms after Vdd reaches 4.5V.
   
    EightbitInit();
   

  
   ioport_set_pin_level(EXT4_PIN_6,0); //Enable = 0;
   ioport_set_pin_level(EXT4_PIN_6,1); //Enable = 1;
   sendChar();    //Send The letter 'S' to the LCD.
   ioport_set_pin_level(EXT4_PIN_6,0); //Enable = 0;


}


void initIO(void)
{
    //Setting the pins for: RS, R/W and E as outputs.
    ioport_set_pin_dir(EXT3_PIN_15, IOPORT_DIR_OUTPUT); //RS
    ioport_set_pin_dir(EXT4_PIN_5, IOPORT_DIR_OUTPUT); //R/W
    ioport_set_pin_dir(EXT4_PIN_6, IOPORT_DIR_OUTPUT); //E
   
    //Setting the pins for: Data DB0-DB7
        ioport_set_pin_dir(EXT1_PIN_5, IOPORT_DIR_OUTPUT); //DB0
        ioport_set_pin_dir(EXT1_PIN_6, IOPORT_DIR_OUTPUT); //DB1
        ioport_set_pin_dir(EXT2_PIN_5, IOPORT_DIR_OUTPUT); //DB2
        ioport_set_pin_dir(EXT2_PIN_6, IOPORT_DIR_OUTPUT); //DB3
        ioport_set_pin_dir(EXT2_PIN_10, IOPORT_DIR_OUTPUT); //DB4
        ioport_set_pin_dir(EXT3_PIN_5, IOPORT_DIR_OUTPUT); //DB5
        ioport_set_pin_dir(EXT3_PIN_6, IOPORT_DIR_OUTPUT); //DB6
        ioport_set_pin_dir(EXT3_PIN_10, IOPORT_DIR_OUTPUT); //DB7 <- Will need to change this to input later on (to check for busy signal).
       
}

void EightbitInit(void)
{
    //8-bit interface mode.

     //Function Set
     ioport_set_pin_level(EXT3_PIN_15, 0); //RS = 0
     ioport_set_pin_level(EXT4_PIN_5, 0); //R/W = 0
    
     ioport_set_pin_level(EXT3_PIN_10,0); //DB7 = 0
     ioport_set_pin_level(EXT3_PIN_6,0); //DB6 = 0
     ioport_set_pin_level(EXT3_PIN_5,1); //DB5 = 1
     ioport_set_pin_level(EXT2_PIN_10,1); //DB4 = 1
     ioport_set_pin_level(EXT2_PIN_6,1); //DB3 = N =  1,  N = Numbers of display line (N:2-line/1-line)
     ioport_set_pin_level(EXT2_PIN_5,1); //DB2 = F =  1, F = Display font type (F:5*10 dots/5*7 dots)
    
     ioport_set_pin_level(EXT1_PIN_6,0); //DB1 = 0 (don't care)
     ioport_set_pin_level(EXT1_PIN_5,0); //DB0 = 0 (don't care)
    
     delay_us(50); //wait more than 39us

      //Display ON/OFF Control
               ioport_set_pin_level(EXT3_PIN_15,0); //RS = 0
               ioport_set_pin_level(EXT4_PIN_5,0); //R/W = 0
              
               ioport_set_pin_level(EXT3_PIN_10,0); //DB7 = 0
               ioport_set_pin_level(EXT3_PIN_6,0); //DB6 = 0
               ioport_set_pin_level(EXT3_PIN_5,0); //DB5 = 0
               ioport_set_pin_level(EXT2_PIN_10,0); //DB4 = 0
               ioport_set_pin_level(EXT2_PIN_6,1); //DB3 = 1
               ioport_set_pin_level(EXT2_PIN_5,1); //DB2 = D = 1, D = Set Display (ON)
              
               ioport_set_pin_level(EXT1_PIN_6,1); //DB1 = C = 1, C =  cursor on
               ioport_set_pin_level(EXT1_PIN_5,1); //DB0 = B = 1, Blinking  cursor (ON/OFF)- on.
         
          delay_us(50); //wait more than 39us
         
          //Display clear
         
          ioport_set_pin_level(EXT3_PIN_15,0); //RS = 0
          ioport_set_pin_level(EXT4_PIN_5,0); //R/W = 0
         
          ioport_set_pin_level(EXT3_PIN_10,0); //DB7 = 0
          ioport_set_pin_level(EXT3_PIN_6,0); //DB6 = 0
          ioport_set_pin_level(EXT3_PIN_5,0); //DB5 = 0
          ioport_set_pin_level(EXT2_PIN_10,0); //DB4 = 0
          ioport_set_pin_level(EXT2_PIN_6,0); //DB3 = 0
          ioport_set_pin_level(EXT2_PIN_5,0); //DB2 = 0
         
          ioport_set_pin_level(EXT1_PIN_6,0); //DB1 = 0
          ioport_set_pin_level(EXT1_PIN_5,1); //DB0 = 1
         
          delay_ms(2);
          //Entry mode set
         
                ioport_set_pin_level(EXT3_PIN_15,0); //RS = 0
                ioport_set_pin_level(EXT4_PIN_5,0); //R/W = 0
               
                ioport_set_pin_level(EXT3_PIN_10,0); //DB7 = 0
                ioport_set_pin_level(EXT3_PIN_6,0); //DB6 = 0
                ioport_set_pin_level(EXT3_PIN_5,0); //DB5 = 0
                ioport_set_pin_level(EXT2_PIN_10,0); //DB4 = 0
                ioport_set_pin_level(EXT2_PIN_6,0); //DB3 = 0
                ioport_set_pin_level(EXT2_PIN_5,1); //DB2 = 1
               
                ioport_set_pin_level(EXT1_PIN_6,1); //DB1 = I/D = 1, Assign cursor moving direction. (increment/decrement) 
                ioport_set_pin_level(EXT1_PIN_5,1); //DB0 = S = 1, Enable the shift of entire display (entire shift off/entire shift on).
               
                //initialization end.
         
}

void sendChar(void)
{
    ////////Do NOT NEED TO DO This stuff as I have already initialized the LCD Screen.
    /*
    //Function set.
   
     ioport_set_pin_level(EXT3_PIN_15, 0); //RS = 0
     ioport_set_pin_level(EXT4_PIN_5, 0); //R/W = 0
    
     ioport_set_pin_level(EXT3_PIN_10,0); //DB7 = 0
     ioport_set_pin_level(EXT3_PIN_6,0); //DB6 = 0
     ioport_set_pin_level(EXT3_PIN_5,1); //DB5 = 1
     ioport_set_pin_level(EXT2_PIN_10,1); //DB4 = 1
     ioport_set_pin_level(EXT2_PIN_6,1); //DB3 = N =  1,  N = Numbers of display line (N:2-line/1-line)
     ioport_set_pin_level(EXT2_PIN_5,0); //DB2 = F =  0, F = Display font type (F:5*11 dots/5*8 dots) (probably mean 5*10 dots and NOT 5*11 dots)
    
     ioport_set_pin_level(EXT1_PIN_6,0); //DB1 = 0 (don't care)
     ioport_set_pin_level(EXT1_PIN_5,0); //DB0 = 0 (don't care)
    
     delay_us(50); //wait more than 39us
    
      //Display ON/OFF Control
      ioport_set_pin_level(EXT3_PIN_15,0); //RS = 0
      ioport_set_pin_level(EXT4_PIN_5,0); //R/W = 0
     
      ioport_set_pin_level(EXT3_PIN_10,0); //DB7 = 0
      ioport_set_pin_level(EXT3_PIN_6,0); //DB6 = 0
      ioport_set_pin_level(EXT3_PIN_5,0); //DB5 = 0
      ioport_set_pin_level(EXT2_PIN_10,0); //DB4 = 0
      ioport_set_pin_level(EXT2_PIN_6,1); //DB3 = 1
      ioport_set_pin_level(EXT2_PIN_5,1); //DB2 = D = 1, D = Set Display
     
      ioport_set_pin_level(EXT1_PIN_6,1); //DB1 = C = 1, C =  cursor on
      ioport_set_pin_level(EXT1_PIN_5,0); //DB0 = B = 0, Blinking of cursor (ON/OFF) off.
       delay_us(50); //wait more than 39us
      
       //Entry mode set (increment)
      
       ioport_set_pin_level(EXT3_PIN_15,0); //RS = 0
       ioport_set_pin_level(EXT4_PIN_5,0); //R/W = 0
      
       ioport_set_pin_level(EXT3_PIN_10,0); //DB7 = 0
       ioport_set_pin_level(EXT3_PIN_6,0); //DB6 = 0
       ioport_set_pin_level(EXT3_PIN_5,0); //DB5 = 0
       ioport_set_pin_level(EXT2_PIN_10,0); //DB4 = 0
       ioport_set_pin_level(EXT2_PIN_6,0); //DB3 = 0
       ioport_set_pin_level(EXT2_PIN_5,1); //DB2 = 1
        ioport_set_pin_level(EXT1_PIN_6,1); //DB1 = I/D = 1 (increment/decrement)
       ioport_set_pin_level(EXT1_PIN_5,0); //DB0 = S = 0, Enable the shift of entire display (entire shift off/entire shift on).
      
       */
   
       //Write 'S' in ASCII:
      
        ioport_set_pin_level(EXT3_PIN_15,1); //RS = 1 //Set the RS bit for writing into the data register.
        ioport_set_pin_level(EXT4_PIN_5,0); //R/W = 0
       
        ioport_set_pin_level(EXT3_PIN_10,0); //DB7 =0
        ioport_set_pin_level(EXT3_PIN_6,1); //DB6 = 1
        ioport_set_pin_level(EXT3_PIN_5,0); //DB5 = 0
        ioport_set_pin_level(EXT2_PIN_10,1); //DB4 =1
        ioport_set_pin_level(EXT2_PIN_6,0); //DB3 = 0
        ioport_set_pin_level(EXT2_PIN_5,0); //DB2 = 0
        ioport_set_pin_level(EXT1_PIN_6,1); //DB1 = 1
        ioport_set_pin_level(EXT1_PIN_5,1); //DB0 = 1
      
}
 
Actually, I figured it out! I did not pulse the enable signal after every command (and character I sent)!.

The following code now works:

Code:
/**
* \file
*
* \brief Empty user application template
*
*/

/**
* \mainpage User Application template doxygen documentation
*
* \par Empty user application template
*
* This is a bare minimum user application template.
*
* For documentation of the board, go \ref group_common_boards "here" for a link
* to the board-specific documentation.
*
* \par Content
*
* -# Include the ASF header files (through asf.h)
* -# Minimal main function that starts with a call to board_init()
* -# Basic usage of on-board LED and button
* -# "Insert application code here" comment
*
*/

/*
* Include header files for all drivers that have been imported from
* Atmel Software Framework (ASF).
*/
#include <asf.h>


void initIO(void);
void EightbitInit (void);
void sendChar(void);

int main (void)
{
    board_init();
       initIO(); //Setting all the directions of all the pins as outputs.
      
    ////////////INITIALIZING BY INSTRUCTION///////////
   delay_ms(50);  //Wait more than 30ms after Vdd reaches 4.5V.
   EightbitInit();
  
   delay_us(1);
    ////////////////////////////////////
    sendChar();    //Send The letter 'S' to the LCD.
    ioport_set_pin_level(EXT4_PIN_6,0); //Enable = 0;

   
   


}


void initIO(void)
{
    //Setting the pins for: RS, R/W and E as outputs.
    ioport_set_pin_dir(EXT3_PIN_15, IOPORT_DIR_OUTPUT); //RS
    ioport_set_pin_dir(EXT4_PIN_5, IOPORT_DIR_OUTPUT); //R/W
    ioport_set_pin_dir(EXT4_PIN_6, IOPORT_DIR_OUTPUT); //E
   
    //Setting the pins for: Data DB0-DB7
        ioport_set_pin_dir(EXT1_PIN_5, IOPORT_DIR_OUTPUT); //DB0
        ioport_set_pin_dir(EXT1_PIN_6, IOPORT_DIR_OUTPUT); //DB1
        ioport_set_pin_dir(EXT2_PIN_5, IOPORT_DIR_OUTPUT); //DB2
        ioport_set_pin_dir(EXT2_PIN_6, IOPORT_DIR_OUTPUT); //DB3
        ioport_set_pin_dir(EXT2_PIN_10, IOPORT_DIR_OUTPUT); //DB4
        ioport_set_pin_dir(EXT3_PIN_5, IOPORT_DIR_OUTPUT); //DB5
        ioport_set_pin_dir(EXT3_PIN_6, IOPORT_DIR_OUTPUT); //DB6
        ioport_set_pin_dir(EXT3_PIN_10, IOPORT_DIR_OUTPUT); //DB7 <- Will need to change this to input later on (to check for busy signal).
       
}

void EightbitInit(void)
{
    //8-bit interface mode.
ioport_set_pin_level(EXT4_PIN_6,1); //Enable = 1;
     //Function Set
     ioport_set_pin_level(EXT3_PIN_15, 0); //RS = 0
     ioport_set_pin_level(EXT4_PIN_5, 0); //R/W = 0
    
     ioport_set_pin_level(EXT3_PIN_10,0); //DB7 = 0
     ioport_set_pin_level(EXT3_PIN_6,0); //DB6 = 0
     ioport_set_pin_level(EXT3_PIN_5,1); //DB5 = 1
     ioport_set_pin_level(EXT2_PIN_10,1); //DB4 = 1
     ioport_set_pin_level(EXT2_PIN_6,1); //DB3 = N =  1,  N = Numbers of display line (N:2-line/1-line)
     ioport_set_pin_level(EXT2_PIN_5,1); //DB2 = F =  1, F = Display font type (F:5*10 dots/5*7 dots)
    
     ioport_set_pin_level(EXT1_PIN_6,0); //DB1 = 0 (don't care)
     ioport_set_pin_level(EXT1_PIN_5,0); //DB0 = 0 (don't care)

ioport_set_pin_level(EXT4_PIN_6,0); //Enable = 0;    
     delay_us(50); //wait more than 39us //OK
    
ioport_set_pin_level(EXT4_PIN_6,1); //Enable = 1;
      //Display ON/OFF Control
               ioport_set_pin_level(EXT3_PIN_15,0); //RS = 0
               ioport_set_pin_level(EXT4_PIN_5,0); //R/W = 0
              
               ioport_set_pin_level(EXT3_PIN_10,0); //DB7 = 0
               ioport_set_pin_level(EXT3_PIN_6,0); //DB6 = 0
               ioport_set_pin_level(EXT3_PIN_5,0); //DB5 = 0
               ioport_set_pin_level(EXT2_PIN_10,0); //DB4 = 0
               ioport_set_pin_level(EXT2_PIN_6,1); //DB3 = 1
               ioport_set_pin_level(EXT2_PIN_5,1); //DB2 = D = 1, D = Set Display (ON)
              
               ioport_set_pin_level(EXT1_PIN_6,1); //DB1 = C = 1, C =  cursor on
               ioport_set_pin_level(EXT1_PIN_5,1); //DB0 = B = 1, Blinking  cursor (ON/OFF)- on.
              
ioport_set_pin_level(EXT4_PIN_6,0); //Enable = 0;         
          delay_us(50); //wait more than 39us //OK

ioport_set_pin_level(EXT4_PIN_6,1); //Enable = 1;         
          //Display clear
         
          ioport_set_pin_level(EXT3_PIN_15,0); //RS = 0
          ioport_set_pin_level(EXT4_PIN_5,0); //R/W = 0
         
          ioport_set_pin_level(EXT3_PIN_10,0); //DB7 = 0
          ioport_set_pin_level(EXT3_PIN_6,0); //DB6 = 0
          ioport_set_pin_level(EXT3_PIN_5,0); //DB5 = 0
          ioport_set_pin_level(EXT2_PIN_10,0); //DB4 = 0
          ioport_set_pin_level(EXT2_PIN_6,0); //DB3 = 0
          ioport_set_pin_level(EXT2_PIN_5,0); //DB2 = 0
         
          ioport_set_pin_level(EXT1_PIN_6,0); //DB1 = 0
          ioport_set_pin_level(EXT1_PIN_5,1); //DB0 = 1
         
     ioport_set_pin_level(EXT4_PIN_6,0); //Enable = 0;     
          delay_ms(2);
          //Entry mode set
ioport_set_pin_level(EXT4_PIN_6,1); //Enable = 1;
          
                ioport_set_pin_level(EXT3_PIN_15,0); //RS = 0
                ioport_set_pin_level(EXT4_PIN_5,0); //R/W = 0
               
                ioport_set_pin_level(EXT3_PIN_10,0); //DB7 = 0
                ioport_set_pin_level(EXT3_PIN_6,0); //DB6 = 0
                ioport_set_pin_level(EXT3_PIN_5,0); //DB5 = 0
                ioport_set_pin_level(EXT2_PIN_10,0); //DB4 = 0
                ioport_set_pin_level(EXT2_PIN_6,0); //DB3 = 0
                ioport_set_pin_level(EXT2_PIN_5,1); //DB2 = 1
               
                ioport_set_pin_level(EXT1_PIN_6,1); //DB1 = I/D = 1, Assign cursor moving direction. (increment/decrement) 
                ioport_set_pin_level(EXT1_PIN_5,1); //DB0 = S = 1, Enable the shift of entire display (entire shift off/entire shift on).
               
     ioport_set_pin_level(EXT4_PIN_6,0); //Enable = 0;
                  delay_us(50); //wait more than 39us
                 
                //initialization end.
         
}

void sendChar(void)
{
    ////////Do NOT NEED TO DO This stuff as I have already initialized the LCD Screen.
   
    //Function set.
    ioport_set_pin_level(EXT4_PIN_6,1); //Enable = 1;
     
     ioport_set_pin_level(EXT3_PIN_15, 0); //RS = 0
     ioport_set_pin_level(EXT4_PIN_5, 0); //R/W = 0
    
     ioport_set_pin_level(EXT3_PIN_10,0); //DB7 = 0
     ioport_set_pin_level(EXT3_PIN_6,0); //DB6 = 0
     ioport_set_pin_level(EXT3_PIN_5,1); //DB5 = 1
     ioport_set_pin_level(EXT2_PIN_10,1); //DB4 = 1
     ioport_set_pin_level(EXT2_PIN_6,1); //DB3 = N =  1,  N = Numbers of display line (N:2-line/1-line)
     ioport_set_pin_level(EXT2_PIN_5,0); //DB2 = F =  0, F = Display font type (F:5*11 dots/5*8 dots) (probably mean 5*10 dots and NOT 5*11 dots)
    
     ioport_set_pin_level(EXT1_PIN_6,0); //DB1 = 0 (don't care)
     ioport_set_pin_level(EXT1_PIN_5,0); //DB0 = 0 (don't care)
    
     ioport_set_pin_level(EXT4_PIN_6,0); //Enable = 0;
    
     delay_us(50); //wait more than 39us
   

     
      //Display ON/OFF Control
     
      ioport_set_pin_level(EXT4_PIN_6,1); //Enable = 1;
       
      ioport_set_pin_level(EXT3_PIN_15,0); //RS = 0
      ioport_set_pin_level(EXT4_PIN_5,0); //R/W = 0
     
      ioport_set_pin_level(EXT3_PIN_10,0); //DB7 = 0
      ioport_set_pin_level(EXT3_PIN_6,0); //DB6 = 0
      ioport_set_pin_level(EXT3_PIN_5,0); //DB5 = 0
      ioport_set_pin_level(EXT2_PIN_10,0); //DB4 = 0
      ioport_set_pin_level(EXT2_PIN_6,1); //DB3 = 1
      ioport_set_pin_level(EXT2_PIN_5,1); //DB2 = D = 1, D = Set Display
     
      ioport_set_pin_level(EXT1_PIN_6,1); //DB1 = C = 1, C =  cursor on
      ioport_set_pin_level(EXT1_PIN_5,0); //DB0 = B = 0, Blinking of cursor (ON/OFF) off.
     
        ioport_set_pin_level(EXT4_PIN_6,0); //Enable = 0;
       
       delay_us(50); //wait more than 39us
      
       //Entry mode set (increment)
       ioport_set_pin_level(EXT4_PIN_6,1); //Enable = 1;
        
       ioport_set_pin_level(EXT3_PIN_15,0); //RS = 0
       ioport_set_pin_level(EXT4_PIN_5,0); //R/W = 0
      
       ioport_set_pin_level(EXT3_PIN_10,0); //DB7 = 0
       ioport_set_pin_level(EXT3_PIN_6,0); //DB6 = 0
       ioport_set_pin_level(EXT3_PIN_5,0); //DB5 = 0
       ioport_set_pin_level(EXT2_PIN_10,0); //DB4 = 0
       ioport_set_pin_level(EXT2_PIN_6,0); //DB3 = 0
       ioport_set_pin_level(EXT2_PIN_5,1); //DB2 = 1
        ioport_set_pin_level(EXT1_PIN_6,1); //DB1 = I/D = 1 (increment/decrement)
       ioport_set_pin_level(EXT1_PIN_5,0); //DB0 = S = 0, Enable the shift of entire display (entire shift off/entire shift on).
      
       ioport_set_pin_level(EXT4_PIN_6,0); //Enable = 0;
        
       delay_us(50);
   
       //Write 'Hello World' in ASCII:
     
      //'H'
        ioport_set_pin_level(EXT4_PIN_6,1); //Enable = 1;
       
        ioport_set_pin_level(EXT3_PIN_15,1); //RS = 1 //Set the RS bit for writing into the data register.
        ioport_set_pin_level(EXT4_PIN_5,0); //R/W = 0
       
        ioport_set_pin_level(EXT3_PIN_10,0); //DB7 =0
        ioport_set_pin_level(EXT3_PIN_6,1); //DB6 = 1
        ioport_set_pin_level(EXT3_PIN_5,0); //DB5 = 0
        ioport_set_pin_level(EXT2_PIN_10,0);//DB4 = 0
        ioport_set_pin_level(EXT2_PIN_6,1); //DB3 = 1
        ioport_set_pin_level(EXT2_PIN_5,0); //DB2 = 0
        ioport_set_pin_level(EXT1_PIN_6,0); //DB1 = 0
        ioport_set_pin_level(EXT1_PIN_5,0); //DB0 = 0
      
         ioport_set_pin_level(EXT4_PIN_6,0); //Enable = 0;
   
    //'e'    
          ioport_set_pin_level(EXT4_PIN_6,1); //Enable = 1;
         
          ioport_set_pin_level(EXT3_PIN_15,1); //RS = 1 //Set the RS bit for writing into the data register.
          ioport_set_pin_level(EXT4_PIN_5,0); //R/W = 0
         
          ioport_set_pin_level(EXT3_PIN_10,0); //DB7 =0
          ioport_set_pin_level(EXT3_PIN_6,1); //DB6 = 1
          ioport_set_pin_level(EXT3_PIN_5,1); //DB5 = 1
          ioport_set_pin_level(EXT2_PIN_10,0);//DB4 = 0
          ioport_set_pin_level(EXT2_PIN_6,0); //DB3 = 0
          ioport_set_pin_level(EXT2_PIN_5,1); //DB2 = 1
          ioport_set_pin_level(EXT1_PIN_6,0); //DB1 = 0
          ioport_set_pin_level(EXT1_PIN_5,1); //DB0 = 1
         
          ioport_set_pin_level(EXT4_PIN_6,0); //Enable = 0;
        
}
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top