#include <REGX52.H>
#include "Delay.h"
#include "LCD1602.h"
#include "XPT2046.h"
#include "Buzzer.h"
#include "LED.h"
unsigned int BATTERY;
unsigned int ADValue;
void main(void)
{
LCD_Init();
LCD_ShowString(1,1,"BATTERY");
while(1)
{
// ADValue=XPT2046_ReadAD(XPT2046_AUX);
ADValue=XPT2046_ReadAD(XPT2046_XP);
if(2048>=ADValue&&ADValue>0){BATTERY=0;}
if(2867>=ADValue&&ADValue>2048){BATTERY=5;}
if(3014>=ADValue&&ADValue>2867){BATTERY=10; }
if(3031>=ADValue&&ADValue>3014){BATTERY=15;}
if(3056>=ADValue&&ADValue>3031){BATTERY=20;}
if(3088>=ADValue&&ADValue>3056){BATTERY=30;}
if(3104>=ADValue&&ADValue>3088){BATTERY=40;}
if(3129>=ADValue&&ADValue>3104){BATTERY=50;}
if(3170>=ADValue&&ADValue>3129){BATTERY=60;}
if(3219>=ADValue&&ADValue>3170){BATTERY=70;}
if(3276>=ADValue&&ADValue>3219){BATTERY=80;}
if(3342>=ADValue&&ADValue>3276){BATTERY=90;}
if(3440>=ADValue&&ADValue>3342){BATTERY=100;}
LCD_ShowNum(2,1,BATTERY,3);
LCD_ShowChar(2,4,0x25);
if(3170>=ADValue&&ADValue>0){LED(1);}
if(3088>=ADValue&&ADValue>0){Buzzer_Time(100);}
Delay(100);
}
}
#include <REGX52.H>
#include "Delay.h"
void LED(unsigned int i)
{
unsigned int j;
for(j=0;j<i;j++)
{
P2=0xfe;
Delay(500);
P2=0xff;
Delay(500);
}
}