LCD su linea I2c

Sezione dedicata al sistema di sviluppo BASCOM-AVR per i micro AVR
At90s, Attiny, Atmega e Xmega

LCD su linea I2c

Postby agennore » 22 Feb 2018, 22:49

Buon giorno a tutti,
ho trovato sul sito della mcselec una nota applicativa per collegare un LCD tramite linea I2c.

https://www.mcselec.com/index.php?option=com_content&task=view&id=82&Itemid=57

Ho acquistato il convertitore e collegato ai pin PB.5-(SCL) e PB.4-(SDA) dell' AtMega8 ( comodo perchè nella presa di programmazione sono presenti +5v e Gnd oltre ai due pin richiesti dall'I2c SCK - MISO ) , ma in fase di compilazione del programma di esempio allegato all' AN118 mi ritornano una decina di errori e non riesco a capirne il motivo.

Tramite il programma I2cscan ho trovato l'indirizzo del dispositivo ( 4E ) ma ogni ulteriore tentativo di scrivere sull'LCD con gli esempi trovati sul sito della mcselec non funziona.

Se può essere utile i collegamenti tra LCD e PCF8574A sono i seguenti:
RS - P0
RW - P1
E - P2
D4 - P4
D5 - P5
D6 - P6
D7 - P7

Qualche idea ?

Grazie in anticipo
Agennore
agennore
 
Posts: 4
Joined: 22 Feb 2018, 21:53

Re: LCD su linea I2c

Postby deluca » 27 Feb 2018, 15:51

agennore benvenuto nel forum

indica la versione di bascom e allega il sorgente... vedremo di dare un'occhiata
Ciao
Il mio sito: http://www.delucagiovanni.com ......e la chat: chat/
User avatar
deluca
Site Admin
 
Posts: 1104
Joined: 19 Jun 2011, 10:44
Location: 95123 - Catania (Italy)

Re: LCD su linea I2c

Postby agennore » 01 Mar 2018, 12:38

Grazie per il benvenuto.
Nel tentativo di trovare una soluzione, sempre sul sito della MCS ho trovato la proposta da Ben's
https://www.mcselec.com/index2.php?option=com_forum&Itemid=59&page=viewtopic&t=12506&highlight=bllcdi2c
scaricato libreria "bl_lcd_i2c.LIB" ed il listato, ho modificato esclusivamente gli indirizzi di SCL e SDA rispettivamente
Config Scl = Portb.3
Config Sda = Portb.4


    'I2c LCD on Arduino Nano 16x2 display with backlight

    $regfile = "m8def.dat"
    $crystal = 8000000
    $baud = 9600 ' baud rate
    Declare Sub I2c_scan
    Config I2cdelay = 10
    $lib "i2c_twi.lib" 'hardware i2c/TWI
    Config Twi = 100000
    $lib "bl_Lcd_i2c.lib" ' AN #118 library from Kent
    ' with this addition
    ' * lds r27,{backlight}
    ' andi _temp2,&hf7
    ' or _temp2,r27


    'LCD-display including backlight
    '0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1
    '1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6

    'G 5 C R R E D D D D D D D D B B
    'N O S W 0 1 2 3 4 5 6 7 L L
    'D V N S

    'PCF8574
    'P7 = D7
    'P6 = D6
    'P5 = D5
    'P4 = D4
    'P3 = 1 = backlight on / 0 = backlight off
    'P2 = E
    'P1 = RW
    'P0 = RS

    Const Pcf_d4 = 4
    Const Pcf_d5 = 5
    Const Pcf_d6 = 6
    Const Pcf_d7 = 7
    Const Pcf_rs = 0
    Const Pcf_rw = 1
    Const Pcf_e1 = 2

    Dim B As Byte
    Dim A As Byte
    Dim _lcd_e As Byte
    Dim Backlight As Byte

    Backlight_on Alias &H08
    Backlight_off Alias &H00

    Backlight = Backlight_on

    _lcd_e = 192

    Const Pcf8574_lcd = &H4E 'Defines the address of the I/O expander for LCD

    Config Scl = Portb.3
    Config Sda = Portb.4

    I2cinit

    'Call I2c_scan 'if you want to check if the PCF8574 is seen activate this

    Wait 2


    Cls
    Home
    Lcd "i2c-display" 'display this at the top line
    Wait 1
    Lowerline 'select the lower line
    Wait 1
    Lcd "Shift this." 'display this at the lower line
    Wait 1
    For A = 1 To 10
    Shiftlcd Right 'shift the text to the right
    Waitms 250 'wait a moment
    Next

    For A = 1 To 10
    Shiftlcd Left 'shift the text to the left
    Waitms 250 'wait a moment
    Next


    Locate 2 , 1 'set cursor position
    Lcd "*" 'display this
    Wait 1 'wait a moment

    Shiftcursor Right 'shift the cursor
    Lcd "@" 'display this
    Wait 1 'wait a moment

    Home Upper 'select line 1 and return home
    Lcd "Replaced." 'replace the text
    Wait 1 'wait a moment

    Cursor Off Noblink 'hide cursor
    Wait 1 'wait a moment
    Cursor On Blink 'show cursor
    Wait 1 'wait a moment
    Display Off 'turn display off
    Wait 1 'wait a moment
    Display On 'turn display on

    'Now lets build a special character
    'the first number is the characternumber (0-7)
    'The other numbers are the rowvalues
    'Use the LCD tool to insert this line
    Deflcdchar 2 , 32 , 10 , 32 , 14 , 17 , 17 , 17 , 14 'replace ? with number (0-7)
    Deflcdchar 0 , 32 , 4 , 32 , 14 , 18 , 18 , 18 , 13 'replace ? with number (0-7)
    Deflcdchar 1 , 32 , 10 , 32 , 14 , 18 , 18 , 18 , 13 'replace ? with number (0-7)
    _lcd_e = 128
    Cls 'select data RAM
    Rem it is important that a CLS is following the deflcdchar statements because it will set the controller back in datamode
    Lcd Chr(0) ; Chr(1) 'print the special character

    '----------------- Now use an internal routine ------------
    _temp1 = 2 'value into ACC
    !rCall _write_lcd 'put it on LCD

    '**************************************************************************

    End

    Sub I2c_scan 'check all devices on the I2c-bus
    Print "Scan start"
    For B = 0 To 254 Step 2 'for all odd addresses
    I2cstart 'send start
    I2cwbyte B 'send address
    If Err = 0 Then 'we got an ack

    ' Print "Slave at : " ; B ; " hex : " ; Hex(b) ; " bin : " ; Bin(b)
    End If
    I2cstop 'free bus
    Next
    Print "End Scan"
    End Sub
Compilato senza errori e programmato il micro (AtMega8) ma il display resta inattivo con la prima riga nera e la seconda chiara.
Tramite oscilloscopio ho verificato che su entrambi i pin SCL e SDA fossero presenti segnali.
Nel dubbio che fosse guasto il dispositivo con il PCF8574A ne ho acquistato un altro di diversa marca ( sempre con uguale pedinatura ), ma non cambia nulla.

La versione del Bascom è la 2.0.7.3

A questo punto non saprei cos'altro provare, ogni aiuto è il benvenuto.
agennore
 
Posts: 4
Joined: 22 Feb 2018, 21:53


Return to BASCOM-AVR

Who is online

Users browsing this forum: No registered users and 1 guest

cron