860662665747408所有整合1.zip
立即下载
资源介绍:
860662665747408所有整合1.zip
#include
#include "hc138.h"
#include "showsmg.h"
#include "delay.h"
#include "chaoshengbo.h"
#include "key.h"
#include "ds1302.h"
#include "pcf8591.h"
#include "uart.h"
#include
#include "onewire.h"
#include "at24c02.h"
unsigned char dis;
//秒,分,时,日,月,周,年
unsigned char time[]={0x50,0x59,0x23,0x09,0x06,0x05,0x23};
unsigned char ds1302[]={0x80,0x82,0x84,0x86,0x88,0x8a,0x8c};
unsigned char keynum,keytemp;
unsigned char mode;
unsigned int t0count,t1count,t3count,F;
unsigned int T,pwm;
unsigned char U;
unsigned char num;
void ds1302_init()
{
unsigned char i;
Write_Ds1302_Byte(0x8e,0x00);
for(i=0;i<7;i++)
{
Write_Ds1302_Byte(ds1302[i],time[i]);
}
Write_Ds1302_Byte(0x8e,0x80);
}
void ds1302_read()
{
unsigned char i;
for(i=0;i<7;i++)
{
time[i]=Read_Ds1302_Byte(ds1302[i]+0x01);
}
}
void smgrun()
{
if(mode==0)
{
dis=receive_wave();
showsmgNodot(0,mode);
showsmgNodot(3,pwm/10);
showsmgNodot(4,pwm%10);
showsmgNodot(6,dis/10);
showsmgNodot(7,dis%10);
}
if(mode==1)
{
showsmgNodot(0,time[2]/16);
showsmgNodot(1,time[2]%16);
showsmgNodot(3,time[1]/16);
showsmgNodot(4,time[1]%16);
showsmgNodot(6,time[0]/16);
showsmgNodot(7,time[0]%16);
}
if(mode==2)
{
showsmgNodot(0,time[6]/16);
showsmgNodot(1,time[6]%16);
showsmgNodot(3,time[4]/16);
showsmgNodot(4,time[4]%16);
showsmgNodot(6,time[3]/16);
showsmgNodot(7,time[3]%16);
}
if(mode==3)
{
showsmgNodot(0,mode);
showsmgNodot(2,t3count/100);
showsmgNodot(3,t3count/10%10);
showsmgNodot(4,t3count%10);
showsmgNodot(6,time[5]/16);
showsmgNodot(7,time[5]%16);
}
if(mode==4)
{
showsmgNodot(0,mode);
showsmgNodot(3,F/10000);
showsmgNodot(4,F/1000%10);
showsmgNodot(5,F/100%10);
showsmgNodot(6,F/10%10);
showsmgNodot(7,F%10);
}
if(mode==5)
{
showsmgNodot(0,mode);
U=pcf8591_ADC(0x03);
showsmgNodot(5,U/100%10);
showsmgNodot(6,U/10%10);
showsmgNodot(7,U%10);
}
if(mode==6)
{
showsmgNodot(0,mode);
U=pcf8591_ADC(0x01);
showsmgNodot(5,U/100%10);
showsmgNodot(6,U/10%10);
showsmgNodot(7,U%10);
}
if(mode==7)
{
showsmgNodot(0,mode);
pcf8591_DAC(U);
showsmgNodot(5,U/100%10);
showsmgNodot(6,U/10%10);
showsmgNodot(7,U%10);
}
if(mode==8)
{
showsmgNodot(0,mode);
showsmgNodot(7,uart_num);
}
if(mode==9)
{
T=ds18b20();
showsmgNodot(0,mode);
showsmgNodot(4,T/1000);
showsmgdot(5,T/100%10);
showsmgNodot(6,T/10%10);
showsmgNodot(7,T%10);
}
if(mode==10)
{
showsmgNodot(0,mode);
showsmgNodot(5,num/100);
showsmgNodot(6,num/10%10);
showsmgNodot(7,num%10);
}
}
void keyrun()
{
keynum=key();
if(keynum!=keytemp)
{
Delay(10);
}
if(keynum==0 && keytemp==1)
{
at24c02_write(1,123);
Delay(100);
num=at24c02_read(1);
Delay(100);
}
if(keynum==0 && keytemp==2)
{
mode++;
mode%=11;
}
if(keynum==0 && keytemp==3)
{
U++;
pwm+=10;
}
if(keynum==0 && keytemp==4)
{
U--;
pwm-=10;
}
keytemp=keynum;
}
void LEDrun()
{
hc138(4);
if(t1count%100<=pwm)
{
P0=0x00;
// t3count=0;
}
if(t1count%100>pwm)
{
P0=0xff;
}
hc138(0);
}
void Timer0_Init(void) //1微秒@12.000MHz
{
AUXR &= 0x7F; //定时器时钟12T模式
TMOD &= 0xF0; //设置定时器模式
TMOD |= 0x06; //设置定时器模式
TL0 = 0xFF; //设置定时初始值
TH0 = 0xFF; //设置定时重载值
TF0 = 0; //清除TF0标志
TR0 = 1; //定时器0开始计时
ET0 = 1; //使能定时器0中断
EA=1;
}
void Timer1_Init(void) //20毫秒@12.000MHz
{
AUXR &= 0xBF; //定时器时钟12T模式
TMOD &= 0x0F; //设置定时器模式
TL1 = 0xB0; //设置定时初始值
TH1 = 0x3C; //设置定时初始值
TF1 = 0; //清除TF1标志
TR1 = 1; //定时器1开始计时
ET1 = 1; //使能定时器1中断
}
void Timer3_Init(void) //100微秒@12.000MHz
{
T4T3M |= 0x02; //定时器时钟1T模式
T3L = 0x50; //设置定时初始值
T3H = 0xFB; //设置定时初始值
T4T3M |= 0x08; //定时器3开始计时
IE2 |= 0x20; //使能定时器3中断
}
void system_init()
{
hc138(4);
P0=0xff;
hc138(5);
P0=0x00;
hc138(0);
}
void main()
{
Timer0_Init();
Timer1_Init();
Timer3_Init();
system_init();
ds1302_init();
UartInit();
printf("hello\r\n");
while(1)
{
keyrun();
smgrun();
LEDrun();
ds1302_read();
if(uart_num==1)
{
uart_num=0;
printf("$%s",uart);
}
}
}
void Timer0_Isr(void) interrupt 1
{
t0count++;
}
void Timer1_Isr(void) interrupt 3
{
t1count++;
if(t1count>=20)
{
t1count=0;
F=t0count;
t0count=0;
}
}
void Timer3_Isr(void) interrupt 19
{
t3count++;
}