📄 main.c
字号:
PORTA = PORTA | 0x0d; //enable the display of ones millisecond
Short_delay();
PORTB = 0;
PORTA = PORTA & 0xff; //disable the display
PORTB = mask (down_time[4]);
PORTA = PORTA | 0x09; //enable the display of ones millisecond
Short_delay();
PORTB = 0;
PORTA = PORTA & 0xff; //disable the display
PORTB = mask (down_time[3]);
PORTA = PORTA | 0x0e; //enable the display of ones millisecond
Short_delay();
PORTB = 0;
PORTA = PORTA & 0xff; //disable the display
PORTB = mask (down_time[2]);
PORTA = PORTA | 0x0b; //enable the display of ones millisecond
Short_delay();
PORTB = 0;
PORTA = PORTA & 0xff; //disable the display
PORTB = mask(down_time[1]);
PORTA = PORTA | 0x0c; //enable the display of ones millisecond
Short_delay();
PORTB = 0;
PORTA = PORTA & 0xff; //disable the display
if (down_time[0]== 0)Short_delay();
else
{
PORTA = PORTA | 0x0a; //enable the display of ones millisecond
Short_delay();
PORTA = PORTA & 0xff; //disable the display
}
}
void Delay_sec()
{
Delay_ms (350);
}
void load_default_values()
{
up_time [0] = 0;
up_time [1] = 0;
up_time [2] = 0;
up_time [3] = 0;
up_time [4] = 0;
up_time [5] = 0;
down_time[0] = 1;
down_time[1] = 0;
down_time[2] = 0;
down_time[3] = 0;
down_time[4] = 0;
down_time[5] = 0;
lapsed_count == 0;
}
void alarm()
{
delay = 2000;
do {
if (!flag.f0)
{
offset_up_time2();
}
if (flag.f0)
{
offset_down_time2();
}
delay--;
} while (delay > 0);
PORTA.F3 = 0;
}
void oem_limit()
{
check_value = EEprom_Read(0x00);
Delay_ms (50);
if (check_value == 0)
{
do {
PORTB = 0;
PORTA = 0;
} while(1);
}
else
{
check_value--;
EEprom_Write (0x00,check_value);
Delay_ms (50);
}
}
void main ()
{
PORTA = 0; // clear porta
PORTB = 0; // clear portb
TRISA = 0x30; // PORTA <4:5> as inputs the rest as outputs
TRISB = 0; // make PORTB as outputs
PORTA = 0x07; // initialize the multiplexer
PORTB = 0; // clear portb
OPTION_REG = 0x08; // used WDT for the prescale at 1:1
INTCON.GIE = 1; // enable global interrupts
load_default_values(); // intialize registers
flag.f0 = 0; // set default mode as up counter
flag.f1 = 0; // clear lapsed flag
oem_limit(); // for safety purposes value must be set manually
delay = 3;
do {
repitition = 250;
do {
PORTB = mask (11); //load millisecond value to PORTB
PORTA = PORTA | 0x01; //enable the display of ones millisecond
Short_delay();
PORTB = 0;
PORTA = PORTA & 0xff; //disable the display
PORTB = mask (1); //load millisecond value to PORTB
PORTA = PORTA | 0x05; //enable the display of ones millisecond
Short_delay();
PORTB = 0;
PORTA = PORTA & 0xff; //disable the display
repitition--;
} while (repitition > 0);
Delay_sec();
delay--;
} while (delay > 0); //repeat until delay is zero
while (1)
{
if (!flag.f0) offset_up_time();
if (flag.f0) offset_down_time();
if ((PORTA & 0x30) == 0x30)// change mode button has been triggered
{
if (!INTCON.T0IE) // if the timer is off
{
delay = 3;
if (!flag.f0)
{
flag.f0 = 1; //change mode as down counter
do {
repitition = 250;
do {
PORTB = mask (11); //load millisecond value to PORTB
PORTA = PORTA | 0x01; //enable the display of ones millisecond
Short_delay();
PORTB = 0;
PORTA = PORTA & 0xff; //disable the display
PORTB = mask (2); //load millisecond value to PORTB
PORTA = PORTA | 0x05; //enable the display of ones millisecond
Short_delay();
PORTB = 0;
PORTA = PORTA & 0xff; //disable the display
repitition--;
} while (repitition > 0);
Delay_sec();
delay--;
} while (delay > 0);
goto exit1
}
if (flag.f0)
{
flag.f0 = 0; //change mode as up counter
do {
repitition = 250;
do {
PORTB = mask (11); //load millisecond value to PORTB
PORTA = PORTA | 0x01; //enable the display of ones millisecond
Short_delay();
PORTB = 0;
PORTA = PORTA & 0xff; //disable the display
PORTB = mask (1); //load millisecond value to PORTB
PORTA = PORTA | 0x05; //enable the display of ones millisecond
Short_delay();
PORTB = 0;
PORTA = PORTA & 0xff; //disable the display
repitition--;
} while (repitition > 0);
Delay_sec();
delay--;
} while (delay > 0);
}
exit1: load_default_values();
flag.f2 = 1;//set reset flag
}
}
//------------------------------------------------------------------------------
if ((PORTA & 0x30)== 0x20) // stop/show button has been triggered
{
if (INTCON.T0IE)
{
INTCON.T0IE = 0;
flag.f1 = 0; // flag.f1 is used as the the lapsed flag
alarm();
goto exit2
}
if (!INTCON.T0IE)
{
delay = 500;
do {
if (flag.f0) offset_up_time();
if (!flag.f0) offset_down_time();
delay--;
if ((PORTA & 0x20) == 0x20) delay = 500;
} while (delay >0);
}
exit2: PORTA.F3 = 0;
}
//-----------------------------------------------------------------------------
if ((PORTA & 0x30) == 0x10) // start button bas been triggered
{
if (!INTCON.T0IE && flag.f2 )
{
lapsed_count = 0;
INTCON.T0IE = 1;
TMR0 = 0;
flag.f1 = 0;
flag.f2 = 0;
}
}
//------------------------------------------------------------------------------
if (PORTB.F0) // reset button has been triggerred
{
if (!INTCON.T0IE)
{
load_default_values();
flag.f2 = 1;//set the reset flag
}
}
//------------------------------------------------------------------------------
if (flag.f1 && !INTCON.T0IE)// lapsed time indication
{
INTCON.T0IE = 0;
flag.f1 = 0; // flag.f1 is used as the the lapsed flag
alarm();
PORTA.F3 = 0;
}
//------------------------------------------------------------------------------
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -