#include
code unsigned char tab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
unsigned char dis_shiwei;
unsigned char dis_gewei;
void delay(unsigned int cnt)
{
while(--cnt);
}
main()
{
tmod |=0x01; //10ms in 12m crystal,工作在模式一,16位定时器
th0=0xd8;
tl0=0xf0;
ie= 0x82; //打开中断
tr0=1; //打开定时开关
while(1)
{
p0=dis_shiwei;
p2=0;
delay(300);
p0=dis_gewei;
p2=1;
delay(300);
}
}
void tim(void) interrupt 1 using 1
{
static unsigned char second,count;
th0=0xd8;
tl0=0xf0;
count++;
if (count==100) //100x10ms
{
count=0;
second++;
if(second==100)
second=0;
dis_shiwei=tab[second/10];
dis_gewei=tab[second%10];
}
}
/*
定时器设定为:th0=0xd8;tl0=0xf0;经确定时10ms。从程序开始执行,每当主程序中的16位数发生溢出则触发中断,主程序保护现场并调用中断子程序,也可以写为:th0=(65536-10000)/256;tl0=(65536-10000)%256。秒脉冲的产生要求精确定时1s,实际情况可能有延误。
1 0000 0000 0000 0000
1101 1000 1111 0000
————————————
0010 0111 0001 0000
time=16(1+16+32+64+512)=16*625=10000us=10ms
主函数中的关于定时器和中断的控制位:
tmod |=0x01; //模式选择
th0=0xd8; //高8位
tl0=0xf0; //低8位
ie= 0x82; //打开中断
tr0=1; //打开定时开关(定时器运行控制位,置“1”启动定时器0)
tmod |= 0x01; //使用模式1,16位定时器
th0=0x00;
tl0=0x00;
ea=1; //总中断打开
et0=1; //定时器中断打开
tr0=1; //定时器开关打开
*/
______________________________________________
功能:99秒倒计时
时间:2010—7—18
______________________________________________
#include
code unsigned char tab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
unsigned char dis_shiwei;
unsigned char dis_gewei;
void delay(unsigned int cnt)
{
while(--cnt);
}
main()
{
tmod |=0x01; //10ms in 12m crystal
th0=0xd8;
tl0=0xf0;
ie= 0x82;
tr0=1;
while(1)
{
p0=dis_shiwei;
p2=0;
delay(300);
p0=dis_gewei;
p2=1;
delay(300);
}
}
void tim(void) interrupt 1 using 1
{
static unsigned char second=99,count;
th0=0xd8;
tl0=0xf0;
count++;
if (count==100)
{
count=0;
second--;
if(second==0)
{
second=99;
}
dis_shiwei=tab[second/10];
dis_gewei=tab[second%10];
复杂应用中运用人工智能核心 强化学习
彻底曝光 这就是今晚将发布的旗舰三星S8
PLC的DI端口抗干扰电路设计方案
这个技术,改善你的电源系统设计!
重力感应器BMA250源代码执行分析
中断触发定时器:99秒计时+99秒倒计时
如何可以对芯片开路点进行定位
AR/VR:呈现在眼前的另一个世界
华为云数字化制品仓,引领企业智能化转型之路
RFID具备怎样独特的优势
未命名的英特尔Rocket Lake处理器基准测试泄露
示波器测时钟会有什么样的变化
关于18650电池以及21700电池概念及其优势详解
NI携手清华,成功举办京津地区虚拟仪器设计邀请赛
用于提供负输出的 60V、4A 同步降压型稳压器
如何防止PoE接口应用差分模式的瞬态电压威胁
华为P50系列即将准备进入量产,首发搭载液态镜头和全新的鸿蒙系统
物联网网关有什么作用,如何工作?
一加5正式发布,明天开卖!2999元买一加5还是买小米6?
3G视频需看ISP脸色