- 积分
- 3553
- 下载分
- 分
- 威望
- 点
- 原创币
- 点
- 下载
- 次
- 上传
- 次
- 注册时间
- 2014-11-13
- 精华
|
马上注册,获取阅读精华内容及下载权限
您需要 登录 才可以下载或查看,没有帐号?注册
x
//////////////stc15MCU//////////////////////
// ------------ //
// ADC--|P1.2 P1.1|--rs //
// --|P1.3 P1.0|--en //
// D4--|P1.4 P3.7|--D7 //
// D5--|P1.5 P3.6|--D6 //
// --|P5.4 P3.3|--D3 //
// Vcc--|V+ P3.2|--D2 //
// --|P5.5 P3.1|--D1 //
// GND--|V- P3.0|--D0 //
// ------------ //
/////////////////////////////////////////////////////////
#include"reg51.h"
#define U16 unsigned int
#define U8 unsigned char
sbit rs=P1^1;
sbit en=P1^0;
U8 dd0[]="shanxi dianzi";
U16 temp;
void delay(U16 us)
{
while(us--);
}
///////////////////////////////////LCD1602///////////////////////////////
// -------------------------------------------------------------------------------- //
// | -------------------------------------------------------------------------- | //
// | | | | //
// | | | | //
// | ----------------------------------------------------------------------- | | //
// --------------------------------------------------------------------------------- //
// | | | | | | | | | | | | | | | | //
// Vss Vdd Vo RS RW EN D0 D1 D2 D3 D4 D5 D6 D7 A K //
////////////////////////////////////////////////////////////////////////////////////
void w1602(bit w,U8 dat)
{
ACC=dat;
rs=w;
en=0;
P3 &=~0xcf; //According to the LCD1602 pin clear
P3 |=dat & 0xcf; //For 1602 pin assignment
P1 &=~0x30; //LCD1602 pin clear
P1 |=dat & 0x30; //For 1602 pin assignment
delay(10);
en=1;
delay(10);
en=0;
}
void init1602()
{
w1602(0,0x38);
w1602(0,0x06);
w1602(0,0x0c);
w1602(0,0x01);
}
void initADC()
{
P1ASF=0x04; //ADC_in in P1.2
ADC_RES=0;
ADC_RESL=0;
ADC_CONTR=0xE2; // 1)ON Power; 2)speed 90 3)ADC in P1.2
delay(15);
}
void main()
{
U8 n;
init1602();
P1M1=0x04;
P1M0=0x00;
CLK_DIV &=~0x20;
while(1)
{
initADC();
ADC_CONTR =0xea;
delay(10);
while(!(ADC_CONTR & 0x10));
ADC_CONTR &=~0x10; //clear ADC_flag
temp =ADC_RES;
temp =temp<<2;
temp |=ADC_RESL;
w1602(0,0x80);
for(n=0;n<13;n++)
w1602(1,dd0[n]);
w1602(0,0xc0);
w1602(1,(temp/1000+0x30));
w1602(1,((temp%1000)/100+0x30));
w1602(1,(((temp%1000)%100)/10+0x30));
w1602(1,(temp%10+0x30));
}
}
///不移动不闪烁的成功程序///+++++++++++++++++++++++OK
#include <REGX51.H>
#include"intrins.h"
sbit rs=P1^1;
sbit en=P1^0;
sbit D0=ACC^0;
sbit D1=ACC^1;
sbit D2=ACC^2;
sbit D3=ACC^3;
sbit D4=ACC^4;
sbit D5=ACC^5;
sbit D6=ACC^6;
sbit D7=ACC^7;
unsigned int temp,temp1;
unsigned char dd0[]=" H:0530;L:0630";
unsigned char dd1[]=" Pow L:";
void delay(unsigned int ms)
{ char i;
while(ms--)
for(i=0;i<5;i++);
}
void w1602c(unsigned char dat)
{
unsigned char i;
ACC=dat;
P30=D0;
P31=D1;
P32=D2;
P33=D3;
P14=D4;
P15=D5;
P36=D6;
P37=D7;
rs=0;
en=0;
i=20;
while(i--);
en=1;
i=20;
while(i--);
en=0;
i=20;
while(i--);
}
void w1602d(unsigned char dat)
{
unsigned char i;
ACC=dat;
P30=D0;
P31=D1;
P32=D2;
P33=D3;
P14=D4;
P15=D5;
P36=D6;
P37=D7;
rs=1;
en=0;
i=20;
while(i--);
en=1;
i=20;
while(i--);
en=0;
i=20;
while(i--);
}
void init1602()
{
w1602c(0x38);
w1602c(0x06);
w1602c(0x0c);
w1602c(0x01);
}
void InitADC()
{
char n;
P1ASF =0x04; //P1.2 ADC_IN
ADC_RES=0;
ADC_RESL=0;
ADC_CONTR =0xE2;//ON_POWER
for(n=0;n<10;n++);
}
void disp(unsigned int dd)
{
char i;
for(i=0;i<7;i++)
w1602d(dd0);
w1602d(0x20);
w1602d(dd/1000+0x30);
w1602d((dd%1000)/100+0x30);
w1602d(((dd%1000)%100)/10+0x30);
w1602d(dd%10+0x30);
}
void main()
{
unsigned int nn;
init1602();
P1M1=0x04;
P1M0=0x00;
CLK_DIV &=~0x20;
while(1)
{
InitADC();
ADC_CONTR=0xea;
nn=10;
while(nn--);
while(!(ADC_CONTR & 0x10));
ADC_CONTR &=~0x10;
temp=ADC_RES;
temp=temp<<2;
temp |=ADC_RESL;
w1602c(0x80);
for(nn=0;nn<15;nn++)
w1602d(dd0[nn]);
delay(100);
w1602c(0xc0);
disp(temp-529);
}
}
/////////////////////////////////////////////+++++++++++++++++++++
#include <REGX51.H>
#include"intrins.h"
sbit rs=P1^1;
sbit en=P1^0;
unsigned int temp;
unsigned char dd0[]=" Pow H:";
unsigned char dd1[]=" Pow L:";
void delay(unsigned int ms)
{
char i;
while(ms--)
for(i=0;i<5;i++);
}
void w1602c(unsigned char dat)
{
char i;
P3 &=~0xcf;
P3 |=(dat & 0xcf);
P1 &=~0x30;
P1 |=((dat) & 0x30);
rs=0;
en=0;
i=6;
while(i--);
en=1;
i=8;
while(i--);
en=0;
}
void w1602d(unsigned char dat)
{
char i;
P3 &=~0xcf;
P3 |=(dat & 0xcf);
P1 &=~0x30;
P1 |=((dat) & 0x30);
rs=1;
en=0;
i=6;
while(i--);
en=1;
i=8;
while(i--);
en=0;
}
void InitADC()
{
char n;
P1ASF =0x02; //P10
ADC_RES=0;
ADC_RESL=0;
ADC_CONTR =0xE2;//ON_POWER
for(n=0;n<10;n++);
}
void init1602()
{
w1602c(0x38);
w1602c(0x06);
w1602c(0x0c);
w1602c(0x01);
}
void main()
{
unsigned char i,nn;
init1602();
CLK_DIV &=~0x20;
while(1)
{
InitADC(); //on exchange power
ADC_CONTR =0xea; //start exchange
nn=10;
while(nn--);
while(!(ADC_CONTR & 0x10));//wait for AD exchenge end
ADC_CONTR &=~0x10;
temp =ADC_RES; //read high 8bit to temp
temp =temp<<2;
temp |=ADC_RESL;//read low 2bit to temp
temp=temp-400;
w1602c(0x80);
for(i=0;i<7;i++)
w1602d(dd0);
w1602d(temp/1000+0x30);
w1602d((temp%1000)/100+0x30);
w1602d(((temp%1000)%100)/10+0x30);
w1602d(temp%10+0x30);
delay(60000);
delay(60000);
delay(60000);
delay(60000);
w1602c(0x01);
}
}
///////////////////////////////////////////////////////////////////////////////////
#include <REGX51.H>
#include"intrins.h"
sbit rs=P3^7;
sbit en=P5^4;
unsigned int temp;
unsigned char dd0[]=" Pow H:";
unsigned char dd1[]=" Pow L:";
void delay(unsigned int ms)
{ char i;
while(ms--)
for(i=0;i<5;i++);
}
void w1602c(unsigned char dat) //d7 d6 d5 d4 d3 d2 d1 d0
{
char i;
P3 &=~0x4c; // s7 s6 s5 s4 s3 s2 s1 s0
P3 |=(dat>>3 & 0x0c) |(dat>>1 & 0x40);
// P36 P33 P32 P15 P14 P13 P12 P11
P1 &=~0x3e; //P1: x x P15 P14 P13 P12 P11 x
P1 |=((dat<<1) & 0x3e); //P3: x P36 x x P33 P32 x x
rs=0;
en=0;
i=6;
while(i--);
en=1;
i=8;
while(i--);
en=0;
}
void w1602d(unsigned char dat)
{
char i;
P3 &=~0x4c; // s7 s6 s5 s4 s3 s2 s1 s0
P3 |=(dat>>3 & 0x0c) |(dat>>1 & 0x40);
// P36 P33 P32 P15 P14 P13 P12 P11
P1 &=~0x3e; //P1: x x P15 P14 P13 P12 P11 x
P1 |=((dat<<1) & 0x3e); //P3: x P36 x x P33 P32 x x
rs=1;
en=0;
i=6;
while(i--);
en=1;
i=8;
while(i--);
en=0;
}
void InitADC()
{
char n;
P1ASF =0x01; //P1.0 ADC_IN
ADC_RES=0;
ADC_RESL=0;
ADC_CONTR =0xE0;//ON_POWER
for(n=0;n<10;n++);
}
void init1602()
{
w1602c(0x38);
w1602c(0x06);
w1602c(0x0c);
w1602c(0x01);
}
void main()
{
unsigned char i,nn;
init1602();
CLK_DIV &=~0x20;
while(1)
{
InitADC(); //on exchange power
ADC_CONTR =0xe8; //start exchange
nn=10;
while(nn--);
while(!(ADC_CONTR & 0x10));//wait for AD exchenge end
ADC_CONTR &=~0x10;
temp =ADC_RES; //read high 8bit to temp
temp =temp<<2;
temp |=ADC_RESL;//read low 2bit to temp
//temp=temp-400;
w1602c(0x80);
for(i=0;i<7;i++)
w1602d(dd0);
w1602d(temp/1000+0x30);
w1602d((temp%1000)/100+0x30);
w1602d(((temp%1000)%100)/10+0x30);
w1602d(temp%10+0x30);
for(i=0;i<5;i++)
w1602d(0x20);
w1602c(0xc0);
for(i=0;i<16;i++)
w1602d(dd1);
delay(60000);
delay(60000);
delay(60000);
delay(60000);
//w1602c(0x01);
}
}
|
|
|