Demo entry 6350655

C

   

Submitted by H on Mar 13, 2017 at 13:52
Language: C. Code size: 7.3 kB.

#include <reg52.h> //头文件 
#define Disdata P0 //液晶数据端口 
#define uchar unsigned char //无符号字符8位 
#define uint unsigned int //无符号整数8位 
uint data dis[4]={0x00,0x00,0x00,0x00};//4个数据单元和一个 
uchar code table[]="OUTPUT: . V "; //定义初始上电液晶默认显示状态 
uchar code table2[]="INPUT: . V "; 
sbit lcden=P2^7; //定义液晶使能端 
sbit lcdrs=P2^5; //定义液晶RS端 
sbit rw=P2 ^6; //定义液晶RW端 
sbit cs_ad=P2^4; 
sbit dout=P2^3; 
sbit clk=P2^2; //转换结束标志位 
sbit da_wr=P2^1; 
sbit da_cs=P2^0; 
sbit beep=P1^7;//蜂鸣器 
data int result;//测量变量暂存地址 
uchar num,num1,num2,num3,num4,num5; 
uchar shii,gei; 
uchar shuru; 
uchar dagg,dass; 
uchar key,temp; 
uchar cvc,mma,mmb; 
uchar ddf; 
uint ddt; 
//********系统延时函数************ 
void delay(uint z) 
{ 
uint x,y; 
for(x=z;x&gt;0;x--) 
for(y=110;y&gt;0;y--); 
} 
 
//************* 
void di() 
{ 
beep=0; 
delay(100); 
beep=1; 
}void write_com(uchar com) //液晶写命令函数 
{ 
lcdrs=0; 
P0=com; 
delay(5); 
lcden=1; 
delay(5); 
lcden=0; 
} 
void write_data(uchar date) //液晶写数据函数 
{ 
lcdrs=1; 
P0=date; 
delay(5); 
lcden=1; 
delay(5); 
lcden=0; 
} 
void write_sg(uchar add,uchar date) //写整数位和小数位函数 
{ 
uint shi,ge; 
shi=date/10; //分解出一个2位数的十位 
ge=date%10; 
write_com(0x80+0x40+add); //设置显示位置 
write_data(0x30+shi); //送去液晶显示十位 
write_data(0x30+ge); //送去液晶显示个位 
} 
//void write_da(uchar sps,uchar uru) 
//{ uchar yuy,rur; 
// yuy=uru; 
// rur=0; 
// write_com(0x80+sps); //设置显示位置 
//if(cvc==8) 
// { 
// write_data(0x30+yuy); //送去液晶显示十位 
// write_data(0x30+rur); //送去液晶显示个位 
// } 
/// else 
// write_data(0x30+rur); //送去液晶显示十位 
// write_data(0x30+yuy); 
//}void init() 
{ 
shuru=0; 
rw=0; 
lcden=0; 
shii=0; 
gei=0; 
dagg=0; 
dass=0; 
write_com(0x38); //初始化1602液晶 
write_com(0x0c); 
write_com(0x06); 
write_com(0x01); 
write_com(0x80); //设置显示初始坐标 for(num2=0;num2&lt;13;num2++) 
{ 
write_data(table1[num2]); 
delay(5); 
} 
write_com(0x80+40); 
for(num3;num3&lt;16;num3++) 
{ 
write_data(table3[num3]); 
delay(5); 
} 
delay(3000); 
 
} //******************************* 
void scan1() 
{ 
write_com(0x80); 
for(num1;num1&lt;16;num1++) 
{ 
write_data(table2[num1]); 
delay(5); 
} 
// write_da(8,dass); 
//write_da(11,dagg); write_com(0x80+0x40); //设置显示初始坐标 
for(num=0;num&lt;16;num++) 
{ 
write_data(table[num]); 
delay(5); 
} 
write_sg(8,shii); 
write_sg(11,gei); 
 
} 
 
//****TLC1549转换处理子函数********void test() 
{ 
 
data uchar i; 
 
cs_ad=1; //禁止i/o clock 
cs_ad=0; //开启控制电路,使能data out和i/o clock 
result=0; //清转换变量 
for(i=0;i&lt;10;i++) //采集10次 ,即10bit 
{ 
clk=0; 
result*=2; 
if(dout) result++; 
clk=1; 
} 
delay(590); 
cs_ad=1; ;;;; //data out 返回到高阻状态而终止序列 
//****数据转换处理********** 
result=result*2; 
dis[2]=result/205; //计算整数位 
dis[3]=result%205; //余数暂存 
dis[3]=dis[3]*10; //计算小数第一位 
dis[1]=dis[3]/205; 
dis[3]=dis[3]%205; 
dis[3]=dis[3]*10; //计算小数第二位 
dis[0]=dis[3]/205; 
shii=dis[2]; 
gei=dis[1]*10+dis[0]; 
write_sg(8,shii); 
write_sg(11,gei); 
 
} 
//*********************** 
void test_da() 
{ 
 
 
ddf=mma+mmb*0.1-0.7; 
ddf=ddf*25.6; 
ddt=ddf; 
da_wr=0; 
da_cs=0; 
P3=ddt; 
delay(1); 
}//************************* 
void markey() 
{ 
 
P1=0xfe; 
temp=P1; 
temp=temp&amp;0xf0; 
if(temp!=0xf0) 
{ 
delay(10); 
temp=P1; 
temp=temp&amp;0xf0; 
if(temp!=0xf0); 
{ 
temp=P1; 
switch(temp) 
{ 
case 0xee: 
if(cvc==0) 
{ 
write_com(0x80+8); 
write_data(0x30+0); 
write_data(0x30+1); 
di(); 
cvc++; 
key=1; 
mma=key; 
break; 
} 
else 
write_com(0x80+11); 
write_data(0x30+1); 
write_data(0x30+0); 
key=1; 
cvc=0; 
di(); 
mmb=key; 
test_da(); 
break; 
case 0xde: 
if(cvc==0) 
{ 
write_com(0x80+8); 
write_data(0x30+0); 
write_data(0x30+2); 
di(); 
cvc++; 
key=2; 
mma=key; 
break; 
} 
else 
write_com(0x80+11); 
write_data(0x30+2); 
write_data(0x30+0); 
key=2; 
cvc=0; 
di(); 
mmb=key; 
test_da(); 
break; 
 
 
case 0xbe: 
if(cvc==0) 
{ 
write_com(0x80+8); 
write_data(0x30+0); 
write_data(0x30+3); 
di(); 
cvc++; 
key=3; 
mma=key; 
break; 
} 
else 
write_com(0x80+11); 
write_data(0x30+3); 
write_data(0x30+0); 
key=3; 
cvc=0; 
di(); 
mmb=key; 
test_da(); 
break; 
} 
while(temp!=0xf0) 
{ 
temp=P1; 
temp=temp&amp;0xf0; 
} 
 
} 
 
 
} P1=0xfd; 
temp=P1; 
temp=temp&amp;0xf0; 
if(temp!=0xf0) 
{ 
delay(10); 
temp=P1; 
temp=temp&amp;0xf0; 
if(temp!=0xf0); 
{ 
temp=P1; 
switch(temp) 
{ 
case 0xed: 
if(cvc==0) 
{ 
write_com(0x80+8); 
write_data(0x30+0); 
write_data(0x30+4); 
di(); 
cvc++; 
key=4; 
mma=key; 
break; 
} 
else 
write_com(0x80+11); 
write_data(0x30+4); 
write_data(0x30+0); 
key=4; 
cvc=0; 
di(); 
mmb=key; 
test_da(); 
break; 
case 0xdd: 
if(cvc==0) 
{ 
write_com(0x80+8); 
write_data(0x30+0); 
write_data(0x30+5); 
di(); 
cvc++; 
key=5; 
mma=key; 
break; 
} 
else 
write_com(0x80+11); 
write_data(0x30+5); 
write_data(0x30+0); 
key=5; 
cvc=0; 
di(); 
mmb=key; 
test_da(); 
break; 
case 0xbd: 
if(cvc==0) 
{ 
write_com(0x80+8); 
write_data(0x30+0); 
write_data(0x30+6); 
di(); 
cvc++; 
key=6; 
mma=key; 
break; 
} 
else 
write_com(0x80+11); 
write_data(0x30+6); 
write_data(0x30+0); 
key=6; 
cvc=0; 
di(); 
mmb=key; 
test_da(); 
break; 
} 
while(temp!=0xf0) 
{ 
temp=P1; 
temp=temp&amp;0xf0; 
} 
 
} 
} P1=0xfb; 
temp=P1; 
temp=temp&amp;0xf0; 
if(temp!=0xf0) 
{ 
delay(10); 
temp=P1; 
temp=temp&amp;0xf0; 
if(temp!=0xf0); 
{ 
temp=P1; 
switch(temp) 
{ 
case 0xeb: 
if(cvc==0) 
{ 
write_com(0x80+8); 
write_data(0x30+0); 
write_data(0x30+7); 
di(); 
cvc++; 
key=7; 
mma=key; 
break; 
} 
else 
write_com(0x80+11); 
write_data(0x30+7); 
write_data(0x30+0); 
key=7; 
cvc=0; 
di(); 
mmb=key; 
test_da(); 
break; 
case 0xdb: 
if(cvc==0) 
{ 
write_com(0x80+8); 
write_data(0x30+0); 
write_data(0x30+8); 
di(); 
cvc++; 
key=8; 
mma=key; 
break; 
} 
else 
write_com(0x80+11); 
write_data(0x30+8); 
write_data(0x30+0); 
key=8; 
cvc=0; 
di(); 
mmb=key; 
test_da(); 
break; 
case 0xbb: 
if(cvc==0) 
{ 
write_com(0x80+8); 
write_data(0x30+0); 
write_data(0x30+9); 
di(); 
cvc++; 
key=9; 
mma=key; 
break; 
} 
else 
write_com(0x80+11); 
write_data(0x30+9); 
write_data(0x30+0); 
key=9; 
cvc=0; 
di(); 
mmb=key; 
test_da(); 
break; 
 
} 
while(temp!=0xf0) 
{ 
temp=P1; 
temp=temp&amp;0xf0; 
} 
 
} 
 
} 
 
P1=0xf7; 
temp=P1; 
temp=temp&amp;0xf0; 
if(temp!=0xf0) 
{ 
delay(10); 
temp=P1; 
temp=temp&amp;0xf0; 
if(temp!=0xf0); 
{ 
temp=P1; 
switch(temp) 
{ 
case 0xe7: 
if(cvc==0) 
{ 
write_com(0x80+8); 
write_data(0x30+0); 
write_data(0x30+0); 
di(); 
cvc++; 
key=0; 
mma=key; 
break; 
} 
else 
write_com(0x80+11); 
write_data(0x30+0); 
write_data(0x30+0); 
key=0; 
cvc=0; 
di(); 
mmb=key; 
test_da(); 
break; 
break; 
case 0xd7: 
key=11; 
write_com(0x80+8); 
write_data(0x30+0); 
write_data(0x30+0); 
write_com(0x80+11); 
write_data(0x30+0); 
write_data(0x30+0); 
di(); 
cvc=0; 
mma=0; 
mmb=0; 
test_da(); 
break; 
case 0xb7: 
key=12; 
break; 
 
} 
while(temp!=0xf0) 
{ 
temp=P1; 
temp=temp&amp;0xf0; 
} 
 
} 
} 
} 
 
 
//*******主函数***** 
void main() 
{ 
init(); 
scan1(); 
while(1) 
{ 
markey();test_da(); 
test(); 
} 
} 
 

This snippet took 0.02 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).