标题:
51单片机数码管无线调时万年历程序
[打印本页]
作者:
二师兄
时间:
2019-4-21 17:27
标题:
51单片机数码管无线调时万年历程序
51数码管无线调时万年历
单片机源程序如下:
#include "STC15Wxx.h"
#include <intrins.h>
#include "string.h"
//#include "sys/mcuinit.h"
#include "sys/delay.h"
#include "enc28j60/enc28j60.h"
#include "fu_ip/fu_config.h"
#include "fu_ip/fu_send.h"
/*TCP UDP NTP协议*/
#include "DS3232/DS3232.H"
#include "led/led.h"
#include "code/currency.h"
#include "code/wireless.h"
#include "code/network.h"
#include "code/school.h"
#include "led/led.h"
#include "key/key.h"
#include "main.h"
/************年月日定义************/
unsigned int year=2017; //年
unsigned char mon=7;
unsigned char day=12;
unsigned char hour=17;
unsigned char min=10;
unsigned char sec=10;
unsigned char _state; //亮灯状态
unsigned char week; //星期
/*************************************/
unsigned char receiveData; //北斗串口接受的数据
unsigned char RX2_Buffer; //无线串口接受数据标志
bit B_TX2_Busy; //串口2标志
bit B_TX1_Busy; //串口1标志
bit B_1ms; //1毫秒标记位
unsigned int count_1ms; //1毫秒计数
unsigned int light_time=0; //亮灯时间
unsigned char xdata key_event; //按键事件
unsigned char keyevent_add =0; //按键事件
unsigned char getevent = 0; //获取按键
unsigned char do_success=0; //接受成功之后的亮灯标志
unsigned char st;
unsigned char cmd3[7]= {0xc0,0x20,0x15,0x50,0x98,0x00};
void PrintString3(unsigned char *puts); //发送一个字符串
/**********函数********************/
void init();
void geiDS3232TIMES();
void PrintString1(unsigned char *puts);
/**********************************/
void main(){
init();
AUX=1; //AUX 先上电
//WX_POWER=0; //开启无线 无线上电
init_DS3231(0x1C); //初始化 守时芯片
//delayms(200);
if(Get_YEAR()==0)Set_time(12,0,0,17,1,1);
getevent=0;
keyevent_add=0;
PrintString3(cmd3);
while(1){
if(B_1ms){ //1毫秒到
B_1ms=0;
if(beginwire==1)lcawire++;
if(beginnet==1)lcanet++;
if(count_1ms>980){ //1秒到了
count_1ms=0;
if(do_success !=0)light_time++;
if(keyevent_add==1)sec++;
//sec++;
if(NETSORT==2){ //1秒一刷
memcpy(DATA,"",1);
Send_UDP_Data_Bag(1);
}
press_time(); //按键时长
}
}
press_key(); //按键
change_mode(); //改变模式
DateTest();
WDT_CONTR |=0x10; //喂狗
if(keyevent_add==0 && getevent !=6)geiDS3232TIMES(); //实时读取守时芯片时间
sendbyte_H(year,mon,day,hour,min,sec); //显示程序
}
}
//初始化
void init(){
P0M0=0X00;
P0M1=0X00;
P4M0=0X00;
P4M1=0X00;
P2M0 = 0X00;
P2M1 = 0X00;
P1M0 = 0;
P1M1 = 0;
P3M1 = 0; P3M0 = 0; //设置为准双向口
P5M0 = 0X00;P5M1 = 0X00;
// AUX = 1; //AUX高电平 进入命令模式 7-21
AUXR |= 0x80; //设置为1T
TMOD = 0x00; //计数器 16位自动重装模式
EX1=0; //禁止外部中断 0 1
EX0=0;
TL0 = (65536-MAIN_Fosc/1000); //1T模式 速度为12T模式的12倍
TH0 = (65536-MAIN_Fosc/1000) >> 8;
TF0 = 0; //计数器中断
ET0 = 1; //Timer0 interrupt enable
TR0 = 1; //Tiner0 run //串口一
PT0 = 1; //设置中断优先级 提升精确度
// 串口4
P_SW2 = 0x00; //串口2在 P1.0 P1.1
AUXR &= ~(1<<4); //Timer stop
AUXR &= ~(1<<3); //Timer2 set As Timer
AUXR |= (1<<2); //Timer2 set as 1T mode
T2H = (65536UL - (MAIN_Fosc / 4) / 9600)/ 256;
T2L = (65536UL - (MAIN_Fosc / 4) / 9600)% 256;
IE2 &= ~(1<<2); //禁止中断
AUXR |= (1<<4); //Timer run enable
S2CON &= ~(1<<7); // 8位数据, 1位起始位, 1位停止位, 无校验
IE2 |= 1; //允许中断
S2CON ^= 0xef ;
S2CON =~S2CON; //不允许接受
EA = 1; //打开总中断
WDT_CONTR=0x07; // 设置看门狗位 256分屏
WDT_CONTR |= 0x20; //启动看们狗
}
/*-----内部中断 计时器1------*/
void init_time0 (void) interrupt 1 using 1 {
B_1ms =1; //1毫秒标记位
count_1ms++;
}
/*-----内部中断 计时器2------*/
/* $GNRMC,084032.007,A,2813.0983,N,11253.1384,E,0.39,0.00,270916,,,A* 7B */
void init_time1(void) interrupt 4 using 1 {
if(RI)
{
RI = 0;
receiveData = SBUF;
if(get_times<4)BDTIME=1;
}
if(TI)
{
TI = 0;
B_TX1_Busy = 0;
}
}
void PrintString1(unsigned char *puts) //发送一个字符串
{
for (; *puts != 0; puts++) //遇到停止符0结束
{
SBUF = *puts;
B_TX1_Busy = 1;
while(B_TX1_Busy);
}
}
/**********************************************************************/
/****************** 串口2中断 ******************************/
/* ?4@2015$GNZDA,004827.000,14,10,2016,08,48*0119000173 */
/**********************************************************************/
void UART2_int (void) interrupt 8 using 2
{
if((S2CON & 1) != 0)
{
S2CON &= ~1; //Clear Rx flag
RX2_Buffer= S2BUF;
WX_FLAG=1;
}
if((S2CON & 2) != 0)
……………………
…………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
51数码管无线调时万年历.zip
(597.96 KB, 下载次数: 9)
2019-4-21 17:26 上传
点击文件名下载附件
下载积分: 黑币 -5
图片.png
(93.05 KB, 下载次数: 29)
下载附件
2019-4-21 17:26 上传
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1