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

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

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

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

Добавлен: 14.06.2025

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

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

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

LCD Interfacing and Programming

325

call

pulseE

; Pulse and delay

; Set RS line for data

bsf

PORTA,RS_line

; RS = 1 for data

call

busyTest ; 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

;and 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)

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


326

Chapter 13

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

; 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


LCD Interfacing and Programming

327

;

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

13.4.3 LCDTest3 Program

;File name: LCDTest3.asm

;Date: April 16, 2006

;Author: Julio Sanchez

;Processor: 16F84A

;Description:

;Program to exercise 4-bit PIC-to-LCD interface.

;Code assumes that LCD is driven by Hitachi HD44780

;controller and that the display supports two lines

;each one with 16 characters. The wiring and base

;address of each display line is stored in #define

;statements. These statements can be edited to

;accommodate a different set-up.

;Program uses delay loops for interface timing.

;WARNING:

;Code assumes 4Mhz clock. Delay routines must be

;edited for faster clock

;

; Displays: Minnesota State, Mankato

;


328

Chapter 13

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

;switches ;===========================

;Switches used in __config directive:

;

_CP_ON

Code protection ON/OFF

; *

_CP_OFF

;

*

_PWRTE_ON

Power-up timer ON/OFF

;_PWRTE_OFF

;

_WDT_ON

Watchdog timer ON/OFF

; * _WDT_OFF

;

_LP_OSC

Low power crystal

occilator

; * _XT_OSC

External parallel

resonator/crystal oscillator

;

_HS_OSC

High speed crystal resonator (8 to

10 MHz)

;

Resonator: Murate

Erie CSA8.00MG =

8 MHz

;

_RC_OSC

Resistor/capacitor oscillator

; |

(simplest, 20% error)

;|

;|_____ * indicates set up values presently selected

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

;set up and configuration

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

processor 16f84A

include

<p16f84A.inc>

__config

_XT_OSC & _WDT_OFF & _PWRTE_ON & _CP_OFF

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

;

constant definitions

; for PIC-to-LCD pin wiring and LCD line addresses ;=====================================================

#define E_line 1

;|

#define RS_line 2

;| — from wiring diagram

#define RW_line 3

;|

; LCD line addresses (from LCD data sheet)

#define LCD_1

0x80

; First LCD line constant

#define LCD_2

0xc0

; Second LCD line constant

;Note: The constants that define the LCD display line

;addresses have the high-order bit set in

;order to facilitate the controller command

;

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

;

variables in PIC RAM

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

; Reserve 16 bytes for string buffer

cblock 0x0c

strData

endc


LCD Interfacing and Programming

329

; Leave 16 bytes and Continue with local variables

cblock

0x1d

; Start of block

count1

; Counter # 1

count2

; Counter # 2

count3

; Counter # 3

pic_ad

; Storage for start of text area

; (labeled strData) in PIC RAM

J

; counter J

K

; counter K

index

; Index into text table (also used

; for auxiliary storage)

store1

; Local temporary storage

store2

; Storage # 2

endc

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

;

program

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

org

0

; start at address

goto

main

; Space for interrupt handlers

org

0x08

main:

movlw

b’00000000’

; All lines to output

tris

PORTA

; in Port-A

tris

PORTB

; and port B

movlw

b’00000000’

; All outputs ports low

movwf

PORTA

movwf

PORTB

; Wait and initialize HD44780

call

delay_5

; Allow LCD time to initialize

; itself

call

delay_5

call

initLCD

; Then do forced

initialization

call

delay_5

; Wait again

; Store base address of text buffer in PIC RAM

movlw

0x0c

; Start address for buffer

movwf

pic_ad

; to local variable

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

;first LCD line ;======================

;Store 16 blanks in PIC RAM, starting at address stored

;in variable pic_ad

call blank16

;Call procedure to store ASCII characters for message

;in text buffer