采用ucos,有詳細的說明,經典的ucos操作系統實例詳解
0.png (10.46 KB, 下載次數: 95)
下載附件
2018-3-13 02:15 上傳
單片機源程序如下:
- /****************************************Copyright (c)****************************************************
- ** Guangzhou ZHIYUAN electronics Co.,LTD.
- **
- **
- **--------------File Info---------------------------------------------------------------------------------
- ** File name: main.c
- ** Last modified Date: 2007-09-01
- ** Last Version: 1.0
- ** Descriptions: The main() function example template
- **
- **--------------------------------------------------------------------------------------------------------
- ** Created by: Zhenghongtao
- ** Created date: 2007-09-01
- ** Version: 1.0
- ** Descriptions: The original version
- **
- **--------------------------------------------------------------------------------------------------------
- ** Modified by:
- ** Modified date:
- ** Version:
- ** Descriptions:
- **
- *********************************************************************************************************/
- #include "config.h" /* 系統頭文件 */
- #include "i2c.h"
- #define TASKKEY_ID 12 /* 定義鍵盤任務的ID */
- #define TASKKEY_PRIO TASKKEY_ID /* 定義鍵盤任務的優先級 */
- #define TASKKEY_STACK_SIZE 512 /* 定義鍵盤任務堆棧大小 */
- #define TASKDISP_ID 13 /* 定義顯示任務的ID */
- #define TASKDISP_PRIO TASKDISP_ID /* 定義顯示任務的優先級 */
- #define TASKDISP_STACK_SIZE 512 /* 定義顯示任務堆棧大小 */
- #define TASKCTRL_ID 6 /* 定義控制任務的ID */
- #define TASKCTRL_PRIO TASKCTRL_ID /* 定義控制任務的優先級 */
- #define TASKCTRL_STACK_SIZE 512 /* 定義控制任務堆棧大小 */
- OS_STK TaskKeyStk[TASKKEY_STACK_SIZE]; /* 定義鍵盤任務的堆棧 */
- OS_STK TaskDispStk[TASKDISP_STACK_SIZE]; /* 定義顯示任務的堆棧 */
- OS_STK TaskCtrlStk[TASKCTRL_STACK_SIZE]; /* 定義控制任務的堆棧 */
- void TaskKey(void *pdata); /* TaskKey 鍵盤任務 */
- void TaskDisp(void *pdata); /* TaskDisp 顯示任務 */
- void TaskCtrl(void *pdata); /* TaskCtrl 控制任務 */
- void ToDispBuf(void);
- void FromDispBuf(void);
- void GetTime(void);
- void SetTime(void);
- void RTC_Exception(void);
- OS_EVENT *GmboxRingCtrl;
- unsigned int GuiMode = 0; /* 模式 */
- unsigned int GuiCursor = 8; /* 光標 */
- unsigned int GuiIndex = 0; /* 索引 */
- unsigned int GuiItem = 0; /* 條目 */
- /*********************************************************************************************************
- 時鐘結構定義
- *********************************************************************************************************/
- struct time {
- unsigned char ucHour; /* 時 */
- unsigned char ucMin; /* 分 */
- unsigned char ucSec; /* 秒 */
- unsigned char ucWeek; /* 星期 */
- unsigned short usYear; /* 年 */
- unsigned char ucMon; /* 月 */
- unsigned char ucDay; /* 日 */
- };
- typedef struct time TIME;
- typedef TIME *PTIME;
- /*********************************************************************************************************
- 鬧鐘結構定義
- *********************************************************************************************************/
- struct alarm {
- unsigned char ucHour; /* 時 */
- unsigned char ucMin; /* 分 */
- unsigned char ucSec; /* 秒 */
- unsigned char ucEnable; /* 鬧鐘使能控制 */
- struct {
- unsigned short usLevel; /* 輸出電平控制 */
- unsigned short usTime; /* 輸出時間控制 */
- } c[4]; /* 4路輸出控制 */
- };
- typedef struct alarm ALARM;
- typedef ALARM *PALARM;
- #define MAX_ALARM 4 /* 最大鬧鐘個數 */
- unsigned char GucTimeDispBuf[2][8]; /* 時鐘顯示緩沖區 */
- unsigned char GucAlarmDispBuf[MAX_ALARM][6][8]; /* 鬧鐘顯示緩沖區 */
- TIME GtimeCurrentTime; /* 當前時間 */
- ALARM GalarmRingTime[MAX_ALARM]; /* 鬧鐘時間 */
- #define LED0 (1u<<18)
- #define LED1 (1u<<19)
- #define LED2 (1u<<20)
- #define LED3 (1u<<21)
- /*********************************************************************************************************
- 時鐘模式下,下一個光標索引表
- *********************************************************************************************************/
- const unsigned char GucTimeNextCursor[2][9] = {
- {7,0,1,2,3,4,7,5,7},
- {5,0,1,2,3,4,5,5,5}
- };
- /*********************************************************************************************************
- 時鐘模式下,上一個光標索引表
- *********************************************************************************************************/
- const unsigned char GucTimePreCursor[2][9] = {
- {1,2,3,4,5,7,7,0,7},
- {1,2,3,4,5,0,5,5,5}
- };
- /*********************************************************************************************************
- 時鐘模式下,最大值限定表
- *********************************************************************************************************/
- const unsigned char GucTimeMaxTable[2][8] = {
- {0x09,0x05,0x09,0x05,0x09,0x02,0x1f,0x06},
- {0x09,0x03,0x09,0x01,0x09,0x09,0x1f,0x1f}
- };
- /*********************************************************************************************************
- 鬧鐘模式下,下一個光標索引表
- *********************************************************************************************************/
- const unsigned char GucAlarmNextCursor[6][9] = {
- {5,0,1,2,3,4,5,5,5},
- {7,0,1,2,3,4,5,6,7},
- {4,0,1,2,3,4,4,4,4},
- {4,0,1,2,3,4,4,4,4},
- {4,0,1,2,3,4,4,4,4},
- {4,0,1,2,3,4,4,4,4}
- };
- /*********************************************************************************************************
- 鬧鐘模式下,上一個光標索引表
- *********************************************************************************************************/
- const unsigned char GucAlarmPreCursor[6][9] = {
- {1,2,3,4,5,0,5,5,5},
- {1,2,3,4,5,6,7,0,7},
- {1,2,3,4,0,4,4,4,4},
- {1,2,3,4,0,4,4,4,4},
- {1,2,3,4,0,4,4,4,4},
- {1,2,3,4,0,4,4,4,4}
- };
- /*********************************************************************************************************
- 鬧鐘模式下,最大值限定表
- *********************************************************************************************************/
- const unsigned char GucAlarmMaxTable[6][8] = {
- {0x09,0x05,0x09,0x05,0x09,0x02,0x1f,0x1f},
- {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01},
- {0x09,0x09,0x09,0x09,0x01,0x1f,0x1f,0x1f},
- {0x09,0x09,0x09,0x09,0x01,0x1f,0x1f,0x1f},
- {0x09,0x09,0x09,0x09,0x01,0x1f,0x1f,0x1f},
- {0x09,0x09,0x09,0x09,0x01,0x1f,0x1f,0x1f}
- };
- /*********************************************************************************************************
- ** Function name: main
- **
- ** Descriptions: 主函數
- **
- ** input parameters:
- ** output parameters:
- **
- ** Returned value
- **
- **
- ** Created by:
- ** Created Date:
- **--------------------------------------------------------------------------------------------------------
- ** Modified by:
- ** Modified date:
- **--------------------------------------------------------------------------------------------------------
- *********************************************************************************************************/
- int main(void)
- {
- OSInit(); /* 初始化uC/OS-II */
- OSTaskCreateExt(TaskKey,
- (void *)0,
- &TaskKeyStk[TASKKEY_STACK_SIZE - 1],
- TASKKEY_PRIO,
- TASKKEY_ID,
- &TaskKeyStk[0],
- TASKKEY_STACK_SIZE,
- (void *)0,
- OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);
- /* 創建鍵盤任務 */
- OSStart(); /* 啟動多任務操作系統 */
- return (0);
- }
- /*********************************************************************************************************
- ** Function name: ZLG7290GetKey
- **
- ** Descriptions: zlg7290讀取鍵值
- **
- ** input parameters:
- ** output parameters:
- **
- ** Returned value
- **
- **
- ** Created by:
- ** Created Date:
- **--------------------------------------------------------------------------------------------------------
- ** Modified by:
- ** Modified date:
- **--------------------------------------------------------------------------------------------------------
- *********************************************************************************************************/
- uint16 ZLG7290GetKey(void)
- {
- uint8 temp[2];
-
- i2cRead( 0, /* I2C0 */
- 0x70, /* 器件地址 */
- temp, /* 接收數據的緩沖區 */
- 1, /* 器件子地址 */
- 1, /* 器件子地址類型為單字節型 */
- 2); /* 讀取數據的長度 */
- while (i2cGetFlag(0) == I2C_BUSY); /* 等待I2C操作完畢 */
- return (uint16)(temp[0] + (temp[1] * 256));
- }
- /*********************************************************************************************************
- ** Function name: ZLG7290ShowChar
- **
- ** Descriptions: zlg7290顯示數值
- **
- ** input parameters:
- ** output parameters:
- **
- ** Returned value
- **
- **
- ** Created by:
- ** Created Date:
- **--------------------------------------------------------------------------------------------------------
- ** Modified by:
- ** Modified date:
- **--------------------------------------------------------------------------------------------------------
- *********************************************************************************************************/
- void ZLG7290ShowChar(uint8 index, uint8 data)
- {
- uint8 buf[2];
-
- buf[0] = (uint8)(0x60 | (index & 0x0f));
- buf[1] = data;
- i2cWrite(0, /* I2C0 */
- 0x70, /* 器件地址 */
- buf, /* 要寫入數據的緩沖區 */
- 0x07, /* 器件子地址 */
- 1, /* 器件子地址類型為單字節型 */
- 2); /* 寫入的數量 */
- while (i2cGetFlag(0) == I2C_BUSY); /* 等待I2C操作完畢 */
- }
- /*********************************************************************************************************
- ** Function name: rtcInit
- **
- ** Descriptions: RTC初始化
- **
- ** input parameters:
- ** output parameters:
- **
- ** Returned value
- **
- **
- ** Created by:
- ** Created Date:
- **--------------------------------------------------------------------------------------------------------
- ** Modified by:
- ** Modified date:
- **--------------------------------------------------------------------------------------------------------
- *********************************************************************************************************/
- void rtcInit(void)
- {
- if(ALYEAR != 2007) { /* 初始化一次 */
- CCR = 0x00; /* 禁止時間計數器 */
- PREINT = Fpclk/32768-1; /* 設置基準時鐘分頻器 */
- PREFRAC = Fpclk%32768;
- CISS = 0; /* 禁止次秒級中斷 */
- AMR = 0xFF; /* 禁止報警中斷 */
- CIIR = 0x01; /* 使能秒增量中斷 */
- ILR = 0x07; /* 清除RTC中斷標志 */
- ALYEAR = 2007; /* 初始化標志 */
-
- YEAR = 2007; /* 初始化時間寄存器 */
- MONTH = 11;
- DOM = 5;
- DOW = 0;
- HOUR = 12;
- MIN = 0;
- SEC = 0;
- CCR = 0x11;
- }
- GetTime(); /* 更新當前時間 */
- }
- /*********************************************************************************************************
- ** Function name: TaskKey
- **
- ** Descriptions: 鍵盤任務
- **
- ** input parameters:
- ** output parameters:
- **
- ** Returned value
- **
- **
- ** Created by:
- ** Created Date:
- **--------------------------------------------------------------------------------------------------------
- ** Modified by:
- ** Modified date:
- **--------------------------------------------------------------------------------------------------------
- *********************************************************************************************************/
- void TaskKey(void *pdata)
- {
- unsigned char ucKey;
- unsigned char ucKey0;
- unsigned char ucFlag = 0; /* 修改狀態標志 */
-
- pdata = pdata; /* 防止編譯器警告 */
-
- TargetInit();
- OSTimeDly(OS_TICKS_PER_SEC/10); /* 上電延時,等待zlg7290復位 */
-
- PINSEL1 = (PINSEL1 & ~(0xff << 22))|( 0x05 << 22 ); /* 設置I2C管腳功能 */
- i2cInit(0, "Speed=30000", NULL); /* 初始化I2C0 */
- SetVICIRQ(9, 2, (int)i2c0IRQ); /* 設置了IRQ中斷 */
-
- GmboxRingCtrl = OSMboxCreate((void *)0); /* 創建消息郵箱 */
- rtcInit();
- SetVICIRQ(13, 3, (int)RTC_Exception);
-
- OSTaskCreateExt (TaskDisp,
- (void *)0,
- &TaskDispStk[TASKDISP_STACK_SIZE - 1],
- TASKDISP_PRIO,
- TASKDISP_ID,
- &TaskDispStk[0],
- TASKDISP_STACK_SIZE,
- (void *)0,
- OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);
- /* 創建顯示任務 */
-
- OSTaskCreateExt (TaskCtrl,
- (void *)0,
- &TaskCtrlStk[TASKCTRL_STACK_SIZE - 1],
- TASKCTRL_PRIO,
- TASKCTRL_ID,
- &TaskCtrlStk[0],
- TASKCTRL_STACK_SIZE,
- (void *)0,
- OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);
- /* 創建輸出控制任務 */
-
- while (1) {
- OSTimeDly(4); /* 延時 */
- ucKey = (uint8)ZLG7290GetKey(); /* 獲取鍵值 */
- if ((ucKey == 0) || (ucKey > 16)) { /* 沒有按鍵 */
- continue;
- }
- if (ucKey<11) { /* 數字鍵 */
- ucKey0 = 0;
- }
- else { /* 功能鍵 */
- ucKey0 = (uint8)(ucKey % 10);
- }
-
- /*
- * 鍵值處理
- */
- OS_ENTER_CRITICAL(); /* 進入臨界區,原子操作 */
- switch (ucKey0) {
-
- case 0: /* 數字鍵 */
- if (ucFlag) { /* 數字鍵只有在修改狀態下有效 */
- ucKey %= 10;
- switch (GuiMode) {
-
- case 0: /* 時鐘模式 */
- if (ucKey <= GucTimeMaxTable[GuiItem][GuiCursor]) {
- GucTimeDispBuf[GuiItem][GuiCursor] = ucKey;
- GuiCursor = GucTimeNextCursor[GuiItem][GuiCursor];
- FromDispBuf();
- SetTime();
- }
- break;
- case 1: /* 鬧鐘模式 */
- if (ucKey <= GucAlarmMaxTable[GuiItem][GuiCursor]) {
- GucAlarmDispBuf[GuiIndex][GuiItem][GuiCursor] = ucKey;
- GuiCursor = GucAlarmNextCursor[GuiItem][GuiCursor];
- FromDispBuf();
- }
- break;
- default:
- break;
- }
-
- }
- break;
- case 1: /* 左移動鍵 */
- if (ucFlag) {
- switch (GuiMode) {
-
- case 0:
- GuiCursor = GucTimePreCursor[GuiItem][GuiCursor];
- break;
- case 1:
- GuiCursor = GucAlarmPreCursor[GuiItem][GuiCursor];
- break;
- default:
- break;
- }
- }
- else {
- switch (GuiMode) {
-
- case 0:
- if (GuiItem > 0) {
- GuiItem--;
- }
- else {
- GuiItem = 1;
- }
- break;
- case 1:
- if (GuiItem > 0) {
- GuiItem--;
- }
- else {
- GuiItem = 5;
- }
- break;
- default:
- break;
- }
- }
- break;
- case 2: /* 右移動鍵 */
- if (ucFlag) {
- switch (GuiMode) {
-
- case 0:
- GuiCursor = GucTimeNextCursor[GuiItem][GuiCursor];
- break;
- case 1:
- GuiCursor = GucAlarmNextCursor[GuiItem][GuiCursor];
- break;
- default:
- break;
- }
- }
- else {
- switch (GuiMode) {
-
- case 0:
- GuiItem = (GuiItem+1)%2;
- break;
- case 1:
- GuiItem = (GuiItem+1)%6;
- break;
- default:
- break;
- }
- }
- break;
- case 3: /* 上移動鍵 */
- if (ucFlag) {
- switch (GuiMode) {
-
- case 0:
- break;
- case 1:
- break;
- default:
- break;
- }
- }
- else {
- switch (GuiMode) {
-
- case 0:
- break;
- case 1:
- if(GuiIndex > 0 ) {
- GuiIndex--;
- }
- else {
- GuiIndex = MAX_ALARM-1;
- }
- GuiItem = 0;
- break;
- default:
- break;
- }
- }
- break;
- case 4: /* 下移動鍵 */
- if (ucFlag) {
- switch (GuiMode) {
-
- case 0:
- break;
- case 1:
- break;
- default:
- break;
- }
- }
- else {
- switch (GuiMode) {
- case 0:
- break;
- case 1:
- GuiIndex = (GuiIndex+1)%MAX_ALARM;
- GuiItem = 0;
- break;
- }
- }
- break;
- case 5: /* 模式切換鍵 */
- if (!ucFlag) {
- GuiMode = (GuiMode+1)%2;
- GuiIndex = 0;
- GuiItem = 0;
- }
- break;
- case 6: /* 確定鍵 */
- ucFlag = (uint8)(!ucFlag);
- if (ucFlag) {
- switch (GuiMode) {
-
- case 0:
- GuiCursor = GucTimeNextCursor[GuiItem][GuiCursor];
- break;
- case 1:
- GuiCursor = GucAlarmNextCursor[GuiItem][GuiCursor];
- break;
- default:
- break;
- }
- }
- else {
- GuiCursor = 8;
- }
- break;
- default:
- break;
- }
- OS_EXIT_CRITICAL(); /* 退出臨界區 */
-
- while (1) { /* 等待按鍵釋放 */
- OSTimeDly(4); /* 延時 */
- ucKey = (uint8)ZLG7290GetKey(); /* 獲取鍵值 */
- if ((ucKey == 0) || (ucKey > 16)) { /* 按鍵釋放 */
- break;
- }
- }
- }
- }
-
- /*********************************************************************************************************
- ** Function name: TaskDisp
- **
- ** Descriptions: 顯示任務
- **
- ** input parameters:
- ** output parameters:
- **
- ** Returned value
- **
- **
- ** Created by:
- ** Created Date:
- **--------------------------------------------------------------------------------------------------------
- ** Modified by:
- ** Modified date:
- **--------------------------------------------------------------------------------------------------------
- *********************************************************************************************************/
- void TaskDisp(void *pdata)
- {
- uint8 i;
-
- pdata = pdata;
-
- while (1) {
- /*顯示任務周期性的輸出全局變量的信息(時鐘和鬧鐘),100ms是一個經驗值,
- 用戶會覺得比較舒服,不會產生“系統死機”的感覺。 */
- OSTimeDly(20); /* 延時 */
-
- OS_ENTER_CRITICAL();
- ToDispBuf(); /* 刷新顯示緩沖區 */
- OS_EXIT_CRITICAL();
-
- switch (GuiMode) { /* 顯示信息 */
-
- case 0: /* 時鐘模式 */
- for (i=0; i<8; i++) {
- ZLG7290ShowChar(i, (uint8)(((i==GuiCursor) ?
- 0x40 : 0x00) | GucTimeDispBuf[GuiItem][i]));
- OSTimeDly(1);
- }
- break;
- case 1: /* 鬧鐘模式 */
- for (i=0; i<8; i++) {
- ZLG7290ShowChar(i, (uint8)(((i==GuiCursor) ?
- 0x40 : 0x00) | GucAlarmDispBuf[GuiIndex][GuiItem][i]));
- OSTimeDly(1);
- }
- break;
- default:
- break;
- }
- }
- }
- /*********************************************************************************************************
- ** Function name: TaskCtrl
- **
- ** Descriptions: 輸出控制任務
- **
- ** input parameters:
- ** output parameters:
- **
- ** Returned value
- **
- **
- ** Created by:
- ** Created Date:
- **--------------------------------------------------------------------------------------------------------
- ** Modified by:
- ** Modified date:
- **--------------------------------------------------------------------------------------------------------
- *********************************************************************************************************/
- void TaskCtrl(void *pdata)
- {
- INT8U ucErr;
- unsigned short usLevel[4]; /* 4路輸出電平控制 */
- unsigned short usTime[4]; /* 4路輸出時間控制 */
- unsigned short *pusMsg;
- OS_MBOX_DATA mboxdataMsg; /* 查詢消息的結構體 */
- int i;
-
- pdata = pdata;
- IO1DIR |= (LED0 | LED1 | LED2 | LED3); /* 設置IO方向 */
- IO1SET = (LED0 | LED1 | LED2 |LED3); /* 設置IO初值 */
-
- while (1) {
- pusMsg = (unsigned short *)OSMboxPend(GmboxRingCtrl, 0, &ucErr);/* 獲取消息 */
- for (i=0; i<4; i++) { /* 解釋消息 */
- usLevel[i] = pusMsg[2*i];
- usTime[i] = pusMsg[2*i+1];
- }
- if (usLevel[0]==0) { /* 設置輸出電平 */
- IO1CLR = LED0;
- }
- if (usLevel[1]==0) {
- IO1CLR = LED1;
- }
- if (usLevel[2]==0) {
- IO1CLR = LED2;
- }
- if (usLevel[3]==0) {
- IO1CLR = LED3;
- }
- while (1) { /* 輸出時間循環 */
- OSTimeDly(OS_TICKS_PER_SEC);
- if (usTime[0] != 0) { /* 0路時間 */
- if (--usTime[0] == 0) {
- IO1SET = LED0;
- }
- }
- if (usTime[1] != 0) { /* 1路時間 */
- if (--usTime[1] == 0) {
- IO1SET = LED1;
- }
- }
- if (usTime[2] != 0) { /* 2路時間 */
- if (--usTime[2] == 0) {
- IO1SET = LED2;
- }
- }
- if (usTime[3] != 0) { /* 3路時間 */
- if (--usTime[3] == 0) {
- IO1SET = LED3;
- }
- }
- if ((usTime[0] == 0) && (usTime[1] == 0) && (usTime[2] == 0) && (usTime[3] == 0)) {
- break;
- }
- OSMboxQuery(GmboxRingCtrl, &mboxdataMsg); /* 查詢是否有新的消息 */
- if (mboxdataMsg.OSMsg != (void *)0) {
- break;
- }
- }
- }
- }
- /*********************************************************************************************************
- ** Function name: GetTime
- **
- ** Descriptions: 獲取當前時間
- **
- ** input parameters:
- ** output parameters:
- **
- ** Returned value
- **
- **
- ** Created by:
- ** Created Date:
- **--------------------------------------------------------------------------------------------------------
- ** Modified by:
- ** Modified date:
- **--------------------------------------------------------------------------------------------------------
- *********************************************************************************************************/
- void GetTime(void)
- {
- GtimeCurrentTime.ucHour = (uint8)HOUR;
- GtimeCurrentTime.ucMin = (uint8)MIN;
- GtimeCurrentTime.ucSec = (uint8)SEC;
- GtimeCurrentTime.usYear = (uint16)YEAR;
- GtimeCurrentTime.ucMon = (uint8)MONTH;
- GtimeCurrentTime.ucDay = (uint8)DOM;
- GtimeCurrentTime.ucWeek = (uint8)DOW;
- }
- /*********************************************************************************************************
- ** Function name: ToDispBuf
- **
- ** Descriptions: 更新顯示緩沖區
- **
- ** input parameters:
- ** output parameters:
- **
- ** Returned value
- **
- **
- ** Created by:
- ** Created Date:
- **--------------------------------------------------------------------------------------------------------
- ** Modified by:
- ** Modified date:
- **--------------------------------------------------------------------------------------------------------
- *********************************************************************************************************/
- void ToDispBuf(void)
- {
- int i, j;
-
- GucTimeDispBuf[0][0] = (uint8)(GtimeCurrentTime.ucSec % 10); /* 星期,時分秒 */
- GucTimeDispBuf[0][1] = (uint8)(GtimeCurrentTime.ucSec / 10);
- GucTimeDispBuf[0][2] = (uint8)(GtimeCurrentTime.ucMin % 10);
- GucTimeDispBuf[0][3] = (uint8)(GtimeCurrentTime.ucMin / 10);
- GucTimeDispBuf[0][4] = (uint8)(GtimeCurrentTime.ucHour % 10);
- GucTimeDispBuf[0][5] = (uint8)(GtimeCurrentTime.ucHour / 10);
- GucTimeDispBuf[0][6] = 0x1f;
- GucTimeDispBuf[0][7] = GtimeCurrentTime.ucWeek;
-
- GucTimeDispBuf[1][0] = (uint8)(GtimeCurrentTime.ucDay % 10); /* 年月日 */
- GucTimeDispBuf[1][1] = (uint8)(GtimeCurrentTime.ucDay / 10);
- GucTimeDispBuf[1][2] = (uint8)(GtimeCurrentTime.ucMon % 10);
- GucTimeDispBuf[1][3] = (uint8)(GtimeCurrentTime.ucMon / 10);
- GucTimeDispBuf[1][4] = (uint8)(GtimeCurrentTime.usYear % 10);
- GucTimeDispBuf[1][5] = (uint8)(GtimeCurrentTime.usYear % 100 / 10);
- GucTimeDispBuf[1][6] = (uint8)(GtimeCurrentTime.usYear % 1000 / 100);
- GucTimeDispBuf[1][7] = (uint8)(GtimeCurrentTime.usYear / 1000);
-
- for (i=0; i<MAX_ALARM; i++) {
- GucAlarmDispBuf[i][0][0] = (uint8)(GalarmRingTime[i].ucSec % 10);
- GucAlarmDispBuf[i][0][1] = (uint8)(GalarmRingTime[i].ucSec % 100 / 10);
- GucAlarmDispBuf[i][0][2] = (uint8)(GalarmRingTime[i].ucMin % 10);
- GucAlarmDispBuf[i][0][3] = (uint8)(GalarmRingTime[i].ucMin % 100 / 10);
- GucAlarmDispBuf[i][0][4] = (uint8)(GalarmRingTime[i].ucHour % 10);
- GucAlarmDispBuf[i][0][5] = (uint8)(GalarmRingTime[i].ucHour % 100 / 10);
- GucAlarmDispBuf[i][0][6] = (uint8)i;
- GucAlarmDispBuf[i][0][7] = 0x0a;
-
- for (j=0; j<8; j++) {
- GucAlarmDispBuf[i][1][j] = (uint8)((GalarmRingTime[i].ucEnable&(1<<j)) ? 0x0e : 0x0d);
- }
-
- for (j=0; j<4; j++) {
- GucAlarmDispBuf[i][j+2][0] = (uint8)(GalarmRingTime[i].c[j].usTime % 10);
- GucAlarmDispBuf[i][j+2][1] = (uint8)(GalarmRingTime[i].c[j].usTime % 100 / 10);
- GucAlarmDispBuf[i][j+2][2] = (uint8)(GalarmRingTime[i].c[j].usTime % 1000 / 100);
- GucAlarmDispBuf[i][j+2][3] = (uint8)(GalarmRingTime[i].c[j].usTime % 10000 / 1000);
- GucAlarmDispBuf[i][j+2][4] = (uint8)(GalarmRingTime[i].c[j].usLevel ? 0x11 : 0x14);
- GucAlarmDispBuf[i][j+2][5] = 0x1f;
- GucAlarmDispBuf[i][j+2][6] = (uint8)j;
- GucAlarmDispBuf[i][j+2][7] = 0x0c;
- }
- }
- }
- /*********************************************************************************************************
- ** Function name: FromDispBuf
- **
- ** Descriptions: 更新當前時間
- **
- ** input parameters:
- ** output parameters:
- **
- ** Returned value
- **
- **
- ** Created by:
- ** Created Date:
- **--------------------------------------------------------------------------------------------------------
- ** Modified by:
- ** Modified date:
- **--------------------------------------------------------------------------------------------------------
- *********************************************************************************************************/
- void FromDispBuf(void)
- {
- int i, j;
-
- GtimeCurrentTime.ucSec = (uint8)(GucTimeDispBuf[0][1]*10 + GucTimeDispBuf[0][0]);
- GtimeCurrentTime.ucMin = (uint8)(GucTimeDispBuf[0][3]*10 + GucTimeDispBuf[0][2]);
- GtimeCurrentTime.ucHour = (uint8)(GucTimeDispBuf[0][5]*10 + GucTimeDispBuf[0][4]);
- GtimeCurrentTime.ucWeek = GucTimeDispBuf[0][7];
-
- GtimeCurrentTime.ucDay = (uint8)(GucTimeDispBuf[1][1]*10 + GucTimeDispBuf[1][0]);
- GtimeCurrentTime.ucMon = (uint8)(GucTimeDispBuf[1][3]*10 + GucTimeDispBuf[1][2]);
- GtimeCurrentTime.usYear = (uint16)(GucTimeDispBuf[1][7]*1000 + GucTimeDispBuf[1][6]*100
- + GucTimeDispBuf[1][5]*10 + GucTimeDispBuf[1][4]);
-
- for (i=0; i<MAX_ALARM; i++) {
- GalarmRingTime[i].ucSec = (uint8)(GucAlarmDispBuf[i][0][1]*10 + GucAlarmDispBuf[i][0][0]);
- if (GalarmRingTime[i].ucSec > 59) {
- GalarmRingTime[i].ucSec = 59;
- }
- GalarmRingTime[i].ucMin = (uint8)(GucAlarmDispBuf[i][0][3]*10 + GucAlarmDispBuf[i][0][2]);
- if (GalarmRingTime[i].ucMin > 59) {
- GalarmRingTime[i].ucMin = 59;
- }
- GalarmRingTime[i].ucHour = (uint8)(GucAlarmDispBuf[i][0][5]*10 + GucAlarmDispBuf[i][0][4]);
- if (GalarmRingTime[i].ucHour > 23) {
- GalarmRingTime[i].ucHour = 23;
- }
-
- for (j=0; j<8; j++) {
- if (GucAlarmDispBuf[i][1][j] == 1) {
- GalarmRingTime[i].ucEnable = (uint8)(GalarmRingTime[i].ucEnable | (1<<j));
- }
- else if (GucAlarmDispBuf[i][1][j] == 0) {
- GalarmRingTime[i].ucEnable = (uint8)(GalarmRingTime[i].ucEnable & (~(1<<j)));
- }
- }
-
- for (j=0; j<4; j++) {
- GalarmRingTime[i].c[j].usTime = (uint16)(GucAlarmDispBuf[i][j+2][3]*1000
- + GucAlarmDispBuf[i][j+2][2]*100
- + GucAlarmDispBuf[i][j+2][1]*10
- + GucAlarmDispBuf[i][j+2][0]);
- if (GucAlarmDispBuf[i][j+2][4] == 1) {
- GalarmRingTime[i].c[j].usLevel = 1;
- }
- else if (GucAlarmDispBuf[i][j+2][4] == 0) {
- GalarmRingTime[i].c[j].usLevel = 0;
- }
- }
- }
- }
- /*********************************************************************************************************
- ** Function name: SetTime
- **
- ** Descriptions: 設置當前時間
- **
- ** input parameters:
- ** output parameters:
- **
- ** Returned value
- **
- **
- ** Created by:
- ……………………
- …………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼
所有資料51hei提供下載:
第四章 電腦自動打鈴器設計與實現.rar
(305.84 KB, 下載次數: 20)
2018-3-12 19:05 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|