📄 hello.c
字号:
/*------------------------------------------------------------------------------
HELLO.C
Copyright 1995-2005 Keil Software, Inc.
------------------------------------------------------------------------------*/
#include <REG52.H> /* special function register declarations */
/* for the intended 8051 derivative */
#include <stdio.h> /* prototype declarations for I/O functions */
#include <stdlib.h> /* standard library .h-file */
#include <ctype.h> /* character functions */
#include <intrins.h>
#ifdef MONITOR51 /* Debugging with Monitor-51 needs */
char code reserve [3] _at_ 0x23; /* space for serial interrupt if */
#endif /* Stop Exection with Serial Intr. */
//定义按健
sbit K1 = P3^4;
sbit K2 = P3^5;
sbit LED = P1^0;
sbit P12MOTO=P1^2;
sbit P33=P3^3;
unsigned char one=0;
//延时
void delay(unsigned char n)
{
while(n--);
}
void timer3(void)interrupt 3
{
TH1=0x0;
TL1=0x0;
TF1=0;
if(one>200)
{
LED=!LED;
one=0;
}
else
one++;
}
// void timer0(void)interrupt 0
// {
// TH1=0x0;
// TL1=0x0;
// //TF1=0;
// if(one>200)
// {
// LED=!LED;
// one=0;
// }
// else
// one++;
//
// }
//
//
// void timer1(void)interrupt 1
// {
// TH1=0x0;
// TL1=0x0;
// TF1=0;
// if(one>200)
// {
// LED=!LED;
// one=0;
// }
// else
// one++;
//
// }
//
//
// void timer2(void)interrupt 2
// {
// TH1=0x0;
// TL1=0x0;
// TF1=0;
// if(one>200)
// {
// LED=!LED;
// one=0;
// }
// else
// one++;
//
// }
/*------------------------------------------------
The main C function. Program execution starts
here after stack initialization.
------------------------------------------------*/
void main (void) {
unsigned int i;
#ifndef MONITOR51
SCON = 0x50; /* SCON: mode 1, 8-bit UART, enable rcvr 101 0000 */
RCAP2H = 0xFF;
TH2 = 0xff;
RCAP2L =0xBF;
TL2 = 0xFB;
T2CON = 0x34; //0011 0100
//TR1 = 1; /* TR1: timer 1 run */
TI = 1; /* TI: set TI to send first char of UART */
ES =0;
//EA =1;
// IE=0xff; //开所有中断
// IP=0x10;
#endif
/*------------------------------------------------
Note that an embedded program never exits (because
there is no operating system to return to). It
must loop and execute forever.
------------------------------------------------*/
//
TMOD =0x00; //工作方式0
TH1=0;
TL1=0;
IE1=1; //中断
//
//
EA=1; //开放总中断
ET1=1; //充许定时器溢出中断
//
TR1=1; //运行
// TMOD =0x01;
// TH0=0x0;
// TL0=0x0;
// EA=1;
// ET0=1;
// TR0=1;
//设置
K1=1;
K2=1;
LED =1;
// delay(1);
for(;;)
{
delay(1);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -