标题: 单片机大佬们数码管和点阵怎么同时工作? [打印本页]
作者: hpf 时间: 2018-11-17 21:53
标题: 单片机大佬们数码管和点阵怎么同时工作?
大佬们,我是想让数码管显示2018,点阵显示0--9,请大佬们指教我该怎么改正
#include<reg51.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
//uchar code DSY_CODE[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uchar code DSY_CODE[]={0xa4,0xc0,0xf9,0x80};
uchar code wei[]={0x80,0x40,0x20,0x10};
unsigned char const xuehao[]={
0x00,0x00,0xFE,0x82,0x82,0x82,0xFE,0x00, //0
0x00,0x00,0x84,0x82,0xFF,0x80,0x80,0x00, //1
0x00,0x00,0xF2,0x92,0x92,0x92,0x9E,0x00, //2
0x00,0x00,0x92,0x92,0x92,0xFE,0x00,0x00, //3
0x00,0x20,0x30,0x28,0x24,0xFE,0x20,0x00, //4
0x00,0x00,0x9E,0x92,0x92,0x92,0xF2,0x00, //5
0x00,0x00,0xFE,0x92,0x92,0x92,0xF2,0x00, //6
0x00,0x00,0x00,0x02,0x02,0x02,0xFE,0x00, //7
0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00, //8
0x00,0x32,0x49,0x49,0x49,0x3e,0x00,0x00 //9
};
unsigned char code lie[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
void DelayMS(uint x)
{
uchar t;
while(x--) for(t=0;t<120;t++);
}
void Timer1Init()
{
TMOD|=0X10;//选择为定时器1模式,工作方式1,仅用TR1打开启动。
TH1=0XFC; //给定时器赋初值,定时1ms
TL1=0X18;
ET1=1;//打开定时器1中断允许
EA=1;//打开总中断
TR1=1;//打开定时器
}
void main()
{
uchar i;
while(1)
{
for(i=0;i<4;i++)
{
P3=0x00; //关闭显示
P1=DSY_CODE[ i]; //发送数字段码
P3=wei[ i];
DelayMS(10);
}
Timer1Init(); //定时器1初始化
}
}
void Timer1() interrupt 3
{
uchar t,j,k;
TH1=0XFC; //给定时器赋初值,定时1ms
TL1=0X18;
for(t=0;t<10;t++)
{
for(j=0;j<30;j++)
{
for(k=0;k<8;k++)
{
P2=lie[k];
P0=~xuehao[t*8+k];
DelayMS(2);
}
}
}
}
作者: angmall 时间: 2018-11-18 09:45
你的程序有缺陷,给你改了一下,你试试。
- #include <reg51.h>
- #include<intrins.h>
- #define uchar unsigned char
- #define uint unsigned int
- //uchar code DSY_CODE[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
- uchar code DSY_CODE[]={0xa4,0xc0,0xf9,0x80};
- uchar code wei[]={0x80,0x40,0x20,0x10};
- unsigned char const xuehao[]={
- 0x00,0x00,0xFE,0x82,0x82,0x82,0xFE,0x00, //0
- 0x00,0x00,0x84,0x82,0xFF,0x80,0x80,0x00, //1
- 0x00,0x00,0xF2,0x92,0x92,0x92,0x9E,0x00, //2
- 0x00,0x00,0x92,0x92,0x92,0xFE,0x00,0x00, //3
- 0x00,0x20,0x30,0x28,0x24,0xFE,0x20,0x00, //4
- 0x00,0x00,0x9E,0x92,0x92,0x92,0xF2,0x00, //5
- 0x00,0x00,0xFE,0x92,0x92,0x92,0xF2,0x00, //6
- 0x00,0x00,0x00,0x02,0x02,0x02,0xFE,0x00, //7
- 0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00, //8
- 0x00,0x32,0x49,0x49,0x49,0x3e,0x00,0x00 //9
- };
- unsigned char code lie[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
- void DelayMS(uint x)
- {
- uchar t;
- while(x--) for(t=0;t<120;t++);
- }
- /*
- void Timer1Init()
- {
- TMOD|=0X10;//选择为定时器1模式,工作方式1,仅用TR1打开启动。
- TH1=0XFC; //给定时器赋初值,定时1ms
- TL1=0X18;
- ET1=1;//打开定时器1中断允许
- EA=1;//打开总中断
- TR1=1;//打开定时器
- }
- */
- void main()
- {
- uchar i;
- uchar t,j,k;
- //Timer1Init(); //定时器1初始化
- while(1)
- {
- //for(i=0;i<4;i++)
- //{
- // DelayMS(10);
- //}
- for(t=0;t<10;t++)
- {
- for(j=0;j<30;j++)
- {
- for(k=0;k<8;k++)
- {
- P2=lie[k];
- P0=~xuehao[t*8+k];
- DelayMS(2);
- P3=0x00; //关闭显示
- P1=DSY_CODE[ k/2]; //发送数字段码
- P3=wei[ k/2];
- }
- }
- }
- }
- }
- /*
- void Timer1() interrupt 3
- {
- TH1=0XFC; //给定时器赋初值,定时1ms
- TL1=0X18;
- }
- */
复制代码
作者: hpf 时间: 2018-11-18 16:31
非常感谢师兄,仿真后没有问题
欢迎光临 (http://www.51hei.com/bbs/) |
Powered by Discuz! X3.1 |