|
代碼設(shè)置的上限是999分鐘,為什么加到255分鐘之后,再按加就變?yōu)?了,求解原因
代碼:
- #include "CH554.H"
- #include "Debug.H"
- #include "GPIO.H"
- #include "HT1621.H"
- #include "Timer.H"
- #include "stdio.h"
- #include <string.h>
- #include <intrins.h>
- #define uchar unsigned char
- #define uint unsigned int
- // // 0 1 2 3 4 5 6 7 8 9
- uchar code tabe1[11] = {0xF0,0x00,0xD0,0x90,0x20,0xB0,0xF0,0x10,0xF0,0xB0};
- uchar code tabe2[11] = {0xA0,0xA0,0x60,0xE0,0xE0,0xC0,0xC0,0xA0,0xE0,0xE0};
- sbit key1 = P3^3; //分鐘加
- sbit key2 = P3^4; //分鐘減
- uchar min,min0,min1,min2,sec,sec1,sec2,count;
- void delay_ms(uint z) //延時(shí)程序1
- {
- uint x,y;
- for(x=z;x>0;x--)
- for(y=110;y>0;y--);
- }
- /*******************************************************************************
- * Function Name : void Display_Init()
- * Description : 時(shí)間顯示
- *******************************************************************************/
- void Display_Init(uchar min0,uchar min1,uchar min2,uchar sec1,uchar sec2)
- {
- Write_1621(3,tabe1[min0],4);
- Write_1621(4,tabe2[min0],4);
- Write_1621(5,tabe1[min1],4);
- Write_1621(6,tabe2[min1],4);
- Write_1621(7,tabe1[min2],4);
- Write_1621(8,tabe2[min2],4);
- Write_1621(11,tabe1[sec1],4);
- Write_1621(12,tabe2[sec1],4);
- Write_1621(13,tabe1[sec2],4);
- Write_1621(14,tabe2[sec2],4);
- }
- /*******************************************************************************
- * Function Name : void Timer0_Init()
- * Description : 定時(shí)器初始化
- *******************************************************************************/
- void Time0_Init()
- {
- count = 0;
- min = 0;
- sec = 59;
- mTimer0Clk12DivFsys(); //T0定時(shí)器時(shí)鐘設(shè)置
- mTimer_x_ModInit(0,1); //T0定時(shí)器模式設(shè)置
- mTimer_x_SetData(0,0xC350); //T0定時(shí)器賦值
- mTimer0RunCTL(1); //T0定時(shí)器啟動(dòng)
- ET0 = 1; //T0定時(shí)器中斷開啟
- EA = 1;
- }
- /*******************************************************************************
- * Function Name : mTimer0Interrupt()
- * Description : CH554定時(shí)計(jì)數(shù)器0定時(shí)計(jì)數(shù)器中斷處理函數(shù)
- *******************************************************************************/
- void mTimer0Interrupt( void ) interrupt INT_NO_TMR0 using 1 //timer0中斷服務(wù)程序,使用寄存器組1
- {
- mTimer_x_SetData(0,0xC350); //非自動(dòng)重載方式需重新給TH0和TL0賦值
- count++;
- if(count==10)
- {
- count=0;
- if(sec==0)
- {
- if(min!=0)
- {
- sec=59;
- min--;
- }
- else
- {
- mTimer0RunCTL(0); //T0定時(shí)器停止
- }
- }
- else sec--;
- }
- }
- void main( )
- {
- Time0_Init();
- Init_1621(); //初始化HT1621
- HT1621_all_off(); //清空LCD顯示
- while(1)
- {
- if(key1==0)
- {
- delay_ms(100);
- if(key1==0)
- {
- if(min!=999)
- {
- min++;
- }
- }
- while(!key2);
- delay_ms(1000);
- while(!key2);
- }
- if(key2==0)
- {
- delay_ms(100);
- if(key2==0)
- {
- if(min!=0)
- {
- min--;
- }
- }
- while(!key1);
- delay_ms(1000);
- while(!key1);
- }
- min0=min/100;
- min1=min%100/10;
- min2=min%10;
- sec1=sec/10;
- sec2=sec%10;
- Display_Init(min0,min1,min2,sec1,sec2);
- }
- }
復(fù)制代碼
|
|