ad7705函数

  • 格式:txt
  • 大小:5.38 KB
  • 文档页数:2
void init_tm7705(void);
void reset_tm7705(void);
void init_led()
{
DDRC = 0XFF; //1111 1111 1时输出,0时输入
PORTC = 0;
DDRB |= 0X07; //0000 0111
PORTB = 0;
#define LED_2 PORTB|=0X07,PORTB&=0XF9 //译码器的输入脚,001选择第二位数码管。
#define LED_3 PORTB|=0X07,PORTB&=0XFA //同上类推
#define LED_4 PORTB|=0X07,PORTB&=0XFB
// write_tm7705_byte( 0xc0 ); //满标度系统校准 1100 0100
_delay_ms(2);
}
int main(void)
{
init_led();
init_tm7705();
while(1)
{
read_tm7705_word();
ch2_dat[1] = data1 / 10000;
ch2_dat[2] = data1 % 10000 / 1000;
ch2_dat[3] = data1 % 10000 % 1000 / 100;
ch2_dat[4] = data1 % 10000 % 1000 % 100 / 10;
SCLK_H;asm("nop");asm("nop");asm("nop");
}
//CLOCK寄存器设置
while(DRDY);
write_tm7705_byte( 0x21 ); //下次设置时钟寄存器,通道2 0010 0001
write_tm7705_byte( 0x0b); //2分频,200Hz输出更新速率 0000 1011
{
if ( adc_dat[q]>adc_dat[q+1] ) //从大到小排列
{
temp = adc_dat[q];
adc_dat[q] = adc_dat[q+1];
adc_dat[q+1] = temp;
}
}
}
//写设置寄存器
while(DRDY);
write_tm7705_byte( 0x11 ); //通道2正常模式下次写入设置寄存器 0001 0001
write_tm7705_byte( 0x40 ); //增益1,双极性,不带缓冲,自校准 0100 0010
// while(DRDY);
{
SCLK_H;
for(unsigned char i=0; i<8; i++)
{
if(data & 0x80)
DIN_H;
else
DIN_L;
SCLK_L;_delay_us(100);
SCLK_H;_delay_us(10);
data <<= 1;
unsigned int adc_dat[5] = {0,0,0,0,0};
for(j=0;j<5;j++)
{
write_tm7705_byte( 0x21 );
write_tm7705_byte( 0x0b);
write_tm7705_byte( 0x11 );
//#define CS_H PORTA |= 0X20 //单片机输出数据信号 PA5 0010 0000
//#define CS_L PORTA &= 0XDF // PA5 1101 1111
#define DOUT PINA & 0X04 // PA2 0000 0100
DDRA &= 0XF9; //1111 1001
RESET_H;
RESET_L;
_delay_ms(2);
RESET_H;
unsigned char i;
for( i=0; i<36; i++ )
{
SCLK_L;asm("nop");asm("nop");asm("nop");
unsigned char ch2_dat[6] = {0,0,0,0,0,0};
void init_led();
void show_led(unsigned char wei,unsigned char dat);
void read_tm7705_byte(void);
void write_tm7705_byte(unsigned char data);
break;
case 4:
LED_4;
PORTC = pgm_read_byte(table+dat);_delay_ms(i);
break;
case 5:
LED_5;
PORTC = pgm_read_byte(table+dat);_delay_ms(i);
#define DIN_L PORTA &= 0XF7 // PA3 1111 0111
#define RESET_H PORTA |= 0X10 //单片机输出数据信号 PA4 0001 0000
#define RESET_L PORTA &= 0XEF // PA4 1110 1111
data0 = adc_dat[2];
temp1 = data0;
if(temp1 > 32768) { adc = 2.491 - 2.491*data0/65536;ch2_dat[0] = 1;}
else adc = 2.491*data0/65536;
data1 = (int)(adc * 10000);
#define DRDY !(PINA & 0X02) // PA1 0000 0010
const prog_uchar table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x80,0x40};//共阴数码管段值表 0-9,.,-
}
DIN_H;
}
void read_tm7705_word(void)
{
unsigned int data0 = 0 ,data1 = 0 ,temp = 0 ,temp1 = 0;
unsigned char i,j,p,q;
float adc = 0;
break;
case 6:
LED_6;
PORTC = pgm_read_byte(table+dat);_delay_ms(i);
break;
case 7:
LED_7;
PORTC = pgm_read_byte(table+dat);_delay_ms(i);
#define LED_5 PORTB|=0X07,PORTB&=0XFC
#define LED_6 PORTB|=0X07,PORTB&=0XFD
#define LED_7 PORTB|=0X07,PORTB&=0XFE
#define LED_8 PORTB|=0X07
//sclk PA0输出 drdy PA1输入 dout PA2输入 din PA3输出 reset PA4输出 cs PA5输出
//写设置寄存器
// write_tm7705_byte( 0x11 ); //通道2正常模式, 0000 0001
// write_tm7705_byte( 0x84 ); //零标度系统校准 1000 0100
// while(DRDY);
//写设置寄存器
// write_tm7705_byte( 0x11 ); //通道2正常模式, 0000 0011
break;
case 2:
LED_2;
PORTC = pgm_read_byte(table+dat);_delay_ms(i);
break;
case 3:
LED_3;
PORTC = pgm_read_byte(table+dat);_delay_ms(i);
show_led(7,ch2_dat[4]);
show_led(8,ch2_dat[5]);
break;
case 8:
LED_8;
PORTC = pgm_read_byte(table+dat);_delay_ms(i);
break;
default: PORTC = 0;
}
}
void write_tm7705_byte(unsigned char data)
SCLK_H; _delay_us(10);
if(DOUT) data0 ++;
data0 <<= 1;
}
DIN_H;
adc_dat[j+1] = data0;
}
for (p=0;p<4;p++)
{
for (q=0;q<4-p;q++)
#include <avr/io.h>
#include <avr/pgmspace.h>

下载文档原格式

  / 2