標(biāo)題:
MiniARM2300電腦自動(dòng)打鈴器設(shè)計(jì)與實(shí)現(xiàn)ucos操作系統(tǒng)
[打印本頁(yè)]
作者:
matmat
時(shí)間:
2018-3-12 19:06
標(biāo)題:
MiniARM2300電腦自動(dòng)打鈴器設(shè)計(jì)與實(shí)現(xiàn)ucos操作系統(tǒng)
采用ucos,有詳細(xì)的說(shuō)明,經(jīng)典的ucos操作系統(tǒng)實(shí)例詳解
0.png
(10.46 KB, 下載次數(shù): 95)
下載附件
2018-3-13 02:15 上傳
單片機(jī)源程序如下:
/****************************************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" /* 系統(tǒng)頭文件 */
#include "i2c.h"
#define TASKKEY_ID 12 /* 定義鍵盤(pán)任務(wù)的ID */
#define TASKKEY_PRIO TASKKEY_ID /* 定義鍵盤(pán)任務(wù)的優(yōu)先級(jí) */
#define TASKKEY_STACK_SIZE 512 /* 定義鍵盤(pán)任務(wù)堆棧大小 */
#define TASKDISP_ID 13 /* 定義顯示任務(wù)的ID */
#define TASKDISP_PRIO TASKDISP_ID /* 定義顯示任務(wù)的優(yōu)先級(jí) */
#define TASKDISP_STACK_SIZE 512 /* 定義顯示任務(wù)堆棧大小 */
#define TASKCTRL_ID 6 /* 定義控制任務(wù)的ID */
#define TASKCTRL_PRIO TASKCTRL_ID /* 定義控制任務(wù)的優(yōu)先級(jí) */
#define TASKCTRL_STACK_SIZE 512 /* 定義控制任務(wù)堆棧大小 */
OS_STK TaskKeyStk[TASKKEY_STACK_SIZE]; /* 定義鍵盤(pán)任務(wù)的堆棧 */
OS_STK TaskDispStk[TASKDISP_STACK_SIZE]; /* 定義顯示任務(wù)的堆棧 */
OS_STK TaskCtrlStk[TASKCTRL_STACK_SIZE]; /* 定義控制任務(wù)的堆棧 */
void TaskKey(void *pdata); /* TaskKey 鍵盤(pán)任務(wù) */
void TaskDisp(void *pdata); /* TaskDisp 顯示任務(wù) */
void TaskCtrl(void *pdata); /* TaskCtrl 控制任務(wù) */
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; /* 光標(biāo) */
unsigned int GuiIndex = 0; /* 索引 */
unsigned int GuiItem = 0; /* 條目 */
/*********************************************************************************************************
時(shí)鐘結(jié)構(gòu)定義
*********************************************************************************************************/
struct time {
unsigned char ucHour; /* 時(shí) */
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;
/*********************************************************************************************************
鬧鐘結(jié)構(gòu)定義
*********************************************************************************************************/
struct alarm {
unsigned char ucHour; /* 時(shí) */
unsigned char ucMin; /* 分 */
unsigned char ucSec; /* 秒 */
unsigned char ucEnable; /* 鬧鐘使能控制 */
struct {
unsigned short usLevel; /* 輸出電平控制 */
unsigned short usTime; /* 輸出時(shí)間控制 */
} c[4]; /* 4路輸出控制 */
};
typedef struct alarm ALARM;
typedef ALARM *PALARM;
#define MAX_ALARM 4 /* 最大鬧鐘個(gè)數(shù) */
unsigned char GucTimeDispBuf[2][8]; /* 時(shí)鐘顯示緩沖區(qū) */
unsigned char GucAlarmDispBuf[MAX_ALARM][6][8]; /* 鬧鐘顯示緩沖區(qū) */
TIME GtimeCurrentTime; /* 當(dāng)前時(shí)間 */
ALARM GalarmRingTime[MAX_ALARM]; /* 鬧鐘時(shí)間 */
#define LED0 (1u<<18)
#define LED1 (1u<<19)
#define LED2 (1u<<20)
#define LED3 (1u<<21)
/*********************************************************************************************************
時(shí)鐘模式下,下一個(gè)光標(biāo)索引表
*********************************************************************************************************/
const unsigned char GucTimeNextCursor[2][9] = {
{7,0,1,2,3,4,7,5,7},
{5,0,1,2,3,4,5,5,5}
};
/*********************************************************************************************************
時(shí)鐘模式下,上一個(gè)光標(biāo)索引表
*********************************************************************************************************/
const unsigned char GucTimePreCursor[2][9] = {
{1,2,3,4,5,7,7,0,7},
{1,2,3,4,5,0,5,5,5}
};
/*********************************************************************************************************
時(shí)鐘模式下,最大值限定表
*********************************************************************************************************/
const unsigned char GucTimeMaxTable[2][8] = {
{0x09,0x05,0x09,0x05,0x09,0x02,0x1f,0x06},
{0x09,0x03,0x09,0x01,0x09,0x09,0x1f,0x1f}
};
/*********************************************************************************************************
鬧鐘模式下,下一個(gè)光標(biāo)索引表
*********************************************************************************************************/
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}
};
/*********************************************************************************************************
鬧鐘模式下,上一個(gè)光標(biāo)索引表
*********************************************************************************************************/
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: 主函數(shù)
**
** 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);
/* 創(chuàng)建鍵盤(pán)任務(wù) */
OSStart(); /* 啟動(dòng)多任務(wù)操作系統(tǒng) */
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, /* 接收數(shù)據(jù)的緩沖區(qū) */
1, /* 器件子地址 */
1, /* 器件子地址類(lèi)型為單字節(jié)型 */
2); /* 讀取數(shù)據(jù)的長(zhǎng)度 */
while (i2cGetFlag(0) == I2C_BUSY); /* 等待I2C操作完畢 */
return (uint16)(temp[0] + (temp[1] * 256));
}
/*********************************************************************************************************
** Function name: ZLG7290ShowChar
**
** Descriptions: zlg7290顯示數(shù)值
**
** 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, /* 要寫(xiě)入數(shù)據(jù)的緩沖區(qū) */
0x07, /* 器件子地址 */
1, /* 器件子地址類(lèi)型為單字節(jié)型 */
2); /* 寫(xiě)入的數(shù)量 */
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; /* 禁止時(shí)間計(jì)數(shù)器 */
PREINT = Fpclk/32768-1; /* 設(shè)置基準(zhǔn)時(shí)鐘分頻器 */
PREFRAC = Fpclk%32768;
CISS = 0; /* 禁止次秒級(jí)中斷 */
AMR = 0xFF; /* 禁止報(bào)警中斷 */
CIIR = 0x01; /* 使能秒增量中斷 */
ILR = 0x07; /* 清除RTC中斷標(biāo)志 */
ALYEAR = 2007; /* 初始化標(biāo)志 */
YEAR = 2007; /* 初始化時(shí)間寄存器 */
MONTH = 11;
DOM = 5;
DOW = 0;
HOUR = 12;
MIN = 0;
SEC = 0;
CCR = 0x11;
}
GetTime(); /* 更新當(dāng)前時(shí)間 */
}
/*********************************************************************************************************
** Function name: TaskKey
**
** Descriptions: 鍵盤(pán)任務(wù)
**
** 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; /* 修改狀態(tài)標(biāo)志 */
pdata = pdata; /* 防止編譯器警告 */
TargetInit();
OSTimeDly(OS_TICKS_PER_SEC/10); /* 上電延時(shí),等待zlg7290復(fù)位 */
PINSEL1 = (PINSEL1 & ~(0xff << 22))|( 0x05 << 22 ); /* 設(shè)置I2C管腳功能 */
i2cInit(0, "Speed=30000", NULL); /* 初始化I2C0 */
SetVICIRQ(9, 2, (int)i2c0IRQ); /* 設(shè)置了IRQ中斷 */
GmboxRingCtrl = OSMboxCreate((void *)0); /* 創(chuàng)建消息郵箱 */
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);
/* 創(chuàng)建顯示任務(wù) */
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);
/* 創(chuàng)建輸出控制任務(wù) */
while (1) {
OSTimeDly(4); /* 延時(shí) */
ucKey = (uint8)ZLG7290GetKey(); /* 獲取鍵值 */
if ((ucKey == 0) || (ucKey > 16)) { /* 沒(méi)有按鍵 */
continue;
}
if (ucKey<11) { /* 數(shù)字鍵 */
ucKey0 = 0;
}
else { /* 功能鍵 */
ucKey0 = (uint8)(ucKey % 10);
}
/*
* 鍵值處理
*/
OS_ENTER_CRITICAL(); /* 進(jìn)入臨界區(qū),原子操作 */
switch (ucKey0) {
case 0: /* 數(shù)字鍵 */
if (ucFlag) { /* 數(shù)字鍵只有在修改狀態(tài)下有效 */
ucKey %= 10;
switch (GuiMode) {
case 0: /* 時(shí)鐘模式 */
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: /* 左移動(dòng)鍵 */
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: /* 右移動(dòng)鍵 */
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: /* 上移動(dòng)鍵 */
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: /* 下移動(dòng)鍵 */
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(); /* 退出臨界區(qū) */
while (1) { /* 等待按鍵釋放 */
OSTimeDly(4); /* 延時(shí) */
ucKey = (uint8)ZLG7290GetKey(); /* 獲取鍵值 */
if ((ucKey == 0) || (ucKey > 16)) { /* 按鍵釋放 */
break;
}
}
}
}
/*********************************************************************************************************
** Function name: TaskDisp
**
** Descriptions: 顯示任務(wù)
**
** input parameters:
** output parameters:
**
** Returned value
**
**
** Created by:
** Created Date:
**--------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**--------------------------------------------------------------------------------------------------------
*********************************************************************************************************/
void TaskDisp(void *pdata)
{
uint8 i;
pdata = pdata;
while (1) {
/*顯示任務(wù)周期性的輸出全局變量的信息(時(shí)鐘和鬧鐘),100ms是一個(gè)經(jīng)驗(yàn)值,
用戶(hù)會(huì)覺(jué)得比較舒服,不會(huì)產(chǎn)生“系統(tǒng)死機(jī)”的感覺(jué)。 */
OSTimeDly(20); /* 延時(shí) */
OS_ENTER_CRITICAL();
ToDispBuf(); /* 刷新顯示緩沖區(qū) */
OS_EXIT_CRITICAL();
switch (GuiMode) { /* 顯示信息 */
case 0: /* 時(shí)鐘模式 */
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: 輸出控制任務(wù)
**
** 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路輸出時(shí)間控制 */
unsigned short *pusMsg;
OS_MBOX_DATA mboxdataMsg; /* 查詢(xún)消息的結(jié)構(gòu)體 */
int i;
pdata = pdata;
IO1DIR |= (LED0 | LED1 | LED2 | LED3); /* 設(shè)置IO方向 */
IO1SET = (LED0 | LED1 | LED2 |LED3); /* 設(shè)置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) { /* 設(shè)置輸出電平 */
IO1CLR = LED0;
}
if (usLevel[1]==0) {
IO1CLR = LED1;
}
if (usLevel[2]==0) {
IO1CLR = LED2;
}
if (usLevel[3]==0) {
IO1CLR = LED3;
}
while (1) { /* 輸出時(shí)間循環(huán) */
OSTimeDly(OS_TICKS_PER_SEC);
if (usTime[0] != 0) { /* 0路時(shí)間 */
if (--usTime[0] == 0) {
IO1SET = LED0;
}
}
if (usTime[1] != 0) { /* 1路時(shí)間 */
if (--usTime[1] == 0) {
IO1SET = LED1;
}
}
if (usTime[2] != 0) { /* 2路時(shí)間 */
if (--usTime[2] == 0) {
IO1SET = LED2;
}
}
if (usTime[3] != 0) { /* 3路時(shí)間 */
if (--usTime[3] == 0) {
IO1SET = LED3;
}
}
if ((usTime[0] == 0) && (usTime[1] == 0) && (usTime[2] == 0) && (usTime[3] == 0)) {
break;
}
OSMboxQuery(GmboxRingCtrl, &mboxdataMsg); /* 查詢(xún)是否有新的消息 */
if (mboxdataMsg.OSMsg != (void *)0) {
break;
}
}
}
}
/*********************************************************************************************************
** Function name: GetTime
**
** Descriptions: 獲取當(dāng)前時(shí)間
**
** 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: 更新顯示緩沖區(qū)
**
** 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); /* 星期,時(shí)分秒 */
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: 更新當(dāng)前時(shí)間
**
** 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: 設(shè)置當(dāng)前時(shí)間
**
** input parameters:
** output parameters:
**
** Returned value
**
**
** Created by:
……………………
…………限于本文篇幅 余下代碼請(qǐng)從51黑下載附件…………
復(fù)制代碼
所有資料51hei提供下載:
第四章 電腦自動(dòng)打鈴器設(shè)計(jì)與實(shí)現(xiàn).rar
(305.84 KB, 下載次數(shù): 20)
2018-3-12 19:05 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1