Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

how to make it can show more than 9. now only can show from 0 till 9

Status
Not open for further replies.

imnoobie

New Member
INCLUDE P16F877A.INC
__CONFIG _XT_OSC & _WDT_OFF & _LVP_OFF
; Count for keys
; Initialise ports
sho EQU 0x30
key EQU 0x20
addvalue EQU 0x21
num1 EQU 0x22
num2 EQU 0x23
num3 EQU 0x32
num4 EQU 0x33
num5 EQU 0x34
num6 EQU 0x26
num7 EQU 0x27
BANKSEL TRISD ;
MOVLW B'00001111' ; Set RD0-RD3 as inputs for Rows 1,2,3,4
MOVWF TRISD ; and RD4-RD7 as outputs for Columns 1,2,3
BANKSEL PORTD
CLRW ; Clear PORTD
MOVWF PORTD
BANKSEL TRISC
CLRW ; Set PORTC as outputs
MOVWF TRISC
BANKSEL PORTC
CLRF PORTC
BANKSEL TRISA
CLRW ; Set PORTC as outputs
MOVWF TRISA
BANKSEL PORTA
CLRF PORTA
movlw 0xFE
movwf key
clrw
GOTO main
; Read keypad
main movlw 0x01
movwf PORTA
movf num6,w
movwf PORTC
clrw
;movlw 0x02
;movwf PORTA
;movf num7,w
;movwf PORTC


;clrw
call scan

GOTO main ; Repeat


scan BSF PORTD,4 ; Column 1 = 1
BCF PORTD,5 ; Column 2 = 0
BCF PORTD,6 ; Column 3 = 0
BTFSC PORTD,0 ; Test and skip if Row 1 = 0
call one ; Key = 1
BTFSC PORTD,1 ; Test and skip if Row 2 = 0
call four ; Key = 4
BTFSC PORTD,2 ; Test and skip if Row 3 = 0
call seven ; Key = 7
BTFSC PORTD,3 ; Test and skip if Row 4 = 0
call equal ; Key = * (10)
BCF PORTD,4 ; Column 1 = 0
BSF PORTD,5 ; Column 2 = 1
BTFSC PORTD,0 ; Test and skip if Row 1 = 0
call two ; Key = 2
BTFSC PORTD,1 ; Test and skip if Row 2 = 0
call five ; Key = 5
BTFSC PORTD,2 ; Test and skip if Row 3 = 0
call eight ; Key = 8
BTFSC PORTD,3 ; Test and skip if Row 4 = 0
call zero ; Key = 0 (11)
BCF PORTD,5 ; Column 2 = 0
BSF PORTD,6 ; Column 3 = 1
BTFSC PORTD,0 ; Test and skip if Row 1 = 0
call three ; Key = 3
BTFSC PORTD,1 ; Test and skip if Row 2 = 0
call six ; Key = 6
BTFSC PORTD,2 ; Test and skip if Row 3 = 0
call nine ; Key = 9
BTFSC PORTD,3 ; Test and skip if Row 4 = 0
call add ; Key = +

return
add movlw 0x01
movwf addvalue
movf num1,w
movwf num3
movf num2,w
movwf num4
return
equal movf num1,w
addwf num3,w
movwf num1
call check
movwf num6
;movf num2,w
;addwf num4,w
;movwf num2
;call check
;movwf num7
;btfsc num1,3
;call checkcarry
return
;checkcarry movlw 0x0A
; btfsc num1,2
; call checkcarry1
; movwf num1
; movlw 0x01
; addwf num2,w
; movwf num2

return
;checkcarry1 btfsc num1,1
; subwf num1,w
; return

;show1 movf num1,w
; movwf num2
;
; MOVF num2,W
; call check
; movwf num7
; return
zero ;movlw 0x00
;movwf num5
;btfss key,1
;call show1
movlw 0x00
movwf num1
movlw 0xFD
movwf key
movlw B'01111110'
movwf num6
return
one ;btfss key,1
;call show1
movlw 0x01
movwf num1
movlw 0xFD
movwf key
movlw B'00001100'
movwf num6
return
two ;btfss key,1
;call show1
movlw 0x02
movwf num1
movlw 0xFD
movwf key
movlw B'10110110'
movwf num6
return
three ;btfss key,1
;call show1
movlw 0x03
movwf num1
movlw 0xFD
movwf key
movlw B'10011110'
movwf num6
return
four ;btfss key,1
;call show1
movlw 0x04
movwf num1
movlw 0xFD
movwf key
movlw B'11001100'
movwf num6
return
five ;btfss key,1
;call show1
movlw 0x05
movwf num1
movlw 0xFD
movwf key
movlw B'11011010'
movwf num6
return
six ;btfss key,1
;call show1
movlw 0x06
movwf num1
movlw 0xFD
movwf key
movlw B'11111010'
movwf num6
return
seven ;btfss key,1
;call show1
movlw 0x07
movwf num1
movlw 0xFD
movwf key
movlw B'00001110'
movwf num6
return
eight ;btfss key,1
;call show1
movlw 0x08
movwf num1
movlw 0xFD
movwf key
movlw B'11111110'
movwf num6
return
nine ;btfss key,1
;call show1
movlw 0x09
movwf num1
movlw 0xFD
movwf key
movlw B'11001110'
movwf num6
return
check ; Get key number
ADDWF PCL ; Jump to Program Counter + W
RETLW B'01111110' ; Code for '0'
RETLW B'00001100' ; Code for '1'
RETLW B'10110110' ; Code for '2'
RETLW B'10011110' ; Code for '3'
RETLW B'11001100' ; Code for '4'
RETLW B'11011010' ; Code for '5'
RETLW B'11111010' ; Code for '6'
RETLW B'00001110' ; Code for '7'
RETLW B'11111110' ; Code for '8'
RETLW B'11001110' ; Code for '9'
end



please help me!!
 
hi,
Please use the Hash symbol in the Menu when posting code, it keeps the formatting, makes it easier to help.

E.

Code:
INCLUDE	P16F877A.INC 
	__config _XT_OSC & _WDT_OFF & _LVP_OFF
; Count for keys  
; Initialise ports  
sho	equ	0x30
key	equ	0x20
addvalue equ	0x21
num1	equ	0x22
num2	equ	0x23
num3	equ	0x32
num4	equ	0x33
num5	equ	0x34
num6	equ	0x26
num7	equ	0x27
	banksel	TRISD		;
	movlw	B'00001111'	; Set RD0-RD3 as inputs for Rows 1,2,3,4
	movwf	TRISD		; and RD4-RD7 as outputs for Columns 1,2,3
	banksel	PORTD
	clrw			; Clear PORTD
	movwf	PORTD
	banksel	TRISC
	clrw			; Set PORTC as outputs
	movwf	TRISC
	banksel	PORTC
	clrf	PORTC
	banksel	TRISA
	clrw			; Set PORTC as outputs
	movwf	TRISA
	banksel	PORTA
	clrf	PORTA
	movlw	0xFE
	movwf	key
	clrw
	goto	main
; Read keypad 
main	movlw	0x01
	movwf	PORTA
	movf	num6,w
	movwf	PORTC
	clrw
;movlw 0x02 
;movwf PORTA 
;movf num7,w 
;movwf PORTC 


;clrw
	call	scan

	goto	main		; Repeat


scan	bsf	PORTD,4		; Column 1 = 1
	bcf	PORTD,5		; Column 2 = 0
	bcf	PORTD,6		; Column 3 = 0
	btfsc	PORTD,0		; Test and skip if Row 1 = 0
	call	one		; Key = 1
	btfsc	PORTD,1		; Test and skip if Row 2 = 0
	call	four		; Key = 4
	btfsc	PORTD,2		; Test and skip if Row 3 = 0
	call	seven		; Key = 7
	btfsc	PORTD,3		; Test and skip if Row 4 = 0
	call	equal		; Key = * (10)
	bcf	PORTD,4		; Column 1 = 0
	bsf	PORTD,5		; Column 2 = 1
	btfsc	PORTD,0		; Test and skip if Row 1 = 0
	call	two		; Key = 2
	btfsc	PORTD,1		; Test and skip if Row 2 = 0
	call	five		; Key = 5
	btfsc	PORTD,2		; Test and skip if Row 3 = 0
	call	eight		; Key = 8
	btfsc	PORTD,3		; Test and skip if Row 4 = 0
	call	zero		; Key = 0 (11)
	bcf	PORTD,5		; Column 2 = 0
	bsf	PORTD,6		; Column 3 = 1
	btfsc	PORTD,0		; Test and skip if Row 1 = 0
	call	three		; Key = 3
	btfsc	PORTD,1		; Test and skip if Row 2 = 0
	call	six		; Key = 6
	btfsc	PORTD,2		; Test and skip if Row 3 = 0
	call	nine		; Key = 9
	btfsc	PORTD,3		; Test and skip if Row 4 = 0
	call	add		; Key = +

	return
add	movlw	0x01
	movwf	addvalue
	movf	num1,w
	movwf	num3
	movf	num2,w
	movwf	num4
	return
equal	movf	num1,w
	addwf	num3,w
	movwf	num1
	call	check
	movwf	num6
;movf num2,w 
;addwf num4,w 
;movwf num2 
;call check 
;movwf num7 
;btfsc num1,3 
;call checkcarry  
	return
;checkcarry movlw 0x0A  
; btfsc num1,2 
; call checkcarry1  
; movwf num1 
; movlw 0x01 
; addwf num2,w 
; movwf num2 

	return
;checkcarry1 btfsc num1,1  
; subwf num1,w 
; return 

;show1 movf num1,w  
; movwf num2 
;
; MOVF num2,W 
; call check 
; movwf num7 
; return 
zero				;movlw 0x00 
;movwf num5 
;btfss key,1 
;call show1 
	movlw	0x00
	movwf	num1
	movlw	0xFD
	movwf	key
	movlw	B'01111110'
	movwf	num6
	return
one				;btfss key,1 
;call show1 
	movlw	0x01
	movwf	num1
	movlw	0xFD
	movwf	key
	movlw	B'00001100'
	movwf	num6
	return
two				;btfss key,1 
;call show1 
	movlw	0x02
	movwf	num1
	movlw	0xFD
	movwf	key
	movlw	B'10110110'
	movwf	num6
	return
three				;btfss key,1 
;call show1 
	movlw	0x03
	movwf	num1
	movlw	0xFD
	movwf	key
	movlw	B'10011110'
	movwf	num6
	return
four				;btfss key,1 
;call show1 
	movlw	0x04
	movwf	num1
	movlw	0xFD
	movwf	key
	movlw	B'11001100'
	movwf	num6
	return
five				;btfss key,1 
;call show1 
	movlw	0x05
	movwf	num1
	movlw	0xFD
	movwf	key
	movlw	B'11011010'
	movwf	num6
	return
six				;btfss key,1 
;call show1 
	movlw	0x06
	movwf	num1
	movlw	0xFD
	movwf	key
	movlw	B'11111010'
	movwf	num6
	return
seven				;btfss key,1 
;call show1 
	movlw	0x07
	movwf	num1
	movlw	0xFD
	movwf	key
	movlw	B'00001110'
	movwf	num6
	return
eight				;btfss key,1 
;call show1 
	movlw	0x08
	movwf	num1
	movlw	0xFD
	movwf	key
	movlw	B'11111110'
	movwf	num6
	return
nine				;btfss key,1 
;call show1 
	movlw	0x09
	movwf	num1
	movlw	0xFD
	movwf	key
	movlw	B'11001110'
	movwf	num6
	return
check				; Get key number 
	addwf	PCL		; Jump to Program Counter + W
	retlw	B'01111110'	; Code for '0'
	retlw	B'00001100'	; Code for '1'
	retlw	B'10110110'	; Code for '2'
	retlw	B'10011110'	; Code for '3'
	retlw	B'11001100'	; Code for '4'
	retlw	B'11011010'	; Code for '5'
	retlw	B'11111010'	; Code for '6'
	retlw	B'00001110'	; Code for '7'
	retlw	B'11111110'	; Code for '8'
	retlw	B'11001110'	; Code for '9'
	end
 
Last edited:
I guess it's a 7 segment display so there's no point you are going to be able to show a single natural number higher than 9, if you want to display more, get another 7 segment display and you'd have to control it via the carry bit (I'm guessing nums are from 0 to 9), or even an alphanumeric display.

But if you want to show another type of symbols you just have to keep on developing the las part of the code I mean:

RETLW B'01111110' ; Code for '0'
RETLW B'00001100' ; Code for '1'
RETLW B'10110110' ; Code for '2'
RETLW B'10011110' ; Code for '3'
RETLW B'11001100' ; Code for '4'
RETLW B'11011010' ; Code for '5'
RETLW B'11111010' ; Code for '6'
RETLW B'00001110' ; Code for '7'
RETLW B'11111110' ; Code for '8'
RETLW B'11001110' ; Code for '9'

So, if you want to show the uppermost segment and the one that's inmediately under and right of it of the display you would put RETLW B'00000110; after the last one, but I don't think you could have any use for this.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top