单片机源程序如下:
- #include<reg52.h>
- #include<intrins.h>
- #include"iic.h"
- #include"key.h"
- unsigned char num,flag;
- unsigned char Voltage=0; //光敏电阻采样电压
- void main()
- {
- Timer_Init();
- ADC_Init();
- while(1)
- {
- KEY_Scan();
- P0=0xff;
- LED_Pro(); //指示灯
- Display_Pro();
- Display();
- P0=0x00;
- RELAY_Pro(); //继电器
- if(flag)
- {
- flag=0;
- Voltage=ADC_Read(); //读取光敏电阻采样电压
- if(Voltage<64)
- {
- LED_flag=0;
- }
- else
- {
- LED_flag=1;
- }
- }
- }
- }
- void T0_Ser() interrupt 1
- {
- TH0=(65536-45872)/256;
- TL0=(65536-45872)%256;
- if(++num==2) //100Ms
- {
- num=0;
- flag=1;
- if(RELAY_flag==0)
- {
- Water++; //每100Ms出水0.01升
- }
- if(Water==9999)
- {
- Water=0;
- RELAY_flag=1;
- }
- Price=Water*0.5;
- }
- }
复制代码
所有资料51hei提供下载:
显示加按键.zip
(28.43 KB, 下载次数: 8)
2012单片机设计与开发项目模拟试题.pdf
(544.22 KB, 下载次数: 6)
|