標(biāo)題:
STC單片機(jī)+12964低電壓保護(hù)源程序
[打印本頁]
作者:
anri1234
時(shí)間:
2019-11-16 11:03
標(biāo)題:
STC單片機(jī)+12964低電壓保護(hù)源程序
單片機(jī)源程序如下:
//#include<reg52.h>
#include<STC_NEW_8051.H>
#include<LCD12864.H>
#include<eeprom.h>
#include<ADC.h>
#include<math.h>
/****定義按鍵接口**************/
sbit Mode=P3^2;
sbit Add=P3^3;
sbit Dec=P3^4;
sbit Ent=P3^5;
sbit Dsp=P3^7;
sbit J5=P2^7;
sbit LED=P4^2;
sbit G1=P4^3;
unsigned char id,num;
unsigned int a[8];
//void Add_key1();
void Lcd_Mark2(void);
/*void Lcd_Mark3(void)
{
Mcs=1;Scs=0;
g= a[0]/100%10;
d= a[0]/10%10;
e= a[0]%10;
Disp_Digit(0,0,zero+g*16);
Disp_Digit(0,8,zero+d*16);
Disp_Digit(0,16,zero+e*16);
Disp_Digit(0,24,space);
Disp_Digit(0,32,space);
g= a[1]/100%10;
d= a[1]/10%10;
e= a[1]%10;
Disp_Digit(2,0,zero+g*16);
Disp_Digit(2,8,zero+d*16);
Disp_Digit(2,16,zero+e*16);
Disp_Digit(2,24,space);
Disp_Digit(2,32,space);
g= a[2]/100%10;
d= a[2]/10%10;
e= a[2]%10;
Disp_Digit(4,0,zero+g*16);
Disp_Digit(4,8,zero+d*16);
Disp_Digit(4,16,zero+e*16);
Disp_Digit(4,24,space);
Disp_Digit(4,32,space);
g= a[3]/100%10;
d= a[3]/10%10;
e= a[3]%10;
Disp_Digit(6,0,zero+g*16);
Disp_Digit(6,8,zero+d*16);
Disp_Digit(6,16,zero+e*16);
Disp_Digit(6,24,space);
Disp_Digit(6,32,space);
Disp_Digit(6,40,space);
Disp_Digit(6,48,space);
Mcs=0;Scs=1;
g= a[4]/100%10;
d= a[4]/10%10;
e= a[4]%10;
Disp_Digit(0,0,zero+g*16);
Disp_Digit(0,8,zero+d*16);
Disp_Digit(0,16,zero+e*16);
g= a[5]/100%10;
d= a[5]/10%10;
e= a[5]%10;
Disp_Digit(2,0,zero+g*16);
Disp_Digit(2,8,zero+d*16);
Disp_Digit(2,16,zero+e*16);
g= a[6]/100%10;
d= a[6]/10%10;
e= a[6]%10;
Disp_Digit(4,0,zero+g*16);
Disp_Digit(4,8,zero+d*16);
Disp_Digit(4,16,zero+e*16);
g= a[7]/100%10;
d= a[7]/10%10;
e= a[7]%10;
Disp_Digit(6,0,zero+g*16);
Disp_Digit(6,8,zero+d*16);
Disp_Digit(6,16,zero+e*16);
} */
/*------------------------------------------------
定時(shí)器初始化子程序
------------------------------------------------*/
void Init_Timer0(void)
{
TMOD |= 0x01; //使用模式1,16位定時(shí)器,使用"|"符號(hào)可以在使用多個(gè)定時(shí)器時(shí)不受影響
TH0=0x00; //給定初值,這里使用定時(shí)器最大值從0開始計(jì)數(shù)一直到65535溢出
TL0=0x01;
ET0=1; //定時(shí)器中斷打開
TR0=1; //定時(shí)器開關(guān)打開
}
void Delay100(int num)//延時(shí)函數(shù) 10ms
{ int i,j;
for ( i=num;i>0;i--)
for ( j=12490;j>0;j--)
{ }
}
void Disp(void);
void main()
{
year=Byte_Read(0X00)<<2;
month=Byte_Read(0X01);
date=Byte_Read(0X02);
hour=Byte_Read(0X03);
min=Byte_Read(0X04);
sec=Byte_Read(0X05);
week=Byte_Read(0X06);
Init_Timer0();
EA = 1; //打開總中斷
InitADC();
Init_lcd();
Clr_Scr(); J5=1;
Delay100(30);
// Delay12864(20000);
Lcd_Mark1();
// Delay12864(10000);
EA=1;
flag=0;G1=1;
while(1)
{
write_com(Disp_On);
a[0]=(GetADCResult(0)<<2|ADC_LOW2); a[0]=a[0]/100*3*month; Delay12864(20);
a[1]=(GetADCResult(1)<<2|ADC_LOW2); a[1]=a[1]/100*3*month; Delay12864(20);
// a[2]=GetADCResult(2);
// a[3]=GetADCResult(3);
// a[4]=GetADCResult(4);
// a[5]=GetADCResult(5);a[5]=a[5]<<1;
// a[6]=GetADCResult(6);a[5]=a[6]<<1;
// a[7]=GetADCResult(7);a[5]=a[7]<<1;
//a[3]=ad[3];
if(Dsp==0)
{
if(Dsp==0)
{
flag=~flag ;
while(Dsp==0);
}
}
if( flag==0)
{//Disp();
Clr_Scr(); Lcd_Mark1(); Lcd_Mark2();
}
if( flag==1)
{ Clr_Scr(); Disp();
}
if ((a[0]>300)&&(a[1]>300))
{Delay100(1000);G1=0;
if ( G1==0)
if( (a[0]<year)&&(a[1]<year))
{
Delay100(hour);
J5=0;Delay100(hour);J5=1;
}
}
// if( (a[5]>year)||(a[6]>year)||(a[7]>year))
// {J5=0;Delay100(100 ); }
// if( (a[2]>month)||(a[3]>month)||(a[4]>month))
// { Delay100(min-30 );
// J5=0; Delay100(100 ); J5=1; }
// if( (a[2]>date)||(a[3]>date)||(a[4]>date))
// { Delay100(sec-30 );
// J5=0; Delay100(100 ); J5=1; }
if(Ent==0)
{ if(Ent==0)
{ Sector_Erase(0x00);
Byte_Program(0x00, year>>2);
Byte_Program(0x00+1, month);
Byte_Program(0x00+2, date);
Byte_Program(0x00+3, hour);
Byte_Program(0x00+4, min);
Byte_Program(0x00+5, sec);
Byte_Program(0x00+6, week);
while(Ent==0); }
}
}
/* switch( id )
{
case 0: Disp( ); Delay12864(20000); break;//正常顯示
case 1:year1 = 1;Add_key1(); Disp( ); break;//年
case 2:month1=1;Add_key1();Disp();break;//月
case 3:day1=1;;Add_key1();Disp();break; //日
case 4:hour1=1;Add_key1();Disp();break;//星期
case 5:min1=1;Add_key1();Disp();break; //小時(shí)
case 6:sec1=1;Add_key1();Disp();break; //分鐘
case 7:sec1=1;Add_key1();Disp();break; //秒
default:break;
} */
}
void Timer0_isr(void) interrupt 1 using 1
{
TH0=0x00; //重新賦值
TL0=0x01;
LED=~LED;
{ if(Mode==0)
{
// Delay12864(20);
if(Mode==0)
{
id++;
if(id>8) id=0;
while(Mode==0); }
}
if(id==1)
{ if(Add==0)
{
Delay12864(20);
if(Add==0)
{ year++;
if (year>0x0fff) year=0;
while(Add==0);
}
}
if(Dec==0)
{
Delay12864(20);
if(Dec==0)
{ year--; if (year<0x00) year=0;
while(Dec==0);
}
}
}
if(id==2)
{ if(Add==0)
{
Delay12864(20);
if(Add==0)
{ month++;if (month>0xff) month=0;
while(Add==0);
}
}
if(Dec==0)
{
Delay12864(20);
if(Dec==0)
{ month--;if (month<0x00) month=0;
while(Dec==0);
}
}
}
if(id==3)
{ if(Add==0)
{
Delay12864(20);
if(Add==0)
{ date++; if (date>0xff) date=0;
while(Add==0);
}
}
if(Dec==0)
{
Delay12864(20);
if(Dec==0)
{date--;//if (date<0x00) date=0;
while(Dec==0);
}
}
}
if(id==4)
{ if(Add==0)
{
Delay12864(20);
if(Add==0)
{ hour++;
if(hour>100)hour=0;
while(Add==0);
}
}
if(Dec==0)
{
Delay12864(20);
if(Dec==0)
{hour--;if(hour>100)hour=0;
while(Dec==0);
}
}
}
if(id==5)
{ if(Add==0)
{
Delay12864(20);
if(Add==0)
{ min++;if((min>0xff)||(min<30))min=30;
while(Add==0);
}
}
if(Dec==0)
{
Delay12864(20);
if(Dec==0)
{min--;if((min>0xff)||(min<30))min=30;
while(Dec==0);
}
}
}
if(id==6)
{ if(Add==0)
{
Delay12864(20);
if(Add==0)
{ sec++;if((sec>0xff)||(sec<30))sec=30;
while(Add==0);
}
}
if(Dec==0)
{
Delay12864(20);
if(Dec==0)
{sec--;if((sec>0xff)||(sec<30))sec=30;
while(Dec==0);
}
}
}
if(id==7)
{ if(Add==0)
{
Delay12864(20);
if(Add==0)
{ week++;if(week>100)week=0;
while(Add==0);
}
}
if(Dec==0)
{
Delay12864(20);
if(Dec==0)
{week--;if(week>100)week=0;
while(Dec==0);
}
}
}
if(id==8)
{
id=0;
}
}
}
void Lcd_Mark2(void)
{ write_com(Disp_On);
Mcs=0;Scs=1; //第二屏
f= a[0]/1000%10;
g= a[0]/100%10;
d= a[0]/10%10;
e= a[0]%10;
Disp_Digit(2,16,zero+f*16);
Disp_Digit(2,24,zero+g*16);
Disp_Digit(2,32,zero+d*16);Disp_Digit(2,40,point );
Disp_Digit(2,48,zero+e*16);
f= a[1]/1000%10;
g= a[1]/100&10;
d= a[1]/10%10;
e= a[1]%10;
Disp_Digit(4,16,zero+f*16);
Disp_Digit(4,24,zero+g*16);
Disp_Digit(4,32,zero+d*16); Disp_Digit(4,40,point );
Disp_Digit(4,48,zero+e*16);
Disp_Digit(6,16,zero+( week/10)*16);
Disp_Digit(6,24,zero+( week%10)*16);
}
void Disp(void)//顯示和閃爍函數(shù)
{
unsigned int i=0;
unsigned char a=0,b=0,c=0,f=0;
Clr_Scr();
write_com(Disp_On);
Mcs=1;Scs=0;
Disp_Digit(0,0,space); Disp_Digit(0,8,space);Disp_Digit(0,16,space); Disp_Digit(0,24,space);
Disp_Chinese(0,32,bao);
Disp_Chinese(0,48,hu);
Mcs=1;Scs=0;
{Disp_Chinese(2,0,dya);
Disp_Chinese(2,16,ya);
f=year/1000;
g=year/100; //低壓值
d=year/10%10;
e=year%10;
if(id!=1)
{ Disp_Digit(2,32,zero+f*16);
Disp_Digit(2,40,zero+g*16);
Disp_Digit(2,48,zero+d*16);// Disp_Digit(2,48,point );
Disp_Digit(2,56,zero+e*16);}
if(id==1)
{ Disp_Digit_f(2,32,zero+f*16);
Disp_Digit_f(2,40,zero+g*16);
Disp_Digit_f(2,48,zero+d*16);// Disp_Digit(2,48,point );
Disp_Digit_f(2,56,zero+e*16);}
}
{ g=hour/100;
d=hour/10%10;
e=hour%10;
Mcs=1;Scs=0;
Disp_Chinese(4,0,xian); Disp_Chinese(4,16,shi);
Disp_Digit(4,32,space);
if(id!=4)
{ Disp_Digit(4,40,zero+d*16); Disp_Digit(4,48,point );
Disp_Digit(4,56,zero+e*16);}
if(id==4)
{ Disp_Digit_f(4,40,zero+d*16); Disp_Digit_f(4,48,point );
Disp_Digit_f(4,56,zero+e*16);}
}
{
d=week/10;
e=week%10; //地址
Mcs=1;Scs=0;
Disp_Chinese(6,0,di);
Disp_Chinese(6,16,zhi);
Disp_Digit(6,32,space); Disp_Digit(6,40,space);
if(id!=7)
{ Disp_Digit(6,48,zero+d*16);
Disp_Digit(6,56,zero+e*16);}
if(id==7)
{ Disp_Digit_f(6,48,zero+d*16);
Disp_Digit_f(6,56,zero+e*16);}
}
write_com(Disp_On);
{ Mcs=0;Scs=1; //右
Disp_Chinese(0,0,tiao);
Disp_Chinese(0,16,zheng);
Disp_Digit(0,32,space); Disp_Digit(0,40,space); Disp_Digit(0,48,space); Disp_Digit(0,56,space);
}
{ g=month/100;
d=month/10%10;
e=month%10;
Disp_Digit(2,0,space); Disp_Digit(2,8,space);
Disp_Digit(2,16,K); Disp_Digit(2,24,space);
if(id!=2)
{ Disp_Digit(2,32,zero+g*16);
Disp_Digit(2,40,zero+d*16);
Disp_Digit(2,48,zero+e*16);}
if(id==2)
{ Disp_Digit_f(2,32,zero+g*16);
Disp_Digit_f(2,40,zero+d*16);
Disp_Digit_f(2,48,zero+e*16);}
Disp_Digit(2,56,space);
}
{
d=sec/10%10;
e=sec%10;
Mcs=0;Scs=1;
Disp_Digit(4,0,space); Disp_Digit(4,8,space); Disp_Digit(4,16,space); Disp_Digit(4,24,space);
Disp_Digit(4,32,space); Disp_Digit(4,40,space); Disp_Digit(4,48,space); Disp_Digit(4,56,space);
}
Mcs=0;Scs=1;
{
d=id/10;
e=id%10;
Mcs=0;Scs=1;
Disp_Chinese(6,0,tiao); Disp_Chinese(6,16,zheng);
Disp_Digit(6,32,space);
Disp_Digit(6,40,zero+d*16);//送顯示
Disp_Digit(6,48,zero+e*16);
Disp_Digit(6,56,space);
}
}
復(fù)制代碼
所有資料51hei提供下載:
低壓.rar
(57.7 KB, 下載次數(shù): 8)
2019-11-16 11:02 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
作者:
admin
時(shí)間:
2019-11-19 20:05
本帖需要重新編輯補(bǔ)全電路原理圖,源碼,詳細(xì)說明與圖片即可獲得100+黑幣(帖子下方有編輯按鈕)
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1