?? tut6014.s
字號:
;------------------------------------------------------------------------------
; Write LCD with text using PSV feature and flash LED1 with a Timer1 loop
;------------------------------------------------------------------------------
.equ __30F6014, 1
.include "E:\Microchip\MPLAB ASM30 Suite\Support\inc\p30f6014.inc"
;------------------------------------------------------------------------------
;Global Declarations:
.global __reset ;The label for the first line of code.
.global __OscillatorFail ;Declare Oscillator Fail trap routine label
.global __AddressError ;Declare Address Error trap routine label
.global __StackError ;Declare Stack Error trap routine label
.global __MathError ;Declare Math Error trap routine label
;------------------------------------------------------------------------------
;Data Declarations in near data space
.section .nbss
flags: .space 1
;------------------------------------------------------------------------------
;Program Specific Constants (literals used in code)
.equ Fcy, #7372800
;------------------------------------------------------------------------------
;Start of code
.text ;Start of Code section
__reset: mov #__SP_init,w15 ;Initalize the Stack Pointer
mov #__SPLIM_init,w0
mov w0,SPLIM ;Initialize the Stack Pointer Limit Register
nop ;Add NOP to follow SPLIM initialization
;------------------------------------------------------------------------------
;Initialize LED outputs on PORTD bits 0-4
mov #0xFFFF,w0 ;Initialize LED pin data to off state
mov w0,LATD
mov #0xFFF0,w0 ;Set LED pins as outputs
mov w0,TRISD
bclr LATD,#RD0 ;Turn LED1 on
;------------------------------------------------------------------------------
;Initialize Timer1 for 1/2 second period
clr T1CON ;Turn off Timer1 by clearing control register
clr TMR1 ;Start Timer1 at zero
mov #Fcy/512,w0 ;Get period register value for 1/2 second
mov w0,PR1 ;Load Timer1 period register
mov #0x8030,w0 ;Get Timer1 settings (1:256 prescaler)
mov w0,T1CON ;Load Timer1 settings into control register
;------------------------------------------------------------------------------
;Initialize SPI for comms to LCD display and clear display
;Ensure LCD Controller is up and running
bset LATD, #LATD7 ;Set chip select high for MCP41010
bclr TRISD, #TRISD7;Set chip select pin to output
rcall SPI_Init ;Call routine to set up SPI2 for LCD display
;Ensure LCD Controller is up and running (~100mS at 7.37MIPs)
mov #256, w0
mov #2800, w1
do w1, end_delay1 ;outer loop
repeat w0 ;inner loop
nop
nop
end_delay1: nop
mov.b #0x82,w0 ;Load command to clear the display
rcall WrtLCD ;Call routine to send the command to the display
mov.b #0x82,w0 ;Load command to clear the display
rcall WrtLCD ;Call routine to send the command to the display
;------------------------------------------------------------------------------
;Set up PSV to make "Demo_Board_Message1" program memory data accessible as data space
bset CORCON, #PSV ;Enable PSV operation in CORCON
mov #psvpage(Demo_Board_Message1),w0 ;Get upper address (page) of text in program memory
mov w0, PSVPAG ;Load address into PSVPAG
mov #psvoffset(Demo_Board_Message1),w4 ;Get lower address (offset) of text in program
;memory and place into w4
bset flags, #0 ;set flag to indicate string write to LCD
rcall WrtNextChr ;display data on LCD
wait: btsc PORTA, #12
bra wait ;wait here until SW1 is pressed
mov.b #0x82,w0 ;Load command to clear the display
rcall WrtLCD ;Call routine to send the command to the display
mov.b #0x82,w0 ;Load command to clear the display
rcall WrtLCD ;Call routine to send the command to the display
;------------------------------------------------------------------------------
;Set up PSV to make "Hi_Msg1" program memory data accessible as data space
bset CORCON, #PSV ;Enable PSV operation in CORCON
mov #psvpage(Hi_Msg1),w0 ;Get upper address (page) of text in program memory
mov w0, PSVPAG ;Load address into PSVPAG
mov #psvoffset(Hi_Msg1),w4 ;Get lower address (offset) of text in program
;memory and place into w4
bclr flags, #0 ;clear flag to indicate non string LCD update
rcall WrtNextChr ;display data on LCD
wait1: btsc PORTA, #13
bra wait1 ;wait here until SW4 is pressed
mov.b #0x82,w0 ;Load command to clear the display
rcall WrtLCD ;Call routine to send the command to the display
;------------------------------------------------------------------------------
;Set up PSV to make "Line Draw" program memory data accessible as data space
bset CORCON, #PSV ;Enable PSV operation in CORCON
mov #psvpage(Line_Draw),w0 ;Get upper address (page) of text in program memory
mov w0, PSVPAG ;Load address into PSVPAG
mov #psvoffset(Line_Draw),w4;Get lower address (offset) of text in program
;memory and place into w4
bclr flags, #0 ;clear flag to indicate non string LCD update
rcall WrtNextChr ;display data on LCD
wait2: btsc PORTA, #14
bra wait2
mov.b #0x82,w0 ;Load command to clear the display
rcall WrtLCD ;Call routine to send the command to the display
;------------------------------------------------------------------------------
;Set up PSV to make "Demo_Board_Message2" program memory data accessible as data space
bset CORCON, #PSV ;Enable PSV operation in CORCON
mov #psvpage(Demo_Board_Message2),w0 ;Get upper address (page) of text in program memory
mov w0, PSVPAG ;Load address into PSVPAG
mov #psvoffset(Demo_Board_Message2),w4 ;Get lower address (offset) of text in program
;memory and place into w4
bset flags, #0 ;set flag to indicate string write to LCD
rcall WrtNextChr ;display data on LCD
;------------------------------------------------------------------------------
;Loop while waiting for a Timer1 match and toggle LED1 when it happens
MainLoop: btss IFS0,#T1IF ;Check if Timer1 interrupt flag is set
bra MainLoop ;Loop back until set
bclr IFS0,#T1IF ;Clear Timer1 interrupt flag
btg LATD,#0 ;Toggle LED1
bra MainLoop ;Loop back
;------------------------------------------------------------------------------
;Initialize SPI port to communicate with the LCD display controller (PIC18F242)
SPI_Init: bset LATG,#LATG9 ;Set SPI slave select pin high
bclr TRISG,#TRISG9 ;and set as output
mov #0x003A,w0 ;Load SPI control register
mov w0,SPI2CON ;Master mode, Clk = Fosc/8, Input data sampled at middle
;of output time, Data clocked out on rising edge, Clk idle is low
bclr IEC1, #SPI2IE ;Ensure SPI interrupt is disabled
mov #0x8000,w0 ;Enable SPI port
mov w0,SPI2STAT
return
;------------------------------------------------------------------------------
;Send w0 byte to LCD
WrtLCD: bclr LATG,#LATG9 ;Set slave select low for new transmission
bclr SPI2STAT,#SPIROV;
mov SPI2BUF, w2 ;Dummy read to avoid overflow
mov.b wreg, SPI2BUF ;Write the data to the output buffer
spibusy: btss SPI2STAT,#SPIRBF ;
bra spibusy ;Loop back until complete
bset LATG,#LATG9 ;Set SPI slave select pin high
return
;------------------------------------------------------------------------------
;Write next char to LCD Controller until loop complete (null character)
WrtNextChr: btss flags, #0 ;test if this is string write to LCD
bra bypass_cmd ;not a string update so bypass "WrtChrNext" command
mov #0xA8, w0 ;Load command to send an ascii character
rcall WrtLCD ;Call routine to send the command to the display
bypass_cmd: mov.b [w4++],w0 ;Get data byte pointed to by w4,
;place in w0 and increment pointer
mov #0x00FF, w1
cp.b w1, w0 ;Test if byte (in w0) is 0xFF
bra NZ, not_end ;If not zero then branch to send more data
return ;end of transmission so return
not_end: rcall WrtLCD ;Call routine to send the character to the display
bra WrtNextChr ;Loop back for next character in table
return
;==============================================================================
;Tables of constants in program memory
;------------------------------------------------------------------------------
;Text in program memory
.section .const,"r"
;------------------------------------------------------------------------------
; Character commands example #1
; Defining ascii string for LCD
Demo_Board_Message1:
.ascii " dsPICDEM(tm)1.1 " ;Text string
.ascii " Development Board " ;Text string
.ascii " " ;Text string
.ascii " Tutorial " ;Text string with trailing zero
.byte 0xFF ;string terminator
;------------------------------------------------------------------------------
; Character commands example #2
; How to define LCD column and row position and write characters
Hi_Msg1:
.byte 0xE7
.ascii "H"
.byte 9, 0
.byte 0xA8
.ascii "i"
.byte 0xFF ;string terminator
;------------------------------------------------------------------------------
; Pixel Commands example
; How to define pixel commands to write lines to the display
Line_Draw:
.byte 0xD7, 1, 1, 0xDA, 119, 31
.byte 0xD7, 1, 31, 0xDA, 119, 1
.byte 0xD7, 1, 1, 0xDA, 1, 31
.byte 0xD7, 119, 1, 0xDA, 119, 31
.byte 0xD7, 1, 31, 0xDA, 119, 31
.byte 0xD7, 1, 1, 0xDA, 119, 1
.byte 0xFF ;string terminator
;------------------------------------------------------------------------------
; Character commands example #3
; Defining ascii string for LCD
Demo_Board_Message2:
.ascii " dsPIC30F 16-bit "
.ascii " Digital Signal "
.ascii " Controller "
.byte 0xFF ;string terminator
;==============================================================================
; Error traps
; Example trap routines. In application use retfie instruction to exit trap
;------------------------------------------------------------------------------
;Oscillator Fail Error trap routine
.text ;Start of Code section
__OscillatorFail:
bclr LATD,#LATD3 ;Turn LED4 on
bclr INTCON1, #OSCFAIL ;Reset oscillator fail trap flag
bra __OscillatorFail ;Loop forever when oscillator failure occurs
;------------------------------------------------------------------------------
;Address Error trap routine
__AddressError:
bclr LATD,#LATD3 ;Turn LED4 on
bclr INTCON1, #ADDRERR ;Reset address error trap flag
bra __AddressError ;Loop forever when address error occurs
;------------------------------------------------------------------------------
;Math (Arithmetic) Error trap routine
__StackError:
bclr LATD,#LATD3 ;Turn LED4 on
bclr INTCON1, #STKERR ;Reset stack error trap flag
bra __StackError ;Loop forever when stack error occurs
;------------------------------------------------------------------------------
;Math (Arithmetic) Error trap routine
__MathError:
bclr LATD,#LATD3 ;Turn LED4 on
bclr INTCON1, #MATHERR ;Reset math error trap flag
bra __MathError ;Loop forever when math error occurs
;------------------------------------------------------------------------------
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; ;
; Software License Agreement ;
; ;
; The software supplied herewith by Microchip Technology Incorporated ;
; (the "Company") for its dsPIC controller is intended and supplied to ;
; you, the Company's customer, for use solely and exclusively on ;
; Microchip dsPIC products. The software is owned by the Company and/or ;
; its supplier, and is protected under applicable copyright laws. All ;
; rights are reserved. Any use in violation of the foregoing ;
; restrictions may subject the user to criminal sanctions under ;
; applicable laws, as well as to civil liability for the breach of the ;
; terms and conditions of this license. ;
; ;
; THIS SOFTWARE IS PROVIDED IN AN "AS IS" CONDITION. NO WARRANTIES, ;
; WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, ;
; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR ;
; PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, IN ANY ;
; CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR CONSEQUENTIAL ;
; DAMAGES, FOR ANY REASON WHATSOEVER. ;
; ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.end ;End of code in this file
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -