Hi frnds,
i am trying to program led blinking in P0_30 using LPC1225/301 microcontroller . there is no error in this program. But led is not blinking. can anyone suggest me what is the problem in this program.
#include<lpc122x.h>
void delay(unsigned short int ms) ;
int main(void)
{
LPC_SYSCON->SYSAHBCLKCTRL |=(1UL<<31)|(1<<30)|(1<<29);
LPC_IOCON->PIO0_30 &=~0xFF;
LPC_IOCON->PIO0_30 |= (1<<4)|(1<<7);
LPC_GPIO0->DIR |= (1<<30);
LPC_GPIO0->CLR |= (1<<30);
while(1)
{
LPC_GPIO0->SET |= (1<<30);
delay(1000);
LPC_GPIO0->CLR |= (1<<30);
delay(1000);
}
}
void delay(unsigned short int ms)
{
unsigned short int j;
unsigned long i;
for(j=0;j<ms;j++)
for(i=0;i<1700;i++);
}
Enable IOCON along with the ports
LPC_SYSCON->SYSAHBCLKCTRL |=(1UL<<31)|(1<<30)|(1<<29) | (1 << 16);
Otherwise, monitor the pin with an Oscope - maybe the LED circuit is incorrect.
Thank you for your reply
As you mentioned, i reprogrammed
#include<lpc122x.h>
void delay(unsigned short int ms) ;
int main(void)
{
LPC_SYSCON->SYSAHBCLKCTRL |=(1UL<<31)|(1<<30)|(1<<29)|(1<<16);
LPC_IOCON->PIO0_30 &=~0xFF;
LPC_IOCON->PIO0_30 |= (1<<4)|(1<<7);
LPC_GPIO0->DIR |= (1<<30);
LPC_GPIO0->CLR |= (1<<30);
while(1)
{
LPC_GPIO0->SET |= (1<<30);
delay(1000);
LPC_GPIO0->CLR |= (1<<30);
delay(1000);
}
}
void delay(unsigned short int ms)
{
unsigned short int j;
unsigned long i;
for(j=0;j<ms;j++)
for(i=0;i<1700;i++);
}
still its not working even i checked circuit is correct i checked osc nothing.
Your delay function won't work as expected, as the compiler will optimise away your loops. Make sure you put 'volatile' on each of your variable declarations:
volatile unsigned short int j;
volatile unsigned long i;
Thank you for your reply my frnd,
I dont think its delay fault i just removed delay function i am trying to program the P0_30 port pin for zero or clear
This program also not working. i dnt know what went wrong
#include<lpc122x.h>
int main(void)
{
LPC_SYSCON->SYSAHBCLKCTRL |=(1UL<<31)|(1<<30)|(1<<29)|(1<<16);
LPC_IOCON->PIO0_30 &=~0xFF;
LPC_IOCON->PIO0_30 |= (1<<4)|(1<<7);
LPC_GPIO0->DIR |= (1<<30);
while(1)
{
LPC_GPIO0->CLR |= (1<<30);
}
}
This program i got from internet this program work superbly
/******************** (C) COPYRIGHT 2010 Embest Info&Tech Co.,LTD. ********************
* File Name : main.c
* Author : Wuhan R&D Center, Embest
* Date First Issued : 10/15/2010
* Description : LED blinky example.
***************************************************************************************
***************************************************************************************
* History:
* 10/15/2010: V1.0
**************************************************************************************/
/* Includes ------------------------------------------------------------------*/
#include "lpc12xx_libcfg.h"
void delay(unsigned short int ms) ;
/* Private define ------------------------------------------------------------*/
/* Number of user LEDs */
#define LED_NUM 1
const unsigned long led_mask[] = { 30};
/* Private variables ---------------------------------------------------------*/
/* SysTick Counter */
volatile unsigned long SysTickCnt;
/* Private functions ---------------------------------------------------------*/
void SysTick_Handler (void);
void Delay (unsigned long tick);
/**
* @brief SysTick handler sub-routine (1ms)
* @param None
* @return None
*/
void SysTick_Handler (void) {
SysTickCnt++;
}
/**
* @brief Delay function
* @param tick - number milisecond of delay time
* @return None
*/
void Delay (unsigned long tick) {
unsigned long systickcnt;
systickcnt = SysTickCnt;
while ((SysTickCnt - systickcnt) < tick);
}
/**
* @brief Main program body
* @param None
* @return int
*/
int main (void) { /* Main Program */
int num = -1;
IOCON_PIO_CFG_Type PIO_mode;
//SysTick_Config(SystemCoreClock/1000 - 1); /* Generate interrupt each 1 ms */
SYS_ConfigAHBCLK(SYS_AHBCLKCTRL_GPIO0, ENABLE);
IOCON_StructInit(&PIO_mode);
PIO_mode.type = IOCON_PIO_0_30;
IOCON_SetFunc(&PIO_mode);
GPIO_SetDir(LPC_GPIO0, 30, 1);
GPIO_SetLowLevel(LPC_GPIO0, 30, 1);
for (;;) { /* Loop forever */
GPIO_SetLowLevel(LPC_GPIO0, 30, 1);
delay(500);
GPIO_SetHighLevel(LPC_GPIO0, 30, 1);
delay(500);
}
}
void delay(unsigned short int ms)
{
unsigned short int j;
unsigned long i;
for(j=0;j<ms;j++)
for(i=0;i<1700;i++);
}
#ifdef DEBUG
/**
* @brief Reports the name of the source file and the source line number
* where the CHECK_PARAM error has occurred.
* @param file file Pointer to the source file name
* @paramline line assert_param error line source number
* @return None
*/
void check_failed(uint8_t *file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Infinite loop */
while(1);
}
#endif
/**
* @}
*/
/* --------------------------------- End Of File ------------------------------ */
this program i worte myself but it is not working i used library #include<lpc122x.h> but not working error also zero
#include<lpc122x.h>
int main(void)
{
LPC_SYSCON->SYSAHBCLKCTRL |=(1UL<<31)|(1<<30)|(1<<29)|(1<<16);
LPC_IOCON->PIO0_30 &=~0xFF;
LPC_IOCON->PIO0_30 |= (1<<4)|(1<<7);
LPC_GPIO0->DIR |= (1<<30);
while(1)
{
LPC_GPIO0->CLR |= (1<<30);
}
}
this program is working
/******************** (C) COPYRIGHT 2010 Embest Info&Tech Co.,LTD. ********************
* File Name : main.c
* Author : Wuhan R&D Center, Embest
* Date First Issued : 10/15/2010
* Description : LED blinky example.
***************************************************************************************
***************************************************************************************
* History:
* 10/15/2010: V1.0
**************************************************************************************/
/* Includes ------------------------------------------------------------------*/
#include "lpc12xx_libcfg.h"
void delay(unsigned short int ms) ;
/* Private define ------------------------------------------------------------*/
/* Number of user LEDs */
#define LED_NUM 2
const unsigned long led_mask[] = { 30,31};
/* Private variables ---------------------------------------------------------*/
/* SysTick Counter */
volatile unsigned long SysTickCnt;
/* Private functions ---------------------------------------------------------*/
void SysTick_Handler (void);
void Delay (unsigned long tick);
/**
* @brief SysTick handler sub-routine (1ms)
* @param None
* @return None
*/
void SysTick_Handler (void) {
SysTickCnt++;
}
/**
* @brief Delay function
* @param tick - number milisecond of delay time
* @return None
*/
void Delay (unsigned long tick) {
unsigned long systickcnt;
systickcnt = SysTickCnt;
while ((SysTickCnt - systickcnt) < tick);
}
/**
* @brief Main program body
* @param None
* @return int
*/
int main (void) { /* Main Program */
IOCON_PIO_CFG_Type PIO_mode;
//LPC_IOCON->PIO0_30 &=~0xFF;
LPC_IOCON->PIO0_30 |= (1<<4)|(1<<7);
PIO_mode.type = IOCON_PIO_0_30;
IOCON_SetFunc(&PIO_mode);
LPC_SYSCON->SYSAHBCLKCTRL |=(1UL<<31)|(1<<30)|(1<<29);
LPC_GPIO0->DIR |= (1<<30);
LPC_GPIO0->CLR |= (1<<30);
for (;;) { /* Loop forever */
LPC_GPIO0->SET |= (1<<30);
delay(1000);
LPC_GPIO0->CLR |= (1<<30);
delay(1000);
}}
void delay(unsigned short int ms)
{
unsigned short int j;
unsigned long i;
for(j=0;j<ms;j++)
for(i=0;i<1700;i++);
}
#ifdef DEBUG
/**
* @brief Reports the name of the source file and the source line number
* where the CHECK_PARAM error has occurred.
* @param file file Pointer to the source file name
* @paramline line assert_param error line source number
* @return None
*/
void check_failed(uint8_t *file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Infinite loop */
while(1);
}
#endif
/**
* @}
*/
/* --------------------------------- End Of File ------------------------------ */
this program is not working
#include<lpc122x.h>
void delay(unsigned int ms);
int main(void)
{
LPC_SYSCON->SYSAHBCLKCTRL |=(1UL<<31)|(1<<30)|(1<<29)|(1<<16);
LPC_IOCON->PIO0_30 &=~0xFF;
LPC_IOCON->PIO0_30 |= (1<<4)|(1<<7);
LPC_GPIO0->DIR |= (1<<30);
LPC_GPIO0->CLR |= (1<<30);
while(1)
{
LPC_GPIO0->SET |= (1<<30);
delay(1000);
LPC_GPIO0->CLR |= (1<<30);
delay(1000);
}
}
void delay(unsigned int ms)
{
int i,j;
for(i=0;i<ms;i++)
{
for(j=0;j<1700;j++);
}
}
There is any different between the #include<lpc122x.h> and #include "lpc12xx_libcfg.h"
why my own program is not working.
Hi Dhinesh E,
You can compare these two headfile, check the details.
Beside, you can debug your code, check the register, whether the according register is modified.
Any further question, just let me know!
Have a great day,
kerry
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------