我用的7219驱动8个数码管,都不亮。请看一下我的程序有问题吗?如果解决了,还有重赏
我用的是AVR单片机的PD5,PD6,PD7三个端口输出信号给7219,程序如下:#include<avr/io.h>//------max7219与M16的连接,可根据...
我用的是AVR单片机的PD5,PD6,PD7三个端口输出信号给7219,程序如下:
#include <avr/io.h>
//------max7219与M16的连接,可根据实际更改--------
#define MAX7219_OUT_DDR DDRD
#define MAX7219_OUT_PORT PORTD
#define MAX7219_LOAD_PORT PD6
#define MAX7219_DIN_PORT PD7
#define MAX7219_CLK_PORT PD5
//----------------------------------------------------------------
//------------------------------------------------------------
#define MAX7219_CLK_1 MAX7219_OUT_PORT|=1<<MAX7219_CLK_PORT
#define MAX7219_CLK_0 MAX7219_OUT_PORT&=~(1<<MAX7219_CLK_PORT)
#define MAX7219_DIN_1 MAX7219_OUT_PORT|=1<<MAX7219_DIN_PORT
#define MAX7219_DIN_0 MAX7219_OUT_PORT&=~(1<<MAX7219_DIN_PORT)
#define MAX7219_LOAD_1 MAX7219_OUT_PORT|=1<<MAX7219_LOAD_PORT
#define MAX7219_LOAD_0 MAX7219_OUT_PORT&=~(1<<MAX7219_LOAD_PORT)
void IO_INIT(void)
{
DDRD=0xff;
PORTD=0x00;
DDRA=0x00;
PORTA=0x00;
DDRB=0x00;
PORTB=0x00;
DDRC=0x00;
PORTC=0x00;
}
void write7219(unsigned char add,unsigned char dat)
{
unsigned char ADS,i,j,a;
i=0;
MAX7219_LOAD_0;//load=0
MAX7219_CLK_0;
while(i<16)
{
if(i<8){ADS=add;}
else{ADS=dat;}
for(j=8;j>=1;j--)
{
a=ADS&0x80;
if (a==0){MAX7219_DIN_0;}
else {MAX7219_DIN_1;}
ADS=ADS<<1;
MAX7219_CLK_1;//clk=1
_delay_ms(100);
MAX7219_CLK_0;//clk=0
_delay_ms(100);
}
i=i+8;
}
MAX7219_LOAD_1;//load=1
_delay_ms(100);
}
void max7219_init(void)
{
write7219(0x0C,0x01); //开启正常工作模式(0xX1)
write7219(0x0F,0x00); //选择工作模式(0xX0)
write7219(0x09,0xFF); //选用全译码模式
write7219(0x0B,0x07); //几个数码管亮
write7219(0x0A,0x0F); //设置初始亮度
}
int main(void)
{
IO_INIT();
while(1)
{
write7219(0x01,0x01);
write7219(0x02,0x02);
write7219(0x03,0x03);
write7219(0x04,0x04);
write7219(0x05,0x05);
write7219(0x06,0x06);
write7219(0x07,0x07);
write7219(0x08,0x08);
}
}
如果谁给解决了, 追加500分 展开
#include <avr/io.h>
//------max7219与M16的连接,可根据实际更改--------
#define MAX7219_OUT_DDR DDRD
#define MAX7219_OUT_PORT PORTD
#define MAX7219_LOAD_PORT PD6
#define MAX7219_DIN_PORT PD7
#define MAX7219_CLK_PORT PD5
//----------------------------------------------------------------
//------------------------------------------------------------
#define MAX7219_CLK_1 MAX7219_OUT_PORT|=1<<MAX7219_CLK_PORT
#define MAX7219_CLK_0 MAX7219_OUT_PORT&=~(1<<MAX7219_CLK_PORT)
#define MAX7219_DIN_1 MAX7219_OUT_PORT|=1<<MAX7219_DIN_PORT
#define MAX7219_DIN_0 MAX7219_OUT_PORT&=~(1<<MAX7219_DIN_PORT)
#define MAX7219_LOAD_1 MAX7219_OUT_PORT|=1<<MAX7219_LOAD_PORT
#define MAX7219_LOAD_0 MAX7219_OUT_PORT&=~(1<<MAX7219_LOAD_PORT)
void IO_INIT(void)
{
DDRD=0xff;
PORTD=0x00;
DDRA=0x00;
PORTA=0x00;
DDRB=0x00;
PORTB=0x00;
DDRC=0x00;
PORTC=0x00;
}
void write7219(unsigned char add,unsigned char dat)
{
unsigned char ADS,i,j,a;
i=0;
MAX7219_LOAD_0;//load=0
MAX7219_CLK_0;
while(i<16)
{
if(i<8){ADS=add;}
else{ADS=dat;}
for(j=8;j>=1;j--)
{
a=ADS&0x80;
if (a==0){MAX7219_DIN_0;}
else {MAX7219_DIN_1;}
ADS=ADS<<1;
MAX7219_CLK_1;//clk=1
_delay_ms(100);
MAX7219_CLK_0;//clk=0
_delay_ms(100);
}
i=i+8;
}
MAX7219_LOAD_1;//load=1
_delay_ms(100);
}
void max7219_init(void)
{
write7219(0x0C,0x01); //开启正常工作模式(0xX1)
write7219(0x0F,0x00); //选择工作模式(0xX0)
write7219(0x09,0xFF); //选用全译码模式
write7219(0x0B,0x07); //几个数码管亮
write7219(0x0A,0x0F); //设置初始亮度
}
int main(void)
{
IO_INIT();
while(1)
{
write7219(0x01,0x01);
write7219(0x02,0x02);
write7219(0x03,0x03);
write7219(0x04,0x04);
write7219(0x05,0x05);
write7219(0x06,0x06);
write7219(0x07,0x07);
write7219(0x08,0x08);
}
}
如果谁给解决了, 追加500分 展开
6个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询