| |
| |
| |
| |
| #include<REG51.H> |
| #define Main_Fosc 12000000L |
| #define T1MS (65536-Main_Fosc/12/1000) |
| #define Key_Debounce 40 |
| sbit LED=P2^0; |
| sbit Key=P3^1; |
| sbit Key2=P3^0; |
| unsigned char Key_Handle=0; |
| void Sys_Init(); |
| void Delay_Long(); |
| void Perpherial_Init(); |
| void Key_Scan(); |
| void Key_Service(); |
| |
| void main() |
| { |
| Sys_Init(); |
| Delay_Long(); |
| Perpherial_Init(); |
| while (1) |
| { |
| Key_Service(); |
| } |
| |
| } |
| |
| void Sys_Init() |
| { |
| TMOD=0X01; |
| TL0=T1MS; |
| TH0=T1MS>>8; |
| } |
| |
| void Delay_Long() |
| { |
| unsigned char i,j; |
| for(i=0;i++;i<220) |
| { |
| for(j=0;j<220;j++) |
| ; |
| } |
| } |
| |
| void Perpherial_Init() |
| { |
| ET0=1; |
| TR0=1; |
| EA=1; |
| } |
| |
| void Timer0_ISR() interrupt 1 |
| { |
| TL0=T1MS; |
| TH0=T1MS>>8; |
| Key_Scan(); |
| } |
| |
| void Key_Scan() |
| { |
| static unsigned int Key_CNT; |
| static unsigned char Key_Lock; |
| |
| if (0!=Key) |
| { |
| Key_CNT=0; |
| Key_Lock=0; |
| } |
| else if (0==Key_Lock) |
| { |
| Key_CNT++; |
| if (Key_CNT>Key_Debounce) |
| { |
| if (0==Key2) |
| { |
| Key_Lock=1; |
| Key_Handle=1; |
| } |
| |
| |
| } |
| |
| } |
| |
| } |
| |
| void Key_Service() |
| { |
| if (0==Key_Handle) |
| { |
| return; |
| } |
| |
| switch (Key_Handle) |
| { |
| case 1: |
| LED=!LED; |
| Key_Handle=0; |
| break; |
| } |
| |
| } |
| |
| |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)