AVR 마이크로컴퓨터로 다양한 조작 ②-3 직렬 통신 3

ATmega328P를 사용하면 Windows에서 받은 값이 증가하면 Windows로 돌아갑니다.
이로써 마이크로컴퓨터의 데이터 수신과 발송을 확인한다.
Windows 프로그램은 다음과 같습니다.
당분간 만지작거리지 않고 Visual Studio만 업데이트되었습니다.
왜 시스템이IO.Ports가 인식되지 않았습니다.
NuGet 포장 관리에서 찾았습니다.
이거 설치하고 안전하게 식별했어.
Program.cs
using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OnBoardTester
{
    class Program
    {
        static void Main(string[] args)
        {
            //受信Only
            SerialPort serialPort = new SerialPort("COM3", 500000, Parity.None, 8, StopBits.One);
            serialPort.Open();

            byte[] counter = { 0 };
            byte rcv;

            while (true)
            {
                serialPort.Write(counter, 0, 1);
                rcv = (byte)serialPort.ReadByte();

                System.Console.WriteLine(rcv.ToString("x2") + "\n");

                counter[0] = rcv;
            }
        }
    }
}
기대하는 동작은 통신치 1개당 1씩 증가하는 값으로 되돌아옵니다
그리고 그걸 마이크로컴퓨터에 입력하세요.
왕복할 때마다 하나씩 증가한다고 가정해 보세요.
마이크로컴퓨터 방면은 다음과 같다.
main.c
#include <avr/io.h>
#include <avr/interrupt.h>

void InitC(){
    DDRC = 0b00111111;
}
int main(void)
{

    /* Replace with your application code */

    //int mode =0;
    InitC();
    PORTC = 1;  //PORTCはデバッグ用
    UCSR0A = UCSR0A |0b00000010; //倍速設定
    UCSR0B = 0b10011000;
    UCSR0C = 0b00000110;
    UBRR0 = 4;
    PORTC = 2;

    sei();//割込み有効

    while(1)
    {

    }
}
ISR(USART_RX_vect){
    unsigned char data;
    data =UDR0;
    PORTC =data;
    while ( !(UCSR0A & (1<<5)) );
    UDR0 = data + 1;
}
수신 후 중단
PC 측에 증가 값을 즉시 전송합니다.
실행 결과는 다음과 같습니다.

다음은... 뭘 할지 까먹었지만
AD 변환을 진행하시겠습니까?

좋은 웹페이지 즐겨찾기