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 / How to interface RFID with PIC18F4550 Microcontroller

How to interface RFID with PIC18F4550 Microcontroller

|

Microcontroller › PIC › How to interface RFID with PIC18F4550 Microcontroller

  • This topic has 5 replies, 2 voices, and was last updated 8 years, 3 months ago by GANEEV SINGH.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • February 11, 2017 at 5:30 pm #4610
    barish
    Participant

    // Program to interface RFID module using EUSART in PIC18F4550

    // Configuration bits
    /* _CPUDIV_OSC1_PLL2_1L, // Divide clock by 2
    _FOSC_HS_1H, // Select High Speed (HS) oscillator
    _WDT_OFF_2H, // Watchdog Timer off
    MCLRE_ON_3H // Master Clear on
    */

    #define FREQ 12000000
    #define baud 9600
    #define spbrg_value (((FREQ/64)/baud)-1)
    #define rs LATA.F0
    #define rw LATA.F1
    #define en LATA.F2
    #define lcdport LATB

    unsigned char rx_data();
    void lcd_ini();
    void lcdcmd(unsigned char);
    void lcddata(unsigned char);
    unsigned char data[]="Unique ID No.";
    unsigned char card_id[12];
    unsigned int i=0,pos;

    void main()
    {
    TRISB=0; // Set Port B as output port
    LATB=0;
    TRISA=0;
    LATA=0;
    SPBRG=spbrg_value; // Fill SPBRG register to set the baud rate
    RCSTA.SPEN=1; // To activate serial port (Tx and Rx pins)
    RCSTA.CREN=1; // To enable continuous reception
    PIE1.RCIE=1; // To enable the Reception (Rx) Interrupt
    INTCON.GIE=1;
    INTCON.PEIE=1;
    lcd_ini(); // LCD initialization
    while(data!='')
    {
    lcddata(data
    ); // To send characters one by one from 'data' array
    i++;
    }
    while(1)
    {
    i=0;
    while(i<12);
    lcdcmd(0xC0);
    i=0;
    while(i<12)
    {
    lcddata(card_id
    ); // Print the 12 byte received data
    i++;
    }
    }
    }


    void interrupt()
    {
    card_id
    =RCREG; // Store the received data byte by byte
    i++;
    }

    void lcd_ini()
    {
    lcdcmd(0x38); // Configure the LCD in 8-bit mode, 2 line and 5x7 font
    lcdcmd(0x0C); // Display On and Cursor Off
    lcdcmd(0x01); // Clear display screen
    lcdcmd(0x06); // Increment cursor
    lcdcmd(0x80); // Set cursor position to 1st line, 1st column
    }

    void lcdcmd(unsigned char cmdout)
    {
    lcdport=cmdout; //Send command to lcdport=PORTB
    rs=0;
    rw=0;
    en=1;
    Delay_ms(10);
    en=0;
    }

    void lcddata(unsigned char dataout)
    {
    lcdport=dataout; //Send data to lcdport=PORTB
    rs=1;
    rw=0;
    en=1;
    Delay_ms(10);
    en=0;
    }

     

     

    In this code how "void interrupt()" function will get executed.  

     

    February 12, 2017 at 4:47 pm #14432
    GANEEV SINGH
    Participant

    Hi there

    PICs can handle atmost one interrupt (if priority is not set) at a time. Thus writing interrupt in front of any function makes it an ISR (interrupt service routine). As in this case, PIE1.RCIE=1; statement is written to enable the USART Rx interrupt; so any interrupt request by Rx's flag will make PIC start executing the void interrupt();

    Also this same interrupt function can be used to see if any other interrupt request has been made or not. Refer its datasheet for the same.

    Hope this clears your doubt :)

    February 12, 2017 at 5:10 pm #14433
    barish
    Participant

    Can we require a assembly function to redirect from 0x0008 or 0x0018 isr location to our c function?

    Or simply given code will work?

    February 13, 2017 at 5:32 am #14435
    GANEEV SINGH
    Participant

    When writing code in C, PIC only calls one ISR function for all of its interrupts i.e. function with name interrupt(); (here). It is then on the coders side to write such a code that could decide which interrupt to focus on and execute its function(s).

    I do not think we can change ISR's address as it is predefined inside the chip. 

    February 13, 2017 at 9:14 am #14438
    barish
    Participant

    thank you

    if 2 or more interrupts are neede to define then how to regognize them i.e. which interrupt is currently active or triggered.

     

    February 15, 2017 at 6:46 am #14442
    GANEEV SINGH
    Participant

    You will need to check their respective flag bits and then accordingly perform any action.

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

RSS Recent Posts

  • Chinese Tarrifs – 104%!?! May 21, 2025
  • An Update On Tarrifs May 21, 2025
  • Tariff Updates from JLCPCB as of Today May 21, 2025
  • Solar lighting motion detector May 21, 2025
  • Telegram Based Alarm - Sensor cable protection May 20, 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