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.

[PIC] Read RS232 using PIC16F877A

Status
Not open for further replies.

kirankumar.t2

Newbie level 3
Newbie level 3
Joined
Feb 13, 2014
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
24
Hi All,

I am new to this microcontroller world, I need support form you all.

I need to make a simple PIC program to ead RS232 data using PIC16F877A, the RS232 data formate is as shown below

Date time voltage currrent
22/10/2013 10:10am 18.05V 20.05A
22/10/2013 10:15am 18.05V 20.05A
22/10/2013 10:20am 18.05V 20.05A
......

RS232 data will be continuously available to PIC for Every 5s once,

if any one of the RS232 data either voltage or current dcross the limit ( 16 V- 19 V ) or ( 19A - 21 A) then Port B first pin should go high ( any port is ok ).

Many thanks in advance.

Regards
Ponnkatt
 

As the data you are sending is in string format use UART receive interrupt to receive data into a buffer (char array) of say 40 bytes. You then have to parse this string and extract voltage and current values to wo temp buffers of size say 8 bytes and then subtract 0x30 from each element if it is not decimal point. convert the elements in array to a float value. You can then compare these values with limit values.
 

simply use microC, there is a library function to do this job and also use MAX232 in hardware in between MCU and PC. Its simple.

Here is a sample code. Hope it will help you...
Code:
/*******************************************************************************
Program for PC Based Load Control
Program Written by_ Engr. Mithun K. Das
Email: [email]mithun060@gmail.com[/email] Cell: +8801722448270;
MCU: PIC16F73; X_Tal: 8MHz;
Date: 28/10/2013;
*******************************************************************************/

unsigned char uart_rd;     // read the received data,

void main() 
{
   //Initialize the USART
   UART1_Init(9600);
   //Write Some lines of TEXT
   UART1_Write_Text(" ");
   UART1_Write_Text(" PC Based LOAD Control");
   UART1_Write_Text(" ");

    Delay_ms(1000);
    TRISB = 0x00;//all out
    PORTB = 0x00;
    while (1)
    {
        if (UART1_Data_Ready())
        { // If data has been received
            uart_rd = UART1_Read();     // read the received data,
            if(uart_rd=='1') RB0_bit = ~RB0_bit;
            if(uart_rd=='2') RB1_bit = ~RB1_bit;
            if(uart_rd=='3') RB2_bit = ~RB2_bit;
            if(uart_rd=='4') RB3_bit = ~RB3_bit;
        }


        Delay_ms(100);
    }
}
 

If your data format is fixed then try attached hex file. I have compiled for PIC18F45K22, 4 MHz external clock. Proteus file attached. test.hex doesn't read UART. Run.hex reads UART. Test.hex extracts data from a fixed string for testing purpose. Use Run.hex in hardware and reply.

102155d1392374907-vi_test.png
 

Attachments

  • Proteus.rar
    54.4 KB · Views: 87
  • vi_test.png
    vi_test.png
    36.9 KB · Views: 133

many thanks for the support,

I am using PIC simulater IDE for simulation, in this simulator i don't have
PIC18F45K22, please let me know how to check with present simulator

Regards,
Ponnkatt
 
Last edited:

I can compile code for any other PIC18(L)F devices. Mention the PIC18(L)F available in PIC Simulator IDE and also Fosc and baudrate. I will compile and post hex file for testing. I tested code with PIC16F and it doesn't work as expected because I got "IRP_bit must be set manually in code" warning in mikroC Compiler. Use PIC18F device for testing in Simulator and also in hardware.


Edit: You have to use Proteus 7.10 or newer or PIC 18 Simulator IDE. Both support PIC18F46K22.
 
Last edited:

    V

    Points: 2
    Helpful Answer Positive Rating
Hi Milan,

Can you send me the PIC16F source code for the above program,

Regards
Ponnkatt
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top