Hi dears ,
I want to write a program to blink an LED each 1 second. I've wrote below code but after loading into the MCU, it does not work at all. Would you let me know how can I do it, please ? < #include "LPC13xx.h" #define PRESCALE 60000 ;
void delayMS(unsigned int milliseconds); void initTimer0();
int main() {
LPC_SYSCON->SYSAHBCLKCTRL = (1<<7); initTimer0(); LPC_GPIO0->DIR |= (1<<3) |(1<<4); LPC_GPIO0->DATA = 0x0;
while(1) { LPC_GPIO0->DATA |= (1<<3);
LPC_GPIO0->DATA |= (1<<3); delayMS(500); LPC_GPIO0->DATA &= ~(1<<3); delayMS(500); LPC_TMR16B0->TCR = 0x0; //disable counter } }
void initTimer0() { //LPC_TMR16B0->CTCR = 0x0; LPC_TMR16B0->PR = PRESCALE-1; LPC_TMR16B0->TCR = 0x02;//reset timer
}
void delayMS(unsigned int milliseconds) { LPC_TMR16B0->TCR = 0x02;//reset timer LPC_TMR16B0->TCR = 0x01;//set timer while(LPC_TMR16B0->TC < milliseconds); LPC_TMR16B0->TCR = 0; //disable counter
}>
I'm not going to waste any time trying to interpret your post.
Why don't you do it so that people can view it easily and without risk if mistaking your intent?
while(1) { LPC_GPIO0->DATA |= (1<<3); LPC_GPIO0->DATA |= (1<<3); <==== why two??? so fast processor one isn't enough??? delayMS(500); LPC_GPIO0->DATA &= ~(1<<3); delayMS(500); LPC_TMR16B0->TCR = 0x0; //disable counter <=== why??? your delayMS() already does this }
Another thing - your prescaler value of 60000 for 1 millisecond would mean the input frequency to the timer is 60MHz. Is it? Where have you documented that in the source code? Always write your prescaler values so they are meaningful to a reader. The magic value 60000 is not meaningful since it doesn't tell how long timer period it's expected to produce, and it doesn't help the reader to know how you computed the value.
#define PCLK 60000000 // 60 MHz #define PRESCALE_ONE_MS ((PCLK)/1000 - 1)
Dears ,
Sorry for inconvenience that I've made for you. This is the first time I issued a problem here. Thanks for your comments. Concerning the Prescaler, actually I do not know the working frequency of the timer. Would you let me know how can I find it ? I've really studied the datasheet but I could not understand what would be the working frequency of the timer. (My development board has a 12MHZ crystal) Would you help me in this regard, please ?
The documentation for the processor has a clear description of how to configure the PLL, and the PCLK. It's way better if you ask specific questions based on specific problems you have to understand that text.
Next thing - you have not made any reference to what doesn't work for you. What you think should happen. What actually happens. What you have tried to do to figure out the difference between expectation and reality.
Another thing:
#define PRESCALE 60000 ;
What do you think that ';' will do to your code, when the compiler performs a text replacement of the PRESCALE symbol?
Hey coder people.
i need code for something like raspberry pi camera connected to a 8X51 cpu processor.
can u give a link.
not urgent but i need it very soon ;--)
I want to ask my question again , I would like to write a code to blink an LED every 1 second. Could anybody help me for LPC1343, please ?
Thank you.