#include <STC15F2K60S2.H>
#define uchar unsigned char
#define uint unsigned int
uchar ccout=0;
/************* 本地常量声明 **************/
uchar code t_display[]={ //标准字库
// 0 1 2 3 4 5 6 7
0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,
// 8 9 A B C D E F
0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71,
//black
0x00};
//公阴极
uchar code T_COM[]={0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F};//位码
/************* IO口定义 **************/
sbit P_HC595_SER = P4^0; //pin 14 SER data input
sbit P_HC595_RCLK = P5^4; //pin 12 RCLk store (latch) clock
sbit P_HC595_SRCLK = P4^3; //pin 11 SRCLK Shift data clock
/**************** 向HC595发送一个字节函数 ******************/
void Send_595(uchar dat)
{
uchar i;
for(i=0; i<8; i++)
{
dat <<= 1;
P_HC595_SER = CY;
P_HC595_SRCLK = 1;
P_HC595_SRCLK = 0;
}
}
void delay1m(uint i)
{
uchar j;
while(i--)
{
for(j=0;j<250;j++)
{;}
}
}
void juq() interrupt 1
{
TH0= 0xFF;
TL0= 0xFB;
ccout++;
Send_595(0x07F);
Send_595(t_display[ccout%10]);
P_HC595_RCLK = 1;
P_HC595_RCLK = 0; //锁存输出数据
}
void main (void)
{
uchar i;
TMOD = 0x05;
TH0= 0xFF;
TL0= 0xFB;
IE = 0x82;
TR0=1;
for(i=0;i<8;i++)
{
Send_595(T_COM[i]);
Send_595(t_display[0x10]); //消隐,全灭
P_HC595_RCLK = 1;
P_HC595_RCLK = 0; //锁存输出数据
}
Send_595(0x07F);
Send_595(t_display[0]);
P_HC595_RCLK = 1;
P_HC595_RCLK = 0; //锁存输出数据
while(1)
{
P17=0;
delay1m(800);
P17=1;
delay1m(800);
}
}
|