سلام به همگی . من این کد رو نوشتم . قصد من این هست که از تایمر 1 برای شمارش زمان 1 ثانیه و از تایمر 0 برای شمارش تعداد پالس ها ورودی به cap0.0 استفاده کنم برنامه ی زیر رو نوشتم . ( البته شاید بعضی کدهاش به موضوع ربط نداشته باشه) . اما نتونستم جواب بگیرم . در واقع می خواستم ببینم سرعت تغییر های پورتهای خروجیش دارای چه فرکانسی هست به همین منظور port2.0 رو مرتبا 0 و 1 می کنم و این پین رو خودم به cap0.0آ متصل کردم اما برنامه جواب نمی ده .
به طور خلاصه بگم مشکل من با کانتر می باشد .
ممنون می شم اگر دوستان تونستند رو کد بنده مشکل رو مشخص کنند و یا کد دلخواهی برای قسمت کانتر که جواب گرفتند قرار بدهند .
به طور خلاصه بگم مشکل من با کانتر می باشد .
ممنون می شم اگر دوستان تونستند رو کد بنده مشکل رو مشخص کنند و یا کد دلخواهی برای قسمت کانتر که جواب گرفتند قرار بدهند .
کد:
/************************************************************************************
Code created using the ARMwizard, visit http://alexan.edaboard.eu
************************************************************************************/
#include <stdio.h>
#include "LCD.h"
#include "delay.h"
#include <LPC23xx.h>
#define I2C0CONCLR I20CONCLR
#define I2C1CONCLR I21CONCLR
#define I2C2CONCLR I22CONCLR
#define INTCLEAR MAC_INTCLEAR
#define USBDevIntClr DEV_INT_CLR
#define USBEpIntClr EP_INT_CLR
#define USBDMARClr DMA_REQ_CLR
#define USBEoTIntClr EOT_INT_CLR
#define USBNDDRIntClr NDD_REQ_INT_CLR
#define USBSysErrIntClr SYS_ERR_INT_CLR
#define OTGIntClr OTG_INT_CLR
#define ILR RTC_ILR
#define IO0DIR IODIR0
#define IO1DIR IODIR1
#define MCIClear MCI_CLEAR
#define DMACIntClear GPDMA_INT_TCCLR
#define DMACIntErrClr GPDMA_INT_ERR_CLR
/******************************************************************************
TIMER1 FAST interrupt service function
******************************************************************************/
__irq void FIQ_Handler (void) {
/* write code here */
unsigned char buffer[15];
/* list of all available flags, select which to use */
T1IR = 1; /* Clear MAT0.0 interrupt flag */
T1IR = 2; /* Clear MAT0.1 interrupt flag */
T1IR = 4; /* Clear MAT0.2 interrupt flag */
T1IR = 8; /* Clear MAT0.3 interrupt flag */
T0IR = 16; /* Clear CAP0.0 interrupt flag */
T1IR = 32; /* Clear CAP0.1 interrupt flag */
VICVectAddr = 0; /* Acknowledge Interrupt */
lcd_clear();
set_cursor (0, 0);
sprintf(buffer," %d",T0TC);
lcd_print(buffer);
T0TC=0;
}
/**********************************************************************************************************
COMMENT THIS LINE IN THE STARTUP FILE USING A SEMICOLON ";" ---> ";FIQ_Handler B FIQ_Handler"
ADD THE FOLLOWING LINE IN THE STARTUP CODE DIRECTLY ABOVE THE "Reset_Addr DCD Reset_Handler"
IMPORT FIQ_Handler ;<---- add this line and use space in front of it
**********************************************************************************************************/
int main(void)
{
/*
P2.0: PORT2.0 (General purpose I/O) Output, neither pull-up nor pull-down
P3.23: CAP0.0 (Capture input for Timer 0 channel 0), neither pull-up nor pull-down
*/
PINSEL0=0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
PINMODE0=0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
IO0DIR=0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
PINSEL1=0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
PINMODE1=0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
PINSEL2=0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
PINMODE2=0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
IO1DIR=0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
PINSEL3=0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
PINMODE3=0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
PINSEL4=0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
PINMODE4=0x00000002; /* binary: 00000000_00000000_00000000_00000010 */
FIO2DIR=0x00000001; /* binary: 00000000_00000000_00000000_00000001 */
PINSEL6=0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
PINMODE6=0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
FIO3DIR=0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
PINSEL7=0x00008000; /* binary: 00000000_00000000_10000000_00000000 */
PINMODE7=0x00008000; /* binary: 00000000_00000000_10000000_00000000 */
PINSEL8=0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
PINMODE8=0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
FIO4DIR=0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
PINSEL9=0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
PINMODE9=0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
/******************************************************************************
Vector interrupt initialization
******************************************************************************/
VICIntSelect = ((unsigned long)1<<5); /* Set TIMER1 as FAST Interrupt */
VICIntEnable = ((unsigned long)1<<5); /* Enable TIMER1 FAST Interrupt */
/******************************************************************************
Timer0 (32bit)
*******************************************************************************
Counter Enabled, Counter Reset=0
Counter mode: TC incremented on both edges of CAP 0.0
Counter clk: Capture input/(PR+1), Counts every: Capture input/(PR+1)
*/
T0TCR=0x01; /* binary: 00000001 */
T0CTCR=0x03; /* binary: 00000011 */
T0TC=0x00000000; /* decimal 0 */
T0PR=0x00000000; /* decimal 0 */
T0PC=0x00000000; /* decimal 0 */
T0MCR=0x0000; /* binary: 00000000_00000000 */
T0MR0=0x00000100; /* decimal 256 */
T0MR1=0x00000000; /* decimal 0 */
T0MR2=0x00000000; /* decimal 0 */
T0MR3=0x00000000; /* decimal 0 */
T0CCR=0x0000; /* binary: 00000000_00000000 */
T0EMR=0x0000; /* binary: 00000000_00000000 */
/******************************************************************************
Timer1 (32bit)
*******************************************************************************
Counter Enabled, Counter Reset=0
Timer mode: count on rising edge of PCLK
Counter clk: 16 MHz, Counts every: 62.5 ns (calculated with peripheral clock: 12MHz)
MCR1.0 : reset, generate interrupt on compare match
*/
T1TCR=0x00; /* binary: 00000001 */
T1CTCR=0x00; /* binary: 00000000 */
T1TC=0x00000000; /* decimal 0 */
T1PR=0x00000002; /* decimal 2 */
T1PC=0x00000000; /* decimal 0 */
T1MCR=0x0003; /* binary: 00000000_00000011 */
T1MR0=0x00F42400; /* decimal 16000000 */
T1MR1=0x00000000; /* decimal 0 */
T1MR2=0x00000000; /* decimal 0 */
T1MR3=0x00000000; /* decimal 0 */
T1CCR=0x0000; /* binary: 00000000_00000000 */
T1EMR=0x0000; /* binary: 00000000_00000000 */
/******************************************************************************/
lcd_init();
lcd_clear();
set_cursor (0, 0);
lcd_print(" Majid Bahramian ");
delay_ms(2000);
/******************************************************************************/
T1TCR=0x01;
while(1)
{
FIO2SET=0x00000001;
FIO2CLR=0x00000001;
}
}

