English 中文(简体)
C# Serial Port + CCS C Serial Port + PIC 16F877A
原标题:C# Serial Port + CCS C Serial Port + PIC 16F877A

我有一个16F887A号事先知情同意协定,与序列港口连接。 我想,当它收到0x01和红.时,它会打绿灯。 我发送了C#窗口申请表的特性,事先知情同意本身与CSC方案一起规划。 你们能否告诉我,如果以下的法典不奏效,那一米错了吗?

Edit:通过t 工作,就意味着在这两种情况下推导红色。

C# 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;
using System.IO.Ports;

namespace deneme
{
    public partial class Form1 : Form
    {
        SerialPort port = new SerialPort("COM2", 9600, Parity.None, 8, StopBits.One);
        public Form1()
        {
            InitializeComponent();
        }

        private void openportbtn_Click(object sender, EventArgs e)
        {
            if (port.IsOpen)
            {
                port.Close();
            }

            if (!port.IsOpen)
            {
                port.Open();
            }
        }

        private void rightbtn_Click(object sender, EventArgs e)
        {
            byte[] right = new byte[1];
            right[0] = 0x01;
            port.Write(right, 0, right.Length);
        }

        private void wrongbtn_Click(object sender, EventArgs e)
        {
            byte[] wrong = new byte[1];
            wrong[0] = 0x00;
            port.Write(wrong, 0, wrong.Length);
        }
    }
}

CCS C 法典

#include <16f877A.h>

#fuses XT,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOPUT,NOWRT,NODEBUG,NOCPD

#use delay (clock=4000000)

#use rs232 (baud=9600, xmit=pin_c6, rcv=pin_c7, parity=N, stop=1, bits=8)

char received;
char right = 0x01;

#int_rda
void serial_interrupt()
{
   disable_interrupts(int_rda);
   received = getc();
   if(received == right)
   {
      output_high(pin_c5); //green led
      delay_ms(200);
      output_low(pin_c5);
   }
   else
   {
      output_high(pin_c4); //red led
      delay_ms(200);
      output_low(pin_c4);
   }
}

void main()
{
   setup_psp(PSP_DISABLED);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_CCP1(CCP_OFF);
   setup_CCP2(CCP_OFF);

   output_low(pin_c4);
   output_low(pin_c5);

   enable_interrupts(GLOBAL);
   while(1)
   {
      enable_interrupts(int_rda);
   }
}
问题回答

如果在这两种情况下都收到0x00美元,那么,你可能出现不满意率,甚至略微。 在发现起点之后,事先知情同意可能会看到头7点零点,并且认为这两起案件中共发生8起。 我将努力从事先知情同意和PC中转来,并在范围上看线,以确保它们保持同样的速度。 你们还可以努力不断传送0xA,以掌握眼光模式(10101010年),并比较这两个信号。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签