📄 base1.sdi
字号:
,,,;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
,,,;
,,,; Project: Interfacing PICs
,,,; Source File Name: BASE1.ASM
,,,; Devised by: MPB
,,,; Date: 31-1-06
,,,; Status: RS232 added
,,,;
,,,;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
,,,;
,,,; 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
00002007,3731,, __CONFIG 0x3731
,,,
,,,; LABEL EQUATES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
,,,
,,, INCLUDE "P16F877A.INC" ; standard register labels
,,,
,,,; User register label allocation ;;;;;;;;;;;;;;;;;;;;;;;;;;
,,,
,,,; GPR 20 - 2A local variables
,,,; GPR 30 - 32 keyin subroutine
,,,; 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
,,,
,,,; Keypad registers
,,,
,,,Cont EQU 30 ; Delay counter
,,,Key EQU 31 ; Input key
,,,Test EQU 32 ; Key check
,,,
,,,;----------------------------------------------------------
,,,; MAIN PROGRAM
,,,;----------------------------------------------------------
,,,
,,, ORG 0 ; Default start address
00000000,0000,, NOP ; required for ICD mode
,,,
,,,; Port & display setup ------------------------------------
,,,
00000001,1683 1303,, BANKSEL TRISA ; Select bank 1
00000003,30C8,, MOVLW B'11001000' ; Port B code for
00000004,0086,, MOVWF TRISB ; keypad row outputs
00000005,3097,, MOVLW B'10010111' ; Port C code for
00000006,0087,, MOVWF TRISC ; rows and columns
00000007,0188,, CLRF TRISD ; Display port is output
,,,
00000008,1283 1303,, BANKSEL PORTA ; Select bank 0
0000000A,0188,, CLRF PORTD ; Clear display outputs
0000000B,01E1,, CLRF HiReg ; select memory page 0
0000000C,01E2,, CLRF LoReg ; select first location
0000000D,2119,, CALL inimem ; initialise serial memory
0000000E,20C5,, CALL inid ; Initialise the display
,,,
,,,;----------------------------------------------------------
,,,; MAIN LOOP
,,,;----------------------------------------------------------
,,,
0000000F,0103,start,start CLRW ; Select AN0 input
00000010,20F7,, CALL adin ; read analogue input
00000011,20E0,, CALL condec ; convert to decimal
00000012,205C,, CALL putdec ; display input
00000013,2072,, CALL store ; store input in memory
,,,
00000014,2079,, CALL putkey ; Fixed message
00000015,2018,, CALL keyin ; scan phone keypad
00000016,20B5,, CALL send ; display key
00000017,280F,, GOTO start ; and again
,,,
,,,
,,,;-----------------------------------------------------------
,,,; SUBROUTINES
,,,
,,,;----------------------------------------------------------
,,,; Routine to scan 3x4 phone key pad
,,,; Returns ASCII code in W
,,,; Output rows: RB2,RB4,RB5,RC5
,,,; Input cols: RC0,RC1,RC2
,,,;----------------------------------------------------------
,,,
00000018,0000,keyin,keyin NOP
00000019,1683 1303,, BANKSEL TRISC
0000001B,3097,, MOVLW B'10010111' ; Port C code for
0000001C,0087,, MOVWF TRISC ; rows and columns
0000001D,1283 1303,, BANKSEL PORTC
,,,
0000001F,1506,, BSF PORTB,2 ; Set
00000020,1606,, BSF PORTB,4 ; rows
00000021,1686,, BSF PORTB,5 ; high
00000022,1687,, BSF PORTC,5 ; initially
,,,
00000023,1430,, BSF Cont,0 ; Counter not zero
00000024,01B2,, CLRF Test ; No key
,,,
,,,; Scan keyboard -------------------------------------------
,,,
00000025,0103,again,again CLRW ; No key yet
00000026,1106,, BCF PORTB,2 ; Row 1
00000027,0000,, NOP ; wait
00000028,0000,, NOP
,,,
00000029,1C07,, BTFSS PORTC,0 ; key pressed?
0000002A,3031,, MOVLW '1' ; yes - load ASCII code
0000002B,1C87,, BTFSS PORTC,1 ; next
0000002C,3032,, MOVLW '2' ; etc
0000002D,1D07,, BTFSS PORTC,2 ;
0000002E,3033,, MOVLW '3' ;
0000002F,1506,, BSF PORTB,2 ; deselect row
,,,; ---------------------------------------------------------
00000030,1206,, BCF PORTB,4 ; second row
00000031,1C07,, BTFSS PORTC,0
00000032,3034,, MOVLW '4'
00000033,1C87,, BTFSS PORTC,1
00000034,3035,, MOVLW '5'
00000035,1D07,, BTFSS PORTC,2
00000036,3036,, MOVLW '6'
00000037,1606,, BSF PORTB,4
,,,; ---------------------------------------------------------
00000038,1286,, BCF PORTB,5 ; third row
00000039,1C07,, BTFSS PORTC,0
0000003A,3037,, MOVLW '7'
0000003B,1C87,, BTFSS PORTC,1
0000003C,3038,, MOVLW '8'
0000003D,1D07,, BTFSS PORTC,2
0000003E,3039,, MOVLW '9'
0000003F,1686,, BSF PORTB,5
,,,; ---------------------------------------------------------
00000040,1287,, BCF PORTC,5 ; fourth row
00000041,1C07,, BTFSS PORTC,0
00000042,302A,, MOVLW '*'
00000043,1C87,, BTFSS PORTC,1
00000044,3030,, MOVLW '0'
00000045,1D07,, BTFSS PORTC,2
00000046,3023,, MOVLW '#'
00000047,1687,, BSF PORTC,5
,,,
,,,;Test key -------------------------------------------------
,,,
00000048,00B2,, MOVWF Test ; get code
00000049,08B2,, MOVF Test,F ; test it
0000004A,1D03,, BTFSS STATUS,Z ; if code found
0000004B,284E,, GOTO once ; beep once
,,,
0000004C,0831,, MOVF Key,W ; load key code and
0000004D,0008,, RETURN ; if no key, or released
,,,
,,,; Check if beep done --------------------------------------
,,,
0000004E,08B0,once,once MOVF Cont,F ; beep already done?
0000004F,1903,, BTFSC STATUS,Z ;
00000050,2825,, GOTO again ; yes - scan again
,,,
00000051,0832,, MOVF Test,W ; store key
00000052,00B1,, MOVWF Key
,,,
,,,; Beep ----------------------------------------------------
,,,
00000053,3010,beep,beep MOVLW 10 ; 10 cycles
00000054,00B0,, MOVWF Cont
,,,
00000055,1406,buzz,buzz BSF PORTB,0 ; one beep cycle
00000056,20A5,, CALL onems ; 2ms
00000057,1006,, BCF PORTB,0
00000058,20A5,, CALL onems
00000059,0BB0,, DECFSZ Cont ; last cycle?
0000005A,2855,, GOTO buzz ; no
,,,
0000005B,2825,, GOTO again ; yes
,,,
,,,; End of keypad routine ------------------------------------
,,,
,,,; ----------------------------------------------------------
,,,; Display input test voltage on top line of LCD
,,,;-----------------------------------------------------------
,,,
0000005C,10F4,putdec,putdec BCF Select,RS ; set display command mode
0000005D,3080,, MOVLW 080 ; code to home cursor
0000005E,20B5,, CALL send ; output it to display
0000005F,14F4,, BSF Select,RS ; and restore data mode
,,,
,,,; Convert digits to ASCII ----------------------------------
,,,
00000060,3030,, MOVLW 030 ; load ASCII offset
00000061,07F8,, ADDWF Huns ; convert hundreds to ASCII
00000062,07F9,, ADDWF Tens ; convert tens to ASCII
00000063,07FA,, ADDWF Ones ; convert ones to ASCII
,,,
,,,; Display voltage on line 1 --------------------------------
,,,
00000064,207F,, CALL volmes ; Display text on line 1
,,,
00000065,0878,, MOVF Huns,W ; load hundreds code
00000066,20B5,, CALL send ; and send to display
00000067,302E,, MOVLW '.' ; load point code
00000068,20B5,, CALL send ; and output
00000069,0879,, MOVF Tens,W ; load tens code
0000006A,20B5,, CALL send ; and output
0000006B,087A,, MOVF Ones,W ; load ones code
0000006C,20B5,, CALL send ; and output
0000006D,3020,, MOVLW ' ' ; load space code
0000006E,20B5,, CALL send ; and output
0000006F,3056,, MOVLW 'V' ; load volts code
00000070,20B5,, CALL send ; and output
,,,
00000071,0008,, RETURN ; done
,,,
,,,; Store voltage in serial memory --------------------------
,,,
00000072,1694,store,store BSF SSPCON,SSPEN ; Enable memory port
00000073,081E,, MOVF ADRESH,W ; Get voltage code
00000074,00E0,, MOVWF SenReg ; Load it to write
00000075,212E,, CALL writmem ; Write it to memory
00000076,0AE2,, INCF LoReg ; Next location
00000077,1294,, BCF SSPCON,SSPEN ; Disable memory port
00000078,0008,, RETURN ; done
,,,
,,,
,,,;----------------------------------------------------------
,,,; Display key input on bottom line of LCD
,,,;----------------------------------------------------------
,,,
00000079,10F4,putkey,putkey BCF Select,RS ; set display command mode
0000007A,30C0,, MOVLW 0C0 ; code to home cursor
0000007B,20B5,, CALL send ; output it to display
0000007C,14F4,, BSF Select,RS ; and restore data mode
0000007D,2089,, CALL keymes
0000007E,0008,, RETURN ; done
,,,
,,,;----------------------------------------------------------
,,,; Display fixed messages
,,,;----------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -