求助!!单片机实现DA转换功能以及各项传感器数据读取

这是我的代码,编译没有错误,但是在89C52单片机上无法正常运行,求大神帮忙指导,谢谢!!
#include “reg52.h” //定义51单片机特殊功能寄存器
#include “i2c.h” //I2C总线驱动库
#include “absacc.h”
#include “onewire.h” //单总线函数库
unsigned char dspbuf[8] = {10,10,10,10,10,10,0,0};//显示缓冲区
unsigned char dspcom = 0;
unsigned char intr;
bit temper_flag = 0;//温度读取标志
code unsigned char tab[] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,
0xff};
#define VREF 4700 //PCF8591参考电压
void display(void);
bit key_re;
unsigned char key_press;
unsigned char key_value;

bit key_flag;
unsigned char read_key(void);
bit adc_flag;
void program1();
void program2();
void program3();
void program4();
void main(void)
{ unsigned char key_temp;
TMOD |= 0x01; //配置定时器工作模式
TH0 = (65536-2000)/256;
TL0 = (65536-2000)%256;
EA = 1;
ET0 = 1; //打开定时器中断
TR0 = 1; //启动定时器
while(1)
{
if(key_flag)
{
key_flag = 0;
key_temp = read_key();
}
//进入按键处理程序部分
switch(key_temp)
{
case 1:
program1();
break;
case 2:
program2();
break;
case 3:
program3();
break;
case 4:
program4();
break;
}
key_temp = 0; //完成按键处理程序后,清除键值

}

}
void program1()
{
unsigned char dac_value; //DAC转换数据
unsigned int Vaout; //输出电压
dac_value=10;
dac_pcf8591(dac_value);
Vaout = VREF/255*dac_value;
//显示数据更新
dspbuf[4] = Vaout/1000; //熄灭
dspbuf[5] = Vaout%1000/100;
dspbuf[6] = Vaout%100/10;
dspbuf[7] = Vaout%10;
}
void program2()
{
unsigned char adc_value; //ADC转换数据

	P1 &= 0x7f;
	init_pcf8591();
	if(adc_flag)
	{
		adc_flag = 0;  //清除ADC扫描标志位 
		adc_value = adc_pcf8591();
		//更新显示数据
		dspbuf[5] = adc_value/100;       
		dspbuf[6] = adc_value%100/10;       
		dspbuf[7] = adc_value%10; 
	}

}
void program3()
{

}
void program4()
{
unsigned char temperature;
if(temper_flag)
{
temper_flag = 0;
temperature = rd_temperature(); //读温度
}

	//显示数据更新    
	dspbuf[6] = temperature/10;       
	dspbuf[7] = temperature%10; 

}
void display(void)
{
XBYTE[0xE000] = 0xff; //消隐

XBYTE[0xC000] = (1<

}
void isr_timer_0(void) interrupt 1 //默认中断优先级 1
{
TH0 = (65536-2000)/256;
TL0 = (65536-2000)%256; //定时器重载
display();
if(++intr == 10)
{
intr = 0;
adc_flag = 1;
}
}
unsigned char read_key(void)
{

unsigned char key_temp;

key_temp = (P3&0x0f);

if(key_temp != 0x0f) //有按键按下
    key_press++;
else
	key_press = 0;  //抖动

if(key_press == 5)
{
	key_press = 0;
	key_re = 1;
	switch(key_temp)
    {
        case 0x0e:
            key_value = 1;  //S1
            break;                
        case 0x0d:
            key_value = 2;  //S5
            break;    
        case 0x0b:
            key_value = 3;  //S9
            break;    
        case 0x07:
            key_value = 4;  //S13
            break;
    }
}
//连续三次检测到按键被按下,并且该按键已经释放
if((key_re == 1) && (key_temp == 0x0f))
{
    key_re = 0;
    return key_value;
}
return 0xff;

}

你可能感兴趣的:(单片机)