logo elektroda
logo elektroda
X
logo elektroda
REKLAMA
REKLAMA
Adblock/uBlockOrigin/AdGuard mogą powodować znikanie niektórych postów z powodu nowej reguły.

LCD WC1602A0 - jak poprawnie zainicjalizować wyświetlacz w ASM?

dr00id88 12 Lip 2007 17:46 1938 4
REKLAMA
  • #1 4075513
    dr00id88
    Poziom 11  
    Posty: 24
    Od kilku dni męczę ten wyswietlacz, a on nic. Tzn. jak odpowiednio zrobię zwarę to widać dwa rzędy prostokącików, ale nie o to chodzi.
    Pod Bascomem nie mogłem, więc spróbowałem w ASM:

    .include "tn2313def.inc"
    ;*******************************************************
                    .list
                    .listmac
    ;-----------------------------------------------------------------------------
    .macro          ldz
                    ldi     r30,low(@0)
                    ldi     r31,high(@0)
    .endm
    ;-----------------------------------------------------------------------------
    .def acc                = r16
    .def param              = r17
    ;-----------------------------------------------------------------------------
                    .dseg
    
                    .cseg
    ;
                    .org    0
                    rjmp    ResetProcessor          ;
    ;-----------------------------------------------------------------------------
                    .org    INT0addr                ;External Interrupt0 Vector ...
                    reti                            ;
    ;-----------------------------------------------------------------------------
                    .org    INT1addr                ;External Interrupt1 Vector ...
                    reti                            ;
    ;-----------------------------------------------------------------------------
                    .org    ICP1addr                ;Input Capture1 Interrupt Vector ...
                    reti                            ;
    ;-----------------------------------------------------------------------------
                    .org    OC1addr                 ;Output Compare1A Interrupt Vector ...
                    reti                            ;
    ;-----------------------------------------------------------------------------
                    .org    OVF1addr                ;Overflow1 Interrupt Vector Address
                    reti                            ;
    ;-----------------------------------------------------------------------------
                    .org    OVF0addr                ;Overflow0 Interrupt Vector Address
                    reti                            ;
    ;-----------------------------------------------------------------------------
                    .org    URXCaddr                ;UART Receive Complete Interrupt ...
                    reti                            ;
    ;-----------------------------------------------------------------------------
                    .org    UDREaddr                ;UART Data Register Empty Interrupt ...
                    reti                            ;
    ;-----------------------------------------------------------------------------
                    .org    UTXCaddr                ;UART Transmit Complete Interrupt ...
                    reti                            ;
    ;-----------------------------------------------------------------------------
                    .org    ACIaddr                 ;Analog Comparator Interrupt Vector ...
                    reti                            ;
    ;-----------------------------------------------------------------------------
    HardwareInit    :                               ;PROCEDURE HardwareInit ;
    ;****************                               ;BEGIN (* HardwareInit *)
                    ldi     acc,0xFF                ; [DDRB] := 0xFF ; -> PORT B - output
                    out     DDRB,acc                ;
                    ret                             ;END (* HardwareInit *) ;
    ;-----------------------------------------------------------------------------
    
    LongDelay       :                               ;PROCEDURE LongDelay ( ) ;
    ;****************                               ;BEGIN (* LongDelay *)
                    ldz     0                       ;
    LoDe_0          :                               ;
                    adiw    zl,1                    ;
                    mov     acc,zl                  ;
                    or      acc,zh                  ;
                    brne    LoDe_0                  ;
                    ret                             ;END (* LongDelay *) ;
    
    ;-----------------------------------------------------------------------------
    WaitOnStartLCD  :                               ;PROCEDURE WaitOnStartLCD ( ) ;
    ;****************                               ;BEGIN (* WaitOnStartLCD *)
                    rcall   LongDelay               ; LongDelay ( ) ;
                    rcall   LongDelay               ; LongDelay ( ) ;
                    rcall   LongDelay               ; LongDelay ( ) ;
                    rcall   LongDelay               ; LongDelay ( ) ;
                    rcall   LongDelay               ; LongDelay ( ) ;
                    rcall   LongDelay               ; LongDelay ( ) ;
                    rcall   LongDelay               ; LongDelay ( ) ;
                    rcall   LongDelay               ; LongDelay ( ) ;
                    ret                             ;END (* WaitOnStartLCD *) ;
    
    ;-----------------------------------------------------------------------------
    LCDDelay        :                               ;PROCEDURE LCDDelay ( ) ;
    ;****************                               ;BEGIN (* LCDDelay *)
                    ldi     acc,0x20                ;
    Delay_1         :                               ;
                    nop                             ;
                    dec     acc                     ;
                    brne    Delay_1                 ;
                    ret                             ;END (* LCDDelay *) ;
    ;-----------------------------------------------------------------------------
    EStrobe         :                               ;PROCEDURE EStrobe ( ) ;
    ;****************                               ;BEGIN (* EStrobe *)
                    sbi     PORTB,3                 ; [LCD.E=1] ;
                    rcall   LCDDelay                ; LCDDelay ( ) ;
                    cbi     PORTB,3                 ; [LCD.E=0] ;
                    ret                             ;END (* EStrobe *) ;
    ;-----------------------------------------------------------------------------
    Delay37ms       :                               ;PROCEDURE Delay37ms ( ) ;
    ;****************                               ;BEGIN (* Delay37ms *)
                    ldi     acc,0x80                ;
    D37_0           :                               ;
                    inc     acc                     ;
                    brne    D37_0                   ;
                    ret                             ;END (* Delay37ms *) ;
    ;-----------------------------------------------------------------------------
    
    
    
    InitialiseLCD   :                               ;PROCEDURE InitialiseLCD ( ) ;
    ;****************                               ;BEGIN (* InitialiseLCD *)
                   ;1
    			   
                 	Sbi 	PORTB,5
    				cbi     PORTB,2                 
                    rcall   EStrobe                 ; EStrobe ( ) ;
    				
    
    				;2--------------
    				rcall   Delay37ms               ; Delay37ms ( ) ;
    
    				Sbi 	PORTB,5
    				rcall	Estrobe
    				Cbi 	Portb,5
    				Sbi 	PORTB,7
    				rcall Estrobe
    				;3--------------
    				rcall   Delay37ms               ; Delay37ms ( ) ;
    
    				Cbi Portb,7
    				Sbi 	PORTB,5
    				rcall	Estrobe
    				Cbi 	Portb,5
    				Sbi 	PORTB,7
    				rcall Estrobe
    				;4--------------
    				rcall   Delay37ms               ; Delay37ms ( ) ;
    				
    				Cbi 	Portb,7
    				rcall	Estrobe
    				Sbi 	Portb,6
    				Sbi 	PORTB,7
    				rcall Estrobe
    			;5--------------
    				rcall   Delay37ms               ; Delay37ms ( ) ;
    				Cbi Portb,7
    				Cbi Portb,6
    				rcall Estrobe
    				Sbi PORTB,6
    				Sbi Portb,5
    				rcall Estrobe
    										
    ret
    
    ;-----------------------------------------------------------------------------
    Delay_1520u     :                               ;PROCEDURE Delay_1520u ( ) ;
    ;****************                               ;BEGIN (* Delay_1520u *)
                    ldz     0xF600                  ;
    D1520_0         :                               ;
                    adiw    zl,1                    ;
                    mov     acc,zl                  ;
                    or      acc,zh                  ;
                    brne    D1520_0                 ;
                    ret                             ;END (* Delay_1520u *) ;
    
    ;-----------------------------------------------------------------------------
    ResetProcessor  :                               ;
                    ldi     acc,LOW(RAMEND)         ;
                    out     SPL,acc                 ;
    Main :                                          ;BEGIN (* Main *)
                    rcall HardwareInit
    		
    				sei
    				rcall WaitOnStartLCD
    				rcall InitialiseLCD
    				
    
    					rcall Estrobe
    					Sbi Portb,4
    					rcall Estrobe
    					rcall   Delay_1520u 
    
    			Sbi     PORTB,2
    			Cbi Portb,4
    			Sbi Portb,5
    			Sbi Portb,6
    			rcall Estrobe
    			Sbi Portb,4
    			Cbi Portb,5
    			Cbi Portb,6
    			rcall Estrobe
    							rcall   Delay37ms 
    											rcall   Delay37ms 
    											rcall   Delay37ms 
    
    
    Main_0  :       rjmp    Main_0                  ; HALT ;
    
    .exit
    


    Może kod nie jest doskonały. Chodziło mi tylko o wyswietlenie choćby jednej literki!! Sterownik to HD44780. Jeśli ktoś mógłby zweryfikować kod...

    PS a jesli ktos ma .hex dla ZL1AVR to też proszę o kontakt.
  • REKLAMA
  • #2 4084765
    ProeXtreme
    Poziom 12  
    Posty: 59
    Ocena: 2
    Dlaczego pod Bascomem nie mogłeś? Mogę Ci napisać jakiś program w Bascomie i napisać jak mają być podłączone wyprowadzenia µC to LCD
  • REKLAMA
  • #3 4087242
    dr00id88
    Poziom 11  
    Posty: 24
    Rzecz w tym że nawet domyślnych w Bascomie nie trzeba zmieniać. Nawet w helpie są te same:] ATTiny2313.
  • REKLAMA
  • #4 4088329
    Xsid
    Poziom 14  
    Posty: 109
    Pomógł: 5
    Ocena: 6
    ja też mam ten wyświetlacz i nie działa, moze ma inne rozkazy?
    czy ktoś rozwiązał ten problem?
  • #5 4090295
    ProeXtreme
    Poziom 12  
    Posty: 59
    Ocena: 2
    Wydaje mi się, że wszystkie wyświetlacze 16*2 są podobne. Spróbuj wpisać ten program do mikroklocka (w Bascom, program z książki do zl2avr):
    
    $regfile = "2313def.dat"           '<---nazwa uC
    $crystal = 8000000                  '<---częstotliwość taktowania oscylatora
    Config Lcd = 16 * 2
    Config Lcdpin = Pin , Db4 = Portc.3 , Db5 = Portc.2 , Db6 = Portc.1 , Db7 = Portc.0 , E = Portc.4 , Rs = Portc.5
    Dim I As Byte
    Cls
    Lcd "* Bascom AVR *"
    Wait 1
    Lowerline
    Wait 1
    Lcd "przesuwaj"
    Wait 1
    
    For I = 1 To 10
    
       Shiftlcd Right
    
       Waitms 500
    Next I
    For I = 1 To 10
    
       Shiftlcd Left
    
       Waitms 500
    Next I
    '(Cls
    Lowerline
    Waitms 100
    Lcd "xD Serio, serio xD"
    Waitms 50
    For I = 1 To 2
    
       Shiftlcd Left
    
       Waitms 50
    Next I
    Cls
    ')
    Locate 2 , 2
    
    Lcd "*"
    Wait 1
    Shiftcursor Right
    Lcd "%"
    
    Wait 1
    Home Upper
    
    Lcd "inny tekst"
    Wait 2
    'For I = 1 To 8
    
     '  Shiftlcd Left
    
      ' Waitms 50
    'Next I
    Wait 2
    Cursor Off Noblink
    Wait 2
    Cursor On Blink
    Wait 2
    Display Off
    Wait 2
    Display On
    
    Deflcdchar 0 , 31 , 31 , 31 , 31 , 30 , 28 , 24 , 16
    Deflcdchar 1 , 1 , 3 , 7 , 15 , 31 , 31 , 31 , 31
    
    Cls
    Lcd Chr(0) ; Chr(1)
    
    Wait 1
    Cls
    _temp1 = 56
    
    RCALL _write_lcd
    
    Wait 2
    Lowerline
    
    I = 150
    Lcd I
    End
    

    P.S.: Na życzenie mogę włożyć gotowy plik .hex , jak nie będzie działać to pobaw się trochę kontrastem lub zmień nazwę uC (jeśli masz inny np. ATmega8 ---> "m8def.dat"
REKLAMA