?nixie.c
#include <sys.h>
#include <onewire.h>
uchar nixie[] = {0XC0, 0XF9, 0XA4, 0XB0, 0X99, 0X92, 0X82, 0XF8, 0X80, 0X90, 0XBF, 0XFF};
//0~9 - 熄灭
uchar interval = 1;//采集时间间隔
uchar interface = 0;//显示界面
uchar index = 0;//0-9
uint temp[10] = {0};//温度收集
uchar temp_num = 0;
void DisplayBit(uchar pos,uchar value)
{
Select_74HC138(7);
P0 = 0XFF;
Select_74HC138(6);
P0 = _crol_(0X01,pos);
Select_74HC138(7);
P0 = nixie[value];
Delay(1);
Select_74HC138(0);
}
void Display_Interval()
{
DisplayBit(5,10);
DisplayBit(6,interval / 10);
DisplayBit(7,interval % 10);
}
void Display_Time()
{
Get_DS1302();
DisplayBit(0,Time[2] / 10);
DisplayBit(1,Time[2] % 10);
if(Time[0] % 2 == 0)
DisplayBit(2,10);
else
DisplayBit(2,11);
DisplayBit(3,Time[1] / 10);
DisplayBit(4,Time[1] % 10);
if(Time[0] % 2 == 0)
DisplayBit(5,10);
else
DisplayBit(5,11);
DisplayBit(6,Time[0] / 10);
DisplayBit(7,Time[0] % 10);
}
void Collect_Temper()
{
if(interface == 1)
{
if(temp_num < 10)
{
if(temp_control == 1)
{
temp[index] = Temper_Get();
temp_control = 0;
index++;
temp_num++;
}
}
else if(temp_num >= 10)
{
Led = 1;
}
}
}
void Display_Temp()
{
DisplayBit(0,10);
DisplayBit(1,index / 10);
DisplayBit(2,index % 10);
DisplayBit(5,10);
DisplayBit(6,temp[index] / 10);
DisplayBit(7,temp[index] % 10);
}
void DisplaySMG()
{
switch(interface)
{
case 0: Display_Interval(); break;
case 1: Display_Time(); break;
case 2: Display_Temp(); break;
}
}
sys.c
#include <sys.h>
#include <onewire.h>
void Select_74HC138(uchar channel)
{
switch(channel)
{
case 0: P2 = P2 & 0X1F; break;
case 4: P2 = (P2 & 0X1F) | 0X80; break;
case 5: P2 = (P2 & 0X1F) | 0XA0; break;
case 6: P2 = (P2 & 0X1F) | 0XC0; break;
case 7: P2 = (P2 & 0X1F) | 0XE0; break;
}
}
void Init_System()
{
uchar i;
Select_74HC138(4);
P0 = 0XFF;
Select_74HC138(5);
P0 = 0X00;
Select_74HC138(7);
P0 = 0XFF;
Select_74HC138(0);
for(i = 0; i < 50; i++)
{
Temper_Get();
}
}
void Delay(uint ms)
{
uint i;
for(ms; ms > 0; ms--)
for(i = 921; i > 0; i--);
}
//==========================================
uchar temp_control = 1;
uchar temp_count = 0;//取样时间间隔
void InitTimer0()//5MS
{
AUXR |= 0X80;
TMOD &= 0XF0;
TL0 = 0XA0;
TH0 = 0X15;
TF0 = 0;
TR0 = 1;
ET0 = 1;
EA = 1;
}
void ServiceTimer0() interrupt 1
{
if(temp_control == 0)
{
temp_count++;
}
if(temp_count >= interval * 200)
{
temp_count = 0;
temp_control = 1;
}
}
//==========================================
uchar Led = 0;
void LedWorking()
{
Select_74HC138(0);
if(Led == 1)
P0 = 0XFE;
else if(Led == 0)
P0 = 0XFF;
Select_74HC138(4);
}
key.c
#include <sys.h>
void KeyScans()
{
uchar i;
if(s4 == 0)
{
Delay(10);
if(s4 == 0)
{
if(interface == 0)
{
if(interval == 1)
interval = 5;
else if(interval == 5)
interval = 30;
else if(interval == 30)
interval = 60;
else if(interval == 60)
interval = 1;
}
while(s4 == 0)
{
DisplaySMG();
}
}
}
if(s5 == 0)
{
Delay(10);
if(s5 == 0)
{
if(interface == 0)
interface = 1;
while(s5 == 0)
{
DisplaySMG();
}
}
}
if(s6 == 0)
{
Delay(10);
if(s6 == 0)
{
if(interface == 1)
interface = 2;
if(interface == 2)
{
index++;
if(index >= 10)
index = 0;
}
if(Led == 1)
Led = 0;
while(s6 == 0)
{
DisplaySMG();
}
}
}
if(s7 == 0)
{
Delay(10);
if(s7 == 0)
{
if(interface == 2)
interface = 0;
temp_num = 0;
index = 0;
temp_control = 1;
for(i = 0; i < 10; i++)
{
temp[i] = 0;
}
}
}
}
main.c
#include <sys.h>
#include <onewire.h>
void main()
{
Init_System();
Set_DS1302();
InitTimer0();
while(1)
{
KeyScans();
Collect_Temper();
DisplaySMG();
LedWorking();
}
}
sys.h
#ifndef _SYS_H_
#define _SYS_H_
#include <STC15F2K60S2.H>
#include <intrins.h>
sbit s4 = P3^3;
sbit s5 = P3^2;
sbit s6 = P3^1;
sbit s7 = P3^0;
#define uchar unsigned char
#define uint unsigned int
extern unsigned char interval;//采集时间间隔
extern unsigned char interface;//现实的界面
extern unsigned char temp_control;//温度采集控制
extern unsigned char index,temp_num;//温度采样个数
extern unsigned int temp[10];
extern unsigned char Led;
//sys.c
void Select_74HC138(unsigned char channel);
void Init_System();
void Delay(unsigned int ms);
void InitTimer0();
void LedWorking();
//nixie.c
void DisplayBit(unsigned char pos,unsigned char value);
void Display_Interval();
void Display_Time();
void Collect_Temper();
void Display_Temp();
void DisplaySMG();
//key.c
void KeyScans();
#endif
|