for(i=0;i<12;i++) disply_listchar((i/6)*42,i%6,lcd_show[i],(cur_sel==i)?0:1); }
if(btn_sav()) {
for(i=0;i<12;i++)WrEEPROM(i,setnum[i]);
disply_listchar(0,0,\ disply_listchar(0,1,\
disply_listchar(0,2,\ disply_listchar(0,3,\ disply_listchar(0,4,\ disply_listchar(0,5,\ while(1); } } }
DDRA=0x00;
DDRB_DDRB0=1;
for(;;) {
delay(setnum[0]*1000);
PORTB_PB0=1;
PWMDTY67=0; PWMDTY45=1000;
delay(setnum[0]*1000);
PORTB_PB0=0;
PWMDTY67=0; PWMDTY45=0;
delay(setnum[0]*1000); PORTB_PB0=0; PWMDTY45=0;
PWMDTY67=1000;
delay(setnum[0]*1000); }
4.码盘控速
#include
PORTB_PB0=0;
PWMDTY67=0; PWMDTY45=0; }
#include \#include \#include \
#define servo_period 20 //ms #define motor_pwm_frequ 1 //khz
void delay(unsigned int ms) {
unsigned int i; unsigned char j; for(i=0;i for(j=0;j<100;j++); } } /******************************倍频 *****************************************/ void vPLLInit(void) { unsigned char refdv; refdv=3; CLKSEL=0X00; PLLCTL_PLLON=1; //disengage PLL to system //turn on PLL SYNR =0xc0 | ((80/(refdv+1))-1); REFDV=0x40 | refdv; POSTDIV=0x00; //pllclock=2*osc*(1+SYNR)/(1+REFDV)=160MHz; _asm(nop); //BUS CLOCK=80M _asm(nop); while(!(CRGFLG_LOCK==1)); //when pll is steady ,then use it; CLKSEL_PLLSEL =1; } /******************************倍频 *****************************************/ /** PWM初始化***/ void Init_PWMout(void) { PWME = 0x00; //禁止输出 PWMPOL = 0xff;//极性寄存器,1 先输出高电平 后为低电平 0 先输出低电平 后为高电平 PWMCTL = 0xf0; //01 23 45 67 通道级联 PWMPRCLK=0x55; //Clock A=Bus Clock/32 ; Clock B=Bus Clock/32; PWMCLK=0b00000000; //选择clock:7B,6B,5A,4A,3B,2B,1A,0A PWME = 0xaa; //pp1,pp3,pp5,pp7口输出 PWMPER67 = 80/4*125/motor_pwm_frequ; //engage PLL to system; PWMPER45 = 80/4*125/motor_pwm_frequ; PWMPER23 = 80/4*servo_period*125; PWMPER01 = 80/4*servo_period*125; PWMDTY67 =0; PWMDTY45 =0; PWMDTY23 =0; PWMDTY01 =0; } /** PWM初始化***/ //////////////////////测速增加部分///////////////////////// int cur_speed; int cur_time; /****测速初始化****/ void speed_Init(void) { PACTL_PAMOD=0;//0 Event counter mode. PACTL_PEDGE=1;//1 Rising edges on IOC7 pin cause the count to be incremented. PACTL_PAEN=1;//1 Pulse Accumulator system enabled. }