一程序同时控制电机和流水灯,可是电机的转速不够快,调整延时和初值电机都不够快,希望大家指教,谢谢!
程序如下
#include <iom16v.h>
#include <macros.h>
#define uint unsigned int
#define uchar unsigned char
#pragma interrupt_handler dianji:9
//#pragma interrupt_handler fgg:10
uchar a[]={0x01,0x02,0x04,0x08};
void delay(uint ms)
{
uint m,n;
for (m=0;m<ms;m++)
for(n=0;n<300;n++);
}
void dianji()
{
uchar j;
for (j=0;j<4;j++)
{
PORTB=a[j];
delay(10);
}
TCNT1H=0XFF;
TCNT1L=0XFE;
}
void main()
{
DDRB=0XFF;
DDRA=0XFF;
PORTB=0X00;
PORTA=0X00;
TCCR1B=0X04;
TCNT1H=0XFF;
TCNT1L=0XFE;
TIMSK|=BIT(2);
SREG|=BIT(7);//sei
while(1)
{
uchar i,j,m;
i=0X01;
for (j=0;j<8;j++)
{
PORTA=~i;
delay(1);
i=i<<1;
}
}
}