單片機(jī)智能家居之-窗簾控制器(上電自動(dòng)識(shí)別位置)
//------------------------------------------------------------------------------------
// Copyright (C) 2011 Shenyang 818.
// by WEN K
// Tool chain: KEIL Full c
//
//#pragma CD OE DB SB// Compilation directives
#include "C8051F310.h"
#define uint unsigned int
#define uchar unsigned char
sbit LED = P3^3 ;//led 端口
sbit ZJDQ = P1^0 ;//正轉(zhuǎn)繼電器端口
sbit FJDQ = P1^1 ;//反轉(zhuǎn)繼電器端口
sbit HEL = P2^0 ;//左側(cè)霍爾檢測(cè)端口 暫定左側(cè)為窗簾拉開
sbit HER = P2^1 ;//右側(cè)霍爾檢測(cè)端口 暫定右側(cè)為窗簾拉上
extern void Init_Device(void);
uchar code CST_c[8] _at_ 0x1fff; //存儲(chǔ)參數(shù)地址
uchar xdata CST_x[8] _at_ 0x1fff;
uchar Flage;
uchar xdata Between[8];
void Flash_Erase_CSP() //flash擦除原來(lái)參數(shù)
{
EA =0;
//VDM0CN = 0x80;
//RSTSRC = 0x02;
//FLSCL=0X80;
PSCTL |= 0x03; //允許擦,允許寫
FLKEY = 0xA5; // 寫入關(guān)鍵字
FLKEY = 0xF1; // 寫入關(guān)鍵字
CST_x[0] = 0;//寫入任意數(shù)
PSCTL&=~0x03; //禁止寫,禁止擦
//EA = 1;
}
評(píng)論