Файл: Microcontroller Programming. Thi Micro Chip PIC (Julio Sanchez, 2007).pdf

ВУЗ: Не указан

Категория: Не указан

Дисциплина: Не указана

Добавлен: 14.06.2025

Просмотров: 8581

Скачиваний: 0

ВНИМАНИЕ! Если данный файл нарушает Ваши авторские права, то обязательно сообщите нам.

LCD Interfacing and Programming

335

;========================

;blank buffer ;========================

;Procedure to store 16 blank characters in PIC RAM

;buffer starting at address stored in the variable

;pic_ad

blank16

movlw

D’16’

;

Set up counter

movwf

count1

movf

pic_ad,w ;

First PIC RAM address

movwf

FSR

;

Indexed addressing

movlw

0x20

;

ASCII space character

storeit

movwf

INDF

;

Store blank character in PIC RAM

;

buffer using FSR register

decfsz

count1,f

; Done?

goto

incfsr

;

no

return

;

yes

incfsr

incf

FSR,f

;

Bump FSR to next buffer space

goto

storeit

;========================

;Set Address register

;to LCD line 1 ;========================

;ON ENTRY:

;Address of LCD line 1 in constant LCD_1

line1:

bcf

PORTA,E_line

; E line low

bcf

PORTA,RS_line

; RS line low, set up for

control

call

delay_5

; busy?

; Set to second display line

movlw

LCD_1

; Address and command bit

call

send8

; 4-bit routine

; Set RS line for data

bsf

PORTA,RS_line

; Set up for data

call

delay_5

; Busy?

return

;========================

;Set Address register

;to LCD line 2 ;========================

;ON ENTRY:

;Address of LCD line 2 in constant LCD_2

line2:

bcf

PORTA,E_line

; E line low


336

Chapter 13

bcf

PORTA,RS_line

; RS line low, set up for

; control

call

delay_5

; Busy?

; Set to second display line

movlw

LCD_2

; Address with high-bit set

call

send8

; Set RS line for data

bsf

PORTA,RS_line

; RS = 1 for data

call

delay_5

; Busy?

return

;===============================

;first text string procedure ;=============================== storeMSU:

;Procedure to store in PIC RAM buffer the message

;contained in the code area labeled msg1

;ON ENTRY:

;variable pic_ad holds address of text buffer

;in PIC RAM

;w register hold offset into storage area

;msg1 is routine that returns the string characters

;andiy a zero terminator

;index is local variable that hold offset into

;text table. This variable is also used for

;temporary storage of offset into buffer

;ON EXIT:

;Text message stored in buffer

;

;Store offset into text buffer (passed in the w register)

;in temporary variable

movwf

index

; Store w in index

; Store base address of text buffer in FSR

movf

pic_ad,w ; first display RAM address to W

addwf

index,w

; Add offset to address

movwf

FSR

; W to FSR

; Initialize index for text string access

movlw

0

; Start at 0

movwf

index

; Store index in variable

; w still = 0

get_msg_char:

call

msg1

; Get character from table

; Test for zero terminator

andlw

0x0ff

btfsc

STATUS,Z ; Test zero flag

goto

endstr1

; End of string

;ASSERT: valid string character in w

;store character in text buffer (by FSR)


LCD Interfacing and Programming

337

movwf

INDF

; store in buffer by FSR

incf

FSR,f

; increment buffer pointer

; Restore table character counter from variable

movf

index,w

; Get value into w

addlw

1

; Bump to next character

movwf

index

; Store table index in

variable

goto

get_msg_char

; Continue

endstr1:

return

; Routine for returning message stored in program area

msg1:

addwf

PCL,f

; Access table

retlw

‘M’

retlw

‘i’

retlw

‘n’

retlw

‘n’

retlw

‘e’

retlw

‘s’

retlw

‘o’

retlw

‘t’

retlw

‘a’

retlw

0

;=================================

;second text string procedure ;================================= storeUniv:

;Processing identical to procedure StoreMSU

movwf

index

; Store w in index

; Store base address of text buffer in FSR

movf

pic_ad,0 ; first display RAM address to W

addwf

index,0

; Add offset to address

movwf

FSR

; W to FSR

; Initialize index for text string access

movlw

0

; Start at 0

movwf

index

; Store index in variable

; w still = 0

get_msg_char2:

call

msg2

; Get character from table

; Test for zero terminator

andlw

0x0ff

btfsc

STATUS,Z ; Test zero flag

goto

endstr2

; End of string

;ASSERT: valid string character in w

;store character in text buffer (by FSR)

movwf

INDF

;

Store in buffer by FSR

incf

FSR,f

;

Increment buffer pointer


338

Chapter 13

; Restore table character counter from variable

movf

index,w

; Get value into w

addlw

1

; Bump to next character

movwf

index

; Store table index in

; variable

goto

get_msg_char2

; Continue

endstr2:

return

; Routine for returning message stored in program area msg2:

addwf

PCL,f

; Access table

retlw

‘S’

retlw

‘t’

retlw

‘a’

retlw

‘t’

retlw

‘e’

retlw

‘,’

retlw

0x20

retlw

‘M’

retlw

‘a’

retlw

‘n’

retlw

‘k’

retlw

‘a’

retlw

‘t’

retlw

‘o’

retlw

0

end