#include<avr/io.h>
#include<avr/interrupt.h>
#include<util/delay.h>
#define uchar unsigned char
#define uint unsigned int
#define fosc 8000000
volatile uchar counter;
uchar jiaodu;
void USART_Init(uint baud)
{
UBRR1H=(fosc/16/(baud+1))/256;
UBRR1L=(fosc/16/(baud+1))%256;
UCSR1A=0X00;
UCSR1C=0X06;
UCSR1B=0X10;
}
uchar usart_receive(void)
{
while(!(UCSR1A&(1<<RXC1)));
return UDR1;
}
void initial(void)
{
DDRB=0XFF;
PORTB=0XEF;
TCNT0=0XFC;
TCCR0=0X07;
TIMSK=0X01;
SREG|=0X80;
counter=0;
jiaodu=1;
}
SIGNAL(SIG_OVERFLOW0)
{
TCNT0=0XFC;
if(counter<jiaodu)
{
PORTB=0X10;
}
else
{
PORTB=0X00;
}
counter++;
counter=counter%40;
}
int main(void)
{
USART_Init(9600);
initial();
while(1)
{
switch(usart_receive())
{
case 1:jiaodu=2;break;
case 2:jiaodu=3;break;
case 3:jiaodu=4;break;
case 4:jiaodu=5;break;
case 0:break;
default:break;
}
}
}
程序是这么编写的,但是舵机不转,请大家指教一下是什么问题??感谢!!!!
此帖出自
小平头技术问答
一周热门 更多>