谢谢4楼古道热肠,刚刚才把问题解决.
现在在我把问题说公布出来. 是数码管显示函数switch函数嵌套过多,单片机堆棧溢出,RET返回地址错误码. 现在在就把数码管显示代码贴出来,供大家参考:
数码显示关文件: /*-------------------------------------------------------*-
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;
/*数码管闪烁标志*/ // 闪烁点:Blink,为0的位闪动 extern bit Dlink1; /*时十位点 为0的位闪动*/ extern bit Dlink2; extern bit Dlink3; extern bit Dlink4; /*分个位点 为0的位闪动*/ // 闪烁位:Blink,为0的位闪动 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
-*------------------------------------------------------*/
数码显示C文件:
/*--------------------------------------------------------------------*-
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 };
/*数码管扫描码表*/ 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;
/*数码管闪烁标志*/ // 闪烁点:Blink,为1的位闪动 bit Dlink1 = 0; /*时十位点 为1的位闪动*/ bit Dlink2 = 0; bit Dlink3 = 0; bit Dlink4 = 0; /*分个位点 为1的位闪动*/ // 闪烁位:Blink,为1的位闪动 bit Blink1 = 0; /*时十位*/ bit Blink2 = 0; /*时个位*/ bit Blink3 = 0; /*分十位*/ bit Blink4 = 0; /*分个位*/
/*用于显示刷新的频率*/ /* 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 = 7; /*最小为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++; if (ucFlashFreq == 100)/*5ms *100*/ { ucFlashFreq = 0; if ( g_DFlashEn ) /*是否需要点闪烁*/ { DFlash = ~DFlash; } else { DFlash = 0; }
if ( g_BFlashEn ) /*是否需要点闪烁*/ { BFlash = ~BFlash; } else { BFlash = 0; } } }
此显示代码功能很全: 可以数码管任意位和任意点同时闪烁.闪烁的频率是1Hz |
|