Буду очень признателен. Пытался понять - не получилось, не понимаю я ассемблер.
Ну или кто знает или умеет - расскажите как с кодом RC5 обращаться. Надо принять команду с пульта от телека... :roll:
roboforum.ruТехнический форум по робототехнике. |
|
|
|
Реклама | ||||
|
|
|||
/*****************************************************
This program was produced by the
CodeWizardAVR V1.24.5 Standard
Automatic Program Generator
c Copyright 1998-2005 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
e-mail:office@hpinfotech.com
Project : stb
Version :
Date : 17.09.2005
Author : Artem
Company : Art Inc. UnLTD.
Comments:
Chip type : AT90S2313
Clock frequency : 7,372800 MHz
Memory model : Tiny
External SRAM size : 0
Data Stack size : 32
*****************************************************/
#include <90s2313.h>
#include <delay.h>
// External Interrupt 1 service routine
#define RXB8 1
#define TXB8 0
#define OVR 3
#define FE 4
#define UDRE 5
#define RXC 7
#define FRAMING_ERROR (1<<FE)
#define DATA_OVERRUN (1<<OVR)
#define DATA_REGISTER_EMPTY (1<<UDRE)
#define RX_COMPLETE (1<<RXC)
// UART 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 UART Receiver buffer overflow
bit rx_buffer_overflow;
// UART Receiver interrupt service routine
interrupt [UART_RXC] void uart_rx_isr(void)
{
char status,data;
status=USR;
data=UDR;
if ((status & (FRAMING_ERROR | DATA_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 UART 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
// UART Transmitter buffer
#define TX_BUFFER_SIZE 8
char tx_buffer[TX_BUFFER_SIZE];
#if TX_BUFFER_SIZE<256
unsigned char tx_wr_index,tx_rd_index,tx_counter;
#else
unsigned int tx_wr_index,tx_rd_index,tx_counter;
#endif
// UART Transmitter interrupt service routine
interrupt [UART_TXC] void uart_tx_isr(void)
{
if (tx_counter)
{
--tx_counter;
UDR=tx_buffer[tx_rd_index];
if (++tx_rd_index == TX_BUFFER_SIZE) tx_rd_index=0;
};
}
#ifndef _DEBUG_TERMINAL_IO_
// Write a character to the UART Transmitter buffer
#define _ALTERNATE_PUTCHAR_
#pragma used+
void putchar(char c)
{
while (tx_counter == TX_BUFFER_SIZE);
#asm("cli")
if (tx_counter || ((USR & DATA_REGISTER_EMPTY)==0))
{
tx_buffer[tx_wr_index]=c;
if (++tx_wr_index == TX_BUFFER_SIZE) tx_wr_index=0;
++tx_counter;
}
else
UDR=c;
#asm("sei")
}
#pragma used-
#endif
// Standard Input/Output functions
#include <stdio.h>
interrupt [EXT_INT1] void ext_int1_isr(void)
{
// Place your code here
unsigned char i,j;
#asm("cli")
PORTB.1=0;
for (i=0;i<250;i++){
delay_us(100);
if (PIND.3==0) { break;};
}
j='D';
if (i<60) {j='C';};
if (i<25) {j='B';};
if (i<10) {j='A';};
putchar(j);
PORTB.1=1;
#asm("sei")
}
// Timer 0 overflow interrupt service routine
interrupt [TIM0_OVF] void timer0_ovf_isr(void)
{
// Reinitialize Timer 0 value
//TCNT0=0x90;
// Place your code here
}
// Declare your global variables here
void main(void)
{
// Declare your local variables here
unsigned char a;
char b;
PORTB=0x00;
DDRB=0xFF;
PORTD=0x7F;
DDRD=0x00;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: 921,600 kHz
TCCR0=0x02;
TCNT0=0xFA;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer 1 Stopped
// Mode: Normal top=FFFFh
// OC1 output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
OCR1H=0x00;
OCR1L=0x00;
// External Interrupt(s) initialization
// INT0: Off
// INT1: On
// INT1 Mode: Falling Edge
GIMSK=0x80;
MCUCR=0x0C;
GIFR=0x80;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x02;
// UART initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// UART Receiver: On
// UART Transmitter: On
// UART Baud rate: 115200
UCR=0xD8;
UBRR=0x2F;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
// Global enable interrupts
#asm("sei")
PORTB.0=1;
PORTB.1=1;
PORTB.2=1;
PORTB.3=1;
PIND.3=1;
delay_ms(500);
for (a=0;a<255;a++){
delay_ms(1);
putchar(a);
}
PORTB.0=0;
while (1)
{
// Place your code here
b=getchar;
};
}
Реклама | ||||
|
|
|||
Сейчас этот форум просматривают: Bing [Bot] и гости: 23