⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 max7219.c

📁 93cxx读写驱动程序.51单片机的驱动程序
💻 C
字号:

#include "zhaobin.h"

void write_max7219 (unsigned int temp_0)
{
  unsigned int  temp_int;
  unsigned int  temp;
  unsigned char temp_1;
  temp=temp_0;
  load=1;   clk_max=0;     _nop_ ();   _nop_ ();   _nop_ ();
  load=0;   _nop_ ();
  for (temp_1=0;temp_1<16;temp_1++)
    {

	 temp_int=temp&0x8000;
	 if (temp_int==0x8000)  din=1;
	 else din=0;
	 _nop_ ();
	 clk_max=1; 
	 _nop_ (); _nop_ ();
   	 clk_max=0;
	 temp=temp<<1;
	 }
  load=1;  clk_max=0;
  _nop_ ();  _nop_ ();
//  clk_max=1;
}

void init_max7219 (void)
{
//  unsigned int max_int_data;
//  unsigned char max_data;
//  write_max7219(0x0f00);          //Display
  write_max7219(0x0c01);          //Shutdown

  write_max7219(0x0b07);         //27/32
  write_max7219(0x0a0f);          //Code B decode for digits 7-0
  write_max7219(0x09ff);         //Display digits


  _nop_ ();


//  write_max7219(0x0f00);          //Display
}
void display_sec (void)
{
  unsigned char ttmp,tnmp;
  ttmp=read_sec ();
  tnmp=ttmp&0x0f;
   write_max7219 (256*8|tnmp);
  tnmp=ttmp&0x70;
  tnmp=tnmp>>4;
  tnmp=0x0f&tnmp;
   write_max7219 (256*7|tnmp);
}

void display_min (void)
{
  unsigned char ttmp,tnmp;
  ttmp=read_min ();
  tnmp=ttmp&0x0f;
   write_max7219 (256*5|tnmp);
  tnmp=ttmp&0x70;
  tnmp=tnmp>>4;
  tnmp=0x0f&tnmp;
   write_max7219 (256*4|tnmp);
}

void display_hour (void)
{
  unsigned char ttmp,tnmp;
  ttmp=read_hour ();
  tnmp=ttmp&0x0f;
   write_max7219 (256*2|tnmp);
  tnmp=ttmp&0x70;
  tnmp=tnmp>>4;
  tnmp=0x0f&tnmp;
   write_max7219 (256*1|tnmp);
}

void display_date (void)
{
  unsigned char ttmp,tnmp;
  ttmp=read_date ();
  tnmp=ttmp&0x0f;
   write_max7219 (256*8|tnmp);
  tnmp=ttmp&0x70;
  tnmp=tnmp>>4;
  tnmp=0x0f&tnmp;
   write_max7219 (256*7|tnmp);
}

void display_month (void)
{
  unsigned char ttmp,tnmp;
  ttmp=read_month ();
  tnmp=ttmp&0x0f;
   write_max7219 (256*5|tnmp);
  tnmp=ttmp&0x70;
  tnmp=tnmp>>4;
  tnmp=0x0f&tnmp;
   write_max7219 (256*4|tnmp);
}

void display_year (void)
{
  unsigned char ttmp,tnmp;
  ttmp=read_year ();
  tnmp=ttmp&0x0f;
   write_max7219 (256*2|tnmp);
  tnmp=ttmp&0x70;
  tnmp=tnmp>>4;
  tnmp=0x0f&tnmp;
   write_max7219 (256*1|tnmp);
}

void display_day (void)
{
  unsigned char ttmp,tnmp;
  ttmp=read_day ();
  tnmp=ttmp&0x0f;
   write_max7219 (0x080a);
   write_max7219 (0x070a);
   write_max7219 (0x060a);
   write_max7219 (0x050a);
   write_max7219 (256*4|ttmp);
   write_max7219 (0x030a);
   write_max7219 (0x020a);
   write_max7219 (0x010a);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -