采用ucos,有详细的说明,经典的ucos操作系统实例详解
单片机源程序如下:
- /****************************************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)
|