+ Reply to Thread
Results 1 to 3 of 3
  1. #1

    Default RFID SHIFTIN/SHIFTOUT working MFRC-522

    I as many had been searching for shiftin/shiftout examples to work with Pic basic pro/Micro code studio. I struggled to understand libraries and code which was a bit over my head. I beat my head against it till I got a simplified version to work. I don't claim this is great code work but I think it may help people who were in the same boat I was follow what what going on.

    I think I am stating this correctly, I am writing in Micro Code Studio, assembling with MPASM and programed through MPLAB. In general, I am not writing this with embedded functions and pointers so I can get an idea of the big picture. Instead of doing the shift left and adding or clearing the FSB I simply use the result from that (in general).

    This first example to run the self test and dispay the number to the LCD. I am using an 18F25k20:


    Include "modedefs.bas" 'Deffinitions for serial

    b var byte
    x var word
    y var word
    z var word
    NSS var PORTA.5
    TRISA.5 = 0 'NSS
    income var word(66)

    RST var PORTC.1
    TRISC.1 = 0
    high RST
    pause 100

    'Bit shifting and masking already done, for instance:
    'CommandRegister = 0x01 = 0000 0001
    'Shift left = 0x02 = 0000 0010 Write
    'Mask $80 = 0x82 = 1000 0010 Read

    '============Self Test=============================
    'SoftReset:
    low NSS
    pause 5
    shiftout PORTC.5, PORTC.3, MSBFIRST, [$02,$0F]
    pause 1
    high NSS
    Pause 500

    'Flush FIFO:
    low NSS
    pause 1
    shiftout PORTC.5, PORTC.3, MSBFIRST, [$14,$80]
    pause 1
    high NSS
    Pause 1

    for x = 1 to 25
    low NSS
    pause 1
    shiftout PORTC.5, PORTC.3, MSBFIRST, [$12,$0]'FIFO Data Reg
    pause 1
    high NSS
    pause 1
    next x

    'Transfer 25 bytes to internal buffer
    low NSS
    pause 5
    shiftout PORTC.5, PORTC.3, MSBFIRST, [$02,$01]
    pause 10
    high NSS
    Pause 20

    'Flush FIFO:
    low NSS
    pause 1
    shiftout PORTC.5, PORTC.3, MSBFIRST, [$14,$80]
    pause 1
    high NSS
    Pause 1

    'Enable Self Test:
    low NSS
    pause 1
    shiftout PORTC.5, PORTC.3, MSBFIRST, [$6C,$09]
    pause 1
    high NSS
    pause 1

    '"00h" to FIFO buffer:
    low NSS
    pause 1
    shiftout PORTC.5, PORTC.3, MSBFIRST, [$12,$00]
    pause 1
    high NSS
    pause 1

    'Calc command
    low NSS
    pause 1
    shiftout PORTC.5, PORTC.3, MSBFIRST, [$02,$03] 'Calc
    pause 1
    high NSS
    Pause 2000

    gosub idle

    for x = 1 to 64
    low NSS
    pause 1
    shiftout PORTC.5, PORTC.3, MSBFIRST, [$12, x]
    pause 1
    high NSS
    Pause 10
    next x

    '-------------------------------------------------------

    'Write Bitframe Register
    low NSS
    pause 1
    shiftout PORTC.5, PORTC.3, MSBFIRST, [$1A,$87]
    pause 1
    high NSS
    Pause 1

    'Write Bitframe Register
    low NSS
    pause 1
    shiftout PORTC.5, PORTC.3, MSBFIRST, [$1A,$07]
    pause 1
    high NSS
    Pause 1

    for x = 1 to 64
    low NSS
    pause 1
    shiftout PORTC.5, PORTC.3, MSBFIRST, [$92] '"0x92"] 'Read FIFOData
    pause 1
    Shiftin PORTC.4, PORTC.3, LSBFIRST, [income(x)]
    pause 1
    high NSS
    next x

    Serout2 PORTB.0, 84, [12]
    pause 10

    y = 1
    for x = 1 to 64
    Serout2 PORTB.0, 84, [hex income(x)," "]
    pause 10
    if Y = 4 then
    Serout2 PORTB.0, 84, [13]
    y = 0
    endif
    y = y + 1
    pause 3000
    next x


    mainloop:
    goto Mainloop



    idle: 'Write Comand MFRC522_IDLE
    Pause 10
    low NSS
    pause 1
    shiftout PORTC.5, PORTC.3, MSBFIRST, [$02,$00]
    pause 1
    high NSS
    Pause 1
    return

  2. #2
    Join Date
    Nov 2019
    Posts
    7

    Default Re: RFID SHIFTIN/SHIFTOUT working MFRC-522

    Hello dear Bunner.
    I'm working this module. But, I don't work. pin connects and codes is attached. I would appreciate if you help.

    Codes
    '************************************************* ***************
    '* Name : UNTITLED.BAS *
    '* Author : [select VIEW...EDITOR OPTIONS] *
    '* Notice : Copyright (c) 2019 [select VIEW...EDITOR OPTIONS] *
    '* : All Rights Reserved *
    '* Date : 04.10.2019 *
    '* Version : 1.0 *
    '* Notes : *
    '* : *
    '************************************************* ***************

    @ DEVICE pic16F628a
    @ DEVICE pic16F628a, WDT_ON
    @ DEVICE pic16F628a, PWRT_ON
    @ DEVICE pic16F628a, BOD_ON
    @ DEVICE pic16F628a, PROTECT_OFF
    @ DEVICE pic16F628a, LVP_OFF
    @ DEVICE pic16F628a, CPD_OFF
    @ DEVICE pic16F628a, MCLR_OFF
    @ DEVICE pic16F628a, INTRC_OSC_NOCLKOUT
    TRISA=%01000000 'A portu 6. pin giriş diğerleri Áıkış olarak ayarlandı.
    TRISB=0 'B portu Áıkış olarak ayarlandı.

    'mfrc 522 tanımlamaları
    miso var porta.6 'master in slave out
    mosi var porta.7 'master out slave in
    sck var porta.0 'sck pini
    nss var porta.1 'sda pini
    x var byte

    PORTA=0
    PORTB=0

    CMCON=7 'komparatŲrler iptal.
    OPTION_REG=7 'pull up direncleri pasif
    'lcd tanımlamaları
    DEFINE LCD_DREG PORTB 'lcd data pinleri portb ye bağlı
    DEFINE LCD_DBIT 0 'lcd data pinleri 0. pinden başlıyor.
    DEFINE LCD_EREG PORTB 'enable pini portb de
    DEFINE LCD_EBIT 4 'enable portb 4. pine bağlı
    DEFINE LCD_RSREG PORTB ' rs pini portb de
    DEFINE LCD_RSBIT 5 ' rs portb 5. pine bağlı
    DEFINE LCD_BITS 4 'data 4 pini bağlı
    DEFINE LCD_LINES 2 'lcd 2 satır
    pause 200

    'veri tanımlaması
    veri var byte(10)
    reg var byte



    nss=0
    reg=$02
    reg=reg<<1
    reg= reg & $7E

    pause 1
    shiftout mosi, sck, 1,[reg,$0F] 'soft reset
    pause 5
    nss=1
    pause 500

    basla:
    for x=1 to 10
    reg=x
    reg=(reg<<1)
    reg=reg & $7E
    reg=reg | $80

    nss=0
    shiftout mosi, sck, 1,[reg]
    shiftin miso,sck,1,[veri(0)]
    nss=1

    lcdout $fe,1,"adres :",HEX reg
    lcdout $fe,$c0,"veri :",bin8 veri(0)

    pause 2000
    next x

    'goto basla

    end

  3. #3
    Join Date
    Nov 2019
    Posts
    7

    Default Re: RFID SHIFTIN/SHIFTOUT working MFRC-522

    Hello Burner1.
    I did the test by doing what you say.
    Now I try to read the Id card.
    Which registers should I change?

Similar Threads

  1. SHIFTIN SHIFTOUT timing problem
    By BrianT in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 11th April 2011, 21:08
  2. Shiftout - shiftin question
    By Lasse1 in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 5th April 2010, 16:34
  3. 16f877A and shiftin shiftout
    By ghdsfier8 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 22nd February 2008, 14:47
  4. shiftout and shiftin
    By Ron Marcus in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 24th April 2006, 15:01
  5. Shiftin/Shiftout
    By paul.mcallister in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 11th May 2005, 04:24

Members who have read this thread : 12

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts