|
|
楼主 |
发表于 2017-1-12 23:58:40
|
显示全部楼层
#include <reg51.h>
#include <intrins.h>
#include "12864Data.h"
#include "stc12c.h"
#include "lcd12864.h"
#include "ADC.h"
#define u8 unsigned char
#define u16 unsigned int
/*******萝莉控LCD引脚***************/
/*
sbit CS=P0^6;
sbit RST=P0^7;
sbit RS=P4^6;
sbit SDA=P4^5;
sbit SCK=P4^4;
*/
u16 CH1,CH2,CH3,CH4,CH5,CH6,CH7,V1;//
sbit LEDA=P2^5;//LCD背光
sbit led = P0^2;
u16 adc;
u8 lcd[6];//显示缓存
uchar aa,bb;
uint time, timea, timeb;
void ET0init(); //定时器0初始化
void init (); //硬件初始化
void main(void)
{
init ();
ET0init ();
LEDA=1;
delay_n_10us(100);//延时100ms等待稳定运行
InitLCD();
ClearScreen();
Display128x64(lcd_128x64);
//lcd[6]=' ';
//lcd[7]=' ';
//lcd[8]=' ';
//lcd[9]=' ';
while(1)
{
Display8x16(1,0,"L");
Display8x16(1,8,"D");
Display8x16(1,16,"Y");
Display5x7(1,52,"0");
Display5x7(1,60,"B");
Display5x7(1,68,"T");
Display8x16(2,28,"F");
Display8x16(2,36,"2");
Display8x16(2,44,"2");
if(adcs(4)>=12)//油门大于12开始计时
{
TR0=1;//启动定时器
lcd[0]= timea/10+48;
lcd[1]= timea+48;
lcd[2]=':';
lcd[3]= time0/10+48;
lcd[4]= time00+48;
Display8x16(2,74,lcd);
}
CH3=adcs(4);//*CH3代表4通道检测到的ADC值**/
lcd[0]= CH3/1000+48;
lcd[1]= CH300/100+48;
lcd[2]= CH30/10+48;
lcd[3]= CH300+48;
lcd[4]=' ';
Display5x7(5,30,lcd);
Display5x7(5,8,"C");
Display5x7(5,14,"H");
Display5x7(5,20,"3");
}
}
void ET0init()//外部中断0初始化
{
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%6;
EA=1;//开总中断
ET0=1;//开定时器中断
//TR0=1;//启动定时器
aa=0;
time=0;
}
void init () //硬件初始化
{
LEDA=0;
P4SW=0x70; //允许P4 IO
P2M0=0x20; //推挽点亮背光
}
void timer0() interrupt 1
{
TH0=(65536-50000)/256; //每50MS产生一次中断,
TL0=(65536-50000)%6; //给寄存器装初值并累加aa
aa++;
bb++;
TR0=0;//关定时器
if(bb>=10) //如果到了0.5S
{
led=~led;
bb=0; //清零
}
if(aa>=20) //如果到了1S
{
aa=0; //清零aa
time++;//秒自增1
}
if(time>=60)//如果到了1分钟
{time=0;//秒清零
timea++;//分自增1
}
if(timea>=60)//如果到了1小时
{timea=0;//分清零
timeb++;//小时自增1
}
if(timeb>=24)//如果到了24小时
{
timeb=0;//小时清零
//led=1;//到了24小时关掉LED
//TR0=0;//到了24小时关掉定时器
}
}
|
| |