單片機智能家居之-窗簾控制器(上電自動識別位置)
//------------------------------------------------------------------------------------
// 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 ;//正轉繼電器端口
sbit FJDQ = P1^1 ;//反轉繼電器端口
sbit HEL = P2^0 ;//左側霍爾檢測端口 暫定左側為窗簾拉開
sbit HER = P2^1 ;//右側霍爾檢測端口 暫定右側為窗簾拉上
extern void Init_Device(void);
uchar code CST_c[8] _at_ 0x1fff; //存儲參數地址
uchar xdata CST_x[8] _at_ 0x1fff;
uchar Flage;
uchar xdata Between[8];
void Flash_Erase_CSP() //flash擦除原來參數
{
EA =0;
//VDM0CN = 0x80;
//RSTSRC = 0x02;
//FLSCL=0X80;
PSCTL |= 0x03; //允許擦,允許寫
FLKEY = 0xA5; // 寫入關鍵字
FLKEY = 0xF1; // 寫入關鍵字
CST_x[0] = 0;//寫入任意數
PSCTL&=~0x03; //禁止寫,禁止擦
//EA = 1;
}
評論