畢業(yè)設計自行車測速儀(共18頁)_第1頁
畢業(yè)設計自行車測速儀(共18頁)_第2頁
畢業(yè)設計自行車測速儀(共18頁)_第3頁
畢業(yè)設計自行車測速儀(共18頁)_第4頁
畢業(yè)設計自行車測速儀(共18頁)_第5頁
已閱讀5頁,還剩13頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、精選優(yōu)質文檔-傾情為你奉上#include <reg52.h>#include <stdio.h>#include <intrins.h>#define GDM12864ADataPort P1 /LCD數(shù)據(jù)線#define uchar unsigned charsbit DI=P22; / 數(shù)據(jù)指令 選擇sbit RW=P21; / 讀寫 選擇sbit EN=P20; / 讀寫使能sbit cs1=P24; / 片選1sbit cs2=P23; / 片選2sbit sclk=P25;sbit i_o=P26;sbit rstb=P27;sbit ds18s

2、20_dq=P36;sbit I2C_SCK=P33;sbit I2C_SDA=P35;uchar qq=0,pp=0;/開始/暫停按鍵,計算機傳輸過來的數(shù)據(jù)為8則上傳uchar code a=/16*16 0x10,0x22,0x64,0x0C,0x80,0x00,0xFE,0x92,0x92,0x92,0x92,0x92,0xFF,0x02,0x00,0x00, 0x04,0x04,0xFE,0x01,0x40,0x7E,0x42,0x42,0x7E,0x42,0x7E,0x42,0x42,0x7E,0x40,0x00, 0x00,0x00,0xFC,0x24,0x24,0x24,0xFC

3、,0xA5,0xA6,0xA4,0xFC,0x24,0x34,0x26,0x04,0x00, 0x40,0x20,0x9F,0x80,0x42,0x42,0x26,0x2A,0x12,0x2A,0x26,0x42,0x40,0xC0,0x40,0x00, 0x00,0xFC,0x84,0x84,0x84,0xFE,0x14,0x10,0x90,0x10,0x10,0x10,0xFF,0x10,0x10,0x00, 0x00,0x3F,0x10,0x10,0x10,0x3F,0x00,0x00,0x00,0x23,0x40,0x80,0x7F,0x00,0x00,0x00, 0x00,0xF8,

4、0x01,0x02,0xF6,0x10,0x12,0x12,0x12,0x12,0xFA,0x12,0x02,0xFF,0x02,0x00, 0x00,0xFF,0x00,0x00,0x3F,0x11,0x11,0x11,0x11,0x11,0x3F,0x40,0x80,0x7F,0x00,0x00, 0x40,0x42,0x44,0xCC,0x00,0xF4,0x94,0x94,0x94,0xFF,0x94,0x94,0x94,0xF6,0x04,0x00, 0x00,0x40,0x20,0x1F,0x20,0x51,0x48,0x44,0x42,0x7F,0x42,0x44,0x4C,0x

5、61,0x20,0x00, 0x00,0x00,0xFE,0x12,0x12,0x12,0x12,0xFE,0x12,0x12,0x12,0x12,0xFF,0x02,0x00,0x00, 0x40,0x48,0x49,0x49,0x49,0x49,0x49,0x7F,0x49,0x49,0x49,0x49,0x4D,0x68,0x40,0x00, 0x24,0x24,0xA4,0xFE,0xA3,0x22,0x20,0x7E,0x42,0x42,0x42,0x42,0x42,0x7F,0x02,0x00, 0x08,0x06,0x01,0xFF,0x00,0x43,0x41,0x49,0x4

6、9,0x49,0x7F,0x49,0x4D,0x69,0x41,0x00, 0x00,0x00,0xFE,0x82,0x92,0x92,0x92,0xFE,0x92,0x9A,0xD2,0x82,0xFF,0x02,0x00,0x00, 0x40,0x20,0x1F,0x00,0x00,0x7E,0x22,0x22,0x22,0x3F,0x42,0x80,0x7F,0x00,0x00,0x00, 0x80,0x80,0x80,0x80,0xFF,0x80,0x80,0xA0,0x90,0x88,0x84,0x86,0x80,0xC0,0x80,0x00, 0x00,0x00,0x00,0x00

7、,0xFF,0x40,0x40,0x23,0x04,0x08,0x10,0x20,0x60,0x20,0x00,0x00, 0x00,0x06,0x09,0x09,0xE6,0xF0,0x18,0x08,0x08,0x08,0x18,0x30,0x78,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x07,0x0F,0x18,0x30,0x20,0x20,0x20,0x10,0x08,0x00,0x00,0x00, 0x80,0x40,0x20,0xF8,0x47,0x48,0x48,0x48,0xC8,0x7F,0x48,0x48,0x4C,0x68,0x40,0

8、x00, 0x00,0x00,0x00,0xFF,0x00,0x00,0x02,0x0B,0x12,0x62,0xD2,0x0A,0x06,0x02,0x00,0x00;uchar code b=/8*160x00,0xF8,0x08,0x08,0x08,0x08,0xF8,0x00,0x00,0x3F,0x20,0x20,0x20,0x20,0x3F,0x00,0x00,0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,0x08,0x08,0x08,0x08,0x08,0xF8,0x

9、00,0x00,0x3F,0x21,0x21,0x21,0x21,0x21,0x00,0x00,0x08,0x08,0x08,0x08,0x08,0xF8,0x00,0x00,0x21,0x21,0x21,0x21,0x21,0x3F,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0xF8,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x3F,0x00,0x00,0xF8,0x08,0x08,0x08,0x08,0x00,0x00,0x00,0x21,0x21,0x21,0x21,0x21,0x3F,0x00,0x00,0xF8,0x08,0x

10、08,0x08,0x08,0x08,0x00,0x00,0x3F,0x21,0x21,0x21,0x21,0x3F,0x00,0x00,0x08,0x08,0x08,0x08,0x08,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0xF8,0x08,0x08,0x08,0x08,0xF8,0x00,0x00,0x3F,0x21,0x21,0x21,0x21,0x3F,0x00,0x00,0xF8,0x08,0x08,0x08,0x08,0xF8,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x3F,0x

11、00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3E,0x01,0x01,0x3E,0x01,0x01,0x3E,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x13,0x24,0x24,0x19,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x

12、0C,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x80,0x40,0x00,0x

13、00,0x00,0x3F,0x06,0x09,0x10,0x20,0x00,0x00,/17,k0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0x02,0x02,0x02,0x3E,0x00,0x00/18,h;/延時程序,延時10usvoid Delay_10_uS(void)char i=10;while(i-);/n mS delayvoid Delay_N_mS( unsigned int n_milisecond) /* n mS delay */unsigned char i;while(n_milisecond-)i=37;w

14、hile(i-);/啟動傳送bit I2C_Start(void)Delay_10_uS();I2C_SDA =1;Delay_10_uS();I2C_SCK =1;Delay_10_uS();if ( I2C_SDA = 0) return 0;if ( I2C_SCK = 0) return 0;I2C_SDA = 0;Delay_10_uS();I2C_SCK = 0;Delay_10_uS();return 1;/停止信號void I2C_Stop(void)Delay_10_uS();I2C_SDA = 0;Delay_10_uS();I2C_SCK = 1;Delay_10_uS(

15、);I2C_SDA = 1;Delay_10_uS();/無應答的時序,有應答時需要在第9位輸出0,沒有應答時,第9位為高void I2C_Nack(void)Delay_10_uS();I2C_SDA=1;Delay_10_uS();I2C_SCK=1;Delay_10_uS();I2C_SCK=0;Delay_10_uS();/如果發(fā)送完成并且在第9個脈沖處得到ack,那么返回0,表示成功bit I2C_Send_Byte( unsigned char d)unsigned char i = 8;bit bit_ack;while( i- )Delay_10_uS();if ( d &am

16、p;0x80 ) I2C_SDA =1;else I2C_SDA =0;Delay_10_uS();I2C_SCK = 1;Delay_10_uS();I2C_SCK = 0;d = d << 1;Delay_10_uS();I2C_SDA = 1;Delay_10_uS();I2C_SCK = 1;Delay_10_uS();bit_ack = I2C_SDA;I2C_SCK =0;Delay_10_uS();return bit_ack;/接收一個8位數(shù)據(jù)unsigned char I2C_Receive_Byte(void)unsigned char i = 8, d;Del

17、ay_10_uS();I2C_SDA = 1;while ( i-)d = d << 1;Delay_10_uS();I2C_SCK =1;if ( I2C_SDA ) d+;Delay_10_uS();I2C_SCK =0;return d;/寫EEPROM操作void AT24C64_W(void *mcu_address, unsigned int AT24C64_address, unsigned int count )while(count-)I2C_Start();I2C_Send_Byte( 0xa0 );I2C_Send_Byte( AT24C64_address/

18、256 );I2C_Send_Byte( AT24C64_address %256 );I2C_Send_Byte( *(unsigned char*)mcu_address );I2C_Stop();Delay_N_mS(10);(unsigned char*)mcu_address)+;AT24C64_address+;/讀EEPROM函數(shù)void AT24C64_R(void *mcu_address,unsigned int AT24C64_address,unsigned int count)while(count-)I2C_Start();I2C_Send_Byte( 0xa0 )

19、;I2C_Send_Byte( AT24C64_address/256 );I2C_Send_Byte( AT24C64_address % 256 );I2C_Start();I2C_Send_Byte( 0xa1 );*(unsigned char*)mcu_address = I2C_Receive_Byte();I2C_Nack();I2C_Stop();(unsigned char*)mcu_address)+;AT24C64_address+;/單總線延時void ds18s20delay(int useconds)int s;for(s=0;s<useconds;s+);/

20、單總線復位uchar ds18s20reset()uchar presencesignal;ds18s20_dq=0;ds18s20delay(30);ds18s20_dq=1;ds18s20delay(3);presencesignal=ds18s20_dq;ds18s20delay(30);return presencesignal;/單總線位寫入void ds18s20writebit(char val)ds18s20_dq=0;if(val=1)ds18s20_dq=1;elseds18s20_dq=0;ds18s20delay(5);ds18s20_dq=1;/單總線字節(jié)寫入void

21、 ds18s20writebyte(char val)uchar i;uchar temp;for(i=0;i<8;i+)temp=val>>i;temp&=0x01;ds18s20writebit(temp);ds18s20delay(5);/單總線位讀取uchar ds18s20readbit(void)uchar i;ds18s20_dq=0;ds18s20_dq=1;for(i=0;i<3;i+)return ds18s20_dq;/單總線字節(jié)讀取uchar ds18s20readbyte(void)uchar i;uchar value=0;for(i

22、=0;i<8;i+)if(ds18s20readbit()value|=0x01<<i;ds18s20delay(7);return(value);/實時時鐘復位函數(shù)void resetds1302()ds18s20delay(1);sclk=0;ds18s20delay(1);rstb=0;ds18s20delay(1);rstb=1;ds18s20delay(1);/時鐘字節(jié)讀取函數(shù)uchar readbyteds1302()uchar i;uchar rbyte;uchar tempbyte; rbyte=0x00; i_o=1; ds18s20delay(1); fo

23、r(i=0;i<8;+i) sclk=1; ds18s20delay(1); sclk=0; ds18s20delay(1); tempbyte=(uchar)i_o; tempbyte<<=7; rbyte>>=1; rbyte|=tempbyte; return rbyte; /時鐘字節(jié)寫入函數(shù)void writebyteds1302(uchar w_byte)uchar i;ds18s20delay(1); for(i=0;i<8;+i) i_o=0; if(w_byte&0x01)i_o=1; sclk=0; ds18s20delay(1);

24、 sclk=1; ds18s20delay(1); w_byte>>=1; /時鐘初始化函數(shù)void initds1302()resetds1302();writebyteds1302(0x8e);writebyteds1302(0);resetds1302();writebyteds1302(0x90);writebyteds1302(0xab);resetds1302();writebyteds1302(0xbe);writebyteds1302(0);writebyteds1302(0);writebyteds1302(0);writebyteds1302(0);writeb

25、yteds1302(0);writebyteds1302(0);writebyteds1302(0);writebyteds1302(0);writebyteds1302(0);resetds1302();/時鐘字節(jié)寫入函數(shù)void writeclkbyte(uchar adress,uchar date)adress=(adress*2)|0x80);resetds1302();writebyteds1302(adress);writebyteds1302(date);resetds1302(); /狀態(tài)檢查 ,void CheckState() unsigned char dat; DI=

26、0; RW=1; do GDM12864ADataPort=0x00; EN=1; dat=GDM12864ADataPort; EN=0; dat=0x80 & dat; /僅當?shù)?位為0時才可操作(判別busy信號) while(!(dat=0x00); /向LCD發(fā)送命令/command :命令void SendCommandToLCD(unsigned char command) CheckState(); RW=0; GDM12864ADataPort=command; EN=1; EN=0;/寫顯示數(shù)據(jù)/dat:顯示數(shù)據(jù)void WriteByte(unsigned cha

27、r dat) CheckState(); DI=1; RW=0; GDM12864ADataPort=dat; EN=1; EN=0; /設定行地址(頁)-X 0-7void SetLine(unsigned char line) line=line & 0x07; / 0<=line<=7 line=line|0xb8; /1011 1xxx SendCommandToLCD(line);/設定列地址-Y 0-63void SetColumn(unsigned char column) column=column &0x3f; / 0=<column<

28、=63 感覺多余的,column已近小于64了。 column=column | 0x40; /01xx xxxx SendCommandToLCD(column);/設定顯示開始行-XXvoid SetStartLine(unsigned char startline) /0-63 startline=startline & 0x07; startline=startline|0xc0; /1100 0000 SendCommandToLCD(startline); /開關顯示void SetOnOff(unsigned char onoff)onoff=0x3e | onoff;

29、/0011 111xSendCommandToLCD(onoff);/選擇屏幕/screen: 0-全屏,1-左屏,2-右屏void SelectScreen(unsigned char screen) /cs1: 1-左; cs2: 1-右switch(screen) case 0: cs1=0;/全屏_nop_(); _nop_(); _nop_(); cs2=0; _nop_(); _nop_(); _nop_(); break; case 1: cs1=0;/左屏_nop_(); _nop_(); _nop_(); cs2=1;_nop_(); _nop_(); _nop_(); br

30、eak;case 2: cs1=1;/右屏_nop_(); _nop_(); _nop_(); cs2=0; _nop_(); _nop_(); _nop_(); break;/延時delay(unsigned int t )unsigned int i=t,m,n;for(m=0;m<i;m+)for(n=0;n<100;n+);/清屏/screen: 0-全屏,1-左屏,2-右 ?分屏干嘛,直接全屏不好嗎void ClearScreen(unsigned char screen) unsigned char i,j;SelectScreen(screen);for(i=0;i&

31、lt;8;i+)SetLine(i);for(j=0;j<128;j+)WriteByte(0x00);/初始化LCDvoid InitLCD() unsigned char i=250; /延時while(i-);SelectScreen(0);SetOnOff(0); /關顯示/ClearScreen(0);/清屏SelectScreen(0);SetOnOff(1); /開顯示SelectScreen(0);SetStartLine(0); /開始行:0/8*8漢字顯示函數(shù)void z88(unsigned char lin,unsigned char column,unsigne

32、d char *w, unsigned int address) unsigned char i;if(column>16) return;if(column<8) SelectScreen(1); /如果列數(shù)<8(0,1,2,3,4,5,6,7)則寫在第一屏上 ,每列一個字節(jié)else SelectScreen(2); /否則 (8,9,10,11,12,13,14,15)寫在第二屏上column=column & 0x07; /防止越界 SetLine(lin);SetColumn(column<<3);/colum×8 0-64for(i=0

33、;i<8;i+) WriteByte(waddress+i);/8*16漢字顯示函數(shù)void z816(unsigned char lin,unsigned char column,unsigned char *p,unsigned int m) lin=lin<<1;z88(lin,column,p,m*16);z88(lin+1,column,p,m*16+8);/16×16漢字顯示函數(shù)void z1616(unsigned char lin,unsigned char column,unsigned char *p,unsigned int m) /lin(頁

34、)=16,8格=column(列,不是y),m為第幾個漢字,所有漢字的字模都寫在一個數(shù)組中。lin=lin<<1; /lin*2,一個漢字占兩頁z88(lin,column,p,m*32);z88(lin,column+1,p,m*32+8);z88(lin+1,column,p,m*32+16);z88(lin+1,column+1,p,m*32+24);/單總線溫度讀取void ds18s20readtemperature(void)char temp_lsb,temp_msb;char ctemperature;z1616(1,0,a,0);z1616(1,2,a,1);z1

35、616(1,8,a,9);z816(1,4,b,13);ds18s20reset();ds18s20writebyte(0xcc);ds18s20writebyte(0x44);ds18s20delay(5);ds18s20reset();ds18s20writebyte(0xcc);ds18s20writebyte(0xbe);ds18s20delay(5);temp_lsb=ds18s20readbyte();temp_msb=ds18s20readbyte();if(temp_msb=0)temp_lsb>>=1;z816(1,5,b,16);else z816(1,5,b,

36、15);ctemperature=temp_lsb=(-1)*temp_lsb);temp_lsb>>=1;ctemperature=temp_lsb;ctemperature/=10;z816(1,6,b,ctemperature);temp_lsb%=10;z816(1,7,b,temp_lsb);/時鐘讀秒寄存器uchar dumiaojicunqqi()uchar d;writebyteds1302(0xbf);d=readbyteds1302();resetds1302();return(d); /時鐘寄存器內容顯示函數(shù)void ds1302display()uchar

37、sec,min,hrs,c;z1616(0,0,a,2);z1616(0,2,a,3);z816(0,4,b,13);z816(0,7,b,13);z816(0,10,b,13);resetds1302();writebyteds1302(0xbf);sec=readbyteds1302();c=sec&0x0f;z816(0,12,b,c);c=(sec&0x70);c>>=4;z816(0,11,b,c);min=readbyteds1302();c=min&0x0f;z816(0,9,b,c);c=(min&0x70);c>>=4;

38、z816(0,8,b,c);hrs=readbyteds1302();c=hrs&0x0f;z816(0,6,b,c);c=(hrs&0x30);c>>=4;z816(0,5,b,c);resetds1302();/讀秒的低4位uchar shizhongdumiao()uchar sec;resetds1302();writebyteds1302(0xbf);sec=readbyteds1302();resetds1302();sec&=0x0f;return(sec);/速度float sudu()float a;TR0=0;a=TL0;TL0=0;TR0=1;a*=1.1304;/0.314*3.6km/hreturn(a);/顯示速度void xianshisudu(float e)unsigned int c,d,f;z1616(2,0,a,4);z1616(2,2,a,1);z816(2,4,b,13);z816(2,7,b,14);z816(2,9,b,17);z816(2,10,b,10);z816(2,11,b,12);z816(2,12,b,18);e*=10;f=d=c=e;c/=100;/十位z816(2,5,b,c);d%=100;d/=10

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論