nop();
SCL = 0;
}
u8 I2c_CheckAck(void)
{
u8 rst;
rst = 0;
SDA = 1;
P6CR |= 0x01 ; // SDA set to input
nop();
SCL = 1;
if (!SDA) rst = 1; // have ack
nop();
SCL = 0;
P6CR &= 0xfe ; // SDA set to output
return rst;
}
////////////////////////////////////////////////////////////
// start and stop of i2c bus
void Start(void)
{
SDA = 1;
SCL = 1;
nop();
nop();
SDA = 0;
nop();
nop();
SCL = 0;
nop();
nop();
}
void Stop(void)
{
SDA = 0;
nop();
nop();
SCL = 1;
nop();
nop();
SDA = 1;
nop();
nop();
}#include "EM78x156xx.h"
#include "HEAD156.H"
///////////////////////////////////////////////////
// function declare
void SysInit(void);
u8 KeySCAN(void);
void Beep(s8 time);
void ScanBuz(void);
void StopBeep(void);
void ScanIR(void);
u8 CheckIR(void);
///////////////////////////////////////////////////
// Global Variable
u8 volatile IntrCnt;
u8 MainStatus;
enum{ // main status
PROTECT,
RELEASE,
RUNNING,
ALARM,
};
u8 MsCnt;
#define KEY_DOOR 0X01
#define KEY_ACC 0X02
#define KEY_BREAK 0X04
u8 SaveKey;
u8 Cont;
u8 Trg;
void main()
{
SysInit();
sei();
while(1)
{
wdtc();
if (IntrCnt == 160) // 20ms
{
IntrCnt = 0;
MsCnt++;
ScanBuz();
ScanIR();
if (KeyScan())
{
if (Trg & KEY_DOOR)
{
Beep(1);
nop();
}
if (Trg & KEY_ACC)
{
Beep(1);
nop();
}
if (Trg & KEY_BREAK)
{
nop();
}
}
switch(MsCnt)
{
case 50: // 1s
MsCnt =0;
break;
default:
break;
}
}
}
}
/**************************************************
BUZZER PROCESS ROUTINE
p61
**************************************************/
#define BUZPIN R65
bit bBuzEn=0;
bit bBuzSW;
s8 cntBuzTimes;
u8 cntBuz;
void ScanBuz(void)
{
if (bBuzEn){
上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] 下一页
本文关键字:单片机 无线 程序 义隆单片机,单片机-工控设备 - 义隆单片机