i have
PortB(pins RB0 through RB7)of the pic16 defined as an input with a dip switch connected to it
PortD(pins RD0 through RD7)as output each connected to a LED,also each pin of PORT B corresponds to one from PORT D
how can i configure that this port is the input and output in the first place and it's supposed to be configured in the pic code? or in the c# application? i think it 's supposed to be in the pic program. but i'm just wondering
when reading from the microcontroller i want to read the status of the 8 output LEDS once or i can collect them, how is that possible?
and i want to be able to control the status of these leds using my c# program but i have an issue on how to receive their status and set it later .
i tried reading but it was on port A not on the output(port d)
i'm using proteus to stimulate the circuit and a comport virtual emulator and to write the code of the pic mikroc (i'm new to it most of the codes i got from the internet and i kinda understood)
i just want to know how to read the status of port D like (101011) pr something like that and how to set each pin of portD if that's possible
i'm still new to all of this i'm just trying my best ,
excuse my lack of knowledge ,afterall i'm still learning .
please, and Thanks !:)
my c# functions code to read and write
SerialPort port ;
void Pread()
{
port = new SerialPort("COM2", 9600, Parity.None, 8, StopBits.One);
port.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);
port.Open();
}
private void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
{
SerialPort port= (SerialPort)sender;
string w = port.ReadByte().ToString();
if (w != String.Empty)
{
Invoke(new Action(() => richTextBox1.AppendText(w)));
}
}
void Pwrite(string num)
{
port.WriteTimeout = 500;
port.Open();
port.WriteLine(num.ToString());
port.Close();
}
private void button1_Click(object sender, EventArgs e)
{
Pread();
}