| ??? 02/12/09 01:29 Read: times |
#162300 - Need some help with port reading and LCD displaying. |
Hi, well, I'm kinda new to assembly code, and I need to do a program were I take the value that is in Port A (I'm using pjrc 8051 development board), and depending on the value in it, I need to show a text in a LCD screen. I just need to use the less significant bits (0 to 3), and I can ignore the value in the more significant. I have the next code, but I can't compile it due to a Syntax error in line 50, and other problems I think I will have even if that is solved. Could someone help me to fix it? (Note: I took some of the code from an example in pjrc page)
.equ locat, 0x2000 ;Location for this program
.equ lcd_horiz_size, 20
.equ lcd_vert_size, 2
.equ lcd_bytes_per_line, (128 / lcd_vert_size)
.equ lcd_clear_cmd, 0x01 ;clears display
.equ lcd_home_cmd, 0x02 ;put cursor at home position
.equ lcd_on_cmd, 0x0C ;turn on display (cursor off)
.equ lcd_shift_cmd, 0x10
.equ lcd_config_cmd, 0x38 ;config 8 bit, 2 lines, 5x7
.equ lcd_command_wr, 0xFE00
.equ lcd_status_rd, 0xFE01
.equ lcd_data_wr, 0xFE02
.equ lcd_data_rd, 0xFE03
.equ cout, 0x0030
.equ cin, 0x0032
.equ phex, 0x0034
.equ phex16, 0x0036
.equ pstr, 0x0038
.equ newline, 0x0048
.equ port_a, 0xF800
.equ port_abc_pgm, 0xF803
.org locat
.db 0xA5,0xE5,0xE0,0xA5 ;signiture bytes
.db 35,255,0,0 ;id (35=prog)
.db 0,0,0,0 ;prompt code vector
.db 0,0,0,0 ;reserved
.db 0,0,0,0 ;reserved
.db 0,0,0,0 ;reserved
.db 0,0,0,0 ;user defined
.db 255,255,255,255 ;length and checksum (255=unused)
.db "Practica 2: LCD",0 ;max 31 characters, plus the zero
.org locat+64 ;executable code begins here
begin:
mov dptr, #mesg_start ;print a message for the user
lcall pstr
acall lcd_init
acall lcd_clear ;setup the LCD
acall lcd_home
mov r4, #0 ;r4/r5 will remember cursor position
mov r5, #1
mov dptr, #mesg_start_lcd
acall lcd_pstr ;print a message on the LCD top line
sjmp reposition_cursor ;start the cursor on second line
main_loop:
mov dptr, #port_a
mov R1, @dptr ;Read Port B into the accumulator
cjne @R1, #00, msg00
cjne @R1, #01, msg01
cjne @R1, #02, msg02
cjne @R1, #03, msg03
cjne @R1, #04, msg04
cjne @R1, #05, msg05
cjne @R1, #06, msg06
cjne @R1, #07, msg07
cjne @R1, #08, msg08
cjne @R1, #09, msg09
cjne @R1, #10, msg0A
cjne @R1, #11, msg0B
cjne @R1, #12, msg0C
cjne @R1, #13, msg0D
cjne @R1, #14, msg0E
cjne @R1, #15, msg0F
ljmp 0 ;quit if they pressed ESC
main2: acall lcd_cout
inc r4 ;keep up with cursor position
cjne r4, #lcd_horiz_size, main_loop
mov r4, #0 ;if right edge, return to left side
inc r5
cjne r5, #lcd_vert_size, reposition_cursor
mov r5, #0 ;if bottom edge, return to top line
reposition_cursor:
mov a, r4
mov r2, a
mov a, r5
mov r3, a
acall lcd_set_xy ;set the cursor back onto screen
sjmp main_loop
mesg_start:
.db "Ingresa un valor binario",13,10
.db "mediante el uso del DIP Switch",13,10,0
mesg_start_lcd:
.db "Ingresa un valor Bin",0
msg00:
mov dptr, #msg0
acall lcd_pstr
msg01:
mov dptr, #msg1
acall lcd_pstr
msg02:
mov dptr, #msg2
acall lcd_pstr
msg03:
mov dptr, #msg3
acall lcd_pstr
msg04:
mov dptr, #msg4
acall lcd_pstr
msg05:
mov dptr, #msg5
acall lcd_pstr
msg06:
mov dptr, #msg6
acall lcd_pstr
msg07:
mov dptr, #msg7
acall lcd_pstr
msg08:
mov dptr, #msg8
acall lcd_pstr
msg09:
mov dptr, #msg9
acall lcd_pstr
msg0A:
mov dptr, #msgA
acall lcd_pstr
msg0B:
mov dptr, #msgB
acall lcd_pstr
msg0C:
mov dptr, #msgC
acall lcd_pstr
msg0D:
mov dptr, #msgD
acall lcd_pstr
msg0E:
mov dptr, #msgE
acall lcd_pstr
msg0F:
mov dptr, #msgF
acall lcd_pstr
msg0:
.db "El camino, mal viaje",0
msg1:
.db "Ahora hay que seguir",0
msg2:
.db "Si tu no comprendes ",0
msg3:
.db "Todo estara igual...",0
msg4:
.db "Solo sigue adelante ",0
msg5:
.db "Olvidate de lo demas",0
msg6:
.db "Escucha todo momento",0
msg7:
.db "Observa cada lamento",0
msg8:
.db "Notaras solo la luz ",0
msg9:
.db "Olvidaras el maƱana ",0
msgA:
.db "Conoceras el pasado ",0
msgB:
.db "A pesar de todo eso ",0
msgC:
.db "No importara conocer",0
msgD:
.db "Ya que todo al final",0
msgE:
.db "Dependera de tu boca",0
msgF:
.db "Y del camino en ti. ",0
;----------------------------------------------------------------
; General purpose routines for accessing the LCD
;----------------------------------------------------------------
lcd_cout:
push dpl
push dph
push acc
acall lcd_busy
mov dptr, #lcd_data_wr
pop acc
movx @dptr, a
pop dph
pop dpl
ret
lcd_pstr:
clr a
movc a, @a+dptr
inc dptr
jz lcd_pstr_end
acall lcd_cout
sjmp lcd_pstr
lcd_pstr_end:
ret
lcd_busy:
mov dptr, #lcd_status_rd
lcd_busy_wait:
movx a, @dptr
jb acc.7, lcd_busy_wait
ret
lcd_set_xy:
mov a, r2
add a, #256 - lcd_horiz_size
jnc lcd_set_xok
mov r2, #lcd_horiz_size - 1
lcd_set_xok:
mov a, r3
add a, #256 - lcd_vert_size
jnc lcd_set_yok
mov r3, #lcd_vert_size - 1
lcd_set_yok:
acall lcd_busy
mov a, r3
mov b, #lcd_bytes_per_line
mul ab
add a, r2
orl a, #0x80 ;msb set for set DD RAM address
mov dptr, #lcd_command_wr
movx @dptr, a
ret
lcd_init:
lcall lcd_busy
mov dptr, #lcd_command_wr
mov a, #lcd_config_cmd
movx @dptr, a
lcall lcd_busy
mov dptr, #lcd_command_wr
mov a, #lcd_on_cmd
movx @dptr, a
lcall lcd_busy
mov dptr, #lcd_command_wr
mov a, #lcd_shift_cmd
movx @dptr, a
ret
lcd_clear:
lcall lcd_busy
mov dptr, #lcd_command_wr
mov a, #lcd_clear_cmd
movx @dptr, a
ret
lcd_home:
lcall lcd_busy
mov dptr, #lcd_command_wr
mov a, #lcd_home_cmd
movx @dptr, a
ret
|
| Topic | Author | Date |
| Need some help with port reading and LCD displaying. | 01/01/70 00:00 | |
| be more specific in your statement of the problem! | 01/01/70 00:00 | |
| is other part(LCD) working? | 01/01/70 00:00 | |
| The LCD actually is working | 01/01/70 00:00 | |
| It worked better than mine | 01/01/70 00:00 | |
| You still have no loop | 01/01/70 00:00 | |
| Nearly perfectly working | 01/01/70 00:00 | |
| what is Your default code? | 01/01/70 00:00 | |
| My actual code | 01/01/70 00:00 | |
| that's not 'code' | 01/01/70 00:00 | |
| Sorry | 01/01/70 00:00 | |
| Is this really all of it? | 01/01/70 00:00 | |
Yeah, it's all of it | 01/01/70 00:00 | |
| thank you for the answer | 01/01/70 00:00 | |
| Compare Jump NOT Equal | 01/01/70 00:00 |



