#include "SN8F5701.H"
/******************************************************************************\
*
* @brief main PZ-PA026 Project
*
* @note none
*
* @author LuoPeng
*
*
\******************************************************************************/
sbit k1 = P0 ^ 4;
#define LED1 P05
bit f_k1;
uint8_t num = 0;
void KEY_prs(void);
void delay(uint8_t x);
void Led_off(void);
void delay(uint8_t x)
{
uint8_t a, b;
for (a = x; a > 0; a--)
for (b = 110; b > 0; b--)
;
}
void key(void)
{
if (f_k1)
{
if (k1 == 0)
{
delay(10);
if (k1 == 0)
{
f_k1 = 0;
LED1 = ~LED1;
}
}
}
else if (k1)
f_k1 = 1;
}
void mcu_config(void)
{
uint16_t delay_timer = 50000;
uint8_t delay_timer1 = 0;
// CLR_WDT();
IEN0 = 0x00;
/** !< CLKSEL Register (0xE5) CLKSEL[2:0] : 110: fcpu = fosc / 2 !> */
CLKSEL = 0x06; // fcpu = 32M / 2 = 16M
CLKCMD = 0X69;
/** !< CKCON Register 6..4 PWSC[2:0] : 001: 1 cycle !> */
CKCON = 0X10; // ROM 2 cycles 16M
/** !< TIMER information !> */
TH0 = 0xFF;
TL0 = 0xFF;
TH1 = 0xFF;
TL1 = 0xFF;
/** !< T0/T1 mode1, clock source from Fcpu/12, 1.33uS !> */
// TMOD |= T0Mode1 | T0ClkFcpu;
/** !< Timer 0/1 enable. Clear TF0/TF1 !> */
TCON |= 0x10;
/** !< Enable T0 interrupt !> */
IEN0 |= 0x02;
/** !< Enable total interrupt >!*/
IEN0 |= 0x80;
/** !< Enable total interrupt >!*/
IEN0 |= 0x80;
P0M |= (1 << 4 | 1 << 1 | 1 << 2 | 1 << 3 | 1 << 5 | 1 << 0);
P0M &= ~(1 << 4); // P04 ÊäÈëģʽ
P0UR |= (1 << 4); //ʹÄÜP04ÉÏÀ
}
void main(void)
{
f_k1 = 1;
mcu_config();
delay(200);
while (1)
{
key();
delay(500);
f_k1 = 1;
delay(500);
f_k1 = 0;
// delay(200); delay(200); LED1=~LED1;
// CLR_WDT();
// if(f_time_10ms)
// {
// f_time_10ms =0;
// }
}
}