完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
程序(32*16)点阵时钟,看看哪里有问题,谢谢
// A B C D 对应P1.0; P1.1 ; P1.2; P1.3 //-------------------------------- #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; //======================== //****显示状态定义**** #define STA_gtiME 1 //滚动显示时间 #define STA_gTEMP 2 //滚动显示温度 #define STA_gWORD 3 //滚动显示文字 #define STA_sTIME 4 //静态显示时间 #define STA_sWEEK 5 //静态显示星期 #define STA_sDATE 6 //静态显示日期 #define STA_sYEAR 7 //静态显示年份 #define STA_sTEMP 8 //静态显示温度 #define STA_sWORD 9 //静态显示文字 #define STA_CHG 10 //校时模式 #define STA_SONG 11 //滚动显示诗歌 #define STA_COPYRIGHT 12 //开机显示 uchar STATE = 1; //========================= //****校时状态定义**** #define CHG_HOUR 1 //调整小时 #define CHG_MIN 2 //调整分 #define CHG_SEC 3 //调整秒 #define CHG_MON 4 //调整月 #define CHG_DAY 5 //调整日 #define CHG_WEEK 6 //调整星期 #define CHG_YEAR 7 //调整年 uchar CHANGE = 1; uchar hide_times = 0; //校时闪烁时间变量 uchar HIDE = 0; //隐藏显示标志位 uchar TMP_TIME = 0; //========================= //****按键定义**** ***it key0 = P1^0; ***it key1 = P1^1; ***it key2 = P1^2; ***it 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; //持续时间 uchar key_keep_times = 0; uchar cur_key_val = 0; uchar key_done = 0; //按键事件有无做好 uchar exit = 0; //校时状态下长时间无按键退出 //========================= //uchar time_read_times = 0; //读时间 //uchar tem_read_times = 0; //读温度 //========================= //****引脚定义**** ***it CLK =P2^5 ; //74HC595移时钟 ***it STB =P2^4 ; // 74HC595锁存信号 ***it Red=P2^7 ; //红色数据输出引脚低电平有效 ***it Greed=P2^6; //全屏控制使能0,低电平有效 ***it OE = P0^7; //全屏使能 //======================== //****DS1302**** ***it SCLK=P0^5; //位定义1302芯片的接口,时钟输出端口定义在P2.4引脚 ***it DATA=P0^6; //位定义1302芯片的接口,数据输出端定义在P2.5引脚 ***it RST=P0^7; //位定义1302芯片的接口,复位端口定义在P2.6引脚 typedef struct __SYSTEMTIME__ { uchar Second; uchar Minute; uchar Hour; uchar Day; uchar Month; uchar Week; uchar Year; } SYSTEMTIME; //定义的时间类型 SYSTEMTIME Time; //========================================= //****18B20**** ***it DQ = P0^4 ; //定义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; //要发送的数据变量 uchar hang; //行扫描变量 (半屏只有16行,所以hang=0到15) uchar move_times = 0; //左右移动位数 uchar start_word = 0; uchar data h_dispram[10]; //显示缓存 uchar code *disword[26]; //显示文字指针 void Keyscan (void); //修改参数按键扫描子程序 void Sendping(); //发送半屏子程序 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]= { {0x21,0x11,0x11,0x02,0x97,0x52,0x52,0x12,0x2F,0x22,0xE2,0x22,0x23,0x20,0x20,0x20}, {0x00,0x00,0xFE,0x00,0xF8,0x88,0x48,0x08,0xFE,0x88,0x48,0x08,0xFE,0x08,0x28,0x10}, {0x22,0x11,0x11,0x07,0x80,0x50,0x57,0x10,0x20,0x2F,0xE0,0x20,0x20,0x20,0x20,0x20}, {0x10,0x10,0x20,0xFC,0x40,0x40,0xFC,0x40,0x40,0xFE,0x40,0x40,0x40,0x40,0x40,0x40}, {0x01,0x10,0x0C,0x08,0x7F,0x40,0x8F,0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x02,0x01}, {0x08,0x8C,0xC8,0x90,0xFE,0x04,0xE8,0x40,0x80,0xFE,0x80,0x80,0x80,0x80,0x80,0x00}, {0x00,0xF8,0x8F,0x94,0xA0,0xA3,0x90,0x88,0x8F,0xA9,0x91,0x81,0x82,0x82,0x84,0x88}, {0x80,0x40,0xFE,0x04,0x00,0xF8,0x00,0x00,0xFE,0x20,0x20,0x20,0x22,0x22,0x22,0x1E}, {0x04,0x0C,0x11,0x3F,0x02,0xFF,0x04,0x09,0x32,0xCC,0x31,0x06,0x18,0x03,0x7C,0x00}, {0x00,0x20,0xF0,0x10,0x00,0xFC,0x40,0x20,0x18,0x6E,0x84,0x18,0x60,0x80,0x00,0x00}, {0x01,0x7F,0x44,0xBF,0x04,0x3F,0x04,0x7F,0x08,0x3F,0xC9,0x09,0x09,0x02,0x0C,0x30}, {0x00,0xFE,0x44,0xF0,0x40,0xF8,0x40,0xFC,0x30,0xEE,0x24,0x20,0x20,0xC0,0x38,0x10}, {0x08,0x0C,0x09,0x13,0x12,0x34,0x50,0x90,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10}, {0x80,0x80,0x00,0xFE,0x80,0x88,0xFC,0x80,0x80,0x84,0xFE,0x80,0x80,0x80,0x80,0x80}, {0x00,0x0F,0x08,0x08,0x08,0x0F,0x08,0x00,0x7E,0x42,0x42,0x42,0x42,0x7E,0x42,0x00}, {0x00,0xF0,0x10,0x10,0x10,0xF0,0x10,0x00,0xFC,0x84,0x84,0x84,0x84,0xFC,0x84,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,0x1F,0x10,0x10,0x14,0x12,0x11,0x10,0x10,0x11,0x12,0x24,0x28,0x40,0x80,0x00}, {0x00,0xF8,0x08,0x48,0x68,0x48,0x48,0x88,0x88,0x48,0x6A,0x2A,0x26,0x06,0x02,0x00},/*"风",0*/ {0x01,0xFF,0x01,0x01,0x7F,0x00,0x3F,0x21,0x21,0x3F,0x20,0x20,0x40,0x40,0x80,0x00}, {0x00,0xFE,0x00,0x00,0xFC,0x00,0xF8,0x08,0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00},/*"声",1*/ {0x00,0xFF,0x01,0x01,0x3F,0x31,0x29,0x25,0x31,0x29,0x25,0x21,0x21,0x21,0x21,0x20}, {0x00,0xFE,0x00,0x00,0xF8,0x88,0x48,0x28,0x88,0x48,0x28,0x08,0x08,0x08,0x28,0x10},/*"雨",2*/ {0x01,0xFF,0x01,0x01,0x7F,0x00,0x3F,0x21,0x21,0x3F,0x20,0x20,0x40,0x40,0x80,0x00}, {0x00,0xFE,0x00,0x00,0xFC,0x00,0xF8,0x08,0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00},/*"声",3*/ {0x01,0xFF,0x01,0x01,0x7F,0x00,0x3F,0x21,0x21,0x3F,0x20,0x20,0x40,0x40,0x80,0x00}, {0x00,0xFE,0x00,0x00,0xFC,0x00,0xF8,0x08,0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00},/*"声",4*/ {0x01,0xFF,0x01,0x01,0x7F,0x00,0x3F,0x21,0x21,0x3F,0x20,0x20,0x40,0x40,0x80,0x00}, {0x00,0xFE,0x00,0x00,0xFC,0x00,0xF8,0x08,0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00},/*"声",5*/ {0x0C,0x06,0x02,0x01,0x03,0x02,0x02,0x04,0x04,0x08,0x08,0x10,0x20,0x40,0x80,0x00}, {0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x40,0x20,0x20,0x10,0x08,0x0E,0x04,0x00,0x00},/*"入",6*/ {0x00,0x7F,0x08,0x08,0x0F,0x08,0x08,0x0F,0x08,0x08,0x08,0xFF,0x00,0x00,0x00,0x00}, {0x00,0xFE,0x10,0x10,0xF0,0x10,0x10,0xF0,0x10,0x10,0xFE,0x90,0x10,0x10,0x10,0x10},/*"耳",7*/ {0x02,0x01,0x3F,0x40,0x5F,0x01,0x02,0x0F,0x72,0x04,0x19,0x66,0x18,0x60,0x05,0x02}, {0x00,0x00,0xFE,0x04,0xE8,0x00,0x00,0x20,0xB0,0xC0,0xC0,0xB0,0x8E,0x84,0x00,0x00},/*"家",8*/ {0x01,0xFF,0x01,0x1F,0x11,0x1F,0x01,0x3F,0x01,0xFF,0x01,0x3F,0x01,0x09,0x05,0x02}, {0x00,0xFE,0x00,0xF8,0x08,0xF8,0x00,0xF8,0x08,0xFE,0x08,0xF8,0x08,0x00,0x00,0x00},/*"事",9*/ {0x00,0x7F,0x40,0x5F,0x41,0x41,0x41,0x4F,0x41,0x41,0x41,0x5F,0x40,0x40,0x7F,0x40}, {0x00,0xFC,0x04,0xF4,0x04,0x04,0x04,0xE4,0x44,0x24,0x24,0xF4,0x04,0x04,0xFC,0x04},/*"国",10*/ {0x01,0xFF,0x01,0x1F,0x11,0x1F,0x01,0x3F,0x01,0xFF,0x01,0x3F,0x01,0x09,0x05,0x02}, {0x00,0xFE,0x00,0xF8,0x08,0xF8,0x00,0xF8,0x08,0xFE,0x08,0xF8,0x08,0x00,0x00,0x00},/*"事",11*/ {0x01,0xFF,0x01,0x1F,0x11,0x1F,0x01,0x3F,0x01,0xFF,0x01,0x3F,0x01,0x09,0x05,0x02}, {0x00,0xFE,0x00,0xF8,0x08,0xF8,0x00,0xF8,0x08,0xFE,0x08,0xF8,0x08,0x00,0x00,0x00},/*"事",12*/ {0x01,0xFF,0x01,0x1F,0x11,0x1F,0x01,0x3F,0x01,0xFF,0x01,0x3F,0x01,0x09,0x05,0x02}, {0x00,0xFE,0x00,0xF8,0x08,0xF8,0x00,0xF8,0x08,0xFE,0x08,0xF8,0x08,0x00,0x00,0x00},/*"事",13*/ {0x08,0x04,0x06,0x04,0x7F,0x01,0x01,0x01,0xFF,0x01,0x02,0x04,0x08,0x10,0x20,0x40}, {0x20,0x30,0x20,0x48,0xFC,0x00,0x00,0x00,0xFE,0x00,0x80,0x40,0x20,0x30,0x1C,0x08},/*"关",14*/ {0x02,0x01,0x00,0x00,0x08,0x08,0x08,0x48,0x48,0x48,0x88,0x08,0x08,0x08,0x07,0x00}, {0x00,0x00,0x80,0xC0,0x80,0x00,0x10,0x08,0x04,0x06,0x04,0x10,0x10,0x10,0xF0,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}, {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}, {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}, {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}, }; 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 = &WORDS[i-1][0]; //first_word+ } } void Put_Hdispram() { uchar i; for(i=0;i<10;i++) { h_dispram = *(disword[i+start_word]+hang); // } } void Move_Left() { uchar i; for(i=0;i<9;i++) { h_dispram = (h_dispram << (move_times)) | (h_dispram[i+1] >> (8-move_times)); } } void Move_Right() { uchar i; for(i=9;i>0;i--) { h_dispram = (h_dispram >> (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<8;n++) { for(j=0;j<16-m;j++) { for(i=0;i<10;i++) { h_dispram = *(disword+m+j); } Show_Line(); } for(j=16-m;j<16;j++) { for(i=0;i<10;i++) { h_dispram = *(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<8;n++) { for(j=0;j for(i=0;i<10;i++) { h_dispram = *(disword[i+8]+15-m+j); } Show_Line(); } for(j=m;j<16;j++) { for(i=0;i<10;i++) { h_dispram = *(disword-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; //上升沿数据锁存 RowsCan(); //行扫描 OE = 0; // delay(); // } void Show_sWord() { int m,i;// hang = 0; for(m=0;m<14;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<6;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: Read_Temperature(); 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<4;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++); } //------------------------------------ //----------字发送子程序----------- 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; } /***************************************************** 函数功能:延时若干微秒 入口参数:n ***************************************************/ void delaynus(unsigned char n) { unsigned char i; for(i=0;i } /***************************************************** 函数功能:向1302写一个字节数据 入口参数:x ***************************************************/ void Write1302(unsigned char dat) { unsigned char i; SCLK=0; //拉低SCLK,为脉冲上升沿写入数据做好准备 delaynus(2); //稍微等待,使硬件做好准备 for(i=0;i<8;i++) //连续写8个二进制位数据 { DATA=dat&0x01; //取出dat的第0位数据写入1302 delaynus(2); //稍微等待,使硬件做好准备 SCLK=1; //上升沿写入数据 delaynus(2); //稍微等待,使硬件做好准备 SCLK=0; //重新拉低SCLK,形成脉冲 dat>>=1; //将dat的各数据位右移1位,准备写入下一个数据位 } } /***************************************************** 函数功能:根据命令字,向1302写一个字节数据 入口参数:Cmd,储存命令字;dat,储存待写的数据 ***************************************************/ void WriteSet1302(unsigned char Cmd,unsigned char dat) { RST=0; //禁止数据传递 SCLK=0; //确保写数居前SCLK被拉低 RST=1; //启动数据传输 delaynus(2); //稍微等待,使硬件做好准备 Write1302(Cmd); //写入命令字 Write1302(dat); //写数据 SCLK=1; //将时钟电平置于已知状态 RST=0; //禁止数据传递 } /***************************************************** 函数功能:从1302读一个字节数据 入口参数:x ***************************************************/ unsigned char Read1302(void) { unsigned char i,dat; delaynus(2); //稍微等待,使硬件做好准备 for(i=0;i<8;i++) //连续读8个二进制位数据 { dat>>=1; //将dat的各数据位右移1位,因为先读出的是字节的最低位 if(DATA==1) //如果读出的数据是1 dat|=0x80; //将1取出,写在dat的最高位 SCLK=1; //将SCLK置于高电平,为下降沿读出 delaynus(2); //稍微等待 SCLK=0; //拉低SCLK,形成脉冲下降沿 delaynus(2); //稍微等待 } return dat; //将读出的数据返回 } /***************************************************** 函数功能:根据命令字,从1302读取一个字节数据 入口参数:Cmd ***************************************************/ unsigned char ReadSet1302(unsigned char Cmd) { unsigned char dat; RST=0; //拉低RST SCLK=0; //确保写数居前SCLK被拉低 RST=1; //启动数据传输 Write1302(Cmd); //写入命令字 dat=Read1302(); //读出数据 SCLK=1; //将时钟电平置于已知状态 RST=0; //禁止数据传递 return dat; //将读出的数据返回 } /***************************************************** 函数功能: 1302进行初始化设置 ***************************************************/ void Init_DS1302(void) { unsigned char flag; flag= ReadSet1302(0x81); if(flag&0x80) { //判断时钟芯片是否关闭 WriteSet1302(0x8E,0x00); //根据写状态寄存器命令字,写入不保护指令 WriteSet1302(0x80,((0/10)<<4|(0%10))); //根据写秒寄存器命令字,写入秒的初始值 WriteSet1302(0x82,((18/10)<<4|(18%10))); //根据写分寄存器命令字,写入分的初始值 WriteSet1302(0x84,((21/10)<<4|(21%10))); //根据写小时寄存器命令字,写入小时的初始值 WriteSet1302(0x86,((23/10)<<4|(23%10))); //根据写日寄存器命令字,写入日的初始值 WriteSet1302(0x88,((7/10)<<4|(7%10))); //根据写月寄存器命令字,写入月的初始值 //WriteSet1302(0x8A,2); WriteSet1302(0x8c,((10/10)<<4|(10%10))); //根据写小时寄存器命令字,写入小时的初始值 WriteSet1302(0x90,0xa5); WriteSet1302(0x8E,0x80); } //如果不想每次都初始化时间,也就是掉电后还想让时钟继续走时的话 就用上面的语句 } void write_time1302() { WriteSet1302(0x8E,0x00); //根据写状态寄存器命令字,写入不保护指令 WriteSet1302(0x80,Time.Second); //根据写秒寄存器命令字,写入秒的初始值 WriteSet1302(0x82,Time.Minute); //根据写分寄存器命令字,写入分的初始值 WriteSet1302(0x84,Time.Hour); //根据写小时寄存器命令字,写入小时的初始值 WriteSet1302(0x86,Time.Day); //根据写日寄存器命令字,写入日的初始值 WriteSet1302(0x88,Time.Month); //根据写月寄存器命令字,写入月的初始值 WriteSet1302(0x8A,Time.Week); WriteSet1302(0x8c,Time.Year); //根据写小时寄存器命令字,写入小时的初始值 // WriteSet1302(0x90,0xa5); //WriteSet1302(0x8E,0x80); } //读时间 void Read_TIME() { RST=0; //拉低RST SCLK=0; //确保写数居前SCLK被拉低 RST=1; //启动数据传输 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; //将时钟电平置于已知状态 RST=0; //禁止数据传递 */ } 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[0]; disword[a+8] = &NO_WORDS[11][0]; //":" //第二屏 //disword[4] = &TIME_WORDS[]; } //将年份放入到显示缓存 //需要参数:缓冲区首地址下标 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]; } //将星期放入到显示缓存 //参数:缓冲区首地址下标 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]; } //将日期放入到显示缓存 //参数:缓冲区首地址下标 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]; //秒地位 } //将时间放入到显示缓存 //参数:缓冲区首地址下标 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]; //秒地位 } //=================================== //*****关于温度检测部分***** 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]; //小数 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]; //小数点 disword[i+6] = &NO_WORDS[temp_ram[0]][0]; //小数 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 = &NO_WORDS[12]; Put_Cpyrt(8); Move_Down(); Put_Cpyrt(0); Put_Tdispram(8); Move_Down(); } //======================== //参数i:放入第几屏缓存 //参数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级延时函数 */ /*******************************************************************/ void Delay(unsigned int num) { num = num*2; while( --num ) ; } /*初始化ds1820 */ /*******************************************************************/ Init_DS18B20(void) { DQ = 1 ; //DQ复位 Delay(8) ; //稍做延时 DQ = 0 ; //单片机将DQ拉低 Delay(90) ; //精确延时 大于 480us DQ = 1 ; //拉高总线 Delay(8) ; presence = DQ ; //如果=0则初始化成功 =1则初始化失败 Delay(100) ; DQ = 1 ; return(presence) ; //返回信号,0=presence,1= no presence } /* 读一个字节 */ /*******************************************************************/ 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) ; } /* 写一个字节 */ /*******************************************************************/ 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) ; // 启动温度转换 Init_DS18B20() ; WriteOneChar(0xCC) ; //跳过读序号列号的操作 WriteOneChar(0xBE) ; //读取温度寄存器 temp_data[0] = ReadOneChar() ; //温度低8位 temp_data[1] = ReadOneChar() ; //温度高8位 } /* 数据转换与温度显示 */ /*******************************************************************/ void Disp_Temperature() { temp_ram[4]=temp_data[0]&0x0f ; temp_ram[0]=ditab[temp_ram[4]]+0x30 ; //查表得小数位的值 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; }*/ //================= //****校时函数**** //================= 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; //关闭定时器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; } } //================== //****加加函数**** //功能: 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= 1; } 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; } } //================== //****减减函数**** //功能: 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; //关闭定时器1闪烁 Change_obj(); if(CHANGE++ >= CHG_YEAR) CHANGE = CHG_HOUR; TR1 = 1; //开启定时器1闪烁 break; case KEY1_S: //加加 case KEY1_L: exit = 0; TR1 = 0; //关闭定时器1闪烁 Add_Time(); TR1 = 1; //开启定时器1闪烁 break; case KEY2_S: //减减 case KEY2_L: exit = 0; TR1 = 0; //关闭定时器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 = 0xb1; TL0 = 0xe0; 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; //按键事件复位 } } }else{ if(key_times > 2 && key_times < 100 && key_done) { //短按键 MSG_KEY = cur_key_val; key_done = 0; //按键事件复位 } else if(key_times >= 100 && key_done) { //长按键 MSG_KEY = 0x10 | cur_key_val; key_done = 0; //按键事件复位 } key_times = 0; key_keep_times = 0; } } timer1() interrupt 3{ if(STATE == STA_CHG){ TH1 = 0x42; TL1 = 0xCA; if(hide_times++ == 8) { HIDE = 0; //显示 switch(CHANGE){ case CHG_HOUR: Time.Hour =TMP_TIME; break; case CHG_MIN: Time.Minute = TMP_TIME; break; case CHG_SEC: Time.Second = TMP_TIME; break; case CHG_MON: Time.Month = TMP_TIME; break; case CHG_DAY: Time.Day = TMP_TIME; break; case CHG_WEEK: Time.Week = TMP_TIME; break; case CHG_YEAR: Time.Year = TMP_TIME; break; default: break; } } if(hide_times > 17) { hide_times = 0; HIDE = 1; //隐藏 exit++; switch(CHANGE){ case CHG_HOUR: TMP_TIME = Time.Hour; Time.Hour = 0xcc; break; case CHG_MIN: TMP_TIME = Time.Minute; Time.Minute = 0xcc; break; case CHG_SEC: TMP_TIME = Time.Second; Time.Second = 0xcc; break; case CHG_MON: TMP_TIME = Time.Month; Time.Month = 0xcc; break; case CHG_DAY: TMP_TIME = Time.Day; Time.Day = 0xcc; break; case CHG_WEEK: TMP_TIME = Time.Week; Time.Week = 0xcc; break; case CHG_YEAR: TMP_TIME = Time.Year; Time.Year = 0xcc; break; default: break; } } } } void Compute_State() { switch(Time.Second) { case 0x1: //STATE = STA_gTIME; break; case 0x2: STATE = STA_sYEAR; break; case 0x15: STATE = STA_sTEMP; break; case 0x31: STATE = STA_sDATE; break; case 0x40: STATE = STA_sWEEK; break; case 0x50: STATE = STA_sTEMP; break; default: break; } if(Time.Minute%2 == 0 && Time.Second == 0) STATE = STA_gTIME; if((Time.Minute&0x0f)%5 == 0 && Time.Second == 30) STATE = STA_gTEMP; if((Time.Minute&0x0f) == 7 && Time.Second == 0) STATE = STA_gWORD; if((Time.Minute&0x0f) == 3 && Time.Second == 0) STATE = STA_SONG; } //;---------主程序循环-------------- void main() { int i; initial(); Tinit(); Init_DS1302(); Read_TIME(); //读取时间 Read_Temperature(); Show_Cpyrt(); //start_time(); //write_time1302(); MSG_MV = MSG_MV_L; STATE = STA_sTIME; while(1) { ReadKey(); switch(STATE) { case STA_gTIME: //添加代码 MSG_MV = MSG_MV_L; move_times = 0; start_word=0; Read_TIME(); //读取时间 Show_All_Info(); MSG_KEY = KEY0_S; //回到时间画面 key_done = 0; break; case STA_gTEMP: Put_Wdispram(TMP_WORDS); //,start_word++ Read_Temperature(); Disp_Temperature(); Put_gTEMP(); //Move_Down(); Show_Move_Word(TMP_WORDS); MSG_KEY = KEY0_S; //回到时间画面 key_done = 0; break; case STA_gWORD: //添加代码 Put_Wdispram(MY_WORDS); //,start_word++ //Move_Down(); Show_Move_Word(MY_WORDS); MSG_KEY = KEY0_S; //回到时间画面 key_done = 0; break; case STA_sTIME: //添加代码 MSG_MV = MSG_MV_L; move_times = 0; start_word=0; Read_TIME(); //读取时间 Put_Tdispram(0); Show_sWord(); Compute_State(); break; case STA_sDATE: //添加代码 MSG_MV = MSG_MV_L; move_times = 0; start_word=0; Read_TIME(); //读取时间 Put_Ddispram(8); Move_Down(); Put_Ddispram(0); for(i=0;i<8;i++) Show_sWord(); Read_TIME(); Put_Tdispram(8); Move_Up(); MSG_KEY = KEY0_S; //回到时间画面 key_done = 0; break; case STA_sWEEK: //添加代码 MSG_MV = MSG_MV_L; move_times = 0; start_word=0; Read_TIME(); //读取时间 Put_Kdispram(8); Move_Up(); //Move_Down(); for(i=0;i<8;i++) { Read_TIME(); //读取时间 Put_Kdispram(0); Show_sWord(); } Read_TIME(); Put_Tdispram(8); Move_Down(); //Move_Up(); MSG_KEY = KEY0_S; //回到时间画面 key_done = 0; break; case STA_sYEAR: MSG_MV = MSG_MV_L; move_times = 0; start_word=0; Read_TIME(); //读取时间 Put_Ydispram(8); Move_Down(); for(i=0;i<8;i++) { Read_TIME(); //读取时间 Put_Ydispram(0); Show_sWord(); } Read_TIME(); Put_Tdispram(8); Move_Up(); MSG_KEY = KEY0_S; //回到时间画面 key_done = 0; break; case STA_sTEMP: //添加代码 MSG_MV = MSG_MV_L; move_times = 0; start_word=0; Read_Temperature(); Disp_Temperature(); Put_sTEMP(8); Move_Up(); //Move_Down(); for(i=0;i<8;i++) { Read_Temperature(); Disp_Temperature(); Put_sTEMP(0); Show_sWord(); } Read_TIME(); Put_Tdispram(8); Move_Down(); //Move_Up(); MSG_KEY = KEY0_S; //回到时间画面 key_done = 0; break; case STA_sWORD: //添加代码 break; case STA_CHG: //校时模式 Change_Time(); write_time1302(); Read_TIME(); Put_Tdispram(8); Move_Up(); MSG_KEY = KEY0_S; break; case STA_SONG: MSG_MV = MSG_MV_L; move_times = 0; start_word=0; Show_Song(); MSG_KEY = KEY0_S; key_done = 0; break; default: break; } } } |
|
相关推荐
12个回答
|
|
哥表示看不出来~!!
|
|
|
|
眼都看花了
|
|
|
|
把警告发出来噻
|
|
|
|
警告呢,兄弟!我翻了半天才翻完!
|
|
|
|
|
|
看看怎么解决?
|
|
|
|
指针的基类型不对吧?
|
|
|
|
能具体点吗?
|
|
|
|
楼主既然能写出这么多,我不信就自己找不到原因。
|
|
|
|
|
|
第一你英文不够好, 第二你比较依赖别人,自己解决啊!
|
|
|
|
哥表示看花了眼
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
嵌入式学习-飞凌嵌入式ElfBoard ELF 1板卡-LCD显示图片编程示例之介绍mmap
238 浏览 0 评论
《DNESP32S3使用指南-IDF版_V1.6》第二章 常用的C语言知识点
629 浏览 0 评论
【RA-Eco-RA2E1-48PIN-V1.0开发板试用】(第三篇)ADC采集+PWM输出
552 浏览 0 评论
《DNK210使用指南 -CanMV版 V1.0》第四十五章 人脸识别实验
552 浏览 0 评论
1074 浏览 0 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
11764 浏览 31 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-23 06:05 , Processed in 1.116964 second(s), Total 96, Slave 77 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号