|
Build target 'Target 1'
assembling STARTUP.A51...
compiling qizhong.c...
QIZHONG.C(117): warning C206: 'DelayMs': missing function-prototype
QIZHONG.C(117): error C267: 'DelayMs': requires ANSI-style prototype
Target not created
代碼
#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char // 以后unsigned char就可以用uchar代替
#define uint unsigned int // 以后unsigned int 就可以用uint 代替
sbit ADC_CS = P1^6; // ADC0832的CS引腳
sbit ADC_CLK = P1^7; // ADC0832的CLK引腳
sbit ADC_DAT = P3^2; // ADC0832的DI/DO引腳
sbit SCK_P = P1^0; // 時鐘芯片DS1302的SCK管腳
sbit SDA_P = P1^1; // 時鐘芯片DS1302的SDA管腳
sbit RST_P = P1^2; // 時鐘芯片DS1302的RST管腳
sbit LcdRs_P = P1^3; // 1602液晶的RS管腳
sbit LcdRw_P = P1^4; // 1602液晶的RW管腳
sbit LcdEn_P = P1^5; // 1602液晶的EN管腳
sbit KeyMode_P = P3^3; // 模式切換
sbit KeySet_P = P3^4; // 設(shè)置時間按鍵
sbit KeySet2_P = P3^5; // 設(shè)置時間模式的開關(guān)時間和光照控制強(qiáng)度
sbit KeyDown_P = P3^6; // 減按鍵
sbit KeyUp_P = P3^7; // 加按鍵
sbit Led_P = P2^0; // 指示燈
uchar gMode=1; // 1是手動模式,2是時間自動模式,3是亮度自動模式
uchar OpenHour = 18; // 開啟窗簾的小時
uchar OpenMinute = 20; // 開啟窗簾的分鐘
uchar CloseHour = 10; // 關(guān)閉窗簾的小時
uchar CloseMinute = 30; // 關(guān)閉窗簾的分鐘
uchar gLight = 40; // 窗簾開關(guān)的閾值
uchar code Clock[]={0x10,0x20,0x40,0x80}; // 步進(jìn)電機(jī)順時針旋轉(zhuǎn)數(shù)組
uchar code AntiClock[]={0x80,0x40,0x20,0x10}; // 步進(jìn)電機(jī)逆時針旋轉(zhuǎn)數(shù)組
uchar TimeBuff[7]={17,9,1,6,18,30,40}; // 時間數(shù)組
// TimeBuff[0] 代表年份,范圍00-99
// TimeBuff[1] 代表月份,范圍1-12
// TimeBuff[2] 代表日期,范圍1-31
// TimeBuff[3] 代表星期,范圍1-7
// TimeBuff[4] 代表小時,范圍00-23
// TimeBuff[5] 代表分鐘,范圍00-59
// TimeBuff[6] 代表秒鐘,范圍00-59
/*********************************************************/
// ADC0832的時鐘脈沖
/*********************************************************/
void WavePlus()
{
_nop_();
ADC_CLK = 1;
_nop_();
ADC_CLK = 0;
}
/*********************************************************/
// 獲取指定通道的A/D轉(zhuǎn)換結(jié)果
/*********************************************************/
uchar Get_ADC0832()
{
uchar i;
uchar dat1=0;
uchar dat2=0;
ADC_CLK = 0; // 電平初始化
ADC_DAT = 1;
_nop_();
ADC_CS = 0;
WavePlus(); // 起始信號
ADC_DAT = 1;
WavePlus(); // 通道選擇的第一位
ADC_DAT = 0;
WavePlus(); // 通道選擇的第二位
ADC_DAT = 1;
for(i=0;i<8;i++) // 第一次讀取
{
dat1<<=1;
WavePlus();
if(ADC_DAT)
dat1=dat1|0x01;
else
dat1=dat1|0x00;
}
for(i=0;i<8;i++) // 第二次讀取
{
dat2>>= 1;
if(ADC_DAT)
dat2=dat2|0x80;
else
dat2=dat2|0x00;
WavePlus();
}
_nop_(); // 結(jié)束此次傳輸
ADC_DAT = 1;
ADC_CLK = 1;
ADC_CS = 1;
if(dat1==dat2) // 返回采集結(jié)果
return dat1;
else
return 0;
}
/*********************************************************/
// 開窗
/*********************************************************/
void Open()
{
uint i,j;
for(j=0;j<255;j++) // 控制步進(jìn)電機(jī)正轉(zhuǎn)
{
for(i=0;i<4;i++)
{
P2=Clock[ i];
DelayMs(3);
}
}
Led_P=0;
}
/*********************************************************/
// 關(guān)窗
/*********************************************************/
void Close()
{
uint i,j;
for(j=0;j<255;j++) // 控制步進(jìn)電機(jī)反轉(zhuǎn)
{
for(i=0;i<4;i++)
{
P2=AntiClock[ i];
DelayMs(3);
}
}
Led_P=1;
}
/*********************************************************/
// 主函數(shù)
/*********************************************************/
void main()
{
uchar light;
LcdInit(); // 執(zhí)行液晶初始化
DS1302_Init(); // 時鐘芯片的初始化
LcdShowInit(); // 液晶顯示內(nèi)容的初始化
if(DS1302_Read_Byte(0x81)>=128) // 判斷時鐘芯片是否正在運(yùn)行
DS1302_Write_Time(); // 如果沒有,則初始化一個時間
while(1)
{
DS1302_Read_Time(); // 獲取當(dāng)前時鐘芯片的時間,存在數(shù)組time_buf中
FlashTime(); // 刷新時間顯示
light=Get_ADC0832(); // 讀取光照強(qiáng)度
light=light/2.5; // 縮小光照檢測結(jié)果(在0-99)
if(light>99) // 如果大于99
light=99; // 則依然保持99
LcdGotoXY(1,14); // 光標(biāo)定位
LcdPrintNum(light); // 顯示光照強(qiáng)度
KeyScanf1(); // 按鍵掃描(時間的設(shè)置)
KeyScanf2(); // 按鍵掃描(閾值的設(shè)置)
KeyScanf3(); // 按鍵掃描(模式切換)
/*手動控制模式*/
if(gMode==1)
{
if(KeyDown_P==0) // 如果關(guān)窗簾鍵按下了
{
if(Led_P==0) // 如果窗簾當(dāng)前是打開的
{
Close(); // 則光閉窗簾
}
}
if(KeyUp_P==0) // 如果開窗簾鍵按下了
{
if(Led_P==1) // 如果窗簾當(dāng)前是關(guān)閉的
{
Open(); // 則打開窗簾
}
}
}
/*時間控制模式*/
if(gMode==2)
{
if((TimeBuff[4]==CloseHour)&&(TimeBuff[5]==CloseMinute)&&(TimeBuff[6]==0))
{
if(Led_P==0) // 如果窗簾當(dāng)前是打開的
{
Close(); // 則光閉窗簾
}
}
if((TimeBuff[4]==OpenHour)&&(TimeBuff[5]==OpenMinute)&&(TimeBuff[6]==0)) {
if(Led_P==1) // 如果窗簾當(dāng)前是關(guān)閉的
{
Open(); // 則打開窗簾
}
}
}
/*光線控制模式*/
if(gMode==3)
{
if(light<gLight) // 當(dāng)前光線小于設(shè)置的閾值
{
if(Led_P==0) // 如果窗簾當(dāng)前是打開的
{
Close(); // 則光閉窗簾
}
}
else // 當(dāng)前光線大于或等于設(shè)置的閾值
{
if(Led_P==1) // 如果窗簾當(dāng)前是關(guān)閉的
{
Open(); // 則打開窗簾
}
}
}
DelayMs(100); // 延時0.1秒
}
} |
|