home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 1996 September
/
pcwk_09_96.iso
/
demo
/
wgelectr
/
pk51demo
/
files.2
/
EXAMPLES
/
CSAMPLE
/
CSAMPLE1.C
< prev
next >
Wrap
C/C++ Source or Header
|
1995-07-08
|
1KB
|
33 lines
/*------------------------------------------------------------------------------
CSAMPLE1.C
Copyright 1995 KEIL Software, Inc.
------------------------------------------------------------------------------*/
#include <reg51.h> /* define 8051 registers */
#include <stdio.h> /* define I/O functions */
extern int getnumber ();
extern output (int);
main () { /* main program */
int number1, number2; /* define operation registers */
bit operation; /* define operation */
SCON = 0x52; /* SCON */ /* setup serial port control */
TMOD = 0x20; /* TMOD */ /* hardware (2400 BAUD @12MHZ) */
TCON = 0x69; /* TCON */
TH1 = 0xf3; /* TH1 */
printf ("\n\nC compiler demonstration program\n\n");
while (1) { /* repeat forever */
number1 = getnumber (); /* read number1 */
number2 = getnumber (); /* read number2 */
printf ("Input operation: '+' (ADD) or '-' (SUB) ? ");
operation = (getchar () == '+'); /* get operation */
output (operation ? (number1 + number2) /* perform operation */
: (number1 - number2) );
}
}