求帮忙看看这个程序,怎么一个等都不显示啊,多谢多谢
#include<avr/io.h>
#include<util/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使能
}
}
你把电路图发一下
你写这个程序是32扫的,对速度要求高,静态显示可能还可以,当要移位的话就显示不好了。还有扫描方式可能要改一下,特别是缓存数据好好处理一下,不然你的程序会很麻烦的。建议选择行列式,这样程序比较好处理,32扫的也可以用行列式,分成4列,每列32个字节的数据,缓存可以这样定义BufferData[4][32]
好的好的,老师只给了块板子,没有电路图
现在亮了,但我只能让它全亮,改了数组数控制不了让哪个灭,好像595进不去呀,麻烦您帮看看呗
//用AVR点亮32*32LED点阵 点阵里集成74hc595 和74hc138芯片
#include<avr/io.h>
#include<util/delay.h>
//#include "uart.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
unsigned char 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}; //行
/*unsigned char scan_date0[128]={0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff };
unsigned char scan_date1[32]={0x1f,0x1e,0x1d,0x1c,0x1b,0x1a,0x19,0x18,0x17,0x16,0x15,0x14,0x13,0x12,0x11,0x10,
0x0f,0x0e,0x0d,0x0c,0x0b,0x0a,0x09,0x08,0x07,0x06,0x05,0x04,0x03,0x02,0x01,0x00};*/
void delay(unsigned int us )
{
while(us--)
_delay_us(1);
}
//初始化函数
void init()
{
//HC_595初始化
DDRC=0xFF;
PORTC=0xFF;
DDRA=0xFF;
PORTA=0xFF;
}
//HC_595列扫描
void HC_595( unsigned int date)
{
unsigned char i;
for(i=0;i<8;i++)
{ SCK0();
if(date&0x80)
PORTC|=(1<<PC0);
else
PORTC&=~(1<<PC0);
SCK1();
// delay(10);
date<<=1;
}
}
int main()
{ init();
// UART_Config();
G0();
SCLR0() ;
SCLR1() ;
// unsigned int i=0;
// unsigned int m=3;
unsigned int n=0;
while(1)
{ for(n=0;n<32;n++)
{
//OE0();
PORTA&=~(1<<PA5);
PORTA=scan_date1[n];
HC_595(scan_date0[n*4]);
HC_595(scan_date0[n*4+1]);
HC_595(scan_date0[n*4+2]);
HC_595(scan_date0[n*4+3]);
RCK0();
RCK1();
OE1();
delay(10);
}
// delay (200);
}
}