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

📄 7219ding.c

📁 AVR驱动7219程序
💻 C
字号:
#include <avr/io.h>
#include "avrbit.h"
#include <avr/interrupt.h>

#define din PB0
#define clk PB1
#define load PB2

#define uchar unsigned char
#define uint unsigned int

uint count1 = 0, s = 0;

#pragma data:code 
const table[] = {0x0000,0x0001,0x0002,0x0003,0x0004,0x0005,0x0006,0x0007,0x0008,
                   0x0009,0x000a,0x000b,0x000c,0x000d,0x000e,0x000f};

#pragma data:code 
const ADREE[] = {0x0100,0x0200,0x0300,0x0400,0x0500,0x0600,0x0700,0x0800,0x0c01,0x0a04,0x0b07,0x09ff};

void shuru(uint wei,uint shu,uint dian)
{
  uint i,j,k;
   k=0x0080 ;

   if( dian == 0 )
      j = ADREE[ wei ] | table[ shu ];
  else
     j=ADREE[wei]|table[shu]|k;
  for(i=0x8000;i>=0x0001;i=i>>1)
  {
    if((i&j)==0)
       din=0;
     else
      din=1;
	 clk=1;
	 clk=0;
  }
  load=1;
  load=0;
}

void shezhi()
{
shuru(8,0,0);//
shuru(9,0,0);//译码方式寄存器
shuru(10,0,0);//亮度
shuru(11,0,0);//数码管显示数目
}
void initial_T1()//选择定时器类型
{
   uint sreg;//
   sreg=SREG;
   TCCR1B=1<<CS10;
   TCNT1H=0x85;
   TCNT1L=0xED;
   SREG=sreg;//
}
SIGNAL(SIG_OVERFLOW1)
{
   count1++;
   if(count1==128)//定时一秒1/8*160
    {  
	    s++;
		if(s==89)
	    s=9;
       count1=0;
     }
}

void main()
{
  uint i=0,j=0;
  din=0;
  clk=0;
  load=0;
  int k;
  DDRB|=0x07;//拉高load
  shezhi();

  initial_T1();
  TIMSK = (1<<TOIE1);
   sei();//以上为定时器1的中断设置

	while(1)
    {
	  for(j=0;j<8;j++)
      {
	   k=s-j;
	    if(k<=0)
         k=0; 
	  shuru(j,k,0);
	  }
	  if(s=9) break;
   }
	
	 
   while(1)
   {
	 shuru(i,(s-i)%16,1);
     i++;
	 if(i==8)
	 i=0;	
   }
}

⌨️ 快捷键说明

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