پاسخ : یه برنامه ساده!
خوب شما باید یه جایی کلاک میکرو رو تنظیم کرده باشین. نمی شه که آخه.
نوشته اصلی توسط majidshahrouzi
ببخشید دو زاریم نمیفته! مثلا کدهای زیر رو ببینید. برای چشمک زدن led ونمایش شمارنده روی LCD نوشتم و کار هم میکنه اما تابع Systeminit رو نداره!
کد:
#include"LPC17xx.h" #define family_lpc17xx /* TFTLCD definition */ #define TFTLCD_DATA_MSB_Nibble_Port_0 #define LCD_MSB_Nibble_OFFSET 15 #define TFTLCD_DATA_LSB_Nibble_Port_0 #define LCD_LSB_Nibble_OFFSET 4 #define TFTLCD_CONTROLPORT_2 #define TFTLCD_CS 8 #define TFTLCD_RS 9 #define TFTLCD_WR 10 #define TFTLCD_RD 11 #define TFTLCD_RST 13 #include "lcd.h" // #include "Touch.h" int main(void){ //unsigned int i; LPC_GPIO2->FIODIR=(0x0f); //set p2.1 to p2.3 as output LPC_SC->PCONP|=(1<<22); //power on timer2 LPC_TIM2->TCR=0X02; //reset and stop timer LPC_TIM2->PR=0X04; //set prescaler=4 LPC_TIM2->MR0=6250000; //set match value for compare LPC_TIM2->MCR=0X1; //interrupt on match(TC=MR0) LPC_TIM2->TC=0X0; //timer-counter=0 NVIC_EnableIRQ(TIMER2_IRQn); //enable TIMER2 Interrupt in NVIC LPC_TIM2->TCR=0X01; //enable timer2 LCD_Init(); LCD_Clear (BLUE); // LCD_ShowNum(100,150,100,4,16); LCD_Fill(0,100,239,150,BLUE); LPC_GPIO2->FIOSET=(0x01); while(1){ //if(LPC_TIM2->TC>=4500000){ // LPC_TIM2->TCR=0X02; // LPC_TIM2->TC=0X0; // LPC_TIM2->TCR=0X01; //LPC_GPIO0->FIOSET=(1<<26); //for(i=0;i<2880000;i++); //LPC_GPIO2->FIOCLR=(1<<0); //} } } TIMER2_IRQHandler(void){ static unsigned int j=0; float s ; LPC_TIM2->IR=0X01; // clear MR0 interrupt flag LPC_TIM2->TCR=0X02; //reset TC and PC register and stop timer?? LPC_TIM2->TC=0X0; //timer-counter=0 LPC_TIM2->TCR=0X01; //enable timer2 j++; LCD_ShowNum(100,150,j,4,16); s=j%2; if(s==0) LPC_GPIO2->FIOSET=(0x02); else LPC_GPIO2->FIOCLR=(0x02); //LPC_GPIO2->FIOSET=(1<<0); //for(j=0;j<43200000;j++); //LPC_GPIO2->FIOCLR=(1<<0); return j; }
دیدگاه