这么点破玩艺,昨天我为了学会它,花了六小时

#define GLOBAL_CLK  1
#include <stdlib.h>
#include <string.h>
#include "def.h"
#include "option.h"
#include "2440addr.h"
#include "2440lib.h"
#include "2440slib.h"
#include "mmu.h"
#include "profile.h"
#include "memtest.h"
void LEDInit()
{
 rGPBCON &= ~(3<<10 | 3<<12 | 3<<14 | 3<<16);
 rGPBCON |= (1<<10 | 1<<12 | 1<<14 | 1<<16);
}
void LEDOpen()
{
 rGPBDAT &= ~(1<<5 | 1<<6 | 1<<7 | 1<<8);
}
void LEDClose()
{
 rGPBDAT |= (1<<5 | 1<<6 | 1<<7 | 1<<8); 
}
int LEDOpenI( int index )
{
 if( index <= 0 )
 {
  return 0;
 }
 if( index >= 5 )
 {
  return 0;
 }
 rGPBDAT &= ~( 1 << ( index + 4 ) );
 return 1;
}
int LEDCloseI( int index )
{
 if( index <= 0 )
 {
  return 0;
 }
 if( index >= 5 )
 {
  return 0;
 }
 rGPBDAT |= ( 1 << ( index + 4 ) );
 return 1;
}
void BeepInit()
{
 rGPBCON &= ~3;
 rGPBCON |= 1;
}
void BeepStop()
{
 rGPBDAT &= ~( 0x01 );
}
void BeepRun()
{
 rGPBDAT |= 0x01;
}
__inline void ButtonProc1()
{
 LEDOpenI( 1 );
}
__inline void ButtonProc2()
{
 LEDOpenI( 2 );
}
__inline void ButtonProc3()
{
 LEDOpenI( 3 );
}
__inline void ButtonProc4()
{
 LEDOpenI( 4 );
}
__inline void ButtonProc5()
{
 BeepRun();
}
__inline void ButtonProc6()
{
 LEDClose();
 BeepStop();
}
static void __irq ButtonCallBack()
{
 if( rEINTPEND & ( 1 << 8 ) )
 {
  ButtonProc1();
  rEINTPEND |= ( 1 << 8 );
  ClearPending( BIT_EINT8_23 );
 }
 if( rEINTPEND & ( 1 << 11 ) )
 {
  ButtonProc2();
  rEINTPEND |= ( 1 << 11 );
  ClearPending( BIT_EINT8_23 );
 }
 if( rEINTPEND & ( 1 << 13 ) )
 {
  ButtonProc3();
  rEINTPEND |= ( 1 << 13 );
  ClearPending( BIT_EINT8_23 );
 }
 if( rEINTPEND & ( 1 << 14 ) )
 {
  ButtonProc4();
  rEINTPEND |= ( 1 << 14 );
  ClearPending( BIT_EINT8_23 );
 }
 if( rEINTPEND & ( 1 << 15 ) )
 {
  ButtonProc5();
  rEINTPEND |= ( 1 << 15 );
  ClearPending( BIT_EINT8_23 );
 }
 if( rEINTPEND & ( 1 << 19 ) )
 {
  ButtonProc6();
  rEINTPEND |= ( 1 << 19 );
  ClearPending( BIT_EINT8_23 );
 }
}
void ButtonInit( unsigned unFunCallBack )
{
 rGPGCON &= ~3;
 rGPGCON |= 2;
 rGPGCON &= ~( 3 << ( 2 * 3 ) );
 rGPGCON |= ( 2 << ( 2 * 3 ) );
 rGPGCON &= ~( 3 << ( 2 * 5 ) );
 rGPGCON |= ( 2 << ( 2 * 5 ) );
 rGPGCON &= ~( 3 << ( 2 * 6 ) );
 rGPGCON |= ( 2 << ( 2 * 6 ) );
 rGPGCON &= ~( 3 << ( 2 * 7 ) );
 rGPGCON |= ( 2 << ( 2 * 7 ) );
 rGPGCON &= ~( 3 << ( 2 * 11 ) );
 rGPGCON |= ( 2 << ( 2 * 11 ) );
 rEXTINT1 &= ~       0xf;
 rEXTINT1 &= ~    0xf000;
 rEXTINT1 &= ~  0xf00000;
 rEXTINT1 &= ~ 0xf000000;
 rEXTINT1 &= ~0xf0000000;
 rEXTINT2 &= ~    0xf000;
 rEINTPEND |= 1<<8;
 rEINTPEND |= 1<<11;
 rEINTPEND |= 1<<13;
 rEINTPEND |= 1<<14;
 rEINTPEND |= 1<<15;
 rEINTPEND |= 1<<19;
 rEINTMASK &= ~( 1 << 8 );
 rEINTMASK &= ~( 1 << 11 );
 rEINTMASK &= ~( 1 << 13 );
 rEINTMASK &= ~( 1 << 14 );
 rEINTMASK &= ~( 1 << 15 );
 rEINTMASK &= ~( 1 << 19 );
 pISR_EINT8_23 = ( ( 0 == unFunCallBack ) ? ( (unsigned)ButtonCallBack ) : ( unFunCallBack ) ) ;
 rINTMSK &= ~(BIT_EINT8_23);
}
__inline void TimerCallBackProc()
{
 if( rGPBDAT & ( 1 << 5 ) )
 {
  rGPBDAT &= ~( 1 << 5 );
 }
 else
 {
  rGPBDAT |= ( 1 << 5 );
 }
}
static void __irq TimerCallBack()
{
 ClearPending( BIT_TIMER0 ); 
 TimerCallBackProc();
}
void TimerInit()
{
 rTCFG0 = 49;
 rTCFG1 = 0x03;
 rTCNTB0 = 62500/2;
 rTCMPB0 = 0;
 rTCON |= (1<<1);
 rTCON = 0x09;
 rPRIORITY = 0x00000000;
 rINTMOD |= 0x00000000;
 ClearPending(BIT_TIMER0);
 pISR_TIMER0 = (U32)TimerCallBack;
 EnableIrq(BIT_TIMER0);
}
void MySetClock()
{
 U32 UPLL;
 U8 m, p, s, hdiv, pdiv;
 m = 92;
 p = 1;
 s = 1;
 hdiv = 2;
 pdiv = 1;
 rMPLLCON = (m<<12 | p<<4 | s);
 rCLKDIVN = (hdiv<<1 | pdiv);
 MMU_SetAsyncBusMode();
 FCLK = ((m+8)*(FIN/100) *2)/((p+2)*(1<<s))*100;
 HCLK = FCLK/4;
 PCLK = HCLK/2;
 UPLL = ((56+8)*FIN)/((2+2)*(1<<2));
 UCLK = UPLL;
}

void Main()
{
 MMU_Init();
 LEDInit();
 ButtonInit( 0 );
 BeepInit();
 MySetClock();
 TimerInit();
 while( 1 );
}

 

posted @ 2014-10-20 16:13  穷到底  阅读(232)  评论(0编辑  收藏  举报