#include "EM78x156xx.h"
#define DISI() _asm{disi} #define ENI() _asm{eni} #define SLEP() _asm{slep} #define NOP() _asm{nop} #define WDTC() _asm{wdtc}
#define uchar unsigned int #define uint unsigned short
#define Key R53 #define Bz R51 #define Out R50 #define Com1 R60 #define Com2 R61 #define Com3 R62 #define Seg1 R63 #define Seg2 R64 #define Seg3 R65 #define Seg4 R66 #define Seg5 R67 #define InCom1 (P6CR|=0x01) #define InCom2 (P6CR|=0x02) #define InCom3 (P6CR|=0x04) #define OutCom1 (P6CR&=0x0E) #define OutCom2 (P6CR&=0x0D) #define OutCom3 (P6CR&=0x0B)
bit OkFlag; bit BzOutFlag; bit StartFlag; bit KeyFlag; uchar Count @0x2F; uint BzOutTime; uint TimeFlag; uchar Minute; uchar Second; uchar BiasTime;
const uchar Number1[10]={ 0x6F,0x06,0x3D,0x37,0x56,0x73,0x7B,0x26,0xFF,0x77}; const uchar Number2[10]={ 0xF7,0x03,0x5E,0x1F,0x8B,0x9D,0xFD,0x13,0xFF,0xBF};
void SysInt(void); void KeyProcess(void); void Delayms(uint ms); void BzOut(void); void LcdDisplay(uchar Num1,uchar Num2); void TimeDisplay(void);
void main() { SysInt(); while(1) { KeyProcess(); TimeDisplay(); } }
void TimeDisplay(void) { uchar temp1,temp2; //Count++; Out=!StartFlag; if(BzOutFlag==1) { if((BzOutTime%1000)==0) BzOut(); if(BzOutTime>=20000) { BzOutTime=0; BzOutFlag=0; } BzOutTime++; } if((Count>=249)&&(StartFlag==1))//Count>=249 { Count=0; if(Second>0) Second--; if(Second==0) { if(Minute>0) { Minute--; Second=60; } else { StartFlag=0; BzOutFlag=1; OkFlag=1; } } } if(OkFlag==1) { LcdDisplay(0x0,0x0); } else if(Minute>=1) { if((Minute>=1)&&(Second>0)&&(StartFlag==1)) { temp2=(Minute+1)/10; temp1=(Minute+1)%10; } else { temp2=Minute/10; temp1=Minute%10; } if((StartFlag==1)&&(Count>125)) { LcdDisplay(0x00,0x00); } else {LcdDisplay(Number1[temp1],Number2[temp2]);} } else { temp2=Second/10; temp1=Second%10; LcdDisplay(Number1[temp1],Number2[temp2]); }
}
void SysInt(void) { WDTCR=0; DISI(); _asm { mov a,@0x44 contw } ISR=0; IMR=0x01; TCC=5; PHCR=0xFF; PDCR=0xFF; P5CR=0x08; P6CR&=0x07; InCom1; InCom2; InCom3; Seg1=0; Seg2=0; Seg3=0; Seg4=0; Seg5=0; BiasTime=0; BzOutTime=0; TimeFlag=0; OkFlag=0; StartFlag=0; BzOutFlag=0; Count=0; Second=0; Minute=0; Bz=0; Out=1; KeyFlag=0; ENI(); }
void LcdDisplay(uchar Num1,uchar Num2) { switch(BiasTime) { case 0: OutCom1; Com1=1; InCom2; InCom3; if((Num1&0x01)==0)Seg1=1; else Seg1=0; if((Num1&0x08)==0)Seg2=1; else Seg2=0; if((Num2&0x01)==0)Seg3=1; else Seg3=0; if((Num2&0x04)==0)Seg4=1; else Seg4=0; if((Num2&0x20)==0)Seg5=1; else Seg5=0; break; case 1: OutCom1; Com1=0; InCom2; InCom3; if((Num1&0x01)==0)Seg1=0; else Seg1=1; if((Num1&0x08)==0)Seg2=0; else Seg2=1; if((Num2&0x01)==0)Seg3=0; else Seg3=1; if((Num2&0x04)==0)Seg4=0; else Seg4=1; if((Num2&0x20)==0)Seg5=0; else Seg5=1; break; case 2: InCom1; OutCom2; Com2=1; InCom3; if((Num1&0x02)==0)Seg1=1; else Seg1=0; if((Num1&0x10)==0)Seg2=1; else Seg2=0; if((Num2&0x02)==0)Seg3=1; else Seg3=0; if((Num2&0x08)==0)Seg4=1; else Seg4=0; if((Num2&0x40)==0)Seg5=1; else Seg5=0; break; case 3: InCom1; OutCom2; Com2=0; InCom3; if((Num1&0x02)==0)Seg1=0; else Seg1=1; if((Num1&0x10)==0)Seg2=0; else Seg2=1; if((Num2&0x02)==0)Seg3=0; else Seg3=1; if((Num2&0x08)==0)Seg4=0; else Seg4=1; if((Num2&0x40)==0)Seg5=0; else Seg5=1; break; case 4: InCom1; InCom2; OutCom3; Com3=1; if((Num1&0x04)==0)Seg1=1; else Seg1=0; if((Num1&0x20)==0)Seg2=1; else Seg2=0; if((Num1&0x40)==0)Seg3=1; else Seg3=0; if((Num2&0x10)==0)Seg4=1; else Seg4=0; if((Num2&0x80)==0)Seg5=1; else Seg5=0; break; case 5: InCom1; InCom2; OutCom3; Com3=0; if((Num1&0x04)==0)Seg1=0; else Seg1=1; if((Num1&0x20)==0)Seg2=0; else Seg2=1; if((Num1&0x40)==0)Seg3=0; else Seg3=1; if((Num2&0x10)==0)Seg4=0; else Seg4=1; if((Num2&0x80)==0)Seg5=0; else Seg5=1; default:break; } Delayms(1); BiasTime++; if(BiasTime>=6) BiasTime=0; }
void KeyProcess(void) { if((TimeFlag>0)&&(TimeFlag<2000)) { OkFlag=0; TimeFlag++; if(TimeFlag>=2000) StartFlag=1; }
if((Key==0)&&(KeyFlag==0)&&(StartFlag==0)) { TimeFlag=1; Minute++; if(Minute>99) Minute=0; if(OkFlag==1) { //OkFlag=0; // Minute="0"; SysInt(); } KeyFlag=1; } else { if(Key==1) KeyFlag=0; if((Key==0)&&(KeyFlag==0)&&(StartFlag==1)) { SysInt(); KeyFlag=1; } } }
void BzOut(void) { uchar i,j; for(i=0;i<150;i++) { Bz=!Bz; for(j=0;j<58;j++) {NOP();NOP();} } /*Delayms(50); for(i=0;i<100;i++) { Bz=!Bz; for(j=0;j<50;j++) {NOP();NOP();} }*/ Bz=0; }
void Delayms(uint ms) { uint i,j; for(i=0;i<ms;i++) for(j=0;j<120;j++) NOP(); }
void _intcall interrupt_l(void) @0x08:low_int 0 { _asm { //save A --> 0x1F ; R3 --> 0x3E (ram bank 1); R4 --> 0x3F (ram bank 1) MOV 0X1F,A ;backup A to 0x1F SWAPA 0X04 ;backup R4 to 0x3F at bank 3 MOV 0X3F,A ;backup R4 to 0x3F at bank 3 SWAPA 0X03 MOV 0X3E,A ;backup R3 to 0x3E at bank 3 } } void _intcall interrupt(void) @int 0 { if(TCIF==0)return; DISI(); ISR=0; _asm { mov a,@0x44 contw } TCC=5; _asm { SWAPA 0X3E ;restore R3 MOV 0X03,A SWAPA 0X3F ;restore R4 MOV 0X04,A SWAP 0X1F ;restore A SWAPA 0X1F } _asm{INC 0X2F} ENI(); }
|
|
文章评论(0条评论)
登录后参与讨论