AVR 마이크로컴퓨터로 다양한 조작 ②-3 직렬 통신 3
6938 단어 ATmega328PAVR직렬 통신
이로써 마이크로컴퓨터의 데이터 수신과 발송을 확인한다.
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 변환을 진행하시겠습니까?
Reference
이 문제에 관하여(AVR 마이크로컴퓨터로 다양한 조작 ②-3 직렬 통신 3), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/smnhooi/items/e5179a6b722441bde0fb텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)