hello_world
Newbie level 2
- Joined
- Feb 15, 2014
- Messages
- 2
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 16
Hello,
I have project to do and it is completed in 90%. My problem is how to save ACC (0-9) to EEPROM.
CD-ROM contains example code how to use FlashEE, but my 52 saves something, but I don't know what
It's code for garage door using LCD display, engine not works but lecturer says that is not problem. It reads from FlashEE number of pages, if it's 1 goes to READFLASH else goes to START. On INC_L and INC# it's saves ACC in WRITEFLASH.
My code:
And example code from CD-ROM:
Datasheet of ADuC842: https://www.analog.com/en/processors-dsp/analog-microcontrollers/aduc842/products/product.html
Comments are in polish so if you want to know what they mean please use google translate My lecturer is old school so he does not know English well.
If someone finds solution I will be gratefull, at this time i will struggle with this problem.
I have project to do and it is completed in 90%. My problem is how to save ACC (0-9) to EEPROM.
CD-ROM contains example code how to use FlashEE, but my 52 saves something, but I don't know what
It's code for garage door using LCD display, engine not works but lecturer says that is not problem. It reads from FlashEE number of pages, if it's 1 goes to READFLASH else goes to START. On INC_L and INC# it's saves ACC in WRITEFLASH.
My code:
Code:
$MOD842 ; use 8052 predefined symbols
; --------------------------------------
; definicja polaczenia lcd z uC
; --------------------------------------
LCD_D4 EQU P2.1
LCD_D5 EQU P2.0
LCD_D6 EQU P2.3
LCD_D7 EQU P2.2
LCD_E EQU P2.5
LCD_RW EQU P2.4
LCD_RS EQU P2.7
LCD_KEY EQU P2.6
LCD_PORT EQU P2
LCD_DATA EQU 30h ; KOMORKA PAMIECI Z KToREJ BAJT WYSYLANY
; DO WYSWIETLACZA
BUTTON EQU P3.2 ; Przycisk INT0
READ EQU 01h ; FlashEE command: 'read page'
WRITE EQU 02h ; FlashEE command: 'write page'
VERIFY EQU 04h ; FlashEE command: 'verify page'
ERASE EQU 05h ; FlashEE command: 'erase page'
ERASEALL EQU 06h ; FlashEE command: 'erase all'
ORG 0000h
CALL LCD_INIT ; Inicjalizacja wyswietlacza LCD
; --------------------------------------
; Zapisanie polskich znakow do CG RAM -
; --------------------------------------
MOV LCD_DATA, #40h ; Ustawienie kursora na pierwszy
ACALL LCD_ROZKAZ ; znak pamieci CG RAM
MOV DPTR, #TAB_3
CALL CIAG_ZN ; Wyslanie do LCD ciagu znakow z
; z tablicy 3 do CG RAM o adresie
; podanym w DPTR konczacego sie 80h
MAIN:
MOV EADRH, #0 ; set data FlashEE address to page 0
MOV EADRL, #0
READFLASH:
MOV ECON, #READ ; read current 4byte page of FlashEE
; into EDATA1,2,3,4
MOV A, EDATA4
CJNE A, #1, START ; if EDATA4 is 1, then page contains
; a valid ACC
; => read EEPROM
; otherwise jump to START
READ_EE:
CALL READ1_L
JMP START
READ1_L:
CLR A
MOV DPL, A
MOV DPH, A ; clear DPTR
MOV DPP, A
MOV R6, #EDATA3
MOV A, #0
CJNE R6, #0, READ2_L
MOV LCD_DATA, #01h ; czyszczenie ekranu
ACALL LCD_ROZKAZ
MOV LCD_DATA, #80h ; kursor na 1 linii
ACALL LCD_ROZKAZ
MOV DPTR, #EDATA1_0
CALL CIAG_ZN
CALL DLY3
RET
READ2_L:
DEC R6
INC ACC
CJNE R6, #0, READ2_L
PUSH ACC
CALL WAIT_D
JMP DEC_L
START:
CLR A
MOV A, #0
CALL RESET_L
WRITEFLASH:
MOV ECON, #ERASEALL ; clear all data FlashEE memory
MOV EADRH, #0
MOV EADRL, #0
WRITE_EE:
CALL WRITE1_L
MOV EDATA1, DPL ; place DPTR in EDATA1,2,3
MOV EDATA2, DPH
; MOV EDATA3, DPP
MOV EDATA4, #1 ; put 1 in EDATA4 as identifier
MOV ECON, #WRITE ; write EDATA1-4 into pre-erased
; page of FlashEE data memory
MOV ECON, #VERIFY ; verify current page is same as
MOV A, ECON ; EDATA1-4. If same, ECON=0.
JNZ WRITEFLASH ; if verify fails, jump to RECORD
RET
WRITE1_L:
CLR A
; MOV DPL,A
; MOV DPH,A ; clear DPTR
; MOV DPP,A
; MOV DPTR, #0
POP ACC
MOV R5, A
PUSH ACC
CJNE R5, #0, WRITE2_L
MOV EDATA3, #0
RET
WRITE2_L:
INC EDATA3
DEC R5
CJNE R5, #0, WRITE2_L
RET
INC_L:
MOV LCD_DATA, #01h ; czyszczenie ekranu
ACALL LCD_ROZKAZ
MOV LCD_DATA, #80h ; kursor na 1 linii
ACALL LCD_ROZKAZ
MOV DPTR, #INC_TXT
CALL CIAG_ZN
CLR A
POP ACC
CJNE A, #0, INC1 ; if A != 0 goto INC1
; else
; ++++++++++++++++++++++++++++++++++++++
PUSH ACC
MOV LCD_DATA, #0c0h ; kursor na 2 linii
ACALL LCD_ROZKAZ
MOV DPTR, #NUM0_T ; 0
CALL CIAG_ZN
CALL DLY3
CLR A
POP ACC
INC ACC
PUSH ACC
CALL WRITEFLASH
JMP INC_L
; ======================================
INC1:
PUSH ACC
MOV LCD_DATA, #01h ; czyszczenie ekranu
ACALL LCD_ROZKAZ
MOV LCD_DATA, #80h ; kursor na 1 linii
ACALL LCD_ROZKAZ
MOV DPTR, #INC_TXT
CALL CIAG_ZN
POP ACC
CJNE A, #1, INC2 ; if A != 1 goto INC2
; else
; ++++++++++++++++++++++++++++++++++++++
PUSH ACC
MOV LCD_DATA, #0c0h ; kursor na 2 linii
ACALL LCD_ROZKAZ
MOV DPTR, #NUM1_T ; 1
CALL CIAG_ZN
CALL DLY3
CLR A
POP ACC
INC ACC
PUSH ACC
CALL WRITEFLASH
JMP INC_L
; ======================================
INC2:
PUSH ACC
MOV LCD_DATA, #01h ; czyszczenie ekranu
ACALL LCD_ROZKAZ
MOV LCD_DATA, #80h ; kursor na 1 linii
ACALL LCD_ROZKAZ
MOV DPTR, #INC_TXT
CALL CIAG_ZN
POP ACC
CJNE A, #2, INC3 ; if A != 2 goto INC3
; else
; ++++++++++++++++++++++++++++++++++++++
PUSH ACC
MOV LCD_DATA, #0c0h ; kursor na 2 linii
ACALL LCD_ROZKAZ
MOV DPTR, #NUM2_T ; 2
CALL CIAG_ZN
CALL DLY3
CLR A
POP ACC
INC ACC
PUSH ACC
CALL WRITEFLASH
JMP INC_L
; ======================================
INC3:
PUSH ACC
MOV LCD_DATA, #01h ; czyszczenie ekranu
ACALL LCD_ROZKAZ
MOV LCD_DATA, #80h ; kursor na 1 linii
ACALL LCD_ROZKAZ
MOV DPTR, #INC_TXT
CALL CIAG_ZN
POP ACC
CJNE A, #3, INC4 ; if A != 3 goto INC4
; else
; ++++++++++++++++++++++++++++++++++++++
PUSH ACC
MOV LCD_DATA, #0c0h ; kursor na 2 linii
ACALL LCD_ROZKAZ
MOV DPTR, #NUM3_T ; 3
CALL CIAG_ZN
CALL DLY3
CLR A
POP ACC
INC ACC
PUSH ACC
CALL WRITEFLASH
JMP INC_L
; ======================================
INC4:
PUSH ACC
MOV LCD_DATA, #01h ; czyszczenie ekranu
ACALL LCD_ROZKAZ
MOV LCD_DATA, #80h ; kursor na 1 linii
ACALL LCD_ROZKAZ
MOV DPTR, #INC_TXT
CALL CIAG_ZN
POP ACC
CJNE A, #4, INC5 ; if A != 4 goto INC5
; else
; ++++++++++++++++++++++++++++++++++++++
PUSH ACC
MOV LCD_DATA, #0c0h ; kursor na 2 linii
ACALL LCD_ROZKAZ
MOV DPTR, #NUM4_T ; 4
CALL CIAG_ZN
CALL DLY3
CLR A
POP ACC
INC ACC
PUSH ACC
CALL WRITEFLASH
JMP INC_L
; ======================================
INC5:
PUSH ACC
MOV LCD_DATA, #01h ; czyszczenie ekranu
ACALL LCD_ROZKAZ
MOV LCD_DATA, #80h ; kursor na 1 linii
ACALL LCD_ROZKAZ
MOV DPTR, #INC_TXT
CALL CIAG_ZN
POP ACC
CJNE A, #5, INC6 ; if A != 5 goto INC6
; else
; ++++++++++++++++++++++++++++++++++++++
PUSH ACC
MOV LCD_DATA, #0c0h ; kursor na 2 linii
ACALL LCD_ROZKAZ
MOV DPTR, #NUM5_T ; 5
CALL CIAG_ZN
CALL DLY3
CLR A
POP ACC
INC ACC
PUSH ACC
CALL WRITEFLASH
JMP INC_L
; ======================================
INC6:
PUSH ACC
MOV LCD_DATA, #01h ; czyszczenie ekranu
ACALL LCD_ROZKAZ
MOV LCD_DATA, #80h ; kursor na 1 linii
ACALL LCD_ROZKAZ
MOV DPTR, #INC_TXT
CALL CIAG_ZN
POP ACC
CJNE A, #6, INC7 ; if A != 6 goto INC7
; else
; ++++++++++++++++++++++++++++++++++++++
PUSH ACC
MOV LCD_DATA, #0c0h ; kursor na 2 linii
ACALL LCD_ROZKAZ
MOV DPTR, #NUM6_T ; 6
CALL CIAG_ZN
CALL DLY3
CLR A
POP ACC
INC ACC
PUSH ACC
CALL WRITEFLASH
JMP INC_L
; ======================================
INC7:
PUSH ACC
MOV LCD_DATA, #01h ; czyszczenie ekranu
ACALL LCD_ROZKAZ
MOV LCD_DATA, #80h ; kursor na 1 linii
ACALL LCD_ROZKAZ
MOV DPTR, #INC_TXT
CALL CIAG_ZN
POP ACC
CJNE A, #7, INC8 ; if A != 7 goto INC8
; else
; ++++++++++++++++++++++++++++++++++++++
PUSH ACC
MOV LCD_DATA, #0c0h ; kursor na 2 linii
ACALL LCD_ROZKAZ
MOV DPTR, #NUM7_T ; 7
CALL CIAG_ZN
CALL DLY3
CLR A
POP ACC
INC ACC
PUSH ACC
CALL WRITEFLASH
JMP INC_L
; ======================================
INC8:
PUSH ACC
MOV LCD_DATA, #01h ; czyszczenie ekranu
ACALL LCD_ROZKAZ
MOV LCD_DATA, #80h ; kursor na 1 linii
ACALL LCD_ROZKAZ
MOV DPTR, #INC_TXT
CALL CIAG_ZN
POP ACC
CJNE A, #8, INC9 ; if A != 8 goto INC9
; else
; ++++++++++++++++++++++++++++++++++++++
PUSH ACC
MOV LCD_DATA, #0c0h ; kursor na 2 linii
ACALL LCD_ROZKAZ
MOV DPTR, #NUM8_T ; 8
CALL CIAG_ZN
CALL DLY3
CLR A
POP ACC
INC ACC
PUSH ACC
CALL WRITEFLASH
JMP INC_L
; ======================================
INC9:
PUSH ACC
MOV LCD_DATA, #01h ; czyszczenie ekranu
ACALL LCD_ROZKAZ
MOV LCD_DATA, #80h ; kursor na 1 linii
ACALL LCD_ROZKAZ
MOV DPTR, #INC_TXT
CALL CIAG_ZN
POP ACC
CJNE A, #9, ERR_I ; if A != 9 goto ERR
; else
; ++++++++++++++++++++++++++++++++++++++
PUSH ACC
MOV LCD_DATA, #0c0h ; kursor na 2 linii
ACALL LCD_ROZKAZ
MOV DPTR, #NUM9_T ; 9
CALL CIAG_ZN
CLR A
CALL WAIT_D ; ===== TUTAJ DO WAIT FOR INT0 =====
JMP DEC_L
; ======================================
ERR_I:
MOV LCD_DATA, #01h ; czyszczenie ekranu
ACALL LCD_ROZKAZ
MOV LCD_DATA, #80h ; kursor na 1 linii
ACALL LCD_ROZKAZ
MOV DPTR, #ERR_T
CALL CIAG_ZN
JMP PTL
DEC_L:
; PUSH ACC
MOV LCD_DATA, #01h ; czyszczenie ekranu
ACALL LCD_ROZKAZ
MOV LCD_DATA, #80h ; kursor na 1 linii
ACALL LCD_ROZKAZ
MOV DPTR, #DEC_TXT
CALL CIAG_ZN
POP ACC
CJNE A, #9, DEC8 ; if A != 9 goto DEC8
; else
; ++++++++++++++++++++++++++++++++++++++
PUSH ACC
MOV LCD_DATA, #0c0h ; kursor na 2 linii
ACALL LCD_ROZKAZ
MOV DPTR, #NUM9_T ; 9
CALL CIAG_ZN
CALL DLY3
CLR A
POP ACC
DEC ACC
PUSH ACC
CALL WRITEFLASH
JMP DEC_L
; ======================================
DEC8:
PUSH ACC
MOV LCD_DATA, #01h ; czyszczenie ekranu
ACALL LCD_ROZKAZ
MOV LCD_DATA, #80h ; kursor na 1 linii
ACALL LCD_ROZKAZ
MOV DPTR, #DEC_TXT
CALL CIAG_ZN
POP ACC
CJNE A, #8, DEC7 ; if A != 8 goto DEC7
; else
; ++++++++++++++++++++++++++++++++++++++
PUSH ACC
MOV LCD_DATA, #0c0h ; kursor na 2 linii
ACALL LCD_ROZKAZ
MOV DPTR, #NUM8_T ; 8
CALL CIAG_ZN
CALL DLY3
CLR A
POP ACC
DEC ACC
PUSH ACC
CALL WRITEFLASH
JMP DEC_L
; ======================================
DEC7:
PUSH ACC
MOV LCD_DATA, #01h ; czyszczenie ekranu
ACALL LCD_ROZKAZ
MOV LCD_DATA, #80h ; kursor na 1 linii
ACALL LCD_ROZKAZ
MOV DPTR, #DEC_TXT
CALL CIAG_ZN
POP ACC
CJNE A, #7, DEC6 ; if A != 7 goto DEC6
; else
; ++++++++++++++++++++++++++++++++++++++
PUSH ACC
MOV LCD_DATA, #0c0h ; kursor na 2 linii
ACALL LCD_ROZKAZ
MOV DPTR, #NUM7_T ; 7
CALL CIAG_ZN
CALL DLY3
CLR A
POP ACC
DEC ACC
PUSH ACC
CALL WRITEFLASH
JMP DEC_L
; ======================================
DEC6:
PUSH ACC
MOV LCD_DATA, #01h ; czyszczenie ekranu
ACALL LCD_ROZKAZ
MOV LCD_DATA, #80h ; kursor na 1 linii
ACALL LCD_ROZKAZ
MOV DPTR, #DEC_TXT
CALL CIAG_ZN
POP ACC
CJNE A, #6, DEC5 ; if A != 6 goto DEC5
; else
; ++++++++++++++++++++++++++++++++++++++
PUSH ACC
MOV LCD_DATA, #0c0h ; kursor na 2 linii
ACALL LCD_ROZKAZ
MOV DPTR, #NUM6_T ; 6
CALL CIAG_ZN
CALL DLY3
CLR A
POP ACC
DEC ACC
PUSH ACC
CALL WRITEFLASH
JMP DEC_L
; ======================================
DEC5:
PUSH ACC
MOV LCD_DATA, #01h ; czyszczenie ekranu
ACALL LCD_ROZKAZ
MOV LCD_DATA, #80h ; kursor na 1 linii
ACALL LCD_ROZKAZ
MOV DPTR, #DEC_TXT
CALL CIAG_ZN
POP ACC
CJNE A, #5, DEC4 ; if A != 5 goto DEC4
; else
; ++++++++++++++++++++++++++++++++++++++
PUSH ACC
MOV LCD_DATA, #0c0h ; kursor na 2 linii
ACALL LCD_ROZKAZ
MOV DPTR, #NUM5_T ; 5
CALL CIAG_ZN
CALL DLY3
CLR A
POP ACC
DEC ACC
PUSH ACC
CALL WRITEFLASH
JMP DEC_L
; ======================================
DEC4:
PUSH ACC
MOV LCD_DATA, #01h ; czyszczenie ekranu
ACALL LCD_ROZKAZ
MOV LCD_DATA, #80h ; kursor na 1 linii
ACALL LCD_ROZKAZ
MOV DPTR, #DEC_TXT
CALL CIAG_ZN
POP ACC
CJNE A, #4, DEC3 ; if A != 4 goto DEC3
; else
; ++++++++++++++++++++++++++++++++++++++
PUSH ACC
MOV LCD_DATA, #0c0h ; kursor na 2 linii
ACALL LCD_ROZKAZ
MOV DPTR, #NUM4_T ; 4
CALL CIAG_ZN
CALL DLY3
CLR A
POP ACC
DEC ACC
PUSH ACC
CALL WRITEFLASH
JMP DEC_L
; ======================================
DEC3:
PUSH ACC
MOV LCD_DATA, #01h ; czyszczenie ekranu
ACALL LCD_ROZKAZ
MOV LCD_DATA, #80h ; kursor na 1 linii
ACALL LCD_ROZKAZ
MOV DPTR, #DEC_TXT
CALL CIAG_ZN
POP ACC
CJNE A, #3, DEC2 ; if A != 3 goto DEC2
; else
; ++++++++++++++++++++++++++++++++++++++
PUSH ACC
MOV LCD_DATA, #0c0h ; kursor na 2 linii
ACALL LCD_ROZKAZ
MOV DPTR, #NUM3_T ; 3
CALL CIAG_ZN
CALL DLY3
CLR A
POP ACC
DEC ACC
PUSH ACC
CALL WRITEFLASH
JMP DEC_L
; ======================================
DEC2:
PUSH ACC
MOV LCD_DATA, #01h ; czyszczenie ekranu
ACALL LCD_ROZKAZ
MOV LCD_DATA, #80h ; kursor na 1 linii
ACALL LCD_ROZKAZ
MOV DPTR, #DEC_TXT
CALL CIAG_ZN
POP ACC
CJNE A, #2, DEC1 ; if A != 2 goto DEC1
; else
; ++++++++++++++++++++++++++++++++++++++
PUSH ACC
MOV LCD_DATA, #0c0h ; kursor na 2 linii
ACALL LCD_ROZKAZ
MOV DPTR, #NUM2_T ; 2
CALL CIAG_ZN
CALL DLY3
CLR A
POP ACC
DEC ACC
PUSH ACC
CALL WRITEFLASH
JMP DEC_L
; ======================================
DEC1:
PUSH ACC
MOV LCD_DATA, #01h ; czyszczenie ekranu
ACALL LCD_ROZKAZ
MOV LCD_DATA, #80h ; kursor na 1 linii
ACALL LCD_ROZKAZ
MOV DPTR, #DEC_TXT
CALL CIAG_ZN
POP ACC
CJNE A, #1, DEC0 ; if A != 1 goto DEC0
; else
; ++++++++++++++++++++++++++++++++++++++
PUSH ACC
MOV LCD_DATA, #0c0h ; kursor na 2 linii
ACALL LCD_ROZKAZ
MOV DPTR, #NUM1_T ; 1
CALL CIAG_ZN
CALL DLY3
CLR A
POP ACC
DEC ACC
PUSH ACC
CALL WRITEFLASH
JMP DEC_L
; ======================================
DEC0:
PUSH ACC
MOV LCD_DATA, #01h ; czyszczenie ekranu
ACALL LCD_ROZKAZ
MOV LCD_DATA, #80h ; kursor na 1 linii
ACALL LCD_ROZKAZ
MOV DPTR, #DEC_TXT
CALL CIAG_ZN
POP ACC
CJNE A, #0, ERR_D ; if A != 0 goto ERR
; else
; ++++++++++++++++++++++++++++++++++++++
PUSH ACC
MOV LCD_DATA, #0c0h ; kursor na 2 linii
ACALL LCD_ROZKAZ
MOV DPTR, #NUM8_T ; 8
CALL CIAG_ZN
CALL WRITEFLASH
CLR A
CALL WAIT_I ; ===== TUTAJ DO WAIT FOR INT0 =====
JMP INC_L
ERR_D:
MOV LCD_DATA, #01h ; czyszczenie ekranu
ACALL LCD_ROZKAZ
MOV LCD_DATA, #80h ; kursor na 1 linii
ACALL LCD_ROZKAZ
MOV DPTR, #ERR_T
CALL CIAG_ZN
JMP PTL
; --------------------------------------
; 1 sekundowa przerwa -
; --------------------------------------
DLY3:
MOV R4, #0Ah ; definicja ilości powtórzeń pętli 3 (10)
PETLA3:
MOV R3, #0C8h ; definicja ilości powtórzeń pętli 2 (200)
PETLA2:
MOV R2, #0F8h ; definicja ilości powtórzeń pętli 1 (248)
PETLA1:
DJNZ R2, PETLA1 ; wykonanie pętli 1
DJNZ R3, PETLA2 ; wykonanie pętli 2
DJNZ R4, PETLA3 ; wykonanie pętli 3
RET
; --------------------------------------
RESET_L:
MOV LCD_DATA, #01h ; czyszczenie ekranu
ACALL LCD_ROZKAZ
MOV LCD_DATA, #80h ; kursor na 1 linii
ACALL LCD_ROZKAZ
MOV DPTR, #PROG_T1
CALL CIAG_ZN
MOV LCD_DATA, #0c0h ; kursor na 2 linii
ACALL LCD_ROZKAZ
MOV DPTR, #PROG_T2
CALL CIAG_ZN
CALL DLY3
CALL DLY3
CALL DLY3
CALL WAIT_I
JMP INC_L
; --------------------------------------
WAIT_I:
CALL WAIT_C
MOV LCD_DATA, #0c0h ; kursor na 2 linii
ACALL LCD_ROZKAZ
MOV DPTR, #CLOSED_T
CALL CIAG_ZN
JB BUTTON, $ ; Oczekiwanie na wcisniecie INT0
RET
; --------------------------------------
WAIT_D:
CALL WAIT_C
MOV LCD_DATA, #0c0h ; kursor na 2 linii
ACALL LCD_ROZKAZ
MOV DPTR, #OPEN_T
CALL CIAG_ZN
JB BUTTON, $ ; Oczekiwanie na wcisniecie INT0
RET
; --------------------------------------
WAIT_C:
MOV LCD_DATA, #01h ; czyszczenie ekranu
ACALL LCD_ROZKAZ
MOV LCD_DATA, #80h ; kursor na 1 linii
ACALL LCD_ROZKAZ
MOV DPTR, #WAIT_T
CALL CIAG_ZN
RET
; --------------------------------------
PTL:
JMP PTL
; --------------------------------------
; Initializacja LCD -
; --------------------------------------
LCD_INIT:
MOV LCD_PORT, #00h
MOV LCD_DATA, #33h ; Pierwsze slowo dodatkowe progr. LCD
ACALL LCD_ROZKAZ
MOV LCD_DATA, #32h ; Drugie slowo dodatkowe progr. LCD
ACALL LCD_ROZKAZ
MOV LCD_DATA, #28h ; Czterobitowy interfejs (F)
; Dwa wiersze, znak 5x7 punktow
; MOV LCD_DATA, #2Ch ; Czterobitowy interfejs (F)
; ; Dwa wiersze, znak 5x10 punktow
ACALL LCD_ROZKAZ
MOV LCD_DATA, #01h ; Czyszcz. ekranu, kursor na 0
ACALL LCD_ROZKAZ ; (A)
MOV LCD_DATA, #0Fh ; Wlaczenie ekranu i kursora
ACALL LCD_ROZKAZ ; mrugajacego (D)
RET
; --------------------------------------
; Wyslanie pojedynczego rozkazu z -
; LCD_DATA do wyswietlacza -
; --------------------------------------
LCD_ROZKAZ:
MOV LCD_PORT, #00h
ACALL LCD_WRITE4
ACALL LCD_WRITE4
ACALL DELAY
RET
; --------------------------------------
; Wyswietlenie pojedynczego znaku z -
; LCD_DATA na wyswietlacz -
; --------------------------------------
LCD_DISPLAY_CHAR:
SETB LCD_RS
ACALL LCD_WRITE4
ACALL LCD_WRITE4
ACALL DELAY
RET
DELAY:
PUSH LCD_PORT ; Odczyt BF
CLR LCD_RS
setb LCD_D7
setb LCD_RW
setb LCD_E
jb LCD_D7,$ ;Oczekiwanie na zgloszenie gotowosci
setb LCD_KEY
POP LCD_PORT
ret
LCD_WRITE4:
PUSH ACC
CLR LCD_E
MOV A, LCD_DATA
RLC A
MOV LCD_D7, C ; D7
RLC A
MOV LCD_D6, C ; D6
RLC A
MOV LCD_D5, C ; D5
RLC A
MOV LCD_D4, C ; D4
SETB LCD_E ; STROB
CLR LCD_E
MOV LCD_DATA, A
POP ACC
RET
; --------------------------------------
; Wylanie ciagu znakow rozpoczynajacych-
; sie od adresu podanego w DPTR i -
; zakonczonego 80h (jest to znak nie -
; definiujacy znak wyswietlany na -
; wyswietlaczu oraz znak do CG RAM ) -
; --------------------------------------
CIAG_ZN:
NOP
K_ZNAK:
MOV A, #0
MOVC A, @A+DPTR
ADD A, #80H
JZ K_STR
ADD A, #80H
INC DPTR
MOV LCD_DATA, A
CALL LCD_DISPLAY_CHAR
JMP K_ZNAK
K_STR:
RET
; --------------------------------------
INC_TXT:
DB 'Otwieranie: '
DB 80h
DEC_TXT:
DB 'Zamykanie: '
DB 80h
NUM0_T:
DB '0'
DB 80h
NUM1_T:
DB '1'
DB 80h
NUM2_T:
DB '2'
DB 80h
NUM3_T:
DB '3'
DB 80h
NUM4_T:
DB '4'
DB 80h
NUM5_T:
DB '5'
DB 80h
NUM6_T:
DB '6'
DB 80h
NUM7_T:
DB '7'
DB 80h
NUM8_T:
DB '8'
DB 80h
NUM9_T:
DB '9'
DB 80h
ERR_T:
DB 'Blad licznika!'
DB 80H
DLY_T:
DB 'Op',4,6,'nienie'
DB 80h
WAIT_T:
DB 'Wci',5,'nij INT0'
DB 80h
PROG_T1:
DB 'Witam w program'
DB 80H
PROG_T2:
DB 'ie bramy gara',7,'.'
DB 80H
CLOSED_T:
DB 'Brama zamkni',2,'ta'
DB 80H
OPEN_T:
DB 'Brama otwarta'
DB 80H
EDATA1_0:
DB 'EDATA1_0'
DB 80H
EDATA1_N0:
DB 'EDATA1_N0'
DB 80H
WAIT_TXT:
DB 'Oczekiwanie'
DB 80H
; --------------------------------------
; zdefiniowane polskie znaki gdyby -
; jakis tkst je zawieral to nalezy -
; napisac (Grzegrzolka): -
; DB 'Grzegrz', 4, 3, 'ka' -
; --------------------------------------
TAB_3:
DB 0, 0, 14, 1, 15, 17, 15, 2 ;znak ą o kodzie 0
DB 4, 0, 15, 16, 16, 17, 15, 0 ;znak ć o kodzie 1
DB 0, 0, 14, 17, 31, 16, 14, 2 ;znak ę o kodzie 2
DB 12, 4, 6, 4, 12, 4, 14, 0 ;znak ł o kodzie 3
DB 2, 4, 14, 17, 17, 17, 14, 0 ;znak ó o kodzie 4
DB 2, 4, 14, 16, 14, 1, 30, 0 ;znak ś o kodzie 5
; DB 2, 4, 22, 25, 17, 17, 17, 0 ;znak ń o kodzie 5
DB 2, 4, 14, 16, 14, 1, 30, 0 ;znak ź o kodzie 6
DB 4, 0, 31, 2, 4, 8, 31, 0 ;znak ż o kodzie 7
DB 80h
END
And example code from CD-ROM:
Code:
;********************************************************************
;
; Author : ADI - Apps www.analog.com/MicroConverter
;
; Date : October 2003
;
; File : dataflsh.asm
;
; Hardware : ADuC842/ADuC843
;
; Description : Demonstrates use of the on-chip read/write 4096 byte
; FlashEE data memory space. Stores a sequence of
; button presses (INT0 button on eval board) in data
; FlashEE space. Replays sequence on LED when board
; is reset or power cycled.
; The ADuC842 stores the play sequece in data flash
; until another is recorded with a new set of button
; presses. To record a new sequence, just wait until
; the current one finishes playing (LED is off) and
; enter new sequence via button (INT0).
;
;********************************************************************
$MOD842 ; Use 8052&ADuC842 predefined symbols
LED EQU P3.4 ; P3.4 drives red LED on eval board
BUTTON EQU P3.2 ; button on eval board drives P3.2
PREVIOUS EQU F0 ; flag to hold previous button value
READ EQU 01h ; FlashEE command: 'read page'
WRITE EQU 02h ; FlashEE command: 'write page'
VERIFY EQU 04h ; FlashEE command: 'verify page'
ERASE EQU 05h ; FlashEE command: 'erase page'
ERASEALL EQU 06h ; FlashEE command: 'erase all'
;--------------------------------------------------------------------
;____________________________________________________________________
; BEGINNING OF CODE
CSEG
ORG 0000h
MAIN:
CLR LED ; turn LED off
MOV EADRH,#0 ; set data FlashEE address to page 0
MOV EADRL,#0
; READ FLASH/EE DATA and indicate values via LED on and off times...
READFLASH:
MOV ECON,#READ ; read current 4byte page of FlashEE
; into EDATA1,2,3,4
MOV A,EDATA4
CJNE A,#1,RECORD ; if EDATA4 is 1, then page contains
; a valid play sequence
; => Play this sequence
; otherwise jump to record mode
;--------------------------------------------------------------------
PLAYBACK:
CALL BLINK ; flash LED for period determined
; by FlashEE data just read
MOV A,EADRL
CJNE A,#0FFh,INCPAGE1 ; if low address is FFh then increment high address
INC EADRH
INCPAGE1:
INC EADRL ; increment to next FlashEE page addr
MOV A,EADRH
CJNE A,#04h,READFLASH
; if address is less than 160 then jump
; to read the next page
; when PLAYBACK is finished jump to RECORD mode
;--------------------------------------------------------------------
RECORD:
CLR LED
JB BUTTON,$ ; wait for first button press
; once button is pressed, erase dataflash
MOV ECON,#ERASEALL ; clear all data FlashEE memory
MOV EADRH,#0
MOV EADRL,#0
; record time of button press
RECORD_NEXT_TIME:
CALL RECORDTIME
MOV EDATA1,DPL ; place DPTR in EDATA1,2,3
MOV EDATA2,DPH
MOV EDATA3,DPP
MOV EDATA4,#1 ; put 1 in EDATA4 as identifier
MOV ECON,#WRITE ; write EDATA1-4 into pre-erased
; page of FlashEE data memory
MOV ECON,#VERIFY ; verify current page is same as
MOV A,ECON ; EDATA1-4. If same, ECON=0.
JNZ RECORD ; if verify fails, jump to RECORD
MOV A,EADRL
CJNE A,#0FFh,INCPAGE2 ; if low address is FFh then increment high address
INC EADRH
INCPAGE2:
INC EADRL ; increment to next FlashEE page addr
MOV A,EADRH
CJNE A,#04h,RECORD_NEXT_TIME
; record first 160 button presses only
; when flash/EE data space is full turn off LED and wait
; for a power cycle
CLR LED
JMP $
;====================================================================
; FUNCTIONS
;====================================================================
;____________________________________________________________________
; SUBROUTINES
BLINK:
; Turn LED ON/OFF based on the time in EDATA3/2/1
CPL LED
CLR A
MOV DPL,A
MOV DPH,A ; clear DPTR
MOV DPP,A
INC EDATA1 ; EDATA1 -> EDATA3 should be
INC EDATA2 ; incremented for the below to work
INC EDATA3
BLINKLOOP:
; the record loop takes 11 instruction cycles hence 7 NOPs are
; required to make the Playback loop 11 instruction cycles also.
; NOTE: the main Playback loop will jump to BLINKLOOP after
; decrementing EDATA1 and hence the time required to decrement
; EDATA2 (approx 1/256 time of main loop) and EDATA3 are ignored.
NOP ; 1
NOP ; 1
NOP ; 1
NOP ; 1
NOP ; 1
NOP ; 1
NOP ; 1
DJNZ EDATA1, BLINKLOOP ; 4
DJNZ EDATA2, BLINKLOOP ; EDATA1 overflows back to FFh
DJNZ EDATA3, BLINKLOOP ; EDATA2 overflows back to FFh
RET
;____________________________________________________________________
RECORDTIME:
; Record how long button is pressed for and store in EDATA3/2/1
CLR A
MOV DPL,A
MOV DPH,A ; clear DPTR
MOV DPP,A
CPL LED
; measure how long the button is either pressed or released
; for. If the button is pressed then the LED is on. If the
; button is released then the LED is off.
RECORDLOOP:
INC DPTR ; incrementing DPTR.. ; 3
JNB LED, CHKB ; 4
JNB BUTTON,RECORDLOOP ; 4
; keep recording while button is pressed
RET
CHKB: JB BUTTON,RECORDLOOP ; 4
; keep recording while button is released
RET
; DPP,DPH,DPL now holds a number that represents the length of
; time between button edges. this data will be stored in FlashEE
; space for use in controlling LED on and off times in "play" mode.
;____________________________________________________________________
END
Datasheet of ADuC842: https://www.analog.com/en/processors-dsp/analog-microcontrollers/aduc842/products/product.html
Comments are in polish so if you want to know what they mean please use google translate My lecturer is old school so he does not know English well.
If someone finds solution I will be gratefull, at this time i will struggle with this problem.