Where the problem in here ?

Status
Not open for further replies.

xp95

New Member
This schema is used to control 16 device through serial port but it gives random results in reality however I have try it in simulation program and it work very well

**broken link removed**

Where the problem in here ?
 
Can you post your code?

What are the loads connected to the output of the 595? If they are LEDs, do you have series resistors?
 
Code:
char E=0x45;
char text[16];
char x,i;
void main()
{
trisb=0;
portb=0;
UART1_Init(9600);
i=0;
while(1){
      if(UART1_Data_Ready()){
      text[i]= UART1_Read();
      i++;
      if(i==16){
          i=0;
for(x=0;x<16;x++)
                 {
                 portb.f0=text[x];
                 portb.f1=0;portb.f1=1;
                 }

portb.f2=0;portb.f2=1;}
}
if(portb.f3==1)
    Uart1_Write(E);
}
}
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;

namespace The_control
{
    public partial class Form1 : Form
    {
        SerialPort port;
        public Form1()
        {
            
            InitializeComponent();
            string[] ports = SerialPort.GetPortNames();
            foreach (string port1 in ports)
            {
                coms.Items.Add(port1);
            }
            

        }
        public String convBoolToString(bool[] a)
        {
            string s = null;
            foreach (bool l in a)
            {
                if (l == true) { s = 1 + s; }
                else s = 0 + s;

            }
            return s;
        }
                    

        private void button2_Click(object sender, EventArgs e)
        {
            button1.Enabled = true;
            c.Enabled = true;
            button2.Enabled = false;
            port = new SerialPort(coms.Text, 9600, Parity.None, 8, StopBits.One);
            if (port.IsOpen) port.Close();
            try
            {
                //open serial port
                port.Open();
            }
            catch (System.Exception )
            {
                if (port.IsOpen) port.Close();
            }
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            
            int i;
            bool[] m = new bool[16];
            for (i = 0; i < c.Items.Count  ; i++)
            {
                m[i] = c.GetItemChecked(i);

            }
            //***************************************
     //  MessageBox.Show(convBoolToString(m));
            port.Write(convBoolToString(m));
            port.DataReceived += new SerialDataReceivedEventHandler(serialPort1_DataReceived);
        }



        private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {

            string m;
            m = port.ReadExisting();
            if (m == "E")
            {

                label1.Text = "     FIRE!!!    ";
                label1.BackColor = Color.Red;



            }

        }

yes, they are leds with 10k resistor
 
Last edited:
I dont see anything obvious in the code. I'd try hardcoding values into the text[] array. Then you'll know if the problem is in the serial comm. or the shift routine.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…