208 views|8 replies

3190

Posts

0

Resources
The OP
 

Programming Problems of Two-Bit 595 Driving 8-Bit Common Cathode Digital Tube [Copy link]

Schematic

Code:
#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char 
 

uchar code Table[] = 
{ // 0	 1	  2	   3	4	 5	  6	   7	8	 9	  A	   b	C    d	  E    F    - 
	0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x86,0xFF,0xbf
};
 //-----------------------------------------------------------------------------

sbit SER = P1^0;	//串行数据输入端
sbit STCP = P1^1;	//时钟脉冲信号——上升沿有效 存储寄存器时钟输入端,并行输出
sbit SHCP = P1^2;	//输入信号————上升沿有效 移位寄存器时钟输入端

sbit key1 = P3^0;	//选择键
sbit key2 = P3^1;	//加键
sbit key3 = P3^2;	//减键
sbit key4 = P3^3;

uchar shan,A,K,C,D,E,F;
uchar knum;		//选择键计数变量

void TimerInit();
void KeyScan();
void Display (uchar shi10,uchar shi,uchar fen10,uchar fen,uchar miao10,uchar miao);	// 数码管显示
void SMG_Int(uchar Dat);		// 数码管单字节串行移位函数

//*****************************************************************************
// 主程序
void main () 
{
	TimerInit();
	while(1)
	{
		Display (A,K,C,D,E,F);
		KeyScan();
	} 
}

void KeyScan()
{
	
}


void Display (uchar shi10,uchar shi,uchar fen10,uchar fen,uchar miao10,uchar miao)
{
	uchar i;

	//显示第1位	小时10位
	i = Table[shi10];

	SMG_Int(i);			
	SMG_Int(0x01);		

	STCP = 0;	 //数据并行输出,(借助上升沿)
	_nop_();
	_nop_();
	STCP = 1;

	//显示第2位	小时个位
	i = Table[shi];

	SMG_Int(i);		
	SMG_Int(0x02);		

	STCP = 0;
	_nop_();
	_nop_();
	STCP = 1;

	//显示第3位	-
	if(shan<10)	 //"-" 闪烁
	i = Table[16]; 
	else 
	i = Table[15];
	SMG_Int(i);			
	SMG_Int(0x04);	

	STCP = 0;
	_nop_();
	_nop_();
	STCP = 1;

	//显示第4位	分钟10位
	i = Table[fen10];

	SMG_Int(i);			
	SMG_Int(0x08);		

	STCP = 0;
	_nop_();
	_nop_();
	STCP = 1;

	//显示第5位	分钟个位
	i = Table[fen];

	SMG_Int(i);			
	SMG_Int(0x10);	

	STCP = 0;
	_nop_();
	_nop_();
	STCP = 1;

	//显示第6位	-
	if(shan<10)	   //"-" 闪烁
	i = Table[16];
	else 
	i = Table[15];

	SMG_Int(i);			
	SMG_Int(0x20);	

	STCP = 0;
	_nop_();
	_nop_();
	STCP = 1;

	//显示第7位	秒10位
	i = Table[miao10];

	SMG_Int(i);			
	SMG_Int(0x40);	

	STCP = 0;
	_nop_();
	_nop_();
	STCP = 1;

	//显示第8位	秒个位
	i = Table[miao];

	SMG_Int(i);		
	SMG_Int(0x80);	

	STCP = 0;
	_nop_();
	_nop_();
	STCP = 1;
}

void SMG_Int(uchar Dat)	 //通过8次循环将8位数据移入74HC595
{
	uchar i;
	for(i=8;i>=1;i--)
	{
		if (Dat & 0x80) 
		{
			SER = 1;
		} 
		
		else
		{ 
			SER = 0;
		}
		Dat <<= 1;
		SHCP = 0;
		_nop_();
		_nop_();
		SHCP = 1;
	}
}

void TimerInit()	 //定时器0初始化
{
	TMOD = 0x01;
	TH0 = (65536-50000)/256;	//50ms初值
	TL0 = (65536-50000)%256;
	EA = 1;
	ET0 = 1;
	TR0 = 1;

}

void Timer0() interrupt 1
{
	static uchar cnt,shi=12,fen=59,miao=30;
	
	TH0 = (65536-50000)/256;
	TL0 = (65536-50000)%256;
	
	shan++;
	if(shan==20)
		shan=0;

	cnt++;
	if(cnt==20)
	{
		cnt = 0;
		miao++;
		if(miao == 60)
		{
			miao = 0;
			fen++;
			if(fen==60)
			{
				fen = 0;
				shi++;
				if(shi==24)
				{
					shi=0;
				}
			}
		}
	}

	A=shi/10;
	K=shi%10;
	C=fen/10;
	D=fen%10;
	E=miao/10;
	F=miao%10;
}



It was modified from common anode, and the segment code table was changed, but the program displayed garbled characters, and some digital tubes did not display anything.

Can any experts please tell me how to solve this problem? Thank you

This post is from 51mcu

Latest reply

Let the segment selector output fully and see if all the digital tubes can light up.   Details Published on 2024-11-22 09:04
Personal signature为江山踏坏了乌骓马,为社稷拉断了宝雕弓。
 

6609

Posts

0

Resources
2
 

This program and hardware circuit need to be combined to find

This post is from 51mcu

Comments

Thanks, is there a problem with the hardware?  Details Published on 2024-11-22 08:30
 
 
 

3190

Posts

0

Resources
3
 
Jacktang posted on 2024-11-22 07:29 This program and the hardware circuit need to be combined to find

Thanks, is there a problem with the hardware?

This post is from 51mcu
 
Personal signature为江山踏坏了乌骓马,为社稷拉断了宝雕弓。
 
 

195

Posts

0

Resources
4
 

It is 8 8-digit display, one 595 is responsible for segment code, and one 595 is responsible for bit code. You write all the combinations on paper, and display them one by one from 0 to 9 in the program, add a long delay in between, and then you can find the problem. However, the bit code 595 is not driven by a transistor, so I don’t know if it can drive the current of 7 segments to light up.

This post is from 51mcu
 
 
 

6788

Posts

2

Resources
5
 

Let the segment selector output fully and see if all the digital tubes can light up.

This post is from 51mcu
 
 
 

3190

Posts

0

Resources
6
 

Thanks, I'll try it back.

This post is from 51mcu
 
Personal signature为江山踏坏了乌骓马,为社稷拉断了宝雕弓。
 
 

3190

Posts

0

Resources
7
 

I have another question. I have two 595s driving digital tubes. Are the segment and bit selections mixed up? Thanks.

This post is from 51mcu
 
Personal signature为江山踏坏了乌骓马,为社稷拉断了宝雕弓。
 
 

3190

Posts

0

Resources
8
 

2.jpg (184.04 KB, downloads: 0)

2.jpg
This post is from 51mcu
 
Personal signature为江山踏坏了乌骓马,为社稷拉断了宝雕弓。
 
 

3190

Posts

0

Resources
9
 

Another question, the position selection does not need to be changed, right?

This post is from 51mcu
 
Personal signature为江山踏坏了乌骓马,为社稷拉断了宝雕弓。
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews

Room 1530, Zhongguancun MOOC Times Building, Block B, 18 Zhongguancun Street, Haidian District, Beijing 100190, China Tel:(010)82350740 Postcode:100190

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list