📄 instamp.sdi
字号:
,,,;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
,,,;
,,,; Project: Interfacing PICs
,,,; Source File Name: INSTAMP.ASM
,,,; Devised by: MPB
,,,; Date: 21-12-05
,,,; Status: Final
,,,;
,,,;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
,,,;
,,,; Demonstrates simple analogue input
,,,; using an external reference voltage of 2.56V
,,,; The 8-bit result is converted to BCD for display
,,,; as a voltage using the standard LCD routines.
,,,;
,,,;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
,,,
,,, PROCESSOR 16F877
,,,; Clock = XT 4MHz, standard fuse settings
00002007,3731,, __CONFIG 0x3731
,,,
,,,; LABEL EQUATES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
,,,
,,, INCLUDE "P16F877A.INC"
,,, ; standard register labels
,,,
,,,;----------------------------------------------------------
,,,; User register labels
,,,;----------------------------------------------------------
,,,; GPR 20 - 2F allocated to included LCD display routine
,,,
,,,count EQU 30 ; Counter for ADC setup delay
,,,ADbin EQU 31 ; Binary input value
,,,huns EQU 32 ; Hundreds digit in decimal value
,,,tens EQU 33 ; Tens digit in decimal value
,,,ones EQU 34 ; Ones digit in decimal value
,,,
,,,;----------------------------------------------------------
,,,; PROGRAM BEGINS
,,,;----------------------------------------------------------
,,,
,,, ORG 0 ; Default start address
00000000,0000,, NOP ; required for ICD mode
,,,
,,,;----------------------------------------------------------
,,,; Port & display setup
,,,
00000001,1683 1303,, BANKSEL TRISC ; Select bank 1
00000003,0188,, CLRF TRISD ; Display port is output
00000004,3003,, MOVLW B'00000011' ; Analogue input setup code
00000005,009F,, MOVWF ADCON1 ; Left justify result,
,,, ; Port A = analogue inputs
,,,
00000006,1283 1303,, BANKSEL PORTC ; Select bank 0
00000008,0188,, CLRF PORTD ; Clear display outputs
00000009,3041,, MOVLW B'01000001' ; Analogue input setup code
0000000A,009F,, MOVWF ADCON0 ; f/8, RA0, done, enable
,,,
0000000B,2067,, CALL inid ; Initialise the display
,,,
,,,;----------------------------------------------------------
,,,; MAIN LOOP
,,,;----------------------------------------------------------
,,,
0000000C,2010,start,start CALL getADC ; read input
0000000D,2019,, CALL condec ; convert to decimal
0000000E,2030,, CALL putLCD ; display input
0000000F,280C,, GOTO start ; jump to main loop
,,,
,,,;-----------------------------------------------------------
,,,; SUBROUTINES
,,,;-----------------------------------------------------------
,,,; Read ADC input and store .................................
,,,
00000010,3007,getADC,getADC MOVLW 007 ; load counter
00000011,00B0,, MOVWF count
00000012,0BB0,down,down DECFSZ count ; and delay 20us
00000013,2812,, GOTO down
,,,
00000014,151F,, BSF ADCON0,GO ; start ADC..
00000015,191F,wait,wait BTFSC ADCON0,GO ; ..and wait for finish
00000016,2815,, GOTO wait
,,,
00000017,081E,, MOVF ADRESH,W ; store result, high 8 bits
00000018,0008,, RETURN
,,,
,,,;-----------------------------------------------------------
,,,; Convert input to decimal
,,,
00000019,00B1,condec,condec MOVWF ADbin ; get ADC result
0000001A,01B2,, CLRF huns ; zero hundreds digit
0000001B,01B3,, CLRF tens ; zero tens digit
0000001C,01B4,, CLRF ones ; zero ones digit
,,,
,,,; Calclulate hundreds digit.................................
,,,
0000001D,1403,, BSF STATUS,C ; set carry for subtract
0000001E,3064,, MOVLW D'100' ; load 100
0000001F,02B1,sub1,sub1 SUBWF ADbin ; and subtract from result
00000020,0AB2,, INCF huns ; count number of loops
00000021,1803,, BTFSC STATUS,C ; and check if done
00000022,281F,, GOTO sub1 ; no, carry on
,,,
00000023,07B1,, ADDWF ADbin ; yes, add 100 back on
00000024,03B2,, DECF huns ; and correct loop count
,,,
,,,; Calculate tens and ones digit.............................
,,,
00000025,1403,, BSF STATUS,C ; repeat process for tens
00000026,300A,, MOVLW D'10' ; load 10
00000027,02B1,sub2,sub2 SUBWF ADbin ; and subtract from result
00000028,0AB3,, INCF tens ; count number of loops
00000029,1803,, BTFSC STATUS,C ; and check if done
0000002A,2827,, GOTO sub2 ; no, carry on
,,,
0000002B,07B1,, ADDWF ADbin ; yes, add 100 back on
0000002C,03B3,, DECF tens ; and correct loop count
0000002D,0831,, MOVF ADbin,W ; load remainder
0000002E,00B4,, MOVWF ones ; and store as ones digit
,,,
0000002F,0008,, RETURN ; done
,,,
,,,;-----------------------------------------------------------
,,,; Output to display
,,,
00000030,10F4,putLCD,putLCD BCF Select,RS ; set display command mode
00000031,3080,, MOVLW 080 ; code to home cursor
00000032,2057,, CALL send ; output it to display
00000033,14F4,, BSF Select,RS ; and restore data mode
,,,
,,,; Convert digits to ASCII and display..........................
,,,
00000034,3030,, MOVLW 030 ; load ASCII offset
00000035,07B2,, ADDWF huns ; convert hundreds to ASCII
00000036,07B3,, ADDWF tens ; convert tens to ASCII
00000037,07B4,, ADDWF ones ; convert ones to ASCII
,,,
00000038,0832,, MOVF huns,W ; load hundreds code
00000039,2057,, CALL send ; and send to display
0000003A,0833,, MOVF tens,W ; load tens code
0000003B,2057,, CALL send ; and output
0000003C,302E,, MOVLW '.' ; load point code
0000003D,2057,, CALL send ; and output
0000003E,0834,, MOVF ones,W ; load ones code
0000003F,2057,, CALL send ; and output
00000040,3020,, MOVLW ' ' ; load space code
00000041,2057,, CALL send ; and output
00000042,306D,, MOVLW 'm' ; load volts code
00000043,2057,, CALL send ; and output
00000044,3056,, MOVLW 'V' ; load volts code
00000045,2057,, CALL send ; and output
,,,
00000046,0008,, RETURN ; done
,,,
,,,;----------------------------------------------------------
,,,; INCLUDED ROUTINES
,,,;----------------------------------------------------------
,,,; Include LCD driver routine
,,,;
,,, INCLUDE "LCDIS.INC"
,,,; LCDIS.INC MPB 19-12-05
,,,;
,,,; Include file to operate 16x2 LCD display
,,,; Uses GPR 70 - 75
,,,;
,,,; Final version
,,,;-------------------------------------------------------------------------------------------
,,,
,,,Timer1 EQU 70 ; 1ms count register
,,,TimerX EQU 71 ; Xms count register
,,,Var EQU 72 ; Output variable
,,,Point EQU 73 ; Program table pointer
,,,Select EQU 74 ; Used to set or clear RS bit
,,,OutCod EQU 75 ; Temp store for output code
,,,
,,,RS EQU 1 ; Register select output bit
,,,E EQU 2 ; Enable output clocks display input
,,,
,,,
,,,;--------------------------------------------------------------------------------------------
,,,; 1ms delay with 1us cycle time (1000 cycles)
,,,;--------------------------------------------------------------------------------------------
00000047,30F9,onems,onems MOVLW D'249' ; Count for 1ms delay
00000048,00F0,, MOVWF Timer1 ; Load count
00000049,0000,loop1,loop1 NOP ; Pad for 4 cycle loop
0000004A,0BF0,, DECFSZ Timer1 ; Count
0000004B,2849,, GOTO loop1 ; until Z
0000004C,0008,, RETURN ; and finish
,,,
,,,;---------------------------------------------------------------------------------------------
,,,; Delay Xms
,,,; Receives count in W, uses Onems
,,,;---------------------------------------------------------------------------------------------
0000004D,00F1,xms,xms MOVWF TimerX ; Count for X ms
0000004E,2047,loopX,loopX CALL onems ; Delay 1ms
0000004F,0BF1,, DECFSZ TimerX ; Repeat X times
00000050,284E,, GOTO loopX ; until Z
00000051,0008,, RETURN ; and finish
,,,
,,,;---------------------------------------------------------------------------------------------
,,,; Generate data/command clock siganl E
,,,;---------------------------------------------------------------------------------------------
00000052,1508,pulseE,pulseE BSF PORTD,E ; Set E high
00000053,2047,, CALL onems ; Delay 1ms
00000054,1108,, BCF PORTD,E ; Reset E low
00000055,2047,, CALL onems ; Delay 1ms
00000056,0008,, RETURN ; done
,,,
,,,;---------------------------------------------------------------------------------------------
,,,; Send a command byte in two nibbles from RB4 - RB7
,,,; Receives command in W, uses PulseE and Onems
,,,;---------------------------------------------------------------------------------------------
00000057,00F5,send,send MOVWF OutCod ; Store output code
00000058,39F0,, ANDLW 0F0 ; Clear low nybble
00000059,0088,, MOVWF PORTD ; Output high nybble
0000005A,18F4,, BTFSC Select,RS ; Test RS bit
0000005B,1488,, BSF PORTD,RS ; and set for data
0000005C,2052,, CALL pulseE ; and clock display register
0000005D,2047,, CALL onems ; wait 1ms for display to complete
,,,
0000005E,0EF5,, SWAPF OutCod ; Swap low and high nybbles
0000005F,0875,, MOVF OutCod,W ; Retrieve output code
00000060,39F0,, ANDLW 0F0 ; Clear low nybble
00000061,0088,, MOVWF PORTD ; Output low nybble
00000062,18F4,, BTFSC Select,RS ; Test RS bit
00000063,1488,, BSF PORTD,RS ; and set for data
00000064,2052,, CALL pulseE ; and clock display register
00000065,2047,, CALL onems ; wait 1ms for display to complete
00000066,0008,, RETURN ; done
,,,
,,,;---------------------------------------------------------------------------------------------
,,,; Initialise the display
,,,; Uses Send
,,,;---------------------------------------------------------------------------------------------
00000067,3064,inid,inid MOVLW D'100' ; Load count for 100ms delay
00000068,204D,, CALL xms ; and wait for display start
00000069,30F0,, MOVLW 0F0 ; Mask for select code
0000006A,00F4,, MOVWF Select ; High nybble not masked
,,,
0000006B,3030,, MOVLW 0x30 ; Load initial nibble
0000006C,0088,, MOVWF PORTD ; and output it to display
0000006D,2052,, CALL pulseE ; Latch initial code
0000006E,3005,, MOVLW D'5' ; Set delay 5ms
0000006F,204D,, CALL xms ; and wait
00000070,2052,, CALL pulseE ; Latch initial code again
00000071,2047,, CALL onems ; Wait 1ms
00000072,2052,, CALL pulseE ; Latch initial code again
00000073,1208,, BCF PORTD,4 ; Set 4-bit mode
00000074,2052,, CALL pulseE ; Latch it
,,,
00000075,3028,, MOVLW 0x28 ; Set 4-bit mode, 2 lines
00000076,2057,, CALL send ; and send code
00000077,3008,, MOVLW 0x08 ; Switch off display
00000078,2057,, CALL send ; and send code
00000079,3001,, MOVLW 0x01 ; Code to clear display
0000007A,2057,, CALL send ; and send code
0000007B,3006,, MOVLW 0x06 ; Enable cursor auto inc
0000007C,2057,, CALL send ; and send code
0000007D,3080,, MOVLW 0x80 ; Zero display address
0000007E,2057,, CALL send ; and send code
0000007F,300C,, MOVLW 0x0C ; Turn on display
00000080,2057,, CALL send ; and send code
,,,
00000081,0008,, RETURN ; Done
,,,
,,,; 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)
,,,;
,,,;----------------------------------------------------------
,,, END ; of source code
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -