📄 8led_test.c
字号:
#define LPCEB2000_I
/*********************************************************************************************
* File: 8led_test.c
* Author: Embest w.h.xie
* Desc: 8 segment led control and display
* History:
*********************************************************************************************/
/*------------------------------------------------------------------------------------------*/
/* include files */
/*------------------------------------------------------------------------------------------*/
#include "target.h"
/*------------------------------------------------------------------------------------------*/
/* local function declare */
/*------------------------------------------------------------------------------------------*/
void irq_time0_svr(void); // Timer0 interrupt
extern void irq_time0(void); // extern Timer0 interrupt
/*------------------------------------------------------------------------------------------*/
/* global variable define */
/*------------------------------------------------------------------------------------------*/
// led control variable
uint8 szLedChr[8], szLedIndex, szLedBase, szLedLast;
// led show variable 0-F
const uint32 lLedDisp[16] = { LED_CHAR_0, LED_CHAR_1, LED_CHAR_2, LED_CHAR_3,
LED_CHAR_4, LED_CHAR_5, LED_CHAR_6, LED_CHAR_7,
LED_CHAR_8, LED_CHAR_9, LED_CHAR_A, LED_CHAR_B,
LED_CHAR_C, LED_CHAR_D, LED_CHAR_E, LED_CHAR_F };
uint8 szShowIndex, szPro;
/*********************************************************************************************
* name: time_dly
* func: display code
* para: dly --in, delay value
* ret: none
* modify:
* comment:
*********************************************************************************************/
void time_dly(uint32 dly)
{
uint32 i;
for(; dly>0; dly--)
for(i=0; i<500; i++);
}
/*********************************************************************************************
* name: led_init
* func: init the led control port and init the display buffer
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
void led_init(void)
{
uint8 i;
// choose led control port and data port set out
IODIR0 |= LED_BIT_CON;
IODIR0 |= LED_SEG_CON;
IODIR0 |= LED_OUT_CON;
IODIR0 |= LED_CON;
IOCLR0 = LED_BIT_CON | LED_SEG_CON | LED_CON;
// init Led value
szLedLast = 7;
szLedBase = 0;
szLedIndex = 0;
for (i=0; i<=szLedLast ; i++) {
szLedChr[i] = i;
}
}
/*********************************************************************************************
* name: time0_init
* func: init the Time0
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
void time0_init(void)
{
// init Timer0 register, 0.5ms timing
TIMER0_PR = 99;
TIMER0_MCR = 0x03;
TIMER0_MR0 = 250;
TIMER0_TCR = 0x03;
TIMER0_TCR = 0x01;
// setup interrupt vector and allow timer interrupt
VICVectCntl3 = 0x24;
VICVectAddr3 = (uint32)irq_time0;
VICIntEnable = 0x00000010;
}
/*********************************************************************************************
* name: sys_init
* func: init the sys
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
void sys_init()
{
// allow PLL
PLLCON = 1;
VPBDIV = PLL_VPBDIV;
PLLCFG = PLL_CFG;
PLLFEED = 0xaa;
PLLFEED = 0x55;
while((PLLSTAT & (1 << 10)) == 0);
PLLCON = 3;
PLLFEED = 0xaa;
PLLFEED = 0x55;
// set MAM 2 CCLK
MAMCR = 0;
MAMTIM = MAM_TIM;
MAMCR = 2;
// init all interrupt
VICIntEnClr = 0xffffffff;
VICVectAddr = 0;
VICIntSelect = 0;
}
/*********************************************************************************************
* name: led_show
* func: Led show out
* para: szLedBit -- in, Led show bit
* szLedchar -- in, Led show data
* ret: none
* modify:
* comment:
*********************************************************************************************/
void led_show(uint32 szshowBit, uint32 szshowchar)
{
// Led bit cortrol
IOSET0 = LED_BIT_CON;
IOSET0 = LED_OUT_CON;
IOCLR0 = LED_BIT_CON;
// Led segment cortrol
IOSET0 = LED_SEG_CON;
IOCLR0 = LED_OUT_CON;
IOSET0 = szshowchar;
IOCLR0 = LED_SEG_CON;
// Led bit cortrol
IOSET0 = LED_BIT_CON;
IOSET0 = LED_OUT_CON;
IOCLR0 = szshowBit;
IOCLR0 = LED_BIT_CON;
}
/*********************************************************************************************
* name: irq_time0_svr
* func: Timer0 interrupt fun
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
void irq_time0_svr(void)
{
// count show Led bit
szLedIndex += 1;
if (szLedIndex > szLedLast) szLedIndex = szLedBase;
// refurbish show LED
led_show((0x01 << szLedIndex+10), lLedDisp[szLedChr[szLedIndex]]);
// interrupt fun finish
TIMER0_IR = 0x01;
VICVectAddr = 0x00;
}
/*********************************************************************************************
* name: Main
* func: main fun
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
int Main(void)
{
PINSEL0 = 0x00000000;
PINSEL1 = 0x00000000;
sys_init();
time0_init();
led_init();
szShowIndex = szLedBase;
while(1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -