7219 chip drives LED electronic clock

Publisher:ShiningSmileLatest update time:2016-11-18 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

/***************The clock adopts the timed interrupt mode, 50MS once******Completely available, the hardware experiment passed**********************/
#include             
#include        
#include
/***********************************************************************/
#define uchar unsigned char
#define uint unsigned int
//common part 
#define HIGH 1
#define LOW 0
#define TRUE 1
#define FALSE 0
#define ZERO 0 
#define MSB 0x80
#define LSB 0x01
//max7219 part
#define REG_NO_OP 0x00 // Define no operation
#define DIG_1 0x01 // Define digital tube 1 
#define DIG_2 0x02 // Define digital tube 2 
#define DIG_3 0x03 // Define digital tube 3 
#define //  MAX7219 Load-Data Input: rising edge pin 12 sbit DIN=P2^5; //MAX7219 12bit LOAD  =  P2 
^  7  ;  //  MAX7219  Load  -  Data Input: rising edge pin 12  sbit DIN=P2^5; // MAX7219 Serial-Data Input: rising edge pin 1 sbit CLK=P2^6; //MAX7219  sbit TT=P1^4; sbit QQ=P3^6; sbit RR=P3^7; //function define /*****************************************************************/ void Write_Max7219_byte(unsigned char temp);//write max7219 a byte void Write_Max7219(unsigned char address,unsigned char dat);//write max7219 command and data void Init_Max7219(void);//Initize max7219 //test program display from 1~8 /****************************************************************************/ /***********************************************************************/ void Write_Max7219_byte(unsigned char temp) {  unsigned char i;  for (i=0;i<8;i++)        {     CLK=LOW;      DIN=(bit)(temp&MSB);            temp<<=1;       CLK=HIGH;    } } /**********************************************************************/ void Write_Max7219(unsigned char address,unsigned char dat) {   LOAD=LOW;    Write_Max7219_byte(address);     Write_Max7219_byte( dat);   LOAD=HIGH;                  }












































/****************************************************** ************************/
void Init_Max7219(void)      

 Write_Max7219(SHUT_DOWN, 0x01); //Normal Operation XXXXXXX1 Shutdown Mode XXXXXXXX0
 Write_Max7219(DISPLAY_TEST, 0x00)
 ;  //   Normal
 Operation
, 0x04); 
 Write_Max7219(DIG_4,0x02); Write_Max7219(DIG_3,0x01);
 Write_Max7219(DIG_6,0x07); Write_Max7219(DIG_5,0x05);
 Write_Max7219(DIG_7,0x01);
}
     
/****************************** ******************************/
void init(void)     
{      
TMOD=0x01;    
TH0=-(50000/256);   
TL0=-( 50000%256);  
ET0=1;     
TR0=1;     
EA=1; 
TT=0;
QQ=0;
RR=0;
Init_Max7219();    
}      
/****************** ***************************/
void time0(void) interrupt 1   
{      
TH0=-(50000/256);   
TL0=-(50000 %256);  
deda++;     
}            
/******************************************/
void conv (void)   
{      
if(deda>=20){deda=0;sec++;Write_Max7219(DIG_8,sec%10); Write_Max7219(DIG_7,sec/10); }
if(sec>=60){sec=0;min++; Write_Max7219(DIG_6 ,min%10); Write_Max7219(DIG_5,min/10);}  
if(min>=60){min=0;hour++; Write_Max7219(DIG_4,hour%10); Write_Max7219(DIG_3,hour/10);} 
if (hour>=24){hour=0;week++; Write_Max7219(DIG_2,week%10);} 
if(week>7){week=1;} 
if(hour==3) TT=1;  
}      
/** ***************************************/
void delay(uint k)   
{     
uint data i,j;   
for(i=0;ifor(j=0;j<121;j++)  
{;}}     
}     
/**************** *********************************/
uchar scan_key(void) 
{     
uchar temp;
P3=0x3f;   
temp=P3 ;    
if(temp!=0x3f)  
   {delay(20);  
    temp=P3;   
   if(temp!=0x3f) return temp;
    }     
return 0x3f;
}
/**************** ****************************/
void main(void)   
{uchar key_flag;  
 init();    
 while(1)   
 {     
 conv() ; 
 key_flag=scan_key();   
 switch(key_flag)  
    {     
    case 0x3b:if(++min>59)min=0; delay(300); Write_Max7219(DIG_6,min%10); Write_Max7219(DIG_5,min/10);break;
    case 0x37:if(++hour>23)hour=0; delay(300);Write_Max7219(DIG_4,hour%10); Write_Max7219(DIG_3,hour/10);break ;      
    case 0x2f:if(++week>7 )week=1; delay(300); Write_Max7219(DIG_2,week%10);break;
    default: break; 
    }     
 }     
}      

Reference address:7219 chip drives LED electronic clock

Previous article:Single chip electronic password lock with password change
Next article:Several Precise Delays of 51 Single Chip Microcomputer

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号