Macro Definitions

Overview

Macro's in MPLAB are treated similarly to macros in Visual C, which results in a nice function-like text where the macro is instantiated.  This module defines macros for delays and text display, as well as some basic LCD manipulation.

Code

subtitle "Macro Module"

; **************************************************************
; *
; * MACRO: VarDelay100uS
; *
; * Variable delay in blocks of approximately 100uS. See
; * VarShortDelay subroutine for details of timing
; *
; **************************************************************
VarDelay100uS macro Delay
ifndef TESTING
if Delay > 255
messg "VarDelay100uS: Maximum value is 255!"
endif
movlw Delay
call VarShortDelay
endif
endm

; **************************************************************
; *
; * MACRO: VarDelay10mS
; *
; * Variable delay in blocks of approximately 10mS. See
; * VarLongDelay subroutine for details of timing
; *
; **************************************************************
VarDelay10mS macro Delay
ifndef TESTING
if Delay > 255
messg "VarDelay10mS: Maximum Value is 255!"
endif
movlw Delay
call VarLongDelay
endif
endm


; **************************************************************
; *
; * MACRO: MoveTo
; *
; * Move the LCD Display Cursor to the defined X/Y position
; * X range from 0-15, Y from 0-3
; *
; **************************************************************
MoveTo macro XPos, YPos
local Address

if YPos > 3
Messg "MoveTo: Y must be between 0 and 3"
endif

if XPos > 15
Messg "MoveTo: X must be between 0 and 3"
endif

if YPos == 0
Address = XPos
endif
if YPos == 1
Address = 0x40 + XPos
endif
if YPos == 2
Address = 0x10 + XPos
endif
if YPos == 3
Address = 0x50 + XPos
endif

movlw Address
pagesel LCD_SetDDRAMAddress
call LCD_SetDDRAMAddress
endm

; **************************************************************
; *
; * MACRO: DisplayTextAt
; *
; * Display text at the specified X/Y position
; *
; **************************************************************
DisplayTextAt macro XPos, YPos, TextAddress
local Address

if YPos > 3
Messg "MoveTo: Y must be between 0 and 3"
endif

if XPos > 15
Messg "MoveTo: X must be between 0 and 3"
endif

if YPos == 0
Address = XPos
endif
if YPos == 1
Address = 0x40 + XPos
endif
if YPos == 2
Address = 0x10 + XPos
endif
if YPos == 3
Address = 0x50 + XPos
endif

movlw Address
pagesel LCD_SetDDRAMAddress
call LCD_SetDDRAMAddress

DisplayText TextAddress

endm


; **************************************************************
; *
; * MACRO: DisplayText
; *
; * Display text at the current cursor position
; *
; **************************************************************
DisplayText macro TextAddress
local DisplayLoop, EndOfDisplayLoop

movlw 1

DisplayLoop movwf LCDTextTableIndex
movwf LCDTextOffset
movlw LOW TextAddress
addwf LCDTextOffset, F
movlw HIGH TextAddress
btfsc STATUS, C
addlw 1
movwf PCLATH
movf LCDTextOffset, w
call TextAddress
pagesel EndOfDisplayLoop
andlw 0xff
btfsc STATUS, Z
goto EndOfDisplayLoop
pagesel LCD_WriteData
call LCD_WriteData ; Display character

movf LCDTextTableIndex, W
addlw 1

pagesel DisplayLoop
goto DisplayLoop
EndOfDisplayLoop:
endm


; **************************************************************
; *
; * MACRO: GetUserTimeEntryFrom
; *
; * Get the User Time input from the specified XY Position
; *
; **************************************************************
GetUserTimeEntryFrom macro XPos, YPos
local Address

if YPos > 3
Messg "MoveTo: Y must be between 0 and 3"
endif

if XPos > 15
Messg "MoveTo: X must be between 0 and 3"
endif

if YPos == 0
Address = XPos
endif
if YPos == 1
Address = 0x40 + XPos
endif
if YPos == 2
Address = 0x10 + XPos
endif
if YPos == 3
Address = 0x50 + XPos
endif

movlw Address
movwf StartDDAdd ; Move address into StartDDAdd

pagesel LCD_SetDDRAMAddress
call LCD_SetDDRAMAddress

pagesel GetUserTimeEntry
call GetUserTimeEntry

endm

; **************************************************************
; *
; * MACRO: DisplayDayListAt
; *
; * Display Day List at specified X,Y Position
; *
; **************************************************************
DisplayDayListAt macro XPos, YPos
local Address

if YPos > 3
Messg "MoveTo: Y must be between 0 and 3"
endif

if XPos > 15
Messg "MoveTo: X must be between 0 and 3"
endif

if YPos == 0
Address = XPos
endif
if YPos == 1
Address = 0x40 + XPos
endif
if YPos == 2
Address = 0x10 + XPos
endif
if YPos == 3
Address = 0x50 + XPos
endif

movlw Address
movwf StartDDAddDOW

pagesel LCD_SetDDRAMAddress
call LCD_SetDDRAMAddress
pagesel DisplayDayList
call DisplayDayList

endm

; **************************************************************
; *
; * MACRO: GetUserDayListFrom
; *
; * Get the User Day List input from the specified XY Position
; *
; **************************************************************
GetUserDayListFrom macro XPos, YPos
local Address

if YPos > 3
Messg "MoveTo: Y must be between 0 and 3"
endif

if XPos > 15
Messg "MoveTo: X must be between 0 and 3"
endif

if YPos == 0
Address = XPos
endif
if YPos == 1
Address = 0x40 + XPos
endif
if YPos == 2
Address = 0x10 + XPos
endif
if YPos == 3
Address = 0x50 + XPos
endif

movlw Address
movwf StartDDAddDOW

pagesel LCD_SetDDRAMAddress
call LCD_SetDDRAMAddress

pagesel GetUserDayList
call GetUserDayList

endm


; **************************************************************
; *
; * MACRO: HandleMenu4
; *
; * Handle menu selection from a 4-choice menu
; *
; **************************************************************
HandleMenu4 Macro Sub1, Sub2, Sub3, Sub4, SubDefault
local Loop1, Loop2, Loop3
decfsz KeypadValue, F
goto Loop1
pagesel Sub1
goto Sub1
Loop1: decfsz KeypadValue, F
goto Loop2
pagesel Sub2
goto Sub2
Loop2: decfsz KeypadValue, F
goto Loop3
pagesel Sub3
goto Sub3
Loop3: decfsz KeypadValue, F
goto SubDefault
pagesel Sub4
goto Sub4
endm

; **************************************************************
; *
; * MACRO: HandleMenu3
; *
; * Handle menu selection from a 3-choice menu
; *
; **************************************************************
HandleMenu3 Macro Sub1, Sub2, Sub3, SubDefault
local Loop1, Loop2
decfsz KeypadValue, F
goto Loop1
pagesel Sub1
goto Sub1
Loop1: decfsz KeypadValue, F
goto Loop2
pagesel Sub2
goto Sub2
Loop2: decfsz KeypadValue, F
goto SubDefault
pagesel Sub3
goto Sub3
endm

; **************************************************************
; *
; * MACRO: HandleMenu2
; *
; * Handle menu selection from a 2-choice menu
; *
; **************************************************************
HandleMenu2 Macro Sub1, Sub2, SubDefault
local Loop1
decfsz KeypadValue, F
goto Loop1
pagesel Sub1
goto Sub1
Loop1: decfsz KeypadValue, F
goto SubDefault
pagesel Sub2
goto Sub2
endm

Page Last Updated on Wednesday September 04, 2002