Hexadecimal ve decimal monitor

Başlatan ipek, 20 Mart 2012, 21:55:10

ipek

Yıllar evvel Dontronics yada Parallax firmasından 8 Bit Data Bus  monitor diye bir kit almıştım, 1995 ten sonra üretimi durmuş.
8 bitlik bir dip switci okumam icab ediyor sıvadım koları oturdum klavyeye ikinci saati takıldım ,sanırım 12bit 14bit farkına takıldım delay rutini bana yabancı geldi bir delay rutini uydurdum nafile.orjinal kit'te bir jumper var bunu yerine takar isem decimal yani 255 olarak okuyorum takmaz isem FFH olarak okuyorum
aslında LCD'li olsa daha iyi olurdu neyse bunada razıyım bu devrenin üzerinde 16C55 var idi 16F873 ve 16F876 bunların comparator'leriyle uğraşmayım diye kutularda bir tane 16F870 buldum firma hex ve source kodunu disket ile yollamıştı oturup 16F870 ' convert işlemine başladım ram bölgesi start vektörü derken
hexadesimal olarak okumayı başardım isis'te ve breadboard üstünde çalıştırdım ne kadar uğraştımsa desimal olarak okuyamadım jumperi desimale almama rağmen hala hex olarak okunuyor
biraz uzun olacak
dosyanın orijinal hali
;;	LIST	P=16C55, N=38, C=132, R=DEC

;****************************************************************************
;*                            DATA BUS MONITOR                              *
                
;*                 For use on the DTE DATA BUS MONITOR board                *

;****************************************************************************


; Define the general registers and I/O port addresses

RTCC	EQU	01		; Real Time Clock/Counter register address
PC	EQU	02		; Program Counter address
STATUS	EQU	03		; Status register address
FSR	EQU	04		; File Select Register address
PORTA	EQU	05		; I/O Port A (lower 4 bits only available)
PORTB	EQU	06		; I/O Port B (all 8 bits available)
PORTC	EQU	07		; I/O Port C (not fitted on PIC16C54/56)

; Assign labels to programming constants used in PIC assembly language.

W	EQU	0		; Destination register becomes 'W' (acc.)
F	EQU	1		; Destination register becomes 'F' (file)

; Assign labels to the various bit values of the STATUS register (03h)

CARRY	EQU	0		; carry bit
DCARRY	EQU	1		; digit carry bit
ZERO	EQU	2		; Zero bit
PDOWN	EQU	3		; power-down bit
WATDOG	EQU	4		; watchdog time-out bit

; Assign basic pin labels to the bit numbers for I/O port A.

RA0	EQU	00		; Port A I/O bit 0
RA1	EQU	01		; Port A I/O bit 1
RA2	EQU	02		; Port A I/O bit 2
RA3	EQU	03		; Port A I/O bit 3

; Assign basic pin labels to the bit numbers for I/O port B.

RB0	EQU	00		; Port B I/O bit 0
RB1	EQU	01		; Port B I/O bit 1
RB2	EQU	02		; Port B I/O bit 2
RB3	EQU	03		; Port B I/O bit 3
RB4	EQU	04		; Port B I/O bit 4
RB5	EQU	05		; Port B I/O bit 5
RB6	EQU	06		; Port B I/O bit 6
RB7	EQU	07		; Port B I/O bit 7

; Assign basic pin labels to the bit numbers for I/O port C.

RC0	EQU	00		; Port C I/O bit 0
RC1	EQU	01		; Port C I/O bit 1
RC2	EQU	02		; Port C I/O bit 2
RC3	EQU	03		; Port C I/O bit 3
RC4	EQU	04		; Port C I/O bit 4
RC5	EQU	05		; Port C I/O bit 5
RC6	EQU	06		; Port C I/O bit 6
RC7	EQU	07		; Port C I/O bit 7

; Assign labels to the various (RAM) data file registers used

	ORG	08		; Set base address for RAM

COUNT1	RES	1		; General purpose counter
DECIM1	RES	1		; Decimal store for 1s digit
DECIM2	RES	1		; Decimal store for 10s digit
DECIM3	RES	1		; Decimal store for 100s digit
DIGIT1	RES	1		; Store for right display data
DIGIT2	RES	1		; Store for middle display data
DIGIT3	RES	1		; Store for left display data
HEXLO	RES	1		; Hex store for middle digit (LSB)
HEXHI	RES	1		; Hex store for left digit (MSB)
IPBUFF	RES	1		; Input buffer status byte

; end of Equates section

; ***************************************************************************

; Start of Program Memory

	ORG	0000		; SET ORIGIN ADDRESS

; General purpose delay routine.  "COUNT1" starts and ends at zero

DELAY
	DECFSZ	COUNT1		; WAIT ...
	GOTO	DELAY
	RETLW	0		; FINISHED - RETURN

; Get input value from port B and store in "IPBUFF"

GETDATA
	MOVF	PORTB,W		; GET DATA ON PORT B
	MOVWF	IPBUFF		; STORE IT IN "IPBUFF"

; Convert "IPBUFF" into Hexadecimal values in "HEXLO" and "HEXHI",
; and into Decimal values in "DECIM1", "DECIM2" and "DECIM3"

; Hexadecimal conversion routine

CONVERT
	SWAPF	IPBUFF,W	; GET NIBBLE SWAPPED "IPBUFF" IN 'W'
	ANDLW	H'0F'		; MASK OFF THE LEFT NIBBLE
	MOVWF	HEXHI		; AND PUT IT IN "HEXHI" (MSB)
	MOVF	IPBUFF,W	; GET "IPBUFF" IN 'W'
	ANDLW	H'0F'		; MASK OFF THE LEFT NIBBLE
	MOVWF	HEXLO		; AND PUT IT IN "HEXLO" (LSB)

; Decimal conversion routine

	MOVF	IPBUFF,W	; GET "IPBUFF" VALUE
	MOVWF	DECIM1		; COPY IT TO RIGHT DIGIT DECIMAL STORE
	CLRF	DECIM2		; CLEAR MIDDLE DIGIT DECIMAL STORE
	CLRF	DECIM3		; CLEAR LEFT DIGIT DECIMAL STORE
CONV2
	MOVLW	10
	SUBWF	DECIM1,W	; CAN 10 BE SUBTRACTED FROM "DECIM1" ?
	BTFSS	STATUS,CARRY	; YES - MODIFY THE REGISTERS
	RETLW	00		; NO - FINISHED CALCULATING - EXIT
	MOVWF	DECIM1		; STORE THE RESULT BACK
	INCF	DECIM2		; AND ADD 1 TO "DECIM2"
	MOVLW	10
	SUBWF	DECIM2,W	; CAN 10 BE SUBTRACTED FROM "DECIM2" ?
	BTFSS	STATUS,CARRY	; YES - MODIFY THE REGISTERS
	GOTO	CONV2		; NO - GO ROUND AGAIN
	MOVWF	DECIM2		; STORE THE RESULT BACK
	INCF	DECIM3		; AND ADD 1 TO "DECIM3"
	GOTO	CONV2		; UNTIL "DECIM1" IS LESS THAN 10

; Get a display character bit pattern by converting 'W' to display code

GETCHAR
	ADDWF	PC,F		; USE 'W' AS AN OFFSET FOR 'PC'
	RETLW	B'11101110'	; RETURN WITH "0" DISPLAY CODE
	RETLW	B'00100100'	; RETURN WITH "1" DISPLAY CODE
	RETLW	B'10111010'	; RETURN WITH "2" DISPLAY CODE
	RETLW	B'10110110'	; RETURN WITH "3" DISPLAY CODE
	RETLW	B'01110100'	; RETURN WITH "4" DISPLAY CODE
	RETLW	B'11010110'	; RETURN WITH "5" DISPLAY CODE
	RETLW	B'11011110'	; RETURN WITH "6" DISPLAY CODE
	RETLW	B'10100100'	; RETURN WITH "7" DISPLAY CODE
	RETLW	B'11111110'	; RETURN WITH "8" DISPLAY CODE
	RETLW	B'11110110'	; RETURN WITH "9" DISPLAY CODE
	RETLW	B'11111100'	; RETURN WITH "A" DISPLAY CODE
	RETLW	B'01011110'	; RETURN WITH "b" DISPLAY CODE
	RETLW	B'11001010'	; RETURN WITH "C" DISPLAY CODE
	RETLW	B'00111110'	; RETURN WITH "d" DISPLAY CODE
	RETLW	B'11011010'	; RETURN WITH "E" DISPLAY CODE
	RETLW	B'11011000'	; RETURN WITH "F" DISPLAY CODE

;*****************************************************************************

; Refresh the displays.  The "DIGIT"s finally contain the bit patterns
; ready for displaying the charaters require for Hex or Decimal readout.
; If display is Decimal then blank out any leading zeros except right digit.

DISPLAY
	BTFSC	PORTA,RA0	; SKIP IF DECIMAL MODE SELECTED
	GOTO	DISP3		; ELSE DISPLAY DATA IN HEX FORMAT

; Display data in Decimal format

	MOVF	DECIM1,W	; GET RIGHT DIGIT DECIMAL DATA
	CALL	GETCHAR		; CONVERT TO DISPLAY CODE
	MOVWF	DIGIT1		; PUT IT IN RIGHT DIGIT
	MOVF	DECIM2,W	; GET MIDDLE DIGIT DECIMAL DATA
	CALL	GETCHAR		; CONVERT TO DISPLAY CODE
	MOVWF	DIGIT2		; PUT IT IN MIDDLE DIGIT
	MOVF	DECIM3,W	; GET LEFT DIGIT DECIMAL DATA
	CALL	GETCHAR		; CONVERT TO DISPLAY CODE
	MOVWF	DIGIT3		; PUT IT IN LEFT DIGIT

; Now blank off any leading zero's

	MOVF	DECIM3,W	; GET LEFT DIGIT DECIMAL DATA
	BTFSS	STATUS,ZERO	; BLANK IT OUT IF ZERO - '0'
	GOTO	DISP4		; NOT ZERO - LEAVE IT ALONE
	CLRF	DIGIT3		; CLEAR ALL BITS IN LEFT DIGIT
	MOVF	DECIM2,W	; GET MIDDLE DIGIT DECIMAL DATA
	BTFSC	STATUS,ZERO	; LEAVE IT ALONE IF NOT ZERO
	CLRF	DIGIT2		; OTHERWISE BLANK IT OUT
	GOTO	DISP4		; LEAVE RIGHT DIGIT ALONE ANYWAY

; Display data in Hexadecimal format

DISP3
	MOVF	HEXHI,W		; GET MSB OF HEX VALUE
	CALL	GETCHAR		; CONVERT TO DISPLAY CODE
	MOVWF	DIGIT3		; PUT IT IN LEFT DIGIT
	MOVF	HEXLO,W		; GET LSB OF HEX VALUE
	CALL	GETCHAR		; CONVERT TO DISPLAY CODE
	MOVWF	DIGIT2		; PUT IT IN MIDDLE DIGIT
	MOVLW	B'01111100'
	MOVWF	DIGIT1		; PUT 'H' IN RIGHT DIGIT - "DIGIT1"

; "DIGIT"s contain the required display codes, now light up the displays

DISP4
	MOVF	DIGIT3,W	; GET LEFT DIGIT DATA
	MOVWF	PORTC		; PUT IT ON PORT C
	BCF	PORTA,RA3	; LIGHT UP THE DISPLAY
	CALL	DELAY		; WAIT FOR LIGHT-UP PERIOD
	BSF	PORTA,RA3	; AND TURN IT OFF AGAIN

	MOVF	DIGIT2,W	; GET MIDDLE DIGIT DATA
	MOVWF	PORTC		; PUT IT ON PORT C
	BCF	PORTA,RA2	; LIGHT UP THE DISPLAY
	CALL	DELAY		; WAIT FOR LIGHT-UP PERIOD
	BSF	PORTA,RA2	; AND TURN IT OFF AGAIN

	MOVF	DIGIT1,W	; GET RIGHT DIGIT DATA
	MOVWF	PORTC		; PUT IT ON PORT C
	BCF	PORTA,RA1	; LIGHT UP THE DISPLAY
	CALL	DELAY		; WAIT FOR LIGHT-UP PERIOD
	BSF	PORTA,RA1	; AND TURN IT OFF AGAIN

; The program now falls through back to the 'START' routine

; *******************************************************
; * Beginning of the main program (program entry point) *
; *******************************************************

START
	MOVLW	255
	MOVWF	PORTA		; SET ALL PORT A OUTPUTS HIGH
	TRIS	PORTB		; SET PORT B FOR INPUT
	MOVLW	01
	TRIS	PORTA		; SET RA0 FOR INPUT
	CLRW
	MOVWF	PORTC		; START WITH ALL DISPLAY BITS OFF
	TRIS	PORTC		; SET PORT C FOR OUTPUT

	CALL	GETDATA		; READ AND CONVERT DATA ON PORT B
	GOTO	DISPLAY		; DISPLAY IT AND GO ROUND FOREVER

;*****************************************************************************

; Set up the reset vector for the type of processor used.
; This varies between devices but is at 1FFh on the 16C54

	ORG	H'1FF'
	GOTO	START
ZZZ				; END OF PROGRAM MARKER
	END


buda eklemeye çalıştığım kod

#include p16f870.inc


; Assign basic pin labels to the bit numbers for I/O port A.

 errorlevel ,-302 ,-305

; Assign labels to the various (RAM) data file registers used
 CBLOCK	0x20		; Set base address for RAM

				; General purpose counter
 H_CONT	
 L_CONT
DECIM1			; Decimal store for 1s digit
DECIM2			; Decimal store for 10s digit
DECIM3			; Decimal store for 100s digit
DIGIT1			; Store for right display data
DIGIT2			; Store for middle display data
DIGIT3			; Store for left display data
HEXLO			; Hex store for middle digit (LSB)
HEXHI			; Hex store for left digit (MSB)
IPBUFF			; Input buffer status byte
 ENDC
; end of Equates section



; Start of Program Memory

	ORG	00		; SET ORIGIN ADDRESS




; INITIALISE PORTS

	BSF	STATUS,5
	movlw b'00000001'       ; A0 input other  IO pins = outputs
	movwf TRISA
	movlw b'11111111'		; PortB All IO pins = inputs
	movwf TRISB
	movlw b'00000000'		; PortC All IO pins = outputs
	movwf TRISC

;---------------------------------------------------------
	movlw b'00000110'       ; all analog pins = digital
	movwf ADCON1			;16F870'te comparator yok CMCON 7 de gerek yok
;----------------------------------------------------------

	bcf STATUS,RP0  ; back to RAM page 0

START;


	CALL	GETDATA		; READ AND CONVERT DATA ON PORT B
	GOTO	DISPLAY		; DISPLAY IT AND GO ROUND FOREVER

;*****************************************************************************


; Get input value from port B and store in "IPBUFF"

GETDATA:
	MOVF	PORTB,W		; GET DATA ON PORT B
	MOVWF	IPBUFF		; STORE IT IN "IPBUFF"

; Convert "IPBUFF" into Hexadecimal values in "HEXLO" and "HEXHI",
; and into Decimal values in "DECIM1", "DECIM2" and "DECIM3"

; Hexadecimal conversion routine

CONVERT:
	SWAPF	IPBUFF,W	; GET NIBBLE SWAPPED "IPBUFF" IN 'W'
	ANDLW	H'0F'		; MASK OFF THE LEFT NIBBLE
	MOVWF	HEXHI		; AND PUT IT IN "HEXHI" (MSB)
	MOVF	IPBUFF,W	; GET "IPBUFF" IN 'W'
	ANDLW	H'0F'		; MASK OFF THE LEFT NIBBLE
	MOVWF	HEXLO		; AND PUT IT IN "HEXLO" (LSB)

; Decimal conversion routine

	MOVF	IPBUFF,W	; GET "IPBUFF" VALUE
	MOVWF	DECIM1		; COPY IT TO RIGHT DIGIT DECIMAL STORE
	CLRF	DECIM2		; CLEAR MIDDLE DIGIT DECIMAL STORE
	CLRF	DECIM3		; CLEAR LEFT DIGIT DECIMAL STORE
CONV2:
	MOVLW	10
	SUBWF	DECIM1,W	; CAN 10 BE SUBTRACTED FROM "DECIM1" ?
	BTFSS	STATUS,C	; YES - MODIFY THE REGISTERS
	RETURN				; NO - FINISHED CALCULATING - EXIT
	MOVWF	DECIM1		; STORE THE RESULT BACK
	INCF	DECIM2		; AND ADD 1 TO "DECIM2"
	MOVLW	10
	SUBWF	DECIM2,W	; CAN 10 BE SUBTRACTED FROM "DECIM2" ?
	BTFSS	STATUS,C	; YES - MODIFY THE REGISTERS
	GOTO	CONV2		; NO - GO ROUND AGAIN
	MOVWF	DECIM2		; STORE THE RESULT BACK
	INCF	DECIM3		; AND ADD 1 TO "DECIM3"
	GOTO	CONV2		; UNTIL "DECIM1" IS LESS THAN 10

; Get a display character bit pattern by converting 'W' to display code

GETCHAR:
	ADDWF	PCL,F		; USE 'W' AS AN OFFSET FOR 'PC'
	RETLW	B'11101110'	; RETURN WITH "0" DISPLAY CODE
	RETLW	B'00100100'	; RETURN WITH "1" DISPLAY CODE
	RETLW	B'10111010'	; RETURN WITH "2" DISPLAY CODE
	RETLW	B'10110110'	; RETURN WITH "3" DISPLAY CODE
	RETLW	B'01110100'	; RETURN WITH "4" DISPLAY CODE
	RETLW	B'11010110'	; RETURN WITH "5" DISPLAY CODE
	RETLW	B'11011110'	; RETURN WITH "6" DISPLAY CODE
	RETLW	B'10100100'	; RETURN WITH "7" DISPLAY CODE
	RETLW	B'11111110'	; RETURN WITH "8" DISPLAY CODE
	RETLW	B'11110110'	; RETURN WITH "9" DISPLAY CODE
	RETLW	B'11111100'	; RETURN WITH "A" DISPLAY CODE
	RETLW	B'01011110'	; RETURN WITH "b" DISPLAY CODE
	RETLW	B'11001010'	; RETURN WITH "C" DISPLAY CODE
	RETLW	B'00111110'	; RETURN WITH "d" DISPLAY CODE
	RETLW	B'11011010'	; RETURN WITH "E" DISPLAY CODE
	RETLW	B'11011000'	; RETURN WITH "F" DISPLAY CODE

;*****************************************************************************

; Refresh the displays.  The "DIGIT"s finally contain the bit patterns
; ready for displaying the charaters require for Hex or Decimal readout.
; If display is Decimal then blank out any leading zeros except right digit.

DISPLAY:
	BTFSC	PORTA,0		; SKIP IF DECIMAL MODE SELECTED
	GOTO	DISP3		; ELSE DISPLAY DATA IN HEX FORMAT

; Display data in Decimal format

	MOVF	DECIM1,W	; GET RIGHT DIGIT DECIMAL DATA
	CALL	GETCHAR		; CONVERT TO DISPLAY CODE
	MOVWF	DIGIT1		; PUT IT IN RIGHT DIGIT
	MOVF	DECIM2,W	; GET MIDDLE DIGIT DECIMAL DATA
	CALL	GETCHAR		; CONVERT TO DISPLAY CODE
	MOVWF	DIGIT2		; PUT IT IN MIDDLE DIGIT
	MOVF	DECIM3,W	; GET LEFT DIGIT DECIMAL DATA
	CALL	GETCHAR		; CONVERT TO DISPLAY CODE
	MOVWF	DIGIT3		; PUT IT IN LEFT DIGIT

; Now blank off any leading zero's

	MOVF	DECIM3,W	; GET LEFT DIGIT DECIMAL DATA
	BTFSS	STATUS,Z	; BLANK IT OUT IF ZERO - '0'
	GOTO	DISP4		; NOT ZERO - LEAVE IT ALONE
	CLRF	DIGIT3		; CLEAR ALL BITS IN LEFT DIGIT
	MOVF	DECIM2,W	; GET MIDDLE DIGIT DECIMAL DATA
	BTFSC	STATUS,Z	; LEAVE IT ALONE IF NOT ZERO
	CLRF	DIGIT2		; OTHERWISE BLANK IT OUT
	GOTO	DISP4		; LEAVE RIGHT DIGIT ALONE ANYWAY

; Display data in Hexadecimal format

DISP3:
	MOVF	HEXHI,W		; GET MSB OF HEX VALUE
	CALL	GETCHAR		; CONVERT TO DISPLAY CODE
	MOVWF	DIGIT3		; PUT IT IN LEFT DIGIT
	MOVF	HEXLO,W		; GET LSB OF HEX VALUE
	CALL	GETCHAR		; CONVERT TO DISPLAY CODE
	MOVWF	DIGIT2		; PUT IT IN MIDDLE DIGIT
	MOVLW	B'01111100'
	MOVWF	DIGIT1		; PUT 'H' IN RIGHT DIGIT - "DIGIT1"

; "DIGIT"s contain the required display codes, now light up the displays

DISP4:
	MOVF	DIGIT3,W	; GET LEFT DIGIT DATA
	MOVWF	PORTC		; PUT IT ON PORT C
	BCF	PORTA,3			; LIGHT UP THE DISPLAY
	CALL	DELAY		; WAIT FOR LIGHT-UP PERIOD
	BSF	PORTA,3			; AND TURN IT OFF AGAIN

	MOVF	DIGIT2,W	; GET MIDDLE DIGIT DATA
	MOVWF	PORTC		; PUT IT ON PORT C
	BCF	PORTA,2			; LIGHT UP THE DISPLAY
	CALL	DELAY		; WAIT FOR LIGHT-UP PERIOD
	BSF	PORTA,2			; AND TURN IT OFF AGAIN

	MOVF	DIGIT1,W	; GET RIGHT DIGIT DATA
	MOVWF	PORTC		; PUT IT ON PORT C
	BCF	PORTA,1			; LIGHT UP THE DISPLAY
	CALL	DELAY		; WAIT FOR LIGHT-UP PERIOD
	BSF	PORTA,1			; AND TURN IT OFF AGAIN
	GOTO	START
; The program now falls through back to the 'START' routine

DELAY:
 MOVLW	H'15'
 MOVWF   H_CONT
 CLRF    L_CONT

DELAY2:
 DECF    L_CONT,F	;Decrement the lower part CONT
 COMF    L_CONT,W	;Inverts the bits
 BTFSC   STATUS,Z	;If all zeros there 'rollover state
 DECF    H_CONT,F	;then decrements the upper part
 MOVF    L_CONT,W	;W Load in the lower
 IORWF   H_CONT,W	;Put OR'd with the upper part
 BTFSS   STATUS,Z	;skip if all zero (end of cycle)
 GOTO    DELAY2		;Otherwise returns DELAY2
 RETURN


	END


buda dosyalar kaynak kodu ve isis       http://www.dosyasitesi.com/download.php?file=5a62ce1c57c73dfcaca5c150641fc243


ipek

biraz daha uğraştıktan sonra meseleyi çözdüm
MOVLW   10
yerine
MOVLW   .10
desimal olduğunu belirten noktayı koyunca program normal çalışmaya başladı
şüphelendiğim delay rutinini eskisiyle değiştirdim gayet güzel çalışıyor.
böyle bir aparatı LCD ile yapan olursa haberim olsun ..kalın sağlıcakla  :)

celebrium

#2
Bir zamanlar bende sizin gibi pic assebly de 2500 satırlık kodlara varan ürünler tasarladım.
Şimdi kodları ve hatayı görünce iyiki vazgeçmişim diyorum. :)
Yazılım yapmanın eziyeti bu olsa gerek. Minnacık hata yap sonra fellik fellik ara.

Kod yazma şekliniz benim yazma stilimin aynısı olunca, yazma gereği duydum bu arada.

5 harf komut : 50 harf açıklama
Bilginlerin aydınlatamadığı toplumu şarlatanlar aydınlatır. Marquis De Condorcet