Sunday, January 28, 2024

XC95108 HD44780 8-BIT LCD Interfacing Example

The HD44780 is a character LCD controller developed by HITACHI during the 1980s. So fa it still a popular stuff for electronics hobbyists, especially the Arduino user. The micro-processor should interface with this LCD using its 8-bit data bus mode. But using the 4-bit data bus mode is common for most electronics designers.

XC95108 HD44780 8-BIT LCD Interfacing Example
Hardware Test on the XC95108 Prototype Board

A digital circuit also able to control this LCD module using a state machine model. If you are a beginner in digital electronics design you can see this post. In this VHLD example, I use an XC95108 CPLD to interface with this LCD controller using the 8-bit data transfer mode. The LCD is a 16x2 character LCD. It will show text on both lines of the LCD. The text should be "XC95108 CPLD" on the first line, and "VHDL Example" on the second line.

  1. ----------------------------------------------------------------------------------
  2. -- Company:
  3. -- Engineer:
  4. --
  5. -- Create Date: 13:36:50 01/28/2024
  6. -- Design Name:
  7. -- Module Name: lcd_control_1 - Behavioral
  8. -- Project Name:
  9. -- Target Devices:
  10. -- Tool versions:
  11. -- Description:
  12. --
  13. -- Dependencies:
  14. --
  15. -- Revision:
  16. -- Revision 0.01 - File Created
  17. -- Additional Comments:
  18. --
  19. ----------------------------------------------------------------------------------
  20. library IEEE;
  21. use IEEE.STD_LOGIC_1164.ALL;
  22.  
  23. -- Uncomment the following library declaration if using
  24. -- arithmetic functions with Signed or Unsigned values
  25. --use IEEE.NUMERIC_STD.ALL;
  26.  
  27. -- Uncomment the following library declaration if instantiating
  28. -- any Xilinx primitives in this code.
  29. --library UNISIM;
  30. --use UNISIM.VComponents.all;
  31.  
  32. entity lcd_control_1 is
  33. Port ( RST : in STD_LOGIC;
  34. CLK : in STD_LOGIC;
  35. RS : out STD_LOGIC;
  36. RW : out STD_LOGIC;
  37. EN : out STD_LOGIC;
  38. DB : out STD_LOGIC_VECTOR(7 DOWNTO 0));
  39. end lcd_control_1;
  40.  
  41. architecture Behavioral of lcd_control_1 is
  42. SIGNAL E: STD_LOGIC:='0';
  43. begin
  44.  
  45. RW<='0';
  46. -- CLOCK AND ENABLE SIGNAL PROCESS
  47. PROCESS(CLK,RST)
  48. VARIABLE COUNTER: INTEGER RANGE 0 TO 25175;
  49. BEGIN
  50. IF RST='0' THEN COUNTER:=0; EN<='0';
  51. ELSIF CLK'EVENT AND CLK='1' THEN
  52. COUNTER:=COUNTER+1;
  53. IF(COUNTER=25175) THEN E<=NOT E; END IF;
  54. EN<=E;
  55. END IF;
  56. END PROCESS;
  57.  
  58. -- LCD COMMAND AND DATA PROCESS
  59. PROCESS(E)
  60. VARIABLE COUNTER: INTEGER RANGE 0 TO 35;
  61. BEGIN
  62. IF RST='0' THEN COUNTER:=0; DB<=x"00"; RS<='0';
  63. ELSIF E'EVENT AND E='1' THEN
  64. COUNTER:=COUNTER+1;
  65. CASE COUNTER IS
  66. -- START UP DELAY
  67. WHEN 0 =>
  68. WHEN 1 =>
  69. WHEN 2 =>
  70. -- LCD COMMAND
  71. WHEN 3 => RS<='0'; DB<=x"38";
  72. WHEN 4 => RS<='0'; DB<=x"0F";
  73. WHEN 5 => RS<='0'; DB<=x"01";
  74. WHEN 6 => RS<='0'; DB<=x"06";
  75. WHEN 7 => RS<='0'; DB<=x"82";
  76. -- LCD DATA "XC95108 "
  77. WHEN 8 => RS<='1'; DB<=x"58";
  78. WHEN 9 => RS<='1'; DB<=x"43";
  79. WHEN 10 => RS<='1'; DB<=x"39";
  80. WHEN 11 => RS<='1'; DB<=x"35";
  81. WHEN 12 => RS<='1'; DB<=x"31";
  82. WHEN 13 => RS<='1'; DB<=x"30";
  83. WHEN 14 => RS<='1'; DB<=x"38";
  84. WHEN 15 => RS<='1'; DB<=x"20";
  85. -- LCD DATA "CPLD"
  86. WHEN 16 => RS<='1'; DB<=x"43";
  87. WHEN 17 => RS<='1'; DB<=x"50";
  88. WHEN 18 => RS<='1'; DB<=x"4C";
  89. WHEN 19 => RS<='1'; DB<=x"44";
  90. -- LCD COMMAND SECOND LINE POSITION 2
  91. WHEN 20 => RS<='0'; DB<=x"C2";
  92. -- LCD DATA "VHDL "
  93. WHEN 21 => RS<='1'; DB<=x"56";
  94. WHEN 22 => RS<='1'; DB<=x"48";
  95. WHEN 23 => RS<='1'; DB<=x"44";
  96. WHEN 24 => RS<='1'; DB<=x"4C";
  97. WHEN 25 => RS<='1'; DB<=x"20";
  98. -- LCD DATA "Example "
  99. WHEN 26 => RS<='1'; DB<=x"45";
  100. WHEN 27 => RS<='1'; DB<=x"78";
  101. WHEN 28 => RS<='1'; DB<=x"61";
  102. WHEN 29 => RS<='1'; DB<=x"6D";
  103. WHEN 30 => RS<='1'; DB<=x"70";
  104. WHEN 31 => RS<='1'; DB<=x"6C";
  105. WHEN 32 => RS<='1'; DB<=x"65";
  106. WHEN 33 => RS<='1'; DB<=x"20";
  107.  
  108. WHEN 34 => RS<='0'; DB<=x"00";
  109. WHEN OTHERS => COUNTER:=34;
  110. END CASE;
  111. END IF;
  112. END PROCESS;
  113. end Behavioral;
  114.  
  115.  

The on-board oscillator is 25.175MHz. So I need to add a VHDL clock divider circuit to get a 1kHz signal.

XC95108 HD44780 8-BIT LCD Interfacing Example
The on-board oscillator is 25.175MHz

Data or command are latched into the LCD controller from logic high low. So at the high logic level the circuit starts send data or command to the LCD. Then they will be latched into the LCD at the up coming logic low.

XC95108 HD44780 8-BIT LCD Interfacing Example
Main CPLD Prototype Board Block
XC95108 HD44780 8-BIT LCD Interfacing Example
Character LCD and Oscillator

The user's constraints for I/O pins is listed below. 

#PACE: Start of Constraints generated by PACE
#PACE: Start of PACE I/O Pin Assignments
NET "CLK"  LOC = "P9"  ;
NET "DB<0>"  LOC = "P2"  ;
NET "DB<1>"  LOC = "P1"  ;
NET "DB<2>"  LOC = "P84"  ;
NET "DB<3>"  LOC = "P83"  ;
NET "DB<4>"  LOC = "P82"  ;
NET "DB<5>"  LOC = "P81"  ;
NET "DB<6>"  LOC = "P80"  ;
NET "DB<7>"  LOC = "P79"  ;
NET "EN"  LOC = "P3"  ;
NET "RS"  LOC = "P5"  ;
NET "RST"  LOC = "P40"  ;
NET "RW"  LOC = "P4"  ;

#PACE: Start of PACE Area Constraints
#PACE: Start of PACE Prohibit Constraints
#PACE: End of Constraints generated by PACE

This digital circuit design uses 35 macro cells and 51 Function Block.

XC95108 HD44780 8-BIT LCD Interfacing Example
XC95108 CPLD Reports

Using a Xilinx Parallel Cable III or IV is suitable for device programming in the Xilinx ISE Design Suite 14.7.

XC95108 HD44780 8-BIT LCD Interfacing Example
Device Programming Using a Xilinx Parallel Cable IV JTAG


Click here to download its source file.


No comments:

Post a Comment

Labels

ADC (10) Analog (14) Arduino (12) Atmega16 (19) Audio (2) AVR (20) Charger (1) Cortex-M0 (1) Counter (10) CPLD (25) Digital I/O (22) Display (34) EEPROM (2) Environment Sensor (1) esp8266 (2) Experiment Board (10) I2C (4) Interrupt (7) LCD (1) LDmicro (29) measurement and instrumentation (7) Microchip Studio (3) MikroC (1) One-Shot (3) OpAmp (1) PCB (31) PIC16 Microcontrollers (16) PIC16F877A (2) PIC16F887 MikroC (22) PLC (35) PWM (11) Regulator (1) RTC (2) Sensor (8) Shift Registers (5) SPI (5) Timer (34) UART (2) ultra-sonic sensor (1) USB (1) VHDL (21) xc8 (1) XC95108 (9) XC9536 (15) XC9572 (1) Xilinx (23) Xilinx ISE (22)