微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > TLC5615简易数控电压表

TLC5615简易数控电压表

时间:08-18 来源:互联网 点击:
/*************简易数控电压表**************************程序功能:输出可调0~5伏电压,步进值为0.1V涉及芯片:1602液晶、TLC5615、TLC549、AT89S52单片机******************************************************/#includereg52.h>#define uint unsigned int#define uchar unsigned charuchar code num[]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39};/*uchar code dianya[]={21,41,65,84,104,125,145,166,186,206,227,247,267,288,308,330,350,370,392,412,432,452,472,494,514,534,556,576,596,616,636,658,678,698,720,740,760,780,802,822,842,862,884,904,924,944,964}; */sbit key1=P1^0;sbit key2=P1^1;sbit key3=P1^2;sbit key4=P1^3;sbit din=P3^0;sbit scl=P3^1;sbit cs1=P3^2;sbit clock=P3^3;//时钟线sbit dout=P3^4;//数据输出端sbit cs=P3^5;//片选(低电平有效)sbit rs=P2^0;//数据/命令选择端(H/L)sbit rw=P2^1;//读/写选择端(H/L)sbit en=P2^2; //使能选择端uchar bdata date; //位寻址sbit date7=date^7;sbit date6=date^6;sbit date5=date^5;sbit date4=date^4;sbit date3=date^3;sbit date2=date^2;sbit date1=date^1;sbit date0=date^0;/****************函数声明**********************/void delay(uint time);void write_com(uchar mingling);void write_date(uchar shuju);void chushihua();void delayus(uint t){while(t--);}void write_sip5615(uchar k){date=k;din=date7;scl=0;scl=1;din=date6;scl=0;scl=1;din=date5;scl=0;scl=1;din=date4;scl=0;scl=1;din=date3;scl=0;scl=1;din=date2;scl=0;scl=1;din=date1;scl=0;scl=1;din=date0;scl=0;scl=1;}void write_5615(uint k){k=2;cs1=0;write_sip5615(k>>8);write_sip5615(k);cs1=1;}uchar read_549()//数据得采集{uint i;uchar k=0x00;//定义一个变量k,将在dout上采集的到的数据装进Kdout=1;//该地方置不置高电平都可以,应为单片机的I/O口默认值为高点平for(i=0;i8;i++){if(dout){k|=(0x80)>>i;}clock=1;//高电平期间采集dout线上的数据clock=0;delayus(10);}return k;//返回值}uchar shuchu_549()//数据得读取{uchar date;cs=0;//片选低电平时数据有效date=read_549();//将read_549()函数中采集到的数据付给变量datecs=1;//片选拉高,表示数据读取完毕delayus(50);return date;//返回值}void main(){uint i=0,n=0,m=0;uchar k0,k1,k2,k3,k4,temp;uchar t1,t2,t3,t4;chushihua();write_5615(0);write_com(0x80+0x00);write_date('O');write_com(0x80+0x01);write_date('X');write_com(0x80+0x03);write_date('N');write_com(0x80+0x04);write_date('u');write_com(0x80+0x05);write_date('m');write_com(0x80+0x06);write_date(':');write_com(0x80+0x40);write_date('D'); write_com(0x80+0x41);write_date('i');write_com(0x80+0x42);write_date('a');write_com(0x80+0x43);write_date('n');write_com(0x80+0x45);write_date('Y');write_com(0x80+0x46);write_date('a');write_com(0x80+0x47);write_date(':');write_com(0x80+0x4a);write_date('.');write_com(0x80+0x4f);write_date('V'); while(1){if(key1==0){n++;if(n==50)n=0;while(!key1);}if(key2==0){n--;if(n==0)n=50;while(!key2);} write_5615(20*n);delayus(30);k0=shuchu_549();temp=k0;       k1=k0/100;k2=k0%100;k3=k2/10;k4=k2%10;t1=(uint)(temp*0.0186);t2=(uint)(temp*0.186)%10;t3=(uint)(temp*1.86)%10;t4=(uint)(temp*18.6)%10;write_com(0x80+0x08);//代码write_date(num[k1]);write_com(0x80+0x09);write_date(num[k3]);write_com(0x80+0x0a);write_date(num[k4]);write_com(0x80+0x49);//电压write_date(num[t1]);write_com(0x80+0x4b);write_date(num[t2]);write_com(0x80+0x4c);write_date(num[t3]);write_com(0x80+0x4d);write_date(num[t4]);  } }/*void delay(uint time)//延时函数(运行的时间与晶振有关系){uint i,j;for(i=time;i>0;i--)for(j=110;j>0;j--);} */void write_com(uchar mingling)//命令输入函数{uchar gao,di; //定义高、低四位gao=mingling0xf0;//分出高四位di=(mingling4)0xf0;//分出低四位//==========================================读走高四位P2=gao;//让数据(mingling)高四位有效rs=0;//rs端为低电平时,为接收命令 delayus(8);en=1; //en一个高脉冲读走高四位数据(mingling)delayus(10);en=0;//把使能端拉回低电平//============================================读走低四位delayus(8); P2=di;//让数据(mingling)低四位有效rs=0;//rs端为低电平时,为接收命令delayus(8);en=1 ;//en一个高电平读走低四位命令(mingling)delayus(10);en=0;//把使能端拉回低电平}void write_date(uchar shuju)//数据输入函数{uchar gao,di;gao=shuju0xf0;//分出高四位di=(shuju4)0xf0;//分出低四位//=======================================读走高四位P2=gao;//让数据(shuju)高四位有效rs=1;//rs端为高电平时,为接收数据delayus(8);en=1;//en一个高电平读走低四位数据 (shuju)delayus(10);en=0;//把使能端拉回低电平//============================================读走低四位delayus(8);P2=di;//让数据(shuju)低四位有效rs=1;//rs端为高电平时,为接收数据delayus(8);en=1;//en一个高电平读走低四位数据(shuju)delayus(10);en=0;//把使能端拉回低电平}void chushihua(){rw=0;//把数据/命令选择端先置为零en=0;//把使能端先置为零write_com(0x28);//设置16*12显示,5*7点阵,4位数据接口write_com(0x01);//清屏write_com(0x0c);//显示开启,不显示光标write_com(0x06);//整屏不移动}

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top