Index=0;
for(;;)
{
P3OUT=0xFF;
P1OUT=table[Index];
P3OUT=~(1<<Index);
while(1);
if(++Index==8) Index=0;
delayms(1);
//while(1);
}
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Index=0;
for(;;)
{
P3OUT=0xFF;
P1OUT=table[Index];
P3OUT=~(1<<Index);
while(1);
if(++Index==8) Index=0;
delayms(1);
//while(1);
}
unsigned char const table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};//共阴数码管
晕了,说错了。 table[o]=0x3f; 数码管显示为 “0”;
chao qian1 说:unsigned char const table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};//共阴数码管晕了,说错了。 table[o]=0x3f; 数码管显示为 “0”;
这样的话就怪了,要不你试试直接左移常数值看看是否有变化,是否能找到规律
for(;;)
{
P3OUT=0xFF;
P1OUT=table[0];
P3OUT=~(1<<0);
while(1);
}
假如 直接用常熟 0 代替的话, 程序 仿真就是对的。 这个程序直接从IAR里 调用 过来的,IAR也是可以的
//你好 没加volatile程序运行如图所示。加了volatile 整个程序如下,在int b=a时出错了
#include <MSP430x24x.h>
#define uchar unsigned char
#define uint unsigned int
uchar const table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07, //共阴数码管段选码表,无小数点
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
#define ROTATE_LEFT(x, s, n) ((x) << (n)) | ((x) >> ((s) - (n)))
#define ROTATE_RIGHT(x, s, n) ((x) >> (n)) | ((x) << ((s) - (n)))
volatile int a=10;
int b=a;
void delayms(volatile uint t)
{
volatile uint i; //volatile
while(t--)
for(i=1330;i>0;i--);//进过参数的调整
}
void main(void)
{
b=a;
WDTCTL=WDTPW + WDTHOLD; // 关闭看门狗
P1DIR=0xFF; // 设置方向
P1SEL=0x00; // 设置为普通I/O 口
P3DIR=0xFF; // 设置方向
P3SEL=0x00; // 设置为普通I/O 口
P1OUT=0x00;
P3OUT=0xFF;
for(;;)
{
P3OUT=0xFF;
P1OUT=table[b];
P3OUT=~(1<<b);
if(++b==8) b=0;
delayms(1);
}
}