当前位置:文档之家› 数据采集系统软件编程

数据采集系统软件编程

asm nop
while( ( CRGFLG & 0x08 ) ==0 ) ; //等待锁相环锁相稳定
CLKSEL &= 0x7F ; //将频率信号设置为PLL
CLKSEL |=0x80 ;
}
void Init_PORT() {
DDRA=0x0F;//低四位输出
/*Ports ABEK, BKGD pin Pull-up Control Register (PUCR)的各位
}
Keynumber=Keynumber+i*ColumnSize;
Keyvalue=KeyDecode[Keynumber];
while((PORTA>>4)!=0x0F) Show();
}
else Output<<=1;
}
}
}
return(Keyvalue);
}
void ATD_init(void) {
{
PTP=DisplayDecode[showdata[DisplayNumber]];
if(DisplayNumber==2) PTP&=0x7f;
PTT=showcon[DisplayNumber];
delay(1);
}
}
unsigned char KeyScan()
{
unsigned char Output,Keynumber,Keyvalue;
7 PUPKE
6 BKPUE
5 0
4 PUPEE
3 0
2 0
1 PUPBE
0 PUPAE
*/
PUCR|=0x01; //A口上拉电阻使能பைடு நூலகம்
DDRP=0xFF;
DDRT=0xFF;
}
unsigned char ADresult;
void delay(unsigned int countert)
{
unsigned int i,j;
~0x6f,~0x77,~0x7c,~0x39,~0x5e,~0x79,~0x71,~0x40};
const unsigned char KeyDecode[]={ 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x00,0x0a,0x0b,
0x0c,0x0d,0x0e,0x0f};
{
uchar i;
for(i = 0; i < 8;i++)
{
DQ0();
DelayNus(6); //延时6us
if(wdata & 0X01)
{
DQin();
}
else
{
DQ0();
}
wdata >>= 1;
DelayNus(50); //延时50us
DQin();
DelayNus(10); //延时10us
DelayNus(500);
DQin(); // DDRJ &= 0XFE
DelayNus(55);
if(DQ==1)
{
Error = 1; //初始化失败
}
else
{
Error = 0; //初始化成功
}
DelayNus(400);
// PORTB=Error;
return Error;
}
void Write_18B20(uchar wdata)
DelayNus(55); //延时55us
}
return temp;
}
/*------------------------------------------------
读取温度
------------------------------------------------*/
unsigned int ReadTemperature(void)
i7=(t&0x40)>>6;
i8=(t&0x80)>>7;
sum=i1*1+i2*2+i3*4+i4*8+i5*16+i6*32+i7*64+i8*128;
return(sum);
}
uchar Init_18B20(void)
{
uchar Error;
DQ0(); //DDRJ |= 0X01;PTJ_PTJ0 = 0
unsigned char i;
Keyvalue=0xFF;
Output=0xF0;
PORTA=Output;
if((PORTA>>4)!=0x0F)
{
Show();
if((PORTA>>4)!=0x0F)
{
Output=0x01;
for(i=0;i<RowSize;i++)
{
PORTA=~Output;
if((PORTA>>4)!=0x0F)
{
switch((PORTA>>4))
{
case 0x0E:
Keynumber=0;
break;
case 0x0D:
Keynumber=1;
break;
case 0x0B:
Keynumber=2;
break;
case 0x07:
Keynumber=3;
break;
{
unsigned int a=0;
unsigned int b=0;
unsigned int t=0;
unsigned char i=0;
Init_18B20() ;
i=Init_18B20() ;
while(i);
Write_18B20(0xCC); //跳过读序号列号的操作
Write_18B20(0x44); //启动温度转换
}
unsigned char TTD (char t)
{
char i1,i2,i3,i4,i5,i6,i7,i8;
int sum;
i1=t&0x01;
i2=(t&0x02)>>1;
i3=(t&0x04)>>2;
i4=(t&0x08)>>3;
i5=(t&0x10)>>4;
i6=(t&0x20)>>5;
for(i=0;i<countert;i++)
for(j=0;j<4000;) j++;
}
void DelayNus( int time )
{
volatile unsigned int i, j ;
for( i = 0; i < time; i ++ )
{
for( j = 0; j < 10; j ++ )
temp+=1;
}
tempH=temp>>4;
tempL=temp&0x000f;
tempH=TTD(tempH) ;
tempL=TTD(tempL) ;
//PORTB= tempL;
d3= tempH/10;
d2= tempH%10;
d1= (tempL*100/16)/10;
d0= (tempL*100/16)%10;
showdata[0]=result0;
showdata[1]= result1;
showdata[2]=0;
showdata[3]=0;
Show();
}
while(keyresult!=0x0D);
}
/*else if (keyresult==0x0D)
{ temp= ReadTemperature();
}
}
uchar Read_18B20(void)
{
uchar i;
uchar temp = 0;
for(i = 0;i < 8;i++)
{
temp >>= 1;
DQ0();
DelayNus(2); //延时2us
DQin();
DelayNus(13); //延时13us
if(DQ==1) temp |= 0x80;
Init_PORT();
EnableInterrupts;
ATD_init();
DDRB=0xFF;
showdata[0]=16;
showdata[1]=16;
showdata[2]=16;
showdata[3]=16;
temp= ReadTemperature();
if(temp&0x8000)
{temp=~temp;
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
#define RowSize 4
#define ColumnSize 4
#define DQ PTJ_PTJ0
d0= (tempL*100/16)%10;
showdata[0]=d0;
showdata[1]=d1;
showdata[2]=d2;
showdata[3]=d3;
do
{
Show();
}
while(keyresult!=0x0F);
相关主题