本来要数码管显示01234567的,但只显示012其余位没有,不知什么原因?????
其中p55和p66是两片74hc595的锁存信号
附程序如下
#include
#define uchar unsigned char
#define uint unsigned int
#define WM1 P5OUT |= BIT5
#define WM0 P5OUT &=~BIT5
#define DM1 P6OUT |= BIT6
#define DM0 P6OUT &=~BIT6
uchar Code[16]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
uchar BitCode=0x80;
void InitClock(void)
{
BCSCTL1=RSEL2+RSEL1+RSEL0;
DCOCTL =DCO2 +DCO1 +DCO0 ;
do
{
IFG1 &= ~OFIFG;
for(uint j=0;j<255;j++);
}
while((IFG1&OFIFG)!=0);
BCSCTL2=SELS+SELM1;
}
void Delay_ms (uint ms)
{
while(ms--)
{
for(uint i=0;i<800;i++);
}
}
void InitPort (void)
{
P4SEL = 0x00;
P5SEL&=~BIT5;
P6SEL&=~BIT6;
P4DIR = 0xFF;
P5DIR|= BIT5;
P6DIR|= BIT6;
}
void main (void)
{
WDTCTL=WDTPW+WDTHOLD;
InitClock();
InitPort ();
P4OUT = 0x00;
P5OUT&=~BIT5;
P6OUT&=~BIT6;
while(1)
{
for(uint i=0;i<8;i++)
{
P4OUT=Code;
DM1;
DM0;
P4OUT=~BitCode;
WM1;
WM0;
BitCode>>=1;
if(BitCode==0)
BitCode=0x80;
Delay_ms(2);
}
}
} |