#include
#include "iic.h"
#define uchar unsigned char
#define uint unsigned int
uchar code tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xbf,0xff,0xc6};
uchar yi,er,san,si,wu,liu,qi,ba;
uchar led_start=0;
uchar mode=1;//????
uchar set=0;//s6??
uint jiange=400;//????
uint LED_tt=0,set_tt=0,AD_tt=0;//0.8???
uint RB2=0;//AD??
uchar flag4=0;//s4????
uchar LED_n=0;
uchar Light=0,LED_T=0;
void allinit();
void Delay1ms(uint ms);
void display1(uchar yi,uchar er);
void display2(uchar san,uchar si);
void display3(uchar wu,uchar liu);
void display4(uchar qi,uchar ba);
void keyscan();
void Timer0Init(void);
void main()
{
allinit();
Timer0Init();
mode=EEPROM_Read(0x10);
Delay1ms(5);
jiange=EEPROM_Read(0x20)*100;
Delay1ms(5);
yi=11;er=11;san=11;si=11;wu=11;liu=11;qi=11;ba=11;
while(1)
{
// RB2=AD_Read(0x03);
if((set==0)&&(flag4==1))
{
if(RB2<64){yi=11;er=11;san=11;si=11;wu=11;liu=11;qi=10;ba=1;}
else if((RB2>=64)&&(RB2<128)){yi=11;er=11;san=11;si=11;wu=11;liu=11;qi=10;ba=2;}
else if((RB2>=128)&&(RB2<192)){yi=11;er=11;san=11;si=11;wu=11;liu=11;qi=10;ba=3;}
else if((RB2>=192)&&(RB2<255)){yi=11;er=11;san=11;si=11;wu=11;liu=11;qi=10;ba=4;}
}
else if(set==0)
{
yi=11;er=11;san=11;si=11;wu=11;liu=11;qi=11;ba=11;
}
keyscan();
display1(yi,er);
display2(san,si);
display3(wu,liu);
display4(qi,ba);
}
}
void keyscan()
{
if(P30==0)//s7
{
Delay1ms(5);
if(P30==0)
{
if(led_start==0)
led_start=1;
else if(led_start==1)
led_start=0;
}
while(!P30);
}
else if(P31==0)//s6
{
Delay1ms(5);
if(P31==0)
{
if(set==0)
{
set=1;set_tt=0;
if(jiange>=1000)
{
yi=10;er=mode;san=10;si=11;wu=jiange/1000;liu=jiange%1000/100;qi=jiange%100/10;ba=jiange%10;
}
else
{
yi=10;er=mode;san=10;si=11;wu=11;liu=jiange/100;qi=jiange%100/10;ba=jiange%10;
}
}
else if(set==1)
{
set=2;set_tt=0;
if(jiange>=1000)
{
yi=10;er=mode;san=10;si=11;wu=jiange/1000;liu=jiange%1000/100;qi=jiange%100/10;ba=jiange%10;
}
else
{
yi=10;er=mode;san=10;si=11;wu=11;liu=jiange/100;qi=jiange%100/10;ba=jiange%10;
}
}
else if(set==2)
{
set=0;set_tt=0;
yi=11;er=11;san=11;si=11;wu=11;liu=11;qi=11;ba=11;
EEPROM_Write(mode,0x10);
Delay1ms(5);
EEPROM_Write(jiange/100,0x20);
Delay1ms(5);
}
}
while(!P31);
}
else if(P32==0)//s5
{
Delay1ms(5);
if(P32==0)
{
if(set==1)
{
mode+=1;
if(mode>4)
{
mode=4;
}
}
else if(set==2)
{
jiange+=100;
if(jiange>1200)
{
jiange=1200;
}
}
}
while(!P32);
}
else if(P33==0)//s4
{
Delay1ms(5);
if(P33==0)
{
flag4=1;
}
}
if((flag4==1)&&(P33==1))
{
flag4=0;
if(set==1)
{
mode-=1;
if(mode<1)
{
mode=1;
}
}
else if(set==2)
{
jiange-=100;
if(jiange<400)
{
jiange=400;
}
}
}
}
void Timer0Init(void) //[email protected]
{
AUXR |= 0x80; //?????1T??
TMOD &= 0xF0; //???????
TL0 = 0x20; //??????
TH0 = 0xD1; //??????
TF0 = 0; //??TF0??
TR0 = 1; //???0????
EA=1;
ET0=1;
}
void Timer0() interrupt 1
{
set_tt++;
LED_tt++;
AD_tt++;
if((LED_tt==1)&&(led_start==1))//?1ms??????
{
if(mode==1)
{
P2=0X00;P0=0XFF;P2=0X80;P0=~(0X01<
}
else if(mode==2)
{
P2=0X00;P0=0XFF;P2=0X80;P0=~(0X80>>LED_n);P2=0X00;
}
else if(mode==3)
{
P2=0X00;P0=0XFF;P2=0X80;
if(LED_n==0)P0=0X7E;
else if(LED_n==1)P0=0XBD;
else if(LED_n==2)P0=0XDB;
else if(LED_n==3)P0=0XE7;
P2=0X00;
}
else if(mode==4)
{
P2=0X00;P0=0XFF;P2=0X80;
if(LED_n==0)P0=0XE7;
else if(LED_n==1)P0=0XDB;
else if(LED_n==2)P0=0XBD;
else if(LED_n==3)P0=0X7E;
P2=0X00;
}
}
else if(LED_tt==Light)//PWM?? ?????20ms mode1 LED_tt=1? 2-20?? ???5%
// mode2 LED_tt=1-4? ???20%
// mode3 1-9???45% mode4 1-19 ???95%
{
P2=0X00;P0=0XFF;P2=0X80;P0=0XFF;P2=0X00;
}
else if(LED_tt==20)//?20ms???? LED_T +1
{
LED_tt=0;LED_T++;
if((LED_T*20)>=jiange)//?????????? ????
{
LED_T=0;
if(mode==1){LED_n++;if(LED_n>=8)LED_n=0;}
else if(mode==2){LED_n++;if(LED_n>=8)LED_n=0;}
else if(mode==3){LED_n++;if(LED_n>=4)LED_n=0;}
else if(mode==4){LED_n++;if(LED_n>=4)LED_n=0;}
}
}
if(AD_tt==200)//?200ms????RB2?
{
AD_tt=0;
RB2=AD_Read(0x03);
if(RB2<64)Light=2;
else if((RB2>=64)&&(RB2<128))Light=5;
else if((RB2>=128)&&(RB2<192))Light=10;
else if((RB2>=192)&&(RB2<256))Light=19;
}
if(set_tt==800)
{
if(set==1)
{
if(jiange>=1000)
{
yi=11;er=11;san=11;si=11;wu=jiange/1000;liu=jiange%1000/100;qi=jiange%100/10;ba=jiange%10;
}
else
{
yi=11;er=11;san=11;si=11;wu=11;liu=jiange/100;qi=jiange%100/10;ba=jiange%10;
}
}
else if(set==2)
{
if(jiange>=1000)
{
yi=10;er=mode;san=10;si=11;wu=11;liu=11;qi=11;ba=11;
}
else
{
yi=10;er=mode;san=10;si=11;wu=11;liu=11;qi=11;ba=11;
}
}
}
if(set_tt==1600)
{
set_tt=0;
if(set==1)
{
if(jiange>=1000)
{
yi=10;er=mode;san=10;si=11;wu=jiange/1000;liu=jiange%1000/100;qi=jiange%100/10;ba=jiange%10;
}
else
{
yi=10;er=mode;san=10;si=11;wu=11;liu=jiange/100;qi=jiange%100/10;ba=jiange%10;
}
}
else if(set==2)
{
if(jiange>=1000)
{
yi=10;er=mode;san=10;si=11;wu=jiange/1000;liu=jiange%1000/100;qi=jiange%100/10;ba=jiange%10;
}
else
{
yi=10;er=mode;san=10;si=11;wu=11;liu=jiange/100;qi=jiange%100/10;ba=jiange%10;
}
}
}
}
void allinit()
{
P2=0X80;
P0=0XFF;
P2=0XC0;
P0=0XFF;
P2=0XE0;
P0=0XFF;
P2=0XA0;
P0=0X00;
}
void Delay1ms(uint ms) //@12.000MHz
{
uint k;
unsigned char i, j;
for(k=ms;k>0;k--)
{
i = 12;
j = 169;
do
{
while (--j);
} while (--i);
}
}
void display1(uchar yi,uchar er)
{
P2=0XC0;
P0=0X01;
P2=0XE0;
P0=tab[yi];
Delay1ms(1);
P2=0XC0;
P0=0X02;
P2=0XE0;
P0=tab[er];
Delay1ms(1);
}
void display2(uchar san,uchar si)
{
P2=0XC0;
P0=0X04;
P2=0XE0;
P0=tab[san];
Delay1ms(1);
P2=0XC0;
P0=0X08;
P2=0XE0;
P0=tab[si];
Delay1ms(1);
}
void display3(uchar wu,uchar liu)
{
P2=0XC0;
P0=0X10;
P2=0XE0;
P0=tab[wu];
Delay1ms(1);
P2=0XC0;
P0=0X20;
P2=0XE0;
P0=tab[liu];
Delay1ms(1);
}
void display4(uchar qi,uchar ba)
{
P2=0XC0;
P0=0X40;
P2=0XE0;
P0=tab[qi];
Delay1ms(1);
P2=0XC0;
P0=0X80;
P2=0XE0;
P0=tab[ba];
Delay1ms(1);
P2=0XC0;
P0=0XFF;
P2=0XE0;
P0=0XFF;//?????????????
}