Sunday, December 17, 2023

XC9536 CPLD HD44780 8-Bit LCD Interfacing Example Using VHDL

Character LCD interfacing is very popular among electronics hobbyists. Using a minimum 8-bit microcontroller with Assembly language programming is very common. This simple 8-bit HD44780 character LCD can be tested manually by applying digital logic inputs by switches without using any controller.







Some electronics practitioners use a digital circuit created by some digital logic chips to control this character LCD. Similarly a Programmable Logic Device (PLD) can replace that complex digital electronics circuit. We can use schematic design or even an easier VHDL or Verilog coding to design an LCD interface circuit that will run on any CPLD or FPGA.

XC9536 CPLD HD44780 8-Bit LCD Interfacing Example Using VHDL
VHDL Code Testing on an experiment board

In this VHDL example, I use an old simple Complex Programmable Logic Device (CPLD) to create a digital electronics circuit inside to interface with a HD44780 based character LCD module.  

Using a Finite State Machine (FSM) model is very common this task. However I didn't follow all of this FSM model. I use a counter to activate each steps of data transfer between CPLD and LCD module.

An on-board 60Hz square wave oscillator is needed to active the circuit. LCD data and command are sequentially send to the LCD. It activated only at the high logic level of Enable (EN) output pin.

I use a low cost Chinese JHD162A LCD module. It costs around 2USD at local store.

XC9536 CPLD HD44780 8-Bit LCD Interfacing Example Using VHDL
JHD162A LCD Module Interfacing Pins

The following VHDL codes will show a "VHDL XC9536" message on a character LCD. Then it will stop transferring data.

  1. ----------------------------------------------------------------------------------
  2. -- Company:
  3. -- Engineer:
  4. --
  5. -- Create Date: 16:57:52 12/16/2023
  6. -- Design Name:
  7. -- Module Name: lcd_8 - 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_8 is
  33. Port ( CLK : in STD_LOGIC;
  34. RST : in STD_LOGIC;
  35. RS : out STD_LOGIC;
  36. EN : out STD_LOGIC;
  37. DB : out STD_LOGIC_VECTOR (7 downto 0));
  38. end lcd_8;
  39.  
  40. architecture Behavioral of lcd_8 is
  41. signal E : STD_LOGIC:='0';
  42. begin
  43. clock: process(CLK,RST)
  44. variable ticks: INTEGER RANGE 0 TO 32:=0;
  45. begin
  46. if(RST='0') then ticks:=0; E<='0';
  47. elsif(CLK'EVENT AND CLK='1') then
  48. if(ticks<32) then
  49. ticks:=ticks+1;
  50. E<=E XOR '1';
  51. EN<=E;
  52. end if;
  53. end if;
  54. end process clock;
  55.  
  56. process(E)
  57. variable temp : INTEGER RANGE 0 TO 16;
  58. begin
  59. if(RST='0') then temp:=0; DB<=x"00";
  60. elsif(E'EVENT AND E='1') then
  61. temp:=temp+1;
  62. CASE temp IS
  63. WHEN 0 => RS<='0'; DB<=x"38"; -- 5x7 Two Lines
  64. WHEN 1 => RS<='0'; DB<=x"0F"; -- LCD On Cursor Blink
  65. WHEN 2 => RS<='0'; DB<=x"01"; -- Clear Screen
  66. WHEN 3 => RS<='0'; DB<=x"06"; -- LCD Shift Cursor Right
  67. ----------------------------------
  68. WHEN 4 => RS<='1'; DB<=x"56"; -- V
  69. WHEN 5 => RS<='1'; DB<=x"48"; -- H
  70. WHEN 6 => RS<='1'; DB<=x"44"; -- D
  71. WHEN 7 => RS<='1'; DB<=x"4C"; -- L
  72. WHEN 8 => RS<='1'; DB<=x"20"; -- SPACE
  73. WHEN 9 => RS<='1'; DB<=x"58"; -- X
  74. WHEN 10 => RS<='1'; DB<=x"43"; -- C
  75. WHEN 11 => RS<='1'; DB<=x"39"; -- 9
  76. WHEN 12 => RS<='1'; DB<=x"35"; -- 5
  77. WHEN 13 => RS<='1'; DB<=x"33"; -- 3
  78. WHEN 14 => RS<='1'; DB<=x"36"; -- 6
  79. WHEN 15 => RS<='1'; DB<=x"20"; -- SPACE
  80. WHEN 16 => RS<='1'; DB<=x"20"; -- SPACE
  81. WHEN OTHERS => NULL;
  82. END CASE;
  83. end if;
  84. end process;
  85. end Behavioral;
  86.  
  87.  

Don't forget to assign its I/O pins. The LCD 8-bit data bus shares with on-board LEDs.

XC9536 CPLD HD44780 8-Bit LCD Interfacing Example Using VHDL
Xilinx PACE Tool - I/O Pin Assignments

We will need to run the Implement Design again to wire its I/O pins. We will see its CPLD Reports.

XC9536 CPLD HD44780 8-Bit LCD Interfacing Example Using VHDL
CPLD Reports

If you have a Desktop computer with a legacy parallel port we can use a Xilinx Parallel Cable III JTAG to program this CPLD. However a modern USB JTAG is currently widely used with an affordable price. A USB JTAG cable is very stable to use than a legacy one's.


Click here to download its VHDL, UCF, and JED files.

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)