//如题,我找了个现成的程序,但KEIL编译通不过,那位大侠能帮忙看下?程序如下:
#include "reg52.h"
#include "intrins.h"
#define pcf8591_write 0x90 //pcf8591在IIC中的地址
#define pcf8591_read 0x91
#define delaynop() _nop_();_nop_();_nop_();_nop_();
#define lcd_on 63
#define lcd_off 62
#define page 184
#define x_position 64
unsigned char receive;
sbit SDA=P1^1;
sbit SCL=P1^0;
sbit d_i=P2^4;
sbit r_w=P2^5;
sbit e =P2^6;
sbit cs1=P2^1;
sbit cs2=P2^2;
sbit rst=P2^3;
void delay(unsigned char times)
{
unsigned i=920;
while(times--)while(i--);
}
void checkack(void)//查检对方应答
{ SDA=1; SCL=1; delaynop(); SCL=0;}//if(SDA==1); F0=1; }
void i2cstart() //开始IIC
{ SDA=1; SCL=1; delaynop(); SDA=0; delaynop(); SCL=0;}
void i2c_w_byte(unsigned char com)//写一个字节
{
unsigned char n=8;
while(n--)
{
if((com&0x80)==0x80)SDA=1;else SDA=0;
SCL=1;
delaynop();
SCL=0;
com<<=1;
}
checkack();
}
unsigned char i2c_r_byte(void)//读一个字节
{
unsigned char n=8,read_data;
while(n--)
{
SDA=1;
SCL=1;
delaynop();
read_data<<=1;
if(SDA)read_data|=0x01;
SCL=0;
}
return read_data;
}
void i2c_mack(void)//发送应答
{ SDA=0; SCL=1; delaynop(); SCL=0;}
void i2c_nack(void)//发送非应答
{ SDA=1; SCL=1; delaynop(); SCL=0;}
void i2c_stop(void)//停止IIC
{ SDA=0; SCL=1; delaynop(); SDA=1; delaynop(); SCL=0;}
void check_busy(void)
{ d_i=0; r_w=1; e=1; while(P0&0x80); e=0;}
void write( F0,unsigned char data_comm)//液晶屏写字节,F0=1为写数据,F0=0为写指令
{
d_i=F0;
r_w=0;
e=1;
P0=data_comm;
e=0;
check_busy();
}
unsigned char getpixel(void)//液晶屏读点
{
unsigned char valve;
d_i=1;
r_w=1;
e=1; P0=255; valve=P0;
e=0;
check_busy();
d_i=1;
e=1;
valve=P0;
e=0;
check_busy();
return valve;
}
void putpixel(unsigned char x,y)//液晶屏写点
{
unsigned char valve;
if(x<64) {cs1=1;cs2=0;} else {cs1=0;cs2=1;x-=64;}
write(0,page+(y>>3));
write(0,x_position+x);
valve=getpixel();
valve|=(1<<(y%8));
write(0,x_position+x);
write(1,valve);
}
void init_lcd(void)
{
unsigned char i,j;
rst=0;
_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
rst=1;
cs1=1;
cs2=1;
write(0,lcd_on);
for(i=0;i<8;i++)
{
write(0,page+i);
write(0,x_position);
for(j=0;j<64;j++)write(1,0);
}
}
void adcpcf8591()//AD采样及显示
{
unsigned char i,j,a1,a2,a3,d[108],f;
i2cstart();
i2c_w_byte(pcf8591_write);
i2c_w_byte(1);
i2cstart();
i2c_w_byte(pcf8591_read);
i2c_r_byte();
i2c_mack();
for(i=0;i<107;i++)
{
for(j=0;j<11;j++){_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_
();}//减慢
d=i2c_r_byte();//采样
i2c_mack();
}
d=i2c_r_byte();
i2c_nack();
i2c_stop();
f=0;
for(i=0;i<107;i++)//显示
{
a1=63-(d>>2);
a2=63-(d[i+1]>>2);
if(a1>a2){a3=a2;a2=a1;a1=a3;}
if(a1>30)f=1;//检测到信号f=1,下面就沿时
for(j=a1;j<=a2;j++)putpixel(i,j);
}
if(f) delay(7);
}
void main(void)
{
TH0=0X93;
TL0=0X00;
while(1)
{
init_lcd();//初始化及清屏
adcpcf8591();
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
那当时的程序还在么?
一周热门 更多>