毕业设计自行车测速仪

2019-01-12 17:27

#include #include #include

#define GDM12864ADataPort P1 //LCD数据线 #define uchar unsigned char

sbit DI=P2^2; // 数据\\指令 选择 sbit RW=P2^1; // 读\\写 选择 sbit EN=P2^0; // 读\\写使能 sbit cs1=P2^4; // 片选1 sbit cs2=P2^3; // 片选2 sbit sclk=P2^5; sbit i_o=P2^6; sbit rstb=P2^7;

sbit ds18s20_dq=P3^6; sbit I2C_SCK=P3^3; sbit I2C_SDA=P3^5;

uchar qq=0,pp=0;//开始/暂停按键,计算机传输过来的数据为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,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,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,0x61,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,0x49,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,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,0x00, 0x00,0x00,0x00,0xFF,0x00,0x00,0x02,0x0B,0x12,0x62,0xD2,0x0A,0x06,0x02,0x00,0x00 };

uchar code b[]={//8*16

0x00,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,0x00,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,0x08,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,0x00, 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,0x0C,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,0x00,0x00,0x3F,0x06,0x09,0x10,0x20,0x00,0x00,//17,k 0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0x02,0x02,0x02,0x3E,0x00,0x00//18,h };

//延时程序,延时10us void Delay_10_uS(void) {

char i=10; while(i--); }

//n mS delay

void Delay_N_mS( unsigned int n_milisecond) /* n mS delay */ {

unsigned char i;

while(n_milisecond--) { i=37; while(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(); 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(); }

//如果发送完成并且在第9个脉冲处得到ack,那么返回0,表示成功 bit I2C_Send_Byte( unsigned char d) {

unsigned char i = 8; bit bit_ack; while( i-- ) {

Delay_10_uS();

if ( d &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位数据

unsigned char I2C_Receive_Byte(void) {

unsigned char i = 8, d; Delay_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/256 ); I2C_Send_Byte( AT24C64_address %6 );

I2C_Send_Byte( *(unsigned char*)mcu_address ); I2C_Stop();

Delay_N_mS(10);

((unsigned char*)mcu_address)++; AT24C64_address++; } }

//读EEPROM函数

void AT24C64_R(void *mcu_address,unsigned int AT24C64_address,unsigned int count) {

while(count--) {

I2C_Start();

I2C_Send_Byte( 0xa0 );

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

//单总线复位

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; else

ds18s20_dq=0; ds18s20delay(5);


毕业设计自行车测速仪.doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:分析化学教案首页(A4)

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: