打印
[ZLG-ARM]

请各位大侠分析下程序

[复制链接]
1305|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
ymblue|  楼主 | 2007-12-4 12:16 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
TI, se, TE, tc, vi
用lpc2114的p0.10的捕获功能,检测输入信号的频率是否在正常的范围内,通过UART0输出结果(1为正确,0为错),可是通过串口助手接到的数据是乱码,大侠门看下程序,指点下,万分感谢!
extern long ztimeval;                           /* LPC21xx definitions */  
extern long timeval;  // count up in 1mSec
extern long tSec ;      // count up in 1 sec     
void initCPU_IO(void);      
int main (void)
{
                    
////////////////// System Initialize 
  initCPU_IO();//此函數內有"init_timer()"這個函數    
///////////////// The Main Loop       
while (1){                           /* Loop forever */ 

         }

}             
************************************************************

#include <string.h>
#include <LPC21XX.H>         // LPC21XX Peripheral Registers
#include "Timer.h"
// Timer0 count
#define  CNT_T0MR0_D  58622    // 1mSec = 58622 counts 

long tSec ;          //sec 
long ztSec;
long timeval;     // count up in 1mSec
long ztimeval;
long ztxtimeval; 
int A; 
int E; 
 
void tc0(void) __irq //_irq--> 例外管理程序
{      
/// 0. Processing Timer, generate tSec timer value 
T0IR        = 1;    // Clear interrupt flag, Clear interrupt flag on MR0-->Match Channel 0;MR0可開始接受中斷(避免中斷失效);T0IR由0x00000001-->0x00000000
VICVectAddr = 0;    // Acknowledge Interrupt
++timeval;
 if ( (timeval - ztimeval) >= 1000 ) 
    {                 // reach 1 Sec
       ++tSec; 
      ztimeval=timeval;
       E=20*A;
       if (E<1)
         {
          /
          U0THR=0;
         }
     else
         {
             if ((E<=3579620)&&(E>=3579460))
              {
            
             U0THR=1;
            }
     else
           {
            if ((E<=4433720)&&(E>=4433520))
                {
            
              U0THR=1;
             }  
     else
            {    
             //lcd_dec7(E);
             //lcd_goto(2,15);               
             //lcd_puts("NG");
             U0THR=1;
            }
          }
        }
    }    
}
  

void t1cap0 (void) __irq  
{

 if(T1IR&0x10) 
    {
     T1IR  = 0x10;
     VICVectAddr=0;
     T1MR0=59029500;    
     A++;   
    }       
}

/* Setup the Timer Counter 0,1  Interrupt */
void init_timer (void) {
  T0MR0 = CNT_T0MR0_D;                        // 1ms , T0MR0 = 58621
  T0MCR = 3;                                  // Interrupt and Reset on MR0(即T0TC=T0MR0時,T0TC會中斷並Reset為0)
  VICVectAddr0  = (unsigned long) tc0; // 
  VICVectCntl0 = 0x20 |4 ;                   // use it for Timer 0 Interrupt ,"VICVectCntl0 = 0x20"-->將向量IRQ Slot0 Enable,決定向量中斷(IRQ Slot)優先權為Slot0
  T0TCR = 1;                                  // Timer0 Enable
  VICIntEnable = 0x00000010;                  // Enable Timer0(MR0~3及CR0~3) Interrupt,VIC bit 4=1(VICIntEnable = 0x00000010=00000000000000000000000000010000),設定中斷源為Timer0

  PINSEL0 |= (2<<20);                        //p0.10 as CAP1.0  
  T1CCR = 5;                                // Capture and Interrupt CAP1.0, rising and 
  T1MCR = 3;
                                 //Interrupt on MR0(令T1TC=T1MR0時,產生中斷) but no reset TCR 
  VICVectAddr1 = (unsigned long)t1cap0;        // set interrupt vector in 1
  VICVectCntl1 = 0x20 | 5; 

                    // use it for Timer 1 Interrupt,決定向量中斷(IRQ Slot)優先權為Slot1
  T1TCR = 1; 
  T1IR=0x01;                                 // Timer1 Enable
  VICIntEnable = 0x20;                  // Enable Timer1(MR0~3及CR0~3) Interrupt,此行 VICVectAddr1的內容正好複製到VICVectAddr(VICVectAddr1的內容=VICVectAddr的內容),表示開始執行向量IRQ中斷;剛開機時回先從這行執行中斷,因T1MR0=0=T1TC,而T0TC須等T0TC=58621時,T0TC才會中斷(此時才會令VICVectAddr0的內容=VICVectAddr的內容)

  timeval=ztimeval=ztxtimeval=0;      
  tSec=ztSec=0xf0; 

  tcapNew=0;   
}
  
void initCPU_IO(void)
{

  VPBDIV = 1;        /* set IO clock, VPB clock=58.8924Mhz same as CCLK  */ //VPBDIV=1,pclk=cclk,因PLLCFG=0x27,所以P=2,M=8,故cclk=M*石英振盪=8*7.3728=58.8924MHz=processor的clock頻率       
  PINSEL0 |= 0x00050005  ;   /* Enable RxD0,1 & TxD0,1   */
                 /* initialize the serial interface   */
  U0LCR = 0x83;                   /* 8 bits, no Parity, 1 Stop bit            */
  U0DLL = 32;                     /* 115200 Baud Rate  */
  U0DLM = 0; 
  U0LCR = 0x03;                   /* DLAB = 0                                 */
  U0FCR = 0x01;                   /* Enable FIFO                              */
  init_timer();    

}












相关帖子

沙发
kernel99| | 2007-12-4 12:52 | 只看该作者

编译

如能编译通过,在init_timer();  
中的VICIntEnable = 0x20;  语句下加条IRQEnable ();先试下,
看编译调试时候,进中断了没

使用特权

评论回复
板凳
ymblue|  楼主 | 2007-12-4 17:32 | 只看该作者

T1MR0=59029500; 干什么用的?

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

9

主题

77

帖子

0

粉丝