当前位置:首页 > 基于单片机的太阳能充电器的设计毕业设计
附录B 整体程序
#include
sbit P3_3=P3^3; //开始充电 sbit P3_4=P3^4; //电压切换 sbit PWM=P3^5; sbit EOC=P3^1; //定义ADC0808的控制引脚/ sbit OE=P3^0; sbit START=P3^2; sbit P3_6=P3^6; sbit P3_7=P3^7; sbit wela=P2^1; sbit dula=P2^0;
uchar time=0,time1=0; uchar period=40; uchar high=6,high1=12; uchar th0=0; uchar tl0=1; uchar i=0,j=0; uint x,z,n;
uchar code dispcode[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; //uchar n=0; //uchar flag1;
//unsigned char volatile g_delay_count;
//================================/ void delay(uchar z) //100us延时子程序/ {
while(z--); }
//==============================/ void display() //定义显示子函数/ 可以使用锁存器实现 {
for(n=0;n<4;n++) {
P0=0x00; dula=1;
P0 =disp[1]; //显示第一位小数 dula=0;
wela=1; P0=0xfb; wela=0; delay(2); P0=0x00; dula=1;
P0=disp[2]; //显示第二位小数 dula=0; wela=1; P0=0xfd; wela=0; delay(2); P0=0x00; dula=1;
P0 =disp[3]; //显示第三位小数 dula=0; wela=1; P0=0xfe; wela=0; delay(2); P0=0x00; dula=1;
P0 =disp[0]+0x80; dula=0; wela=1; P0=0xf7; wela=0; delay(2); } }
//===============================/ uint ADC0808() //定义ADC0808读入数据子函数,并通过函数返回/ {
uchar d ; uchar value;
START=1;START=0; //启动ADC0808,开始A/D转换/ while(!EOC); //等待ADC0808,转换结束,即EOC为高电平/ OE=1;
if(time1 value=0.4*d; } else if(high1==20) { value=0.5*d; } else if(high1==24) { value=0.6*d; } else if(high1==28) { value=0.7*d; } else if(high1==32) { value=0.8*d; } else if(high1==36) { value=0.9*d; } } //允许ADC0808输出数据 if(time value=0.2*d; } else if(high==10) { value=0.25*d; } else if(high==12) { value=0.3*d; } else if(high==14) { value=0.35*d; } else if(high==16) { value=0.4*d; } else if(high==18) / { value=0.45*d; } else if(high==20) { value=0.5*d; } else if(high==22) { value=0.55*d; } else if(high==24) { value=0.6*d; } else if(high==26) { value=0.65*d; } else if(high==28) { value=0.7*d; } else if(high==30) { value=0.75*d; } else if(high==32) { value=0.75*d; } else if(high==34) { value=0.8*d; } else if(high==36) { value=0.85*d; } } OE=0; //禁止ADC0808数据输出/ return value; //返回A/D转换数据/ } //=================================/
共分享92篇相关文档