1、char row;char line;char interval=7;char oeflag=0;char y_upr_max+2;char temp_upr_max+2;#define latch 20 #define latch_neg -20 char w_flgr_max+2;int dif; /-/ /SCI variables/ char sci_d; /PWM variables/ #define mid_P 20 int ctl;第VI页 第十一章 总结 int errr_max+2;unsigned char m_speed;int str;int turn;unsigned
2、 char pulse6;unsigned char speed;unsigned char turn_S;unsigned char str_S; /general variables/ char x,y,z; /-/ Declaration of Functions /overall initiation void ini_orall(void) DDRS_DDRS2=0; DDRS_DDRS7=1; TIOS_IOS0=0; TIOS_IOS1 = 0; TCTL4=0b00001101; TSCR1_TEN = 1; ICPAR_PA1EN = 1; DDRH=0xff; /initi
3、ate bus clock void ini_PLL(void) REFDV=3; SYNR=7; while(0=CRGFLG_LOCK); CLKSEL=0x80;VII第 页 /*SCI*/ /initiate SCI void ini_SCI(void) SCI0BD=208; SCI0CR1=0x00; SCI0CR2=0x0C;/SCI receive void re_sci(void) while(SCI0SR1_RDRF!=1); sci_d=SCI0DRL;/SCI transmit void tx_sci(char tx_d) while(SCI0SR1_TC! while
4、(SCI0SR1_TDRE! SCI0DRL=tx_d; /*/ /*PWM*/ /PWM & 33886 initialization void ini_PWM(void) PTS_PTS7 = 0; PWME = 0x00; PWMCTL_CON01= 1; PWMPRCLK = 0x33 ; PWMSCLA = 100 ; PWMSCLB = 1 ; PWMCLK = 0b00011100; PWMPOL = 0xff ; PWMCAE = 0x00 ; PWMPER0 = 0x4e ;第VIII页 PWMPER1 = 0x20 ; PWMDTY0 = 0x18 ; PWMDTY1 =
5、0x38 ; PWME_PWME1 = 1 ; PWMDTY2 = 120 ; PWMPER2 = 200 ; PWME_PWME2 = 1 ;/Set the angle of steer void pwm_set(int dutycycle) int high8; high8=dutycycle&0xFF00; PWMDTY0=high88; PWMDTY1=dutycycle&0x00FF; /*/ /*SPEED*/ /Initiate the Average speed void speed_init(void) DDRM_DDRM0=0; DDRM_DDRM1=0; DDRM_DD
6、RM2=0; DDRM_DDRM3=0; DDRM_DDRM4=0; DDRM_DDRM5=0; DDRJ_DDRJ6=0; DDRJ_DDRJ7=0; if(1=PTIM_PTIM0) m_speed = 120 + 2*(PTIM_PTIM1*10+PTIM_PTIM2*5+PTIM_PTIM3*2+PTIM_PTIM4*2+PTIM_PTIM5+PTIJ_PTIJ6+PTIJ_PTIJ7); else m_speed = 120 - IX PWMDTY2=m_speed; str_S=m_speed/2-10;/Get the current speed void get_speed()
7、 char k; for(k=0;k5;k+) pulsek=pulsek+1; pulse5=PACN1; speed=pulse5-pulse0;/Set the current speed void set_speed(unsigned char a) if(speed PWMDTY2=0; /*CONTROL*/ void vhcl_pid(void) get_speed(); if(err80) ctl=6250+42*err8; ctl=6250+38*err8; /- dif=err2+err10-2*err6; if(dif-7)&(dif-15)&(err620) str=0
8、; PTH=0x00; set_speed(29); set_speed(str_S); /- if(ctl7400) ctl=7400; pwm_set(ctl); if(1=odd_even) oeflag=1; if(0=odd_even) oeflag=0; /*CCD*/ /Initiate A/D registers void ini_AD(void) ATD0CTL2=0xC0; ATD0CTL3=0x08; ATD0CTL4=0x81; ATD0CTL5=0xA0; ATD0DIEN=0x00;XI/Scan the CCD image void ccd_sc(void) r_chg=0; while(r_chg26-interval) if(1=hs) clr_hs=1; r_chg+; line=0; for(row=1;row=interval) ini_AD(); for(line=0;linel_max;line+) while(!ATD0STAT1_CCF0); ccdline=video; line=6; row+; w_flgrow-1=0; ATD0CTL2=0x00; if(r_chginterval-2)&(linelatch) temp_uprow-1=line+3; w_flgrow-1=1;第XII页 if(diflatch_ne
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1