|
#include<reg51.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
#define DB P0
#define DW P1
int X,Y;
sbit lcdrs=P2^1;
sbit lcdrw=P2^2;
sbit lcden=P2^3;
sbit dacs=P2^4;
sbit dawr=P2^5;
sbit CLK=P3^1;
sbit DI=P3^0;
sbit CS=P2^6;
uchar digit[]={0,0};
uchar dat;
int n,b;
int z,num;
void delay(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
int q,w;
unsigned char adc0832_write_data()
{
CS=1;
CLK=0;
DI=1;
CS=0;
CLK=0;
CLK=1;
DI=1;
CLK=0;
CLK=1;
DI=0;
CLK=0;
CLK=1;
DI=1;
CLK=0;
for(n=0;n<8;n++)
{
CLK=0;
CLK=1;
dat=dat<<1;
}
CS=1;
return dat;
}
void write_com(uchar command)
{
lcdrs=0;
lcdrw=0;
lcden=0;
DW=command;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void write_data(uchar q)
{
lcdrs=1;
lcdrw=0;
lcden=0;
DW=q;
lcden=1;
delay(5);
lcden=0;
}
void LCDping()
{
lcden=0;
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
}
void xianshidianya(int da)
{
da=dat*10;
digit[0]=da/10;
digit[1]=da%10;
}
uchar code table[]={"volt"} ;
void LCD_write_data()
{
write_com(0x80);
for(X=0;X<4;X++);
{
write_data(table[X]);
delay(5);
}
write_com(0x80+0x40+0x11);
write_data(digit[0]);
write_com(0x80+0x40+0x12);
write_data('.');
write_com(0x80+0x40+0x13);
write_data(digit[1]);
}
void dac0832()
{
dacs=0;
_nop_();
dawr=0;
_nop_();;
DB=dat;
delay(50);
{
dawr=1;
_nop_();
dacs=1;
}
}
void main( )
{
unsigned char adc0832_write_data();
xianshidianya();
LCDping();
LCD_write_data();
dac0832();
}
|
|