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; // 设置时间按键
sbit KeySet2_P = P3^5; // 设置时间模式的开关时间和光照控制强度
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; // 关闭窗帘的小时
uchar CloseMinute = 30; // 关闭窗帘的分钟
uchar gLight = 40; // 窗帘开关的阈值
uchar code Clock[]={0x10,0x20,0x40,0x80}; // 步进电机顺时针旋转数组
uchar code AntiClock[]={0x80,0x40,0x20,0x10}; // 步进电机逆时针旋转数组
uchar TimeBuff[7]={17,9,1,6,18,30,40}; // 时间数组
// 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转换结果
/*********************************************************/
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_(); // 结束此次传输
ADC_DAT = 1;
ADC_CLK = 1;
ADC_CS = 1;
if(dat1==dat2) // 返回采集结果
return dat1;
else
return 0;
}
/*********************************************************/
// 开窗
/*********************************************************/
void Open()
{
uint i,j;
for(j=0;j<255;j++) // 控制步进电机正转
{
for(i=0;i<4;i++)
{
P2=Clock[ i];
DelayMs(3);
}
}
Led_P=0;
}
/*********************************************************/
// 关窗
/*********************************************************/
void Close()
{
uint i,j;
for(j=0;j<255;j++) // 控制步进电机反转
{
for(i=0;i<4;i++)
{
P2=AntiClock[ i];
DelayMs(3);
}
}
Led_P=1;
}
/*********************************************************/
// 主函数
/*********************************************************/
void main()
{
uchar light;
LcdInit(); // 执行液晶初始化
DS1302_Init(); // 时钟芯片的初始化
LcdShowInit(); // 液晶显示内容的初始化
if(DS1302_Read_Byte(0x81)>=128) // 判断时钟芯片是否正在运行
DS1302_Write_Time(); // 如果没有,则初始化一个时间
while(1)
{
DS1302_Read_Time(); // 获取当前时钟芯片的时间,存在数组time_buf中
FlashTime(); // 刷新时间显示
light=Get_ADC0832(); // 读取光照强度
light=light/2.5; // 缩小光照检测结果(在0-99)
if(light>99) // 如果大于99
light=99; // 则依然保持99
LcdGotoXY(1,14); // 光标定位
LcdPrintNum(light); // 显示光照强度
KeyScanf1(); // 按键扫描(时间的设置)
KeyScanf2(); // 按键扫描(阈值的设置)
KeyScanf3(); // 按键扫描(模式切换)
/*手动控制模式*/
if(gMode==1)
{
if(KeyDown_P==0) // 如果关窗帘键按下了
{
if(Led_P==0) // 如果窗帘当前是打开的
{
Close(); // 则光闭窗帘
}
}
if(KeyUp_P==0) // 如果开窗帘键按下了
{
if(Led_P==1) // 如果窗帘当前是关闭的
{
Open(); // 则打开窗帘
}
}
}
/*时间控制模式*/
if(gMode==2)
{
if((TimeBuff[4]==CloseHour)&&(TimeBuff[5]==CloseMinute)&&(TimeBuff[6]==0))
{
if(Led_P==0) // 如果窗帘当前是打开的
{
Close(); // 则光闭窗帘
}
}
if((TimeBuff[4]==OpenHour)&&(TimeBuff[5]==OpenMinute)&&(TimeBuff[6]==0)) {
if(Led_P==1) // 如果窗帘当前是关闭的
{
Open(); // 则打开窗帘
}
}
}
/*光线控制模式*/
if(gMode==3)
{
if(light<gLight) // 当前光线小于设置的阈值
{
if(Led_P==0) // 如果窗帘当前是打开的
{
Close(); // 则光闭窗帘
}
}
else // 当前光线大于或等于设置的阈值
{
if(Led_P==1) // 如果窗帘当前是关闭的
{
Open(); // 则打开窗帘
}
}
}
DelayMs(100); // 延时0.1秒
}
} |