注册 登录
电子工程世界-论坛 返回首页 EEWORLD首页 频道 EE大学堂 下载中心 Datasheet 专题
lovedata的个人空间 https://home.eeworld.com.cn/space-uid-83057.html [收藏] [复制] [分享] [RSS]
日志

DIY第一天,LPC1343驱动led点阵成功

已有 1758 次阅读2010-6-3 08:51

<>      针对近来我们论坛的lpc和传感器的DIY活动,由于手头没有lcd,昨天我干脆焊了一个8*32的LED,整整花了我一天的时间,打算用它来显示调试信息,并做显示用。到时候还可以在上面直接玩贪吃蛇,俄罗斯方块,迷宫,飞机等游戏。为了不扩展别的芯片,我打算直接用io来驱动,了解了下lpc1343,它一共才有42个gpio,以后还要接各种传感器,usb等,8*32点阵就要把它给用完了,所以就用3块好了,8*24用做显示也足够了,等以后有了lcd再做更精细的显示吧~~</P>
<>     废话少说先上代码~~ </P>
<>/*<BR>===============================================================================<BR> Name        : main.c<BR> Author      : lovedata<BR> Version     :<BR> Copyright   : (C) Copyright <BR> Description : main definition<BR>===============================================================================<BR>*/</P>
<P>#ifdef __USE_CMSIS<BR>#include "LPC13xx.h"<BR>#endif</P>
<P>// TODO: insert other include files here<BR>#include "clkconfig.h"<BR>#include "gpio.h"<BR>#include "led_matrix.h"<BR>// TODO: insert other definitions and declarations here<BR>volatile uint32_t msTicks;                            /* counts 1ms timeTicks */<BR>/*----------------------------------------------------------------------------<BR>  SysTick_Handler<BR> *----------------------------------------------------------------------------*/<BR>void SysTick_Handler(void) {<BR>  msTicks++;                        /* increment counter necessary in Delay() */<BR>}</P>
<P>/*------------------------------------------------------------------------------<BR>  delays number of tick Systicks (happens every 1 ms)<BR> *------------------------------------------------------------------------------*/<BR>__INLINE static void Delay (uint32_t dlyTicks) {<BR>  uint32_t curTicks;</P>
<P>  curTicks = msTicks;<BR>  while ((msTicks - curTicks) &lt; dlyTicks);<BR>}</P>
<P>__INLINE void SysInit(void)<BR>{<BR>  GPIOInit();<BR> /* Initialize port data so LED Matrix is OFF by default */<BR>  LPC_GPIO3-&gt;DATA |= 0x0f;   /* set P3_0~P3_3 output data to all 1's */<BR>   LPC_GPIO1-&gt;DATA |= 0xf00;   /* set P1_8~P1_11 output data to all 1's */<BR>   LPC_GPIO2-&gt;DATA &= ~0x7f8;   /* set P2_3~P2_10 output data to all 0's */<BR>   LPC_GPIO3-&gt;DIR |= 0x00f;             /* set P3_0~P3_3 to output */<BR>   LPC_GPIO1-&gt;DIR |= 0xf00;             /* set P1_8~P1_11 to output */<BR>   LPC_GPIO2-&gt;DIR |= 0x7f8;            /* set P2_3~P2_10 to output */<BR>}<BR>__INLINE void PrintMsg(uint32_t character)<BR>{<BR> uint32_t i;<BR> for(i = 0; i &lt; 5; i ++)<BR> {<BR>  LPC_GPIO3-&gt;DATA = ~(1&lt;&lt;i);<BR>  LPC_GPIO1-&gt;DATA = ~( 1&lt;&lt; (i+4));<BR>  LPC_GPIO2-&gt;DATA = (FontTable [character-32]&lt;&lt;3);<BR>  Delay(5);<BR> }<BR>}<BR>int main(void) {<BR> <BR> // TODO: insert code here<BR> SysInit();<BR> if (SysTick_Config(SystemCoreClock / 1000)) { /* Setup SysTick Timer for 1 msec interrupts  */<BR> while (1);                                  /* Capture error */<BR> }</P>
<P> if ( !(SysTick-&gt;CTRL & SysTick_CTRL_CLKSOURCE_Msk) )<BR> {<BR> /* When external reference clock is used(CLKSOURCE in<BR> Systick Control and register bit 2 is set to 0), the<BR> SYSTICKCLKDIV must be a non-zero value and 2.5 times<BR> faster than the reference clock.<BR> When core clock, or system AHB clock, is used(CLKSOURCE<BR> in Systick Control and register bit 2 is set to 1), the<BR> SYSTICKCLKDIV has no effect to the SYSTICK frequency. See<BR> more on Systick clock and status register in Cortex-M3<BR> technical Reference Manual. */<BR> LPC_SYSCON-&gt;SYSTICKCLKDIV = 0x08;<BR> }<BR> while(1)<BR> {<BR>  PrintMsg('B');<BR> }<BR> return 0 ;<BR>}<BR>    上面这段代码使8*8led点阵显示了一个"B",这个模块只用到了io的设置和系统的滴答定时器,感觉lpc1343的io驱动能力还是很强的,驱动8*8的点阵全亮都没问题,所以在驱动上就不用担心了,接下来我会把led显示驱动写完整,完了就可以进行DIY的第一个应用了,用加速度传感器在led上显示倾斜角度。。。。。。</P>
评论 (0 个评论)

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 注册

热门文章