/*--------------------------------------------------------------------*-
LedDisp.C (V1.00)
-*---------------------------------------------------------------------*/
/*
* Copyright (c) 2006,wsl
* All rights reserved
*
* 文件名称: LedDisp.C
* 文件标识:
* 摘 要: 数码显示
*
* 当前版本: V1.0 * 取代版本:
* 作 者: wsl * 修 改:
* 版本信息: 2006-09-14 * 修改信息:
*/
//***********************************************************************
#include"main.H"
#include"Port.H"
#include"MMI.h"
#include"SCH51.H"
#include"Uart.h"
#include"LedDisp.h"
/*************************************************************************/
/*动态数码管个数*/
#define LED_NUMBER (4)
extern time_str now;
/*数码管显示段码表,不带点*/
unsigned char code DispCode[]=
{
0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92,
0x82, 0xf8, 0x80, 0x90, 0xff, 0x92,/*s*/ 0x86,/*E*/ 0x87/*t*/
};
/*数码管扫描码表*/
unsigned char code ScanCode[4]=
{
0xfe, 0xfd, 0xfb, 0xf7
};
/*数码管显示缓冲区*/
unsigned char dispbuf[4]=
{
1,2,3,4
};
/*LED数码管工作模式控制字*/
/*工作模式分三种, 1> 点位同时闪烁(LED_TMOD = 0x00)
2> 点位分别闪烁(LED_TMOD = 0x01)
3> 点位不闪烁 (LED_TMOD = 0x10)
*/
unsigned char LED_TMOD = 0x00;
/*更新显示数据标志*/
bit g_UpdataFlagEn = 1; /*(1)可以更新;(0)不可以更新*/
/*点闪烁总使能标志为1点闪动*/
bit g_DFlashEn = 0;
/*位闪烁总使能标志为1位闪动*/
bit g_BFlashEn = 0;
/*用于切换点的闪烁状态,闪烁或不闪烁*/
static bit DFlash;
/*用于切换位的闪烁状态,闪烁或不闪烁*/
static bit BFlash;
/*数码管闪烁标志*/
unsigned char bdata Flag;
// 闪烁点:Blink,为1的位闪动
sbit Dlink1 = Flag^0; /*时十位点 为1的位闪动*/
sbit Dlink2 = Flag^1;
sbit Dlink3 = Flag^2;
sbit Dlink4 = Flag^3; /*分个位点 为1的位闪动*/
// 闪烁位:Blink,为1的位闪动
sbit Blink1 = Flag^4; /*时十位*/
sbit Blink2 = Flag^5; /*时个位*/
sbit Blink3 = Flag^6; /*分十位*/
sbit Blink4 = Flag^7; /*分个位*/
/*用于显示刷新的频率*/
/*
g_DispFreq = 0 动态扫描的频是200HZ
g_DispFreq = 1 动态扫描的频是100HZ
g_DispFreq = 2 动态扫描的频是66HZ
g_DispFreq = 3 动态扫描的频是50HZ
g_DispFreq = 4 动态扫描的频是40HZ
g_DispFreq = 5 动态扫描的频是33HZ
g_DispFreq = 6 动态扫描的频是28HZ
g_DispFreq = 7 动态扫描的频是25HZ
*/
unsigned char g_DispScanFreq = 4; /*最小为0,最大为7*/
/*私有函数*/
/**************************************************************************-
关于数码管显示的各寄存器的应用说明:
g_DispScanFreq: 用于显示刷新的频率,最小为0,最大为7
// 任意位和任意点可以同时闪烁(点位总使能开同时开)
#define LED_DISP_MODE0() {LED_TMOD = 0x00; g_DFlashEn = 1; g_BFlashEn = 1;}
// 只能任意点可以闪烁(点总使能开)
#define LED_DISP_MODE1_D() {LED_TMOD = 0x01; g_DFlashEn = 1; g_BFlashEn = 0;}
// 只能任意位可以闪烁(位总使能开)
#define LED_DISP_MODE1_B() {LED_TMOD = 0x01; g_DFlashEn = 0; g_BFlashEn = 1;}
// 点和位都不会闪烁
#define LED_DISP_MODE2() {LED_TMOD = 0x10; g_DFlashEn = 0; g_BFlashEn = 0;}
-**************************************************************************/
/*-----------------------------------------------------------------------*-
* 函数名称: LedDisplay()
* 参 数: XX
* 返 回: XX
* 函数功能: 数码显示
*
* 说 明:
*
* 当前版本: V1.0 * 取代版本:
* 作 者: wsl * 修 改:
* 版本信息: 2006-09-14 * 修改信息:
-*-----------------------------------------------------------------------*/
void LedDisplay(void)
{
unsigned char i, BitCnt;
if ( g_UpdataFlagEn ) /*是否更新显示数据*/
{ /*更新时钟数据*/
dispbuf[0] = now.hour / 10;
dispbuf[1] = now.hour % 10;
dispbuf[2] = now.min / 10;
dispbuf[3] = now.min % 10;
}
/*动态扫描*/
for (BitCnt=0; BitCnt<LED_NUMBER; BitCnt++)
{
LedCont = ScanCode[BitCnt];
switch (LED_TMOD)
{
case 0x00:
if ( DFlash ) /*否则是点闪烁*/
{
switch (BitCnt)
{
case 0: if (Dlink1) {LedPort = DispCode[dispbuf[BitCnt]] & 0x7f;}
else {LedPort = DispCode[dispbuf[BitCnt]];} break;
case 1: if (Dlink2) {LedPort = DispCode[dispbuf[BitCnt]] & 0x7f;}
else {LedPort = DispCode[dispbuf[BitCnt]];} break;
case 2: if (Dlink3) {LedPort = DispCode[dispbuf[BitCnt]] & 0x7f;}
else {LedPort = DispCode[dispbuf[BitCnt]];} break;
case 3: if (Dlink4) {LedPort = DispCode[dispbuf[BitCnt]] & 0x7f;}
else {LedPort = DispCode[dispbuf[BitCnt]];} break;
default: break;
}
}
else if ( !BFlash ) /*否则是位闪烁*/
{
switch (BitCnt)
{
case 0: if (Blink1) {LedPort = 0xff;}
else {LedPort = DispCode[dispbuf[BitCnt]];} break;
case 1: if (Blink2) {LedPort = LedPort = 0xff;}
else {LedPort = DispCode[dispbuf[BitCnt]];} break;
case 2: if (Blink3) {LedPort = LedPort = 0xff;}
else {LedPort = DispCode[dispbuf[BitCnt]];} break;
case 3: if (Blink4) {LedPort = LedPort = 0xff;}
else {LedPort = DispCode[dispbuf[BitCnt]];} break;
default: break;
}
}
else
{
LedPort = DispCode[dispbuf[BitCnt]];
}
break;
case 0x01:
if ( DFlash ) /*否则是点闪烁*/
{
switch (BitCnt)
{
case 0: if (Dlink1) {LedPort = DispCode[dispbuf[BitCnt]] & 0x7f;}
else {LedPort = DispCode[dispbuf[BitCnt]];} break;
case 1: if (Dlink2) {LedPort = DispCode[dispbuf[BitCnt]] & 0x7f;}
else {LedPort = DispCode[dispbuf[BitCnt]];} break;
case 2: if (Dlink3) {LedPort = DispCode[dispbuf[BitCnt]] & 0x7f;}
else {LedPort = DispCode[dispbuf[BitCnt]];} break;
case 3: if (Dlink4) {LedPort = DispCode[dispbuf[BitCnt]] & 0x7f;}
else {LedPort = DispCode[dispbuf[BitCnt]];} break;
default: break;
}
}
else if ( BFlash ) /*否则是位闪烁*/
{
switch (BitCnt)
{
case 0: if (Blink1) {LedPort = 0xff;}
else {LedPort = DispCode[dispbuf[BitCnt]];} break;
case 1: if (Blink2) {LedPort = LedPort = 0xff;}
else {LedPort = DispCode[dispbuf[BitCnt]];} break;
case 2: if (Blink3) {LedPort = LedPort = 0xff;}
else {LedPort = DispCode[dispbuf[BitCnt]];} break;
case 3: if (Blink4) {LedPort = LedPort = 0xff;}
else {LedPort = DispCode[dispbuf[BitCnt]];} break;
default: break;
}
}
else
{
LedPort = DispCode[dispbuf[BitCnt]];
}
break;
case 0x10: LedPort = DispCode[dispbuf[BitCnt]]; break;
default: break;
}
for (i=0; i<10; i++);
LedPort = 0xff; /*消隐*/
}
}
/*-----------------------------------------------------------------------*-
* 函数名称: FlashFreq()
* 参 数: XX
* 返 回: XX
* 函数功能: 控制闪烁频率(在定时中断中运行)
*
* 说 明:
*
* 当前版本: V1.0 * 取代版本:
* 作 者: wsl * 修 改:
* 版本信息: 2006-09-14 * 修改信息:
-*-----------------------------------------------------------------------*/
void FlashFreq(void)
{
static unsigned char ucFlashFreq = 0;
ucFlashFreq++;/*设每5mS中断一次*/
if (ucFlashFreq == 100)/*5ms *100*/
{
ucFlashFreq = 0;
if ( g_DFlashEn ) /*是否需要点闪烁*/
{
DFlash = ~DFlash;
}
else
{
DFlash = 0;
}
if ( g_BFlashEn ) /*是否需要点闪烁*/
{
BFlash = ~BFlash;
}
else
{
BFlash = 0;
}
}
}
-
-
xilinxue 发表于 2008/9/20 13:17:51
/*-------------------------------------------------------*-
LedDisp.H (V1.1)
-*-------------------------------------------------------*/
/*
* Copyright (c) 2006,wsl
* All rights reserved
*
* 文件名称: LedDisp.H
* 文件标识:
* 摘 要:
*
*
* 当前版本: 1.1 * 取代版本:
* 作 者: wsl * 原作者 :
* 完成日期: 2006-09-14 * 完成日期:
*********************************************************/
#ifndef _LedDisp_H
#define _LedDisp_H
// -------------------------------------------------------
#define LED_DISP_MODE0() {LED_TMOD = 0x00; g_DFlashEn = 1; g_BFlashEn = 1;}
#define LED_DISP_MODE1_D() {LED_TMOD = 0x01; g_DFlashEn = 1; g_BFlashEn = 0;}
#define LED_DISP_MODE1_B() {LED_TMOD = 0x01; g_DFlashEn = 0; g_BFlashEn = 1;}
#define LED_DISP_MODE2() {LED_TMOD = 0x10; g_DFlashEn = 0; g_BFlashEn = 0;}extern unsigned char LED_TMOD;
extern bit g_UpdataFlagEn;
/*点闪烁使能标志为0的点闪动*/
extern bit g_DFlashEn;
/*位闪烁使能标志为0的位闪动*/
extern bit g_BFlashEn;
/*数据缓冲区*/
extern unsigned char dispbuf[4];
/*数码管闪烁标志*/
extern unsigned char bdata Flag;
// 闪烁点:Blink,为1的位闪动
extern bit Dlink1; /*时十位点 为1的位闪动*/
extern bit Dlink2;
extern bit Dlink3;
extern bit Dlink4; /*分个位点 为1的位闪动*/
// 闪烁位:Blink,为1的位闪动
extern bit Blink1; /*时十位*/
extern bit Blink2; /*时个位*/
extern bit Blink3; /*分十位*/
extern bit Blink4; /*分个位*/
extern unsigned char g_DispScanFreq;
extern void LedDisplay(void);
extern void FlashFreq(void);
//--------------------------------------------------------#endif
/*------------------------------------------------------*-
END OF FILE-*------------------------------------------------------*/
引用 xilinxue 2008/9/20 13:17:51 发表于2楼的内容
-
-
-
bbs1234567 | 当前状态:在线
总积分:130 2024年可用积分:0
注册时间: 2012-09-26
最后登录时间: 2013-01-28
-
bbs1234567 发表于 2012/9/26 16:52:43
LED数码管电子钟挺实用的,看到自己做的电子钟挺高兴的。3楼 回复本楼
引用 bbs1234567 2012/9/26 16:52:43 发表于3楼的内容
-