共2条
1/1 1 跳转至页
LED LED显示摇棒全套方案及源程序--读后感
问
*************************************************************************/
// ---------------
// LED显示摇棒
// ---------------
// 作者:nim 于 http://www.21icbbs.com 2005-1-7
//
// email: linyige@yahoo.com
//
// 本设计版权归作者所有,请勿擅自用于商业目的,转载请注明作者及出处
/*************************************************************************/
#include <reg51.h>
#define SEG 17 //每帧图片分成17列来显示
#define INTERVAL 20 //每幅图片在左右摇摆20次后换下一幅
typedef unsigned char uchar;
typedef unsigned int uint;
code char pattern[17][3]={ //3幅图片的字模
{0xff,0xff,0xff},
{0xff,0xff,0xff},
{0xff,0xff,0xff},
{0xff,0x9f,0xff},
{0xff,0x6f,0xf9},
{0xff,0x77,0x65},
{0xfe,0xbb,0x1e},
{0x7e,0xdd,0xfe},
{0x00,0xee,0xfe},
{0x7e,0xdd,0xfe},
{0xfe,0xbb,0x1e},
{0xff,0x77,0x65},
{0xff,0x6f,0xf9},
{0xff,0x9f,0xff},
{0xff,0xff,0xff},
{0xff,0xff,0xff},
{0xff,0xff,0xff},
};
uchar phase,th1,tl1,index,count;
main()
{
EA=0;
EX0=1;
ET1=1;
PX0=1;
IT0=1;
TMOD=0x11;
index=0;
EA=1;
while(1)
{
}
}
void Int0_Handle(void) interrupt 0 using 2
{
uint t0_time;
TR0=0;
TR1=0;
TF1=0;
t0_time=TH0<<8|TL0;
TL0=0;
TH0=0;
TR0=1;
t0_time=65535-t0_time/SEG;
th1=t0_time/256;
TH1=th1;
tl1=t0_time % 256;
TL1=tl1;
if (count<3*INTERVAL){ //3幅图片循环
count++;
}
else{
count=0;
}
index=count/INTERVAL;
if (th1!=0xff || tl1!=0xff){ //如果摆动特别慢,定时器溢出就不显示
phase=0;
TR1=1;
}
else{
TR1=0;
}
}
void Timer1(void) interrupt 3 using 3
{
if (phase<SEG) //17段依次显示
{
P1=pattern[phase][index];
phase++;
TH1=th1;
TL1=tl1;
}
}
一直没弄明白如何用定时器0计算两次外部中断的间隔的摇摆时间的?
答 1: 顶!2051中的定时器/计数器0的初值如何赋值的,事先并不知道摇摆一次所需的时间啊!而timer/counter0工作必须先赋值进去(是由2051是步增的,溢出产生中断的)
// ---------------
// LED显示摇棒
// ---------------
// 作者:nim 于 http://www.21icbbs.com 2005-1-7
//
// email: linyige@yahoo.com
//
// 本设计版权归作者所有,请勿擅自用于商业目的,转载请注明作者及出处
/*************************************************************************/
#include <reg51.h>
#define SEG 17 //每帧图片分成17列来显示
#define INTERVAL 20 //每幅图片在左右摇摆20次后换下一幅
typedef unsigned char uchar;
typedef unsigned int uint;
code char pattern[17][3]={ //3幅图片的字模
{0xff,0xff,0xff},
{0xff,0xff,0xff},
{0xff,0xff,0xff},
{0xff,0x9f,0xff},
{0xff,0x6f,0xf9},
{0xff,0x77,0x65},
{0xfe,0xbb,0x1e},
{0x7e,0xdd,0xfe},
{0x00,0xee,0xfe},
{0x7e,0xdd,0xfe},
{0xfe,0xbb,0x1e},
{0xff,0x77,0x65},
{0xff,0x6f,0xf9},
{0xff,0x9f,0xff},
{0xff,0xff,0xff},
{0xff,0xff,0xff},
{0xff,0xff,0xff},
};
uchar phase,th1,tl1,index,count;
main()
{
EA=0;
EX0=1;
ET1=1;
PX0=1;
IT0=1;
TMOD=0x11;
index=0;
EA=1;
while(1)
{
}
}
void Int0_Handle(void) interrupt 0 using 2
{
uint t0_time;
TR0=0;
TR1=0;
TF1=0;
t0_time=TH0<<8|TL0;
TL0=0;
TH0=0;
TR0=1;
t0_time=65535-t0_time/SEG;
th1=t0_time/256;
TH1=th1;
tl1=t0_time % 256;
TL1=tl1;
if (count<3*INTERVAL){ //3幅图片循环
count++;
}
else{
count=0;
}
index=count/INTERVAL;
if (th1!=0xff || tl1!=0xff){ //如果摆动特别慢,定时器溢出就不显示
phase=0;
TR1=1;
}
else{
TR1=0;
}
}
void Timer1(void) interrupt 3 using 3
{
if (phase<SEG) //17段依次显示
{
P1=pattern[phase][index];
phase++;
TH1=th1;
TL1=tl1;
}
}
一直没弄明白如何用定时器0计算两次外部中断的间隔的摇摆时间的?
答 1: 顶!2051中的定时器/计数器0的初值如何赋值的,事先并不知道摇摆一次所需的时间啊!而timer/counter0工作必须先赋值进去(是由2051是步增的,溢出产生中断的)
共2条
1/1 1 跳转至页
回复
| 有奖活动 | |
|---|---|
| 硬核工程师专属补给计划——填盲盒 | |
| “我踩过的那些坑”主题活动——第002期 | |
| 【EEPW电子工程师创研计划】技术变现通道已开启~ | |
| 发原创文章 【每月瓜分千元赏金 凭实力攒钱买好礼~】 | |
| 【EEPW在线】E起听工程师的声音! | |
| 高校联络员开始招募啦!有惊喜!! | |
| 【工程师专属福利】每天30秒,积分轻松拿!EEPW宠粉打卡计划启动! | |
| 送您一块开发板,2025年“我要开发板活动”又开始了! | |
我要赚赏金
