|
首先,希望管理員賞我些黑幣 ,快21年電賽了,想能多下載寫資料
話不多說
下面是我分享的MAX30100心率血氧模塊
單片機源程序如下:
- # include <reg52.h>
- # include <stdio.h>
- # include <intrins.h>
- //??IIC??
- sbit IIC_SCL =P3^5; //IIC?SCL
- sbit IIC_SDA =P3^7; //IIC?SDA
- bit IIC_ACK; //IIC?ACK
- int rda; //IIC??
- //-------------------------------------------------------------------------------------//
- //??: delayms()
- //??: ????
- //-------------------------------------------------------------------------------------//
- void delayms(unsigned int ms)
- {
- unsigned char i=100,j;
- for(;ms;ms--)
- {
- while(--i)
- {
- j=10;
- while(--j);
- }
- }
- }
- //-------------------------------------------------------------------------------------//
- //??: void iic_start();
- //??: I2C????
- //-------------------------------------------------------------------------------------//
- // SCL --- --- ___
- // SDA --- ___ ___
- void iic_start()
- {
- IIC_SDA=1;
- _nop_();
- _nop_();
- IIC_SCL=1;
- _nop_();
- _nop_();
- IIC_SDA=0;
- _nop_();
- _nop_();
- IIC_SCL=0;
- _nop_();
- _nop_();
- }
- //-------------------------------------------------------------------------------------//
- //??: void iic_stop();
- //??: I2C????
- //???:
- //-------------------------------------------------------------------------------------//
- // SCL ___ --- ---
- // SDA ___ ___ ---
- void iic_stop()
- {
- IIC_SCL=0;
- _nop_();
- _nop_();
- IIC_SDA=0;
- _nop_();
- _nop_();
- IIC_SCL=1;
- _nop_();
- _nop_();
- IIC_SDA=1;
- _nop_();
- _nop_();
- }
- //-------------------------------------------------------------------------------------//
- //??: void iic_sendbyte(unsigned char c);
- //??: ?? 8_BIT ??
- //-------------------------------------------------------------------------------------//
- void iic_sendbyte(unsigned char c)
- {
- unsigned char bitcnt;
- for(bitcnt=0;bitcnt<8;bitcnt++)
- {
- if((c<<bitcnt)&0x80)
- IIC_SDA=1;
- else
- IIC_SDA=0;
- _nop_();
- _nop_();
- IIC_SCL=1;
- _nop_();
- _nop_();
- IIC_SCL=0;
- }
- _nop_();
- _nop_();
- IIC_SDA=1;
- _nop_();
- _nop_();
- IIC_SCL=1;
- _nop_();
- _nop_();
- if(IIC_SDA==0)
- IIC_ACK=0;
- else
- IIC_ACK=1;
- IIC_SCL=0;
- _nop_();
- _nop_();
- }
- //-------------------------------------------------------------------------------------//
- //??: int iic_rcvbyte_nack();
- //??: ?? 8_BIT ?? ??ack??
- //-------------------------------------------------------------------------------------//
- int iic_rcvbyte_nack()
- {
- unsigned char retc;
- unsigned char bitcnt;
- retc=0;
- IIC_SDA=1;
- for(bitcnt=0;bitcnt<8;bitcnt++)
- {
- _nop_();
- _nop_();
- IIC_SCL=0;
- _nop_();
- _nop_();
- IIC_SCL=1;
- _nop_();
- _nop_();
- retc=retc<<1;
- if(IIC_SDA==1)
- retc=retc+1;
- _nop_();
- _nop_();
- }
- //??NACK??
- _nop_();
- _nop_();
- IIC_SCL=0;
- _nop_();
- _nop_();
- IIC_SDA=1;
- _nop_();
- _nop_();
- IIC_SCL=1;
- _nop_();
- _nop_();
- IIC_SCL=0;
- _nop_();
- _nop_();
- return(retc);
- }
- //-------------------------------------------------------------------------------------//
- //??: int iic_rcvbyte_ack();
- //??: ?? 8_BIT ?? ??ack??
- //-------------------------------------------------------------------------------------//
- int iic_rcvbyte_ack()
- {
- unsigned char retc;
- unsigned char bitcnt;
- retc=0;
- IIC_SDA=1;
- for(bitcnt=0;bitcnt<8;bitcnt++)
- {
- _nop_();
- _nop_();
- IIC_SCL=0;
- _nop_();
- _nop_();
- IIC_SCL=1;
- _nop_();
- _nop_();
- retc=retc<<1;
- if(IIC_SDA==1)
- retc=retc+1;
- _nop_();
- _nop_();
- }
- //??ACK??
- _nop_();
- _nop_();
- IIC_SCL=0;
- _nop_();
- _nop_();
- IIC_SDA=0;
- _nop_();
- _nop_();
- IIC_SCL=1;
- _nop_();
- _nop_();
- IIC_SCL=0;
- _nop_();
- _nop_();
- return(retc);
- }
- //-------------------------------------------------------------------------------------//
- //??: wr_max30100_one_data()
- //??: ???max30100??
- //address: ?????
- //saddress: ??????
- //w_data: ????
- //-------------------------------------------------------------------------------------//
- void wr_max30100_one_data(int address,int saddress,int w_data )
- {
- _nop_();
- iic_start();
- _nop_();
- iic_sendbyte(address);
- _nop_();
- iic_sendbyte(saddress);
- _nop_();
- iic_sendbyte(w_data);
- _nop_();
- iic_stop();
- _nop_();
- }
- //-------------------------------------------------------------------------------------//
- //??: rd_max30100_one_data()
- //??: ???max30100??
- //address: ?????
- //saddress: ??????
- //rda: ?????
- //-------------------------------------------------------------------------------------//
- void rd_max30100_one_data(int address,int saddress)
- {
- iic_start();
- _nop_();
- iic_sendbyte(address);
- _nop_();
- iic_sendbyte(saddress);
- _nop_();
- address=address+1;
- _nop_();
- iic_start();
- _nop_();
- iic_sendbyte(address);
- _nop_();
- rda=iic_rcvbyte_nack();
- _nop_();
- iic_stop();
- }
- //-------------------------------------------------------------------------------------//
- //??: ???
- //??: ?max30100????
- //-------------------------------------------------------------------------------------//
- main()
- {
- double temp,temp1,temp2;
- //temp ????
- //temp1 30100??????
- //temp2 30100??????
- TMOD=0x21;
- SCON=0x50;
- TH1=0xFD;
- TL1=0xFD;
- TR1=1;
- TI=1;
- //??51????? 9600 N 8 1
- //51???11.0592MHz
- while(1)
- {
- wr_max30100_one_data(0xae,0x06,0x0a); // 0X06??B3?TEMP_EN?1
- delayms(20); // ????????,???,??????
- rd_max30100_one_data(0xae,0x16); // ??????
- printf("temp1=%d\n",rda); // ????
- temp1=rda;
- rd_max30100_one_data(0xae,0x17); // ??????????
- printf("temp2=%d\n",rda); // ????
- temp2=rda;
- temp=temp1+(temp2/100);
- printf("temp=%.2f\n",temp); // ????
- rd_max30100_one_data(0xae,0xff); // ????ID
- printf("MAX30100 ID =%d\n",rda); // ????
- delayms(100);
- }
- }
復制代碼
|
評分
-
查看全部評分
|