MSP430F149流水灯闪烁以及数码管的显示
扫描二维码
随时随地手机看文章
今天下午写了一个流水灯闪烁的实验,总的来说,不难,因为这块板子集合的电路图没有上一块那么复杂,所以总的来说,还是比较顺手,开始的时候,出现流水灯没有流转的现象,原来是没有加入延时函数,后来经过调整,结果很快就出来了
电路示意图:
示例代码:
#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;
}
}
实验板点亮数码管
实验板的电路图
示例代码:
#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};
//记录显示位数的全局变量
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的方式写出来了,但是问题出现了,把该程序下载到板子上,结果发现不是第一个数码管亮,改变段选,结果数码管又亮了,这是led灯后三位也亮了,不知道怎么回事,这个程序还有待完善~~