/* =============================================================================== Name : main.c Author : $(author) Version : Copyright : $(copyright) Description : main definition =============================================================================== */ #ifdef __USE_CMSIS #include "LPC8xx.h" #endif #include <cr_section_macros.h> #include <NXP/crp.h> // Variable to store CRP value in. Will be placed automatically // by the linker when "Enable Code Read Protect" selected. // See crp.h header for more information __CRP const unsigned int CRP_WORD = CRP_NO_CRP ; // TODO: insert other include files here #include "lpc8xx_spi.h" #include "lpc8xx_gpio.h" //#include "lpc8xx_mrt.h" //functions not used; only used for defines #include "font.h" // TODO: insert other definitions and declarations here /* MRT Control register bit definition. */ #define MRT_INT_ENA(0x1<<0) #define MRT_REPEATED_MODE(0x00<<1) #define MRT_ONE_SHOT_INT(0x01<<1) #define MRT_ONE_SHOT_STALL(0x02<<1) /* MRT Status register bit definition */ #define MRT_STAT_IRQ_FLAG(0x1<<0) #define MRT_STAT_RUN(0x1<<1) void MRT_IRQHandler(void); void mrt_set_timer(uint8_t, uint32_t); void init__mrt(void); void SwitchMatrix_Init(void); void IOCON_Init(); volatile uint8_t PoVnextLine = 0; volatile uint8_t next_charrow = 0; int main(void) { const uint8_t PoVstring[]="<<GOGBOT 2014>>"; uint8_t PoVstring_index = 0; uint8_t PoVstring_charrow = 0; // TODO: insert code here GPIOInit(); SwitchMatrix_Init(); IOCON_Init(); init__mrt(); mrt_set_timer(0,12000); //1kHz timer mrt_set_timer(1,100000); //10 Hz timer mrt_set_timer(2,24000); //500 Hz timer SPI_Init(LPC_SPI0,19,(CFG_ENABLE|/*CFG_CPHA|CFG_CPOL|*/CFG_MASTER|CFG_MOSIDRV),0); //GPIOSetDir(PORT0,5,0); while(1) { if(PoVnextLine) { PoVnextLine = 0; for(PoVstring_index = 0; PoVstring_index < sizeof(PoVstring); PoVstring_index++) { //if(!GPIOGetPinValue(0,5)) //{ for(PoVstring_charrow = 0; PoVstring_charrow < 8 ; PoVstring_charrow++) { static uint8_t pinvalue; while(!next_charrow); pinvalue = GPIOGetPinValue(PORT0,5); next_charrow = 0; SPI_Send(LPC_SPI0 \ ,0 \ ,&pinvalue/*&font_8x8[PoVstring[PoVstring_index]-0x20][PoVstring_charrow]*/ \ ,1); } //} //else //{ //while(GPIOGetPinValue(0,5)); //} } } } return 0 ; } void IOCON_Init() { /* Enable UART clock */ LPC_SYSCON->SYSAHBCLKCTRL |= (1<<18); /* Pin I/O Configuration */ LPC_IOCON->PIO0_0 = 0x80; LPC_IOCON->PIO0_1 = 0x80; /* LPC_IOCON->PIO0_2 = 0x90; */ /* LPC_IOCON->PIO0_3 = 0x90; */ /* LPC_IOCON->PIO0_4 = 0x90; */ LPC_IOCON->PIO0_5 = 0x90; } void SwitchMatrix_Init() { /* Enable SWM clock */ LPC_SYSCON->SYSAHBCLKCTRL |= (1<<7); /* Pin Assign 8 bit Configuration */ /* SPI0_SCK */ LPC_SWM->PINASSIGN3 = 0x02ffffffUL; /* SPI0_MOSI */ /* SPI0_SSEL */ LPC_SWM->PINASSIGN4 = 0xff04ff03UL; /* Pin Assign 1 bit Configuration */ /* ACMP_I1 */ /* ACMP_I2 */ LPC_SWM->PINENABLE0 = 0xfffffffcUL; } /****************************************************************************** ** Function name:MRT_IRQHandler ** ** Descriptions:MRT interrupt handler ** ** parameters:None ** Returned value:None ** ******************************************************************************/ void MRT_IRQHandler(void) { if ( LPC_MRT->Channel[0].STAT & MRT_STAT_IRQ_FLAG ) { LPC_MRT->Channel[0].STAT = MRT_STAT_IRQ_FLAG;/* clear interrupt flag */ //mrt_counter++; } if ( LPC_MRT->Channel[1].STAT & MRT_STAT_IRQ_FLAG ) { LPC_MRT->Channel[1].STAT = MRT_STAT_IRQ_FLAG;/* clear interrupt flag */ PoVnextLine = 1; } if ( LPC_MRT->Channel[2].STAT & MRT_STAT_IRQ_FLAG ) { LPC_MRT->Channel[2].STAT = MRT_STAT_IRQ_FLAG;/* clear interrupt flag */ next_charrow = 1; } return; } void mrt_set_timer(uint8_t channel, uint32_t TimerInterval ) { //mrt_counter = 0; LPC_MRT->Channel[channel].INTVAL = TimerInterval; LPC_MRT->Channel[channel].INTVAL |= 0x1UL<<31; LPC_MRT->Channel[channel].CTRL = MRT_REPEATED_MODE|MRT_INT_ENA; } /****************************************************************************** ** Function name:init_timer ** ** Descriptions:Initialize timer, set timer interval, reset timer, **install timer interrupt handler ** ** parameters:none ** Returned value:None ** ******************************************************************************/ void init__mrt(void) { /* Enable clock to MRT and reset the MRT peripheral */ LPC_SYSCON->SYSAHBCLKCTRL |= (0x1<<10); LPC_SYSCON->PRESETCTRL &= ~(0x1<<7); LPC_SYSCON->PRESETCTRL |= (0x1<<7); /* Enable the MRT Interrupt */ #if NMI_ENABLED NVIC_DisableIRQ( MRT_IRQn ); NMI_Init( MRT_IRQn ); #else NVIC_EnableIRQ(MRT_IRQn); #endif return; } |