Embedded C
Embedded C
#INCLUDE<STDIO.H>
void main(void)
{
printf(“hai welcome to cross compiler”)
}
//serial interrupt//
#include<reg51.sfr>
#include<stdio.h>
#include<stdio.h>
#include<reg51.sfr>
_regparm func(int);
_regparm func(int i)
{
printf("%d",i);
}
#include<reg51.sfr>
#include<stdio.h>
/* void _nop(void);
* bit _testclear(bit);
* unsigned char _da(unsigned char);
* unsigned char _rol(unsigned char,unsigned char);
* unsigned char _ror(unsigned char,unsigned char);
*/
static bit b;
static unsigned char c,d;
static int i;
main()
{
_nop(); /* insert a nop instruction */
6, DEMO.C
#include <string.h>
/*
* 'optimize t' forces 'initval' to be allocated directly
after 'table'.
* Needed for the deliberate bug, to be discovered in the
tutorial.
*/
_idat unsigned int table[7]; /* table of factorial values
*/
_idat int initval; /* initialization value for
calculation */
#define INPUT_LEN 2
#define OUTPUT_LEN 35
char inbuf[INPUT_LEN]; /* input buffer for one
character */
char outbuf[OUTPUT_LEN]; /* output buffer for a line
*/
/*
* FUNCTION PROTOTYPES
*
* These functions are present in this module.
*/
void myputs( _rom char * );
void mygetchar( char * );
unsigned int factorial( unsigned char );
/*
* The function addone() is present in the module
"addone.src".
* This function is deliberately treated as an assembly
routine
* (although it has been created by CC51) to demonstrate
* assembly level debugging.
*/
_regparm unsigned int addone( unsigned int );
/*
* The simulated I/O functions _simi() and _simo() are
present in the
* module "_simio.c". Prototypes are present in the
include file
* "simio.h". These functions are used by CrossView Pro
for temporary
* breakpoints, when performing simulated I/O. You can
have up to 8 I/O
* channels (called streams) in your application. This
demo uses the
* default streams 0 for input and 1 for output. In
CrossView Pro you
* can connect these streams to a window, file or
keyboard.
*/
#include <simio.h>
#define INPUT_STREAM 0
#define OUTPUT_STREAM 1
void
main(void)
{
unsigned char loopvar; /* the loop counter
*/
char cvar; /* sample char variable
*/
unsigned int sum; /* 17+sum of factorials from 0
to 6 */
initval = 17;
if (sum == 891)
{
myputs("pass\n");
}
else
{
myputs("fail\n");
}
recordvar.color = red;
recordvar.a = strlen(recordvar.b);
recordvar.color = blue;
if (cvar == 'y')
{
myputs( bell );
}
myputs( "End of demo\n" );
}
/*
* Iteration performs better than recursion.
*/
unsigned int
factorial( unsigned char num )
{
char locvar = 'x'; /* an unused local variable */
unsigned int tmp;
if (num < 2)
return 1;
else
{
for (tmp = num--; num; num--)
tmp *= num;
}
return tmp;
}
void
myputs( _rom char *string )
{
char *p = outbuf;
void
mygetchar( char *c )
{
_simi( INPUT_STREAM, inbuf, 2);
*c = inbuf[0];
}