We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi everybody,
I'm a beginner trying to generate a PWM wave on a C8051F330 micro controller using C programming language. I have many doubts regarding this exercise. It would be really helpful if someone clarifies my doubtswhich will eventually get me going.
Can anybody please explain me roughly the flow of the following program...??
// Include Files // // Global constants // // Function Prototypes // // Main Routine //
void main (void) { PCA0MD &= ~0x40; Oscillator_Init (); Port_Init (); External_Interrupt_Init (); Timer2_Init (); PCA_Init (); EA = 1; while (1); }
// Oscillator Initialisation // void Oscillator_Init (void) { //do something// }
//Port Initialisation // void Port_Init (void) { //do something// }
//External Interrupt Initialisation // void External_Interupt_Init (void) { //do something// EX0 = 1; }
//Timer2 Initialisation // void Timer2_Init (void) { TMR2CN=0x00; TMR2RL= RELOAD_VALUE; TMR2 = 0xFFFF; // Set to reload immediately // }
//PCA Initialisation // void PCA_Init (void) { //do something// }
//Interrupt Service Routine (ISR) // INTERRUPT(INT0_ISR, INTERRUPT_INT0) { TR2 = 1; }
This program is in C. I'm here trying to understand the program flow. I know that the "main()" is the first function that gets executed here. And then the line "PCA0MD &= ~0x40" followed by Osillator_Init function. The program control actually goes into the called Oscillator_Init function (below main()) and executes it,.and so on...
In case of External_Interrupt_Init(),I have enabled /INT0 interrupt using "EX0=1". Where does the program flow control go from here...??
And in ISR where does the program control go after executing TR2 = 1,.
Please folks help me find answers to my doubts.
No, you have completely got me wrong. This is completely my code. It's just that I haven't pasted the whole code. No, teacher has given the code to me. I'm not in school or college level doing this. I'm an engineer who has just started to familiarise myself with programming in Keil IDE at my job. This is my first programming attempt with Keil. I did go through the documentation for the processor C8051F330 and the necessary application notes. I have gone through the basic examples of External Interrupts, Timers and Blinky which I had access to. My doubts are clearly stated in my first post. But again for your reference:: "I'm here trying to understand the program flow. I know that the "main()" is the first function that gets executed here. And then the line "PCA0MD &= ~0x40" followed by Osillator_Init function. The program control actually goes into the called Oscillator_Init function (below main()) and executes it,.and so on... What are Initialisation functions ? Why do they have to be coded one after the other as functions..?? Can I not have some functional code inside the Initialisation function..???
In case of External_Interrupt_Init(),I have enabled /INT0 interrupt using "EX0=1". Where does the program flow control go from here...?? According to my understanding the program control jumps to service the ISR (Interrupt service routine).
And in ISR where does the program control go after executing TR2 = 1 (code to start Timer2),."
As you already said this function does nothing but to set EX0=1, then it move to next line of the main function.
Do some basic search on google about what is an "Interrupt service routine".
Thanks for your reply. Yeah I understand that, as I have EX0 = 1 (External Interrupt for /INT0 set) the program flow jumps to servise the ISR(Interrupt service routine). But in the ISR I have set the Timer2 to logic 1 which means Timer2 is set to run. Could you please tell me Where does the program control go after this..??
Again, after the execution of the ISR the control should go back to service the instruction that would have been executed if the Interrupt request had not occured. But in this case, as I start a timer, where could the program control go....??
The questions you're asking are about pretty basic embedded programming concepts - they have nothing specifically to do with Keil, nor even the C8051F330 microcontroller.
The Keil manuals and microcontroller datasheet, etc, do assume that you are proficient.
Therefore, especially as this is for your job, I most strongly recommend that you take an embedded training course.
There are some (providers) mentioned here: http://www.keil.com/events/ (see "Third party training")
And here: blog.antronics.co.uk/.../08
You local SiLabs and/or Keil distributors should be able to suggest others - and may even provide training themselves...