TA的每日心情 | 开心 2015-11-30 11:39 |
---|
签到天数: 359 天 连续签到: 1 天 [LV.8]以坛为家I
|
楼主 |
发表于 2014-1-14 10:42:17
|
显示全部楼层
huixianfxt 发表于 2014-1-14 10:38
程序贴上来!没换芯片的话是2553呢.........
#include <MSP430x24x.h>
#define uchar unsigned char
#define uint unsigned int
#define LCK_SET P1OUT|=0x10
#define LCK_CLR P1OUT&=~0x10
const int disply[10] = {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
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 SendSpi(uchar Data)
{
LCK_CLR;
//delayms(10);
UCA0TXBUF = Data;
while (!(IFG2 & UCA0TXIFG));
LCK_SET;
delayms(10);
}
void main(void)
{
WDTCTL=WDTPW + WDTHOLD; // 关闭看门狗
SPI_Init();
P1SEL=0; // 设置为普通I/O 口
P1DIR=0x3E; // 设置方向
P1OUT=0xFF; // 设置初始值
int i=0;
while(1)
{
if((P1IN&0x01) == 0)
{
while(!(P1IN&0x01));
if(i>8)
i=0;
else
i++;
SendSpi(disply);
}
}
}
这程序我用proteus 都仿真过 |
|