急!!!求大神们帮忙看看这个代码,初学者看不懂

2019-07-15 16:40发布

#include <MSP430x24x.h>
#define uchar unsigned char
#define uint unsigned int

#define LCK_SET  P1OUT|=0x10
#define LCK_CLR  P1OUT&=~0x10

#define E_SET  P1OUT|=0x20
#define E_CLR  P1OUT&=~0x20
const uchar Num[]=
{0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x24,0x18,0x00,0x00,/*"0",0*/

0x00,0x00,0x00,0x08,0x0E,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x3E,0x00,0x00,/*"1",1*/

0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x20,0x20,0x10,0x08,0x04,0x42,0x7E,0x00,0x00,/*"2",2*/

0x00,0x00,0x00,0x3C,0x42,0x42,0x20,0x18,0x20,0x40,0x40,0x42,0x22,0x1C,0x00,0x00,/*"3",3*/

0x00,0x00,0x00,0x20,0x30,0x28,0x24,0x24,0x22,0x22,0x7E,0x20,0x20,0x78,0x00,0x00,/*"4",4*/

0x00,0x00,0x00,0x7E,0x02,0x02,0x02,0x1A,0x26,0x40,0x40,0x42,0x22,0x1C,0x00,0x00,/*"5",5*/

0x00,0x00,0x00,0x38,0x24,0x02,0x02,0x1A,0x26,0x42,0x42,0x42,0x24,0x18,0x00,0x00,/*"6",6*/

0x00,0x00,0x00,0x7E,0x22,0x22,0x10,0x10,0x08,0x08,0x08,0x08,0x08,0x08,0x00,0x00,/*"7",7*/

0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x24,0x18,0x24,0x42,0x42,0x42,0x3C,0x00,0x00,/*"8",8*/

0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x64,0x58,0x40,0x40,0x24,0x1C,0x00,0x00,/*"9",9*/
};
void delayms(uint t)
{
    uint i;
    while(t--)
      for(i=5000;i>0;i--);//进过参数的调整 1330
}
void SPI_Init()
{
  P3SEL |= 0x11;                            // P3.0,4 USCI_A0 option select
  UCA0CTL0 |= UCCKPH + UCMSB + UCMST + UCSYNC;  // 3-pin, 8-bit SPI master
  UCA0CTL1 |= UCSSEL_2;                     // SMCLK
  UCA0BR0 |= 0x02;
  UCA0BR1 = 0;
  UCA0MCTL = 0;
  UCA0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
}
void Init_Timer_A(void)
{
    CCTL0 = CCIE; // 使能CCR0 中断
    TAR=0xFC18;  // 计数装入初值
    TACTL=TASSEL_2+MC_2+TAIE+ID_3;//设置时钟源和计数模式 采用SMCLK/8 =1Mhz                          

}
void SendSpi(uchar Data)
{
   while (!(IFG2 & UCA0TXIFG));   
   UCA0TXBUF = Data;

}


void main(void)
{

    WDTCTL=WDTPW + WDTHOLD; // 关闭看门狗
    SPI_Init();
    Init_Timer_A();
    P1SEL=0;            // 设置为普通I/O 口
    P1DIR=0x3f;            // 设置方向
    P1OUT=0xFF;        // 设置初始值
    P4DIR=0x01;
    P4SEL=0;
    _BIS_SR(LPM0_bits+ GIE);//进入低功耗睡眠模式



    while(1)
    {

   //_BIS_SR(LPM0_bits+ GIE);//进入低功耗睡眠模式

    }


}
#pragma vector=TIMERA0_VECTOR //定时器A 中断服务程序
__interrupt void Timer_a(void)
{
  static uchar i,timer;
  static uint count;
  switch(TAIV)         //TAIV 表示中断向量号  
  {
  case 2:break;
  case 4:break;
  case 10:              //TAIV=10 表示中断计数器溢出中断  
  TAR=65536-1000;       // (65536-1000)

   if(++count==100)
   {
     count=0;
     if(++timer==100)
       timer=0;
   }

     SendSpi(~Num[i+(timer%10)*16]);
     SendSpi(~Num[i+(timer/10)*16]);

     E_SET;
     LCK_CLR;
     LCK_SET;
     P1OUT=i;
     E_CLR;
     P4OUT^=0x01;
     //delayms(1);
      if(++i==16)
     i=0;
  }
  //LPM0_EXIT;

}


友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
2条回答
电子发烧不会玩
1楼-- · 2019-07-15 17:29
 精彩回答 2  元偷偷看……
韩山童
2楼-- · 2019-07-15 22:24
建议楼主去看看寄存器配置,SPI总线的操纵方法,中断程序的编写方法,了解这些了你就知道是什么意思了。

一周热门 更多>