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 p16f882 and serialport

Status
Not open for further replies.

EgrK

Junior Member level 2
Junior Member level 2
Joined
Jul 31, 2012
Messages
24
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Location
East part of world
Activity points
1,438
hellow
i want to send the string y23 followed by newline (CR then LF) this is done by file.asm then read that string by c# program (file2.cs )
those are my two program
Code:
loop	        movlw	0x79
		call	snd
		movlw	2
		call	snd
		movlw	3
		call	snd
                movlw	0x0D	;CR
		call	snd	;Send CR
		movlw	0x0A	;LF
		call	snd	;Send LF
		goto	loop
Code:
and this is the c# program
using System;
using System.Collections;//.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;
using System.Threading;

namespace graphic1
{
    public partial class Form1 : Form
    {   SerialPort sp = new SerialPort();
        int i,j;
        string str;
        public Form1()
        {   InitializeComponent();
            sp.PortName = "com1";
            sp.BaudRate =  115200;        // 9600;
            sp.DataBits = 8;
            sp.Parity = Parity.None;
            sp.StopBits = StopBits.One;
            sp.Handshake = Handshake.None;
            sp.ReadTimeout = 15000;
            sp.WriteTimeout = 15000;
            sp.DataReceived += serialPort_DataReceived;
            sp.Open();
        }
       //
        void serialPort_DataReceived(object s, SerialDataReceivedEventArgs e)
        {
            byte[] data = new byte[sp.BytesToRead];
            sp.Read(data, 0, data.Length);
            //MessageBox.Show(data.ToString());
            str=ByteArrayToString2(data);
            MessageBox.Show(str);
        }
}
}
i could see very long string in the messageBox and it becomes longer and longer
need your help
 
Last edited:

because u using 'goto loop' again and again.
 
  • Like
Reactions: EgrK

    EgrK

    Points: 2
    Helpful Answer Positive Rating
Code:
        void serialPort_DataReceived(object s, SerialDataReceivedEventArgs e)
        {
            //the program works when i wrote those line
            str=sp.ReadLine();
            MessageBox.show(str);
           //i did not removed the goto loop 
        }
 

hello,


you didn't send the string y23 !

y=0x79 ..ok
but 2 is 0x32
and 3 -> 0x33
and add a delay betwen each invoice
or your PC buffer will overload..
 

thanks for your help. i was interested to get any message from the Pic no matter what was the character is.
i should send .2 then .3 followed by CR and LF
it works thanks again
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top