📄 da8751.txt
字号:
//这些函数用于操作ADS1110。程序工作原理与spi是一样的。与spi不同的是启动i2c
//开始读取采集到的数据是由定时器中断完成的。a/d芯片完成一次采集大约需要60多ms
//因此定时器中断必须大于这个值。
//***************FileName:Compare.C***************//
//***************ICCAVR V6.30编译*****************//
#include <iom16v.h>
#include <macros.h>
#define YES 0
#define SLA_W 0x98
#define I2CONTROL 0x10 //连续转换,15sps
#define uchar unsigned char
#define uint unsigned int
uint k;
//数码管字型表,对应0,1,2,3,4,5,6,7,8,9//
uchar Table[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uchar Data[4]={0,0,0,2}; //显示初始值:0 0 0 0
uint u=26384;
void DelayMs(uint i ) //Ms级延时,参数i为延时时间
{uint j;
for(;i!=0;i--)
{for(j=1142;j!=0;j--) {;}} //原来8000,改为1142//
}
//unsigned char Flag,Key;
void Display(uchar *p) //动态显示函数,参数p为待显示的数组名
{uint i,sel=0xff7f;
for(i=0;i<4;i++)
{PORTC=sel; //选通最右边的数码管
PORTA=Table[p[i]]; //送字型码
DelayMs(2); //显示延时
sel=sel>>1; //移位以显示前一位
}
}
void port_init()
{PORTA=0Xff; //all out
DDRA=0Xff;
PORTC=0Xff;
DDRC=0Xff;
}
/*void i2c_init(void)
{
TWCR= 0X00; //disable twi
TWBR= 0x0B; //set bit rate
TWSR= 0x00; //set prescale
}*/
void error(unsigned char err)
{//unsigned char er[]={"错误:"};
//LcdLineDis(0x91,"0错误:");
}
//ADS1110芯片初始化。对这个芯片工作方式的一些配置。配置为单次转化模式。
/*void DA8751_init(void)
{
TWCR=(1<<TWINT)|(1<<TWSTA)|(1<<TWEN);
while(!(TWCR&(1<<TWINT)));
if((TWSR&0XF8)!=0X08)error(0X08);
TWDR=SLA_W;
TWCR=(1<<TWINT)|(1<<TWEN);
while(!(TWCR&(1<<TWINT)));
if((TWSR&0XF8)!=0X18)error(0X18);
TWDR=I2CONTROL;
TWCR=(1<<TWINT)|(1<<TWEN);
while(!(TWCR&(1<<TWINT)));
if((TWSR&0XF8)!=0X28)error(0X28);
TWCR=(1<<TWINT)|(1<<TWEN)|(1<<TWSTO);
}*/
void FS(void)
{
TWCR=(1<<TWINT)|(1<<TWSTA)|(1<<TWEN);
while(!(TWCR&(1<<TWINT)));
if((TWSR&0XF8)!=0X08)error(0X08);
TWDR=SLA_W;
TWCR=(1<<TWINT)|(1<<TWEN);
while(!(TWCR&(1<<TWINT)));
if((TWSR&0XF8)!=0X18)error(0X18);
TWDR=I2CONTROL;
TWCR=(1<<TWINT)|(1<<TWEN);
while(!(TWCR&(1<<TWINT)));
if((TWSR&0XF8)!=0X28)error(0X28);
TWDR=u>>8;
TWCR=(1<<TWINT)|(1<<TWEN);
while(!(TWCR&(1<<TWINT)));
if((TWSR&0XF8)!=0X28)error(0X28);
TWDR=u&0x00ff;
TWCR=(1<<TWINT)|(1<<TWEN);
while(!(TWCR&(1<<TWINT)));
if((TWSR&0XF8)!=0X28)error(0X28);
TWCR=(1<<TWINT)|(1<<TWEN)|(1<<TWSTO);
}
main(void)
{
port_init();
//DA8751_init();
while(1)
{
FS();
//SEI();
//if(ADInputNew == YES)
//{
//ADInputNew_no;
//data = I2cData.ReceiveData; //读取接收到的数据
//}
Display(Data);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -