|
#include<reg51.h> //頭文件
#define uchar unsigned char //宏定義,為方便編程
#define uint unsigned int
#define LED P0 //宏定義,將P1口定義為LED
uchar led_value[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe,0x00}; //定義一數組,內存放跑馬燈數據
uchar *p=led_value; //定義指針,指向跑馬燈數組首地址
void delay() //延遲函數,與跑馬燈跳動頻率有關
{
uchar ii,jj;
for(ii=0;ii<200;ii++)
for(jj=0;jj<200;jj++);
}
void run_led() //跑馬燈運行函數
{
while(*p!=0x00)
{
LED=*p; //將數組中數據取出賦給P1口
p++; //預取下一數據
delay(); //延遲
}
p=led_value;
}
char code SST516[3] _at_ 0x003b; //仿真器保留
main() //主函數
{
while(1)
run_led(); //上電即運行跑馬燈程序
}
|
|