📄 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;
//延时
void delay(unsigned int n)
{
unsigned int i;
for(i=0;i<n;i++)
_nop_;
}
//串口中断
void serial0(void) interrupt 4
{
unsigned char tmp;
EA=0; //关中断
if(RI) //处理接收中断
{
tmp=SBUF;
printf("%bu",tmp);
RI=0;
}
if(TI) //处理发送中断
{
TI=0;
}
EA=1;
}
/*------------------------------------------------
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 =1; //允许串行中断
EA =1;
#endif
/*------------------------------------------------
Note that an embedded program never exits (because
there is no operating system to return to). It
must loop and execute forever.
------------------------------------------------*/
//设置
K1=1;
K2=1;
LED =1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -