我们从2011年坚守至今,只想做存粹的技术论坛。  由于网站在外面,点击附件后要很长世间才弹出下载,请耐心等待,勿重复点击不要用Edge和IE浏览器下载,否则提示不安全下载不了

 找回密码
 立即注册
搜索
查看: 494|回复: 1

MSP430单片机LED点阵控制程序

[复制链接]

该用户从未签到

3

主题

0

回帖

0

积分

一级逆天

积分
0

终身成就奖

QQ
发表于 2016-5-16 06:40:28 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区

您需要 登录 才可以下载或查看,没有账号?立即注册

×
MSP430单片机LED点阵控制程序。测试通过。

#include "msp430x14x.h"
#define uchar unsigned char
#define uint unsigned int
//-----------------------------------------------------//
#define LT0     P3OUT&=~BIT0
#define LT1     P3OUT|=BIT0
#define SK0     P3OUT&=~BIT1
#define SK1     P3OUT|=BIT1
#define EN0     P3OUT&=~BIT2
#define EN1     P3OUT|=BIT2
#define R0      P3OUT&=~BIT3
#define R1      P3OUT|=BIT3
#define LS      P1OUT
//-----------------------------------------------------//
uchar count_move=0; //移动计数器
uchar flag_move=0; //移动标准位
uchar Move=0; //移位
uchar line=0;   //扫描的行
uint  zimuo=0; //字模计数器
uint  all_date; //定义汉字字模的长度
uchar BUFF[10]; //显示缓冲区,多加1个汉字,即2个字节
//-----------------------------------------------------//
const char Table[]={
0xFF,0xFF,0x00,0x80,0xDF,0xFD,0xDF,0xFD,0x01,0xC0,0xDD,0xDD,0xDD,0xDD,0xDD,0xDD,
0xDD,0xDD,0xED,0xC3,0xF5,0xDF,0xF9,0xDF,0xFD,0xDF,0x01,0xC0,0xFD,0xDF,0xFF,0xFF,/*"西",0*/
0xFF,0xFF,0xFD,0xFE,0xF3,0xFE,0xF7,0xFE,0x0F,0xC0,0xFF,0xFE,0xFF,0xFE,0xF8,0xFE,
0x7B,0xFD,0x7B,0xFB,0xBB,0xE7,0xDB,0xCF,0xEB,0xEF,0xF5,0xBF,0x0E,0xC0,0xFF,0xFF,/*"达",1*/
0x7F,0xFF,0x7F,0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FD,0xFF,0xFE,0xFF,0xFE,0x7F,0xFE,0x7F,0xFE,0x7F,0xFE,0xFF,0xFF,0xFF,0xFF,/*"7",0*/
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x0F,0xF0,0xE3,0xC7,0xF3,0xCF,0xE3,0xCF,0x8F,0xF7,
0x4F,0xF8,0xF3,0xE3,0xF9,0xCF,0xF9,0xCF,0xF3,0xE7,0x0F,0xF8,0xFF,0xFF,0xFF,0xFF,/*"8",1*/
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x0F,0xF8,0xF3,0xE3,0xF9,0xEF,0xF9,0xCF,0xF9,0xCF,
0xF3,0xC3,0x07,0xCC,0xFF,0xE7,0xFF,0xE7,0xF3,0xF1,0x07,0xFC,0xFF,0xFF,0xFF,0xFF,/*"9",2*/
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x3F,0xF0,0xCF,0xE7,0xE7,0xCF,0xF3,0x9F,0xF3,0x9F,
0xF3,0x9F,0xF3,0x9F,0xF3,0x9F,0xE7,0xCF,0xCF,0xE7,0x3F,0xF8,0xFF,0xFF,0xFF,0xFF,/*"0",3*/
0xFF,0xFF,0x03,0xC0,0x7F,0xFF,0x7F,0xFF,0x7F,0xFF,0x7F,0xFF,0x01,0x80,0x7F,0xFF,//天
0x7F,0xFF,0xBF,0xFE,0xBF,0xFD,0xDF,0xFB,0xEF,0xE7,0xF7,0x8F,0xFB,0xDF,0xFD,0xFF,
};
//-----------------------------------------------------//
void delay(unsigned int n)   //延时函数
{ unsigned int k;
   for(k=0;k<n;k++);
}
//-----------------------------------------------------//
void IO_Init(void)
{
//IO初始化---------------------------------------
   P1DIR |=0xFF;                       
   P3DIR |=0xFF;
}
//-----------------------------------------------------//
void variable_init()//变量初始化
{
   all_date = sizeof( Table )-128;  //计算出字模的长度,在减去16X64的缓存区
}
//-----------------------------------------------------//
void load_data(void) //装载数据 16*64点阵的 缓存区
{
char s;
for(s=5;s>0;s--)
{
  BUFF[2*(s-1)]=Table[zimuo+32*(s-1)+2*line];
  BUFF[2*(s-1)+1]=Table[zimuo+1+32*(s-1)+2*line];         
}
}
//-----------------------------------------------------//
void send_data (void) //发送数据     
{
  uchar s;
  uchar inc,tempyid,temp,k;
  if(Move<8)  inc=0;
  else   inc=1;
  for(s=0+inc;s<8+inc;s++)   //发送8字节数据
{
  if(Move<8) tempyid=Move;
  else  tempyid=Move-8;  
  temp= ((BUFF>>tempyid)|(BUFF[s+1]<<(8-tempyid)));//h1左移tempyid位后和h2右移8-tempyid相或,取出移位后的数据。
for(k = 0; k < 8; k++)
{
  if(temp&0x01) R1;   //串行输出Data数据
        else   R0;
  SK0;
  temp=temp>>1;
  //_NOP();
  SK1;
  }
}
}
//-----------------------------------------------------//
void led_show1()//左移显示16X64
{
for(line=0;line<16;line++)
{
  load_data(); //调整移动数据
  send_data(); //装载移动数据
  EN1;    //关显示屏片选
  delay(500);  
  //_NOP();//消影
  LT1;   
  LT0;    //输出锁存
  LS=line;    //16行地址
  //_NOP();//消影
  EN0;     //开显示屏片选
}
}
//-----------------------------------------------------//
void main( void )
{
  char z;
  WDTCTL = WDTPW + WDTHOLD;
  IO_Init();
  variable_init();
   /*------选择系统主时钟为8MHz-------*/
    BCSCTL1 &= ~XT2OFF;                 //打开XT2高频晶体振荡器
    do
    {
        IFG1 &= ~OFIFG;                 //清除晶振失败标志
        for (z = 0xFF; z > 0; z--);     //等待8MHz晶体起振
    }
    while ((IFG1 & OFIFG));             //晶振失效标志仍然存在?
    BCSCTL2 |= SELM_2 + SELS;           //MCLK和SMCLK选择高频晶振
   /*------选择定时器时钟为32768Hz-------*/
    CCTL0= CCIE;
    CCR0 =327;
    TACTL = TASSEL_1 +TACLR+MC_1;  
    _EINT();  //使能中断,每100ms中断一次
   
      while(1)
{

   led_show1();
    if(flag_move)
  {
   flag_move=0;
   Move++;
   if(Move>=16) //一个汉字已经全部移出
   {
    Move=0;
    zimuo=zimuo+32; //换下一个字
    if(zimuo>= all_date)
    zimuo = 0;
   }
  }  
}
}
//-----------------------------------------------------//
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A (void) //定时器A的CC0中断处理程序
{
  
count_move++;  //点阵屏移动计数器
    if(count_move>=6)
{
  count_move=0; //点阵屏移动计数器清零
  flag_move=1;  //移动标准位置一
}
   
}
回复

使用道具 举报

  • TA的每日心情
    开心
    5 天前
  • 签到天数: 9 天

    [LV.3]偶尔看看II

    1

    主题

    97

    回帖

    156

    积分

    二级逆天

    积分
    156

    终身成就奖社区居民

    QQ
    发表于 2016-5-16 08:51:43 | 显示全部楼层
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    每日签到,有金币领取。


    Copyright ©2011-2024 NTpcb.com All Right Reserved.  Powered by Discuz! (NTpcb)

    本站信息均由会员发表,不代表NTpcb立场,如侵犯了您的权利请发帖投诉

    ( 闽ICP备2024076463号-1 ) 论坛技术支持QQ群171867948 ,论坛问题,充值问题请联系QQ1308068381

    平平安安
    TOP
    快速回复 返回顶部 返回列表