Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

A good book for embedded c programming

Status
Not open for further replies.

Raveesh

Member level 2
Joined
Feb 6, 2011
Messages
42
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,564
Hi,
Can any one suggest a good book for embedded C ( for general compiler )...
 

ckshivaram

Advanced Member level 5
Joined
Apr 21, 2008
Messages
5,070
Helped
2,146
Reputation
4,298
Reaction score
2,087
Trophy points
1,393
Location
villingen (Germany) / Bangalore
Activity points
30,097
first of all there isnothing called general compiler for embedded systems. all cross compilers are specific. and embedded C is a derivative of C , so all compilers support C languages. but some commands and syntax are supported by specific compilers.... So there is no standard book for embedded C.. Whatever you get is covering for C concepts... Embedded C syntax is different for different compilers as some support some features , other compilers do not support those features....

the best help you can get is the help of the compiler you use.. as that compiler will talk of only those commands that it supports.. same commends in other compilers may or may not be supported as architecture of controllers are different,...............
 

Kandeepan

Junior Member level 1
Joined
Nov 18, 2010
Messages
16
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,436
Hi Shivram,
Hope you can remember me. I'm very new to PIC C programming. What does it mean by " set_timer0(42);"
Looking forward to hear from you soon.

Regards

Kandeepan
 

ckshivaram

Advanced Member level 5
Joined
Apr 21, 2008
Messages
5,070
Helped
2,146
Reputation
4,298
Reaction score
2,087
Trophy points
1,393
Location
villingen (Germany) / Bangalore
Activity points
30,097
set_timer0(42);

it looks like an function to load the value of timer0

So you are setting the timer0 value to run for 42millisecs.. the 42 depends on the parameter the function is taking.. it can be in msec, or sec depending on the function prototype.....
 

Kandeepan

Junior Member level 1
Joined
Nov 18, 2010
Messages
16
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,436
Hi Shivaram, Thanks for your reply. pls have a look at the following code


/******************************* Fuse Settings ******************************/

#fuses INTRC_IO,NOWDT,NOPUT,NOMCLR,BROWNOUT,PROTECT,NOCPD

/***************** Based on Internal Clock frequency of 4MHz ****************/

#use delay(clock=4000000)

/****************************************************************************
Timer0 Interrupt Service Routine to Generate Blinking.
----------------------------------------------------------------------------
Blinking Rate -------------------------------------- 40/min
Blinking Frequency --------------------------------- 0.667 Hz
Time period ---------------------------------------- 1.5s
Blinking Duty Cycle -------------------------------- 50%

********************* Interupt Service Routine ******************************/
#INT_TIMER0

void Flashing_Timer()
{
set_timer0(42); // Timer preset to produce

// 250uS interrupt cycle.
Blink++; // increment Blink Time Counter
mSec++; // Increment Millisecond Counter

if(Stop_Seconds == 0)
{
if (mSec == 4003) // Second Counter
{
Seconds++; // Increment seconds count
mSec =0; // Reset mSec for next second
}
}

if(Stop_Blink == 0)
{
if (Blink == 3007) // Flashing timer to provide
// 40 Flashes/min
{
output_toggle(Left); // Toggle both lamps
output_toggle(Right);
Blink =0; // Reset flahing counter
}
}

}

/******************** Interupt Service Routine End ***************************/

/**************************** Main Function **********************************/

void main()
{
Initialize(); // Initialization Routine

Calibrate_Internal_Oscillator(); // Internal Oscillator
// Calibration Routine
Timer_Set();

delay_ms(100);

/**************************** Perpetual Loop *********************************/

while(1) // Do forever
{
while (input(Start) ) // Wait for start signal - mag switch
{
stop_seconds = 1; // Seconds count disabled
output_low(left); // Set lamps off
output_low(right);
seconds = 0; // Ensure seconds start at 0
}

while (!input (Start)) // Activate TAFLU
{
delay_ms(5);
if (!input (start));
{
//Switch_set(); // Get Delay time
output_high (Left); // Set one Lamp on
output_low (right);
stop_seconds = 0; // Enable seconds count
enable_interrupts(INT_TIMER0); // Start Timer0
enable_interrupts(GLOBAL); // enable interupts
Stop_Blink = 0;

/*****************************************************************************/
// Loop here until Seconds = minutes or switch is pressed
/*****************************************************************************/
do
{
Delay_Ms(1000); // Make sure Switch released
if (!input (Start)) // See if switch Activated
Seconds = Minutes; // Set seconds = minutes
} // to stop flash
while (seconds < minutes); // until the seconds = mins
}

}
/************************* Time expired **************************************/
{
stop_seconds = 1; // stop the seconds
stop_Blink = 1; // stop the flasher toggle

disable_interrupts(INT_TIMER0); // Disable timer interupt
disable_interrupts(GLOBAL); // Disable global interupt
output_low(left); // Turn lamps off
output_low(right);
}

Delay_Ms(1000);
/***************************** End of main loop ******************************/
}
/**************************** Main Function End ******************************/
}
/*****************************************************************************/

I could not understand the values in it "if (mSec == 4003) " & "if (Blink == 3007)" where did they drive these values(4003 and 3007) from?
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top