📄 base1.txt
字号:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Project: Interfacing PICs
; Source File Name: BASE1.ASM
; Devised by: MPB
; Date: 31-1-06
; Status: Final
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Program to exercise the 16F877 BASE module
; with 8-bit analogue input, LCD, phone keypad
; and serial memory
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
PROCESSOR 16F877
; Clock = XT 4MHz, standard fuse settings
__CONFIG 0x3731
; LABEL EQUATES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
INCLUDE "P16F877A.INC" ; standard register labels
; User register label allocation ;;;;;;;;;;;;;;;;;;;;;;;;;;
; GPR 20 - 2A local variables
; GPR 30 - 32 KEY12 keypad driver
; GPR 60 - 65 SERMEM serial memory driver
; GPR 70 - 75 LCDIS display driver
; GPR 77 - 7A CONDEC BCD conversion routine
LCDport EQU 08 ; assign LCD to Port D
LCDdirc EQU 88 ; data direction register
Temp EQU 20 ; temp store
Tabin EQU 21 ; Table pointer
;----------------------------------------------------------
; MAIN PROGRAM
;----------------------------------------------------------
ORG 0 ; Default start address
NOP ; required for ICD mode
; Port & display setup ------------------------------------
BANKSEL TRISA ; Select bank 1
MOVLW B'11111100' ; port setup
MOVWF TRISB ; = 2 outputs
CLRF TRISD ; Display port is output
BANKSEL PORTA ; Select bank 0
CLRF PORTD ; Clear display outputs
CLRF HiReg ; select memory page 0
CLRF LoReg ; select first location
CALL inimem ; initialise serial memory
CALL inid ; Initialise the display
;----------------------------------------------------------
; MAIN LOOP
;----------------------------------------------------------
start CLRW ; Select AN0 input
CALL adin ; read analogue input
CALL condec ; convert to decimal
CALL putdec ; display input
CALL store ; store input in memory
CALL putkey ; Fixed message
CALL key12 ; scan phone keypad
CALL send ; display key
GOTO start ; and again
;-----------------------------------------------------------
;-----------------------------------------------------------
; SUBROUTINES
;-----------------------------------------------------------
; Display input test voltage on top line of LCD
;-----------------------------------------------------------
putdec BCF Select,RS ; set display command mode
MOVLW 080 ; code to home cursor
CALL send ; output it to display
BSF Select,RS ; and restore data mode
; Convert digits to ASCII ----------------------------------
MOVLW 030 ; load ASCII offset
ADDWF Huns ; convert hundreds to ASCII
ADDWF Tens ; convert tens to ASCII
ADDWF Ones ; convert ones to ASCII
; Display voltage on line 1 --------------------------------
CALL volmes ; Display text on line 1
MOVF Huns,W ; load hundreds code
CALL send ; and send to display
MOVLW '.' ; load point code
CALL send ; and output
MOVF Tens,W ; load tens code
CALL send ; and output
MOVF Ones,W ; load ones code
CALL send ; and output
MOVLW ' ' ; load space code
CALL send ; and output
MOVLW 'V' ; load volts code
CALL send ; and output
RETURN ; done
; Store voltage in serial memory --------------------------
store BSF SSPCON,SSPEN ; Enable memory port
MOVF ADRESH,W ; Get voltage code
MOVWF SenReg ; Load it to write
CALL writmem ; Write it to memory
INCF LoReg ; Next location
BCF SSPCON,SSPEN ; Disable memory port
RETURN ; done
;----------------------------------------------------------
; Display key input on bottom line of LCD
;----------------------------------------------------------
putkey BCF Select,RS ; set display command mode
MOVLW 0C0 ; code to home cursor
CALL send ; output it to display
BSF Select,RS ; and restore data mode
CALL keymes
RETURN ; done
;----------------------------------------------------------
; Display fixed messages
;----------------------------------------------------------
volmes CLRF Tabin ; Zero table pointer
next1 MOVF Tabin,W ; Load table pointer
CALL mess1 ; Get next character
MOVWF Temp ; Test data...
MOVF Temp,F ; ..for zero
BTFSC STATUS,Z ; Last letter done?
RETURN ; yes - next block
CALL send ; no - display it
INCF Tabin ; Point to next letter
GOTO next1 ; and get it
; ---------------------------------------------------------
keymes CLRF Tabin ; Zero table pointer
next2 MOVF Tabin,W ; Load table pointer
CALL mess2 ; Get next character
MOVWF Temp ; Test data...
MOVF Temp,F ; ..for zero
BTFSC STATUS,Z ; Last letter done?
RETURN ; yes - next block
CALL send ; no - display it
INCF Tabin ; Point to next letter
GOTO next2 ; and get it
;----------------------------------------------------------
; Text strings for fixed messages
;----------------------------------------------------------
mess1 ADDWF PCL ; Set table pointer
DT "Volts = ",0 ; Text for display
mess2 ADDWF PCL ; Set table pointer
DT "Key = ",0 ; Text for display
;-------------------------------------------------------------
;----------------------------------------------------------
; INCLUDED ROUTINES
;----------------------------------------------------------
; LCD DRIVER
; Contains routines:
; init: Initialises display
; onems: 1 ms delay
; xms: X ms delay
; Receives X in W
; send: sends a character to display
; Receives: Control code in W (Select,RS=0)
; ASCII character code in W (RS=1)
;
INCLUDE "LCDIS.INC"
;
;----------------------------------------------------------
; Convert 8 bits to 3 digit decimal
;
; Receives 8-bits in W
; Returns BCD diits in 'huns','tens','ones'
;
INCLUDE "CONDEC.INC";
;
;----------------------------------------------------------
; KEYPAD DRIVER
; Define port used = Keyport
; Bits 0-2 = input columns
; Bits 4-7 = output rows
; Returns ASCII for key in W
;
INCLUDE "KEY12.INC"
;
;----------------------------------------------------------
; Read selected analogue input
;
; Receives channel number in W
; Returns 8-bit input in W
;
INCLUDE "ADIN.INC"
;
;----------------------------------------------------------
; SERIAL MEMORY DRIVER
; Write high address into 'HiReg' 00-3F
; Write low address into 'LoReg' 00-FF
; Load data send into 'SenReg'
; Read data received from 'RecReg'
;
; To initialise call 'inimem'
; To write call 'writmem'
; To read call 'readmem'
;
INCLUDE "SERMEM.INC"
;
;----------------------------------------------------------
END ; of source code
;----------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -