STC89C52RC第二個程序基本成功~~~
用LED小燈珠模擬循環顯示0~9、A~F,除了4、5(經查,原來是這兩個數的16進制數搞錯了,一改就好,非常容易)顯示不對,其它的都正確。
開機循環顯示一遍,熄滅等待;按鍵一下又循環顯示一遍,再按再顯示。。。
代碼如下,請高手指點指點~~
#include <reg52.h>
#include <intrins.h>
unsigned char Key_n,a,b,c;
unsigned char h ,i, j,k,t;
unsigned char arr_nm[] ={0x40,0x4f,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10,0x88,0x83,0xc6,0xa1,0x86,0x8e} ;
sbit Key=P1^0;
void delay10ms(void)
{
for (c=1;c>0;c--)
{
for (b=38;b>0;b--)
{
for (a=130;a>0;a--);
{ }
}
}
}
void delay1s(void)
{
unsigned char h,i,j,k;
for(h=5;h>0;h--)
for(i=4;i>0;i--)
for(j=116;j>0;j--)
for(k=214;k>0;k--);
}
int main()
{
for(t=0;t<16;t++)
{
P0= arr_nm[t];
delay1s() ;
}
P0= 0xff;
Key_n=0;
do
{
if (Key==0)
{
delay10ms() ;
if (Key==0)
{
P0= arr_nm[Key_n];
Key_n++;
}
}
}
while(Key_n<16);
return 0;
}
|