求助关于TM1620的驱动程序
想用1620做一个数码管显示,测试自动地址加1方式正常,测试固定地址模式怎么都通不过,表现为永远都是第一位显示为最后一位的数据,其它位的全部是乱的。附程序如下:#include<reg52.h>
#define uchar unsigned char
uchar a={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07};
sbit STB=P1^3; //定义端口
sbit CLK=P1^2;
sbit DIN=P1^0;
void indate(unsigned char p)
{
unsigned int i;
STB=0;
for(i=8;i>0;i--)
{
CLK=0;
if((p&0x01)!=0)
{
DIN=1;
}
else
{
DIN=0;
}
CLK=1;
p=p>>1;
}
}
void display()
{
DIN=1;
CLK=1;
STB=1; //初始化
indate(0x44); //固定地址方式
STB=1;
indate(0xc0); //传地址
indate(a); //传数据
indate(0xc1); //传地址
indate(a); //传数据
indate(0xc2); //传地址
indate(a); //传数据
indate(0xc3); //传地址
indate(a); //传数据
indate(0xc4); //传地址
indate(a); //传数据
indate(0xc5); //传地址
indate(a); //传数据 第一位永远都是显示这里的数据
STB=1;
indate(0x8f); //显示控制命令
STB=1;
}
void main(void)
{
DIN=1;
CLK=1;
STB=1;
indate(0x00);//设置显示模式
STB=1;
display(); //传送地址数据
while(1);
} 没用过这个芯片,只用过TM1638,看起来比这个简单的多。。。 继续求助啊,哪位高手知道,帮忙一下,谢谢! 本帖最后由 lmt50211 于 2014-1-10 17:04 编辑
imfv 发表于 2014-1-10 11:52
继续求助啊,哪位高手知道,帮忙一下,谢谢!
楼主,显存地址错了。 上面写得很清楚,地址是00H,02H,04H,06H,08H,0AH;而你是从00H--05H;
void tm_display()//写多字节数据
{
uchar i;
tm_clk=1;
tm_dio=1;
tm_stb=1;
send_data(0x44);//写数据
tm_stb=1;
for(i=0;i<6;i++)
{
send_data(0xc0+(i*2));//写地址
send_data(disbuf);//写数据到显存
tm_stb=1;
}
send_data(0x8f);//开显示,亮度为16/16
tm_stb=1;
} lmt50211 发表于 2014-1-10 17:02
楼主,显存地址错了。 上面写得很清楚,地址是00H,02H,04H,06H,08H,0AH;而你是从00H--05H;
void tm_di ...
是不是地址分别为:0xc0,0xc2,0xc4,0xc6,0xc8,0xca? lmt50211 发表于 2014-1-10 17:02
楼主,显存地址错了。 上面写得很清楚,地址是00H,02H,04H,06H,08H,0AH;而你是从00H--05H;
void tm_di ...
按照你所说的方法,现在只改了程序里的这部分,现在能够正常显示前4位,后两位不能显示。
void display()
{
DIN=1;
CLK=1;
STB=1; //初始化
indate(0x44); //固定地址方式
STB=1;
indate(0xc0); //传地址
indate(a); //传数据
STB=1;
indate(0xc2); //传地址
indate(a); //传数据
STB=1;
indate(0xc4); //传地址
indate(a); //传数据
STB=1;
indate(0xc6); //传地址
indate(a); //传数据
STB=1;
indate(0xc8); //传地址
indate(a); //传数据 这位不能显示
STB=1;
indate(0xca); //传地址
indate(a); //传数据 这位不能显示
STB=1;
indate(0x8f); //显示控制命令
STB=1;
} 试了一下,把显示模式改为0x02后都显示出来了,为什么? 终于搞定了,上传全部代码,供其他人参考,程序写的不好,还请高手指教。
/************************************************************
测试环境:STC12C5A16S2晶振:12M
************************************************************/
#include<reg52.h>
#define uchar unsigned char
uchar a={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07};
sbit STB=P1^3; //定义端口
sbit CLK=P1^2;
sbit DIN=P1^0;
void indate(unsigned char p)
{
unsigned int i;
STB=0;
for(i=0;i<8;i++)
{
CLK=0;
if((p&0x01)!=0)
{
DIN=1;
}
else
{
DIN=0;
}
CLK=1;
p=p>>1;
}
}
void display()
{
DIN=1;
CLK=1;
STB=1; //初始化
indate(0x44); //固定地址方式
STB=1;
indate(0xc0); //传第一位地址
indate(a); //传第一位数据
STB=1;
indate(0xc2); //传第二位地址
indate(a); //传第二位数据
STB=1;
indate(0xc4); //传第三位地址
indate(a); //传第三位数据
STB=1;
indate(0xc6); //传第四位地址
indate(a); //传第四位数据
STB=1;
indate(0xc8); //传第五位地址
indate(a); //传第五位数据
STB=1;
indate(0xca); //传第六位地址
indate(a); //传第六位数据
STB=1;
indate(0x8f); //传显示控制命令
STB=1;
}
void main(void)
{
DIN=1;
CLK=1;
STB=1;
indate(0x02);//设置显示模式
STB=1;
display(); //传送地址和数据
while(1);
} 谢谢啦,正在调试tm1668程序,可以参考LZ的代码 在这里记一下!能用的着! 非常不错 用过tm1640
页:
[1]