#include <msp430x14x.h>
#define Duan P6OUT //段选
#define Wei P4OUT //位选
const unsigned char SMG[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
const unsigned char BIT[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
void delay(volatile unsigned int);
int main()
{
unsigned int j;
WDTCTL = WDTPW + WDTHOLD;// Stop watchdog timer to prevent time out reset
//端口初始化
P6DIR=0xff; //P6为输出模式
P4DIR=0xff;//P4做为输出端口
P6OUT=0x00;
P4OUT=0xff;
while(1)
{
for(j=0;j<8;j++)
{
P6OUT=SMG[j];
P4OUT=BIT[j];
delay(200);
}
}
}
void delay(volatile unsigned int k)
{
unsigned int i,m;
for(i=0;i<k;i++)
{ for(m=0;m<25;m++)
{;}
}
}
现在的问题是只要有delay函数程序就无法继续运行了,比如现在把delay放在了for函数里边数码管就只显示0,如果放在for函数外边就只显示7了;我试过用for直接做延时可以完美显示,主要就是搞不懂delay的作用机理,按理说都是一样的啊为什么就不行呢?
望大虾们指教! |