Trích:
Nguyên văn bởi tdm
nhờ các bạn giúp đỡ để viết một bảng tra lớn hơn 256 byte .
|
Bạn có thể sử dụng bộ nhớ chương trình (Flash memory) để lưu bảng, sau dùng tính năng đọc bộ nhớ chương trìng để tra bảng. Với phưong pháp này bạn có thể tạo bảng có độ dài tối đa = 2^14 words. Đoạn chương trình sau có thể giúp bạn hiểu rõ hơn
Code:
lcd_print:
movlw HIGH(msg_table)
movwf addrh
movlw LOW(msg_table)
addwf pointer,W ; point to message in the msg_table
btfsc STATUS,C ; check for overflow
incf addrh,f ; yes, increase hi address
movwf addrl ; no, goto next step
lcd_print_loop:
call flash_read ; read from flash memory
movf datah ; test for zero
btfsc STATUS,Z
movf datal ; test for zero
btfsc STATUS,Z
return
bcf STATUS, C ; clear carry flag
rlf datal,W ; shift MSB of low byte to C
bcf datal,7 ; clear MSB bit
rlf datah,f ; shift C to LSB position of hi byte
movf datah,W ; put hi byte to LCD
call lcd_put_char
movf datal,W ; put low byte to LCD
call lcd_put_char
incf addrl ; increase address pointer
btfsc STATUS,C ; check for overflow
incf addrh,f
goto lcd_print_loop
return
;---------------------------------------------------------------
;flash read
flash_read:
global flash_read
movf addrl, w ;low address
Bank2
movwf EEADR
Bank0
movf addrh,w ;hi address
Bank2
movwf EEADRH
Bank3
bsf EECON1,EEPGD ;point to program memory (see 16F873A datasheet)
bsf EECON1,RD ;start read operation
nop ;required two nops
nop
Bank2
movf EEDATA,W ;datal = eedata
Bank0
movwf datal ;
Bank2
movf EEDATH,W ;datah = eedath
Bank0
movwf datah ;
return
;----------------------------------------------------------
;program memory string table
msg_table:
global msg_table ;(pointer position,msg length)
DA "HW ver 1.0",0 ;(0,6)
DA "SW ver 1.2",0 ;(6,6)