tecclock.c
来自「采用C语言编程」· C语言 代码 · 共 207 行
C
207 行
/*1-VSS 2-VDD 3-V0 4-RS 5-R/W 6-E
*7-14 DB0-DB7 15-BLA 16-BLK
*/
#define uchar unsigned char
#define uint unsigned int
#include "def.h"
#include <reg52.h>
#include <stdio.h>
#include <math.h>
#include <intrins.h>
#include <public.h>
//1602
extern void DelayMs(unsigned char ms);
extern void InitLcd();
extern void ShowString (unsigned char line,char *ptr);
extern uchar count,num,minute,second,temp;
//18B20
extern unsigned char ReadTemperature(void);
//1302
extern void Write_Ds1302_byte(unsigned char temp);
extern void Write_Ds1302( unsigned char address,unsigned char dat );
extern unsigned char Read_Ds1302 ( unsigned char address );
extern void Read_RTC(void);//read RTC
extern void Set_RTC(void);//set RTC
extern void chang();
/*****************************************************************************/
//主函数变量定义
uchar cTaskNo = 0;
uchar cScanSlotNo = 0;
uchar pCurrentSlot = 0;
//time0初始化
/*****************************************************************************/
extern uchar cTimeFlag;
extern void TimerInit();
//tecclockzhicuankou
/*****************************************************************************/
extern uchar code menu[];
extern void uart0int();
extern void uartsendstr(uchar *);
extern void putchar1(uchar );
/**********************************************************************/
//主函数的多任务处理
uchar code tTaskTable[MAX_SLOTNO][MAX_TASKNO] = {
1,0,0,0,0,
0,1,1,0,0,
1,0,0,1,0,
0,1,0,0,0,
1,0,1,0,0,
0,1,0,1,0,
1,0,0,0,0,
0,1,1,0,0,
1,0,0,1,0,
0,1,0,0,0
};
uchar task_scan()
{
if(cTimeFlag == FALSE)
{
return FALSE;
}
else
{
cTimeFlag = FALSE;
cScanSlotNo ++;
if(cScanSlotNo >= MAX_SLOTNO)
{
cScanSlotNo = 0;
}
pCurrentSlot = cScanSlotNo;
return (TURE);
}
}
//读命令
void task1()
{
uchar tempstr[12];
if(gCommandDeal == TURE)
{
if(gUart0Buf[0] == 'a')
{
tempstr[0] = 'y';
tempstr[1] = 'y';
tempstr[2] = '\n';
tempstr[3] = 0;
uartsendstr(tempstr);
gUart0RecCount=0;
gCommandDeal=FALSE;
return;
}
if(gUart0Buf[0] == 't')
{
gTimeDisplay = TURE;
gUart0RecCount = 0;
gCommandDeal = FALSE;
//return;
}
gUart0RecCount = 0;
gCommandDeal = FALSE;
}
}
//在板子的LCD上显示时间
void task2()
{
Read_RTC();
chang();
ShowString(0,l_tmpdate1);
}
//在板子上显示温度
void task3()
{
uchar temp1[] = {0x00,0x00,0x43,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20};
temp = ReadTemperature();
temp1[0] = temp/10 + 0x30;
temp1[1] = temp%10 + 0x30;
ShowString(1,temp1);
}
//在超级终端中显示时间
void task4()
{
uchar i;
if(gTimeDisplay == TURE)
{
SBUF = 0x0d;
while(!TI);
TI = 0;
for(i = 0;i < 16;i ++)
{
SBUF = l_tmpdate1[i];
while(!TI);
TI = 0;
}
}
}
//用于扩展
void task5()
{
}
void main(void)
{
void (*FunctionPionter[MAX_TASKNO])(void); //指针函数数组
uchar i;
InitLcd();
DelayMs(15); //延时15.6ms
sprintf(Test1,"t");//the first line
ShowString(0,Test1);
sprintf(TimeNum,"m");//the first line
ShowString(1,TimeNum);
Set_RTC(); //设置时钟
for(num=100;num>0;num--)
{
for(minute=20;minute>0;minute--)
{
for(count=248;count>0;count--)
{;}
}
}
TimerInit();
uart0int();
uartsendstr(menu);
FunctionPionter[0] = task1;
FunctionPionter[1] = task2;
FunctionPionter[2] = task3;
FunctionPionter[3] = task4;
FunctionPionter[4] = task5;
while(1)
{
if(task_scan() == TURE)
{
for(i = 0;i < MAX_TASKNO;i ++)
{
if(tTaskTable[pCurrentSlot][i] == 1)
{
(*FunctionPionter[i])();
}
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?