//用AVR点亮32*32LED点阵 点阵里集成74hc595 和74hc138
芯片
#include<avr/io.h>
#include<u
til/delay.h>
#include<avr/interrupt.h>
#include<avr/pgmspace.h>
#define SI1 PORTC|=(1<<PC0)
#define SI0 PORTC&=~(1<<PC0)
#define G1() PORTC|=(1<<PC1) // HC_595输出使能控制端置1
#define G0() PORTC&=~(1<<PC1) // HC_595输出使能控制端置0
#define RCK1() PORTC|=(1<<PC2) // HC_595存储寄存器时钟输入置1
#define RCK0() PORTC&=~(1<<PC2) // HC_595存储寄存器时钟输入置0
#define SCK1() PORTC|=(1<<PC3) // HC_595移位寄存器时钟输入置1
#define SCK0() PORTC&=~(1<<PC3) // HC_595移位寄存器时钟输入置0
#define SCLR1() PORTC|=(1<<PC4) // HC_595移位寄存器清零输入置1
#define SCLR0() PORTC&=~(1<<PC4) // HC_595移位寄存器清零输入置0
#define OE1() PORTA|=(1<<PA5) // HC_138使能置1
#define OE0() PORTA&=~(1<<PA5) // HC_138使能置0
long scan_date0[128]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
unsigned char scan_date1[32]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,
0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f}; //行
void delay(unsigned int ms )
{
while(ms--)
_delay_ms(1);
}
//初始化函数
void init()
{
//HC_595初始化
DDRC=0x1F;
PORTC=0xFF;
//G0() ; //使能HC_595输出使能控制端
//SCK0(); // HC_595移位寄存器时钟输入端口置低电平
//RCK0();
//SCLR0();
//SCLR1();
// HC_595存储寄存器时钟输入
//HC_138初始化
DDRA=0x3F;
PORTA=0xFF;
}
//HC_595列扫描
void HC_595( unsigned int date)
{
unsigned char i;
for(i=0;i<8;i++)
{ PORTA&=~(1<<PA5);
PORTC&=~(1<<PC3);
if(date&0x80)
PORTC|=(1<<PC0); //串行数据输入
else
PORTC&=~(1<<PC0);
date<<=1;
PORTC|=(1<<PC3) ;
}
PORTC&=~(1<<PC2); //上升沿锁存数据输出
PORTC|=(1<<PC2);
PORTC|=(1<<PC1); //关闭输出使能控制端
}
int main()
{ init();
unsigned int i=0;
unsigned int m=3;
unsigned int n=0;
for(i=0;i<=31;i++)
{
PORTA&=~(1<<PA5); //打开HC_138使能
PORTA=scan_date1[i];
for(n=m-3;n<=m;n++)
{ if(n<=127)
{
HC_595(scan_date0[n]);
m=m+4;
}
delay(4);
}
// OE1(); //关闭HC_138使能
}
}
一周热门 更多>