nirmala h
Member level 1
- Joined
- Jan 18, 2011
- Messages
- 36
- Helped
- 6
- Reputation
- 12
- Reaction score
- 6
- Trophy points
- 1,288
- Location
- Bangalore, India
- Activity points
- 1,530
What is the difference between C & Embedded C ?And also solve this program
To generate 100 Fibbonacci no's in C will write as
How do we write in Embedded...?
while(n<100)
{
r=p+q;
p=q;
q=r;
printf("%d",r);
}
#include <stdio.h>
#include "serialport.h"
void main(void)
{
unsigned long r, p, q; // may vary depending on compiler supported integer variable types
n=1;
p=0;
q=1;
r=0;
initport(PORT1, 9600, 8, N, 1); //initial serial port connection to PC
while(n<100)
{
r=p+q;
p=q;
q=r;
printf(" %u ",r); // STDOUT defined in header file
n++;
}
while(1); // necessary to prevent program exit, no OS present
}
In Embedded printf is not used, so could you tell me how to write the code..And where you are storing all the generated no's..
#include <htc.h>
void main( void )
{
char data;
// configure external LCD
OpenXLCD( EIGHT_BIT & LINES_5X7 );
// configure USART
OpenUSART( USART_TX_INT_OFF & USART_RX_INT_OFF &
USART_ASYNCH_MODE & USART_EIGHT_BIT &
USART_CONT_RX,
25);
while(1)
{
while(!DataRdyUSART()); //wait for data
data = ReadUSART(); //read data
WriteDataXLCD(data); //write to LCD
if(data==’Q’)
break;
}
CloseUSART();
}
And where you are storing all the generated no's..
Program is as simple to understand...good example...
And you have explained various concenpts involved in it...
everything is true ... but usually we dont develop fibonacci, factorial of number and these kind of programs in embedded as embedded has programs for specific application... it purely depends on the IDE and compiler syntax on how to write them.... data are stored in flash or eeproms.. printf are usually not used unless using an UART, as the output is seen on display device and not on any specific console like pc monitor.. printf and scanf are used much.... these libraries take huge amount of memory while using stdio.h
which is usually not recommended...
---------- Post added at 11:22 ---------- Previous post was at 11:21 ----------
these programs are good for compilers and learning purpose, but not for cross compilers...
static char variable;
const char variable;
hello I have also question about some syntax in embedded C
I usually declare a variable inside a ISR like this so that in every iteration, the value of a variable is not re defined.
that's my purpose of declaring like this but i dont know if it's really for this application..
PHP:static char variable;
is there any equivalent decalaration like this in standard C programming?
and also if we declare a variable like
PHP:const char variable;
const means constant right? I read from somewhere that if we declare like this the value will not be stored in RAM but in Flash memory.. correct?
is there any such thing like this in normal C programming?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?