void HSelect(unsigned char x)
{
switch(x)
{
case 0: LA_0;LB_0;LC_0;LD_0;break;
case 1: LA_0;LB_0;LC_0;LD_1;break;
case 2: LA_0;LB_0;LC_1;LD_0;break;
case 3: LA_0;LB_0;LC_1;LD_1;break;
case 4: LA_0;LB_1;LC_0;LD_0;break;
case 5: LA_0;LB_1;LC_0;LD_1;break;
case 6: LA_0;LB_1;LC_1;LD_0;break;
case 7: LA_0;LB_1;LC_1;LD_1;break;
case 8: LA_1;LB_0;LC_0;LD_0;break;
case 9: LA_1;LB_0;LC_0;LD_1;break;
case 10: LA_1;LB_0;LC_1;LD_0;break;
case 11: LA_1;LB_0;LC_1;LD_1;break;
case 12: LA_1;LB_1;LC_0;LD_0;break;
case 13: LA_1;LB_1;LC_0;LD_1;break;
case 14: LA_1;LB_1;LC_1;LD_0;break;
case 15: LA_1;LB_1;LC_1;LD_1;break;
default:break;
@pywmiss 这是今天改的程序 但是led屏不显示
/*
* led.c
*
* Created on: 2016-6-26
* Author: zhang
*/
//#include "led.h"
#include "MSP430G2553.h"
#include "ZIMU.h"
#define _UP 1
#define _DOWN 2
#define _DisBuf 1
#define _EffectBuf 2
/***********需要根据实际情况调整****************/
#define LedNO 8//横向串联的LED数
/*******************MCU引脚与点阵屏引脚对应关系********************
* LA=P1^0 LB=P1^1 LC=P1^2 LD=p1^3
* EN=P1^4 R1=P1^5 LT=P1^6 SK=P1^7
* 使用时点阵屏和单片机必须共地
*******************************************************************/
//#define HSelect(x) P1 &= 0XF0;P1 |= (x);
#define LA_1 P1OUT |=BIT4;
#define LA_0 P1OUT &=~BIT4;
#define LB_1 P1OUT |=BIT5;
#define LB_0 P1OUT &=~BIT5;
#define LC_1 P2OUT |=BIT0;
#define LC_0 P2OUT &=~BIT0;
#define LD_1 P2OUT |=BIT1;
#define LD_0 P2OUT &=~BIT1;
#define nEN_1 P2OUT |=BIT2;
#define nEN_0 P2OUT &=~BIT2;
#define RED_1 P2OUT |=BIT3;
#define RED_0 P2OUT &=~BIT3;
#define LT_1 P2OUT |=BIT4;
#define LT_0 P2OUT &=~BIT4;
#define SK_1 P2OUT |=BIT5;
#define SK_0 P2OUT &=~BIT5;
void LA_Init(void);//点阵屏(LedArray)引脚初始化
void LA_ByteOut(unsigned char Byte);//单个字节输出
void LA_Disp(void);//将显示缓冲区的内容送LED屏显示
void LA_ByteLoad(unsigned char LedCnt,unsigned char *p);//将一个8*16点阵(ASCII字符字模)导入显示缓冲区
void HSelect(unsigned char x);
void test2(void);//右流动显示“welcome”
unsigned char DisBuf[16][LedNO+4];//显示缓冲区
void HSelect(unsigned char x)
{
switch(x)
{
case 0: LA_0;LB_0;LC_0;LD_0;break;
case 1: LA_0;LB_0;LC_0;LD_1;break;
case 2: LA_0;LB_0;LC_1;LD_0;break;
case 3: LA_0;LB_0;LC_1;LD_1;break;
case 4: LA_0;LB_1;LC_0;LD_0;break;
case 5: LA_0;LB_1;LC_0;LD_1;break;
case 6: LA_0;LB_1;LC_1;LD_0;break;
case 7: LA_0;LB_1;LC_1;LD_1;break;
case 8: LA_1;LB_0;LC_0;LD_0;break;
case 9: LA_1;LB_0;LC_0;LD_1;break;
case 10: LA_1;LB_0;LC_1;LD_0;break;
case 11: LA_1;LB_0;LC_1;LD_1;break;
case 12: LA_1;LB_1;LC_0;LD_0;break;
case 13: LA_1;LB_1;LC_0;LD_1;break;
case 14: LA_1;LB_1;LC_1;LD_0;break;
case 15: LA_1;LB_1;LC_1;LD_1;break;
default:break;
}
}
void LA_Init(void)
{
/***********************************
* 将与LED相连的相关引脚配置成推挽输出
***********************************/
HSelect(0);
nEN_1;
LT_1;
SK_0;
}
void LA_ByteOut(unsigned char Byte)
{
unsigned char cnt;
Byte=~Byte;
for(cnt=0;cnt<8;cnt++){
// RED(Byte>>7);
if(Byte&0x01)
{
RED_1;
}
else
{
RED_0;
}
SK_1;
Byte<<=1;
SK_0;
}
}
void LA_Disp(void)
{
unsigned char cnt1;
unsigned long cnt2;
unsigned long cnt;
for(cnt1=0;cnt1<16;cnt1++)
{
for(cnt2=0;cnt2<LedNO;cnt2++)
LA_ByteOut(DisBuf[cnt1][cnt2+2]);
//延时。串联的LED板越多的时候,这个时间应当越小,否则会有闪烁现象
for(cnt=20;cnt!=0;cnt--);
nEN_1;
LT_1;
LT_0;
HSelect(cnt1);
nEN_0;
}
for(cnt=80;cnt!=0;cnt--);
nEN_1;
}
/*******************************************************
* 功能:将一个8*16点阵(ASCII字符字模)导入显示缓冲区
* 参数:WhichBuf指定目标缓冲区,_DisBuf表示显示缓冲区,
* LedCnt缓冲区横坐标
* p指向待插入的内容
*******************************************************/
void LA_ByteLoad(unsigned char LedCnt,unsigned char *p)
{
unsigned char cnt;
for(cnt=0;cnt<16;cnt++)
DisBuf[cnt][LedCnt] = *(p++);
}
void test2(void)//右流动显示“welcome”
{
unsigned char cnt;
LA_ByteLoad(9,ZiMu2[7]);//空格
LA_ByteLoad(8,ZiMu2[0]);//w
LA_ByteLoad(7,ZiMu2[1]);//e
LA_ByteLoad(6,ZiMu2[2]);//l
LA_ByteLoad(5,ZiMu2[3]);//c
LA_ByteLoad(4,ZiMu2[4]);//o
LA_ByteLoad(3,ZiMu2[5]);//m
LA_ByteLoad(2,ZiMu2[6]);//e
for(cnt=150;cnt!=0;cnt--)//停留一段时间
LA_Disp();
}
#include <MSP430G2553.h>
#include "led.h"
/*
* main.c
*/
int main(void) {
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
LA_Init();
P1DIR |=BIT0;
while(1)
{
test2();
P1OUT |=BIT0;
}
}
一周热门 更多>