跪求大神了................................搞了好几天都不知道问题出在哪,现在开始怀疑是芯片坏了...............
单片机是c8051f020,用p3.5,,p3.6,p3.7端口,设置为漏极开路,外面接5v上拉电阻后输入到max7219(单片机3.3v供电,7219要求>=3.5v),7219的D0-D3接了4个数码管,段选也都接对了,电阻RSET=12K。
程序如下:
#define sysclk 8000000
#define sar_rate 2000000
#define DECODE_MODE 0x09
#define INTENSITY 0x0A
#define SCAN_LIMIT 0x0B
#define SHUTDOWN 0x0C
#define DISPLAY_TEST 0x0F
#define Digit0 0x01
#define Digit1 0x02
#define Digit2 0x03
#define Digit3 0x04
#define Digit4 0x05
#define Digit5 0x06
#define Digit6 0x07
#define Digit7 0x08
#define uchar unsigned char
#include <c8051f020.h>
sbit LOAD=P3^5;
sbit DIN=P3^6;
sbit CLK=P3^7;
sfr16 RCAP2 = 0xca;
sfr16 TMR2 = 0xcc;
sfr16 ADC0 = 0xbe;
sfr16 TMR3RL = 0x92;
sfr16 TMR3 = 0x94;
void Osc_init(void);
void Port_init(void);
void ADC0_init(void);
void Wait_ms(int ms);
void Tmr3_init(void);
void Write_7219(uchar address,uchar dat);
void Init_7219(void);
void Display(uchar left);
void ADC0_ISR(void);
头文件直接都弄上来了,本来还要用到其他资源,但是显示模块都没出来,蛋疼了....
下面是7219的测试程序:
#include <process.h>
void main(void)
{
WDTCN=0xde;
WDTCN=0xad;
Osc_init();
Port_init();
Init_7219();
Display(90);
}
void Osc_init(void)
{
/* int i;
OSCXCN=0x67;
for(i=0;i<8000;i++);
while(!(OSCXCN&0x80));
OSCICN=0x88; */
OSCICN=0x96;
}
void Port_init(void)
{
// P1MDIN=0x00;
// P3MDOUT=0x07;
XBR2=0xC0;
}
void Write_7219 (uchar address,uchar dat)
{
uchar i;
LOAD=0;
for (i=0;i<8;i++)
{
CLK=0;
DIN=(bit)(address&0x80);
address<<=1;
CLK=1;
}
for (i=0;i<8;i++)
{
CLK=0;
DIN=(bit)(dat&0x80);
dat<<=1;
CLK=1;
}
LOAD=1;
}
void Init_7219(void)
{
Write_7219(SHUTDOWN,0x01);
Write_7219(SCAN_LIMIT,0x03); //<4需要改变RSET值。 RSET>=9.53K
Write_7219(INTENSITY,0x07);
Write_7219(DECODE_MODE,0x0f);
Write_7219(DISPLAY_TEST,0x00);
}
void Display(uchar left)
{
uchar bai=0,shi=0,ge=0;
if(left<10)
{
Write_7219(SCAN_LIMIT,0x00);
while(1)
{
Write_7219(0x01,left);
}
}
else if(left<100&&left>=10)
{
shi=left/10;
ge=left-10*shi;
Write_7219(SCAN_LIMIT,0x01);
while(1)
{
Write_7219(Digit1,shi);
Write_7219(Digit0,ge);
}
}
else if(left<=180&&left>=100)
{
bai=left/100;
shi=(left-100*bai)/10;
ge=left%10;
Write_7219(SCAN_LIMIT,0x02);
while(1)
{
Write_7219(Digit2,bai);
Write_7219(Digit1,shi);
Write_7219(Digit0,ge);
}
}
else
{
Write_7219(SCAN_LIMIT,0x03);
while(1)
{
Write_7219(Digit7,0x0A);
Write_7219(Digit6,0x0A);
Write_7219(Digit5,0x0A);
Write_7219(Digit4,0x0A);
Write_7219(Digit3,0x0A);
Write_7219(Digit2,0x0A);
Write_7219(Digit1,0x0A);
Write_7219(Digit0,0x0A);
}
}
}
复位问题?不太懂啊,昨天已经用最简单的直接动态扫描重新做了一个......
用单片机去复位7219
类似的还有8155/8255
也有这样的问题
一周热门 更多>