📄 123.c
字号:
#include<reg51.h>
#include<intrins.h>
#include<absacc.h>
#define uchar unsigned char
#define uint unsigned int
sbit P1_0=P1^0;
sbit P1_1=P1^1;
sbit P1_2=P1^2;
sbit P1_3=P1^3;
sbit P1_4=P1^4;
sbit P1_5=P1^5;
sbit P1_6=P1^6;
sbit P1_7=P1^7;
sbit dis3=P2^5;
sbit dis2=P2^4;
sbit dis1=P2^3;
sbit dis0=P2^2;
sbit key1=P2^1;
sbit key0=P2^0;
sbit CLK=P3^3;
sbit DAT=P3^4;
sbit CS=P3^5;
uchar code weixuan[4]={0x20,0x10,0x08,0x04};
uchar code distab[10]={0x28,0xee,0x32,0xa2,0xe4,0xa1,0x21,0xea,0x20,0xa0};
uchar disp[4];
uchar mdat[5]={0x00,0x00,0x00,0x00,0x00};
uchar colcha[2]={0x00,0x00};
uint i=0;
uint count=0;
uchar x=0;
void time(t)
{
uint i;
for(i=0;i<t;i++);
}
keproc()
{ uchar keytemp;
if(!P2^2)
if(!P2^0) keytemp--;
else keytemp++;
else if(!P2^3)
if(!P2^0) keytemp=-5;
else keytemp=+5;
else if(!P2^4)
if(!P2^0) keytemp=-10;
else keytemp=+10;
P2=0xff;
return(keytemp);
}
uchar tlc549adc(void)
{
uchar i,x;
CLK=0;
//DAT=1;
CS=0;
for(i=0;i<8;i++)
{
CLK=1;x<<=1;
if(DAT==1) x++;
CLK=0;
}
return(x);
}
void display(float dispcode) //数码现显示
{//float dispcode;
uchar i;
disp[0]=(int)(dispcode*100)%10; //0.01
disp[1]=(int)(dispcode*10)%10; //0.1
disp[2]=(int)(dispcode/1)%10; //1
disp[3]=(int)(dispcode/10)%10; //10
P2=0xff;
P2=weixuan[i]; //段选
if(i==2)
P0=distab[disp[i]]&0xdf ; //加点
i++;
if(i>=4) i=0;
}
//void timer()interrupt 3
//{
// float dispcode;
// TH1=(65535-10000)/256; //扫描频率
// TH0=(65535-10000)%256;
// display(dispcode);
//}
void timer()interrupt 1
{ float dispcode;
// uchar ad_data,t=0x00;
TH1=(65535-4000)/256; //扫描频率
TH0=(65535-4000)%256;
display(dispcode);
// ad_data=tlc549adc();
//mdat[0]=mdat[1];
//mdat[1]=mdat[2];
//mdat[2]=mdat[3];
// mdat[3]=mdat[4];
// mdat[4]=ad_data;
// t=(mdat[0]+mdat[1]+mdat[2]+mdat[3]+mdat[4])/5;
// return(t);
// count++;
// if(count==100)
// {
// count=0;
// colcha[0]=colcha[1];
// colcha[1]=t;
// }
}
main() //主函数
{
uint keytemp;
//float coltemp,tempcha;
//uchar t,speed;
//i=0;
float dispcode;
keytemp=20;
TMOD=0x11; IE=0x8a; //开中断
TR0=1;TR1=1;
TH1=(65535-10000)/256; //扫描频率
TH0=(65535-10000)%256;
P2=0xff;
//P1=0xff;
while(1)
{
keproc();
dispcode=keytemp;
// tlc549adc();
//coltemp=t*100/255;
//if(!P2^5)
// {
// if(!P2^0) dispcode=keytemp; //设定温度的现显示
// else dispcode=coltemp; //采集温度的现显示
// }
// tempcha=keytemp-coltemp;
// speed=colcha[1]-colcha[0];
// if(tempcha>=10) //控制算法
// {
// P1_1=0;
// }
// else if(tempcha>=5)
// {
// P1_1=0;
// time(1000*speed);
// P1_1=1;
// time(1000);
// }
// else if(tempcha>=2)
// {
// P1_1=0;
// time(1000*speed);
// P1_1=1;
// time(1000);
// }
// else if(tempcha>=1)
// {
// P1_1=0;
// time(1000*speed);
// P1_1=1;
// time(1000);
// }
// else if(tempcha>=0.5)
// {
// P1_1=0;
// time(1000*speed);
// P1_1=1;
// time(1000);
// }
// else if(tempcha>=0.1)
// {
// P1_1=0;
// time(1000*speed);
// P1_1=1;
// time(1000);
// }
//else if(tempcha<=0.1)
// {
// P1_1=1;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -