历史上的今天
今天是:2025年12月26日(星期五)
2022年12月26日 | 定时器功能演示程序
2022-12-26 来源:zhihu
#include #include //sbit led1=P1^0; //sbit led2=P1^1; //sbit led3=P1^2; //sbit led4=P1^3; unsigned char count; unsigned char direction; unsigned char delay1; unsigned char delay2; void timer0(void) interrupt 1 using 0 { TL0=0x06; TH0=delay2; /* 定时器0中断 */ if (++delay1 > 4){ delay1 = 0; if (++count > 3) count = 0; P1 |= 0x0f; P1 &= ~(0x01 << count); } /* 定时器0中断 */ } void timer1(void) interrupt 3 using 0 { TL1=0x06; TH1=0x00; /* 定时器1中断 */ if (direction){ if (++delay2 == 255)direction = 0; } else { if (--delay2 == 0)direction = 1; } /* 定时器1中断 */ } void serial() interrupt 4 using 3 { } // 定时器功能演示程序 // P01、P02、P03、P04脚接发光二极管led1、led2、led3、led4 // 每个发光二极管串上电阻接到5V电源上, 运行本演示程序 // 将会看到发光二极管被依次点亮和熄灭, 比街上的彩灯好看 // 多了,不信你试试看。 void main(void){ EA = 1; /* 开总中断 */ ET0 = 1; /* 允许定时器0中断 */ ET1 = 1; /* 允许定时器1中断 */ TMOD = 0x11; /* 定时器工作方式选择 */ TL0 = 0x06; TH0 = 0x00; /* 定时器赋予初值 */ TL1 = 0x06; TH1 = 0x00; /* 定时器赋予初值 */ TR0 = 1; /* 启动定时器 */ TR1 = 1; /* 启动定时器 */ delay2 = 0; direction = 1; while(1){ _nop_ (); /* delay for hardware */ } }
上一篇:单片机定时器0、1演示程序
下一篇:6通道dmx512控制器程序
史海拾趣
|
我看中了两款开发板 TQ2440 和 mini2440 下面是链接 http://item.taobao.com/item.htm?id=3727179227 http://item.taobao.com/item.htm?id=2190406747 学习用,不知道这两款哪个更好一些 谁帮忙看下… 查看全部问答> |
|
最近读STM32手册定时器部分, The auto-reload register is preloaded. Writing to or reading from the auto-reload register accesses the preload register. The content of the preload register are transferred into the shadow regist ...… 查看全部问答> |
|
1、“综合测评”测试对象为赛区推荐上报全国评奖的优秀参赛队全体队员,并在各赛区以封闭方式进行。测试题目与评分标准由全国专家组负责统一制定,并委托各赛区在当地组织,赛区专家组完成相应测试工作。全国专家组将排遣专家参加综合测评。 2、 ...… 查看全部问答> |
|
我这个是用LaunchPad驱动HT1621B型芯片,从而达到控制段式液晶,至于段式液晶屏,一定是3V地。 有图有真象先上图先: 段显显示: 我是用线搭的,DATA、WR、CS、接P1的0、1、2、 上程序: 此程序 ...… 查看全部问答> |
|
小弟初学,按照教程步骤来的。 1,新建工程,file-new-project 2,加入文件,add to project-existing file 3,编译文件,compile-compile all 显示编译成功,compile of xxx.v is successful. 4,在library选项卡 ...… 查看全部问答> |




