Microcontroller › PIC › Need help with creativity on modify the code
- This topic has 1 reply, 1 voice, and was last updated 12 years ago by
Aaron.
-
AuthorPosts
-
May 15, 2011 at 12:53 pm #937
Aaron
ParticipantHi there all friends, I just make a code that can display 0-9 when I run it with PIC Simulator IDE when pressing 1 of the port on keypad matrix and the output will show out at 7-segment LED display panel. Anyone can modify it with code that add some creative functions to the original code with MPLAB and attach the code for me ? Thanks ^^
Here are the codes that I have done.
; Keyscan.asm
; Reads keypad and returns value in W regINCLUDE P16F877A.INC
__CONFIG _XT_OSC & _WDT_OFF & _LVP_OFF
key EQU 0x20 ; Count for keys; Initialise ports
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
CLRW
MOVWF TRISC ; Set PortC as outputs
BANKSEL PORTD
MOVWF PORTD
CLRF PORTC
GOTO main; Read keypad
main CALL scan
MOVWF key
CALL show ; Display it
GOTO main ; Repeat; Output display code..
show CALL table ; Get display code
MOVWF PORTC ; and show it
RETURNscan 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
RETLW D’1′ ; Key = 1
BTFSC PORTD,1 ; Test and skip if Row 2 = 0
RETLW D’4′ ; Key = 4
BTFSC PORTD,2 ; Test and skip if Row 3 = 0
RETLW D’7′ ; Key = 7
BTFSC PORTD,3 ; Test and skip if Row 4 = 0
RETLW D’10’ ; Key = * (10)
BCF PORTD,4 ; Column 1 = 0
BSF PORTD,5 ; Column 2 = 1
BTFSC PORTD,0 ; Test and skip if Row 1 = 0
RETLW D’2′ ; Key = 2
BTFSC PORTD,1 ; Test and skip if Row 2 = 0
RETLW D’5′ ; Key = 5
BTFSC PORTD,2 ; Test and skip if Row 3 = 0
RETLW D’8′ ; Key = 8
BTFSC PORTD,3 ; Test and skip if Row 4 = 0
RETLW D’11’ ; 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
RETLW D’3′ ; Key = 3
BTFSC PORTD,1 ; Test and skip if Row 2 = 0
RETLW D’6′ ; Key = 6
BTFSC PORTD,2 ; Test and skip if Row 3 = 0
RETLW D’9′ ; Key = 9
BTFSC PORTD,3 ; Test and skip if Row 4 = 0
RETLW D’12’ ; Key = # (12)
RETLW 0 ; No Key Pressed
; Display code table.
table MOVF key,W ; Get key number
ADDWF PCL ; Jump to Program Counter + W
RETLW B’00000000′ ; No key
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’
RETLW B’10010010′ ; Code for ‘*’
RETLW B’01111110′ ; Code for ‘0’
RETLW B’11101100′ ; Code for ‘#’END
May 16, 2011 at 2:43 pm #6244Aaron
ParticipantWith this code how can I do to make it has the function of calculator that can add and subtract ? I totally got no clue about how to do this @@ Hope that someone can help me to solve this and thanks.
-
AuthorPosts
- You must be logged in to reply to this topic.