当前位置 博文首页 > zbossz的博客:数码管表白(投稿用)
数码管表白
现在我们设想一个程序:
首先,我们让流水灯一个一个流,然后双向奔赴,到一定程度,全闪。就像感情,只有经过细水长流,双向奔赴,才能开花结果。
接下来,我们让数码管显示520 1314.YU,I CAN By YOUR SIDE FOREVER ,I LOVE YOU 。
我们先让它们一个一个显示出来,最终一句话就全体闪烁一下,最终到I LOVE YOU 的部分,我们就一直闪烁,和LED一起闪烁。
那么,我们开始逐步分析吧:
数字部分是肯定能显示出来的,所以我们研究字母部分就行了
这是大概的情况,虽然我们是沉迷于技术学习的孩子,但是,我们心里时时刻刻都想着对象,你们说是吧!赶紧自己设计一段话,设计好排版,考虑在目前这只有8个数码管的小板子上,表达对你女朋友的爱意吧!当然,你还可以考虑加入蜂鸣器的版本,就是让蜂鸣器唱歌,众所周知,振动是发声的来源,所以,蜂鸣器不同的振动频率和延时效果可以让单片机唱歌,阴乐不分高低!我不会!
好嘞,开始编想程序吧!
我们可以考虑把字母的码子,先搞出来:
好嘞!字母搞出来了!
现在开始把需要的2个定时器都设定好,主程序框架也设定好:
这是我们用到的中断
先 主框架:
#include <STC15F2K60S2.H>
#define uchar unsigned char
#define uint unsigned int
uchar t0,t1;
unsigned int code list[]={0xc0,0xf9,0x24,0x30,
0x19,0x12,0x02,0xf8,
0x00,0x10,0x08,0x03,
0x46,0x21,0x06,0x0e};
void time0() interrupt 1
{
TH0 = (65536-50000)/256;
TL0 = (65536-50000)%256;
t0 +=1;
}
void time1() interrupt 3
{
TH0 = (65536-50000)/256;
TL0 = (65536-50000)%256;
t1 +=1;
}
void delay(uint k)
{
uint i = 0;
uint j = 0;
for(i=700;i>0;i--)
{
for(j=0;j<k;j++)
{
;
}
}
}
void initAll()
{
TMOD = 0x00;
TH0 = (65536 - 50000)/256;
TL0 = (65536 - 50000)%256;
TH1 = (65536 - 50000)/256;
TL1 = (65536 - 50000)%256;
EA = 1;
ET0 = 1;
ET1 = 1;
TR0 = 1;
TR1 = 1;
}
void display()
{
}
void main(void)
{
initAll();
while(1)
{
}
}
接下来我们完善整个函数,根据自己想要的情形
我觉得520 1314 太土了,就没用了,加了别的
#include <STC15F2K60S2.H>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
uchar t0,t1,wei,duan,flag1;
uchar oled1 = 0xfe;
uchar oled2 = 0x7f;
unsigned int code list[]={0xc0,0xf9,0x24,0x30,
0x19,0x12,0x02,0xf8,
0x00,0x10,0x08,0x03,
0x46,0x21,0x06,0x0e};
void time0() interrupt 1
{
TH0 = (65536-50000)/256;
TL0 = (65536-50000)%256;
t0 +=1;
}
void time1() interrupt 3
{
TH0 = (65536-50000)/256;
TL0 = (65536-50000)%256;
t1 +=1;
}
void delay(uint k)
{
uint i = 0;
uint j = 0;
for(i=700;i>0;i--)
{
for(j=0;j<k;j++)
{
;
}
}
}
void InitAll()
{
TMOD = 0x00;
TH0 = (65536 - 50000)/256;
TL0 = (65536 - 50000)%256;
TH1 = (65536 - 50000)/256;
TL1 = (65536 - 50000)%256;
EA = 1;
ET0 = 1;
ET1 = 1;
TR0 = 1;
TR1 = 1;
}
//void DisplayLed1()
//{
// again:
// if(flag1 != 8)
// {
// flag1 += 1;
// P2=((P2&0x1f)|0x80);
// P0=oled1;
// P2 &= 0x1f;
// oled1 = _crol_(oled1,1);
// t0 = 0;
// goto again;
// }
// else
// {
// P2=((P2&0x1f)|0x80);
// P0=0x00;
// P2 &= 0x1f;
// delay(100);
// P2=((P2&0x1f)|0x80);
// P0=0xff;
// P2 &= 0x1f;
// delay(100);
// P2=((P2&0x1f)|0x80);
// P0=0x00;
// P2 &= 0x1f;
// }
//}
//void DisplayLed2()
//{
// oled2 = 0x7f;
// P2=((P2&0x1f)|0x80);
// P0=oled2;
// P2 &= 0x1f;
// oled2 = _cror_(oled2,1);
continue....
//}
//void DisplaySmg1()
//{
// wei = 0x01,
5
// P2=((P2&0x1f)|0xc0);
// P0=wei;
// P2 &= 0x1f;
// P2=((P2&0x1f)|0xe0);
// P0=list[5];
// P2 &= 0x1f;
// delay(500);
2
// wei<<=1;
// P2=((P2&0x1f)|0xc0);
// P0=wei;
// P2 &= 0x1f;
// P2=((P2&0x1f)|0xe0);
// P0=list[2];
// P2 &= 0x1f;
// delay(500);
0
// wei<<=1;
// P2=((P2&0x1f)|0xc0);
// P0=wei;
// P2 &= 0x1f;
// P2=((P2&0x1f)|0xe0);
// P0=list[0];
// P2 &= 0x1f;
// delay(500);
1
// wei<<=2;
// P2=((P2&0x1f)|0xc0);
// P0=wei;
// P2 &= 0x1f;
// P2=((P2&0x1f)|0xe0);
// P0=list[1];
// P2 &= 0x1f;
// delay(500);
3
// wei<<=1;
// P2=((P2&0x1f)|0xc0);
// P0=wei;
// P2 &= 0x1f;
// P2=((P2&0x1f)|0xe0);
// P0=list[3];
// P2 &= 0x1f;
// delay(500);
1
// wei<<=1;
// P2=((P2&0x1f)|0xc0);
// P0=wei;
// P2 &= 0x1f;
// P2=((P2&0x1f)|0xe0);
// P0=list[1];
// P2 &= 0x1f;
// delay(500);
4
// wei<<=1;
// P2=((P2&0x1f)|0xc0);
// P0=wei;
// P2 &= 0x1f;
// P2=((P2&0x1f)|0xe0);
// P0=list[4];
// P2 &= 0x1f;
// delay(500);
//}
void DisplaySmg2()
{
wei = 0x01,
//y
P2=((P2&0x1f)|0xc0);
P0=wei;
P2 &= 0x1f;
P2=((P2&0x1f)|0xe0);
P0=0x91;
P2 &= 0x1f;
delay(500);
//u
wei<<=1;
P2=((P2&0x1f)|0xc0);
P0=wei;
P2 &= 0x1f;
P2=((P2&0x1f)|0xe0);
P0=0xc1;
P2 &= 0x1f;
delay(500);
//i
wei<<=2;
P2=((P2&0x1f)|0xc0);
P0=wei;
P2 &=