Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] PIC16F8870 & RS232 RFID READER & Mikro C

Status
Not open for further replies.

Linspire

Full Member level 5
Joined
Sep 1, 2011
Messages
303
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,298
Location
M'sia
Activity points
3,279
Hi guys,
Due to last friday, I have burnt out the PIC18F4520 and I cant proceed further for mine SD Card project.
However, I have my friend sharing his PIC16F8870.
Therefore, I would like to implement communication between RS232 and PIC16F8870.

This is the link for my RS-232 RFID Reader..RFID-IDR-232N - RFID Reader RS232 (New)

So there are few questions shown below, hopefully you guys can help me answer them:
1) Any good references for me to learn (prefer step by step) ?
2) Any good example software simulation example such as ISIS 7 testing this kind of circuits ?

Regards
Linspire
 

Since the device has a RS-232 interface, it is fairly straight forward. You need another MAX232 RS-232 transceiver for the PIC side of the circuit.

IC MAX232

As well as a set of appropriate capacitors required by the MAX232. You may want to see if they have a RS-232 breakout board with a DB9, this would simply adding a RS-232 interface to future projects.

Also take a look at my RFID Technologies Group for sample code and example applications.

RFID Technologies Group

Here's a nice tutorial which covers implementing an RS-232 port on a PIC18F, the differences are minor with the PIC16F:

RS232 Communication using PIC18F4520′s USART – PIC Microcontroller Tutorial

The info should get you started in the right direction. If you encounter any problems just post them here.

BigDog
 
Last edited by a moderator:
Since the device has a RS-232 interface, it is fairly straight forward. You need another MAX232 RS-232 transceiver for the PIC side of the circuit.

IC MAX232

As well as a set of appropriate capacitors required by the MAX232. You may want to see if they have a RS-232 breakout board with a DB9, this would simply adding a RS-232 interface to future projects.

Also take a look at my RFID Technologies Group for sample code and example applications.

RFID Technologies Group

Here's a nice tutorial which covers implementing an RS-232 port on a PIC18F, the differences are minor with the PIC16F:

RS232 Communication using PIC18F4520′s USART – PIC Microcontroller Tutorial

The info should get you started in the right direction. If you encounter any problems just post them here.



BigDog

These're good resources.
Well, any necessary library should I use for MikroC so that I can compile / testing with simulation software ISIS 7.
 
Last edited by a moderator:

Explain the general purpose of your project.

I realize the RFID reader will be connected to the PICs UART. What will become of the RFID value once it is received by the PIC, displayed on LCD, etc?

You will obviously use MikroC's UART library, what other libraries will be utilized depends on your projects other tasks.

BigDog
 
  • Like
Reactions: FvM

    FvM

    Points: 2
    Helpful Answer Positive Rating
I'm going to do simple testing like using RFID passive card near to RFID reader , pass the data to the PIC16F8870, then display the output from LCD display.
 

Here is a MikroC UART to LCD Project which contains most of the elements necessary to complete your project:

A PIC Serial LCD project.

A couple of tutorials:

Lab 4: Interfacing a character LCD

Lab 8: Asynchronous serial communication


You should have examples of all the required libraries to utilize in your project.

BigDog

Thank you, BigDog.
Another question, do you think ISIS 7 have any devices that can be configured then sent some output such like RFID reader ?
I want this for testing to check whether my code is working properly or not.
 

Hi,
I want to ask simple question due long time didnt practice the programming C well.

How should I write if I want pass the function value to Lcd_Out(,,function) instead pointer.
Because I want to pass my UART read value and print it out in LCD display.

I have made simple programming for LCD display 16x2.
However in the simulation, it doest show correct result.

Here's the attachment codes:
Code:
int sum(int i, int j){

int totalsum;

    totalsum = i + j;
    return totalsum;
}

void main() {
   ANSEL  = 0;                        // Configure AN pins as digital I/O
   ANSELH = 0;
   C1ON_bit = 0;                      // Disable comparators
   C2ON_bit = 0;
   TRISB = 0;
   PORTB = 0xFF;
   Lcd_Init();
   Lcd_Out(1,1,sum(1,2));
}
 
Last edited:

Another question, do you think ISIS 7 have any devices that can be configured then sent some output such like RFID reader ?
I want this for testing to check whether my code is working properly or not.

As far as I know ISIS Proteus 7 does not have a RFID reader model. However, you could easily simulate a RFID reader with a RS-232 interface by using the virtual terminal and manually sending a RFID string to the PIC.

Hi,
How should I write if I want pass the function value to Lcd_Out(,,function) instead pointer.
Because I want to pass my UART read value and print it out in LCD display.

I have made simple programming for LCD display 16x2.
However in the simulation, it doest show correct result.

Here's the attachment codes:
Code:
int sum(int i, int j){

int totalsum;

    totalsum = i + j;
    return totalsum;
}

void main() {
   ANSEL  = 0;                        // Configure AN pins as digital I/O
   ANSELH = 0;
   C1ON_bit = 0;                      // Disable comparators
   C2ON_bit = 0;
   TRISB = 0;
   PORTB = 0xFF;
   Lcd_Init();
   Lcd_Out(1,1,sum(1,2));
}

There are two reasons the above code fails to yield expected results.

1. The "void Lcd_Out(char row, char column, char *text)" expects to be passed a valid pointer to a character string and you are passing an integer value, the return type of sum.

2. There is a significant difference between the integer 1 and the character '1', while "int sum(int i, int j)" returns an integer, "char UART1_Read()" return an ASCII character.

I would recommend using "void Lcd_Chr(char row, char column, char out_char)" which accepts a single character value and outputs it at the specified cursor location as does Lcd_Out().

Example:
Code:
void main() {
   ANSEL  = 0;                        // Configure AN pins as digital I/O
   ANSELH = 0;
   C1ON_bit = 0;                      // Disable comparators
   C2ON_bit = 0;
   TRISB = 0;
   PORTB = 0xFF;
   Lcd_Init();
   if (UART1_Data_Ready())              //<------ Check if a character has been received before reading
       Lcd_Out(1,1,UART1_Read());
   while(1);                                   //<------ Do not let the execution exit main()
}

Hope this example helps,

BigDog
 
As far as I know ISIS Proteus 7 does not have a RFID reader model. However, you could easily simulate a RFID reader with a RS-232 interface by using the virtual terminal and manually sending a RFID string to the PIC.



There are two reasons the above code fails to yield expected results.

1. The "void Lcd_Out(char row, char column, char *text)" expects to be passed a valid pointer to a character string and you are passing an integer value, the return type of sum.

2. There is a significant difference between the integer 1 and the character '1', while "int sum(int i, int j)" returns an integer, "char UART1_Read()" return an ASCII character.

I would recommend using "void Lcd_Chr(char row, char column, char out_char)" which accepts a single character value and outputs it at the specified cursor location as does Lcd_Out().

Example:
Code:
void main() {
   ANSEL  = 0;                        // Configure AN pins as digital I/O
   ANSELH = 0;
   C1ON_bit = 0;                      // Disable comparators
   C2ON_bit = 0;
   TRISB = 0;
   PORTB = 0xFF;
   Lcd_Init();
   if (UART1_Data_Ready())              //<------ Check if a character has been received before reading
       Lcd_Out(1,1,UART1_Read());
   while(1);                                   //<------ Do not let the execution exit main()
}

Hope this example helps,

BigDog

Thank you, Big Dog.
I have successfully compile it but show incorrect results in the LCD display.
The display result shows shifted character in the LCD screen.
Example:
Actual result shows " 123" instead of "123"

Take note: I used IntToStr().
 

Another question, how do I manually trigger the sending data from Virtual Terminal ?
 

I have successfully compile it but show incorrect results in the LCD display.
The display result shows shifted character in the LCD screen.

Example:
Actual result shows " 123" instead of "123"

Take note: I used IntToStr().

Reference MikroC Pro User Manual, pg 584, Section IntToStr:

Prototype void IntToStr(int input, char *output);

Description Converts input signed integer number to a string. The output string has fixed width
of 7 characters including null character at the end (string termination). The output
string is right justified and the remaining positions on the left (if any) are filled with
blanks.


Parameters:
- input: signed integer number to be converted
- output: destination string

Requires Destination string should be at least 7 characters in length.

Example int j = -4220;
char txt[7];
...
IntToStr(j, txt); // txt is " -4220" (one blank here)

For a quick fix I would recommend using the sprintl() function to convert an integer into a string.

Or if code size is an issue, write a short routine which coverts integers to string contained in a character buffer (array).

Concerning the Proteus' Virtual Terminal, each character will be transmitted as it is typed into the terminal. Be sure and configure all the appropriate settings by right clicking the Virtual Terminal and selecting "Edit Properties."

BigDog
 
  • Like
Reactions: FvM

    FvM

    Points: 2
    Helpful Answer Positive Rating
I have found useful links for solving simple UART connection which is mikroElektronika • View topic - Help in USART Terminal, MikroC and Proteus

But, I cant display any outputs of LCD 16x2 display ?
However, it does display in UART Terminal in receiving part (MikroC).
Here's my code :

Code:
// LCD define
// Lcd pinout settings
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D4 at RB0_bit;

// Pin direction
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D7_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB0_bit;

char *uart_rd;
char data;

void main() {
   ANSEL  = 0;                        // Configure AN pins as digital I/O
   ANSELH = 0;
   C1ON_bit = 0;                      // Disable comparators
   C2ON_bit = 0;
   TRISB = 0;
   PORTB = 0xFF;
   UART1_Init(9600);
   Delay_ms(100);
   Lcd_Init();
   Delay_ms(100);
   while(1) {
   if (UART1_Data_Ready()){              //<------ Check if a character has been received before reading
       uart_rd = UART1_Read();     // read the received data,
       UART1_Write(uart_rd);
       Lcd_Out(1,1,uart_rd);
       }
    }
}


I not yet successful yet display single character by changing into Lcd_Chr().
How to show full result sending from UART Terminal
example: every second sent "abcderf..."
result: 'a'/'b'/'c'/'d' random.
 
Last edited:

Hi,
So far I only managed to print first output from UART, for next input from RS232, my LCD 16x2 cant display exact result.
Here's the codes shown below:
Code:
unsigned char uart_rd;
unsigned char data;
unsigned char temp[10];
unsigned char N = 0;

// LCD define
// Lcd pinout settings
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D4 at RB0_bit;

// Pin direction
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D7_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB0_bit;



void main() {

   ANSEL  = 0;                        // Configure AN pins as digital I/O
   ANSELH = 0;
   C1ON_bit = 0;                      // Disable comparators
   C2ON_bit = 0;
   TRISB = 0;
   PORTB = 0xFF;
   UART1_Init(9600);
   Delay_ms(100);

   Lcd_Init();
   Lcd_Cmd(_LCD_BLINK_CURSOR_ON);
   Delay_ms(100);

   do {
   if (UART1_Data_Ready()){              //<------ Check if a character has been received before reading
       uart_rd = UART1_Read();     // read the received data,
       UART1_Write(uart_rd);

       temp[N] = uart_rd;
       N = N +1;

       if (N == 9) // temp storing  string
       {
          Lcd_Cmd(_LCD_CLEAR);

          Lcd_out(1,1,temp);

        }

       }
    } while(1);
}

I plan to sent each inputs which contained 9 characters/ a byte through UART.
This codes only works for first input, for 2nd input onwards, it does not working properly.

Hope you guys understand my problem.
 

Looks like you are not resetting the counter N once the buffer has been written to the LCD.

Try:

Code:
if (N == 9) // temp storing  string
       {
          Lcd_Cmd(_LCD_CLEAR);

          Lcd_out(1,1,temp);

          [COLOR="#FF0000"]N = 0;[/COLOR]

        }

BigDog
 
  • Like
Reactions: FvM

    FvM

    Points: 2
    Helpful Answer Positive Rating
Looks like you are not resetting the counter N once the buffer has been written to the LCD.

Try:

Code:
if (N == 9) // temp storing  string
       {
          Lcd_Cmd(_LCD_CLEAR);

          Lcd_out(1,1,temp);

          [COLOR="#FF0000"]N = 0;[/COLOR]

        }

BigDog

Lol., it's working, BigDog.
Thank you.
Why I didnt think about this thing.
 

Decades of experience.


BigDog

Alright.
Well, another question, I dont know what's purpose of MAX232, the 1uF capacitors needed to be connected with some pins.
If 10uF capacitors used ,will it be fine ?
I have checked the datasheet, it doesn't indicate the purpose of implement capacitors ?
I thought purpose maybe for stabilizing/regulate the voltage.
 

Well, another question, I dont know what's purpose of MAX232, the 1uF capacitors needed to be connected with some pins.

The signal levels of an RS-232 interface are quite different than the TTL levels of the PIC UART. The RS-232 levels can be in the +/- 25 volts range which is why you never want to connect a UART of any MCU directly to an RS-232 port. Doing so could easily damage the MCU or RS-232 port or both.

The MAX232 is an RS-232 transceiver with translates the signal levels of RS-232 to TTL and vice versa. The capacitors are used to implement a charge pump to generate these relatively high positive and negative voltages need for the RS-232 interface.

If 10uF capacitors used ,will it be fine ?

No. Always use the values specified in the MAX232 datasheet.

I have checked the datasheet, it doesn't indicate the purpose of implement capacitors ?
I thought purpose maybe for stabilizing/regulate the voltage.

As I explained above the capacitors purpose is to implement a charge pump.

Charge Pump

BigDog
 
  • Like
Reactions: FvM

    FvM

    Points: 2
    Helpful Answer Positive Rating
Alright, thank you for your verification.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top