|
這是單片機(jī)點陣時鐘的程序和proteus圖,歡迎大家指正
原理圖大家執(zhí)行解壓后用protel99打開.
0.png (8.03 KB, 下載次數(shù): 68)
下載附件
2017-11-15 20:48 上傳
單片機(jī)源程序如下:
- //LED點陣時鐘程序
- //作者:劉寧
- //--------------------------------
- #include "reg52.h"
- #define uchar unsigned char
- #define uint unsigned int
- //========================
- //****滾屏事件定義****
- #define MSG_MV_L 1 //左移
- #define MSG_MV_R 2 //右移
- #define MSG_MV_U 3 //上移
- #define MSG_MV_D 4 //下移
- #define MSG_NONE 0 //無
- uchar MSG_MV = 0;
- //========================
- //****顯示狀態(tài)定義****
- #define STA_gTIME 1 //滾動顯示時間
- #define STA_gTEMP 2 //滾動顯示溫度
- #define STA_gWORD 3 //滾動顯示文字
- #define STA_sTIME 4 //靜態(tài)顯示時間
- #define STA_sWEEK 5 //靜態(tài)顯示星期
- #define STA_sDATE 6 //靜態(tài)顯示日期
- #define STA_sYEAR 7 //靜態(tài)顯示年份
- #define STA_sTEMP 8 //靜態(tài)顯示溫度
- #define STA_sWORD 9 //靜態(tài)顯示文字
- #define STA_CHG 10 //校時模式
- #define STA_SONG 11 //滾動顯示詩歌
- #define STA_COPYRIGHT 12 //開機(jī)顯示
- uchar STATE = 1;
- //=========================
- //****校時狀態(tài)定義****
- #define CHG_HOUR 1 //調(diào)整小時
- #define CHG_MIN 2 //調(diào)整分
- #define CHG_SEC 3 //調(diào)整秒
- #define CHG_MON 4 //調(diào)整月
- #define CHG_DAY 5 //調(diào)整日
- #define CHG_WEEK 6 //調(diào)整星期
- #define CHG_YEAR 7 //調(diào)整年
- uchar CHANGE = 1;
- uchar hide_times = 0; //校時閃爍時間變量
- uchar HIDE = 0; //隱藏顯示標(biāo)志位
- uchar TMP_TIME = 0;
- //=========================
- //****按鍵定義****
- sbit key0 = P1^0;
- sbit key1 = P1^1;
- sbit key2 = P1^2;
- sbit key3 = P1^3;
- #define KEY0 0x0e
- #define KEY1 0x0d
- #define KEY2 0x0b
- #define KEY3 0x07
- #define KEY0_S 0x0e //KEY0短按下
- #define KEY1_S 0x0d //KEY1短按下
- #define KEY2_S 0x0b //KEY2短按下
- #define KEY3_S 0x07 //KEY3短按下
- #define KEY0_L 0x1e //KEY0長按下
- #define KEY1_L 0x1d //KEY1長按下
- #define KEY2_L 0x1b //KEY2長按下
- #define KEY3_L 0x17 //KEY3長按下
- #define KEY_NONE 0 //無按鍵
- uchar MSG_KEY = KEY_NONE;
- uchar key_times = 0; //持續(xù)時間
- uchar key_keep_times = 0;
- uchar cur_key_val = 0;
- uchar key_done = 0; //按鍵事件有無做好
- uchar exit = 0; //校時狀態(tài)下長時間無按鍵退出
- //=========================
- //uchar time_read_times = 0; //讀時間
- //uchar tem_read_times = 0; //讀溫度
- //=========================
- //****引腳定義****
- sbit CLK =P2^5 ; //74HC595移時鐘
- sbit STB =P2^4 ; // 74HC595鎖存信號
- sbit Red=P2^7 ; //紅色數(shù)據(jù)輸出引腳低電平有效
- sbit Greed=P2^6; //全屏控制使能0,低電平有效
- sbit OE = P0^7; //全屏使能
- //========================
- //****DS1302****
- sbit SCLK=P0^4; //位定義1302芯片的接口,時鐘輸出端口定義在P2.4引腳
- sbit DATA=P0^5; //位定義1302芯片的接口,數(shù)據(jù)輸出端定義在P2.5引腳
- sbit RST=P0^6; //位定義1302芯片的接口,復(fù)位端口定義在P2.6引腳
- typedef struct __SYSTEMTIME__
- {
- uchar Second;
- uchar Minute;
- uchar Hour;
- uchar Day;
- uchar Month;
- uchar Week;
- uchar Year;
- }SYSTEMTIME; //定義的時間類型
- SYSTEMTIME Time;
- //=========================================
- //****18B20****
- sbit DQ = P0^7
- ; //定義DS18B20端口DQ
- unsigned char data temp_data[2] = {0x00,0x00} ;
- unsigned char data temp_ram[5] = {0x00,0x00,0x00,0x00,0x00} ;
- unsigned char code ditab[16] = {0x00,0x01,0x01,0x02,0x03,0x03,0x04,0x04,
- 0x05,0x06,0x06,0x07,0x08,0x08,0x09,0x09};
- //==========================================
- bit presence ;
- uchar SendData; //要發(fā)送的數(shù)據(jù)變量
- uchar hang; //行掃描變量 (半屏只有16行,所以hang=0到15)
- uchar move_times = 0; //左右移動位數(shù)
- uchar start_word = 0;
- uchar data h_dispram[10]; //顯示緩存
- uchar code *disword[26]; //顯示文字指針
- void Keyscan (void); //修改參數(shù)按鍵掃描子程序
- void Sendping(); //發(fā)送半屏子程序
- void Put_Wdispram(uchar first_word);//
- void Put_Hdispram(); //把顯示文字放入顯示緩存
- void Move_Left(); //左移
- void Move_Right(); //右移
- void RL_Move();
- void UD_Move();
- void Show_Line();
- void Show_Move_Word(uchar code *WORDS[][8]);
- void delay();
- void SendByte(void);
- void RowsCan(void);
- void Disp_Temperature();
- void Put_gTEMP();
- void Change_obj();
- uchar ReadKey1();
- uchar code MY_WORDS[][16]=
- {
- {0x10,0x08,0x04,0x7F,0x01,0x21,0x12,0x0A,0x04,0x06,0x0A,0x11,0x21,0x41,0x80,0x00},
- {0x04,0x04,0x04,0xA4,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x04,0x84,0x14,0x08,0x00},/*"劉",0*/
- {0x02,0x01,0x3F,0x20,0x40,0x00,0x00,0x7F,0x01,0x01,0x01,0x01,0x01,0x01,0x05,0x02},
- {0x00,0x04,0xFE,0x04,0x08,0x00,0x00,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"寧",1*/
- {0x01,0x01,0x01,0x01,0x01,0x1F,0x10,0x10,0x10,0x1F,0x10,0x01,0x28,0x24,0x44,0x00},
- {0x00,0x00,0xF8,0x00,0x10,0xF8,0x10,0x10,0x10,0xF0,0x10,0x10,0x88,0x44,0x44,0x00},/*"點",2*/
- {0x00,0xF8,0x88,0x97,0xA1,0x91,0x8A,0x8F,0x88,0xA8,0x97,0x80,0x80,0x80,0x80,0x80},
- {0x80,0x80,0x80,0xFC,0x00,0x40,0x40,0xFC,0x40,0x40,0xFE,0x40,0x40,0x40,0x40,0x40},/*"陣",3*/
- {0x00,0x00,0x3F,0x00,0x00,0x00,0xFF,0x03,0x07,0x06,0x0C,0x18,0x31,0x7F,0x20,0x00},
- {0x00,0x30,0xF8,0x00,0x00,0x0C,0xFE,0x00,0x00,0x40,0x20,0x10,0xF8,0x0C,0x08,0x00},/*"云",0*/
- {0x01,0x01,0xFF,0x01,0x02,0x3F,0x24,0x22,0x2F,0x21,0x3F,0x21,0x21,0x21,0x21,0x00},
- {0x00,0x04,0xFE,0x00,0x00,0xFC,0x24,0x44,0xF4,0x04,0xFC,0x04,0x04,0x14,0x08,0x00},/*"南",1*/
- {0x02,0x02,0x04,0x3F,0x20,0x20,0x20,0x20,0x3F,0x20,0x20,0x20,0x20,0x3F,0x20,0x00},
- {0x00,0x00,0x00,0xF8,0x08,0x08,0x08,0x08,0xF8,0x08,0x08,0x08,0x08,0xF8,0x08,0x00},/*"白",2*/
- {0x04,0x04,0x7F,0x04,0x14,0x10,0x24,0x7C,0x09,0x10,0x7E,0x20,0x06,0x78,0x20,0x00},
- {0x40,0x40,0xFE,0x40,0x40,0x40,0x7C,0x84,0x04,0x44,0x24,0x24,0x04,0x04,0x28,0x10},/*"藥",3*/
- {0x08,0x08,0x1F,0x10,0x20,0x4F,0x00,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
- };
- uchar code NO_WORDS[][16]={
- {0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x24,0x18,0x00,0x00},/*"0",0*/
- {0x00,0x00,0x00,0x10,0x70,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x7C,0x00,0x00},/*"1",1*/
- {0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x04,0x04,0x08,0x10,0x20,0x42,0x7E,0x00,0x00},/*"2",2*/
- {0x00,0x00,0x00,0x3C,0x42,0x42,0x04,0x18,0x04,0x02,0x02,0x42,0x44,0x38,0x00,0x00},/*"3",3*/
- {0x00,0x00,0x00,0x04,0x0C,0x14,0x24,0x24,0x44,0x44,0x7E,0x04,0x04,0x1E,0x00,0x00},/*"4",4*/
- {0x00,0x00,0x00,0x7E,0x40,0x40,0x40,0x58,0x64,0x02,0x02,0x42,0x44,0x38,0x00,0x00},/*"5",5*/
- {0x00,0x00,0x00,0x1C,0x24,0x40,0x40,0x58,0x64,0x42,0x42,0x42,0x24,0x18,0x00,0x00},/*"6",6*/
- {0x00,0x00,0x00,0x7E,0x44,0x44,0x08,0x08,0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x00},/*"7",7*/
- {0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x24,0x18,0x24,0x42,0x42,0x42,0x3C,0x00,0x00},/*"8",8*/
- {0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x26,0x1A,0x02,0x02,0x24,0x38,0x00,0x00},/*"9",9*/
- {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"-",10*/
- {0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00},/*":",11*/
- {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"空格",12*/
- };
- uchar code TMP_WORDS[][16]={
- {0x02,0x01,0x3F,0x20,0x40,0x3F,0x04,0x08,0x1F,0x01,0x01,0x3F,0x01,0x01,0xFF,0x00},
- {0x00,0x00,0xFE,0x04,0x08,0xFC,0x00,0x20,0xF0,0x10,0x00,0xF8,0x00,0x00,0xFE,0x00},/*"室",3*/
- {0x40,0x27,0x24,0x07,0x94,0x54,0x17,0x20,0x2F,0xC9,0x49,0x49,0x49,0x49,0x5F,0x40},
- {0x00,0xF0,0x10,0xF0,0x10,0x10,0xF0,0x00,0xFC,0x24,0x24,0x24,0x24,0x24,0xFE,0x00},/*"溫",4*/
- {0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00},/*":",5*/
- {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*" ",6*/
- {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*" ",7*/
- {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*" ",8*/
- {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x60,0x00,0x00},/*".",9*/
- {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*" ",10*/
- {0x00,0xC0,0xC0,0x3E,0x42,0x42,0x80,0x80,0x80,0x80,0x80,0x42,0x44,0x38,0x00,0x00},/*"C",11*/
- };
- uchar code TIME_WORDS[][16]={
- {0x01,0x01,0x02,0x04,0x08,0x12,0x21,0xC0,0x00,0x1F,0x00,0x00,0x00,0x00,0x00,0x01},
- {0x00,0x00,0x80,0x40,0x20,0x18,0x8E,0x84,0x00,0xF0,0x20,0x20,0x40,0x40,0x80,0x00},/*"今",0*/
- {0x00,0x3F,0x01,0x01,0x01,0x01,0x7F,0x01,0x01,0x02,0x02,0x04,0x08,0x10,0x20,0x40},
- {0x00,0xFC,0x00,0x00,0x00,0x00,0xFE,0x00,0x00,0x80,0x40,0x20,0x18,0x0E,0x04,0x00},/*"天",1*/
- {0x00,0x0F,0x08,0x0F,0x08,0x0F,0x00,0xFF,0x01,0x09,0x09,0x09,0x15,0x23,0x40,0x00},
- {0x00,0xF0,0x10,0xF0,0x10,0xF0,0x00,0xFE,0x00,0x00,0xF8,0x00,0x00,0x00,0xFE,0x00},/*"是",2*/
- {0x08,0x0F,0x10,0x10,0x20,0x4F,0x88,0x08,0x08,0x08,0xFF,0x00,0x00,0x00,0x00,0x00},
- {0x00,0xFC,0x80,0x80,0x80,0xF8,0x80,0x80,0x80,0x80,0xFE,0x80,0x80,0x80,0x80,0x80},/*"年",1*/
- {0x07,0x04,0x04,0x04,0x07,0x04,0x04,0x04,0x07,0x04,0x08,0x08,0x10,0x20,0x40,0x00},
- {0xF0,0x10,0x10,0x10,0xF0,0x10,0x10,0x10,0xF0,0x10,0x10,0x10,0x10,0x50,0x20,0x00},/*"月",2*/
- {0x00,0x1F,0x10,0x10,0x10,0x10,0x1F,0x10,0x10,0x10,0x10,0x10,0x1F,0x10,0x00,0x00},
- {0x00,0xF0,0x10,0x10,0x10,0x10,0xF0,0x10,0x10,0x10,0x10,0x10,0xF0,0x10,0x00,0x00},/*"日",3*/
- {0x00,0x1F,0x10,0x1F,0x10,0x1F,0x01,0x11,0x1F,0x21,0x21,0x4F,0x01,0x01,0x7F,0x00},
- {0x00,0xF8,0x08,0xF8,0x08,0xF8,0x00,0x00,0xFC,0x00,0x00,0xF8,0x00,0x00,0xFE,0x00},/*"星",4*/
- {0x22,0x22,0x7F,0x22,0x3E,0x22,0x3E,0x22,0x22,0xFF,0x00,0x24,0x22,0x43,0x81,0x00},
- {0x00,0x7C,0x44,0x44,0x44,0x7C,0x44,0x44,0x44,0x7C,0x44,0x84,0x84,0x14,0x08,0x00},/*"期",5*/
- };
- uchar code WEEK_WORDS[][16]={
-
- {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
- {0x00,0x00,0x00,0x00,0x00,0x00,0x04,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"一",0*/
- {0x00,0x00,0x3F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x00,0x00,0x00},
- {0x00,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0xFE,0x00,0x00,0x00},/*"二",1*/
- {0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,0x00,0x7F,0x00,0x00},
- {0x00,0x00,0xFC,0x00,0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0xFE,0x00,0x00},/*"三",2*/
- {0x00,0x7F,0x44,0x44,0x44,0x44,0x44,0x44,0x48,0x48,0x50,0x60,0x40,0x7F,0x40,0x00},
- {0x00,0xFC,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x7C,0x04,0x04,0x04,0xFC,0x04,0x00},/*"四",3*/
- {0x00,0x7F,0x02,0x02,0x02,0x02,0x02,0x3F,0x04,0x04,0x04,0x04,0x04,0xFF,0x00,0x00},
- {0x00,0xF8,0x00,0x00,0x00,0x00,0x20,0xF0,0x20,0x20,0x20,0x20,0x24,0xFE,0x00,0x00},/*"五",4*/
- {0x04,0x03,0x01,0x01,0xFF,0x00,0x00,0x04,0x06,0x04,0x08,0x08,0x10,0x20,0x40,0x00},
- {0x00,0x00,0x80,0x00,0xFE,0x00,0x00,0x80,0x40,0x20,0x10,0x18,0x0C,0x0C,0x08,0x00},/*"六",5*/
- {0x00,0x1F,0x10,0x10,0x10,0x10,0x1F,0x10,0x10,0x10,0x10,0x10,0x1F,0x10,0x00,0x00},
- {0x00,0xF0,0x10,0x10,0x10,0x10,0xF0,0x10,0x10,0x10,0x10,0x10,0xF0,0x10,0x00,0x00},/*"日",0*/
- };
- uchar code SONG_WORDS[][16] = {
-
- {0x00,0x08,0x04,0x04,0x00,0x0F,0x01,0x01,0x7F,0x01,0x02,0x04,0x08,0x30,0x00,0x00},
- {0x40,0x40,0x40,0x80,0xE0,0x00,0x00,0xF8,0x00,0x00,0x80,0x40,0x30,0x1C,0x00,0x00},/*"關(guān)",0*/
- {0x00,0x08,0x04,0x04,0x00,0x0F,0x01,0x01,0x7F,0x01,0x02,0x04,0x08,0x30,0x00,0x00},
- {0x40,0x40,0x40,0x80,0xE0,0x00,0x00,0xF8,0x00,0x00,0x80,0x40,0x30,0x1C,0x00,0x00},/*"關(guān)",1*/
- {0x00,0x00,0x18,0x68,0x49,0x6B,0x4D,0x69,0x49,0x4D,0x71,0xC1,0x01,0x01,0x01,0x00},
- {0x40,0x40,0xA0,0x90,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x10,0x1E,0x60,0x00,0x00,0x00},/*"雎",2*/
- {0x00,0x00,0x10,0x11,0x1D,0x75,0x15,0x15,0x17,0x25,0x24,0x40,0x87,0x00,0x00,0x00},
- {0x40,0x40,0xF0,0x10,0x50,0x10,0x70,0x00,0x1C,0xE4,0x04,0xF4,0x04,0x14,0x08,0x00},/*"鳩",3*/
- {0x01,0x01,0x01,0x01,0x1E,0x04,0x04,0x08,0x18,0x2B,0x48,0x88,0x0F,0x08,0x08,0x00},
- {0x00,0x00,0x00,0xF0,0x00,0x40,0x40,0x40,0x70,0xC0,0x40,0x7C,0x80,0x00,0x00,0x00},/*"在",4*/
- {0x00,0x10,0x08,0x07,0x40,0x21,0x06,0x04,0x13,0x10,0x20,0x20,0x20,0x00,0x00,0x00},
- {0x00,0x00,0x1E,0xF0,0x10,0x90,0x90,0x90,0x90,0x10,0x10,0x10,0x30,0x10,0x00,0x00},/*"河",5*/
- {0x00,0x04,0x02,0x00,0x03,0x3C,0x00,0x03,0x0C,0xF0,0x0C,0x03,0x00,0x00,0x00,0x00},
- {0x00,0x00,0x00,0x00,0xE0,0x40,0x80,0x00,0x00,0x00,0x00,0x80,0x7E,0x00,0x00,0x00},/*"之",6*/
- {0x00,0x00,0x20,0x12,0x02,0x82,0x4B,0x0A,0x2A,0x22,0x24,0x48,0x50,0x00,0x00,0x00},
- {0x00,0x08,0x08,0x48,0x48,0x48,0x68,0xD8,0x48,0x48,0x48,0x08,0x08,0x08,0x00,0x00},/*"洲",7*/
- {0x02,0x01,0x01,0x3E,0x24,0x18,0x08,0x10,0x25,0x38,0x12,0x2E,0x31,0x02,0x04,0x00},
- {0x00,0x00,0xF8,0x88,0x40,0x20,0x40,0x78,0xC8,0x48,0x88,0x90,0x50,0x20,0x00,0x00},/*"窈",8*/
- {0x02,0x01,0x11,0x1E,0x24,0x08,0x00,0x24,0x14,0x0C,0x74,0x04,0x08,0x10,0x20,0x00},
- {0x00,0x00,0xF8,0x88,0x40,0x00,0x90,0xA0,0xC0,0xA0,0x94,0x84,0x84,0x7C,0x00,0x00},/*"窕",9*/
- {0x00,0x02,0x22,0x13,0x02,0x83,0x5C,0x02,0x2B,0x2A,0x52,0xC3,0x06,0x02,0x00,0x00},
- {0x00,0x00,0x00,0x80,0x38,0x48,0x90,0x50,0x20,0x50,0x88,0x0E,0x00,0x00,0x00,0x00},/*"淑",10*/
- {0x02,0x02,0x02,0x02,0x02,0x02,0x07,0xFC,0x04,0x02,0x01,0x06,0x18,0x00,0x00,0x00},
- {0x00,0x00,0x00,0x00,0x00,0x40,0xFE,0x40,0x80,0x80,0x80,0x60,0x10,0x00,0x00,0x00},/*"女",11*/
- {0x00,0x01,0x0E,0x02,0x7F,0x02,0x03,0x3E,0x04,0x08,0x17,0x24,0xC4,0x07,0x00,0x00},
- {0x00,0xF0,0x10,0x1E,0xE0,0x20,0xE0,0x00,0x00,0xF0,0x10,0x10,0x70,0x80,0x00,0x00},/*"君",12*/
- {0x00,0x01,0x0E,0x00,0x01,0x01,0x7F,0x00,0x00,0x00,0x00,0x00,0x06,0x01,0x00,0x00},
- {0x00,0xE0,0x40,0x80,0x00,0x7C,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x00},/*"子",13*/
- {0x00,0x10,0x10,0x11,0x10,0x14,0x1E,0xE5,0x14,0x08,0x14,0x22,0x40,0x00,0x00,0x00},
- {0x00,0x00,0x78,0x90,0x20,0x40,0x3E,0xE0,0x20,0x20,0x20,0x20,0x60,0x20,0x00,0x00},/*"好",14*/
- {0x00,0x00,0x20,0x10,0x03,0x30,0xD4,0x22,0x21,0x22,0x15,0xF8,0x07,0x00,0x00,0x00},
- {0x80,0x90,0x88,0xF0,0x80,0x90,0xB0,0xC0,0xA0,0x90,0x88,0x00,0x80,0x7E,0x00,0x00},/*"逑",15*/
- };
- uchar code CPYRT_WORDS[][16] = {
- {0x00,0x08,0x04,0x04,0x7B,0x01,0x22,0x12,0x0C,0x06,0x09,0x11,0x20,0x40,0x00,0x00},
- {0x00,0x02,0x04,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x04,0x04,0x0C,0x00,0x00},/*"劉",0*/
- {0x00,0x01,0x00,0x00,0x3F,0x60,0x00,0x3F,0x01,0x01,0x01,0x01,0x00,0x03,0x00,0x00},
- {0x00,0x00,0x80,0x04,0xFC,0x00,0x04,0xF8,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00},/*"寧",1*/
- {0x00,0x06,0x14,0x24,0x3F,0x44,0x7F,0x04,0x24,0x3F,0x24,0x24,0x25,0x04,0x00,0x00},
- {0x00,0x02,0x02,0x92,0x12,0x12,0xD2,0x12,0x52,0xD2,0x52,0x42,0x82,0x0C,0x04,0x00},/*"制",2*/
- {0x00,0x0C,0x08,0x09,0x11,0x1A,0x34,0x54,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x00},
- {0x00,0xC0,0x80,0x04,0xF8,0x40,0x40,0x7C,0x40,0x40,0x44,0x78,0x40,0x40,0x00,0x00},/*"作",3*/
- };
- void Put_Wdispram(uchar code *WORDS[][8]){ //,uchar first_word
- uchar i;
- disword[0] = &NO_WORDS[12][0];
- for(i=1;i<25;i++){
- disword[i] = &WORDS[i-1][0]; //first_word+
- }
- }
- void Put_Hdispram(){
- uchar i;
- for(i=0;i<10;i++){
- h_dispram[i] = *(disword[i+start_word]+hang); //
- }
- }
- void Move_Left(){
- uchar i;
- for(i=0;i<9;i++){
- h_dispram[i] = (h_dispram[i] << (move_times)) | (h_dispram[i+1] >> (8-move_times));
- }
- }
- void Move_Right(){
- uchar i;
- for(i=9;i>0;i--){
- h_dispram[i] = (h_dispram[i] >> (move_times)) | (h_dispram[i-1] << (8-move_times));
- }
- }
- void RL_Move(){
- //
- switch(MSG_MV){
- case MSG_MV_L: //左移
- Move_Left();
- break;
- case MSG_MV_R: //右移
- Move_Right();
- break;
- case MSG_NONE:
- break;
- default:
- break;
- }
- }
- void Move_Up(){
- //
- uchar i,j,m,n;
- for(m=0;m<16;m++){
- for(n=0;n<4;n++){
- for(j=0;j<16-m;j++){
- for(i=0;i<10;i++){
- h_dispram[i] = *(disword[i]+m+j); //
- }
- Show_Line();
- }
- for(j=16-m;j<16;j++){
- for(i=0;i<10;i++){
- h_dispram[i] = *(disword[i+8]+m+j-16); //0x00
- }
- Show_Line();
- }
- }
- }
- }
- void Move_Down(){
- //
- uchar i,j,m,n;
- for(m=0;m<16;m++){
- for(n=0;n<4;n++){
- for(j=0;j<m;j++){
- for(i=0;i<10;i++){
- h_dispram[i] = *(disword[i+8]+15-m+j); //
- }
- Show_Line();
- }
- for(j=m;j<16;j++){
- for(i=0;i<10;i++){
- h_dispram[i] = *(disword[i]-m+j); //0x00
- }
- Show_Line();
- }
- }
- }
- }
- void UD_Move(){
- //
- switch(MSG_MV){
- case MSG_MV_U: //左移
- // Move_Up();
- break;
- case MSG_MV_D: //右移
- // Move_Down();
- break;
- case MSG_NONE:
- break;
- default:
- break;
- }
- }
- void Show_Line(){
- uchar m;
- OE=1;
- for(m =0;m<8;m++)
- {
- SendData = h_dispram[m+1];
- SendByte();
- }
- STB = 0;
- STB = 1; //上升沿數(shù)據(jù)鎖存
- RowsCan(); //行掃描
- OE = 0;
- // delay(); //
- }
- void Show_sWord(){
- int m,i;//
- hang = 0;
- for(m=0;m<7;m++){
- for(i=0;i<16;i++){
- Put_Hdispram(); //把第i行放入行緩沖
- Show_Line();
- //delay(); //看需要
- }
-
- }
- }
- void Show_Move_Word(uchar code *WORDS[][8]){
- int m,i;
- while(1){
- for(m=0;m<3;m++){ //若要上下移動 m=16
- //hang = 0;
- for(i=0;i<16;i++){
- Put_Hdispram(); //把第i行放入行緩沖
- RL_Move(); //是否要左右移動
- Show_Line();
- //delay(); //看需要
- }
- //UD_Move(); //是否要上下移動
- }
- //========================================
- //測試左移右移 切換時有跳變!!
- // if(MSG_MV){
- move_times++;
- if((move_times == 9) && (MSG_MV == MSG_MV_L)){
- move_times = 1;
- Put_Wdispram(WORDS);
- start_word++;
- switch(STATE){
- case STA_gTEMP:
- Disp_Temperature(); //
- Put_gTEMP(); //
- if(start_word > (sizeof(TMP_WORDS)/16 - 8))
- MSG_MV = MSG_MV_R;
- break;
- case STA_gWORD:
- if(start_word > (sizeof(MY_WORDS)/16 - 8))
- MSG_MV = MSG_MV_R;
- default:
- break;
- }
- if(start_word > (sizeof(TMP_WORDS)/16 - 4))
- MSG_MV = MSG_MV_R;
- }
- else if((move_times == 9) && (MSG_MV == MSG_MV_R)){
- move_times = 1;
- Put_Wdispram(WORDS); //
- start_word-- ;
- switch(STATE){
- case STA_gTEMP:
- Disp_Temperature(); //
- Put_gTEMP();
- break;
- default:
- break;
- }
- if(start_word < 1){
- MSG_MV = MSG_MV_L;
- return;
- }
- }
- // }
- }
- }
- void Show_All_Word(){
- int m,i;
- //MSG_MV = MSG_MV_L;
- for(start_word = 0;start_word < 8;start_word++){
- for(move_times = 0; move_times < 8;move_times++){
- for(m=0;m<2;m++){ //若要上下移動 m=16
- for(i=0;i<16;i++){
- Put_Hdispram(); //把第i行放入行緩沖
- RL_Move(); //是否要左右移動
- Show_Line();
- }
- }
- }
- }
- }
- void delay()
- {
- uint i;
- for(i=0;i<40;i++);
- }
-
- //------------------------------------
- //----------字發(fā)送子程序-----------
- void SendByte(void)
- {
- uchar m;
- for(m=0;m<8;m++)
- {
- CLK = 0;
- Red = (SendData & 0x80); //紅屏顯示
- // Greed = (SendData & 0x80); //綠屏顯示
- SendData =SendData<<1;
- CLK = 1; //移位時鐘上升沿
- }
- }
- //-----------------------------------
- //----------行掃描子程序-------------
- void RowsCan(void)
- {
- P2 = P2 & 0xf0;
- P2 = P2 | hang;
- hang++;
- if (hang>=16)
- {
- hang =0x00;
- }
- }
- void initial(void)
- {
- OE = 1;
- Red = 1;
- Greed = 1;
- SendData = 0x00;
- hang = 0x00;
-
- }
- /*****************************************************
- 函數(shù)功能:延時若干微秒
- 入口參數(shù):n
- ***************************************************/
- void delaynus(unsigned char n)
- {
- unsigned char i;
- // for(i=0;i<n;i++)
- ;
- }
- /*****************************************************
- 函數(shù)功能:向1302寫一個字節(jié)數(shù)據(jù)
- 入口參數(shù):x
- ***************************************************/
- void Write1302(unsigned char dat)
- {
- unsigned char i;
- SCLK=0; //拉低SCLK,為脈沖上升沿寫入數(shù)據(jù)做好準(zhǔn)備
- delaynus(2); //稍微等待,使硬件做好準(zhǔn)備
- for(i=0;i<8;i++) //連續(xù)寫8個二進(jìn)制位數(shù)據(jù)
- {
- DATA=dat&0x01; //取出dat的第0位數(shù)據(jù)寫入1302
- delaynus(2); //稍微等待,使硬件做好準(zhǔn)備
- SCLK=1; //上升沿寫入數(shù)據(jù)
- delaynus(2); //稍微等待,使硬件做好準(zhǔn)備
- SCLK=0; //重新拉低SCLK,形成脈沖
- dat>>=1; //將dat的各數(shù)據(jù)位右移1位,準(zhǔn)備寫入下一個數(shù)據(jù)位
- }
-
- }
- /*****************************************************
- 函數(shù)功能:根據(jù)命令字,向1302寫一個字節(jié)數(shù)據(jù)
- 入口參數(shù):Cmd,儲存命令字;dat,儲存待寫的數(shù)據(jù)
- ***************************************************/
- void WriteSet1302(unsigned char Cmd,unsigned char dat)
- {
- RST=0; //禁止數(shù)據(jù)傳遞
- SCLK=0; //確保寫數(shù)居前SCLK被拉低
- RST=1; //啟動數(shù)據(jù)傳輸
- delaynus(2); //稍微等待,使硬件做好準(zhǔn)備
- Write1302(Cmd); //寫入命令字
- Write1302(dat); //寫數(shù)據(jù)
- SCLK=1; //將時鐘電平置于已知狀態(tài)
- RST=0; //禁止數(shù)據(jù)傳遞
- }
- /*****************************************************
- 函數(shù)功能:從1302讀一個字節(jié)數(shù)據(jù)
- 入口參數(shù):x
- ***************************************************/
- unsigned char Read1302(void)
- {
- unsigned char i,dat;
- delaynus(2); //稍微等待,使硬件做好準(zhǔn)備
- for(i=0;i<8;i++) //連續(xù)讀8個二進(jìn)制位數(shù)據(jù)
- {
- dat>>=1; //將dat的各數(shù)據(jù)位右移1位,因為先讀出的是字節(jié)的最低位
- if(DATA==1) //如果讀出的數(shù)據(jù)是1
- dat|=0x80; //將1取出,寫在dat的最高位
- SCLK=1; //將SCLK置于高電平,為下降沿讀出
- delaynus(2); //稍微等待
- SCLK=0; //拉低SCLK,形成脈沖下降沿
- delaynus(2); //稍微等待
- }
- return dat; //將讀出的數(shù)據(jù)返回
- }
- /*****************************************************
- 函數(shù)功能:根據(jù)命令字,從1302讀取一個字節(jié)數(shù)據(jù)
- 入口參數(shù):Cmd
- ***************************************************/
- unsigned char ReadSet1302(unsigned char Cmd)
- {
- unsigned char dat;
- RST=0; //拉低RST
- SCLK=0; //確保寫數(shù)居前SCLK被拉低
- RST=1; //啟動數(shù)據(jù)傳輸
- Write1302(Cmd); //寫入命令字
- dat=Read1302(); //讀出數(shù)據(jù)
- SCLK=1; //將時鐘電平置于已知狀態(tài)
- RST=0; //禁止數(shù)據(jù)傳遞
- return dat; //將讀出的數(shù)據(jù)返回
- }
- /*****************************************************
- 函數(shù)功能: 1302進(jìn)行初始化設(shè)置
- ***************************************************/
- void Init_DS1302(void)
- {
- unsigned char flag;
-
- flag= ReadSet1302(0x81);
- if(flag&0x80) { //判斷時鐘芯片是否關(guān)閉
- WriteSet1302(0x8E,0x00); //根據(jù)寫狀態(tài)寄存器命令字,寫入不保護(hù)指令
- WriteSet1302(0x80,((0/10)<<4|(0%10))); //根據(jù)寫秒寄存器命令字,寫入秒的初始值
- WriteSet1302(0x82,((18/10)<<4|(18%10))); //根據(jù)寫分寄存器命令字,寫入分的初始值
- WriteSet1302(0x84,((21/10)<<4|(21%10))); //根據(jù)寫小時寄存器命令字,寫入小時的初始值
- WriteSet1302(0x86,((23/10)<<4|(23%10))); //根據(jù)寫日寄存器命令字,寫入日的初始值
- WriteSet1302(0x88,((7/10)<<4|(7%10))); //根據(jù)寫月寄存器命令字,寫入月的初始值
- //WriteSet1302(0x8A,2);
- WriteSet1302(0x8c,((10/10)<<4|(10%10))); //根據(jù)寫小時寄存器命令字,寫入小時的初始值
- WriteSet1302(0x90,0xa5);
- WriteSet1302(0x8E,0x80);
- }
- //如果不想每次都初始化時間,也就是掉電后還想讓時鐘繼續(xù)走時的話 就用上面的語句
- /*--------------------這是每次都初始化的語句-----------------*/
- /* WriteSet1302(0x8E,0x00); //根據(jù)寫狀態(tài)寄存器命令字,寫入不保護(hù)指令
- WriteSet1302(0x80,((0/10)<<4|(0%10))); //根據(jù)寫秒寄存器命令字,寫入秒的初始值
- WriteSet1302(0x82,((18/10)<<4|(18%10))); //根據(jù)寫分寄存器命令字,寫入分的初始值
- WriteSet1302(0x84,((21/10)<<4|(21%10))); //根據(jù)寫小時寄存器命令字,寫入小時的初始值
- WriteSet1302(0x86,((23/10)<<4|(23%10))); //根據(jù)寫日寄存器命令字,寫入日的初始值
- WriteSet1302(0x88,((7/10)<<4|(7%10))); //根據(jù)寫月寄存器命令字,寫入月的初始值
- //WriteSet1302(0x8A,2);
- WriteSet1302(0x8c,((10/10)<<4|(10%10))); //根據(jù)寫小時寄存器命令字,寫入小時的初始值
- WriteSet1302(0x90,0xa5);
- WriteSet1302(0x8E,0x80);
- */
- }
- void write_time1302(){
- WriteSet1302(0x8E,0x00); //根據(jù)寫狀態(tài)寄存器命令字,寫入不保護(hù)指令
- WriteSet1302(0x80,Time.Second); //根據(jù)寫秒寄存器命令字,寫入秒的初始值
- WriteSet1302(0x82,Time.Minute); //根據(jù)寫分寄存器命令字,寫入分的初始值
- WriteSet1302(0x84,Time.Hour); //根據(jù)寫小時寄存器命令字,寫入小時的初始值
- WriteSet1302(0x86,Time.Day); //根據(jù)寫日寄存器命令字,寫入日的初始值
- WriteSet1302(0x88,Time.Month); //根據(jù)寫月寄存器命令字,寫入月的初始值
- WriteSet1302(0x8A,Time.Week);
- WriteSet1302(0x8c,Time.Year); //根據(jù)寫小時寄存器命令字,寫入小時的初始值
- // WriteSet1302(0x90,0xa5);
- //WriteSet1302(0x8E,0x80);
- }
- //讀時間
- void Read_TIME(){
- RST=0; //拉低RST
- SCLK=0; //確保寫數(shù)居前SCLK被拉低
- RST=1; //啟動數(shù)據(jù)傳輸
- Write1302(0xbf); //寫入命令字
- Time.Second = Read1302() & 0x7f;
- Time.Minute = Read1302() & 0x7f;
- Time.Hour = Read1302() & 0x7f;
- Time.Day = Read1302() & 0x7f;
- Time.Month = Read1302() & 0x7f;
- Time.Week= Read1302() & 0x7f;
- Time.Year = Read1302() & 0x7f;
- SCLK=1; //將時鐘電平置于已知狀態(tài)
- RST=0; //禁止數(shù)據(jù)傳遞
-
- /*unsigned char ReadValue; //儲存從1302讀取的數(shù)據(jù)
- ReadValue = ReadSet1302(0x81); //從秒寄存器讀數(shù)據(jù)
- Time.Second =ReadValue&0x7f;//(ReadValue&0x70) + (ReadValue&0x0F);//將讀出數(shù)據(jù)轉(zhuǎn)化
- ReadValue = ReadSet1302(0x83); //從分寄存器讀
- Time.Minute = ReadValue&0x7f;//(ReadValue&0x70) + (ReadValue&0x0F); //將讀出數(shù)據(jù)轉(zhuǎn)化
- ReadValue = ReadSet1302(0x85); //從時寄存器讀
- Time.Hour = ReadValue&0x7f;//(ReadValue&0x70) + (ReadValue&0x0F); //將讀出數(shù)據(jù)轉(zhuǎn)化
- ReadValue = ReadSet1302(0x87); //從分寄存器讀
- Time.Day = ReadValue&0x7f;//(ReadValue&0x70) + (ReadValue&0x0F); //將讀出數(shù)據(jù)轉(zhuǎn)化
- ReadValue = ReadSet1302(0x89); //從分寄存器讀
- Time.Month = ReadValue&0x7f;//(ReadValue&0x70) + (ReadValue&0x0F); //將讀出數(shù)據(jù)轉(zhuǎn)化
- ReadValue = ReadSet1302(0x8B); //從時寄存器讀
- Time.Week= ReadValue&0x7f;//(ReadValue&0x70) + (ReadValue&0x0F); //將讀出數(shù)據(jù)轉(zhuǎn)化
- ReadValue = ReadSet1302(0x8d); //從分寄存器讀
- Time.Year = ReadValue&0x7f;//(ReadValue&0x70) + (ReadValue&0x0F); //將讀出數(shù)據(jù)轉(zhuǎn)化
-
- */ }
- void Put_Adispram(uchar a){
- uchar i;
- //第一屏"今天是:"
- disword[a+1] = &NO_WORDS[12][0]; //空格
- for(i=0;i<6;i++)
- disword[a+i+2] = &TIME_WORDS[i][0];
- disword[a+8] = &NO_WORDS[11][0]; //":"
- //第二屏
- //disword[4] = &TIME_WORDS[];
-
- }
-
- //將年份放入到顯示緩存
- //需要參數(shù):緩沖區(qū)首地址下標(biāo)
- void Put_Ydispram(uchar i){
- disword[i+1] = &NO_WORDS[12][0];
- if(Time.Year < 30 && !HIDE){
- disword[i+2] = &NO_WORDS[2][0];
- disword[i+3] = &NO_WORDS[0][0];
- }
- else if(!HIDE){
- disword[i+2] = &NO_WORDS[1][0];
- disword[i+3] = &NO_WORDS[9][0];
- }
- disword[i+4] = &NO_WORDS[Time.Year>>4][0];
- disword[i+5] = &NO_WORDS[Time.Year&0x0f][0];
- disword[i+6] = &TIME_WORDS[6][0];
- disword[i+7] = &TIME_WORDS[7][0]; //年
- disword[i+8] = &NO_WORDS[12][0];
- }
- //將星期放入到顯示緩存
- //參數(shù):緩沖區(qū)首地址下標(biāo)
- void Put_Kdispram(uchar i){
- disword[i+1] = &NO_WORDS[12][0];
- disword[i+2] = &TIME_WORDS[12][0];
- disword[i+3] = &TIME_WORDS[13][0]; //星期
- disword[i+4] = &TIME_WORDS[14][0];
- disword[i+5] = &TIME_WORDS[15][0];
- if(STATE== STA_CHG &&HIDE){
- disword[i+6] = &NO_WORDS[12][0]; //
- disword[i+7] = &NO_WORDS[12][0]; //
- }
- else{
- disword[i+6] = &WEEK_WORDS[Time.Week*2-2][0]; //
- disword[i+7] = &WEEK_WORDS[Time.Week*2-1][0]; //
- }
- disword[i+8] = &NO_WORDS[12][0];
- }
- //將日期放入到顯示緩存
- //參數(shù):緩沖區(qū)首地址下標(biāo)
- void Put_Ddispram(uchar i){
- disword[i+1] = &NO_WORDS[Time.Month>>4][0]; //小時高位
- disword[i+2] = &NO_WORDS[ Time.Month&0x0f][0]; //小時地位
- disword[i+3] = &TIME_WORDS[8][0]; //-
- disword[i+4] = &TIME_WORDS[9][0]; //分鐘高位
- disword[i+5] = &NO_WORDS[ Time.Day>>4][0]; //分鐘地位
- disword[i+6] = &NO_WORDS[Time.Day&0x0f][0]; //-
- disword[i+7] = &TIME_WORDS[10][0]; //秒高位
- disword[i+8] = &TIME_WORDS[11][0]; //秒地位
- }
- //將時間放入到顯示緩存
- //參數(shù):緩沖區(qū)首地址下標(biāo)
- void Put_Tdispram(uchar i){
- disword[i+1] = &NO_WORDS[Time.Hour>>4][0]; //小時高位
- disword[i+2] = &NO_WORDS[ Time.Hour&0x0f][0]; //小時地位
- disword[i+3] = &NO_WORDS[ 11 ]; //-
- disword[i+4] = &NO_WORDS[Time.Minute>>4][0]; //分鐘高位
- disword[i+5] = &NO_WORDS[ Time.Minute&0x0f][0]; //分鐘地位
- disword[i+6] = &NO_WORDS[ 11 ]; //-
- disword[i+7] = &NO_WORDS[Time.Second>>4][0]; //秒高位
- disword[i+8] = &NO_WORDS[ Time.Second&0x0f][0]; //秒地位
- }
- //===================================
- //*****關(guān)于溫度檢測部分*****
- void Put_gTEMP(){
- // uchar i;
- // Put_Wdispram(TMP_WORDS,0);
- disword[6] = &NO_WORDS[temp_ram[3]][0]; //百位
- disword[7] = &NO_WORDS[temp_ram[2]][0]; //十位
- disword[8] = &NO_WORDS[temp_ram[1]][0]; //個位
- disword[10] = &NO_WORDS[temp_ram[0]][0]; //小數(shù)
- disword[12] = &NO_WORDS[12]; //空格
- disword[13] = &NO_WORDS[12]; //空格
- //
- }
- void Put_sTEMP(uchar i){
- disword[i+1] = &NO_WORDS[12]; //空格
- disword[i+2] = &NO_WORDS[12];//&NO_WORDS[temp_ram[3]][0]; //百位
- disword[i+3] = &NO_WORDS[temp_ram[2]][0]; //十位
- disword[i+4] = &NO_WORDS[temp_ram[1]][0]; //個位
- disword[i+5] = &TMP_WORDS[8][0]; //小數(shù)點
- disword[i+6] = &NO_WORDS[temp_ram[0]][0]; //小數(shù)
- disword[i+7] = &TMP_WORDS[10][0];
- disword[i+8] = &NO_WORDS[12]; //空格
- }
- void Put_Cpyrt(uchar i){
- uchar m;
- for(m=0;m<8;m++)
- disword[i+1+m] = &CPYRT_WORDS[m];
- }
- void Show_Cpyrt(){
- uchar i;
- for(i=1;i<9;i++)
- disword[i] = &NO_WORDS[12];
- Put_Cpyrt(8);
- Move_Down();
- Put_Cpyrt(0);
- Put_Tdispram(8);
- Move_Down();
- }
-
- //========================
- //參數(shù)i:放入第幾屏緩存
- //參數(shù)j:詩歌第幾頁
- //========================
- void Put_Song(uchar i,uchar j){
- uchar m;
- for(m=0;m<8;m++)
- disword[i+1+m] = &SONG_WORDS[j+m];
- }
- //顯示詩歌
- void Show_Song(){
- uchar i;
- Put_Song(8,0);
- Move_Up();
- for(i=0;i<3;i++){
- Put_Song(0,i*8);
- Put_Song(8, (i+1)*8);
- Move_Up();
- }
- Put_Song(0, 3*8);
- Put_Tdispram(8);
- Move_Up();
- }
-
- //======================
- //*滾動顯示所有信息*
- //======================
- void Show_All_Info(){
- Put_Adispram(8);
- Move_Down(); //切換效果
-
- Put_Adispram(0);
- Put_Ydispram(8); //XXXX年
- Show_All_Word();
-
- Put_Ydispram(0); //XXXX年
- Put_Ddispram(8);
- Show_All_Word();
- Put_Ddispram(0);
- Put_Kdispram(8);
- Show_All_Word();
-
- Read_Temperature();
- Disp_Temperature();
- Put_Kdispram(0);
- Put_Tdispram(8);
- Show_All_Word();
- Read_Temperature();
- Disp_Temperature();
- Put_Tdispram(0);
- Put_sTEMP(8);
- Show_All_Word();
- Read_TIME();
- Put_sTEMP(0);
- Put_Tdispram(8);
- Move_Up();
-
- }
-
- /*us級延時函數(shù) */
- /*******************************************************************/
- void Delay(unsigned int num)
- {
- num = num/2;
- while( --num ) ;
- }
- /*初始化ds1820 */
- /*******************************************************************/
- Init_DS18B20(void)
- {
- DQ = 1 ; //DQ復(fù)位
- Delay(8) ; //稍做延時
- DQ = 0 ; //單片機(jī)將DQ拉低
- Delay(90) ; //精確延時 大于 480us
- DQ = 1 ; //拉高總線
- Delay(8) ;
- presence = DQ ; //如果=0則初始化成功 =1則初始化失敗
- Delay(100) ;
- DQ = 1 ;
-
- return(presence) ; //返回信號,0=presence,1= no presence
- }
- /* 讀一個字節(jié) */
- /*******************************************************************/
- ReadOneChar(void)
- {
- unsigned char i = 0 ;
- unsigned char dat = 0 ;
- for (i = 8 ; i > 0 ; i--)
- {
- DQ = 0 ; // 給脈沖信號
- dat >>= 1 ;
- DQ = 1 ; // 給脈沖信號
- if(DQ)
- dat |= 0x80 ;
- Delay(4) ;
- }
- return (dat) ;
- }
- /* 寫一個字節(jié) */
- /*******************************************************************/
- WriteOneChar(unsigned char dat)
- {
- unsigned char i = 0 ;
- for (i = 8 ; i > 0 ; i--)
- {
- DQ = 0 ;
- DQ = dat&0x01 ;
- Delay(5) ;
- DQ = 1 ;
- dat>>=1 ;
- }
- }
- /* 讀取溫度 */
- /*******************************************************************/
- Read_Temperature(void)
- {
- Init_DS18B20() ;
-
- WriteOneChar(0xCC) ; // 跳過讀序號列號的操作
- WriteOneChar(0x44) ; // 啟動溫度轉(zhuǎn)換
- Init_DS18B20() ;
- WriteOneChar(0xCC) ; //跳過讀序號列號的操作
- WriteOneChar(0xBE) ; //讀取溫度寄存器
- temp_data[0] = ReadOneChar() ; //溫度低8位
- temp_data[1] = ReadOneChar() ; //溫度高8位
- }
- /* 數(shù)據(jù)轉(zhuǎn)換與溫度顯示 */
- /*******************************************************************/
- void Disp_Temperature()
- {
- temp_ram[4]=temp_data[0]&0x0f ;
- temp_ram[0]=ditab[temp_ram[4]]+0x30 ; //查表得小數(shù)位的值
-
- temp_ram[4]=((temp_data[0]&0xf0)>>4)|((temp_data[1]&0x0f)<<4) ;
- temp_ram[3]=temp_ram[4]/100+0x30 ;
- temp_ram[1]=temp_ram[4]%100 ;
- temp_ram[2]=temp_ram[1]/10+0x30 ;
- temp_ram[1]=temp_ram[1]%10+0x30 ;
- if(temp_ram[3]==0x30) //高位為0,不顯示
- {
- temp_ram[3]=0x20 ;
- if(temp_ram[2]==0x30) //次高位為0,不顯示
- temp_ram[2]=0x20 ;
- }
- }
- void start_time(){
- Time.Year = 0x10;
- Time.Month = 0x7;
- Time.Day = 0x23;
- Time.Hour = 0x21;
- Time.Minute = 0x58;
- Time.Second = 0x0;
- Time.Week = 0x5;
- }
- //=================
- //****校時函數(shù)****
- //=================
- void Change_Time(){
- //
- MSG_MV = MSG_MV_L;
- move_times = 0;
- start_word=0;
- TMP_TIME = Time.Hour;
- TR1 = 1; //開啟定時器1閃爍
- do{
- switch(CHANGE){
- case CHG_HOUR:
- case CHG_MIN:
- case CHG_SEC:
- Put_Tdispram(0);
- break;
- case CHG_MON:
- case CHG_DAY:
- Put_Ddispram(0);
- break;
- case CHG_WEEK:
- Put_Kdispram(0);
- break;
- case CHG_YEAR:
- Put_Ydispram(0);
- break;
- default:
- break;
- }
- Show_sWord();
- //if(!key_done)
- // ReadKey1();
- }while(ReadKey1() != KEY3_S && exit < 10); //MSG_KEY
- Change_obj(); //保證退出校時無隱身
- HIDE = 0;
- key_done = 0;
- //key_done = 1; //按鍵事件處理完成
- TR1 = 0; //關(guān)閉定時器1閃爍
-
- }
- //==================
- //****對象切換****
- //==================
- void Change_obj(){
- switch(CHANGE){
- case CHG_HOUR:
- if(Time.Hour == 0xcc)
- Time.Hour = TMP_TIME;
- TMP_TIME = Time.Minute;
- break;
- case CHG_MIN:
- if(Time.Minute == 0xcc)
- Time.Minute = TMP_TIME;
- TMP_TIME = Time.Second;
- break;
- case CHG_SEC:
- if(Time.Second == 0xcc)
- Time.Second = TMP_TIME;
- TMP_TIME = Time.Month;
- break;
- case CHG_MON:
- if(Time.Month == 0xcc)
- Time.Month = TMP_TIME;
- TMP_TIME = Time.Day;
- break;
- case CHG_DAY:
- if(Time.Day == 0xcc)
- Time.Day = TMP_TIME;
- TMP_TIME = Time.Week;
- break;
- case CHG_WEEK:
- if(Time.Week == 0xcc)
- Time.Week = TMP_TIME;
- TMP_TIME = Time.Year;
- break;
- case CHG_YEAR:
- if(Time.Year == 0xcc)
- Time.Year = TMP_TIME;
- TMP_TIME = Time.Hour;
- break;
- default:
- break;
- }
- }
- //==================
- //****加加函數(shù)****
- //功能: 0x19 ++ =0x20
- //==================
- uchar Add_num(char *num){
- ++(*num);
- if(((*num) & 0x0f) == 0x0a){
- *num += 0x10;
- *num &= 0xf0;
- }
- return *num;
- }
- //==================
- //****校時加加****
- //==================
- void Add_Time(){
- switch(CHANGE){
- case CHG_HOUR:
- if(HIDE){
- if(Add_num(&TMP_TIME) == 0x24)
- TMP_TIME= 0;
- }
- else{
- if(Add_num(&Time.Hour) == 0x24)
- Time.Hour = 0;
- }
- break;
- case CHG_MIN:
- if(HIDE){
- if(Add_num(&TMP_TIME) == 0x60)
- TMP_TIME= 0;
- }
- else{
- if(Add_num(&Time.Minute) == 0x60)
- Time.Minute= 0;
- }
- break;
- case CHG_SEC:
- if(HIDE){
- if(Add_num(&TMP_TIME) == 0x60)
- TMP_TIME= 0;
- }
- else{
- if(Add_num(&Time.Second) == 0x60)
- Time.Second = 0;
- }
- break;
- case CHG_MON:
- if(HIDE){
- if(Add_num(&TMP_TIME) == 0x13)
- TMP_TIME= 0;
- }
- else{
- if(Add_num(&Time.Month) == 0x13)
- Time.Month= 1;
- }
- break;
- case CHG_DAY:
- if(HIDE){
- if(Add_num(&TMP_TIME) == 0x32)
- TMP_TIME= 0;
- }
- else{
- if(Add_num(&Time.Day) == 0x32)
- Time.Day= 0;
- }
- break;
- case CHG_WEEK:
- if(HIDE){
- if(Add_num(&TMP_TIME) == 0x08)
- TMP_TIME= 0;
- }
- else{
- if(Add_num(&Time.Week) == 0x08)
- Time.Week= 1;
- }
- break;
- case CHG_YEAR:
- if(HIDE){
- if(Add_num(&TMP_TIME) == 0xa0)
- TMP_TIME = 0;
- }
- else{
- if(Add_num(&Time.Year) == 0xa0)
- Time.Year = 0;
- }
- //if(Add_num(&Time.Year) == 0x24)
- // Time.Year= 0;
- break;
- default:
- break;
- }
- }
- //==================
- //****減減函數(shù)****
- //功能: 0x20 -- =0x19
- //==================
- uchar Cut_num(char *num){
- --(*num);
- if(((*num)&0x0f) == 0x0f){
- //*num -= 0x10;
- *num &= 0xf9;
- }
- //if((*num == 0xf9)
- //*num = 0x99;
- return *num;
- }
- //==================
- //****校時減減****
- //==================
- void Cut_Time(){
- switch(CHANGE){
- case CHG_HOUR:
- if(HIDE){
- if(Cut_num(&TMP_TIME) == 0xf9)
- TMP_TIME= 0x23;
- }
- else{
- if(Cut_num(&Time.Hour) == 0xf9)
- Time.Hour = 0x23;
- }
- break;
- case CHG_MIN:
- if(HIDE){
- if(Cut_num(&TMP_TIME) == 0xf9)
- TMP_TIME= 0x59;
- }
- else{
- if(Cut_num(&Time.Minute) == 0xf9)
- Time.Minute= 0x59;
- }
- break;
- case CHG_SEC:
- if(HIDE){
- if(Cut_num(&TMP_TIME) == 0xf9)
- TMP_TIME= 0x59;
- }
- else{
- if(Cut_num(&Time.Second) == 0xf9)
- Time.Second = 0x59;
- }
- break;
- case CHG_MON:
- if(HIDE){
- if(Cut_num(&TMP_TIME) == 0xf9)
- TMP_TIME= 0x12;
- }
- else{
- if(Cut_num(&Time.Month) == 0xf9)
- Time.Month= 0x12;
- }
- break;
- case CHG_DAY:
- if(HIDE){
- if(Cut_num(&TMP_TIME) == 0xf9)
- TMP_TIME= 0x31;
- }
- else{
- if(Cut_num(&Time.Day) == 0xf9)
- Time.Day= 0x31;
- }
- break;
- case CHG_WEEK:
- if(HIDE){
- if(Cut_num(&TMP_TIME) == 0xf9)
- TMP_TIME= 0x7;
- }
- else{
- if(Cut_num(&Time.Week) == 0xf9)
- Time.Week= 0x7;
- }
- break;
- case CHG_YEAR:
- if(HIDE){
- if(Cut_num(&TMP_TIME) == 0xf9)
- TMP_TIME= 0x99;
- }
- else{
- if(Cut_num(&Time.Year) == 0xf9)
- Time.Year = 0x99;
- }
- //if(Cut_num(&Time.Year) == 0x99)
- // Time.Year= 0;
- break;
- default:
- break;
- }
- }
- //======按鍵======
- uchar ReadKey(){
- //
- if(!key_done){
- switch(MSG_KEY){
- case KEY0_S:STATE = STA_sTIME;
- break;
- case KEY1_S:STATE = STA_gWORD; //STA_sWEEK
- break;
- case KEY2_S:STATE = STA_gTEMP;
- break;
- case KEY3_S:STATE = STA_gTIME;
- break;
- case KEY0_L:STATE = STA_CHG;
- break;
- case KEY1_L:STATE = STA_SONG;
- break;
- case KEY2_L:STATE = STA_gTEMP;
- break;
- case KEY3_L:STATE = STA_gWORD; //STA_sTIME
- break;
- default: break;
- }
- }
- key_done = 1; //按鍵事件處理完成
- return MSG_KEY;
- }
- //=======================
- //****校時按鍵處理****
- //=======================
- uchar ReadKey1(){
- //
- if(!key_done){
- switch(MSG_KEY){
- case KEY0_S: //切換校時對象
- case KEY0_L:
- exit = 0;
- TR1 = 0; //關(guān)閉定時器1閃爍
- Change_obj();
- if(CHANGE++ >= CHG_YEAR)
- CHANGE = CHG_HOUR;
- TR1 = 1; //開啟定時器1閃爍
- break;
- case KEY1_S: //加加
- case KEY1_L:
- exit = 0;
- TR1 = 0; //關(guān)閉定時器1閃爍
- Add_Time();
- TR1 = 1; //開啟定時器1閃爍
- break;
- case KEY2_S: //減減
- case KEY2_L:
- exit = 0;
- TR1 = 0; //關(guān)閉定時器1閃爍
- Cut_Time();
- TR1 = 1; //開啟定時器1閃爍
- break;
- case KEY3_L:
- case KEY3_S:
- return KEY3_S;
- default: break;
- }
- }
- key_done = 1; //按鍵事件處理完成
- return 0;
- }
- //===========================
- void Tinit(){
- TMOD = 0x11;
- TH0 = 0xD8;
- TL0 = 0xF0;
- TH1 = 0x42;
- TL1 = 0xCA;
- TR0 = 1;
- //TR1 = 1;
- ET0 = 1;
- ET1 = 1;
- EA = 1;
- }
- timer0() interrupt 1{
- TH0 = 0xD8;
- TL0 = 0xF0;
- if(P1 != 0xff) {//若有鍵按下
- cur_key_val = P1&0x0f; //記錄按鍵值
- if(key_times < 150)
- key_times++;
- else{
- key_keep_times++; //長按連擊
- if(key_keep_times >= 10){ //10 1秒連擊10次
- key_keep_times = 0;
- MSG_KEY = 0x10 | cur_key_val;
- key_done = 0; //按鍵事件復(fù)位
- }
- }
- }else{
- if(key_times > 2 && key_times < 100 && key_done){ //短按鍵
- MSG_KEY = cur_key_val;
- key_done = 0; //按鍵事件復(fù)位
-
- ……………………
- …………限于本文篇幅 余下代碼請從51黑下載附件…………
復(fù)制代碼
所有資料51hei提供下載:
led點陣時鐘.rar
(1.92 MB, 下載次數(shù): 132)
2017-11-15 19:11 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|
|