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.
So, I see that your teacher have given you a skeleton code for your programming exercise.
Well, I'm pretty sure that your teacher also is of the belief that students who have been visiting the lessons would also have enough skill to know how to solve this programming exercise. And you have probably also received documentation or links to documentation.
So exactly where are you stuck? What part of the microcontroller course did you understand, and what part did you fail to understand?
Have you spent time with the documentation for the processor?
Have you checked for application notes?
Have you checked what potentially useful examples there are on the manufacturers home page or installed with the Keil tools? Or available on this site?
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..??
View all questions in Keil forum