Skip to content

Instantly share code, notes, and snippets.

@wwng2333
Created November 20, 2019 09:50
Show Gist options
  • Save wwng2333/3a455fb6468677a83e7a1b8be5abab9a to your computer and use it in GitHub Desktop.
Save wwng2333/3a455fb6468677a83e7a1b8be5abab9a to your computer and use it in GitHub Desktop.
#include "STC8.h"
#include "intrins.h"
sbit PWRSW1 = P5^4;
sbit PWRSW2 = P3^3;
sbit PWRDET = P5^5;
sbit PWRBTN = P3^2;
void Delay100ms() //@11.0592MHz
{
unsigned char i, j, k;
_nop_();
i = 6;
j = 157;
k = 59;
do
{
do
{
while (--k);
} while (--j);
} while (--i);
}
void GPIO_Init(void)
{
P3M0 = 0xFF;
P3M1 = 0xFF;
P5M0 = 0xFF;
P5M1 = 0xFF; //all IO open drain
}
void main(void)
{
bit SW_Status;
GPIO_Init();
if((PWRSW1 == 1) & (PWRSW2 == 0)) SW_Status = 0;
if((PWRSW1 == 0) & (PWRSW2 == 1)) SW_Status = 1;
while(1)
{
if(PWRBTN == 1)
{
if(SW_Status)
{
PWRSW2 = 0;
Delay100ms();
PWRSW2 = 1;
}
else
{
PWRSW1 = 0;
Delay100ms();
PWRSW1 = 1;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment