www.elektronik.si Seznam forumov www.elektronik.si
Forum o elektrotehniki in računalništvu
 
 PomočPomoč  IščiIšči  Seznam članovSeznam članov  SkupineSkupine  StatisticsStatistika  AlbumAlbum  DatotekeFilemanager DokumentacijaDocDB LinksPovezave   Registriraj seRegistriraj se 
  PravilaPravila  LinksBolha  PriponkePriponke  KoledarKoledar  ZapiskiZapiski Tvoj profilTvoj profil Prijava za pregled zasebnih sporočilPrijava za pregled zasebnih sporočil PrijavaPrijava 

2 LCDja na Mega16
Pojdi na stran 1, 2  Naslednja
 
Objavi novo temo   Odgovori na to temo   Printer-friendly version    www.elektronik.si Seznam forumov -> Osnove programiranja AVR-jev
Poglej prejšnjo temo :: Poglej naslednjo temo  
Avtor Sporočilo
marko11
Član
Član



Pridružen-a: Ned 14 Dec 2003 17:47
Prispevkov: 866
Aktiv.: 3.90
Kraj: Dobrepolje

PrispevekObjavljeno: Sob Dec 16, 2017 8:53 pm    Naslov sporočila:  2 LCDja na Mega16 Odgovori s citatom

Hi
Sprašujem ali je možno na Mega16 priklopiti 2 LCDja 4x20, in na vsakega posebej pisati z BascomAVR ?

Lp,marko
Nazaj na vrh
Odsoten Poglej uporabnikov profil Pošlji zasebno sporočilo Pošlji E-sporočilo
mato1111
Član
Član



Pridružen-a: Pet 28 Dec 2012 14:42
Prispevkov: 610
Aktiv.: 4.45
Kraj: Vrhnika

PrispevekObjavljeno: Sob Dec 16, 2017 10:12 pm    Naslov sporočila:   Odgovori s citatom

To sem nekje že zasledil tam so jih priklopili preko I2C ali pa SPI vodila.
Edit: Tukaj se nahaja clanek
Nazaj na vrh
Odsoten Poglej uporabnikov profil Pošlji zasebno sporočilo
Silvo
Moderator
Moderator



Pridružen-a: Pon 24 Feb 2003 17:09
Prispevkov: 14551
Aktiv.: 65.53
Kraj: Koroška-okolica Dravograda

PrispevekObjavljeno: Sob Dec 16, 2017 10:48 pm    Naslov sporočila:   Odgovori s citatom

Za bascom ne vem. Sicer je izvedljivo. Data linije paralelno. Z enable pa displej za pisanje preklapljaš. Lahko tudi preko kakega zgoraj omenjenega protokola.
_________________
lp
Silvo
Nazaj na vrh
Odsoten Poglej uporabnikov profil Pošlji zasebno sporočilo
marko11
Član
Član



Pridružen-a: Ned 14 Dec 2003 17:47
Prispevkov: 866
Aktiv.: 3.90
Kraj: Dobrepolje

PrispevekObjavljeno: Ned Dec 17, 2017 7:12 pm    Naslov sporočila:   Odgovori s citatom

Bi probal nekako tako kot je napisal Silvo, pa me zanima, če je kje kaj napisanega, sam ne najdem nobene povezave, za I2C so primeri. Kako povezati in programirati v bascom pa ne najdem, tako kot opisuje Silvo.

LP,marko

_________________
Če ne veš kam greš, se ne moreš zgubiti.
Nazaj na vrh
Odsoten Poglej uporabnikov profil Pošlji zasebno sporočilo Pošlji E-sporočilo
Vlado
Član
Član



Pridružen-a: Sre 03 Mar 2004 21:35
Prispevkov: 561
Aktiv.: 2.53
Kraj: Ljubljana

PrispevekObjavljeno: Ned Dec 17, 2017 7:31 pm    Naslov sporočila:   Odgovori s citatom

Marko,
v Bascomu lahko narediš prek I2C ali SPI, tako kot je opisal Silvo, lahko narediš
če napišeš svoj .lib, drugače ne bo šlo.
Lahko pa probaš tako da LCD-je povežeš prek stikal (4053), in izbiraš na kateri LCD boš pisal. V tem primeru ne pozabi narediti inicializacijo za vsak LCD posebaj.
Nazaj na vrh
Odsoten Poglej uporabnikov profil Pošlji zasebno sporočilo
marko11
Član
Član



Pridružen-a: Ned 14 Dec 2003 17:47
Prispevkov: 866
Aktiv.: 3.90
Kraj: Dobrepolje

PrispevekObjavljeno: Ned Dec 17, 2017 7:38 pm    Naslov sporočila:   Odgovori s citatom

Hvala za nasvete. "Napiši svoj .lib", tole pa bo preveč zamene, verjetno bom vrgel puško v koruzo. Če bi videl kak primer, kako se to naredi....

LP,
Nazaj na vrh
Odsoten Poglej uporabnikov profil Pošlji zasebno sporočilo Pošlji E-sporočilo
Vlado
Član
Član



Pridružen-a: Sre 03 Mar 2004 21:35
Prispevkov: 561
Aktiv.: 2.53
Kraj: Ljubljana

PrispevekObjavljeno: Ned Dec 17, 2017 7:40 pm    Naslov sporočila:   Odgovori s citatom

Marko,
napiši katere displeje imaš?
Zakaj nebi uporabil I2C način. Za to obstaja že napisan primer, mislim da ga je objavil Jure na MCS-u.
Nazaj na vrh
Odsoten Poglej uporabnikov profil Pošlji zasebno sporočilo
igo
Član
Član



Pridružen-a: Sre 11 Okt 2006 19:11
Prispevkov: 3638
Aktiv.: 17.11

PrispevekObjavljeno: Ned Dec 17, 2017 8:53 pm    Naslov sporočila:   Odgovori s citatom

Z minimalno truda v besedilnem urejevalniku ( notepad++ ) odpreš .cpp knjižnico za LCD in podvojiš vse funkcije (označiš vse funkcije, jih kopiraš in prilepiš znotraj iste knjižnice).
Nato dvojnike funkcij preimenuješ - imenom dodaš na primer številko 2:
void LCD::InitLCD(...)
void LCD::InitLCD2(...)

Nato odpreš še .h knjižnico in tudi tam podvojiš in preimenuješ imena funkcij.

V programu potem delaš povsem enako kot doslej. Pri definiranju pinov vneseš ustrezne številke. Za prvi LCD kličeš dosedanje funkcije, za drugega pa funkcije2.

Lahko pa sem pripneš knjižnice v zvezi z LCD in jih bomo "predelali".

_________________
Teoretično je praksa posledica teorije, praktično je pa ravno obratno. (igo 2001)
LP, Igor
Nazaj na vrh
Odsoten Poglej uporabnikov profil Pošlji zasebno sporočilo Pošlji E-sporočilo
marko11
Član
Član



Pridružen-a: Ned 14 Dec 2003 17:47
Prispevkov: 866
Aktiv.: 3.90
Kraj: Dobrepolje

PrispevekObjavljeno: Pon Dec 18, 2017 8:07 pm    Naslov sporočila:   Odgovori s citatom

Vlado je napisal/a:
Marko,
napiši katere displeje imaš?
Zakaj nebi uporabil I2C način. Za to obstaja že napisan primer, mislim da ga je objavil Jure na MCS-u.


LCD imam od AX elektronike :
DEM 20485 SYH/V
ABC020004B24-YLY

Za I2C je verjetno potrebna predelava vezja, vezje pa imam že narejeno.

@Igo kje pa so te knjižnice?

LP,
Nazaj na vrh
Odsoten Poglej uporabnikov profil Pošlji zasebno sporočilo Pošlji E-sporočilo
igo
Član
Član



Pridružen-a: Sre 11 Okt 2006 19:11
Prispevkov: 3638
Aktiv.: 17.11

PrispevekObjavljeno: Pon Dec 18, 2017 8:53 pm    Naslov sporočila:   Odgovori s citatom

Jaz nimam Bascoma.
Knjižnice imajo končnico .lib in so nekje na kupu v Bascom mapah.
Vsako odpreš z urejevalnikom besedil in pogledaš, kaj je notri.
Sem prilepi vse tiste, v katerih se nahajajo funkcije za delo z LCD-ji.
Potem bom videl, kaj se da storiti z njimi.

_________________
Teoretično je praksa posledica teorije, praktično je pa ravno obratno. (igo 2001)
LP, Igor
Nazaj na vrh
Odsoten Poglej uporabnikov profil Pošlji zasebno sporočilo Pošlji E-sporočilo
Vlado
Član
Član



Pridružen-a: Sre 03 Mar 2004 21:35
Prispevkov: 561
Aktiv.: 2.53
Kraj: Ljubljana

PrispevekObjavljeno: Pon Dec 18, 2017 8:53 pm    Naslov sporočila:   Odgovori s citatom

Marko,
poglej kako je to narejeno na tem linku:
https://www.mcselec.com/index2.php?option=com_forum&Itemid=59&page=viewtopic&t=9091
LP
Nazaj na vrh
Odsoten Poglej uporabnikov profil Pošlji zasebno sporočilo
marko11
Član
Član



Pridružen-a: Ned 14 Dec 2003 17:47
Prispevkov: 866
Aktiv.: 3.90
Kraj: Dobrepolje

PrispevekObjavljeno: Pon Dec 18, 2017 9:06 pm    Naslov sporočila:   Odgovori s citatom

Našel sem tele knjižnice:
lcd4.lbx
lcd4.lib
lcd4busy.lbx
lcd4busy.lib

Tukaj je copy lcd4busy.lib:

Koda:

copyright = MCS Electronics
www       = http://www.mcselec.com
email     = avr@mcselec.com
comment   = Optimized LCD library with busy check
libversion   = 1.00
date         = 5 april 2002
statement    = No SOURCE code from the library may be distributed in any form
statement    = Of course this does not applie for the COMPILED code when you have a BASCOM-AVR license
history      = No known bugs.


;the default library for BASCOM can handle worst case scenarios where each pin of the LCD
;is connected to a random pin of the micro
;When we choose the data port pin in sequence, we can save some code
;This lib shows how to use the LCD in 4 bit mode

;Rs = PortB.3
;RW = PortB.2 
; E = PortB.1
;E2 = PortB.0        optional for lcd with 2 chips
;Db4 = PortB.4       the data bits must be in a nibble to save code
;Db5 = PortB.5
;Db6 = PortB.6
;Db7 = PortB.7
; in your basic program use:
;$lib "lcd4busy.lib"
;Const _lcdport = Porta
;Const _lcdddr = Ddra
;Const _lcdin = Pina
;Const _lcd_e = 1
;Const _lcd_rw = 2
;Const _lcd_rs = 3



;This routine is called when the LCD must be initialized
[_Init_LCD]
_Init_LCD:
    clr R24                            ; set all portpins low
*   out _LCDport, r24
    ser r24                             ; set port pins to output
*   out _LCDDDR, r24
    Ldi R30, 28
    Ldi R31, 78
    Rcall _lcd_delay                    ; 20 ms delay at 4 MHz

    ldi r24, &B00110000                 ; 8-bit interface high nibble
*   out _LCDport, r24
*   sbi _LCDport, _LCD_E                ; set pin
    nop                                 ; delay
    nop
*   cbi _LCDport, _LCD_E                ; disable E
    Ldi R30, 132
    Ldi R31, 19
    rcall _lcd_delay                    ; 5 mS delay at 4 MHz
*   sbi _LCDport, _LCD_E                ; nibble is already setup
    nop
    nop
*   cbi _LCDport, _LCD_E
    Ldi R30, 96                         ; 100 uS delay at 4 MHz
    Ldi R31, 0
    rcall _lcd_delay
*   sbi _LCDport, _LCD_E
    nop
    nop
*   cbi _LCDport, _LCD_E                ; clear
    Ldi R30, 96                         ; 100 uS delay at 4 MHz
    Ldi R31, 0
    rcall _lcd_delay
    ldi r24, &B00100000                 ; Command for 4-bit interface high nibble
*   out _LCDport, r24
*   sbi _LCDport, _LCD_E                ; pulse
    nop
    nop
*   cbi _LCDport, _LCD_E                ; clear enable
    ldi r24, &H28
    rcall _Lcd_control
    Ldi r24,14                          ; Display on, Cursor on, Noblink
    Rcall _Lcd_control
    Ldi r24,6                           ; Cursor moves right, text doesn't move
    RJmp _Lcd_control                   ; return will come from _lcd_control

_lcd_delay:
   Sbiw R30,1                           ;2 cycles   
   Brne _lcd_delay                      ;2 cycles
Ret

[END]


;high nibble must be written first
;rw must be low for a write
;rs must be low for control, high for data
;data passed in r24
[_Write_lcd]
_Write_lcd:
  rcall _LCD_Busy                       ; Wait for LCD to be ready
  ldi r25, &b11110000
  and r25, r24                          ; Get upper nibble into upper half port
* out _LCDport, r25                     ; Send data to LCD

* sbi _LCDport, _LCD_RS                 ; Set LCD to data mode
  rcall _write_lcd2                     ; saving code

  ldi r25, &B00001111
  and r25, r24                          ; Get lower nibble into upper half port
  swap r25
* out _LCDport, r25                     ; Send data to LCD
* sbi _LCDport, _LCD_RS                 ; Set LCD to data mode
_write_lcd2:
* sbi _LCDport, _LCD_E ;toggle E for LCD
  nop
  nop
* cbi _LCDport, _LCD_E
  ret

_Lcd_control:
  rcall _LCD_Busy                       ; Wait for LCD to be ready
  ldi r25, &B11110000
  and r25,r24                           ; Get upper nibble into upper half port
* out _LCDport, r25                     ; Send data to LCD
  rcall _write_lcd2
  swap r24
  ldi r25, &b11110000
  and r25, r24                          ; Get lower nibble into upper half port
* out _LCDport, r25                     ; Send data to LCD
rjmp _write_lcd2                        ; finish there to save code


_LCD_Busy:
  ldi r25, &b00001111                   ; Set high nibble to input
* out _LCDDDR, r25
  clr r25                               ; remove pull-ups on data nibble
* out _LCDport, r25
* sbi _LCDport, _LCD_RW                 ; Setup to read busy flag
* sbi _LCDport, _LCD_E                  ; Set E high
  nop
  nop
* in r25, _LCDin                        ; Read upper nibble busy flag, DDRam address
* cbi _LCDport, _LCD_E                  ; Set E low
  nop
  nop
* sbi _LCDport, _LCD_E                  ; Set E high to get rid of lower nibble
  nop
  nop
* cbi _LCDport, _LCD_E                  ; Set E low
  sbrc r25, 7                           ; Check busy flag, high = busy
  rjmp _LCD_Busy                        ; if high check again
* cbi _LCDport, _LCD_RW                 ; back to write mode
  ser r25
* out _LCDDDR, r25                      ; set for output
ret
[END]




[_CLS]
$EXTERNAL _WRITE_LCD , _INIT_LCD
_Cls:
  Ldi R24,1                         ; Clear display
  Rcall _Lcd_control
  Ldi R30, 180
  Ldi R31, 11
  rcall _lcd_delay
  Ldi R24,128                       ; Select line 1
  Rjmp _Lcd_control                 ; finish
[END]




če je potrebno pa skopiram še druge .lib

lp,
Nazaj na vrh
Odsoten Poglej uporabnikov profil Pošlji zasebno sporočilo Pošlji E-sporočilo
igo
Član
Član



Pridružen-a: Sre 11 Okt 2006 19:11
Prispevkov: 3638
Aktiv.: 17.11

PrispevekObjavljeno: Pon Dec 18, 2017 10:03 pm    Naslov sporočila:   Odgovori s citatom

Huh. Niti ni tako grozno. Podvoji se 3 funkcije, nato pa se vsem dodanim signalom, funkcijam in labelam na koncu doda recimo _L2.
_Init_LCD postane _Init_LCD_L2.
LCDport -> LCDport_L2
_LCD_E -> _LCD_E_L2
_lcd_delay -> _lcd_delay_L2
_lcd_busy -> _lcd_busy_L2
_CLS -> _CLS_L2
_write_lcd2 -> _write_lcd2_L2
_Write_lcd -> _Write_lcd_L2
...


Enako je treba podvojiti imena še v .lbx , a morajo ostati znotraj istega oklepaja.
Če ne boš ničesar pozabil spremeniti, se bodo funkcije za prvi in drugi LCD obnašale kot povsem neodvisne in počele stvari na nastavljenih pinih.

Seveda pa najprej kopiraj originalni datoteki na varno mesto.

_________________
Teoretično je praksa posledica teorije, praktično je pa ravno obratno. (igo 2001)
LP, Igor
Nazaj na vrh
Odsoten Poglej uporabnikov profil Pošlji zasebno sporočilo Pošlji E-sporočilo
igo
Član
Član



Pridružen-a: Sre 11 Okt 2006 19:11
Prispevkov: 3638
Aktiv.: 17.11

PrispevekObjavljeno: Pon Dec 18, 2017 11:11 pm    Naslov sporočila:   Odgovori s citatom

Koda:

copyright = MCS Electronics
www       = http://www.mcselec.com
email     = avr@mcselec.com
comment   = Optimized LCD library with busy check
libversion   = 1.00
date         = 5 april 2002
statement    = No SOURCE code from the library may be distributed in any form
statement    = Of course this does not applie for the COMPILED code when you have a BASCOM-AVR license
history      = No known bugs.


;the default library for BASCOM can handle worst case scenarios where each pin of the LCD
;is connected to a random pin of the micro
;When we choose the data port pin in sequence, we can save some code
;This lib shows how to use the LCD in 4 bit mode

;Rs = PortB.3
;RW = PortB.2 
; E = PortB.1
;E2 = PortB.0        optional for lcd with 2 chips
;Db4 = PortB.4       the data bits must be in a nibble to save code
;Db5 = PortB.5
;Db6 = PortB.6
;Db7 = PortB.7
; in your basic program use:
;$lib "lcd4busy.lib"
;Const _lcdport = Porta
;Const _lcdddr = Ddra
;Const _lcdin = Pina
;Const _lcd_e = 1
;Const _lcd_rw = 2
;Const _lcd_rs = 3



;This routine is called when the LCD must be initialized
[_Init_LCD]
_Init_LCD:
    clr R24                            ; set all portpins low
*   out _LCDport, r24
    ser r24                             ; set port pins to output
*   out _LCDDDR, r24
    Ldi R30, 28
    Ldi R31, 78
    Rcall _lcd_delay                    ; 20 ms delay at 4 MHz

    ldi r24, &B00110000                 ; 8-bit interface high nibble
*   out _LCDport, r24
*   sbi _LCDport, _LCD_E                ; set pin
    nop                                 ; delay
    nop
*   cbi _LCDport, _LCD_E                ; disable E
    Ldi R30, 132
    Ldi R31, 19
    rcall _lcd_delay                    ; 5 mS delay at 4 MHz
*   sbi _LCDport, _LCD_E                ; nibble is already setup
    nop
    nop
*   cbi _LCDport, _LCD_E
    Ldi R30, 96                         ; 100 uS delay at 4 MHz
    Ldi R31, 0
    rcall _lcd_delay
*   sbi _LCDport, _LCD_E
    nop
    nop
*   cbi _LCDport, _LCD_E                ; clear
    Ldi R30, 96                         ; 100 uS delay at 4 MHz
    Ldi R31, 0
    rcall _lcd_delay
    ldi r24, &B00100000                 ; Command for 4-bit interface high nibble
*   out _LCDport, r24
*   sbi _LCDport, _LCD_E                ; pulse
    nop
    nop
*   cbi _LCDport, _LCD_E                ; clear enable
    ldi r24, &H28
    rcall _Lcd_control
    Ldi r24,14                          ; Display on, Cursor on, Noblink
    Rcall _Lcd_control
    Ldi r24,6                           ; Cursor moves right, text doesn't move
    RJmp _Lcd_control                   ; return will come from _lcd_control

_lcd_delay:
   Sbiw R30,1                           ;2 cycles   
   Brne _lcd_delay                      ;2 cycles
Ret

[END]


;high nibble must be written first
;rw must be low for a write
;rs must be low for control, high for data
;data passed in r24
[_Write_lcd]
_Write_lcd:
  rcall _LCD_Busy                       ; Wait for LCD to be ready
  ldi r25, &b11110000
  and r25, r24                          ; Get upper nibble into upper half port
* out _LCDport, r25                     ; Send data to LCD

* sbi _LCDport, _LCD_RS                 ; Set LCD to data mode
  rcall _write_lcd2                     ; saving code

  ldi r25, &B00001111
  and r25, r24                          ; Get lower nibble into upper half port
  swap r25
* out _LCDport, r25                     ; Send data to LCD
* sbi _LCDport, _LCD_RS                 ; Set LCD to data mode
_write_lcd2:
* sbi _LCDport, _LCD_E ;toggle E for LCD
  nop
  nop
* cbi _LCDport, _LCD_E
  ret

_Lcd_control:
  rcall _LCD_Busy                       ; Wait for LCD to be ready
  ldi r25, &B11110000
  and r25,r24                           ; Get upper nibble into upper half port
* out _LCDport, r25                     ; Send data to LCD
  rcall _write_lcd2
  swap r24
  ldi r25, &b11110000
  and r25, r24                          ; Get lower nibble into upper half port
* out _LCDport, r25                     ; Send data to LCD
rjmp _write_lcd2                        ; finish there to save code


_LCD_Busy:
  ldi r25, &b00001111                   ; Set high nibble to input
* out _LCDDDR, r25
  clr r25                               ; remove pull-ups on data nibble
* out _LCDport, r25
* sbi _LCDport, _LCD_RW                 ; Setup to read busy flag
* sbi _LCDport, _LCD_E                  ; Set E high
  nop
  nop
* in r25, _LCDin                        ; Read upper nibble busy flag, DDRam address
* cbi _LCDport, _LCD_E                  ; Set E low
  nop
  nop
* sbi _LCDport, _LCD_E                  ; Set E high to get rid of lower nibble
  nop
  nop
* cbi _LCDport, _LCD_E                  ; Set E low
  sbrc r25, 7                           ; Check busy flag, high = busy
  rjmp _LCD_Busy                        ; if high check again
* cbi _LCDport, _LCD_RW                 ; back to write mode
  ser r25
* out _LCDDDR, r25                      ; set for output
ret
[END]


[_CLS]
$EXTERNAL _WRITE_LCD , _INIT_LCD
_Cls:
  Ldi R24,1                         ; Clear display
  Rcall _Lcd_control
  Ldi R30, 180
  Ldi R31, 11
  rcall _lcd_delay
  Ldi R24,128                       ; Select line 1
  Rjmp _Lcd_control                 ; finish
[END]


; LCD 2 ==>  _L2


;This routine is called when the LCD_L2 must be initialized
[_Init_LCD_L2]
_Init_LCD_L2:
    clr R24                            ; set all portpins low
*   out _LCDport_L2, r24
    ser r24                             ; set port pins to output
*   out _LCDDDR_L2, r24
    Ldi R30, 28
    Ldi R31, 78
    Rcall _lcd_delay_L2                    ; 20 ms delay at 4 MHz

    ldi r24, &B00110000                 ; 8-bit interface high nibble
*   out _LCDport_L2, r24
*   sbi _LCDport_L2, _LCD_E_L2                ; set pin
    nop                                 ; delay
    nop
*   cbi _LCDport_L2, _LCD_E_L2                ; disable E
    Ldi R30, 132
    Ldi R31, 19
    rcall _lcd_delay_L2                    ; 5 mS delay at 4 MHz
*   sbi _LCDport_L2, _LCD_E_L2                ; nibble is already setup
    nop
    nop
*   cbi _LCDport_L2, _LCD_E_L2
    Ldi R30, 96                         ; 100 uS delay at 4 MHz
    Ldi R31, 0
    rcall _lcd_delay_L2
*   sbi _LCDport_L2, _LCD_E_L2
    nop
    nop
*   cbi _LCDport_L2, _LCD_E_L2                ; clear
    Ldi R30, 96                         ; 100 uS delay at 4 MHz
    Ldi R31, 0
    rcall _lcd_delay_L2
    ldi r24, &B00100000                 ; Command for 4-bit interface high nibble
*   out _LCDport_L2, r24
*   sbi _LCDport_L2, _LCD_E_L2                ; pulse
    nop
    nop
*   cbi _LCDport_L2, _LCD_E_L2                ; clear enable
    ldi r24, &H28
    rcall _Lcd_control_L2
    Ldi r24,14                          ; Display on, Cursor on, Noblink
    Rcall _Lcd_control_L2
    Ldi r24,6                           ; Cursor moves right, text doesn't move
    RJmp _Lcd_control_L2                   ; return will come from _lcd_control

_lcd_delay_L2:
   Sbiw R30,1                           ;2 cycles   
   Brne _lcd_delay_L2                      ;2 cycles
Ret

[END]


;high nibble must be written first
;rw must be low for a write
;rs must be low for control, high for data
;data passed in r24
[_Write_lcd_L2]
_Write_lcd_L2:
  rcall _LCD_Busy_L2                       ; Wait for LCD to be ready
  ldi r25, &b11110000
  and r25, r24                          ; Get upper nibble into upper half port
* out _LCDport_L2, r25                     ; Send data to LCD

* sbi _LCDport_L2, _LCD_RS_L2                 ; Set LCD to data mode
  rcall _write_lcd2_L2                     ; saving code

  ldi r25, &B00001111
  and r25, r24                          ; Get lower nibble into upper half port
  swap r25
* out _LCDport_L2, r25                     ; Send data to LCD
* sbi _LCDport_L2, _LCD_RS_L2                 ; Set LCD to data mode
_write_lcd2_L2:
* sbi _LCDport_L2, _LCD_E_L2 ;toggle E for LCD
  nop
  nop
* cbi _LCDport_L2, _LCD_E_L2
  ret

_Lcd_control_L2:
  rcall _LCD_Busy_L2                       ; Wait for LCD to be ready
  ldi r25, &B11110000
  and r25,r24                           ; Get upper nibble into upper half port
* out _LCDport_L2, r25                     ; Send data to LCD
  rcall _write_lcd2_L2
  swap r24
  ldi r25, &b11110000
  and r25, r24                          ; Get lower nibble into upper half port
* out _LCDport_L2, r25                     ; Send data to LCD
rjmp _write_lcd2_L2                       ; finish there to save code


_LCD_Busy_L2:
  ldi r25, &b00001111                   ; Set high nibble to input
* out _LCDDDR_L2, r25
  clr r25                               ; remove pull-ups on data nibble
* out _LCDport_L2, r25
* sbi _LCDport_L2, _LCD_RW_L2                 ; Setup to read busy flag
* sbi _LCDport_L2, _LCD_E_L2                  ; Set E high
  nop
  nop
* in r25, _LCDin_L2                        ; Read upper nibble busy flag, DDRam address
* cbi _LCDport_L2, _LCD_E_L2                  ; Set E low
  nop
  nop
* sbi _LCDport_L2, _LCD_E_L2                  ; Set E high to get rid of lower nibble
  nop
  nop
* cbi _LCDport_L2, _LCD_E_L2                  ; Set E low
  sbrc r25, 7                           ; Check busy flag, high = busy
  rjmp _LCD_Busy_L2                        ; if high check again
* cbi _LCDport_L2, _LCD_RW_L2                 ; back to write mode
  ser r25
* out _LCDDDR_L2, r25                      ; set for output
ret
[END]


[_CLS_L2]
$EXTERNAL _WRITE_LCD , _INIT_LCD
_Cls_L2:
  Ldi R24,1                         ; Clear display_L2
  Rcall _Lcd_control_L2
  Ldi R30, 180
  Ldi R31, 11
  rcall _lcd_delay_L2
  Ldi R24,128                       ; Select line 1
  Rjmp _Lcd_control_L2                 ; finish
[END]


Pripni še pripadajoč .lbx .

_________________
Teoretično je praksa posledica teorije, praktično je pa ravno obratno. (igo 2001)
LP, Igor
Nazaj na vrh
Odsoten Poglej uporabnikov profil Pošlji zasebno sporočilo Pošlji E-sporočilo
marko11
Član
Član



Pridružen-a: Ned 14 Dec 2003 17:47
Prispevkov: 866
Aktiv.: 3.90
Kraj: Dobrepolje

PrispevekObjavljeno: Tor Dec 19, 2017 12:28 am    Naslov sporočila:   Odgovori s citatom

Pripenjam še lcd4busy.lbx

Kaj pa je s temi lcd4.lbx in lcd4.lib ?

Koda:

Comment = Compiled LIB file, no comment included

copyright = MCS Electronics
www       = http://www.mcselec.com
email     = avr@mcselec.com
comment   = Optimized LCD library with busy check
libversion   = 1.00
date         = 5 april 2002
statement    = No SOURCE code from the library may be distributed in any form
statement    = Of course this does not applie for the COMPILED code when you have a BASCOM-AVR license
history      = No known bugs.
[_Init_LCD]
_Init_LCD:
.OBJ 2788
*   out _LCDport, r24
.OBJ EF8F
*   out _LCDDDR, r24
.OBJ E1EC
.OBJ E4FE
    Rcall _lcd_delay
.OBJ E380
*   out _LCDport, r24
*   sbi _LCDport, _LCD_E
.OBJ 0
.OBJ 0
*   cbi _LCDport, _LCD_E
.OBJ E8E4
.OBJ E1F3
    rcall _lcd_delay
*   sbi _LCDport, _LCD_E
.OBJ 0
.OBJ 0
*   cbi _LCDport, _LCD_E
.OBJ E6E0
.OBJ E0F0
    rcall _lcd_delay
*   sbi _LCDport, _LCD_E
.OBJ 0
.OBJ 0
*   cbi _LCDport, _LCD_E
.OBJ E6E0
.OBJ E0F0
    rcall _lcd_delay
.OBJ E280
*   out _LCDport, r24
*   sbi _LCDport, _LCD_E
.OBJ 0
.OBJ 0
*   cbi _LCDport, _LCD_E
.OBJ E288
    rcall _Lcd_control
.OBJ E08E
    Rcall _Lcd_control
.OBJ E086
    RJmp _Lcd_control
_lcd_delay:
.OBJ 9731
   Brne _lcd_delay
.OBJ 9508
[END]
[_Write_lcd]
_Write_lcd:
  rcall _LCD_Busy
.OBJ EF90
.OBJ 2398
* out _LCDport, r25
* sbi _LCDport, _LCD_RS
  rcall _write_lcd2
.OBJ E09F
.OBJ 2398
.OBJ 9592
* out _LCDport, r25
* sbi _LCDport, _LCD_RS
_write_lcd2:
* sbi _LCDport, _LCD_E
.OBJ 0
.OBJ 0
* cbi _LCDport, _LCD_E
.OBJ 9508
_Lcd_control:
  rcall _LCD_Busy
.OBJ EF90
.OBJ 2398
* out _LCDport, r25
  rcall _write_lcd2
.OBJ 9582
.OBJ EF90
.OBJ 2398
* out _LCDport, r25
rjmp _write_lcd2
_LCD_Busy:
.OBJ E09F
* out _LCDDDR, r25
.OBJ 2799
* out _LCDport, r25
* sbi _LCDport, _LCD_RW
* sbi _LCDport, _LCD_E
.OBJ 0
.OBJ 0
* in r25, _LCDin
* cbi _LCDport, _LCD_E
.OBJ 0
.OBJ 0
* sbi _LCDport, _LCD_E
.OBJ 0
.OBJ 0
* cbi _LCDport, _LCD_E
.OBJ FD97
  rjmp _LCD_Busy
* cbi _LCDport, _LCD_RW
.OBJ EF9F
* out _LCDDDR, r25
.OBJ 9508
[END]
[_CLS]
$EXTERNAL _WRITE_LCD , _INIT_LCD
_Cls:
.OBJ E081
  Rcall _Lcd_control
.OBJ EBE4
.OBJ E0FB
  rcall _lcd_delay
.OBJ E880
  Rjmp _Lcd_control
[END]


lp,
Nazaj na vrh
Odsoten Poglej uporabnikov profil Pošlji zasebno sporočilo Pošlji E-sporočilo
Pokaži sporočila:   
Objavi novo temo   Odgovori na to temo   Printer-friendly version    www.elektronik.si Seznam forumov -> Osnove programiranja AVR-jev Časovni pas GMT + 2 uri, srednjeevropski - poletni čas
Pojdi na stran 1, 2  Naslednja
Stran 1 od 2

 
Pojdi na:  
Ne, ne moreš dodajati novih tem v tem forumu
Ne, ne moreš odgovarjati na teme v tem forumu
Ne, ne moreš urejati svojih prispevkov v tem forumu
Ne, ne moreš brisati svojih prispevkov v tem forumu
Ne ne moreš glasovati v anketi v tem forumu
Ne, ne moreš pripeti datotek v tem forumu
Ne, ne moreš povleči datotek v tem forumu

Uptime: 47 dni


Powered by phpBB © 2001, 2005 phpBB Group