📄 hello.c
字号:
/*------------------------------------------------------------------------------
HELLO.C
Copyright 1995-1999 Keil Software, Inc.
------------------------------------------------------------------------------*/
#include <REG52.H> /* special function register declarations */
/* for the intended 8051 derivative */
#include <stdio.h> /* prototype declarations for I/O functions */
#ifdef MONITOR51 /* Debugging with Monitor-51 needs */
char code reserve [3] _at_ 0x23; /* space for serial interrupt if */
#endif /* Stop Exection with Serial Intr. */
/* is enabled */
/*------------------------------------------------
The main C function. Program execution starts
here after stack initialization.
------------------------------------------------*/
//#define FREQ_OS 24000000L
#define FREQ_OS 18432000L
#define RATE 9600L
#define BIT_SMODE 1
#if BIT_SMODE
#define BAUD_CHAR (256 - (unsigned char)( (2L*FREQ_OS)/(32L*12L*RATE) ) )
#else
#define BAUD_CHAR (256 - (unsigned char)( FREQ_OS/(32L*12L*RATE) ) )
#endif
#define baud9600 (256-13) //24M/SMODE=1
#if 0
void init_serial(void)
{
SCON = 0x50; /* SCON: mode 1, 8-bit UART, enable rcvr */
TMOD |= 0x20; /* TMOD: timer 1, mode 2, 8-bit reload */
// TH1 = baud9600;
TH1 = BAUD_CHAR ; /* TH1: reload value for 1200 baud @ 16MHz */
TR1 = 1; /* TR1: timer 1 run */
TI = 1; /* TI: set TI to send first char of UART */
RI=0;
#if BIT_SMODE
PCON |=0x80;
#else
PCON &=0x7f;
#endif
}
void putc(char x)
{
while(!TI);
TI=0;
SBUF=x;
}
char getc(void)
{
while(!RI);
RI=0;
return(SBUF);
}
void wputs(char s[])
{
unsigned char i;
for(i=0;s[i];i++)
{
while(!TI);
TI=0;
SBUF=s[i];
}
}
unsigned char wgets(char s[])
{
unsigned char i;
for(i=0;i<20;i++)
{
while(!RI);
RI=0;
if(SBUF==0x0d) break;
s[i]=SBUF;
putc(SBUF);
}
s[i]=0;
return(i);
}
void LCD_GRP(unsigned char const *string_num);
void LCD_INIT(void);
void LCD_CLS(void);
int mainxx (void);
char GetAdc(char s[]);
void mainxxxx (void) {
int i,j;
char c;
idata char s[20];
unsigned char const *string_num="1234567890";
init_serial();
//LCD_INIT();
//LCD_CLS();
//LCD_GRP(string_num);
wputs("hello mcs51");
mainxx();
while (1)
{
// P1^0= 0x01; /* Toggle P1.0 each time we print */
//for(i=0;i<1000;i++)
//for(j=0;j<100;j++);
c=wgets(s);
if(c>0)
wputs("...");
c=getc();
putc(c);
}
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -