+ Reply to Thread
Page 2 of 2
First 1 2
Results 16 to 18 of 18

Thread: PIC is the "list" directive nessary?

  1. #16
    Mike, K8LH Excellent Mike, K8LH Excellent Mike, K8LH Excellent Mike, K8LH Excellent Mike, K8LH Excellent Mike, K8LH Excellent Mike, K8LH Excellent
    Join Date
    Jan 2005
    Location
    Michigan, USA
    Posts
    2,521

    Default

    Please update Nigel's 4x4 Keypad tutorial before you use it to avoid the one minor flaw of using 4 pins as outputs at the same time without four diodes in the matrix.

    If it helps by example, here's my simple alternative (below) which uses TRIS for only one active output. It uses a key state latch so you don't have to wait for a key to be released and it also features (1) switch press beep, and (2) repeat key capability. The Keypad pinout is also inline which matches most of the keypad connectors I've come across but the program only requires a minor change to scan Nigel's Keypad board with reversed RB0..RB3 polarity.

    Code:
    ;******************************************************************
    ;*                                                                *
    ;*  GetKey, a blocking type subroutine, waits for key press and   *
    ;*  returns a character in WREG from the keypad "map" table       *
    ;*                                                                *
            radix   dec
    GetKey
            DelayMS(16)             ; delay 16 msecs between scans    |B0
            call    ScanPad         ; scan the keypad                 |B0
            bz      GetKey          ; a new press? no, branch, else   |B0
    
            bsf     Beep,4          ; prep for 16 msec beep           |B0
    DoBeep  movf    PORTA,W         ; read port A                     |B0
            xorlw   1<<Spkr         ; toggle speaker bit              |B0
            movwf   PORTA           ; toggle speaker pin              |B0
            DelayCy(Clock/4*1000-6) ; delay 1000 us for 500 Hz tone   |B0
            decfsz  Beep,F          ; done?  yes, skip, else          |B0
            goto    DoBeep          ; loop (toggle Spkr pin again)    |B0
    
            movlw   high(Map-128)   ; table address hi -128           |B0
            movwf   PCLATH          ;                                 |B0
            movlw   low(Map-128)    ; table address lo -128           |B0
            addwf   Keylat,W        ; add key latch (80..8F)          |B0
            skpnc                   ; carry? no, skip, else           |B0
            incf    PCLATH,F        ; bump PCLATH                     |B0
            movwf   PCL             ; return with map table char      |B0
    Map     dt      '0','1','2','3' ; row 0 map                       |B0
            dt      '4','5','6','7' ; row 1 map                       |B0
            dt      '8','9','A','B' ; row 2 map                       |B0
            dt      'C','D','E','F' ; row 3 map                       |B0
    
    Code:
    ;******************************************************************
    ;*                                                                *
    ;*  ScanPad, 4x4 Keypad              Mike McLaren, K8LH, Nov '07  *
    ;*                                                                *
    ;*      RB3 RB2 RB1 RB0      <> requires PORTB weak pull-ups      *
    ;*  RB4 [0] [1] [2] [3]      <> returns Z=0 for a "new" key only  *
    ;*  RB5 [4] [5] [6] [7]      <> returns Z=1 when no keys pressed  *
    ;*  RB6 [8] [9] [A] [b]         or if same key is still pressed   *
    ;*  RB7 [C] [D] [E] [F]      <> isochronous (77 cycles per call)  *
    ;*                                                                *
    ;*  the Keylat key state latch contains pressed key value 80..8F  *
    ;*  or 0 (no key pressed).  clear Keylat after getting a new key  *
    ;*  from ScanPad for "repeat key" operation (see example).        *
    ;*                                                                *
    ;*  26 words, 77 instruction cycles (isochronous)                 *
    ;*                                                                *
    ScanPad
            movlw   TRISB           ; address of TRISB in bank 1      |B0
            movwf   FSR             ; setup indirect access           |B0
            movlw   b'11110111'     ; setup column 0 (RB3) as output  |B0
            movwf   INDF            ; pseudo "movwf TRISB"            |B0
            clrf    Column          ; set keypad column offset = 0    |B0
            movlw   0               ; clear W                         |B0
            setc                    ; must shift 1 bits into TRISB    |B0
    ScanCol
            clrf    PORTB           ; set column pin low and Z=1      |B0
            btfss   PORTB,4         ; row 0 press? no, skip, else     |B0
            iorlw   0x80            ; indicate key 0, 1, 2, or 3      |B0
            btfss   PORTB,5         ; row 1 press? no, skip, else     |B0
            iorlw   0x84            ; indicate key 4, 5, 6, or 7      |B0
            btfss   PORTB,6         ; row 2 press? no, skip, else     |B0
            iorlw   0x88            ; indicate key 8, 9, A, or B      |B0
            btfss   PORTB,7         ; row 3 press? no, skip, else     |B0
            iorlw   0x8C            ; indicate key C, D, E, or F      |B0
            skpz                    ; key press? no, skip, else       |B0
            iorwf   Column,W        ; W = 80,84,88,or 8C + Column     |B0
    NextCol
            incf    Column,F        ; increment column offset, 0..3   |B0
            rrf     INDF,F          ; setup TRISB for next column     |B0
            skpnc                   ; are we done? yes, skip, else    |B0
            goto    ScanCol         ; scan the next column            |B0
    ScanLat
            xorwf   Keylat,W        ; same as last key state latch?   |B0
            skpz                    ; yes, skip with Z=1, else        |B0
            xorwf   Keylat,F        ; update key state latch          |B0
            return                  ; Z=0 only for a "new" key press  |B0
    
    ;******************************************************************
    
    Code:
    ;
    ;  example "repeat key" operation
    ;
    SetClock
            call    GetKey          ; wait for key press
    ChkInc
            xorlw   '+'             ; the '+' key?
            bnz     ChkDec          ; no, branch, else
            call    IncFunc         ; do increment function
            DelayMS(d'500')         ; wait 500 msecs
            clrf    Keylat          ; clear latch (allow repeat)
            goto    SetClock        ; check keypad
    ChkDec
            xorlw   '-'^'+'         ; the '-' key?
            bnz     ChkNxt          ; no, branch, else
            call    DecFunc         ; do decrement function
            DelayMS(d'500')         ; wait 500 msecs
            clrf    Keylat          ; clear latch (allow repeat)
            goto    SetClock        ; check keypad
    ChkNxt
            xorlw   '>'^'-'         ; the '>' key?
            bnz     ChkSet          ; no, branch, else
            call    NxtGrp          ; advance to next digit group
            goto    SetClock        ; check keypad
    ChkSet
            xorlw   'S'^'>'         ; the 'S' (Set) key?
            bnz     SetClock        ; no, branch, else
    Update                          ; update Clock, exit Set mode
    
    Last edited by Mike, K8LH; 16th April 2008 at 03:29 AM.


  2. #17
    eng1 Excellent eng1 Excellent eng1 Excellent eng1 Excellent eng1 Excellent
    Join Date
    Apr 2006
    Location
    Italy
    Posts
    938

    Default

    Quote Originally Posted by Pommie
    If I have "list p=16F88" and then include <16F886.inc> I will not get an error.
    That's not the case I've described. Suppose that you're writing a program for the PIC16F88, but you've accidentally selected another processor when creating the project with the wizard or with the configuration dialog (Configuration->Select device...).
    If you use the LIST directive:
    Code:
        list p=16f88
        include "p16F88.inc"
    
    you'll get a warning:

    Warning[215] Processor superseded by command line. Verify processor symbol.



    If you don't use the LIST directive, the code will compile for the wrong PIC (or the correct PIC - if you've selected it voluntarily - with the wrong include file) and you won't get any warning AFAIK.
    Last edited by eng1; 14th December 2007 at 08:14 PM.

  3. #18
    Help us help you blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent
    Join Date
    Jan 2007
    Location
    Toronto, Canada
    Posts
    10,701
    Blog Entries
    5

    Default

    Well I'll use Nigels tutorials, update them for the 18F series PICs and get them running on the various kits I sell. Starting with the Junebug (lights , switches, A/D, PWM and EUSART), Unicorn (LCD, GLCD, matrix keypads I2C and maybe USB and or RS485) and the Dragonfly with a 18F2525 (seven segment display muxing, A/D, TMR1 OSC, simple keypad scanning and RS485)
    It's all going in the book.
    Bill
    Smart Kits build Smart People

    http://www.blueroomelectronics.com/

+ Reply to Thread
Page 2 of 2
First 1 2

Similar Threads

  1. Quik PIC Programming kit
    By Krumlink in forum General Electronics Chat
    Replies: 5
    Latest: 27th January 2008, 11:27 PM
  2. Am I USING PIC UART CORRECTLY??
    By cyprio7 in forum Micro Controllers
    Replies: 46
    Latest: 15th January 2008, 06:03 PM
  3. Capturing and reproducing audio with a PIC
    By Fred.Amoson in forum Micro Controllers
    Replies: 14
    Latest: 14th December 2007, 08:22 PM
  4. Problems switchin relay with PIC
    By Andy1845c in forum General Electronics Chat
    Replies: 5
    Latest: 17th November 2007, 06:14 PM
  5. High ADC sampling rate PIC, 18F needed?
    By bananasiong in forum Micro Controllers
    Replies: 24
    Latest: 28th October 2007, 12:13 PM

Tags for this Thread