EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Topics / Need help with creativity on modify the code

Need help with creativity on modify the code

|

Microcontroller › PIC › Need help with creativity on modify the code

  • This topic has 1 reply, 1 voice, and was last updated 14 years, 1 month ago by Aaron.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • May 15, 2011 at 12:53 pm #937
    Aaron
    Participant

    Hi 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 reg

            INCLUDE 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
            RETURN

    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
            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 #6244
    Aaron
    Participant

    With 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.

  • Author
    Posts
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • Adhesive Defibrillator Pad Cable June 25, 2025
  • Epson crystal oscillators June 25, 2025
  • Simple LED Analog Clock Idea June 24, 2025
  • Fun with AI and swordfish basic June 24, 2025
  • Microinverters and storeage batteries? June 23, 2025

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise