125310, , .. , , , . 16-18, , 15-6

2301

2301

2301

: NPN

: KT-1-7

2301

2301 13.5

AVR, .
USART, RS 232. 8 . ,
. , a .
CodeVisionAVR:

unsigned int schet_ad; //

// USART Receiver buffer
#define RX_BUFFER_SIZE 8 //
//
char rx_buffer[RX_BUFFER_SIZE];

#if RX_BUFFER_SIZE<256
unsigned char rx_wr_index,rx_rd_index,rx_counter;
#else
unsigned int rx_wr_index,rx_rd_index,rx_counter;
#endif

// This flag is set on USART Receiver buffer overflow
bit rx_buffer_overflow;

// USART Receiver interrupt service routine
interrupt [USART_RXC] void usart_rx_isr(void)
{
char status,data;
status=UCSRA;
data=UDR;
//*************
schet_ad ++; //
//**************
if ((status & (FRAMING_ERROR | PARITY_ERROR | D?4??4??1?_OVERRUN))==0)
{
rx_buffer[rx_wr_index]=data;
if (++rx_wr_index == RX_BUFFER_SIZE) rx_wr_index=0;
if (++rx_counter == RX_BUFFER_SIZE)
{
rx_counter=0;
rx_buffer_overflow=1;

};
};
}

#ifndef _DEBUG_TERMINAL_IO_
// Get a character from the USART Receiver buffer
#define _ALTERNATE_GETCHAR_
#pragma used+
char getchar(void)
{
char data;
while (rx_counter==0);
data=rx_buffer[rx_rd_index];
if (++rx_rd_index == RX_BUFFER_SIZE)
rx_rd_index=0;

#asm("cli")
--rx_counter;
#asm("sei")
return data;
}
#pragma used-
#endif
------------------------

// USART initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART Receiver: On
// USART Transmitter: Off
// USART Mode: Asynchronous
// USART Baud rate: 115200 (Double Speed Mode)
UCSRA=0x02;
UCSRB=0x90;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x08;
----------------------------
while (1)
{
while (schet_bayt != schet_ad ) //
{
if (schet_ad == 1) // 1
{
pwm1 = getchar();
OCR2 = pwm1; //
};// if (schet_ad == 1)

if (schet_ad == 2) // 2
{
pwm2 = getchar();
OCR1A = pwm2; //
};// if (schet_ad == 2)
if (schet_ad == 3) // 3
{
flag1 = 1; // -
pwm3 = getchar();
OCR1B = pwm3; // 1
flag1 = 1; // -
};// if (schet_ad == 3)
}; // while (schet_ad <= schet_bayt-1)

if (flag1 == 1) //
{
schet_ad = 0; //
flag1 = 0; // 0
}// if (flag1 == 1)
};// while (1) , 2643-2, 315 npn , 2603