本文仅记录我自己瞎搞的东西,自己当做笔记看,如果偶然间您看到了本文,希望能博您一笑。
我是菜逼!我是菜逼!我是菜逼!
我的单片机长这样:
![f18eac773d7094c6fa717aa714d30c06.png](https://i-blog.csdnimg.cn/blog_migrate/1bfca124183ea81449318dced2db8201.jpeg)
(我也不知道为啥他为啥传上来就斜了)
![0c0eef40ac484e237e5b5885bef3d5b6.png](https://i-blog.csdnimg.cn/blog_migrate/e4eb6852a4f42191ce284ca1a0d50e4b.jpeg)
我初步写的程序:
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit C573 = P2^5; //控制数码管芯片开启
uchar times = 0; //计数器轮数
uint time = 30; //初步定义倒计时30秒
code uchar letter[] = {
0xc0,0xf9,0xa4,0xb0,
0x99,0x92,0x82,0xf8,
0x80,0x90,0x88,0x83,
0xc6,0xa1,0x86,0x8e};
/* 0 , 1 , 2 , 3 ,
4 , 5 , 6 , 7 ,
8 , 9 , a , b ,
c , d , e , f , */
code uchar local[] = {
1 ,0xfe,0xfd,0xfb,0xf7};
//数码管位 占位,左1,左2,左3,左4
void Clock1(); //计时1s
void T0reset();
//uint Alltime( uint time ); //总时间(以后再写)
void Output( uint temp ); //显示输出当前时间
void delay( uint ); //延时函数
void main()
{
while(1)
{
while(time)
{
Output(time); //显示时间
Clock1(); //计时1秒
time--; //时间-1秒
}
}
}
void Clock1()
{
times = 14;
while(times)
{
if(TF0 == 1)
{
T0reset();
times--;
}
}
}
void T0reset()
{
TMOD = 0x01;
TH0 = 0;
TL0 = 0;
TF0 = 0;
TR0 = 1;
}
void delay( uint temp )
{
while(temp--);
}
void Output( uint temp )
{
C573 = 1;
if(time > 9)
{
while(1)
{
P2 = local[3];
P0 = letter[time/10];
delay(200);
P0