?? 求飛思卡爾智能車程序_百度知道.mht
字號:
=CF=D6=BB=F9=B1=BE=B9=A6=C4=DC=BC=B4=BF=C9.=D7=A2=CA=CD=D4=BD=CF=EA=CF=B8=
=D4=BD=BA=C3.=B4=F0=B0=B8=C2=FA=D2=E2=BB=E1=BC=D3=B7=D6.</CD></DIV>
<DIV class=3D"f14 wr"></DIV></DIV>
<DIV class=3Dgray align=3Dright>=CC=E1=CE=CA=D5=DF=A3=BA =
=C4=E4=C3=FB</DIV></DIV></DIV>
<DIV class=3Drg_4></DIV>
<DIV class=3Drg_5></DIV>
<DIV class=3Drg_1></DIV></DIV>
<DIV class=3D"mb12 bai">
<DIV class=3Drr_1></DIV>
<DIV class=3Drr_2></DIV>
<DIV class=3Drr_3></DIV>
<DIV class=3Drr>
<DIV class=3Dt1>
<DIV class=3Dico>
<DIV class=3Dibest></DIV></DIV>=D7=EE=BC=D1=B4=F0=B0=B8</DIV>
<DIV class=3Dbc0=20
style=3D"PADDING-RIGHT: 0pt; PADDING-LEFT: 0pt; PADDING-BOTTOM: 5px; =
PADDING-TOP: 5px">
<DIV class=3Dwr>
<DIV class=3D"f14 p90 pl10"><CA>/*=20
<BR><BR>*****************************************************************=
******************=20
<BR><BR>* Test.c <BR><BR>* Description: This file includes I/ O function =
for=20
test, the PWM outputs function for test, function <BR><BR>* testing =
sensors.=20
<BR><BR>* (c) Copyright 2006,Zhao Cheng <BR><BR>* All Rights Reserved =
<BR><BR>*=20
<BR><BR>* By : Zhao Cheng <BR><BR>* Note : Don't change this file if =
possible.=20
<BR><BR>*****************************************************************=
*****************/=20
<BR><BR>#include <hidef.h> <BR><BR>#include <mc9s12dg128.h>=20
<BR><BR>#define HIGHSPEED 8000 <BR><BR>#define LOWSPEED 11000 /* =
=CB=D9=B6=C8=B1=E4=C1=BF=A3=AC0-24000=20
=CA=FD=D6=B5=D4=BD=B4=F3=A3=AC=CB=D9=B6=C8=D4=BD=C2=FD */ <BR><BR>void =
PWMout(int, int); <BR><BR>/* 24000-20000 */=20
<BR><BR>void IOtest(void) <BR><BR>{ <BR><BR>static unsigned char =
i=3D0,j=3D0x01,k;=20
<BR><BR>DDRB =3D DDRA =3D 0xFF; <BR><BR>PORTB =3D 0xf0; <BR><BR>for(;;) =
<BR><BR>{=20
<BR><BR>k=3D(~j)&0x7f; <BR><BR>PORTA =3D PORTB =3D k; <BR><BR>while =
(TCNT !=3D=20
0x0000); <BR><BR>while (TCNT =3D=3D 0x0000) <BR><BR>{ <BR><BR>if(i>9) =
<BR><BR>{=20
<BR><BR>j=3Dj<<1; <BR><BR>i=3D0; <BR><BR>} <BR><BR>i++; <BR><BR>}=20
<BR><BR>if(j>=3D0x80) <BR><BR>j=3D0x01; <BR><BR>} <BR><BR>} =
<BR><BR>void=20
PWMtest(void) <BR><BR>{ <BR><BR>int counter=3D-4500; <BR><BR>DDRB =3D =
0xff;=20
<BR><BR>PORTB =3D 0xff; <BR><BR>TSCR1 =3D 0x80; /* enable timer TCNT */=20
<BR><BR>TSCR2 =3D 0x00; /* TCNT prescaler setup */ <BR><BR>for(;;) =
<BR><BR>{=20
<BR><BR>while (TCNT !=3D 0x0000); <BR><BR>while (TCNT =3D=3D 0x0000);=20
<BR><BR>counter=3Dcounter+30; <BR><BR>if(counter >=3D 3000) <BR><BR>{ =
<BR><BR>counter =3D 0; <BR><BR>PWMout(4500, LOWSPEED); <BR><BR>}=20
<BR><BR>if(counter =3D=3D 1500) <BR><BR>{ <BR><BR>PWMout(-4500, =
LOWSPEED); <BR><BR>}=20
<BR><BR>PORTB =3D (char)(counter/100); <BR><BR>} <BR><BR>} <BR><BR>void=20
SignalTest(void) <BR><BR>{ <BR><BR>unsigned char signal; <BR><BR>int =
Direction,=20
Velocity; <BR><BR>Direction =3D 0; <BR><BR>Velocity =3D LOWSPEED; =
<BR><BR>DDRA =3D=20
0x00; <BR><BR>DDRB =3D 0xff; <BR><BR>signal =3D PORTA; <BR><BR>PORTB =3D =
~signal;=20
<BR><BR>switch(signal) <BR><BR>{ <BR><BR>case 0x08: /* 0001 1000 */ =
<BR><BR>case=20
0x10: <BR><BR>Direction =3D 800; <BR><BR>Velocity =3D HIGHSPEED; =
<BR><BR>break;=20
<BR><BR>case 0x04: /* 0010 0100 */ <BR><BR>case 0x20: <BR><BR>Direction =
=3D 1500;=20
<BR><BR>Velocity =3D HIGHSPEED; <BR><BR>break; <BR><BR>case 0x02: /* =
0100 0010 */=20
<BR><BR>case 0x40: <BR><BR>Direction =3D 2800; <BR><BR>Velocity =3D =
HIGHSPEED;=20
<BR><BR>break; <BR><BR>case 0x01: /* 1000 0001 */ <BR><BR>case 0x80:=20
<BR><BR>Direction =3D 4000; <BR><BR>Velocity =3D LOWSPEED; =
<BR><BR>break;=20
<BR><BR>case 0x3c: /* 0011 1100 over start line */ <BR><BR>case 0xff: /* =
1111=20
1111 over crossing line */ <BR><BR>case 0x00: /* 0000 0000 go straight =
not need=20
changed state */ <BR><BR>default: <BR><BR>break; <BR><BR>} =
<BR><BR>if(signal=20
> 0x0f) <BR><BR>Direction =3D -Direction; <BR><BR>PWMout(Direction, =
LOWSPEED);=20
<BR><BR>} <BR><BR>/*=20
<BR><BR>*****************************************************************=
******************=20
<BR><BR>* LCD1620.c <BR><BR>* ICC-AVR application builder : 2006-1-8 =
21:43:48=20
<BR><BR>* Target : M8 <BR><BR>* Crystal: 4.0000Mhz <BR><BR>* <BR><BR>* =
Note :=20
Don't change this file if possible.=20
<BR><BR>*****************************************************************=
*****************/=20
<BR><BR>#define CMD_CLEAR 0x01 <BR><BR>#define CMD_RESET 0x02 =
<BR><BR>#include=20
<iom8v.h> <BR><BR>#include <macros.h> <BR><BR>#define =
LCD_DATA 0xff=20
<BR><BR>#define LCD_EN 0x01 //PORTC 0 <BR><BR>#define LCD_RS 0x02 =
//PORTC 1=20
<BR><BR>#define LCD_RW 0x04 //PORTC 2 <BR><BR>#define LCD_DATAPORT PORTB =
<BR><BR>#define LCD_ENPORT PORTA <BR><BR>#define LCD_RSPORT PORTA=20
<BR><BR>#define LCD_RWPORT PORTA <BR><BR>void lcd_init(void); =
<BR><BR>void=20
lcd_write_cmd(unsigned cmd,unsigned data); <BR><BR>void =
lcd_setxy(unsigned char=20
x,unsigned char y); <BR><BR>void lcd_write_string(unsigned char =
X,unsigned char=20
Y,unsigned char *str); <BR><BR>void delay_nus(unsigned int n); =
<BR><BR>void=20
delay_nms(unsigned int n); <BR><BR>void lcd_init(void) <BR><BR>{ =
<BR><BR>DDRB |=3D=20
LCD_DATA; <BR><BR>DDRA |=3D LCD_EN | LCD_RS | LCD_RW;=20
<BR><BR>LCD_RWPORT&=3D~LCD_RW; <BR><BR>LCD_DATAPORT=3D0x30;=20
//=BF=D8=D6=C6=D7=D6=B9=E6=D4=F2=A3=BA5=A3=BA8bit,4:16x2,3:5x7 =
<BR><BR>LCD_ENPORT|=3DLCD_EN; <BR><BR>delay_nus(1);=20
<BR><BR>LCD_ENPORT&=3D~LCD_EN; <BR><BR>delay_nus(40);=20
<BR><BR>lcd_write_cmd(0,0x38); //8bit test =
<BR><BR>lcd_write_cmd(0,0x0c); //=CF=D4=CA=BE=BF=AA=20
<BR><BR>lcd_write_cmd(0,0x01); //=CF=D4=CA=BE=C7=E5=C6=C1 =
<BR><BR>lcd_write_cmd(0,0x06); =
//=CF=D4=CA=BE=B9=E2=B1=EA=D2=C6=B6=AF=C9=E8=D6=C3=20
<BR><BR>} <BR><BR>void lcd_write_cmd(unsigned cmd,unsigned data) =
<BR><BR>{=20
<BR><BR>if(cmd=3D=3D0) <BR><BR>LCD_RSPORT&=3D~LCD_RS; <BR><BR>else=20
<BR><BR>LCD_RSPORT|=3DLCD_RS; <BR><BR>LCD_DATAPORT&=3D0x00;=20
<BR><BR>LCD_DATAPORT=3Ddata; <BR><BR>LCD_ENPORT|=3DLCD_EN; =
<BR><BR>delay_nus(10);=20
<BR><BR>LCD_ENPORT&=3D~LCD_EN; <BR><BR>delay_nus(10); <BR><BR>} =
<BR><BR>void=20
lcd_setxy(unsigned char x,unsigned char y) <BR><BR>{ <BR><BR>unsigned =
char addr;=20
<BR><BR>if(y=3D=3D0) <BR><BR>addr=3Dx+0x80; <BR><BR>else =
<BR><BR>addr=3Dx+0xc0;=20
<BR><BR>lcd_write_cmd(0,addr); <BR><BR>} <BR><BR>void =
lcd_write_string(unsigned=20
char X,unsigned char Y,unsigned char *str) <BR><BR>{ =
<BR><BR>lcd_setxy(X,Y);=20
<BR><BR>while(*str) <BR><BR>{ <BR><BR>lcd_write_cmd(1,*str); =
<BR><BR>str++;=20
<BR><BR>} <BR><BR>} <BR><BR>void delay_1us(void) =
//1us=D1=D3=CA=B1=BA=AF=CA=FD <BR><BR>{=20
<BR><BR>asm("nop"); <BR><BR>} <BR><BR>void delay_nus(unsigned int n) //N =
us=D1=D3=CA=B1=BA=AF=CA=FD=20
<BR><BR>{ <BR><BR>unsigned int i=3D0; <BR><BR>for (i=3D0;i<n;i++)=20
<BR><BR>delay_1us(); <BR><BR>} <BR><BR>void delay_1ms(void) =
//1ms=D1=D3=CA=B1=BA=AF=CA=FD <BR><BR>{=20
<BR><BR>unsigned int i; <BR><BR>for (i=3D0;i<1140;i++); <BR><BR>} =
<BR><BR>void=20
delay_nms(unsigned int n) //N ms=D1=D3=CA=B1=BA=AF=CA=FD <BR><BR>{ =
<BR><BR>unsigned int i=3D0;=20
<BR><BR>for (i=3D0;i<n;i++) <BR><BR>delay_1ms(); <BR><BR>} =
<BR><BR>//call this=20
routine to initialize all peripherals <BR><BR>void main(void) <BR><BR>{=20
<BR><BR>lcd_init(); <BR><BR>while(1) <BR><BR>{ =
<BR><BR>lcd_write_cmd(0,0x01);=20
//=C7=E5=C6=C1 <BR><BR>delay_nms(2); <BR><BR>lcd_write_string(0,0,"happy =
new year");=20
<BR><BR>delay_nms(100); <BR><BR>lcd_write_string(0,1,"LCD successful!"); =
<BR><BR>delay_nms(100); <BR><BR>} <BR><BR>}=20
<BR><BR>/******************************* =B3=CC=D0=F2=BD=E1=CA=F8 =
*********************************/=20
<BR><BR><BR>=D4=F5=D1=F9?</CA></DIV>
<DIV class=3Dgray style=3D"MARGIN: 5px 5px 8px" =
align=3Dright>=BB=D8=B4=F0=D5=DF=A3=BA<A=20
href=3D"http://passport.baidu.com/?business&aid=3D6&un=3Dxiiic13#=
2"=20
target=3D_blank>xiiic13</A> -<A=20
href=3D"http://www.baidu.com/search/zhidao_help.html#n5" =
target=3D_blank> =BE=AD=C0=ED =CB=C4=BC=B6</A>=20
3-3 12:39</DIV>
<DIV =
class=3Dt2>=CC=E1=CE=CA=D5=DF=B6=D4=D3=DA=B4=F0=B0=B8=B5=C4=C6=C0=BC=DB=A3=
=BA</DIV>
<DIV class=3D"p90 pl10 f14">=D0=BB=D0=BB=C1=CB!</DIV>
<DIV =
class=3Dt2>=C6=C0=BC=DB=D2=D1=BE=AD=B1=BB=B9=D8=B1=D5 &n=
bsp;<SPAN class=3D"f12 gray"=20
style=3D"FONT-WEIGHT: normal">=C4=BF=C7=B0=D3=D0 5 =
=B8=F6=C8=CB=C6=C0=BC=DB</SPAN></DIV>
<DIV class=3Dpl10>
<TABLE cellSpacing=3D0 cellPadding=3D0 border=3D0>
<TBODY>
<TR vAlign=3Dtop>
<FORM name=3Dfpj action=3Dhttp://zhidao.baidu.com/q =
method=3Dpost><INPUT=20
type=3Dhidden value=3D22 name=3Dct> <INPUT type=3Dhidden name=3Dmpn> =
<INPUT=20
type=3Dhidden value=3D100003 name=3Dcm> <INPUT type=3Dhidden =
value=3D47196851=20
name=3Dqid> <INPUT type=3Dhidden value=3Diksubmit name=3Dtn>
<SCRIPT>function g(w){ =
document.fpj.mpn.value=3Dw;};document.write("<input type=3Dhidden =
name=3Dlu value=3D"+ escape(location.href)+">");</SCRIPT>
=20
<TD class=3Df14 width=3D120>=BA=C3<BR><SPAN class=3Dred>80%</SPAN> =
=A3=A84=A3=A9</TD>
<TD class=3Df14 width=3D120>=B2=BB=BA=C3<BR><SPAN class=3Dgrn>20%=20
=
</SPAN>=A3=A81=A3=A9</TD></FORM></TR></TBODY></TABLE></DIV></DIV></DIV></=
DIV>
<DIV class=3Drr_4></DIV>
<DIV class=3Drr_5></DIV>
<DIV class=3Drr_1></DIV></DIV>
<DIV class=3D"mb12 bai">
<DIV class=3Drg_1></DIV>
<DIV class=3Drg_2></DIV>
<DIV class=3Drg_3></DIV>
<DIV class=3Drg>
<DIV class=3Dt1>
<DIV class=3Dico>
<DIV class=3Direlate></DIV></DIV>=CF=E0=B9=D8=CE=CA=CC=E2</DIV>
<DIV class=3Dbc0>
<TABLE class=3Dwr cellSpacing=3D0 cellPadding=3D0 border=3D0>
<TBODY>
<TR>
<TD class=3Dgray vAlign=3Dtop width=3D10>• </TD>
<TD class=3Df14><A=20
href=3D"http://zhidao.baidu.com/question/43286539.html?fr=3Dqrl"=20
=
target=3D_blank>=B7=C9=CB=BC=BF=A8=B6=FB=D6=C7=C4=DC=B3=B5=B4=F3=C8=FC=B9=
=E6=D4=F2=B5=C4=D7=CA=C1=CF=A3=A1</A></TD></TR>
<TR>
<TD class=3Dgray vAlign=3Dtop width=3D10>• </TD>
<TD class=3Df14><A=20
href=3D"http://zhidao.baidu.com/question/46671109.html?fr=3Dqrl"=20
=
target=3D_blank>=B9=D8=D3=DA=B7=C9=CB=BC=BF=A8=B6=FB=B1=AD</A></TD></TR>
<TR>
<TD class=3Dgray vAlign=3Dtop width=3D10>• </TD>
<TD class=3Df14><A=20
href=3D"http://zhidao.baidu.com/question/42702387.html?fr=3Dqrl"=20
=
target=3D_blank>=CB=BD=BC=D2=B3=B5=A3=AC=C7=EB=B4=F3=BC=D2=CD=C6=BC=F6=BC=
=B8=BF=EE=BA=C3=C5=C6=D7=D3=B5=C4=CC=A5=D1=B9=B1=A8=BE=AF=C6=F7=A3=A8TPMS=
=A3=A9=A3=A1</A></TD></TR>
<TR>
<TD class=3Dgray vAlign=3Dtop width=3D10>• </TD>
<TD class=3Df14><A=20
href=3D"http://zhidao.baidu.com/question/17783611.html?fr=3Dqrl"=20
target=3D_blank>=CA=B2=C3=B4=CA=C7smartcar</A></TD></TR>
<TR>
<TD class=3Dgray vAlign=3Dtop width=3D10>• </TD>
<TD class=3Df14><A=20
href=3D"http://zhidao.baidu.com/question/17755661.html?fr=3Dqrl"=20
=
target=3D_blank>MC9S12DG128=B5=C4=D6=D0=CE=C4=D7=CA=C1=CF=A3=BF=A3=BF=A3=A8=
=D7=B7=BC=D3100=B7=D6=A3=A1=A3=A1=A3=A9</A></TD></TR></TBODY></TABLE></DI=
V></DIV>
<DIV class=3Drg_4></DIV>
<DIV class=3Drg_5></DIV>
<DIV class=3Drg_1></DIV></DIV>
<DIV class=3Dbai>
<DIV class=3D"mb12 bai">
<DIV class=3Drg_1></DIV>
<DIV class=3Drg_2></DIV>
<DIV class=3Drg_3></DIV>
<DIV class=3Drg>
<DIV class=3Dt1>
<DIV class=3Dico>
<DIV =
class=3Dicomment></DIV></DIV>=B6=D4=D7=EE=BC=D1=B4=F0=B0=B8=B5=C4=C6=C0=C2=
=DB <SPAN=20
class=3D"f12 gray" style=3D"FONT-WEIGHT: normal">=B9=B2 1 =
=CC=F5</SPAN></DIV>
<DIV class=3Dbc0=20
style=3D"PADDING-RIGHT: 0pt; PADDING-LEFT: 0pt; PADDING-BOTTOM: 5px; =
PADDING-TOP: 5px">
<DIV class=3Dwr>
<DIV class=3D"f14 p90 =
pl10">=D5=E2=B8=F6=B2=BB=CA=C7=D3=C3C=B1=E0=B5=C4=C3=B4=A3=AC=B2=BB=CA=C7=
=BB=E3=B1=E0=B0=A1=B2=BB=B9=FD=CE=D2=CA=D5=CF=C2=C1=CB=B9=FE~~~</DIV>
<DIV style=3D"MARGIN: 5px 5px 8px" align=3Dright><SPAN =
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -