大佬好,有没有16位数码管的驱动例子?8位的参照范例弄成功了,16位的却不行 ...
3个 595,1个驱动数码管段选(a-g,p),2个驱动数码管位选(com1-16) 用扫描方式驱动
[*]/****************************************************************
[*]* 文件名:code.c
[*]* 说明:Chip=STC89C52; Crystal=12MHz;12T
[*]* 功能:3*74xx595 显示16数码管
[*]* 修订:FreeFish 2019
[*]* 版本:V0.1
[*]****************************************************************/
[*]#include<reg52.h>
[*]sbit Dat=P2^0;
[*]sbit RCK=P2^2;
[*]sbit SCK=P2^3;
[*]unsigned char index,k;
[*]unsigned intposition;
[*]unsigned char code table[]={
[*]0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
[*]unsigned char Dat_Buf; //要送出的3个字节数据(段数据-位数据-位数据)
[*]unsigned char Dat_Disp; //要显示的16个字符。
[*]/****************************************************************
[*]* 函数功能:595写入数据
[*]****************************************************************/
[*]void write595(unsigned char Data)
[*]{
[*]unsigned char i;
[*]for (i=0;i<8;i++)
[*]{
[*] Dat = ((Data & 0x80)==0x80)?1:0;
[*] Data = Data << 1;
[*] SCK = 1;
[*] SCK = 0;
[*]}
[*]}
[*]void InitTimer0(void) //1ms
[*]{
[*]TMOD = 0x01;
[*]TH0 = 0x0FC;
[*]TL0 = 0x18;
[*]EA = 1;
[*]ET0 = 1;
[*]TR0 = 1;
[*]}
[*]/****************************************************************
[*]* 函数功能:主函数
[*]****************************************************************/
[*]void main()
[*]{
[*]InitTimer0();
[*]Dat_Disp=3;
[*]Dat_Disp=1;
[*]Dat_Disp=4;
[*]Dat_Disp=1;
[*]Dat_Disp=5;
[*]Dat_Disp=9;
[*]Dat_Disp=2;
[*]Dat_Disp=6;
[*]Dat_Disp=5;
[*]Dat_Disp=3;
[*]Dat_Disp=5;
[*]Dat_Disp=8;
[*]Dat_Disp=9;
[*]Dat_Disp=7;
[*]Dat_Disp=9;
[*]Dat_Disp=3;
[*]while(1)
[*]{
[*] if(index==0)
[*] Dat_Buf=table]-0x80;//装载段数据
[*] else
[*] Dat_Buf=table];//装载段数据
[*] position=1<<index;
[*] Dat_Buf=position/256; //位选16-9
[*] Dat_Buf=position%256; //位选8-1
[*] for (k=0;k<3;k++)
[*] {
[*] write595(Dat_Buf);//
[*] }
[*] RCK=1; //更新数据
[*] RCK=0; //准备下一次
[*] //Delay(10); //点亮一段时间
[*]}
[*]}
[*]void Timer0Interrupt(void) interrupt 1 //1ms
[*]{
[*]TH0 = 0x0FC;
[*]TL0 = 0x18;
[*]//add your code here!
[*]index++;
[*]index=index%16;
[*]}
[*]
angmall 发表于 2024-5-16 13:27
3个 595,1个驱动数码管段选(a-g,p),2个驱动数码管位选(com1-16) 用扫描方式驱动
非常感谢大佬!
我是TB上买的2块8位数码管,每块有2片595,因为IO不够用,将2块三线串联成16位一起使用,与你的有点区别。
没有编程基础,对位的没有认识,也不会仿真,硬是靠笨办法试,N多次摸索下载实测
已经试验成功,回过头一看,其实跟一块8位数码管一样的驱动,一块的时候发段码-发位码-锁存,
两块串一起的时候,就是发段码-发位码-发段码-发位码-锁存,让4片595都收到数据后锁存
页:
1
[2]