AVR單片機(jī)控制舵機(jī)
作者:
時(shí)間:2012-08-02
來(lái)源:網(wǎng)絡(luò)
收藏
#include iom32v.h>typedef struct BYTE_BIT{unsigned BIT0:1;unsigned BIT1:1;unsigned BIT2:1;unsigned BIT3:1;unsigned BIT4:1;unsigned BIT5:1;unsigned BIT6:1;unsigned BIT7:1;}BYTEBIT;#define SET_BIT8_FORMAT(Addr) (*((volatile BYTEBIT *)Addr)) # define PORTB_BIT SET_BIT8_FORMAT(PORTB)# define _PB0 PORTB_BIT.BIT0# define _PB1 PORTB_BIT.BIT1# define _PB2 PORTB_BIT.BIT2# define _PB3 PORTB_BIT.BIT3# define _PB4 PORTB_BIT.BIT4# define _PB5 PORTB_BIT.BIT5# define _PB6 PORTB_BIT.BIT6# define _PB7 PORTB_BIT.BIT7/*delay(1)延時(shí)時(shí)間為300USdelay(80)延時(shí)時(shí)間為20mSdelay(4)延時(shí)時(shí)間為1mSdelay(8)延時(shí)時(shí)間為2mSdelay(6)延時(shí)時(shí)間為1.55mSdelay(2)延時(shí)時(shí)間為0.55MSdelay(10)延時(shí)時(shí)間為2.5mS*/void Delay(int j){ int i;for(;j>0;j--){ for(i=0;i35;i++);}}void main(void) {int i,j;DDRB=0XFF;while(1){//2.0ms 135度位置_PB7=1;Delay(8);_PB7=0;Delay(74);/*//1.0ms 45度位置_PB7=1;Delay(4);_PB7=0;Delay(78);//1.5ms 90度位置_PB7=1;Delay(6);_PB7=0;Delay(78);// 2.5ms 180度位置_PB7=1;Delay(10);_PB7=0;Delay(72);//0.5ms 0度位置_PB7=1;Delay(2);_PB7=0;Delay(78);*/}}
評(píng)論