ÇнÀ¸ñÇ¥    1

ÇнÀÁÖÁ¦    1

¿¹½À³»¿ë    1

½Ç½À¹æ¹ý    1

°ú    Á¦    1

AVR°ú PC Åë½Å (Ãâ·ÂÁ¦¾î)

ÇнÀ¸ñÇ¥

PC¿¡¼­ ¿ø°Å¸® º¸µåÀÇ Ãâ·ÂÀ» Á¦¾îÇÑ´Ù.

ÇнÀÁÖÁ¦

RS232·Î ¹®ÀÚ ¡°0¡± (0x30)ÀÌ Àü¼ÛµÇ¸é C0 Æ÷Æ®·Î 1À» Ãâ·ÂÇÏ°í ±×¿ÜÀÇ ¹®ÀÚ°¡ Àü¼ÛµÇ¸é 0À» Ãâ·ÂÇÑ´Ù.

PC Install Program (°úÁ¦)

¿¹½À³»¿ë

RS232¿¡ ÀÇÇÑ ¹®ÀÚÀü¼Û

½Ç½À¹æ¹ý

¸ñ    Â÷

´ÙÀ½Àº AVR¼Ò½º ÇÁ·Î±×·¥ÀÌ´Ù. PC ÇÁ·Î±×·¥Àº 2ÁÖÂ÷ ÇÁ·Î±×·¥À» ±×´ë·Î »ç¿ëÇÏ¸é µÈ´Ù.

 

º¸±â1  AVR ÇÁ·Î±×·¥

 

 

#include <mega128.h>  

#include <delay.h>

#include <stdio.h>

 

char rxd;

 

// USART0 Receiver interrupt service routine

interrupt [USART0_RXC] void uart0_rx_isr(void)

{

   // Àü¼ÛÀü ¹®ÀÚ¸¦ ¹Þ´Â´Ù.

   rxd=getchar();

      

   // ¹®ÀÚ"0"ÀÌ Àü¼ÛµÇ¸é C0¿¡ 1À» Ãâ·Â ±×·¸Áö ¾ÊÀ¸¸é 0À» Ãâ·Â

   if(rxd==0x30)

      PORTC=0x01;

   else

      PORTC=0x00;  

 }

 

// Standard Input/Output functions

#include <stdio.h>

 

void main(void)

{

// Port C initialization

// Func0=Out Func1=Out Func2=Out Func3=Out Func4=Out Func5=Out Func6=Out Func7=Out

// State0=0 State1=0 State2=0 State3=0 State4=0 State5=0 State6=0 State7=0

PORTC=0x00;

DDRC=0xFF;

 

// USART0 initialization

// Communication Parameters: 8 Data, 1 Stop, No Parity

// USART0 Receiver: On

// USART0 Transmitter: On

// USART0 Mode: Asynchronous

// USART0 Baud rate: 9600

UCSR0A=0x00;

UCSR0B=0xD8;

UCSR0C=0x06;

UBRR0H=0x00;

UBRR0L=0x67;

 

// Global enable interrupts

#asm("sei") 

 

while (1)

      {

      // Place your code here

 

      };

}

 

óÀ½

°ú    Á¦

°úÁ¦1

¹®ÀÚ¡±0¡±=C0 ¹®ÀÚ¡±1¡±=C1 ¹®ÀÚ¡±2¡±=C2 ¹®ÀÚ¡±3¡±=C3 ¹®ÀÚ¡±4¡±=C4 ¹®ÀÚ¡±5¡±=C5 ¿¡ µû¶ó Ãâ·ÂÀ» Á¦¾îÇϽÿÀ

 

ÈùÆ® ¿©±â¿¡ ¹®ÀÚ 4,5¸¦ Ãß°¡ ÇØ¾ß ÇÑ´Ù.

if(rxd==0x30)

      PORTC=0x01; 

   else if(rxd==0x31)

      PORTC=0x02;

   else if(rxd==0x32)

      PORTC=0x04;

   else if(rxd==0x33)

      PORTC=0x08;

   else

      PORTC=0x00;

 

°úÁ¦2

¿À¸¥ÂÊ ±×¸²¿¡¼­ PC¿¡¼­ ³ëºê¿¡ µû¶ó °úÁ¦1ÀÇ ¹®ÀÚ¸¦ Àü¼ÛÇØ Ãâ·Â º¸µå¸¦ Á¦¾î ÇϽÿÀ

 

[PCÇÁ·Î±×·¥ ³»·Á¹Þ±â]

 

º¸±â2

³ëºêÀÇ °ªÀÌ º¯ÇÒ ¶§ ±×°ªÀ» Àо ÇØ´ç ¹®ÀÚ¸¦ AVR·Î Åë½Å Àü¼ÛÇÏ´Â ÇÔ¼ö

 

 

void CRs232Dlg::OnPointerValueChangedCwknob1(long Pointer, VARIANT FAR* Value)

{

              // TODO: Add your control notification handler code here

              CString strTemp;

 

              if(m_nOut.Value==0)

                             strTemp.Format("%c",0x30);

              else if(m_nOut.Value==1)

                             strTemp.Format("%c",0x31);

              else if(m_nOut.Value==2)

                             strTemp.Format("%c",0x32);

              else if(m_nOut.Value==3)

                             strTemp.Format("%c",0x33);

              else

                             strTemp.Format("%c",0x29);

              m_ComuPort.WriteComm((unsigned char*)(LPCTSTR)strTemp,strTemp.GetLength());

}