那位帮看看这个程序怎么更改为51单片机使用两片74HC595级联驱动八位数码管电子时钟C
#include <AT89X51.H>
#define MAIN_Fosc 11059200UL //?????
#define Timer0_Reload (MAIN_Fosc / 12000)
#define uchar unsigned char //ÉùÃ÷ÎÞ·ûºÅ×Ö·û±äÁ¿£¬
#define uint unsigned int //ÉùÃ÷ÎÞ·ûºÅ×Ö·û±äÁ¿£
//º¯ÊýÉùÃ÷
void main (void); // Ö÷º¯Êý
void LED_Display (void); // LEDÏÔʾ³ÌÐò
void LED_OUT(uchar LED); // LEDµ¥×Ö½Ú´®ÐÐÒÆλº¯Êý
void delay(void); //ÑÓʱ³ÌÐò
void time_pro(void); //ʱ¼ä´¦Àí³ÌÐò
void key_pro(void); //¼üÅÌɨÃè³ÌÐò
uchar code segment[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xbf,0xff}; //¶ÎÂë
uchar code segbit[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}; //λÂë
uchar LED[8]={0,0,0,0,0,0,0,0}; //ÓÃÓÚLEDµÄ8λÏÔʾ»º´æ
uchar LED_bit; //¶¨ÒåÒ»¸ö´ýÊä³ö×Ö½Ú±äÁ¿
uchar display_index; //LEDÏÔʾλË÷Òý
sbit DIO = P1^0; //´®ÐÐÊý¾ÝÊäÈë pin 14 SER data input
sbit RCLK = P1^1; //ʱÖÓÂö³åÐźšª¡ªÉÏÉýÑØÓÐЧ pin 12 RCLk store (latch) clock
sbit SCLK = P1^2; //´òÈëÐźšª¡ª¡ª¡ªÉÏÉýÑØÓÐЧ pin 11 SRCLK Shift data clock
bit B_1ms; //1msÑÓʱ
/**********************************************/
void main(void)
{
SCLK = 0;
DIO = 1;
while(1)
{
uchar i;
for(i=0;i<8;i++)
{
LED_bit = LED;
LED_OUT(i);
delay();
}
}
}
void delay(void)
{
uchar i,k;
uint j;
TMOD = 0x00; //Timer 0 config as 16bit timer, 12T
TH0 = (65536 - Timer0_Reload) / 256;
TL0 = (65536 - Timer0_Reload) % 256;
ET0 = 1;
TR0 = 1;
EA = 1;
for(i=0; i<8; i++) LED[i] = 0x10; //ÉϵçÏûÒþ
j = 0;
k = 0;
while(1)
{
while(!B_1ms) ; //µÈ´ý1msµ½
B_1ms = 0;
if(++j >= 500); //500msµ½
{
j = 0;
for(i=0; i<8; i++) LED[i] = k; //Ë¢ÐÂÏÔʾ
if(++k > 7) k = 0; //8¸öÊýÂë¹ÜÑ»·ÏÔʾ0,1,2...,A,B..F,ÏûÒþ. Õâ¸ö¿ÉÒÔµ÷ÕûÏÔʾÄǸö²»ÏÔʾÄǸö
}
}
}
void LED_OUT(uchar LED) //·¢ËÍÒ»¸ö×Ö½Ú
{
uchar i;
for(i=0; i<8; i++)
{
if(LED & 0x80) DIO = 1;
else DIO = 0;
LED = LED << 1;
SCLK = 1;
SCLK = 0;
}
}
void LED_Display(void) //ÏÔʾɨÃ躯Êý
{
uchar i;
LED_bit = segment;
i = LED_bit;
LED_OUT(segment[display_index]); //¹²ÑôÊä³öλÂë
LED_OUT(segbit[LED[display_index]]); //¹²ÑôÊä³ö¶ÎÂë
RCLK = 1;
RCLK = 0; //??????
if(++display_index >= 8) display_index = 0; //8λ½áÊø»Ø0
}
void timer0 (void) interrupt 1 //Timer0 1ms ÖжϺ¯Êý
{
TH0 = (65536 - Timer0_Reload) / 256; //ÖØ×°¶¨Ê±Æ÷
TL0 = (65536 - Timer0_Reload) % 256;
LED_Display(); //1msɨÃèÏÔʾһλ
B_1ms = 5; //1ms±êÖ¾
}
|