#include <STC90C5xAD.H> unsigned int t; unsigned char keynum; void Timer0Init(void) { t=2000; AUXR &= 0x7F; TMOD &= 0xF0; TMOD |= 0x01; TL0 = (65536-t)%256; TH0 = (65536-t)/256; TF0 = 0; TR0 = 1; EA=1; ET0=1; PT0=1; } void Delay(unsigned int xms) { while(xms--) { unsigned char i, j; i = 2; j = 239; do { while (--j); } while (--i); } } unsigned char key() { unsigned char keynumber=0; if(P20==0){Delay(20);while(P20==0);Delay(20);keynumber=1;} if(P21==0){Delay(20);while(P21==0);Delay(20);keynumber=2;} if(P22==0){Delay(20);while(P22==0);Delay(20);keynumber=3;} if(P23==0){Delay(20);while(P23==0);Delay(20);keynumber=4;} return keynumber; } void main() { Timer0Init(); while(1) { keynum=key(); if(keynum) { if(keynum==1) { t+=200; } if(keynum==2) { t-=200; } } } } void Timer0_countine() interrupt 1 { static unsigned int T0count; TL0 = (65536-t)%256; TH0 = (65536-t)/256; T0count++; if(T0count>=500) { T0count=0; P00=~P00; if(keynum==1) { t+=200; } if(keynum==2) { t-=100; } } }
时间: 2024-03-03 10:52:24 浏览: 32
这段代码是STC90C5xAD单片机的程序。它使用了定时器0和外部按键来控制定时器的计数值。程序中的Timer0Init函数用来初始化定时器0的工作模式和计数值,Delay函数用来实现简单的延时功能,key函数用来检测外部按键状态并返回按键编号,main函数中不断循环检测按键状态并根据按键编号修改计数器的值,Timer0_countine函数则是定时器0的中断处理函数,每隔一段时间就会执行一次,根据计数器的值来控制LED的闪烁频率。
相关问题
#include<STC89C5xRC.H> #define u8 unsigned char #define u16 unsigned int #define key1 P22 #define ke
`#include<STC89C5xRC.H>` 是 Keil C51 编译器中的头文件,该头文件包含了 STC89C5xRC 芯片的寄存器定义和函数库等信息。
`#define u8 unsigned char` 和 `#define u16 unsigned int` 分别定义了无符号 8 位和 16 位整型数据类型。
`key1 P22` 和 `key2 P23` 分别将 P22 和 P23 引脚命名为 key1 和 key2。
根据您提供的信息,代码没有完成,后面的部分被截断了,请问您还有其他问题或信息需要补充吗?
#include<STC89C5xRC.H> #define u8 unsigned char #define u16 unsigned int #define key1 P22 #define key2 P23 u8 pl=2;
`#include<STC89C5xRC.H>` 是单片机开发中常用的头文件,其作用是定义了单片机的寄存器地址和对应的位。同时,该头文件还包含了一些常用的函数和宏定义。
`#define u8 unsigned char` 宏定义了 `u8` 为无符号字符型,相当于 `unsigned char`。
`#define u16 unsigned int` 宏定义了 `u16` 为无符号整型,相当于 `unsigned int`。
`key1` 和 `key2` 宏定义了 `P22` 和 `P23` 两个端口为按键输入端口。
`u8 pl=2;` 定义了 `pl` 为无符号字符型,并初始化为2。
如果您需要更详细的解释,请告诉我您的具体问题,我会尽力回答。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)