;Steuerprogramm fuer LCD Testmodul

;Verwendete Hardware:
; ESEM 80535 Board, Testboard für LCD Modul
;
;Erstellt: Maerz 2001, Klaus Leidinger
;
;Letzte Aenderung:
;22.03.01 Code Syntax für RAD51 angepasst

;------------------------------------------------------------------------------

ChipType equ 51     ; Typ des verwendeten Prozessors 52/535/1051/20514051, 8051 ist default


;Definitionen fuer LC-Display (falls verwendet)

DISPtype equ 20  ;Zahl ist Anzahl der Stellen, je nach Display
LCDlines equ 1   ;für 1 oder 2 für 2 zeilige Displays
LCDModus equ 4   ;4 Bit Ansteuerung, 8 für 8 Bit Datenbus

 if ChipType = 51
    incl "MOD51.H"  ; Erweiterte Definitionen für 8051 (P1_0 usw.)
  endif



;  org   050H             ;internes RAM, 1. freie Adresse

;Definition der Programmtypischen Variablen/Labels

;Adressen des LCD Ports
  if LCDModus=8
LCD_daten equ P1
LCD_Busy  equ P1_7       ;Siehe Datenblatt, abfrage Status
LCD_RS    equ P2_7
LCD_RW    equ P2_6
LCD_E     equ P2_5
LCD_Light equ P1_4       ; 
  endif 
;      
  if LCDModus=4
LCD_daten equ P2
LCD_Busy  bit P2_3       ;Siehe Datenblatt, abfrage Status
LCD_RS    bit P2_7
LCD_RW    bit P2_6
LCD_E     bit P2_5
LCD_Light bit P2_4
  endif
  
Tastatur equ 0     ;Wenn Tastatur angeschlossen, anzahl der Tasten eingeben, sonst 0
Trailer equ 1       ;Lauflicht am Anfang


;Anschluss und Typ der Tastatur
  if Tastatur=12
Keypad equ P1
Key_row1 bit P1_3
Key_row2 bit P1_2
Key_row3 bit P1_1
Key_row4 bit P1_0
Key_col1 bit P1_6
Key_col2 bit P1_5
Key_col3 bit P1_4
Key_col4 bit P1_7  ;Dummyeintrag, damit gleiche Source verwendet werden kann
Key_nokeyval equ  11110000B  ;Setzt alle Reihen auf "L"
Key_numcol equ 3             ;Anzahl der Spalten
  endif

  if Tastatur=16
Keypad   equ P1
Key_row1 bit P1_7
Key_row2 bit P1_6
Key_row3 bit P1_5
Key_row4 bit P1_4
Key_col1 bit P1_3
Key_col2 bit P1_2
Key_col3 bit P1_1
Key_col4 bit P1_0
Key_nokeyval equ  00001111B  ;Setzt alle Reihen auf "L"
Key_numcol equ 4             ;Anzahl der Spalten
  endif



; Start des Programmcodes
          org 0000H      ;Programmstart
        ljmp STARTPROG
          org 0033H      ;Ende der Interrupttabelle


  db "Testprogramm LCD Ansteuerung V1.0 "
  db "Klaus Leidinger vom 23.03.01"

          org 0100H      ;Programmstart


STARTPROG               ;Start des eigentlichen Programms
       mov  SP,#0DFH    ;Stack setzen
       lcall LCDini     ;initialisierung des Displays
       lcall LCDLight_on
LCD_Endloop
  if Trailer            ;Wenn ein LCD Modul angeschlossen ist
       lcall LCDcls     ;Clear Display
       mov DPTR,#Text1  ;Lade Text1
       lcall LCDtxtL    ;Text als Lauftext ausgeben
       lcall LCDwait    ;warten bis Text gelesen ist ;-)
       lcall LCDhome    ;Cursor auf zurück Startposition
       mov DPTR,#Text2  ;Lade Text2
       lcall LCDtxtL    ;und nochmal das ganze...
       lcall LCDwait
       lcall LCDhome
  if Tastatur=0        ;Falls keine Tastatur angeschlossen ist, Endloop
       ajmp LCD_Endloop
  endif

  endif  ;Trailer

  if Tastatur             ;falls keine Tastatur angeschlossen, ignorieren
Keyloopreset
       lcall LCDcls       ;Lösche Display
       mov DPTR,#Text3    ;Lade Text3
       lcall LCDtxt       ;Ausgabe Text3
       mov R5,#DISPtype-4 ;Zähler für Anzahl Stellen minus Text "Key:"
Endloop                   ;Ewig weiter bis zum Reset
       lcall KEYascii     ;holt direkt den Asciiwert der Taste
       jnc   Endloop      ;Carry=0, keine Taste gedrückt
       lcall LCDchr       ;bei Carry=1, Ausgabe der Taste
       lcall KEYrelease   ;warte bis Taste losgelassen
       djnz R5,Endloop    ;R5 zählt bis Zeilenende
       ajmp Keyloopreset  ;Bei Zeilenende wieder von vorne
   endif

Text1  db "LCD - Board Test",0 ;0 ist Textende Erkennung

Text2  db "                ",0
Text3  db "Key:",0

  if LCDModus=8
    incl "LCD_at89.LIB"   ;LCD Library für 8 Bit Ansteuerung
  endif
  if LCDModus=4
    incl "lcd4at89.lib"    ;LCD Library für 4 Bit Ansteuerung
  endif
  if Tastatur
    incl "keypad.lib"      ;Keypad Library
  endif
  
END                    ;letzte Zeile des Programmes

