Nikolica
Newbie level 6
This is my code for capture egde from rotary encoder. Can anyone help me .
The problem is in code.
The problem is in code.
Code:
#define MOJTIP (unsigned char *)
#define MR0I_FLAG (1<<0)
/**********************************************/
void UART0_Init(void);
void UART0_Ispisi(unsigned char vrednost);
void UART0_Ispisi_Tekst(unsigned char msg[]);
unsigned char UART0_Citaj(void);
unsigned char UART0_CitajINT(void);
void UART0_Ispisi_NumberINT(unsigned int num[]);
/**********************************************/
__irq void T0ISR(void);
/**********************************************/
char jbuffer[20] = { 0 };
int jirq=0;
int value2;
/**********************************************/
/*Main Function Starts*/
int main(void)
{
PINSEL0 = 0x00000020; // Enable pin 0.2 as capture channel0
T0PR = 1500;
T0TCR = 0x00000002; // Reset counter and prescaler
T0CCR = 0x00000005; // Capture on rising edge of channel 0
T0TCR = 0x00000001; // enable timer
VICVectAddr4 = (unsigned)T0ISR; // Set the timer ISR vector address
VICVectCntl4 = 0x00000024; // Set channel
VICIntEnable = 0x00000010; // Enable the interrupt
UART0_Init();
while(1)
{
T0TCR = 0x001;
UART0_Ispisi('x');
if(value2>0)
{
snprintf(jbuffer,20,"%d",jirq);
UART0_Ispisi_Tekst(MOJTIP "\n\t");
UART0_Ispisi_Tekst(MOJTIP jbuffer);
}
}
}
__irq void T0ISR(void) // __irq void T0ISR(void);
{
static int value;
UART0_Ispisi('b');
value = T0CR0; // read the capture value
value2=value;// sprintf(jbuffer,"n%d",(unsigned int)value); // UART0_Ispisi_Tekst(MOJTIP jbuffer);
if(value>0)
{
jirq++;
UART0_Ispisi('c');
}
T0IR |= 0x00000001; // Clear match 0 interrupt
VICVectAddr = 0x00000000; // Dummy write to signal end of
}
void UART0_Init(void)
{
PINSEL0 = 0x00000005;
U0LCR = 0x83;
U0DLM = 0x00;
U0DLL = 0x62; //Baud Rate - 9600
U0LCR = 0x03;
}
void UART0_Ispisi(unsigned char vrednost)
{
while(!(U0LSR&0x20));
U0THR = vrednost;
}
void UART0_Ispisi_Tekst(unsigned char msg[])
{
while(*msg)
{
UART0_Ispisi(*msg);
msg++;
}
}
unsigned char UART0_Citaj(void)
{