//////////////////////////////////////////////////////////////////////////////////
//本程序只供学习使用,未经作者许可,不得用于其它任何用途
//中景园电子
//店铺地址:http://shop73023976.taobao.com/?spm=2013.1.0.0.M4PqC2
//
// 文 件 名 : main.c
// 版 本 号 : v2.0
// 作 者 : HuangKai
// 生成日期 : 2014-0101
// 最近修改 :
// 功能描述 : OLED IIC接口演示例程(51系列)
// 说明:
// ----------------------------------------------------------------
// GND 电源地
// VCC 接5V或3.3v电源
// D0 P1^0(SCL)
// D1 P1^1(SDA)
// RES 接高
// DC 接地
// CS 接地
// ----------------------------------------------------------------
// 修改历史 :
// 日 期 :
// 作 者 : HuangKai
// 修改内容 : 创建文件
//版权所有,盗版必究。
//Copyright(C) 中景园电子2014/3/16
//All rights reserved
//******************************************************************************/
#include "reg52.h"
#include"ds1302.h"
#include "oled.h"
#include "picture.h"
#include "mpu6050.h"
/*******************************Main*******************************/
unsigned char count=1;
unsigned char START_FLAG=0;
unsigned char number=0;
unsigned char BUF[8];
unsigned char idata bad_flag[3]={0,0,0};
unsigned int idata array0[3]={1,1,1};
unsigned int idata array1[3]={1,1,1};
unsigned int idata array2[3]={0,0,0};
unsigned int idata adresult[3];
unsigned int idata max[3]={0,0,0};
unsigned int idata min[3]={1000,1000,1000};
unsigned int idata dc[3]={500,500,500};
unsigned int idata vpp[3]={30,30,30};
unsigned int idata precision[3]={5,5,5};
unsigned int idata old_fixed[3];
unsigned int idata new_fixed[3];
unsigned int idata STEPS=0;
unsigned char code hanzi[][32]=
{
{0x00,0x20,0x18,0xC7,0x44,0x44,0x44,0x44,0xFC,0x44,0x44,0x44,0x44,0x04,0x00,0x00,
0x04,0x04,0x04,0x07,0x04,0x04,0x04,0x04,0xFF,0x04,0x04,0x04,0x04,0x04,0x04,0x00},/*"年",0*/
{0x00,0x00,0x00,0xFE,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0xFE,0x00,0x00,0x00,
0x80,0x40,0x30,0x0F,0x02,0x02,0x02,0x02,0x02,0x02,0x42,0x82,0x7F,0x00,0x00,0x00},/*"月",1*/
/* (16 X 16 , 宋体 )*/
{0x00,0x00,0x00,0xFE,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0xFE,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0xFF,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0xFF,0x00,0x00,0x00,0x00},/*"日",2*/
/* (16 X 16 , 宋体 )*/
{0x00,0x00,0x00,0xBE,0x2A,0x2A,0x2A,0xEA,0x2A,0x2A,0x2A,0x3E,0x00,0x00,0x00,0x00,
0x00,0x44,0x42,0x49,0x49,0x49,0x49,0x7F,0x49,0x49,0x49,0x49,0x41,0x40,0x00,0x00},/*"星",3*/
/* (16 X 16 , 宋体 )*/
{0x00,0x04,0xFF,0x24,0x24,0x24,0xFF,0x04,0x00,0xFE,0x22,0x22,0x22,0xFE,0x00,0x00,
0x88,0x48,0x2F,0x09,0x09,0x19,0xAF,0x48,0x30,0x0F,0x02,0x42,0x82,0x7F,0x00,0x00},/*"期",4*/
/* (16 X 16 , 宋体 )*/
{0x40,0x40,0x40,0x7C,0x40,0x40,0x40,0xFF,0x44,0x44,0x44,0x44,0x44,0x40,0x40,0x00,
0x80,0x90,0x88,0x46,0x40,0x40,0x20,0x2F,0x10,0x10,0x08,0x04,0x02,0x00,0x00,0x00},/*"步",5*/
/* (16 X 16 , 宋体 )*/
{0x90,0x52,0x34,0x10,0xFF,0x10,0x34,0x52,0x80,0x70,0x8F,0x08,0x08,0xF8,0x08,0x00,
0x82,0x9A,0x56,0x63,0x22,0x52,0x8E,0x00,0x80,0x40,0x33,0x0C,0x33,0x40,0x80,0x00}/*"数",6*/
/* (16 X 16 , 宋体 )*/
};
unsigned char code week[][32] =
{
{0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"一",0*/
{0x00,0x00,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x00,0x00,0x00,
0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x00},/*"二",0*/
{0x00,0x04,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x04,0x00,0x00,
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x00},/*"三",0*/
/* (16 X 16 , 宋体 )*/
{0x00,0xFC,0x04,0x04,0x04,0xFC,0x04,0x04,0x04,0xFC,0x04,0x04,0x04,0xFC,0x00,0x00,
0x00,0x7F,0x28,0x24,0x23,0x20,0x20,0x20,0x20,0x21,0x22,0x22,0x22,0x7F,0x00,0x00},/*"四",0*/
/* (16 X 16 , 宋体 )*/
{0x00,0x02,0x42,0x42,0x42,0xC2,0x7E,0x42,0x42,0x42,0x42,0xC2,0x02,0x02,0x00,0x00,
0x40,0x40,0x40,0x40,0x78,0x47,0x40,0x40,0x40,0x40,0x40,0x7F,0x40,0x40,0x40,0x00},/*"五",0*/
/* (16 X 16 , 宋体 )*/
{0x20,0x20,0x20,0x20,0x20,0x20,0x21,0x22,0x2C,0x20,0x20,0x20,0x20,0x20,0x20,0x00,
0x00,0x40,0x20,0x10,0x0C,0x03,0x00,0x00,0x00,0x01,0x02,0x04,0x18,0x60,0x00,0x00},/*"六",0*/
/* (16 X 16 , 宋体 )*/
{0x00,0x00,0x00,0xFE,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0xFE,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0xFF,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0xFF,0x00,0x00,0x00,0x00}/*"日",0*/
/* (16 X 16 , 宋体 )*/
/* (16 X 16 , 宋体 )*/
};
unsigned char code fuhao[]={0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00} ;
unsigned char code Time_data[][16]={
{0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00},/*"0",0*/
/* (8 X 16 , 宋体 )*/
{0x00,0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00},/*"1",0*/
/* (8 X 16 , 宋体 )*/
{0x00,0x70,0x08,0x08,0x08,0x08,0xF0,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00},/*"2",0*/
/* (8 X 16 , 宋体 )*/
{0x00,0x30,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x18,0x20,0x21,0x21,0x22,0x1C,0x00},/*"3",0*/
/* (8 X 16 , 宋体 )*/
{0x00,0x00,0x80,0x40,0x30,0xF8,0x00,0x00,0x00,0x06,0x05,0x24,0x24,0x3F,0x24,0x24},/*"4",0*/
/* (8 X 16 , 宋体 )*/
{0x00,0xF8,0x88,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x20,0x20,0x20,0x11,0x0E,0x00},/*"5",0*/
/* (8 X 16 , 宋体 )*/
{0x00,0xE0,0x10,0x88,0x88,0x90,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x20,0x1F,0x00},/*"6",0*/
/* (8 X 16 , 宋体 )*/
{0x00,0x18,0x08,0x08,0x88,0x68,0x18,0x00,0x00,0x00,0x00,0x3E,0x01,0x00,0x00,0x00},/*"7",0*/
/* (8 X 16 , 宋体 )*/
{0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00},/*"8",0*/
/* (8 X 16 , 宋体 )*/
{0x00,0xF0,0x08,0x08,0x08,0x10,0xE0,0x00,0x00,0x01,0x12,0x22,0x22,0x11,0x0F,0x00}/*"9",0*/
/* (8 X 16 , 宋体 )*/
};
void display();
void delayms(int k) //k单位为毫秒
{
int i,j;
for(i=k;i>0;i--)
for(j=110;j>0;j--) ;
}
void Delay5ms()
{
unsigned int n = 400;
while (n--);
}
void Multiple_read_ADXL345(void)
{
unsigned char i;
I2C_Start(); //起始信号
I2C_SendByte(SlaveAddress); //发送设备地址+写信号
I2C_SendByte(0x3B); //发送存储单元地址,从0开始
I2C_Start(); //起始信号
I2C_SendByte(SlaveAddress+1); //发送设备地址+读信号
for (i=0; i<6; i++) //连续读取6个地址数据,存储中BUF
{
//BUF[i] = I2C_RecvByte(); //BUF[0]存储0x32地址中的数据
BUF[i] = Single_ReadI2C(ACCEL_XOUT_H + i);
if (i == 5)
I2C_SendACK(1); //最后一个数据需要回NOACK
else
I2C_SendACK(0); //回应ACK
}
I2C_Stop(); //停止信号
Delay5ms();
//delayms(3);
}
void DisplayTime()
{
Ds1302ReadTime();
hanzi_8(0,0,Time_data[2]);
hanzi_8(0,1,Time_data[0]);
hanzi_8(0,2,Time_data[TIME[6]/16]);
hanzi_8(0,3,Time_data[TIME[6]&0x0f]);
hanzi_16(0,2,hanzi[0]); //年
hanzi_8(0,6,Time_data[TIME[4]/16]);
hanzi_8(0,7,Time_data[TIME[4]&0x0f]);
hanzi_16(0,4,hanzi[1]); //月
hanzi_8(0,10,Time_data[TIME[3]/16]);
hanzi_8(0,11,Time_data[TIME[3]&0x0f]);
hanzi_16(0,6,hanzi[2]); //日
hanzi_16(1,0,hanzi[3]);
hanzi_16(1,1,hanzi[4]);
hanzi_16(1,2,week[TIME[5]&0x07]);
hanzi_8(1,6,Time_data[TIME[2]/16]);
hanzi_8(1,7,Time_data[TIME[2]&0x0f]);
hanzi_8(1,8,fuhao);
hanzi_8(1,9,Time_data[TIME[1]/16]);
hanzi_8(1,10,Time_data[TIME[1]&0x0f]);
hanzi_8(1,11,fuhao);
hanzi_8(1,12,Time_data[TIME[0]/16]);
hanzi_8(1,13,Time_data[TIME[0]&0x0f]);
}
void open_mpu6050()
{
delay(500); //上电延时
InitMPU6050(); //初始化MPU6050
delay(150);
}
/*void walk_count()
{
char