单片机时钟设计MAX7219驱动数码管

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
}
void timer0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
count++;
if(count==20)
{
count=0;
flag=~flag;
sec++;
if(sec==60)
{
sec=0;
min++;
if(min==60)
{
min=0;
hour++;
if(hour==24)
{
hour=0;
min=0;
sec=0;
}
}
}
}
}
void main()
{
init();
Init_max7219 ( );
while(1)
{
conv(hour,min);
write_max7219(ShutDown,0x01);//*"设置电源工作模式"*/
write_max7219(DisplayTest,0x01);
delay(5);
write_max7219(DisplayTest,0x00);
}
void conv(uchar in1,in2)
{
disp_buf[0]=in1/10;
uchar hour=12,min=0,sec=0,count=0;
bit flag;
void delay (uint a) //"毫秒延时函数"
{
uint i;
while( --a != 0)
{
for(i = 0; i < 110; i++);
}
}
void write_max7219_byte(uchar temp)
uchar code seg_data[]={0x7E,0x30,0x6D,0x79,0x33,
0x5B,0x5F,0x70,0x7F,0x7B}; //"0,1,2,3,4,5,6,7,8,ቤተ መጻሕፍቲ ባይዱ"
uchar disp_buf[5];
uchar code bit_tab[]={0x01,0x02,0x03,0x04};
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit DIN=P0^1; //"显示串行数据输入端"
sbit LOAD=P0^2; //"显示数据锁存端"
sbit CLK=P0^3; //"显示时钟输入端"
write_max7219(bit_tab[1],disp_buf[1]);
write_max7219(bit_tab[2],disp_buf[2]);
write_max7219(bit_tab[3],disp_buf[3]);
}
void init()
{
TMOD=0x01;
TH0=(65536-50000)/256;
#define DecodeMode 0x09 //"译码模式"
#define Intensity 0x0a//"亮度"
#define ScanLimit 0x0b //"扫描界限"
#define ShutDown 0x0c//"掉电模式"
#define DisplayTest 0x0f//"显示测试"
LOAD=1;
}
void Init_max7219 (void)
{
write_max7219(ScanLimit,0x07); //*"设置扫描界限"*/
write_max7219(DecodeMode,0xff); //*"设置译码模式"*/
write_max7219(Intensity,0x04);//*"设置亮度"*/
{
uchar i;
for(i=0;i<8;i++)
{
CLK=0;
DIN=(bit)(temp&0x80);
temp<<=1;
CLK=1;
}
}
void write_max7219(uchar address,uint dat)
{
LOAD=0;
write_max7219_byte(address);
write_max7219_byte(dat);
disp_buf[1]=in1%10;
disp_buf[2]=in2/10;
if(flag==0)
disp_buf[3]=(in2%10)|0x80;
else
disp_buf[3]=in2%10;
}
void display( )
{
write_max7219(bit_tab[0],disp_buf[0]);
display( );
}
}
相关文档
最新文档