DESIGN PROJECT STUCKED

Discussion in 'The Projects Forum' started by gadress, Apr 28, 2009.

  1. gadress

    Thread Starter New Member

    Apr 23, 2009
    9
    0
    I'M AM STUCK IN THE MIDDLE OF NO WHERE!!!!!!!

    I'M ACTUALLY DESIGNING THE 3X4 KEYPAD LOCK USING PIC16F628. BUT NOW I'M STUCK. THE PROGRAMME CAN ONLY DISPLAY ENTER CODE BUT CAN NOT SHOW THE NUMBERS PRESSED IN THE LCD. IF ANYONE COULD HELP PLEASE DO SO. I HAD A LOOK ON NIGELS TUTORIAL BUT I'M STILL STUCKED.:mad:
     
  2. -SK-

    Member

    Apr 14, 2009
    25
    0
    Post a schematic, code listing, and more complete explanation of how your project works. From the information you've given, it is impossible to provide help.
     
  3. gadress

    Thread Starter New Member

    Apr 23, 2009
    9
    0
    I'VE BEEN WORKING WITH THIS CODE
    ;3X4 KEYPAD CODE
    ;DESIGN PROJECT 3
    LIST P=16F628
    #INCLUDE <P16F628.INC>
    ERRORLEVEL 0, -302 ;SUPPRESS BANK SELECTION MESSAGES
    __CONFIG 0X3D18 ; SELECTING THE INTERNAL OSCILLATOR
    CBLOCK 0X20 ;START OF GENERAL PURPOSE REGISTERS
    COUNT ;USED IN LOOPING ROUTINES
    COUNT1 ;USED IN DELAY ROUTINE
    COUNTA ;USED IN DELAY ROUTINE
    COUNTB ;USED IN DELAY ROUTINE
    TMP1 ;TEMPORARY STORAGE
    TMP2
    TEMPLCD ;TEMP STORE FOR 4 BIT MODE
    TEMPLCD2
    KEY ;WHICH KEY WAS PRESSED
    ROWS ;COUNTER FOR NUMBER OF ROWS
    NUM1 ;REGISTERS FOR SECRET CODE
    NUM2
    NUM3
    NUM4
    KEY1 ;REGISTERS FOR KEYED ATTEMPTS
    KEY2
    KEY3
    KEY4
    ENDC
    LCD_PORT EQU PORTA ;LCD PORT
    LCD_TRIS EQU TRISA
    LCD_RS EQU 0X04
    LCD_RW EQU 0X06
    LCD_E EQU 0X07
    KEY_PORT EQU PORTB ;KEYPAD PORT
    KEY_TRIS EQU TRISB
    COL1 EQU 0 ;PINS USED FOR KEYPAD INPUTS
    COL2 EQU 1
    COL3 EQU 2
    COL4 EQU 3
    Row1 EQU 4
    ROW2 EQU 5
    ROW3 EQU 6
    ROW4 EQU 7
    ;******************************************************************************
    ; PINOUT USED *
    ;******************************************************************************
    ;PORTB , 0 IS COLUMN 1
    ;PORTB , 1 IS COLUMN 2
    ;PORTB , 2 IS COLUMN 3
    ;PORTB , 4 IS SCANNING ROW 1
    ;PORTB , 5 IS SCANNING ROW 2
    ;PORTB , 6 IS SCANNING ROW 3
    ;PORTB , 7 IS SCANNING ROW 4
    ;PORTA , 5 IS CLOCK OUTPUT
    ;PORTA , 6 IS RW PIN
    ;PORTA , 7 IS ENABLE
    ;PORTA , 4 IS R/S PIN
    ;PORTA0-A3 IS DATA LINES
    ORG 0X00
    GOTO START
    ;******************************************************************************
    ; TRANSLATION FOR KEYPAD,HEXADECIMAL TABLE LCD AND LOOKUP TABLE'S *
    ;******************************************************************************
    KEY_TABLE ADDWF PCL , F ;TRANSLATION TABLE FOR KEYPAD
    RETLW 0X31 ;1
    RETLW 0X34 ;4
    RETLW 0X37 ;7
    RETLW 0X2A ;*
    RETLW 0X32 ;2
    RETLW 0X35 ;5
    RETLW 0X38 ;8
    RETLW 0X30 ;0
    RETLW 0X33 ;3
    RETLW 0X36 ;6
    RETLW 0X39 ;9
    RETLW 0X23 ;#
    RETLW 0X43 ;C
    RETLW 0X44 ;D
    RETLW 0X45 ;E
    RETLW 0X46 ;F
    HEX_TABLE ADDWF PCL , F ;HEX TABLE FOR LCD ROUTINES
    RETLW 0X30
    RETLW 0X31
    RETLW 0X32
    RETLW 0X33
    RETLW 0X34
    RETLW 0X35
    RETLW 0X36
    RETLW 0X37
    RETLW 0X38
    RETLW 0X39
    RETLW 0X41
    RETLW 0X42
    RETLW 0X43
    RETLW 0X44
    RETLW 0X45
    RETLW 0X46
    TEXT ADDWF PCL, F
    RETLW 'E'
    RETLW 'N'
    RETLW 'T'
    RETLW 'E'
    RETLW 'R'
    RETLW ' '
    RETLW 'C'
    RETLW 'O'
    RETLW 'D'
    RETLW 'E'
    RETLW '!'
    RETLW '!'
    RETLW 0X00
    WRONG_TEXT ADDWF PCL, F
    RETLW 'W'
    RETLW 'R'
    RETLW 'O'
    RETLW 'N'
    RETLW 'G'
    RETLW ' '
    RETLW ' '
    RETLW 'C'
    RETLW 'O'
    RETLW 'D'
    RETLW 'E'
    RETLW '!'
    RETLW '!'
    RETLW 0X00
    CORRECT_TEXT ADDWF PCL, F
    RETLW 'C'
    RETLW 'O'
    RETLW 'R'
    RETLW 'R'
    RETLW 'E'
    RETLW 'C'
    RETLW 'T'
    RETLW ' '
    RETLW 'C'
    RETLW 'O'
    RETLW 'D'
    RETLW 'E'
    RETLW '.'
    RETLW 0X00
    ;****************************************************************************
    ; THE MAIN PROGRAM STARTS *
    ;****************************************************************************
    START MOVLW 0X07
    MOVWF CMCON ;TURN COMPARATORS OFF
    INITIALISE MOVLW '1' ;SET 4 DIGIT SECRET CODE
    MOVWF NUM1
    MOVLW '2'
    MOVWF NUM2
    MOVLW '3'
    MOVWF NUM3
    MOVLW '4'
    MOVWF NUM4
    SETPORTS BSF STATUS, RP0 ;SELECT BANK 1
    MOVLW 0X00 ;MAKE ALL PINS OUTPUTS
    MOVWF LCD_TRIS
    MOVLW 0X0F ;SET KEYPAD PINS
    MOVWF KEY_TRIS ;HALF IN, HALF OUT
    MOVWF TRISB
    BCF STATUS, RP0 ;SELECT BANK 0
    INIT CALL LCD_INIT ;SETUP LCD
    CLRF COUNT ;SET COUNTER REGISTER TO ZERO
    MESSAGE MOVF COUNT, W ;PUT COUNTER VALUE IN W
    CALL TEXT ;GET A CHARACTER FROM THE TEXT TABLE
    XORLW 0X00 ;IS IT A ZERO?
    BTFSC STATUS, Z
    GOTO MAIN
    CALL LCD_CHAR
    INCF COUNT, F
    GOTO MESSAGE
    WRONG CALL LCD_CLR
    CLRF COUNT ;SET COUNTER REGISTER TO ZERO
    MESSAGE1 MOVF COUNT,W ;PUT COUNTER VALUE IN W
    CALL WRONG_TEXT ;GET A CHARACTER FROM THE TEXT TABLE
    XORLW 0X00 ;IS IT A ZERO?
    BTFSC STATUS, Z
    GOTO WRONG_WAIT
    CALL LCD_CHAR
    INCF COUNT, F
    GOTO MESSAGE1
    WRONG_WAIT CALL LONGDELAY
    CALL LONGDELAY
    GOTO INIT
    CORRECT CALL LCD_CLR
    CLRF COUNT ;SET COUNTER REGISTER TO ZERO
    MESSAGE2 MOVF COUNT, W ;PUT COUNTER VALUE IN W
    CALL CORRECT_TEXT ;GET A CHARACTER FROM THE TEXT TABLE
    XORLW 0X00 ;IS IT A ZERO?
    BTFSC STATUS, Z
    GOTO CORRECT_WAIT
    CALL LCD_CHAR
    INCF COUNT, F
    GOTO MESSAGE2
    CORRECT_WAIT CALL LONGDELAY
    CALL LONGDELAY

    GOTO INIT
    MAIN MOVLW D'1'
    CALL LCD_LINE2W ;MOVE TO 2ND ROW, 2ND COLUMN
    CALL LCD_CURON
    CALL CHK_KEYS ;WAIT FOR KEY
    MOVWF KEY1 ;STORE FIRST DIGIT
    CALL LCD_CHAR
    CALL CHK_KEYS ;WAIT FOR KEY
    MOVWF KEY2 ;STORE SECOND DIGIT
    CALL LCD_CHAR
    CALL CHK_KEYS ;WAIT FOR KEY
    MOVWF KEY3 ;STORE THIRD DIGIT
    CALL LCD_CHAR
    CALL CHK_KEYS ;WAIT FOR KEY
    MOVWF KEY4 ;STORE FOURTH DIGIT
    CALL LCD_CHAR
    CALL LCD_CUROFF
    CHK_CODE MOVF NUM1, W ;TEST FIRST DIGIT
    SUBWF KEY1, W
    BTFSS STATUS, Z
    GOTO WRONG
    MOVF NUM2, W ;TEST SECOND DIGIT
    SUBWF KEY2, W
    BTFSS STATUS, Z
    GOTO WRONG
    MOVF NUM3, W ;TEST THIRD DIGIT
    SUBWF KEY3, W
    BTFSS STATUS, Z
    GOTO WRONG
    MOVF NUM4, W ;TEST FOURTH DIGIT
    SUBWF KEY4, W
    BTFSS STATUS, Z
    GOTO WRONG
    GOTO CORRECT
    ;******************************************************************************
    ; KEYPAD ROUTINE *
    ;******************************************************************************
    CHK_KEYS MOVLW 0X00 ;WAIT UNTIL NO KEY PRESSED
    MOVWF KEY_PORT ;SET ALL OUTPUT PINS LOW
    MOVF KEY_PORT, W
    ANDLW 0X0F ;MASK OFF HIGH BYTE
    SUBLW 0X0F
    BTFSC STATUS, Z ;TEST IF ANY KEY PRESSED
    GOTO KEYS ;IF NONE, READ KEYS
    CALL SHORTDELAY
    GOTO CHK_KEYS ;ELSE TRY AGAIN
    KEYS CALL SCAN_KEYS
    MOVLW 0X10 ;CHECK FOR NO KEY PRESSED
    SUBWF KEY, W
    BTFSS STATUS, Z
    GOTO KEY_FOUND
    CALL SHORTDELAY
    GOTO KEYS
    KEY_FOUND MOVF KEY, W
    ANDLW 0X0F
    CALL KEY_TABLE ;LOOKUP KEY IN TABLE
    MOVWF KEY ;SAVE BACK IN KEY
    RETURN ;KEY PRESSED NOW IN W
    SCAN_KEYS CLRF KEY
    MOVLW 0XFF ;SET ALL OUTPUT LINES HIGH
    MOVWF KEY_PORT
    MOVLW 0X0F
    MOVWF ROWS ;SET NUMBER OF ROWS
    BCF STATUS, C ;PUT A 0 INTO CARRY
    SCAN RRF KEY_PORT, F
    BSF STATUS, C ;FOLLOW THE ZERO WITH ONES
    ;COMMENT OUT NEXT TWO L INES FOR 4X3 NUMERIC KEYPAD.
    BTFSS KEY_PORT, COL4
    GOTO PRESS
    INCF KEY, F
    BTFSS KEY_PORT, COL3
    GOTO PRESS
    INCF KEY, F
    BTFSS KEY_PORT, COL2
    GOTO PRESS
    INCF KEY, F
    BTFSS KEY_PORT, COL1
    GOTO PRESS
    INCF KEY, F
    DECFSZ ROWS, F
    GOTO SCAN
    PRESS RETURN
    ;END OF KEYPAD SUBROUTINES.
    ;********************************************************************************
    ;LCD ROUTINES AND INITITIALIZE LCD
    ;********************************************************************************
    LCD_INIT CALL LCD_BUSY ;WAIT FOR LCD TO SETTLE
    MOVLW 0X20 ;SET 4 BIT MODE
    CALL LCD_CMD
    MOVLW 0X28 ;SET DISPLAY SHIFT
    CALL LCD_CMD
    MOVLW 0X06 ;SET DISPLAY CHARACTER MODE
    CALL LCD_CMD
    MOVLW 0X0C ;SET DISPLAY ON/OFF AND CURSOR COMMAND
    CALL LCD_CMD ;SET CURSOR OFF
    CALL LCD_CLR ;CLEAR DISPLAY
    RETLW 0X00
    ;*********************************************************************************
    ; COMMAND SET ROUTINE
    ;*********************************************************************************
    LCD_CMD MOVWF TEMPLCD
    SWAPF TEMPLCD, W ;SEND UPPER NIBBLE
    ANDLW 0X0F ;CLEAR UPPER 4 BITS OF W
    MOVWF LCD_PORT
    BCF LCD_PORT, LCD_RS ;RS LINE TO 1
    CALL PULSE_E ;PULSE THE E LINE HIGH
    MOVF TEMPLCD, W ;SEND LOWER NIBBLE
    ANDLW 0X0F ;CLEAR UPPER 4 BITS OF W
    MOVWF LCD_PORT
    BCF LCD_PORT, LCD_RS ;RS LINE TO 1
    CALL PULSE_E ;PULSE THE E LINE HIGH
    CALL LCD_BUSY
    RETLW 0X00
    LCD_CHARD ADDLW 0X30 ;ADD 0X30 TO CONVERT TO ASCII
    LCD_CHAR MOVWF TEMPLCD
    SWAPF TEMPLCD, W ;SEND UPPER NIBBLE
    ANDLW 0X0F ;CLEAR UPPER 4 BITS OF W
    MOVWF LCD_PORT
    BSF LCD_PORT, LCD_RS ;RS LINE TO 1
    CALL PULSE_E ;PULSE THE E LINE HIGH
    MOVF TEMPLCD, W ;SEND LOWER NIBBLE
    ANDLW 0X0F ;CLEAR UPPER 4 BITS OF W
    MOVWF LCD_PORT
    BSF LCD_PORT, LCD_RS ;RS LINE TO 1
    CALL PULSE_E ;PULSE THE E LINE HIGH
    CALL LCD_BUSY
    RETLW 0X00
    LCD_LINE1 MOVLW 0X80 ;MOVE TO 1ST ROW, FIRST COLUMN
    CALL LCD_CMD
    RETLW 0X00
    LCD_LINE2 MOVLW 0XC0 ;MOVE TO 2ND ROW, FIRST COLUMN
    CALL LCD_CMD
    RETLW 0X00
    LCD_LINE1W ADDLW 0X80 ;MOVE TO 1ST ROW, COLUMN W
    CALL LCD_CMD
    RETLW 0X00
    LCD_LINE2W ADDLW 0XC0 ;MOVE TO 2ND ROW, COLUMN W
    CALL LCD_CMD
    RETLW 0X00
    LCD_CURON MOVLW 0X0D ;SET DISPLAY ON/OFF AND CURSOR COMMAND
    CALL LCD_CMD
    RETLW 0X00
    LCD_CUROFF MOVLW 0X0C ;SET DISPLAY ON/OFF AND CURSOR COMMAND
    CALL LCD_CMD
    RETLW 0X00
    LCD_CLR MOVLW 0X01 ;CLEAR DISPLAY
    CALL LCD_CMD
    RETLW 0X01
    LCD_HEX MOVWF TMP1
    SWAPF TMP1, W
    ANDLW 0X0F
    CALL HEX_TABLE
    CALL LCD_CHAR
    MOVF TMP1, W
    ANDLW 0X0F
    CALL HEX_TABLE
    CALL LCD_CHAR
    RETLW 0X01
    LONGDELAY MOVLW 0XFF
    GOTO D0
    MLONGDELAY MOVLW D'100'
    GOTO D0
    MASTERDELAY MOVLW D'50'
    GOTO D0
    SHORTDELAY MOVLW D'20'
    GOTO D0
    SHORTERDELAY MOVLW 0X05 ;DELAY 5.000 MS (4 MHZ CLOCK)
    D0 MOVWF COUNT1
    D1 MOVLW 0XC7 ;DELAY 1MS
    MOVWF COUNTA
    MOVLW 0X01
    MOVWF COUNTB
    DELAY_0 DECFSZ COUNTA, F
    GOTO $+2
    DECFSZ COUNTB, F
    GOTO DELAY_0
    DECFSZ COUNT1 ,F
    GOTO DELAY_0
    RETLW 0X00
    PULSE_E BSF LCD_PORT, LCD_E
    NOP
    BCF LCD_PORT, LCD_E
    RETLW 0X00
    LCD_BUSY
    BSF STATUS, RP0 ;SET BANK 1
    MOVLW 0X0F ;SET PORT FOR INPUT
    MOVWF LCD_TRIS
    BCF STATUS,RP0 ;SET BANK 0
    BCF LCD_PORT, LCD_RS ;SET LCD FOR COMMAND MODE
    BSF LCD_PORT, LCD_RW ;SETUP TO READ BUSY FLAG
    BSF LCD_PORT, LCD_E
    SWAPF LCD_PORT, W ;READ UPPER NIBBLE (BUSY FLAG)
    BCF LCD_PORT, LCD_E
    MOVWF TEMPLCD2
    BSF LCD_PORT, LCD_E ;DUMMY READ OF LOWER NIBBLE
    BCF LCD_PORT, LCD_E
    BTFSC TEMPLCD2, 7 ;CHECK BUSY FLAG, HIGH = BUSY
    GOTO LCD_BUSY ;IF BUSY CHECK AGAIN
    BCF LCD_PORT, LCD_RW
    BSF STATUS, RP0 ;SET BANK 1
    MOVLW 0X00 ;SET PORT FOR OUTPUT
    MOVWF LCD_TRIS
    BCF STATUS, RP0 ;SET BANK 0
    RETURN
    ;*****************************************************************************
    ;END OF LCD ROUTINES *
    ;*****************************************************************************
    END
    ;END OF THE PROGRAM
    :mad::mad::mad::mad:
     
  4. -SK-

    Member

    Apr 14, 2009
    25
    0
    Why is everything in caps?
    When you say it can only display 'Enter Code', and not the numbers pressed....what does it display? Is it stuck displaying 'Enter Code' or does it display gibberish, or turn off, or show the wrong number...?
    What is Nigel's tutorial?
    If you can write 'Enter Code' to the LCD, probably your LCD routine works. Try commenting out most of the program, and just get it to display whatever key is pressed on the LCD. If it won't display, probably your key scanning code is not correct. If that is the case, try only scanning one row or column, or even one key, and displaying its value when pressed. Once you can get something displaying, and definitely reading one key, you can expand to reading the whole pad and displaying whatever you want.
     
Loading...