News:

;) This forum is the property of Proton software developers

Main Menu

SPI I/O expander – For LCD display, MCP23S17

Started by Yves, Sep 19, 2022, 08:05 AM

Previous topic - Next topic

Yves

Anyone has a driver for the MCP23S17 to drive a LCD 2 by 16? I have the PICDEM™ PIC18 Explorer and I'm batteling to display anything.
https://www.microchip.com/en-us/development-tool/DM183032
Regards,

Yves
Yves

normnet

A 12-22-2012 post by pic-ignorant: SPi Control of MCP23S17 Port expander

Device = 16F887
Xtal 8
Declare Reminders Off
@ CONFIG_REQ = 0 ; Override Compiler's configuration settings
Asm-
__Config _Config1, 0x28D4 ;FOSC_INTRC_NOCLKOUT & WDTE_OFF & PWRTE_OFF & MCLRE_OFF & CP_OFF & CPD_OFF & BOREN_OFF & IESO_OFF & FCMEN_ON & LVP_OFF & DEBUG_OFF
__Config _Config2, 0x3FFF ;BOR4V_BOR40V & WRT_OFF
Endasm-
Declare Reminders On
PortB_Pullups FALSE
'SET UP PIC's INTERNAL OSCILLATOR FOR 8 MHZ (IF EXTERNAL XTAL NOT USED)-
OSCCON.4 =1
OSCCON.5 =1
OSCCON.6 =1
'SET UP PORT DIRECTION
'*NOTE* THE PORT DIRECTION OF THE SDI PIN IS CONTROLLED BY THE SPI MODULE,SDO & SCK MUST BE CLEARED IN TRIS REG
TRISA = %11110011
TRISB = %11111100
TRISC = %00010111
TRISD = %00001100
TRISE = %00000111
'SET UP A/D FOR ALL PINS DIGITAL
ADCON1 = %10000000 ' Left justify result, Volt Ref VDD & VSS
ANSEL = %00000000 ' AN0 - AN7 DIGITAL
ANSELH = %00000000 ' AN8 - AN12 DIGITAL
'DISABLE COMPARATORS
CM1CON0 = %00000000 ' COMPARATOR MODULE OFF
CM2CON0 = %00000000 ' COMPARATOR MODULE OFF
'SET UP EASYPIC 6 LCD (IF USED)
Float_Display_Type = Fast
Declare LCD_DTPin PORTB.0
Declare LCD_ENPin PORTB.5
Declare LCD_RSPin PORTB.4
Declare LCD_Lines 2
Declare LCD_Type ALPHA
DelayMS 100
Cls
'SET UP MSSP MODULE FOR SPI
'****READ THE DATASHEET. SSPCON AND SSPSTAT NEED TO BE SET CORRECTLY IF USING HARDWARE SPI*****
SSPSTAT = 0x80 ' INPUT DATA SAMPLED AT THE END OF DATA OUTPUT TIME
SSPCON = 0x31 ' SSP ENABLED,CLOCK IDLE STATE = HIGH, SPI MASTER MODE, CLOCK = FOSC/16
'SOME OF THE MCP23S17 PORT EXPANDER REGISTERS
Symbol MCPWRITE = 0x40 'OPCODE IN WRITE MODE
Symbol MCPREAD = 0x41 'OPCODE IN READ MODE
Symbol IOCON = 0x0A 'CONTROL REGISTER
Symbol IODIRA = 0x00 'PORTA TRIS
Symbol IODIRB = 0x01 'PORTB TRIS
Symbol GPIOA = 0x12 'PORTA GENERAL I/O REGISTER
Symbol GPIOB = 0x13 'PORTB GENERAL I/O REGISTER
Symbol OLATA = 0x14 'PORTA LATCH
Symbol OLATB = 0x15 'PORTB LATCH
Symbol GGPUA = 0x0C 'PORTA PULLUP CONTROL REGISTER
Symbol GPPUB = 0x0D 'PORTB PULLUP CONTROL REGISTER
'MCP23S17 CONTROL PINS
Symbol EXP_CS = PORTA.2 'CONTROLS MCP23S17 CHIP SELECT PIN
Symbol RST = PORTA.3 'CONTROLS MCP23S17 RESET PIN
'MCP23S17 SSP INTERRUPT FLAG
Symbol SSP1IF = PIR1.3 'SSP INTERRUPT FLAG
'GENERAL VARIABLES
Dim DataOut As Byte
Dim DataIn As Byte
Dim GPIOA_DATA As Byte
Dim GPIOB_DATA As Byte
Dim MCPREG As Byte
Dim A As Byte
DelayMS 100 'ALLOW PIC TO SETTLE
EXP_CS = 1 'PULL CHIP SELECT HIGH TO DISABLE
GoSub INIT 'SET UP PORT DIRECTION ETC ON MCP23S17
MAIN:
MCPREG = GPIOA 'TARGET PORTA ON MCP23S17
DataOut = %01010101 'LOAD VARIABLE WITH DATA TO WRITE TO PORTA
GoSub SEND_DATA 'GOSUB WRITE DATA ROUTINE
MCPREG =GPIOB 'TARGET PORTB ON MCP23S17
DataOut = %10101010 'LOAD VARIABLE WITH DATA TO WRITE TO PORTB
GoSub SEND_DATA 'GOSUB MCP23S17 WRITE DATA ROUTINE
DelayMS 100
MCPREG = GPIOA 'TARGET PORTA ON MCP23S17
DataOut = %10101010 'LOAD VARIABLE WITH DATA TO WRITE TO PORTA
GoSub SEND_DATA 'GOSUB WRITE DATA ROUTINE
DelayMS 100
MCPREG =GPIOB 'TARGET PORTB ON MCP23S17
DataOut = %01010101 'LOAD VARIABLE WITH DATA TO WRITE TO PORTB
GoSub SEND_DATA 'GOSUB MCP23S17 WRITE DATA ROUTINE
DelayMS 100 'SMALL DELAY SO THE CHANGES ARE VISIBLE TO THE EYE
 
GoTo MAIN 'LOOP CONTINUALLY
 
INIT:'INITIALIZE THE MCP23S17
EXP_CS = 0 'PULL CHIP SELECT LOW TO ENABLE
DelayUS 1 '1 INSTRUCTION CYCLE DELAY
MCPREG = IOCON 'TARGET IOCON REG
DataOut = 0x20 'SEQUENTIAL OPERATION DISABLED
GoSub SEND_DATA 'GOSUB MCP23S17 WRITE DATA ROUTINE
MCPREG = IODIRA 'TARGET PORTA TRIS
DataOut = 0x00 'SET ALL TO OUTPUTS
GoSub SEND_DATA 'GOSUB MCP23S17 WRITE DATA ROUTINE
MCPREG = IODIRB 'TARGET PORTB TRIS
DataOut = 0x00 'SET ALL TO OUTPUTS
GoSub SEND_DATA 'GOSUB MCP23S17 WRITE DATA ROUTINE
MCPREG = GPPUB 'TARGET PORTB PULLUP REG
DataOut = 0x00 'SET ALL PORTB PULLUPS OFF
GoSub SEND_DATA 'GOSUB MCP23S17 WRITE DATA ROUTINE
EXP_CS = 1 'PULL CHIP SELECT HIGH TO DISABLE
Return
'************************************************************
'************************************************************
SEND_DATA: 'SENDS DATA OUT ON SELECTED REGISTER
EXP_CS = 0 'PULL CHIP SELECT LOW TO ENABLE MCP23S17
DelayUS 1 '1 INSTRUCTION CYCLE DELAY
SSP1IF = 0 'CLEAR SSP INTERRUPT FLAG SO READY TO READ AGAIN
SSPBUF = 0x40 'SET OPCODE TO WRITE MODE: CHIP ADDR = 000
Repeat '
Until SSP1IF = 1 'WAIT FOR BUFFER WRITE TO COMPLETE
SSP1IF = 0 'CLEAR SSP INTERRUPT FLAG SO READY TO READ AGAIN
SSPBUF = MCPREG 'POINT TO SELECTED REGISTER
Repeat
Until SSP1IF = 1 'WAIT FOR BUFFER WRITE TO COMPLETE
SSP1IF = 0 'CLEAR SSP INTERRUPT FLAG SO READY TO READ AGAIN
SSPBUF = DataOut 'DATA TO BE SENT TO OLATA
Repeat
Until SSP1IF = 1 'WAIT FOR BUFFER WRITE TO COMPLETE
EXP_CS = 1 'PULL CHIP SELECT HIGH TO DISABLE
Return
'************************************************************
'************************************************************
RECEIVE_DATA:
EXP_CS = 0 'PULL CHIP SELECT LOW TO ENABLE
DelayUS 1 '1 INSTRUCTION CYCLE DELAY
SSP1IF = 0 'CLEAR SSP INTERRUPT FLAG SO READY TO READ AGAIN
SSPBUF = 0x41 'SET OPCODE TO READ MODE 'CHIP ADDR = 000'
Repeat
Until SSP1IF = 1 'WAIT FOR BUFFER WRITE TO COMPLETE
SSP1IF = 0 'CLEAR SSP INTERRUPT FLAG SO READY TO READ AGAIN
SSPBUF = MCPREG 'POINT TO GPIOB REGISTER
Repeat
Until SSP1IF = 1 'WAIT FOR BUFFER WRITE TO COMPLETE
SSP1IF = 0 'CLEAR FLAG
SSPBUF = 0x00 'FEED A BYTE IN TO PUSH THE DATA OUT
Repeat
Until SSP1IF = 1 'WAIT FOR BUFFER WRITE TO COMPLETE
DataIn = SSPBUF 'DATA RECEIVED FROM GPIOB REGISTER
EXP_CS = 1 'PULL CHIP SELECT PIN HIGH TO DISABLE
DelayMS 100
Return

Yves

Thank you Normnet.
I will try to adapt the code for the on board  PIC18F8722 microcontroller.

Regards,

Yves
Yves

Yves

#3
Hello Normnet,

I'm trying to understand your code to address the MCP23S17 but I failed to understand the connections to adapt to the on board connections. I have modified the fuses to adapt to the chip that is on board of the PICDEM™ PIC18 EXPLORER DEMONSTRATION BOARD
The device I use is 18F8722 and the connections are as follow:

RA2 for CS
RC3 for SCK
RC5 for SI
RF6 for Reset

Also what code I have to use to send text to the LCD? Excuse my ignorance and many thanks for your help.

Regards,

Yves

Yves

normnet

#4
pic-ignorant may be able to assist with pin-outs as he is the author.  I'm not sure if he is still on the forum however.

Attached is another MC23S17 program by Les.  Also found in samples.

Dompie

Pic-ignorant Last active:March 14, 2021, 19:41:49, so I'm afraid he isn't activ on the forum anymore.

Johan

Yves

I'm still don't have something that works for me to address the MCP23S17 to print text to a 2 by 16 simple LCD. The MCP23S17   is a SPI orientated and I thought it is addressed with conventional Shout commands which I do understand. As per picture I sent above it is connected on the 8 data pins and the usual RS and E pins. It doesn't matter the processor for an example, I can change the the pins in the code an adapt it. It is the mechanism to address the LCD I don't really understand.
Is anyone can give me a push start on this? Many thanks in advance.

Regards,

Yves
 
Yves

trastikata

If you have 4 spare pins, you can drive the 2x16 LCD with only 4 data lines.

RGV250

Hi,
I hope this is not a silly question but have you looked at the code example for the board? It is well documented and looks like it should convert to Positron quite easily.

Bob

Yves

Yes I did but it is in assembly and I had a look at it but it is like Chinese for me, that is why I love Positron coding. The only thing I need is to access the LCD. The rest it is easy.

Yves
Yves

RGV250

Hi,
I do not know where you got those files from, I was looking at these.
It is written in C which should not be that difficult to convert, have a look and come back if there is anything you need to know. I am no expert but I have done it a few times.
The comments are different in Positron, a lot of it is junk that you don't need in Positron as it is taken care of for you.
Void is a subroutine, you could probably turn those into procedures. Once you get going you will be surprised how quickly you can do it, most is repetitive. I would first change all the comments by adding "'"
 
C file
/*******************************************************************************************
* FileName:        BBSPI_LCD.c
* Dependencies:    See INCLUDES section below
* Processor:       PIC18F8722 and PIC18F87J11 on PICDEM PIC18 Explorer
* Compiler:        XC8
* Version:         1.34
* Company:         Microchip Technology, Inc.
********************************************************************************************
*   PICDEM PIC18 Explorer Setup Details
*
*   LCD Module on PICDEM PIC18 Explorer is LCM-S01602DTR/M
*   Display controller is based on the Hitachi 44780U
*   Display is 16 characters x 2 lines; 5x7 dot resolution w/ cursor or 5x8 w/o cursor
*   Parallel I/O Expander for SPI interface is MCP23S17
*********************************************************************************************
*   LCD interface on PICDEM PIC18 Explorer board:
*
*   Control/Power Lines to LCD Module
*   MCP23S17 PORTA7 = RS        : LCD Register Select, (Instruction Reg = 0; Data Reg = 1)
*   MCP23S17 PORTA7 = LCD EN    : LCD enable signal
*   R/W = GND (0)               : Data Write only
*   Vdd = +5                    : LCM-S01602DTR/M Specification for Vdd
*   Vss = GND (0)               : LCM-S01602DTR/M Specification for Vss
*
*   Data lines for LCD Module
*   MCP23S17 PORTB<7:0> = LCD D<7:0>
*********************************************************************************************
*   SPI (Master) interface to MCP23S17 (Slave):
*
*   RA2       = CS              : MCP23S17 Chip Select
*   RC5/SD01  = SI              : MCP23S17 Serial Data Input
*   RC3/SCK1  = SCK             : MCP23S17 Serial Clock Input
*   RF6       = RESET           : MCP23S17 Hardware Reset
*********************************************************************************************/

#include "BBSPI_LCD.h"

/*******************************************************************
* FUNCTION:     LCDInit ()
* INPUTS:       None
* OUTPUTS:      None
* DESCRIPTION:  Initialize the LCD
********************************************************************/

void LCDInit (void)
{
    InitBBSPI();                    // initialize SPI
    LCD_RST_TRIS = 0;               // set RF6 as output to control RESET pin
    LCD_RST = 0;                    // reset MCP23S17
    __delay_ms(LCD_delay);
    LCD_RST = 1;
    Port_BBSPIInit (PORTA_DIR);     // initialize MCP23S17 PORTA
    Port_BBSPIInit (PORTB_DIR);     // initialize MCP23S17 PORTB
    WritePort_BBSPI (PORTA_ADD, 0);
    __delay_ms(LCD_Startup);        // required by display controller to allow power to stabilize
    LCDPutInst(0x32);               // required by display initialization
    LCDPutInst(FUNCTION_SET);       // set interface size, # of lines and font
    LCDPutInst(DISPLAY_SETUP);      // turn on display and sets up cursor
    mLCD_CLEAR;                     // clear the display
    LCDPutInst(ENTRY_MODE);         // set cursor movement direction
}

/*******************************************************************
* FUNCTION:     InitBBSPI ()
* INPUTS:       None
* OUTPUTS:      None
* DESCRIPTION:  Initialize I/O Ports for Bit Bang SPI
********************************************************************/

void InitBBSPI (void)
{
    LCD_CS_TRIS = 0;      // make the CS pin an output
    LCD_DIN_TRIS = 1;     // make the DIN pin an input
    LCD_DOUT_TRIS = 0;    // make the DOUT pin an output
    LCD_SCLK_TRIS = 0;    // make the SCLK pin an output

    LCD_CS = 1;           // raise the CS pin
    LCD_DIN = 1;          // set the DIN pin
    LCD_DOUT = 0;         // clear the DOUT pin
    LCD_SCLK = 0;         // clear the SCLK pin
}

/*******************************************************************
* FUNCTION:     SendByteBBSPI ()
* INPUTS:       output = byte to be transmitted
* OUTPUTS:      None
* DESCRIPTION:  Outputs a byte through the set DOUT pin
*               and receives dummy data through the DIN pin
********************************************************************/

void SendByteBBSPI (unsigned char output)
{
    unsigned char bitcount;
    unsigned char input = output;
   
    for(bitcount=0;bitcount<8;bitcount++)
    {
       // transmit data MSB
        if(output & 0x80)                // condition if transmit byte MSB is 1
            LCD_DOUT = 1;                // make SDO pin output high
        else                             // condition if byte MSB is 0
            LCD_DOUT = 0;                // make SDO pin output low
        // receive dummy data
        if (LCD_DIN)                     // condition if receive byte MSB is 1
            input = (input << 1) | 0x1;  // shift input 1 bit to the left and move carry bit to LSB
        else                             // condition if receive bit is 0
            input = input << 1;          // shift input 1 bit to the left
        LCD_SCLK = 1;                           // set the SCLK pin
        NOP();NOP();NOP();NOP();NOP();NOP();    // produces ~50% duty cycle clock
        NOP();NOP();NOP();NOP();NOP();NOP();
        LCD_SCLK = 0;                           // clear the SCLK pin
        output <<= 1;                           // shift output 1 bit to the left
    }
}

/*******************************************************************
* FUNCTION:     Port_BBSPIInit ()
* INPUTS:       port_dir = address of IODIRx
* OUTPUTS:      None
* DESCRIPTION:  Initialize MCP923S17 Portx as output
********************************************************************/

void Port_BBSPIInit (unsigned char port_dir)
{
    // IOCON.BANK POR/RST Value = 0
    // Sequence = Device Opcode + Register Address + 1 Data Byte

    LCD_CS = 0;                 // lower CS to initialize SPI write operation on MCP923S17
    SendByteBBSPI(0x40);        // transmit device opcode (slave address and write enable)
    SendByteBBSPI(port_dir);    // point to address of IODIRx(I/O Direction register of PORTx)
    SendByteBBSPI(0x00);        // set all PORTx pins as output
    LCD_CS = 1;                 // end sequence
}

/*******************************************************************
* FUNCTION:     WritePort_BBSPI ()
* INPUTS:       port_add = address of GPIOx
*               a = instruction register or data register
* OUTPUTS:      None
* DESCRIPTION:  Writes to PORTx and selects between data and instruction
*               register
********************************************************************/

void WritePort_BBSPI (unsigned char port_add, unsigned char a)
{
    LCD_CS = 0;                 // lower CS to initialize SPI write operation on MCP923S17
    SendByteBBSPI(0x40);        // transmit device opcode (slave address and write enable)
    SendByteBBSPI(port_add);    // point to address of GPIOx (General Purpose I/O of PORTx)
    SendByteBBSPI(a);           // write value to GPIOx
    LCD_CS = 1;                 // end sequence
}

/*******************************************************************
* FUNCTION:     LCDPutChar ()
* INPUTS:       ch = character to send
* OUTPUTS:      None
* DESCRIPTION:  Writes character to LCD at current cursor position
********************************************************************/

void LCDPutChar (unsigned char ch)
{
    __delay_ms(LCD_delay);
    WritePort_BBSPI (PORTA_ADD, data);        // prepare to send data to LCD
    __delay_ms(1);
    WritePort_BBSPI (PORTB_ADD, ch);          // write the character to be displayed
    __delay_ms(1);
    WritePort_BBSPI (PORTA_ADD, send_data);   // send data to LCD
    __delay_ms(1);
    WritePort_BBSPI (PORTA_ADD, 0x00);        // stop sending data to LCD
}

/*******************************************************************
* FUNCTION:     LCDPutInst ()
* INPUTS:       ch = character to send
* OUTPUTS:      None
* DESCRIPTION:  Writes character to LCD instruction register
*******************************************************************/

void LCDPutInst (unsigned char ch)
{
    __delay_ms(LCD_delay);
    WritePort_BBSPI (PORTA_ADD, instr);       // prepare to send instruction to LCD
    __delay_ms(1);
    WritePort_BBSPI (PORTB_ADD, ch);          // write the instruction to be sent to LCD
    __delay_ms(1);
    WritePort_BBSPI (PORTA_ADD,send_instr);   // send instruction to LCD
    __delay_ms(1);
    WritePort_BBSPI (PORTA_ADD, 0x00);        // stop sending instruction to LCD
}

/*******************************************************************
* FUNCTION:     LCDPutStr ()
* INPUTS:       *ptr = Pointer to string to send
* OUTPUTS:      None
* DESCRIPTION:  Writes string to LCD at current cursor position
*******************************************************************/

void LCDPutStr (const char *ptr)
{
    while(*ptr) LCDPutChar(*(ptr++));
}

H file
/*
 * File:   BBSPI_LCD.h
 * Author: A16026
 *
 * Created on April 13, 2015, 2:11 PM
 */

#ifndef BBSPI_LCD_H
#define BBSPI_LCD_H

#ifdef __cplusplus
extern "C" {
#endif

#include "mcc_generated_files/mcc.h"

// set up the timing for the LCD delays
//#define _XTAL_FREQ 10000000                                  // device clock frequency (_XTAL_FREQ) used by XC8 for __delay_ms()
#define LCD_delay           5                                // ~5mS
#define LCD_Startup         15                               // ~15mS

// Command set for LCD display controller
#define LCD_CLEAR           0x01
#define LCD_HOME            0x02
#define LCD_CURSOR_BACK     0x10
#define LCD_CURSOR_FWD      0x14
#define LCD_PAN_LEFT        0x18
#define LCD_PAN_RIGHT       0x1C
#define LCD_CURSOR_OFF      0x0C
#define LCD_CURSOR_ON       0x0E
#define LCD_CURSOR_BLINK    0x0F
#define LCD_CURSOR_LINE1    0x80
#define LCD_CURSOR_LINE2    0xC0

// Macros recommended for new labs
#define mOPEN_LCD           LCDInit()
#define mLCD_PAN_RIGHT      LCDPutInst(LCD_PAN_RIGHT)
#define mLCD_PAN_LEFT       LCDPutInst(LCD_PAN_LEFT)
#define mLCD_CURSOR_BLINK   LCDPutInst(LCD_CURSOR_BLINK)
#define mLCD_HOME           LCDPutInst(LCD_HOME)
#define mLCD_CLEAR          LCDPutInst(LCD_CLEAR)

#define mCURSOR_ON          LCDPutInst(LCD_CURSOR_ON)
#define mCURSOR_OFF         LCDPutInst(LCD_CURSOR_OFF)
#define mCURSOR_FWD         LCDPutInst(LCD_CURSOR_FWD)
#define mCURSOR_BACK        LCDPutInst(LCD_CURSOR_BACK)
#define mCURSOR_LINE1       LCDPutInst(LCD_CURSOR_LINE1)
#define mCURSOR_LINE2       LCDPutInst(LCD_CURSOR_LINE2)

// Macro definitions specific to XC8 (not recommended for new code)
#define text_display        LCDPutStr                       // legacy support
#define LCDLine1()          LCDPutInst(LCD_HOME)            // legacy support
#define LCDLine2()          LCDPutInst(LCD_CURSOR_LINE2)    // legacy support
#define shift_cursor()      LCDPutInst(LCD_CURSOR_FWD)      // legacy support
#define cursor_on()         LCDPutInst(LCD_CURSOR_ON)       // legacy support
#define DisplayClr()        LCDPutInst(LCD_CLEAR)           // Legacy support

// Function prototypes

/**
* @FUNCTION     LCDInit()
* @INPUTS       None
* @OUTPUTS      None
* @DESCRIPTION  Initialize the LCD
*/

    void LCDInit(void);

/**
* @FUNCTION     InitBBSPI()
* @INPUTS       None
* @OUTPUTS      None
* @DESCRIPTION  Initialize I/O Ports for Bit Bang SPI
*/

    void InitBBSPI (void);

/**
* @FUNCTION     SendByteBBSPI
* @INPUTS       output = byte to be transmitted
* @OUTPUTS      None
* @DESCRIPTION  Outputs a byte through the set DOUT pin and receives dummy data through the DIN pin
*/

    void SendByteBBSPI (unsigned char output);

/**
* @FUNCTION     Port_BBSPIInit()
* @INPUTS       port_dir = address of IODIRx
* @OUTPUTS      None
* @DESCRIPTION  Initialize MCP923S17 Portx as output
*/

    void Port_BBSPIInit (unsigned char port_dir);

/**
* @FUNCTION     WritePort_BBSPI()
* @INPUTS       port_add = address of GPIOx;
*               a = instruction register or data register
* @OUTPUTS      None
* @DESCRIPTION  Writes to PORTx and selects between data and instruction register
*/

    void WritePort_BBSPI (unsigned char port_add, unsigned char a);

/**
* @FUNCTION     LCDPutChar()
* @INPUTS       ch = character to send
* @OUTPUTS      None
* @DESCRIPTION  Writes character to LCD at current cursor position
*/

    void LCDPutChar(unsigned char);

/**
* @FUNCTION     LCDPutInst()
* @INPUTS       ch = character to send
* @OUTPUTS      None
* @DESCRIPTION  Writes character to LCD instruction register
*/

    void LCDPutInst(unsigned char);

/**
* @FUNCTION     LCDPutStr()
* @INPUTS       *ptr = Pointer to string to send
* @OUTPUTS      None
* @DESCRIPTION  Writes string to LCD at current cursor position
*/

    void LCDPutStr(const char *);                                     

// Common legacy macros
#define LCDHome()           LCDPutInst(LCD_HOME)            // legacy support
#define LCDClr()            LCDPutInst(LCD_CLEAR)           // legacy support
#define LCDPutChar          LCDPutChar                      // legacy support

#define PORTA_DIR               0x00        // I/O Direction register of PORTA
#define PORTB_DIR               0x01        // I/O Direction register of PORTB
#define PORTA_ADD               0x12        // address of General Purpose I/O of PORTA
#define PORTB_ADD               0x13        // address of General Purpose I/O of PORTB

// Display controller setup commands
#define FUNCTION_SET        0x3C                         // 8 bit interface, 2 lines, 5x8 font
#define ENTRY_MODE          0x06                         // increment mode
#define DISPLAY_SETUP       0x0C                         // display on, cursor off, blink offd

//----------------------------------------------------------------------
// Definitions specific to the PICDEM PIC18 Explorer
//----------------------------------------------------------------------

// selecting between instruction register or data register
#define instr        0x00
#define data         0x80

// to send instruction or data to LCD
#define send_instr   0x40
#define send_data    0xC0

// These #defines create the pin connections to the LCD in case they are changed on a future demo board
#define LCD_CS          LATAbits.LATA2          //LCD chip select
#define LCD_CS_TRIS     TRISAbits.TRISA2        //LCD chip select
#define LCD_RST         LATFbits.LATF6          //LCD hardware reset
#define LCD_RST_TRIS    TRISFbits.TRISF6        //LCD hardware reset
#define LCD_DOUT        LATCbits.LATC5          //Serial Data Output pin
#define LCD_DOUT_TRIS   TRISCbits.TRISC5        //Serial Data Output pin
#define LCD_DIN         LATCbits.LATC4          //Serial Data Input pin
#define LCD_DIN_TRIS    TRISCbits.TRISC4        //Serial Data Input pin
#define LCD_SCLK        LATCbits.LATC3          //Serial Clock pin
#define LCD_SCLK_TRIS   TRISCbits.TRISC3        //Serial Clock pin


#ifdef __cplusplus
}
#endif

#endif /* BBSPI_LCD_H */


John Drew

Yves, there was code on the old site to drive a 2x16 lcd using I2C and a mcp23017 from memory. I had it working.
Tomorrow I'll see if I still have the code. It's getting late here and we lose an hour tonight for daylight saving time.
John

Yves

Thank you John, it is most appreciated. even though it will be I2C it wont be to difficult to change it to SPI.

Regards,

Yves
Yves

John Drew

#13
Hi Yves,
Here's the original code from George/Barrak.
It uses a PCF8574 but the principle was the same. I'll keep looking because I adapted it to the MCP23017 so I could also send info back from an external control board.
Cheers
John
I2Cprint George.zip

PS Just found the MCP23017 code. The essential difference was the address (which you won't be using). The code also did a number of other things tied in with it being a remote terminal  which complicated the code so I think you're better off using the above code as a starting point.

Pepe

#14
I have created the LCD16x2.inc library for the Hitachi 44780 lcd with the mcp23s17 library of Les

Yves

Tank you Pepe, Kindly can you send the Lcd.inc too
Regards,

Yves
Yves

Pepe

#16
I hope you value the selfless effort I have made to create this LCD16x2.inc bookstore and proteus simulation for pic 18f8722

Yves

Quote from: Pepe on Oct 02, 2022, 11:50 AMI hope you value the selfless effort I have made to create this LCD15x2.inc bookstore
I really do and I appreciate your valuable help. I really looking forward to get the lcd.inc routine. Many thanks in advance.

Kind regards,

Yves
Yves

Yves

Sorry Pepe i found it in your initial post.

Many thanks

Regards,

Yves
Yves

Pepe