MSP430F149流水燈閃爍以及數(shù)碼管的顯示
今天下午寫了一個流水燈閃爍的實驗,總的來說,不難,因為這塊板子集合的電路圖沒有上一塊那么復雜,所以總的來說,還是比較順手,開始的時候,出現(xiàn)流水燈沒有流轉的現(xiàn)象,原來是沒有加入延時函數(shù),后來經過調整,結果很快就出來了
電路示意圖:
示例代碼:
#include
#define CPU_F ((double)8000000)
#define delay_us(x) __delay_cycles((long)(CPU_F*(double)x/1000000.0))
#define delay_ms(x) __delay_cycles((long)(CPU_F*(double)x/1000.0))
unsigned char table1[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
void main( void )
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
unsigned char i=0;
P2SEL = 0x0;//設置P2普通的I/O
P2DIR = 0xff;//設置普通的輸出
while(1)
{
P2OUT = table1[i];
delay_ms(50);
i++;
if(i == 8)
i=0;
}
}
實驗板點亮數(shù)碼管
實驗板的電路圖
示例代碼:
#include
#define dula_l P6OUT &=~BIT6
#define dula_h P6OUT "=BIT6
#define wela_l P5OUT &=~BIT5
#define wela_h P5OUT |=BIT5
#define CPU_F ((double)8000000)
#define delay_us(x) __delay_cycles((long)(CPU_F*(double)x/1000000.0))
#define delay_ms(x) __delay_cycles((long)(CPU_F*(double)x/1000.0))
unsigned char scandata[16] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
//記錄顯示位數(shù)的全局變量
void main( void )
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
P6SEL = 0x0;//設置P6,P5,P4為普通的I/O
P5SEL = 0x0;
P4SEL = 0x0;
P6DIR |=BIT6;//選擇P6.6,P5.5為輸出
P5DIR |=BIT5;
P4DIR = 0xff;
wela_h;//拉高位選
P4OUT = 0xff;
wela_l;
P4OUT = 0x0;//消影
dula_h;
P4OUT = scandata[4];//選擇段選
delay_ms(10);//延時
dula_l;
while(1);
}
然程序按照51的方式寫出來了,但是問題出現(xiàn)了,把該程序下載到板子上,結果發(fā)現(xiàn)不是第一個數(shù)碼管亮,改變段選,結果數(shù)碼管又亮了,這是led燈后三位也亮了,不知道怎么回事,這個程序還有待完善~~