Last active
December 16, 2015 07:39
-
-
Save gabriellett/5400663 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; put data in RAM | |
MOV 30H, #'0' | |
MOV 31H, #'1' | |
MOV 33H, #'2' | |
MOV 34H, #'3' | |
MOV 35H, #'4' | |
MOV 36H, #'5' | |
MOV 37H, #'6' | |
MOV 38H, #'7' | |
MOV 39H, #'8' | |
MOV 39H, #'9' | |
MOV 41H, #30H ; Valor no display 1 | |
MOV 42H, #30H ; Valor no display 2 | |
MOV 43H, #58 ; dois pontos | |
MOV 44H, #30H ; Valor no display 3 | |
MOV 45H, #30H ; Valor no display 4 | |
; initialise the display | |
; see instruction set for details | |
CLR P1.3 ; clear RS - indicates that instructions are being sent to the module | |
; function set | |
CLR P1.7 ; | | |
CLR P1.6 ; | | |
SETB P1.5 ; | | |
CLR P1.4 ; | high nibble set | |
SETB P1.2 ; | | |
CLR P1.2 ; | negative edge on E | |
CALL delay ; wait for BF to clear | |
; function set sent for first time - tells module to go into 4-bit mode | |
; Why is function set high nibble sent twice? See 4-bit operation on pages 39 and 42 of HD44780.pdf. | |
SETB P1.2 ; | | |
CLR P1.2 ; | negative edge on E | |
; same function set high nibble sent a second time | |
SETB P1.7 ; low nibble set (only P1.7 needed to be changed) | |
SETB P1.2 ; | | |
CLR P1.2 ; | negative edge on E | |
; function set low nibble sent | |
CALL delay ; wait for BF to clear | |
; entry mode set; set to increment with no shift | |
CLR P1.7 ; | | |
CLR P1.6 ; | | |
CLR P1.5 ; | | |
CLR P1.4 ; | high nibble set | |
SETB P1.2 ; | | |
CLR P1.2 ; | negative edge on E | |
CLR P1.7 ; | | |
SETB P1.6 ; | | |
SETB P1.2 ; | | |
CLR P1.2 ; | negative edge on E | |
CALL delay ; wait for BF to clear | |
; display on/off control | |
; the display is turned on, the cursor is turned on and blinking is turned on | |
CLR P1.7 ; | | |
CLR P1.6 ; | | |
CLR P1.5 ; | | |
CLR P1.4 ; | high nibble set | |
SETB P1.2 ; | | |
CLR P1.2 ; | negative edge on E | |
SETB P1.7 ; | | |
SETB P1.6 ; | | |
SETB P1.5 ; | | |
SETB P1.4 ; | low nibble set | |
SETB P1.2 ; | | |
CLR P1.2 ; | negative edge on E | |
CALL delay ; wait for BF to clear | |
;loop: | |
;mov A, #'A' | |
;lcall sendData | |
;LCALL voltaUm | |
;ljmp loop | |
; send data | |
SETB P1.3 ; clear RS - indicates that data is being sent to module | |
iniciaDisplay: | |
MOV R1, #41H | |
LCALL migraValor | |
LCALL sendData | |
LCALL voltaUm | |
MOV R1, #42H | |
LCALL migraValor | |
LCALL sendData | |
LCALL voltaUm | |
MOV R1, #43H | |
LCALL migraValor | |
LCALL sendData | |
LCALL voltaUm | |
MOV R1, #44H | |
LCALL migraValor | |
LCALL sendData | |
LCALL voltaUm | |
MOV R1, #45H | |
LCALL migraValor | |
LCALL sendData | |
MOV R1, #45H ;display 4 | |
LCALL diplayQuatro | |
migraValor: | |
MOV A, @R1 | |
MOV R1, A | |
MOV A, @R1 | |
RET | |
vaiUm: | |
MOV A, #10H; | |
LCALL sendInst | |
RET | |
voltaUm: | |
MOV A, #14H; | |
LCALL sendInst | |
RET | |
diplayQuatro: | |
LCALL voltaUm | |
MOV A, @R1 ; move data pointed to by R1 to A | |
;JZ finish | |
LCALL sendData ; send data in A to LCD module | |
INC R1 ; point to next piece of data | |
JMP diplayQuatro | |
MOV R1, #30H ; data to be sent to LCD is stored in 8051 RAM, starting at location 30H | |
;loop: | |
; MOV A, @R1 ; move data pointed to by R1 to A | |
; JZ finish ; if A is 0, then end of data has been reached - jump out of loop | |
; CALL sendCharacter ; send data in A to LCD module | |
; INC R1 ; point to next piece of data | |
;JMP loop ; repeat | |
finish: | |
JMP $ | |
sendData: | |
SETB P1.3 | |
LCALL send | |
RET | |
sendInst: | |
CLR P1.3 | |
LCALL send | |
RET | |
send: | |
MOV C, ACC.7 ; | | |
MOV P1.7, C ; | | |
MOV C, ACC.6 ; | | |
MOV P1.6, C ; | | |
MOV C, ACC.5 ; | | |
MOV P1.5, C ; | | |
MOV C, ACC.4 ; | | |
MOV P1.4, C ; | high nibble set | |
SETB P1.2 ; | | |
CLR P1.2 ; | negative edge on E | |
MOV C, ACC.3 ; | | |
MOV P1.7, C ; | | |
MOV C, ACC.2 ; | | |
MOV P1.6, C ; | | |
MOV C, ACC.1 ; | | |
MOV P1.5, C ; | | |
MOV C, ACC.0 ; | | |
MOV P1.4, C ; | low nibble set | |
SETB P1.2 ; | | |
CLR P1.2 ; | negative edge on E | |
CALL delay ; wait for BF to clear | |
RET | |
delay: | |
MOV R0, #50 | |
DJNZ R0, $ | |
RET |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment