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 上傳
點擊文件名下載附件
|