我用的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分 展开
2011-04-28
展开全部
下载我的看看好使不
#define <reg51.h>
#define DECODE_MODE 0x09
#define INTENSITY 0x0A
#define SCAN_LIMIT 0x0B
#define SHUT_DOWN 0x0C
#define DISPLAY_TEST 0x0F
/*******************************/
sbit LOAD=P1^1;
sbit DIN=P1^0;
sbit CLK=P1^2;
/*******************************/
void Write_Max7219_byte(uchar temp)
{
uchar i;
for (i=0;i<8;i++)
{
CLK=0;
DIN=(bit)(temp&0x80);
temp<<=1;
CLK=1;
}
}
/*******************************/
void Write_Max7219(uchar address,uchar dat)
{
LOAD=0;
Write_Max7219_byte(address);
Write_Max7219_byte(dat);
LOAD=1;
}
/*******************************/
void Init_Max7219(void)
{
Write_Max7219(SHUT_DOWN, 0x01); //设置掉电模式
Write_Max7219(DISPLAY_TEST, 0x00); //设置不工作寄存器
Write_Max7219(DECODE_MODE, 0x09); //设置编码模式
Write_Max7219(SCAN_LIMIT, 0x06); //扫描控制寄存器
Write_Max7219(INTENSITY, 0x04); //设置亮度调节 0xX0~0xXf
}
/*******************************/
void main()
{
unsigned char ii;
Init_Max7219();
for(ii=1;ii<8;ii++)
{
Write_Max7219(ii,ii);
}
while(1);
}
#define <reg51.h>
#define DECODE_MODE 0x09
#define INTENSITY 0x0A
#define SCAN_LIMIT 0x0B
#define SHUT_DOWN 0x0C
#define DISPLAY_TEST 0x0F
/*******************************/
sbit LOAD=P1^1;
sbit DIN=P1^0;
sbit CLK=P1^2;
/*******************************/
void Write_Max7219_byte(uchar temp)
{
uchar i;
for (i=0;i<8;i++)
{
CLK=0;
DIN=(bit)(temp&0x80);
temp<<=1;
CLK=1;
}
}
/*******************************/
void Write_Max7219(uchar address,uchar dat)
{
LOAD=0;
Write_Max7219_byte(address);
Write_Max7219_byte(dat);
LOAD=1;
}
/*******************************/
void Init_Max7219(void)
{
Write_Max7219(SHUT_DOWN, 0x01); //设置掉电模式
Write_Max7219(DISPLAY_TEST, 0x00); //设置不工作寄存器
Write_Max7219(DECODE_MODE, 0x09); //设置编码模式
Write_Max7219(SCAN_LIMIT, 0x06); //扫描控制寄存器
Write_Max7219(INTENSITY, 0x04); //设置亮度调节 0xX0~0xXf
}
/*******************************/
void main()
{
unsigned char ii;
Init_Max7219();
for(ii=1;ii<8;ii++)
{
Write_Max7219(ii,ii);
}
while(1);
}
展开全部
void max7219_init(void) //这是初始化max芯片的程序吧
{
write7219(0x0C,0x01); //开启正常工作模式(0xX1)
write7219(0x0F,0x00); //选择工作模式(0xX0)
write7219(0x09,0xFF); //选用全译码模式
write7219(0x0B,0x07); //几个数码管亮
write7219(0x0A,0x0F); //设置初始亮度
}
main() 函数里 将初始化函数max7219_init放在最前面 如果要重复执行的话 用循环 也要注意新
一次执行时 芯片是被初始化过的
如果你是硬件实现的 main()里加上初始化后 数码管还是不亮的话 你就应该从电路的链接上找问
题了 有没有加上拉电阻? max7219周边电路需不需要电阻和电容? 值是多少?
祝顺利
{
write7219(0x0C,0x01); //开启正常工作模式(0xX1)
write7219(0x0F,0x00); //选择工作模式(0xX0)
write7219(0x09,0xFF); //选用全译码模式
write7219(0x0B,0x07); //几个数码管亮
write7219(0x0A,0x0F); //设置初始亮度
}
main() 函数里 将初始化函数max7219_init放在最前面 如果要重复执行的话 用循环 也要注意新
一次执行时 芯片是被初始化过的
如果你是硬件实现的 main()里加上初始化后 数码管还是不亮的话 你就应该从电路的链接上找问
题了 有没有加上拉电阻? max7219周边电路需不需要电阻和电容? 值是多少?
祝顺利
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
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)
这些是对的吗?
#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)
这些是对的吗?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
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);
}
这是?
#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)
这些是对的吗?
{
write7219(0x01,0x01);
write7219(0x02,0x02);
write7219(0x03,0x03);
write7219(0x04,0x04);
write7219(0x05,0x05);
write7219(0x06,0x06);
write7219(0x07,0x07);
write7219(0x08,0x08);
}
这是?
#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)
这些是对的吗?
更多追问追答
追问
上面那几行是第一位显示1,第二位显示2.。。。
下边的都是对的
追答
ADS是add|dat
而a=ADS&0x80;
那么if (a==0){MAX7219_DIN_0;}
else {MAX7219_DIN_1;}
这儿也确实是这样逻辑吗?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2011-04-07
展开全部
我用的7219驱动8个数码管,都不亮。请看一下我的程序有问题吗?如果解决了,还有重赏
就注定被错过,
就注定被错过,
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询