本文目录一览:
- 1、使用Python,实现程序运行计时的数码管表示
- 2、用for语句使数码管动态显示
- 3、怎么实现数码管动态动态扫描显示(同时显示不同的数字)?以下程序只能一次显示一个数字。
- 4、Python七段数码管绘制的文字步骤,请问哪位大佬能简单说一下。是要文字版的,不需要写代码的?
- 5、数码管的动态显示问题,是共阳极的,在仿真的时候只有一个正常显示
使用Python,实现程序运行计时的数码管表示
用python实现计时器功能,代码如下:
”’ Simple Timing Function.
This function prints out a message with the elapsed time from the
previous call. It works with most Python 2.x platforms. The function
uses a simple trick to store a persistent variable (clock) without
using a global variable.
”’
import time
def dur( op=None, clock=[time.time()] ):
if op != None:
duration = time.time() – clock[0]
print ‘%s finished. Duration %.6f seconds.’ % (op, duration)
clock[0] = time.time()
# Example
if __name__ == ‘__main__’:
import array
dur() # Initialise the timing clock
opt1 = array.array(‘H’)
for i in range(1000):
for n in range(1000):
opt1.append(n)
dur(‘Array from append’)
opt2 = array.array(‘H’)
seq = range(1000)
for i in range(1000):
opt2.extend(seq)
dur(‘Array from list extend’)
opt3 = array.array(‘H’)
seq = array.array(‘H’, range(1000))
for i in range(1000):
opt3.extend(seq)
dur(‘Array from array extend’)
# Output:
# Array from append finished. Duration 0.175320 seconds.
# Array from list extend finished. Duration 0.068974 seconds.
# Array from array extend finished. Duration 0.001394 seconds.
用for语句使数码管动态显示
数码管动态显示程序,本就应该用for循环语句写,那些一位一位地显示的程序,太不规范啦,程序显得很长,很乱的。
如下的仿真图,是8位数码管,就得用for循环语句写,程序很简单,很简洁。
程序如下
#includereg52.h
#includeintrins.h
unsigned char code ledtab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,
0x77,0x7c,0x39,0x5e,0x79,0x71};//共阴数码管段码表
unsigned char buffer[]={1,2,3,4,5,6,7,8};
void delay()
{
unsigned int j;
for(j=400;j0;j–);
}
void display()
{
unsigned char i,ledbit=0xfe;
for(i=0;i8;i++)
{
P2=ledbit; //先输出位码
P0=ledtab[buffer[i]];//后输出段码
ledbit=_crol_(ledbit,1);
delay();
}
}
void main()
{
while(1)
{
display();
}
}
怎么实现数码管动态动态扫描显示(同时显示不同的数字)?以下程序只能一次显示一个数字。
很容易,首先假如我们有6位数码管,每位数码管需要8个段选1个公共选通端, 那么6位数码管自然是8位端选信号 6位选通信号(分别选通1-6其中的一个数码管)
#define SMG_WEI P0 //P1.0 -P1.5 分别驱动数码管选通
#define SMG_DUAN P1 //P1.0 -P1.7接数码管8个段选
unsigned char smgcode[]={x,x,x,x,x,x,x,x,x,x} //对应数码管0-9的值,实际根据段信号确定
void Delay(unsigned long w)
{
while(w–);
}
void DisPlay(unsigned char s1,unsigned char s2,unsigned char s3,unsigned char s4,unsigned char s5,unsigned char s6) //s1 -s6表示1-6的数码管需要显示的数字
{
SMG_WEI =0x01 //第1个数码管选通 000001
SMG_DUAN =smgcode[s1]; //如s1传入1表示要显示1,那么直接调用数组偏移量为1的值,显示1
Delay(100); //延时一段时间消影
SMG_WEI =0x02 //第2个数码管选通 000010
SMG_DUAN =smgcode[s2]; //如s2传入2表示要显示2,那么直接调用数组偏移量为2的值,显示2
Delay(100); //延时一段时间消影
S3 /////
S4 /////
S5 //////
SMG_WEI =0x20 //第6个数码管选通 100000
SMG_DUAN =smgcode[s6]; //如s6传入6表示要显示6,那么直接调用数组偏移量为6的值,显示6
Delay(100); //延时一段时间消影
SMG_WEI =0;
SMG_DUAN =0; //清除显示,保证每位数码管亮度一致
}
void main()
{
while(1)
{
DisPlay(1,2,3,4,5,6);//数码管显示 1 2 3 4 5 6
}
}
Python七段数码管绘制的文字步骤,请问哪位大佬能简单说一下。是要文字版的,不需要写代码的?
绘制七段数码管需要用到turtle绘图体系。
基本思路是:1、绘制单个数字对应的数码管。2、获得一串数字绘制对应的数码管。
具体操作:步骤1、绘制单个数码管:顾名思义,七段数码管是由7段基本线条组成的,不同的数字显示不同的线条,并且数码管可以有固定的顺序;编写程序时,可以先定义画单段数码管的函数,再定义根据数字绘制七段数码管的函数,利用if语句,根据数字调用单段数码管函数进行绘制。步骤2,获得要输出的数字,利用eval()函数将数字变为整数,调用根据数字绘制七段数码管的函数进行绘制。
总结:1、对七段数码进行分析,整理思路。根据数字绘制七段数码管时,用到哪一段基本线条就把哪一段绘制出来。
七段数码管
2、利用到的知识点:turtle库、函数、if语句、eval()函数
数码管的动态显示问题,是共阳极的,在仿真的时候只有一个正常显示
中断里动态点亮数码管的程序有错误,如下:
P1_0=0;P1_1=1;
P0=dispcode[second/10];
P1_0=1;P1_1=0;
P0=dispcode[second%10];
点亮第一位后接着灭掉第一位、点亮第二位,由于时间太快,而且中断时间太长,所以第一位点亮就看不到了,而只能看到第二位的数字了,也就是dispcode[second%10]对应的数码管。修改一下程序应该是这样的:
#include reg51.h
sbit P1_0=P1^0;
sbit P1_1=P1^1;
unsigned char code dispcode[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
volatile unsigned char second; //告诉编译器不要优化变量,具体用法百度一下
unsigned char tcount;
//短暂延时
void delay(char x)
{
char i,j;
for(i=0;ix;i++)
for(j=0;j200;j++);
}
void main(void)
{
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TR0=1;
ET0=1;
EA=1;
tcount=0;
second=0;
while(1)
{
P1_0=0;P1_1=1;
P0=dispcode[second/10];
delay(2); //x的值自己试试,只要能正常显示就行
P1_0=1;P1_1=0;
P0=dispcode[second%10];
delay(2);
}
}
void t0(void) interrupt 1 using 0
{
tcount++;
if(tcount==20)
{
tcount=0;
second++;
if(second==60)
{
second=0;
}
}
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TR0=1;
}
原创文章,作者:小蓝,如若转载,请注明出处:https://www.506064.com/n/291680.html