嵌入式汽車發(fā)動(dòng)機(jī)檢測(cè)裝置設(shè)計(jì)
uint32 speed(void)
{
uint32 Time;
uint32 SpeedValue;
PINSEL0 = 0x00050005;
PINSEL1 = 0x14000000;
IO0DIR = 0x02000000;
IO1DIR = 0x003f0000;
// 硬件輸入輸出接口初始化
T0TC = 0;
//定時(shí)器設(shè)置為0
T0PR = 0;
//時(shí)鐘不分頻
while((IOPIN0x00000004) != 0); //等待p0.4低電平脈沖信號(hào)
T0TCR = 0x01;
//啟動(dòng)定時(shí)器0
while((IOPIN0x00000004) == 0)
while((IOPIN0x00000004) != 0);
//等待p0.4下一個(gè)低電平脈沖信號(hào)
T0TCR = 0x00;
Time = T0TC;
Time = Time/Fpclk;
//記錄脈沖寬度
SpeedValue = 1/Time*60;
//計(jì)算速度每分鐘多少轉(zhuǎn)
return SpeedValue;
}
顯示部分子程序及解釋如下:
/*-顯示器初始化-*/
void init_lcd (void)
{
IO1CLR = rst;//rst=0;
delay(50);
IO1SET = rst;//rst=1;
IO1SET = cs1;//cs1=1;
IO1SET = cs2;//cs2=1;
wr_lcd (comm,disp_off); //#define comm 0 關(guān)顯示
//#define disp_off 0x3e
wr_lcd (comm,disp_on);
//#define disp_on 0x3f 開顯示
}
/*-寫數(shù)據(jù)或命令到LCD-*/
void wr_lcd (uint8dat_comm, uint8 content)
{
chk_busy ();
if(dat_comm){ IO1SET = di; }
else{ IO1CLR = di; } //di=dat_comm;
IO1CLR = rw;//rw=0;
IO0DIR = IO0DIR | IO16_23;
// 設(shè)置P0.0-P0.7為GPIO輸出模式
data_ora=( ( data_ora !(IO16_23) ) | content16 );
IO1SET = e;//e=1;
IO1CLR = e;//e=0;
IO0DIR=IO0DIR !(IO16_23);// 設(shè)置P0.16-P0.23為GPIO輸入模式
}
/*-讀LCD數(shù)據(jù)-*/
uint8 rd_lcd (void)
{
uint8 rddata;
chk_busy ();
IO1SET = di;//di=1;
IO1SET = rw;//rw=1;
IO1SET = e;//e=1;
rddata= data_ora>>16;
IO1CLR = e;//e=0;
return rddata;
}
/*-寫點(diǎn)陣-*/
void lat_disp (uint8 data1,uint8 data2)
{
uint8 i,j;
IO1SET = cs1;//cs1=1; //兩屏同時(shí)寫數(shù)據(jù)
IO1SET = cs2;
//cs2=1;
wr_lcd (comm,disp_on);
for(j=0;j8;j++) //共8頁
{
wr_lcd (comm,disp_x+j);
wr_lcd (comm,disp_z);
wr_lcd (comm,disp_y);
for(i=0;i32;i++)
{
wr_lcd (dat,data1);
wr_lcd (dat,data2); //每頁64個(gè)數(shù)
}
}
}
/*---指定位置(x,y)顯示row_xl行(每行row_yl個(gè))漢字(大小8xl*yl)---*/
void chn_disp (uint8 x,uint8 y,uint8 xl,uint8 yl,uint8 row_xl,uint8 row_yl,const uint8 *chn)
{
uint8 i,j,k,l,a;
//row_xl:顯示row_xl行
wr_lcd (comm,disp_on);
//每行row_yl個(gè)漢字
for(l=0;l
//xl:頁大小,一頁八個(gè)點(diǎn)
{
//yl: 列大小,一列一個(gè)點(diǎn)
for(k=0;k
//x,y:起始位置
{
for(j=0;j
{
wr_lcd (comm,disp_x+x+l *xl+j);
wr_lcd (comm,disp_z);
wr_lcd (comm,disp_y+y+k*yl);
a=l*xl*yl*row_yl+k*xl*yl+j*yl; //a:數(shù)組chn[]中第a個(gè)字符
for(i=0;i
wr_lcd (dat,chn[a+i]);
}
}
}
}
結(jié)語
本系統(tǒng)以目前廣泛應(yīng)用的LPC2134 ARM為控制處理核心,以感應(yīng)高壓線圈和低壓線圈作為ARM的輸入信號(hào),用OCM12864的點(diǎn)陣作為儀器的顯示,使該裝置可以有效完成對(duì)汽車發(fā)動(dòng)機(jī)的的精確測(cè)量。它可以將發(fā)動(dòng)機(jī)動(dòng)態(tài)運(yùn)行的各種參數(shù)和故障檢測(cè)診斷出來,然后通過維修、調(diào)整以達(dá)到修復(fù)發(fā)動(dòng)機(jī)的目的。
linux操作系統(tǒng)文章專題:linux操作系統(tǒng)詳解(linux不再難懂)
評(píng)論